From f5099f21fd63033d6f9e3445092f38319ce84688 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Fri, 23 Aug 2013 18:52:57 +0200 Subject: [PATCH] new model type for the current containment actions qml invocable methods to add and remove entries --- src/shell/configview.h | 2 - src/shell/containmentconfigview.cpp | 82 +++++++++++++++---- src/shell/containmentconfigview.h | 25 +++++- .../ConfigurationContainmentActions.qml | 16 ++-- 4 files changed, 96 insertions(+), 29 deletions(-) diff --git a/src/shell/configview.h b/src/shell/configview.h index a4c7ffb3c..2e8f68ff8 100644 --- a/src/shell/configview.h +++ b/src/shell/configview.h @@ -114,8 +114,6 @@ private: }; -//TODO: the config view for the containment should be a subclass -//TODO: is it possible to move this in the shell? class ConfigView : public QQuickView { Q_OBJECT diff --git a/src/shell/containmentconfigview.cpp b/src/shell/containmentconfigview.cpp index 6236dade5..d1104ef0d 100644 --- a/src/shell/containmentconfigview.cpp +++ b/src/shell/containmentconfigview.cpp @@ -26,7 +26,7 @@ #include #include #include - +#include #include @@ -35,16 +35,74 @@ #include + +CurrentContainmentActionsModel::CurrentContainmentActionsModel(Plasma::Containment *cotainment, QObject *parent) + : QStandardItemModel(parent) +{ + QHash roleNames; + roleNames[NameRole] = "name"; + roleNames[PluginRole] = "plugin"; + + setRoleNames(roleNames); + + QHash actions = cotainment->containmentActions(); + + QHashIterator i(actions); + while (i.hasNext()) { + i.next(); + + QStandardItem *item = new QStandardItem(); + item->setData(i.key(), NameRole); + item->setData(i.value()->pluginInfo().pluginName(), PluginRole); + appendRow(item); + } +} + +CurrentContainmentActionsModel::~CurrentContainmentActionsModel() +{ +} + +void CurrentContainmentActionsModel::append(const QString &action, const QString &plugin) +{ + QStandardItem *item = new QStandardItem(); + item->setData(action, NameRole); + item->setData(plugin, PluginRole); + appendRow(item); +} + +void CurrentContainmentActionsModel::update(int row, const QString &action, const QString &plugin) +{ + QModelIndex idx = index(row, 0); + + if (idx.isValid()) { + setData(idx, action, NameRole); + setData(idx, plugin, PluginRole); + } +} + +void CurrentContainmentActionsModel::remove(int row) +{ + removeRows(row, 1); +} + +void CurrentContainmentActionsModel::save() +{ + +} + + + //////////////////////////////ContainmentConfigView ContainmentConfigView::ContainmentConfigView(Plasma::Containment *cont, QWindow *parent) : ConfigView(cont, parent), m_containment(cont), m_wallpaperConfigModel(0), m_containmentActionConfigModel(0), - m_currentContainmentActionConfigModel(0), + m_currentContainmentActionsModel(0), m_currentWallpaperConfig(0), m_ownWallpaperConfig(0) { + qmlRegisterType(); engine()->rootContext()->setContextProperty("configDialog", this); setCurrentWallpaper(cont->containment()->wallpaper()); @@ -90,24 +148,12 @@ ConfigModel *ContainmentConfigView::containmentActionConfigModel() return m_containmentActionConfigModel; } -ConfigModel *ContainmentConfigView::currentContainmentActionConfigModel() +QStandardItemModel *ContainmentConfigView::currentContainmentActionsModel() { - if (!m_currentContainmentActionConfigModel) { - m_currentContainmentActionConfigModel = new ConfigModel(this); - - QHash actions = m_containment->containmentActions(); - - QHashIterator i(actions); - while (i.hasNext()) { - i.next(); - - ConfigCategory *cat = new ConfigCategory(m_currentContainmentActionConfigModel); - cat->setName(i.key()); - cat->setPluginName(i.value()->pluginInfo().name()); - m_currentContainmentActionConfigModel->appendCategory(cat); - } + if (!m_currentContainmentActionsModel) { + m_currentContainmentActionsModel = new CurrentContainmentActionsModel(m_containment, this); } - return m_currentContainmentActionConfigModel; + return m_currentContainmentActionsModel; } ConfigModel *ContainmentConfigView::wallpaperConfigModel() diff --git a/src/shell/containmentconfigview.h b/src/shell/containmentconfigview.h index bd286db78..9507681df 100644 --- a/src/shell/containmentconfigview.h +++ b/src/shell/containmentconfigview.h @@ -29,12 +29,31 @@ namespace Plasma { class ConfigPropertyMap; +class CurrentContainmentActionsModel : public QStandardItemModel +{ + Q_OBJECT + +public: + enum Roles { + NameRole = Qt::UserRole+1, + PluginRole + }; + + CurrentContainmentActionsModel(Plasma::Containment *cotainment, QObject *parent = 0); + ~CurrentContainmentActionsModel(); + + Q_INVOKABLE void append(const QString &action, const QString &plugin); + Q_INVOKABLE void update(int row, const QString &action, const QString &plugin); + Q_INVOKABLE void remove(int row); + Q_INVOKABLE void save(); +}; + //TODO: is it possible to move this in the shell? class ContainmentConfigView : public ConfigView { Q_OBJECT Q_PROPERTY(ConfigModel *containmentActionConfigModel READ containmentActionConfigModel CONSTANT) - Q_PROPERTY(ConfigModel *currentContainmentActionConfigModel READ currentContainmentActionConfigModel CONSTANT) + Q_PROPERTY(QStandardItemModel *currentContainmentActionsModel READ currentContainmentActionsModel CONSTANT) Q_PROPERTY(ConfigModel *wallpaperConfigModel READ wallpaperConfigModel CONSTANT) Q_PROPERTY(ConfigPropertyMap *wallpaperConfiguration READ wallpaperConfiguration NOTIFY wallpaperConfigurationChanged) Q_PROPERTY(QString currentWallpaper READ currentWallpaper WRITE setCurrentWallpaper NOTIFY currentWallpaperChanged) @@ -46,7 +65,7 @@ public: virtual void init(); ConfigModel *containmentActionConfigModel(); - ConfigModel *currentContainmentActionConfigModel(); + QStandardItemModel *currentContainmentActionsModel(); ConfigModel *wallpaperConfigModel(); QString currentWallpaper() const; void setCurrentWallpaper(const QString &wallpaper); @@ -65,7 +84,7 @@ private: Plasma::Containment *m_containment; ConfigModel *m_wallpaperConfigModel; ConfigModel *m_containmentActionConfigModel; - ConfigModel *m_currentContainmentActionConfigModel; + CurrentContainmentActionsModel *m_currentContainmentActionsModel; QString m_currentWallpaper; ConfigPropertyMap *m_currentWallpaperConfig; ConfigPropertyMap *m_ownWallpaperConfig; diff --git a/src/shell/qmlpackages/desktop/contents/configuration/ConfigurationContainmentActions.qml b/src/shell/qmlpackages/desktop/contents/configuration/ConfigurationContainmentActions.qml index a1ed4f29a..a646ab5c5 100644 --- a/src/shell/qmlpackages/desktop/contents/configuration/ConfigurationContainmentActions.qml +++ b/src/shell/qmlpackages/desktop/contents/configuration/ConfigurationContainmentActions.qml @@ -28,10 +28,14 @@ Item { implicitHeight: childrenRect.height Column { - anchors.centerIn: parent + anchors { + top: parent.top + topMargin: 25 + horizontalCenter: parent.horizontalCenter + } Repeater { - model: configDialog.currentContainmentActionConfigModel + model: configDialog.currentContainmentActionsModel delegate: RowLayout { width: root.width * 0.8 QtControls.Button { @@ -53,16 +57,16 @@ Item { QtControls.Button { iconName: "list-remove" width: height + onClicked: { + configDialog.currentContainmentActionsModel.remove(index) + } } } } QtControls.Button { text: "Add Action" onClicked: { - for (var i in configDialog.currentContainmentActions) { - print("AAA"+i+configDialog.currentContainmentActions[i]) - } - print(configDialog.currentContainmentActions) + configDialog.currentContainmentActionsModel.append("RightButton;NoModifier", "org.kde.contextmenu"); } } }