Make service records model.

This commit is contained in:
2020-06-06 21:14:24 -04:00
parent c9d742fab7
commit 0590c2bec6
3 changed files with 44 additions and 4 deletions

View File

@@ -16,3 +16,39 @@
*/
#include "sqlservicerecord.h"
#include <QSqlRecord>
SqlServiceRecord::SqlServiceRecord(QObject* parent)
{
setTable("records");
}
QHash<int, QByteArray> SqlServiceRecord::roleNames() const
{
QHash<int, QByteArray> roles;
// record() returns an empty QSqlRecord
for (int i = 0; i < this->record().count(); i ++) {
roles.insert(Qt::UserRole + i + 1, record().fieldName(i).toUtf8());
}
return roles;
}
QVariant SqlServiceRecord::data(const QModelIndex& index, int role) const
{
QVariant value = QSqlQueryModel::data(index, role);
if(role < Qt::UserRole)
{
value = QSqlQueryModel::data(index, role);
}
else
{
int columnIdx = role - Qt::UserRole - 1;
QModelIndex modelIndex = this->index(index.row(), columnIdx);
value = QSqlQueryModel::data(modelIndex, Qt::DisplayRole);
}
return value;
}