diff --git a/src/plasmaquick/configmodel.h b/src/plasmaquick/configmodel.h --- a/src/plasmaquick/configmodel.h +++ b/src/plasmaquick/configmodel.h @@ -85,6 +85,11 @@ Q_INVOKABLE void appendCategory(const QString &iconName, const QString &name, const QString &path, const QString &pluginName, bool visible); + // QML Engine isn't particulary smart resolving namespaces, hence fully qualified signature + Q_INVOKABLE void appendCategory(PlasmaQuick::ConfigCategory *category); + + Q_INVOKABLE void removeCategory(PlasmaQuick::ConfigCategory *category); + Q_INVOKABLE void removeCategoryAt(int index); /** * clears the model diff --git a/src/plasmaquick/configmodel.cpp b/src/plasmaquick/configmodel.cpp --- a/src/plasmaquick/configmodel.cpp +++ b/src/plasmaquick/configmodel.cpp @@ -57,6 +57,8 @@ QHash kcms; void appendCategory(ConfigCategory *c); + void removeCategory(ConfigCategory *c); + void removeCategoryAt(int index); void clear(); QVariant get(int row) const; @@ -154,6 +156,31 @@ emit q->countChanged(); } +void ConfigModelPrivate::removeCategory(ConfigCategory *c) +{ + const int index = categories.indexOf(c); + if (index > -1) { + removeCategoryAt(index); + } +} + +void ConfigModelPrivate::removeCategoryAt(int index) +{ + if (index < 0 || index >= categories.count()) { + return; + } + + q->beginRemoveRows(QModelIndex(), index, index); + + ConfigCategory *c = categories.takeAt(index); + if (c->parent() == q) { + c->deleteLater(); + } + + q->endRemoveRows(); + emit q->countChanged(); +} + QVariant ConfigModelPrivate::get(int row) const { QVariantMap value; @@ -287,6 +314,21 @@ d->appendCategory(cat); } +void ConfigModel::appendCategory(ConfigCategory *category) +{ + d->appendCategory(category); +} + +void ConfigModel::removeCategory(ConfigCategory *category) +{ + d->removeCategory(category); +} + +void ConfigModel::removeCategoryAt(int index) +{ + d->removeCategoryAt(index); +} + void ConfigModel::clear() { d->clear();