8#include "configmodel.h"
9#include "Plasma/Applet"
10#include "Plasma/Containment"
11#include "configcategory_p.h"
12#include "configview.h"
14#include "sharedqmlengine.h"
18#include <QQmlComponent>
23#include <KLocalizedString>
24#include <KQuickConfigModule>
25#include <KQuickConfigModuleLoader>
27#include <Plasma/Corona>
28#include <Plasma/PluginLoader>
29#include <kquickconfigmoduleloader.h>
35class ConfigModelPrivate
38 ConfigModelPrivate(ConfigModel *model);
39 ~ConfigModelPrivate();
46 void appendCategory(ConfigCategory *c);
47 void removeCategory(ConfigCategory *c);
48 void removeCategoryAt(
int index);
58ConfigModelPrivate::ConfigModelPrivate(ConfigModel *model)
63ConfigModelPrivate::~ConfigModelPrivate()
69 ConfigModel *model = qobject_cast<ConfigModel *>(prop->object);
70 if (!model || index >= model->d->categories.count() || index < 0) {
73 return model->d->categories.at(index);
79 ConfigModel *model = qobject_cast<ConfigModel *>(prop->object);
84 if (o->parent() == prop->object) {
85 o->setParent(
nullptr);
88 o->setParent(prop->object);
89 model->d->appendCategory(o);
94 ConfigModel *model = qobject_cast<ConfigModel *>(prop->object);
96 return model->d->categories.count();
104 ConfigModel *model = qobject_cast<ConfigModel *>(prop->object);
112void ConfigModelPrivate::clear()
114 q->beginResetModel();
115 while (!categories.isEmpty()) {
116 categories.first()->setParent(
nullptr);
117 categories.pop_front();
120 Q_EMIT q->countChanged();
123void ConfigModelPrivate::appendCategory(ConfigCategory *c)
129 q->beginInsertRows(
QModelIndex(), categories.size(), categories.size());
130 categories.append(c);
132 auto emitChange = [
this, c] {
133 const int row = categories.indexOf(c);
136 Q_EMIT q->dataChanged(modelIndex, modelIndex);
147 Q_EMIT q->countChanged();
150void ConfigModelPrivate::removeCategory(ConfigCategory *c)
152 const int index = categories.indexOf(c);
154 removeCategoryAt(index);
158void ConfigModelPrivate::removeCategoryAt(
int index)
160 if (index < 0 || index >= categories.count()) {
166 ConfigCategory *c = categories.takeAt(index);
167 if (c->parent() == q) {
172 Q_EMIT q->countChanged();
175QVariant ConfigModelPrivate::get(
int row)
const
178 if (row < 0 || row >= categories.count()) {
182 value[QStringLiteral(
"name")] = categories.at(row)->name();
183 value[QStringLiteral(
"icon")] = categories.at(row)->icon();
184 value[QStringLiteral(
"pluginName")] = categories.at(row)->pluginName();
185 value[QStringLiteral(
"source")] = q->
data(q->index(row, 0), ConfigModel::SourceRole);
186 value[QStringLiteral(
"includeMargins")] = categories.at(row)->includeMargins();
187 value[QStringLiteral(
"visible")] = categories.at(row)->visible();
188 value[QStringLiteral(
"kcm")] = q->data(q->index(row, 0), ConfigModel::KCMRole);
193ConfigModel::ConfigModel(
QObject *parent)
195 , d(new ConfigModelPrivate(this))
199ConfigModel::~ConfigModel()
204int ConfigModel::rowCount(
const QModelIndex &index)
const
209 return d->categories.count();
214 if (index.
row() < 0 || index.
row() >= d->categories.count()) {
219 return d->categories.at(index.
row())->name();
221 return d->categories.at(index.
row())->icon();
223 const QString source = d->categories.
at(index.
row())->source();
226 return d->appletInterface.data()->fileUrl(
"ui", source);
232 return d->categories.at(index.
row())->pluginName();
233 case IncludeMarginsRole:
234 return d->categories.at(index.
row())->includeMargins();
236 return d->categories.at(index.
row())->visible();
238 const QString pluginName = d->categories.
at(index.
row())->pluginName();
244 if (d->kcms.contains(pluginName)) {
247 auto parent =
const_cast<ConfigModel *
>(
this);
249 auto cmResult = KQuickConfigModuleLoader::loadModule(
KPluginMetaData(pluginName), parent, QVariantList(), engine->engine());
256 d->kcms[pluginName] = cm;
259 qCDebug(LOG_PLASMAQUICK) <<
"Error loading KCM:" << cmResult.errorText;
273 {SourceRole,
"source"},
274 {PluginNameRole,
"pluginName"},
275 {IncludeMarginsRole,
"includeMargins"},
276 {VisibleRole,
"visible"},
288 ConfigCategory *cat =
new ConfigCategory(
this);
289 cat->setIcon(iconName);
291 cat->setSource(path);
292 cat->setPluginName(pluginName);
293 d->appendCategory(cat);
296void ConfigModel::appendCategory(
const QString &iconName,
const QString &name,
const QString &path,
const QString &pluginName,
bool visible)
298 ConfigCategory *cat =
new ConfigCategory(
this);
299 cat->setIcon(iconName);
301 cat->setSource(path);
302 cat->setPluginName(pluginName);
303 cat->setVisible(visible);
304 d->appendCategory(cat);
307void ConfigModel::appendCategory(ConfigCategory *category)
309 d->appendCategory(category);
312void ConfigModel::removeCategory(ConfigCategory *category)
314 d->removeCategory(category);
317void ConfigModel::removeCategoryAt(
int index)
319 d->removeCategoryAt(index);
322void ConfigModel::clear()
329 d->appletInterface = interface;
334 return d->appletInterface.data();
341 ConfigModelPrivate::categories_append,
342 ConfigModelPrivate::categories_count,
343 ConfigModelPrivate::categories_at,
344 ConfigModelPrivate::categories_clear);
349#include "moc_configmodel.cpp"
An object that instantiates an entire QML context, with its own declarative engine.
The EdgeEventForwarder class This class forwards edge events to be replayed within the given margin T...
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QQmlContext * contextForObject(const QObject *object)
void setContextForObject(QObject *object, QQmlContext *context)
const QChar at(qsizetype position) const const
bool endsWith(QChar c, Qt::CaseSensitivity cs) const const
bool isEmpty() const const
bool startsWith(QChar c, Qt::CaseSensitivity cs) const const
QVariant fromValue(T &&value)