From 7167ce41b61d2ba2cdb526777a4233eb84a3b66a Mon Sep 17 00:00:00 2001 From: Unit 193 Date: Sat, 6 Dec 2014 17:33:25 -0500 Subject: Imported Upstream version 2.99.6 --- SQLiteStudio3/guiSQLiteStudio/dblistmodel.h | 66 +++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 SQLiteStudio3/guiSQLiteStudio/dblistmodel.h (limited to 'SQLiteStudio3/guiSQLiteStudio/dblistmodel.h') 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 + +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 unsortedList; + QList dbList; + SortMode sortMode = SortMode::ConnectionOrder; + QComboBox* comboBox = nullptr; + + private slots: + void dbConnected(Db* db); + void dbDisconnected(Db* db); +}; + +#endif // DBLISTMODEL_H -- cgit v1.2.3