Added support for database maintenance. Added core plugin.
This commit is contained in:
+11
-30
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user