File: dblistmodel.h

package info (click to toggle)
sqlitestudio 3.4.21%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 54,880 kB
  • sloc: ansic: 406,208; cpp: 123,872; yacc: 2,692; tcl: 497; sh: 462; xml: 426; makefile: 19
file content (76 lines) | stat: -rw-r--r-- 1,859 bytes parent folder | download
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
#ifndef DBLISTMODEL_H
#define DBLISTMODEL_H

#include "db/db.h"
#include "guiSQLiteStudio_global.h"
#include <QAbstractListModel>

class QComboBox;

class GUI_API_EXPORT DbListModel : public QAbstractListModel
{
        Q_OBJECT
    public:
        enum class SortMode
        {
            LikeDbTree,
            Alphabetical,
            AlphabeticalCaseInsensitive,
            ConnectionOrder
        };

        explicit DbListModel(QObject *parent = 0);
        ~DbListModel();

        QVariant data(const QModelIndex & index, int role) const;
        int rowCount(const QModelIndex & parent = QModelIndex()) const;
        QModelIndex sibling(int row, int column, const QModelIndex & idx) const;

        Db* getDb(int index);
        int getIndexForDb(Db* db);
        void setSortMode(SortMode sortMode);
        SortMode getSortMode() const;
        void setSortMode(const QString& sortMode);
        QString getSortModeString() const;
        void setCombo(QComboBox* combo);

    private:
        using QAbstractItemModel::sort;

        class DbTreeComparer
        {
            public:
                DbTreeComparer();
                bool operator()(Db* db1, Db* db2);

            private:
                QStringList dbTreeOrder;
        };

        class AlphaComparer
        {
            public:
                AlphaComparer(Qt::CaseSensitivity cs = Qt::CaseSensitive);

                bool operator()(Db* db1, Db* db2);

            private:
                Qt::CaseSensitivity cs;
        };

        void sort();

        QList<Db*> unsortedList;
        QList<Db*> dbList;
        SortMode sortMode = SortMode::ConnectionOrder;
        QComboBox* comboBox = nullptr;

    private slots:
        void dbConnected(Db* db);
        void dbDisconnected(Db* db);

    signals:
        void listCleared();
};

#endif // DBLISTMODEL_H