aboutsummaryrefslogtreecommitdiffstats
path: root/SQLiteStudio3/guiSQLiteStudio/dbobjlistmodel.cpp
diff options
context:
space:
mode:
authorLibravatarUnit 193 <unit193@ubuntu.com>2014-12-06 17:33:25 -0500
committerLibravatarUnit 193 <unit193@ubuntu.com>2014-12-06 17:33:25 -0500
commit7167ce41b61d2ba2cdb526777a4233eb84a3b66a (patch)
treea35c14143716e1f2c98f808c81f89426045a946f /SQLiteStudio3/guiSQLiteStudio/dbobjlistmodel.cpp
Imported Upstream version 2.99.6upstream/2.99.6
Diffstat (limited to 'SQLiteStudio3/guiSQLiteStudio/dbobjlistmodel.cpp')
-rw-r--r--SQLiteStudio3/guiSQLiteStudio/dbobjlistmodel.cpp120
1 files changed, 120 insertions, 0 deletions
diff --git a/SQLiteStudio3/guiSQLiteStudio/dbobjlistmodel.cpp b/SQLiteStudio3/guiSQLiteStudio/dbobjlistmodel.cpp
new file mode 100644
index 0000000..99d3f27
--- /dev/null
+++ b/SQLiteStudio3/guiSQLiteStudio/dbobjlistmodel.cpp
@@ -0,0 +1,120 @@
+#include "dbobjlistmodel.h"
+#include "db/db.h"
+#include <QDebug>
+#include <schemaresolver.h>
+
+DbObjListModel::DbObjListModel(QObject *parent) :
+ QAbstractListModel(parent)
+{
+}
+
+QVariant DbObjListModel::data(const QModelIndex& index, int role) const
+{
+ if (index.row() < 0 || index.row() >= objectList.size())
+ return QVariant();
+
+ if (role == Qt::DisplayRole || role == Qt::EditRole)
+ {
+ if (sortMode == SortMode::Alphabetical)
+ return objectList[index.row()];
+ else
+ return unsortedObjectList[index.row()];
+ }
+
+ return QVariant();
+}
+
+int DbObjListModel::rowCount(const QModelIndex& parent) const
+{
+ if (parent.isValid())
+ return 0;
+
+ return objectList.count();
+}
+
+QModelIndex DbObjListModel::sibling(int row, int column, const QModelIndex& idx) const
+{
+ if (!idx.isValid() || column != 0 || row >= objectList.count())
+ return QModelIndex();
+
+ return createIndex(row, 0);
+}
+
+Db* DbObjListModel::getDb() const
+{
+ return db;
+}
+
+void DbObjListModel::setDb(Db* value)
+{
+ db = value;
+ updateList();
+}
+
+DbObjListModel::SortMode DbObjListModel::getSortMode() const
+{
+ return sortMode;
+}
+
+void DbObjListModel::setSortMode(const SortMode& value)
+{
+ sortMode = value;
+ beginResetModel();
+ endResetModel();
+}
+
+DbObjListModel::ObjectType DbObjListModel::getType() const
+{
+ return type;
+}
+
+void DbObjListModel::setType(const ObjectType& value)
+{
+ type = value;
+ updateList();
+}
+
+void DbObjListModel::updateList()
+{
+ if (!db || type == ObjectType::null)
+ return;
+
+ beginResetModel();
+ SchemaResolver resolver(db);
+ resolver.setIgnoreSystemObjects(!includeSystemObjects);
+ objectList = resolver.getObjects(typeString().toLower());
+ unsortedObjectList = objectList;
+ qSort(objectList);
+ endResetModel();
+}
+
+QString DbObjListModel::typeString() const
+{
+ switch (type)
+ {
+ case ObjectType::TABLE:
+ return "TABLE";
+ case ObjectType::INDEX:
+ return "INDEX";
+ case ObjectType::TRIGGER:
+ return "TRIGGER";
+ case ObjectType::VIEW:
+ return "VIEW";
+ case ObjectType::null:
+ break;
+ }
+ return QString::null;
+}
+bool DbObjListModel::getIncludeSystemObjects() const
+{
+ return includeSystemObjects;
+}
+
+void DbObjListModel::setIncludeSystemObjects(bool value)
+{
+ includeSystemObjects = value;
+}
+
+
+
+