[ConfigModel] Allow programmatically adding and removing ConfigCategory
The appendCategory(ConfigCategory*) allows to add a category created by e.g. an Instantiator that can use bindings rather than fixed arguments. The removeCategory methods allow to remove a category when e.g. the model in an Instantiator resets. CCBUG: 372090 Differential Revision: https://phabricator.kde.org/D7602
This commit is contained in:
parent
d574dec0f8
commit
11e416bea6
@ -57,6 +57,8 @@ public:
|
||||
QHash<QString, KQuickAddons::ConfigModule *> kcms;
|
||||
|
||||
void appendCategory(ConfigCategory *c);
|
||||
void removeCategory(ConfigCategory *c);
|
||||
void removeCategoryAt(int index);
|
||||
void clear();
|
||||
QVariant get(int row) const;
|
||||
|
||||
@ -154,6 +156,31 @@ void ConfigModelPrivate::appendCategory(ConfigCategory *c)
|
||||
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 @@ void ConfigModel::appendCategory(const QString &iconName, const QString &name,
|
||||
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();
|
||||
|
@ -85,6 +85,11 @@ public:
|
||||
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user