Add a 'visible' property/role to ConfigCategory/ConfigModel.

This gives users a bit to conditionally hide categories in
combination with a filter model.
This commit is contained in:
Eike Hein 2015-02-27 18:58:21 +01:00
parent 80c32e6d51
commit 6cc17ea25e
4 changed files with 48 additions and 1 deletions

View File

@ -1,5 +1,6 @@
/* /*
* Copyright 2013 Marco Martin <mart@kde.org> * Copyright 2013 Marco Martin <mart@kde.org>
* Copyright 2015 Eike Hein <hein@kde.org>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as * it under the terms of the GNU Library General Public License as
@ -151,6 +152,8 @@ QVariant ConfigModelPrivate::get(int row) const
} else { } else {
value["source"] = categories.at(row)->source(); value["source"] = categories.at(row)->source();
} }
value["visible"] = categories.at(row)->visible();
return value; return value;
} }
@ -163,6 +166,7 @@ ConfigModel::ConfigModel(QObject *parent)
roleNames[IconRole] = "icon"; roleNames[IconRole] = "icon";
roleNames[SourceRole] = "source"; roleNames[SourceRole] = "source";
roleNames[PluginNameRole] = "pluginName"; roleNames[PluginNameRole] = "pluginName";
roleNames[VisibleRole] = "visible";
setRoleNames(roleNames); setRoleNames(roleNames);
} }
@ -198,6 +202,8 @@ QVariant ConfigModel::data(const QModelIndex &index, int role) const
} }
case PluginNameRole: case PluginNameRole:
return d->categories.at(index.row())->pluginName(); return d->categories.at(index.row())->pluginName();
case VisibleRole:
return d->categories.at(index.row())->visible();
default: default:
return QVariant(); return QVariant();
} }
@ -219,6 +225,18 @@ void ConfigModel::appendCategory(const QString &iconName, const QString &name,
d->appendCategory(cat); d->appendCategory(cat);
} }
void ConfigModel::appendCategory(const QString &iconName, const QString &name,
const QString &path, const QString &pluginName, bool visible)
{
ConfigCategory *cat = new ConfigCategory(this);
cat->setIcon(iconName);
cat->setName(name);
cat->setSource(path);
cat->setPluginName(pluginName);
cat->setVisible(visible);
d->appendCategory(cat);
}
void ConfigModel::clear() void ConfigModel::clear()
{ {
d->clear(); d->clear();

View File

@ -1,5 +1,6 @@
/* /*
* Copyright 2013 Marco Martin <mart@kde.org> * Copyright 2013 Marco Martin <mart@kde.org>
* Copyright 2015 Eike Hein <hein@kde.org>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as * it under the terms of the GNU Library General Public License as
@ -68,7 +69,8 @@ public:
NameRole = Qt::UserRole + 1, NameRole = Qt::UserRole + 1,
IconRole, IconRole,
SourceRole, SourceRole,
PluginNameRole PluginNameRole,
VisibleRole
}; };
ConfigModel(QObject *parent = 0); ConfigModel(QObject *parent = 0);
~ConfigModel(); ~ConfigModel();
@ -80,6 +82,9 @@ public:
void appendCategory(const QString &iconName, const QString &name, void appendCategory(const QString &iconName, const QString &name,
const QString &path, const QString &pluginName); const QString &path, const QString &pluginName);
void appendCategory(const QString &iconName, const QString &name,
const QString &path, const QString &pluginName, bool visible);
/** /**
* clears the model * clears the model
**/ **/

View File

@ -1,5 +1,6 @@
/* /*
* Copyright 2013 Marco Martin <mart@kde.org> * Copyright 2013 Marco Martin <mart@kde.org>
* Copyright 2015 Eike Hein <hein@kde.org>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as * it under the terms of the GNU Library General Public License as
@ -45,6 +46,7 @@ namespace PlasmaQuick
ConfigCategory::ConfigCategory(QObject *parent) ConfigCategory::ConfigCategory(QObject *parent)
: QObject(parent) : QObject(parent)
, m_visible(true)
{ {
} }
@ -111,6 +113,21 @@ void ConfigCategory::setPluginName(const QString &name)
emit pluginNameChanged(); emit pluginNameChanged();
} }
bool ConfigCategory::visible() const
{
return m_visible;
}
void ConfigCategory::setVisible(bool visible)
{
if (m_visible == visible) {
return;
}
m_visible = visible;
emit visibleChanged();
}
} }
#include "private/moc_configcategory_p.cpp" #include "private/moc_configcategory_p.cpp"

View File

@ -1,5 +1,6 @@
/* /*
* Copyright 2013 Marco Martin <mart@kde.org> * Copyright 2013 Marco Martin <mart@kde.org>
* Copyright 2015 Eike Hein <hein@kde.org>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as * it under the terms of the GNU Library General Public License as
@ -45,6 +46,7 @@ class ConfigCategory : public QObject
Q_PROPERTY(QString icon READ icon WRITE setIcon NOTIFY iconChanged) Q_PROPERTY(QString icon READ icon WRITE setIcon NOTIFY iconChanged)
Q_PROPERTY(QString source READ source WRITE setSource NOTIFY sourceChanged) Q_PROPERTY(QString source READ source WRITE setSource NOTIFY sourceChanged)
Q_PROPERTY(QString pluginName READ pluginName WRITE setPluginName NOTIFY pluginNameChanged) Q_PROPERTY(QString pluginName READ pluginName WRITE setPluginName NOTIFY pluginNameChanged)
Q_PROPERTY(bool visible READ visible WRITE setVisible NOTIFY visibleChanged)
public: public:
ConfigCategory(QObject *parent = 0); ConfigCategory(QObject *parent = 0);
@ -62,17 +64,22 @@ public:
QString pluginName() const; QString pluginName() const;
void setPluginName(const QString &pluginName); void setPluginName(const QString &pluginName);
bool visible() const;
void setVisible(bool visible);
Q_SIGNALS: Q_SIGNALS:
void nameChanged(); void nameChanged();
void iconChanged(); void iconChanged();
void sourceChanged(); void sourceChanged();
void pluginNameChanged(); void pluginNameChanged();
void visibleChanged();
private: private:
QString m_name; QString m_name;
QString m_icon; QString m_icon;
QString m_source; QString m_source;
QString m_pluginName; QString m_pluginName;
bool m_visible;
}; };
} }