Basic JSON RESTful client fetching items from a local server at application start and adding them to the model.
This commit is contained in:
@ -6,6 +6,8 @@
|
||||
#include <QList>
|
||||
#include <QString>
|
||||
|
||||
// TODO add namespace
|
||||
|
||||
/// model data
|
||||
enum UserRoles {
|
||||
NameRole = Qt::UserRole + 1,
|
||||
@ -16,6 +18,7 @@ enum UserRoles {
|
||||
/// helper roles
|
||||
ToStringRole
|
||||
};
|
||||
|
||||
static UserRoles DEFAULT_ROLE = NameRole;
|
||||
static QList<UserRoles> USER_FACING_ROLES = {NameRole, DescriptionRole, InfoRole, AmountRole,
|
||||
FactorRole};
|
||||
|
||||
@ -193,6 +193,12 @@ void TableModel::insertItems(int startPosition,
|
||||
const QModelIndex& parentIndex) {
|
||||
const QList<ModelItemValues> valueList = JsonParser::toItemValuesList(jsonDoc, ITEM_KEY_STRING);
|
||||
|
||||
if (valueList.empty()) {
|
||||
/// don't try inserting if no values to insert
|
||||
qDebug() << "No items found in JSON document. Not adding anything...";
|
||||
return;
|
||||
}
|
||||
|
||||
insertItems(startPosition, valueList, parentIndex);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user