Commit 17bf3139 authored by Martin Straka's avatar Martin Straka

Added set databox model data from sql query

parent b7442f19
......@@ -22,6 +22,7 @@
*/
#include <QQmlEngine> /* qmlRegisterType */
#include <QSqlRecord>
#include "src/models/databoxmodel.h"
......@@ -204,6 +205,39 @@ void DataboxListModel::addEntry(const DataboxModelEntry &data)
endInsertRows();
}
int DataboxListModel::setQuery(QSqlQuery &query, const QString &dbId,
bool isAppend)
{
int databoxCnt = 0;
if (query.record().count() != 3) {
return databoxCnt;
}
beginResetModel();
if (!isAppend) {
m_databoxes.clear();
}
query.first();
while (query.isActive() && query.isValid()) {
if (dbId != query.value(0).toString()) {
// some model items are not available in local database
m_databoxes.append(DataboxModelEntry(
query.value(0).toString(), QString(),
query.value(1).toString(), query.value(2).toString(),
QString(), QString(), QString()));
databoxCnt++;
}
query.next();
}
endResetModel();
return databoxCnt;
}
Qt::ItemFlags DataboxListModel::flags(const QModelIndex &index) const
{
return QAbstractListModel::flags(index);
......
......@@ -25,6 +25,7 @@
#define _DATABOXMODEL_H_
#include <QAbstractListModel>
#include <QSqlQuery>
class DataboxModelEntry {
public:
......@@ -134,6 +135,17 @@ public:
*/
void addEntry(const DataboxModelEntry &data);
/*!
* @brief Sets the content of the model according to the supplied query.
*
* @param[in,out] query SQL query result.
* @param[in] dbId Account databox ID.
* @param[in] isAppend True if we can append other queries into model.
* False means that model will clear before append.
* @return Number of items in the model.
*/
int setQuery(QSqlQuery &query, const QString &dbId, bool isAppend);
/*!
* @brief Returns item flags for given index.
*
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment