diff options
| author | 2023-04-30 18:31:18 -0400 | |
|---|---|---|
| committer | 2023-04-30 18:31:18 -0400 | |
| commit | 4de57f628bc74f00ba1885e91c84ea07c5405d8f (patch) | |
| tree | 5d91900751e826d491ff1b2ebc571a787e84f864 /SQLiteStudio3/guiSQLiteStudio/windows/codesnippeteditormodel.h | |
| parent | 74d881cefa9097e58e129e37b9c44d680d8c7dfe (diff) | |
| parent | 3565aad630864ecdbe53fdaa501ea708555b3c7c (diff) | |
Update upstream source from tag 'upstream/3.4.4+dfsg'
Update to upstream version '3.4.4+dfsg'
with Debian dir 482614bd23f0ef52dabc9803477204ad88e917ed
Diffstat (limited to 'SQLiteStudio3/guiSQLiteStudio/windows/codesnippeteditormodel.h')
| -rw-r--r-- | SQLiteStudio3/guiSQLiteStudio/windows/codesnippeteditormodel.h | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/SQLiteStudio3/guiSQLiteStudio/windows/codesnippeteditormodel.h b/SQLiteStudio3/guiSQLiteStudio/windows/codesnippeteditormodel.h new file mode 100644 index 0000000..ae5fa86 --- /dev/null +++ b/SQLiteStudio3/guiSQLiteStudio/windows/codesnippeteditormodel.h @@ -0,0 +1,80 @@ +#ifndef CODESNIPPETEDITORMODEL_H +#define CODESNIPPETEDITORMODEL_H + +#include "guiSQLiteStudio_global.h" +#include "services/codesnippetmanager.h" +#include <QAbstractListModel> + +class GUI_API_EXPORT CodeSnippetEditorModel : public QAbstractListModel +{ + Q_OBJECT + + public: + using QAbstractItemModel::setData; + + enum Role + { + CODE = 1000, + MODIFIED = 1001, + VALID = 1002 + }; + + explicit CodeSnippetEditorModel(QObject *parent = 0); + + void clearModified(); + bool isModified() const; + bool isModified(int row) const; + void setModified(int row, bool modified); + bool isValid() const; + bool isValid(int row) const; + void setValid(int row, bool valid); + void setCode(int row, const QString& code); + QString getCode(int row) const; + void setName(int row, const QString& newName); + QString getName(int row) const; + void setHotkey(int row, const QKeySequence& value); + QKeySequence getHotkey(int row) const; + void setData(const QList<CodeSnippetManager::CodeSnippet*>& snippets); + void addSnippet(CodeSnippetManager::CodeSnippet* snippet); + void deleteSnippet(int row); + QList<CodeSnippetManager::CodeSnippet*> generateSnippets() const; + QStringList getSnippetNames() const; + void validateNames(); + bool isAllowedName(int rowToSkip, const QString& nameToValidate); + bool isAllowedHotkey(int rowToSkip, const QKeySequence& hotkeyToValidate); + bool isValidRowIndex(int row) const; + + int moveUp(int row); + int moveDown(int row); + int rowCount(const QModelIndex& parent = QModelIndex()) const; + QVariant data(const QModelIndex& index, int role) const; + + private: + struct Snippet + { + Snippet(); + Snippet(CodeSnippetManager::CodeSnippet* other); + + CodeSnippetManager::CodeSnippet data; + bool modified = false; + bool valid = true; + QString originalName; + }; + + void emitDataChanged(int row); + + QList<Snippet*> snippetList; + + /** + * @brief List of snippets pointers before modifications. + * + * This list is kept to check for modifications in the overall list of snippets. + * Pointers on this list may be already deleted, so don't use them! + * It's only used to compare list of pointers to snippetList, so it can tell you + * if the list was modified in regards of adding or deleting functions. + */ + QList<Snippet*> originalSnippetList; + bool listModified = false; +}; + +#endif // CODESNIPPETEDITORMODEL_H |
