new model type for the current containment actions

qml invocable methods to add and remove entries
This commit is contained in:
Marco Martin 2013-08-23 18:52:57 +02:00
parent 0502f8f972
commit f5099f21fd
4 changed files with 96 additions and 29 deletions

View File

@ -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

View File

@ -26,7 +26,7 @@
#include <QDir>
#include <QQmlContext>
#include <QQmlEngine>
#include <QQmlComponent>
#include <KLocalizedString>
@ -35,16 +35,74 @@
#include <Plasma/PluginLoader>
CurrentContainmentActionsModel::CurrentContainmentActionsModel(Plasma::Containment *cotainment, QObject *parent)
: QStandardItemModel(parent)
{
QHash<int, QByteArray> roleNames;
roleNames[NameRole] = "name";
roleNames[PluginRole] = "plugin";
setRoleNames(roleNames);
QHash<QString, Plasma::ContainmentActions*> actions = cotainment->containmentActions();
QHashIterator<QString, Plasma::ContainmentActions*> 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<QStandardItemModel>();
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<QString, Plasma::ContainmentActions*> actions = m_containment->containmentActions();
QHashIterator<QString, Plasma::ContainmentActions*> 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()

View File

@ -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;

View File

@ -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");
}
}
}