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 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
|
#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)
return objectList[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;
switch (sortMode)
{
case SortMode::Alphabetical:
objectList.sort();
break;
case SortMode::AlphabeticalCaseInsensitive:
objectList.sort(Qt::CaseInsensitive);
break;
case SortMode::LikeInDb:
break;
}
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();
}
bool DbObjListModel::getIncludeSystemObjects() const
{
return includeSystemObjects;
}
void DbObjListModel::setIncludeSystemObjects(bool value)
{
includeSystemObjects = value;
}
|