Added support for database maintenance. Added core plugin.

This commit is contained in:
2015-11-13 15:11:47 +01:00
parent 1264b2547a
commit 7c90c66468
14 changed files with 278 additions and 34 deletions
+11 -30
View File
@@ -20,33 +20,6 @@ public:
virtual ~AutoTableModel() {}
private:
class Comparator
{
public:
Comparator(const QString &property, Qt::SortOrder order)
{
m_property = property;
m_order = order;
}
bool operator()(QSharedPointer<T> entA, QSharedPointer<T> entB) {
QObject *rawEntityA = (QObject*)entA.data();
QObject *rawEntityB = (QObject*)entB.data();
if (m_order == Qt::AscendingOrder) {
return rawEntityA->property(m_property.toStdString().c_str()) < rawEntityB->property(m_property.toStdString().c_str());
} else {
return rawEntityB->property(m_property.toStdString().c_str()) < rawEntityA->property(m_property.toStdString().c_str());
}
}
private:
QString m_property;
Qt::SortOrder m_order;
};
// QAbstractItemModel interface
public:
int rowCount(const QModelIndex &parent = QModelIndex()) const
@@ -117,10 +90,18 @@ public:
}
beginResetModel();
QObject *rawEntity = (QObject*)m_list.at(0).data();
Comparator c(rawEntity->metaObject()->property(column + 1).name(), order);
std::sort(m_list.begin(), m_list.end(), c);
QObject *rawEntity = (QObject*)m_list.at(0).data();
const char *prop = rawEntity->metaObject()->property(column + 1).name();
std::sort(m_list.begin(), m_list.end(), [prop, order](QSharedPointer<T> entA, QSharedPointer<T> entB) -> bool {
if (order == Qt::AscendingOrder) {
return ((QObject*)entA.data())->property(prop) < ((QObject*)entB.data())->property(prop);
} else {
return ((QObject*)entB.data())->property(prop) < ((QObject*)entA.data())->property(prop);
}
});
endResetModel();
}