aboutsummaryrefslogtreecommitdiffstats
path: root/SQLiteStudio3/guiSQLiteStudio/windows/collationseditormodel.h
blob: 46f7ab5a6ba378292888a7567add9c5bf3aa26fb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#ifndef COLLATIONSEDITORMODEL_H
#define COLLATIONSEDITORMODEL_H

#include "services/collationmanager.h"
#include "guiSQLiteStudio_global.h"
#include <QIcon>
#include <QHash>
#include <QAbstractListModel>

class GUI_API_EXPORT CollationsEditorModel : public QAbstractListModel
{
        Q_OBJECT
    public:
        using QAbstractItemModel::setData;

        explicit CollationsEditorModel(QObject *parent = nullptr);

        void clearModified();
        bool isModified() const;
        bool isModified(int row) const;
        void setModified(int row, bool modified);
        void setName(int row, const QString& name);
        QString getName(int row) const;
        void setLang(int row, const QString& lang);
        QString getLang(int row) const;
        void setAllDatabases(int row, bool allDatabases);
        bool getAllDatabases(int row) const;
        void setCode(int row, const QString& code);
        QString getCode(int row) const;
        void setDatabases(int row, const QStringList& databases);
        QStringList getDatabases(int row);
        bool isValid(int row) const;
        void setValid(int row, bool valid);
        bool isValid() const;
        void setData(const QList<CollationManager::CollationPtr>& collations);
        void addCollation(const CollationManager::CollationPtr& collation);
        void deleteCollation(int row);
        QList<CollationManager::CollationPtr> getCollations() const;
        QStringList getCollationNames() const;
        void validateNames();
        bool isAllowedName(int rowToSkip, const QString& nameToValidate);
        bool isValidRowIndex(int row) const;

        int rowCount(const QModelIndex& parent = QModelIndex()) const;
        QVariant data(const QModelIndex& index, int role) const;

    private:
        struct Collation
        {
            Collation();
            Collation(const CollationManager::CollationPtr& other);

            CollationManager::CollationPtr data;
            bool modified = false;
            bool valid = true;
            QString originalName;
        };

        void init();
        void emitDataChanged(int row);

        QList<Collation*> collationList;

        /**
         * @brief List of collation pointers before modifications.
         *
         * This list is kept to check for modifications in the overall list of collations.
         * Pointers on this list may be already deleted, so don't use them!
         * It's only used to compare list of pointers to collationList, so it can tell you
         * if the list was modified in regards of adding or deleting collations.
         */
        QList<Collation*> originalCollationList;
        QHash<QString,QIcon> langToIcon;
        bool listModified = false;
};

#endif // COLLATIONSEDITORMODEL_H