summaryrefslogtreecommitdiffstats
path: root/SQLiteStudio3/guiSQLiteStudio/dblistmodel.h
diff options
context:
space:
mode:
Diffstat (limited to 'SQLiteStudio3/guiSQLiteStudio/dblistmodel.h')
-rw-r--r--SQLiteStudio3/guiSQLiteStudio/dblistmodel.h66
1 files changed, 66 insertions, 0 deletions
diff --git a/SQLiteStudio3/guiSQLiteStudio/dblistmodel.h b/SQLiteStudio3/guiSQLiteStudio/dblistmodel.h
new file mode 100644
index 0000000..121db4d
--- /dev/null
+++ b/SQLiteStudio3/guiSQLiteStudio/dblistmodel.h
@@ -0,0 +1,66 @@
+#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,
+ 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);
+ 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:
+ bool operator()(Db* db1, Db* db2);
+ };
+
+ 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);
+};
+
+#endif // DBLISTMODEL_H