summaryrefslogtreecommitdiffstats
path: root/SQLiteStudio3/guiSQLiteStudio/selectabledbobjmodel.h
blob: 2fca1b4965a6e31a77a0da9d6d4baa86ba6b3715 (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
#ifndef SELECTABLEDBOBJMODEL_H
#define SELECTABLEDBOBJMODEL_H

#include "guiSQLiteStudio_global.h"
#include <QSortFilterProxyModel>
#include <QSet>

class DbTreeItem;
class QTreeView;

class GUI_API_EXPORT SelectableDbObjModel : public QSortFilterProxyModel
{
        Q_OBJECT
    public:
        explicit SelectableDbObjModel(QObject *parent = 0);

        QVariant data(const QModelIndex& index, int role) const;
        bool setData(const QModelIndex& index, const QVariant& value, int role);
        Qt::ItemFlags flags(const QModelIndex& index) const;

        QString getDbName() const;
        void setDbName(const QString& value);

        QStringList getCheckedObjects() const;
        void setCheckedObjects(const QStringList& value);

        void setRootChecked(bool checked);
        DbTreeItem* getItemForIndex(const QModelIndex& index) const;

    protected:
        bool filterAcceptsRow(int srcRow, const QModelIndex& srcParent) const;

    private:
        DbTreeItem* getItemForProxyIndex(const QModelIndex& index) const;
        Qt::CheckState getStateFromChilds(const QModelIndex& index) const;
        void setRecurrently(const QModelIndex& index, Qt::CheckState checked);
        bool isObject(DbTreeItem* item) const;
        bool checkRecurrentlyForDb(DbTreeItem* item) const;

        QSet<QString> checkedObjects;
        QString dbName;
};

#endif // SELECTABLEDBOBJMODEL_H