diff --git a/src/serviceitemmodel.cpp b/src/serviceitemmodel.cpp index c3e7cc1..d5749b4 100644 --- a/src/serviceitemmodel.cpp +++ b/src/serviceitemmodel.cpp @@ -580,9 +580,34 @@ bool ServiceItemModel::load(QUrl file) { QVariantList serviceList = array.toVariantList(); qDebug() << serviceList; + + // now lets remove all items from current list and add loaded ones + clearAll(); + + for (int i = 0; i < serviceList.length(); i++) { + // int id = serviceList + qDebug() << "*********************************"; + qDebug() << serviceList[i].toMap(); + qDebug() << "*********************************"; + + QMap item = serviceList[i].toMap(); + + insertItem(i, item.value("name").toString(), item.value("type").toString(), + item.value("background").toString(), + item.value("backgroundType").toString(), + item.value("text").toStringList(), item.value("audio").toString(), + item.value("font").toString(), item.value("fontSize").toInt()); + } + return true; } return false; } + +void ServiceItemModel::clearAll() { + for (int i = m_items.size(); i >= 0; i--) { + removeItem(i); + } +} diff --git a/src/serviceitemmodel.h b/src/serviceitemmodel.h index abc8676..8fdeae1 100644 --- a/src/serviceitemmodel.h +++ b/src/serviceitemmodel.h @@ -89,6 +89,7 @@ public: Q_INVOKABLE bool activate(int id); Q_INVOKABLE QVariantMap getItem(int index) const; Q_INVOKABLE QVariantList getItems(); + Q_INVOKABLE void clearAll(); Q_INVOKABLE bool save(QUrl file); Q_INVOKABLE bool load(QUrl file);