migrate page loading to ConfigModel
This commit is contained in:
parent
4fc1dbef00
commit
6458522bbc
@ -121,17 +121,39 @@ QVariant ConfigModel::data(const QModelIndex& index, int role) const
|
||||
case IconRole:
|
||||
return m_categories.at(index.row())->icon();
|
||||
case SourceRole:
|
||||
return m_categories.at(index.row())->source();
|
||||
if (m_appletInterface) {
|
||||
return QUrl::fromLocalFile(m_appletInterface.data()->applet()->package().filePath("ui", m_categories.at(index.row())->source()));
|
||||
} else {
|
||||
return m_categories.at(index.row())->source();
|
||||
}
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
}
|
||||
|
||||
QVariant ConfigModel::get(int row) const
|
||||
{
|
||||
QVariantMap value;
|
||||
if (row < 0 || row >= m_categories.count()) {
|
||||
return value;
|
||||
}
|
||||
|
||||
value["name"] = m_categories.at(row)->name();
|
||||
value["icon"] = m_categories.at(row)->icon();
|
||||
if (m_appletInterface) {
|
||||
value["source"] = QUrl::fromLocalFile(m_appletInterface.data()->applet()->package().filePath("ui", m_categories.at(row)->source()));
|
||||
} else {
|
||||
value["source"] = m_categories.at(row)->source();
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
void ConfigModel::appendCategory(ConfigCategory *c)
|
||||
{
|
||||
beginInsertRows(QModelIndex(), m_categories.size(), m_categories.size());
|
||||
m_categories.append(c);
|
||||
endInsertRows();
|
||||
emit countChanged();
|
||||
}
|
||||
|
||||
void ConfigModel::clear()
|
||||
@ -142,6 +164,17 @@ void ConfigModel::clear()
|
||||
m_categories.pop_front();
|
||||
}
|
||||
endResetModel();
|
||||
emit countChanged();
|
||||
}
|
||||
|
||||
void ConfigModel::setAppletInterface(AppletInterface *interface)
|
||||
{
|
||||
m_appletInterface = interface;
|
||||
}
|
||||
|
||||
AppletInterface *ConfigModel::appletInterface() const
|
||||
{
|
||||
return m_appletInterface.data();
|
||||
}
|
||||
|
||||
QQmlListProperty<ConfigCategory> ConfigModel::categories()
|
||||
@ -220,10 +253,12 @@ ConfigView::ConfigView(AppletInterface *interface, QWindow *parent)
|
||||
|
||||
|
||||
QQmlComponent *component = new QQmlComponent(engine(), QUrl::fromLocalFile(m_appletInterface->applet()->package().filePath("ui", "config.qml")), this);
|
||||
|
||||
QObject *configObject = component->create(engine()->rootContext());
|
||||
if (configObject) {
|
||||
m_configPages = configObject->property("modules").value<QQmlListProperty<QObject> >();
|
||||
QObject *object = component->create(engine()->rootContext());
|
||||
m_configModel = qobject_cast<ConfigModel *>(object);
|
||||
if (m_configModel) {
|
||||
m_configModel->setAppletInterface(m_appletInterface);
|
||||
} else {
|
||||
delete object;
|
||||
}
|
||||
|
||||
delete component;
|
||||
@ -238,9 +273,9 @@ ConfigView::~ConfigView()
|
||||
}
|
||||
|
||||
|
||||
QQmlListProperty<QObject> ConfigView::configPages() const
|
||||
QObject *ConfigView::configModel() const
|
||||
{
|
||||
return m_configPages;
|
||||
return m_configModel;
|
||||
}
|
||||
|
||||
//To emulate Qt::WA_DeleteOnClose that QWindow doesn't have
|
||||
|
@ -65,6 +65,8 @@ class ConfigModel : public QAbstractListModel
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QQmlListProperty<ConfigCategory> categories READ categories CONSTANT)
|
||||
Q_CLASSINFO("DefaultProperty", "categories")
|
||||
Q_PROPERTY(int count READ count NOTIFY countChanged)
|
||||
|
||||
public:
|
||||
enum Roles {
|
||||
NameRole = Qt::UserRole+1,
|
||||
@ -77,8 +79,13 @@ public:
|
||||
void appendCategory(ConfigCategory *c);
|
||||
void clear();
|
||||
|
||||
virtual int rowCount(const QModelIndex &index) const;
|
||||
void setAppletInterface(AppletInterface *interface);
|
||||
AppletInterface *appletInterface() const;
|
||||
|
||||
int count() {return rowCount();}
|
||||
virtual int rowCount(const QModelIndex &index = QModelIndex()) const;
|
||||
virtual QVariant data(const QModelIndex&, int) const;
|
||||
Q_INVOKABLE QVariant get(int row) const;
|
||||
|
||||
QQmlListProperty<ConfigCategory> categories();
|
||||
|
||||
@ -87,20 +94,24 @@ public:
|
||||
static int categories_count(QQmlListProperty<ConfigCategory> *prop);
|
||||
static void categories_clear(QQmlListProperty<ConfigCategory> *prop);
|
||||
|
||||
Q_SIGNALS:
|
||||
void countChanged();
|
||||
|
||||
private:
|
||||
QList<ConfigCategory*>m_categories;
|
||||
QWeakPointer<AppletInterface> m_appletInterface;
|
||||
};
|
||||
|
||||
class ConfigView : public QQuickView
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QQmlListProperty<QObject> configPages READ configPages CONSTANT)
|
||||
Q_PROPERTY(QObject *configModel READ configModel CONSTANT)
|
||||
|
||||
public:
|
||||
ConfigView(AppletInterface *scriptEngine, QWindow *parent = 0);
|
||||
virtual ~ConfigView();
|
||||
|
||||
QQmlListProperty<QObject> configPages() const;
|
||||
QObject *configModel() const;
|
||||
|
||||
protected:
|
||||
void hideEvent(QHideEvent *ev);
|
||||
@ -108,7 +119,7 @@ protected:
|
||||
|
||||
private:
|
||||
AppletInterface *m_appletInterface;
|
||||
QQmlListProperty<QObject> m_configPages;
|
||||
ConfigModel *m_configModel;
|
||||
};
|
||||
|
||||
#endif // multiple inclusion guard
|
||||
|
@ -18,51 +18,12 @@
|
||||
|
||||
import QtQuick 2.0
|
||||
|
||||
import org.kde.plasma.core 0.1 as PlasmaCore
|
||||
import org.kde.plasma.components 0.1 as PlasmaComponents
|
||||
import org.kde.plasma.configuration 0.1
|
||||
|
||||
|
||||
QtObject {
|
||||
|
||||
property list<QtObject> modules: [
|
||||
QtObject {
|
||||
property string name: "General"
|
||||
property string icon: "plasma"
|
||||
property Component component: Component {
|
||||
Item {
|
||||
id: iconsPage
|
||||
width: childrenRect.width
|
||||
height: childrenRect.height
|
||||
implicitWidth: mainColumn.implicitWidth
|
||||
implicitHeight: pageColumn.implicitHeight
|
||||
|
||||
property alias cfg_Test: testConfigField.text
|
||||
/*ListView {
|
||||
model: ConfigModel {
|
||||
ConfigCategory {
|
||||
//property int title: Math.max(3, 9)
|
||||
title: "AAAAA"
|
||||
icon: "plasma"
|
||||
source: "kkkk"
|
||||
}
|
||||
ConfigModel {
|
||||
ConfigCategory {
|
||||
name: "General"
|
||||
icon: "plasma"
|
||||
source: "configGeneral.qml"
|
||||
}
|
||||
delegate: Text {text: title}
|
||||
}*/
|
||||
Column {
|
||||
id: pageColumn
|
||||
anchors.fill: parent
|
||||
spacing: 4
|
||||
Row {
|
||||
PlasmaComponents.Label {
|
||||
text: "Text Config value"
|
||||
}
|
||||
PlasmaComponents.TextField {
|
||||
id: testConfigField
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
47
src/shell/applets/testapplet/contents/ui/configGeneral.qml
Normal file
47
src/shell/applets/testapplet/contents/ui/configGeneral.qml
Normal file
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright 2013 Marco Martin <mart@kde.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
import QtQuick 2.0
|
||||
|
||||
import org.kde.plasma.core 0.1 as PlasmaCore
|
||||
import org.kde.plasma.components 0.1 as PlasmaComponents
|
||||
|
||||
|
||||
Item {
|
||||
id: iconsPage
|
||||
width: childrenRect.width
|
||||
height: childrenRect.height
|
||||
implicitWidth: mainColumn.implicitWidth
|
||||
implicitHeight: pageColumn.implicitHeight
|
||||
|
||||
property alias cfg_Test: testConfigField.text
|
||||
|
||||
Column {
|
||||
id: pageColumn
|
||||
anchors.fill: parent
|
||||
spacing: 4
|
||||
Row {
|
||||
PlasmaComponents.Label {
|
||||
text: "Text Config value"
|
||||
}
|
||||
PlasmaComponents.TextField {
|
||||
id: testConfigField
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -31,19 +31,15 @@ MouseArea {
|
||||
//BEGIN properties
|
||||
width: childrenRect.width
|
||||
height: childrenRect.height
|
||||
property bool current: main.sourceComponent == dataSource[modelData].component
|
||||
property bool current: main.sourceFile == model.source
|
||||
//END properties
|
||||
|
||||
//BEGIN model
|
||||
property list<QtObject> dataSource
|
||||
//END model
|
||||
|
||||
//BEGIN connections
|
||||
onClicked: {
|
||||
if (delegate.current) {
|
||||
return
|
||||
} else {
|
||||
main.sourceComponent = dataSource[modelData].component
|
||||
main.sourceFile = model.source
|
||||
root.restoreConfig()
|
||||
}
|
||||
}
|
||||
@ -64,14 +60,14 @@ MouseArea {
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
width: theme.IconSizeHuge
|
||||
height: width
|
||||
source: dataSource[modelData].icon
|
||||
source: model.icon
|
||||
}
|
||||
PlasmaComponents.Label {
|
||||
anchors {
|
||||
left: parent.left
|
||||
right: parent.right
|
||||
}
|
||||
text: dataSource[modelData].name
|
||||
text: model.name
|
||||
wrapMode: Text.Wrap
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
}
|
||||
|
@ -34,24 +34,14 @@ Rectangle {
|
||||
//END properties
|
||||
|
||||
//BEGIN model
|
||||
property list<QtObject> globalConfigPages: [
|
||||
QtObject {
|
||||
property string name: "Keyboard shortcuts"
|
||||
property string icon: "preferences-desktop-keyboard"
|
||||
property Component component: Component {
|
||||
Item {
|
||||
id: iconsPage
|
||||
width: childrenRect.width
|
||||
height: childrenRect.height
|
||||
|
||||
PlasmaComponents.Button {
|
||||
iconSource: "settings"
|
||||
text: "None"
|
||||
}
|
||||
}
|
||||
}
|
||||
property ConfigModel globalConfigModel: ConfigModel {
|
||||
id: globalConfigModel
|
||||
ConfigCategory {
|
||||
name: "Keyboard shortcuts"
|
||||
icon: "preferences-desktop-keyboard"
|
||||
source: "ConfigurationShortcuts.qml"
|
||||
}
|
||||
]
|
||||
}
|
||||
//END model
|
||||
|
||||
//BEGIN functions
|
||||
@ -75,10 +65,10 @@ Rectangle {
|
||||
|
||||
//BEGIN connections
|
||||
Component.onCompleted: {
|
||||
if (configDialog.configPages.length > 0) {
|
||||
main.sourceComponent = configDialog.configPages[0].component
|
||||
if (configDialog.configModel.count > 0) {
|
||||
main.sourceFile = configDialog.configModel.get(0).source
|
||||
} else {
|
||||
main.sourceComponent = globalConfigPages[0].component
|
||||
main.sourceFile = globalConfigModel.get(0).source
|
||||
}
|
||||
root.restoreConfig()
|
||||
root.width = mainColumn.implicitWidth
|
||||
@ -110,7 +100,7 @@ Rectangle {
|
||||
top: parent.top
|
||||
bottom: parent.bottom
|
||||
}
|
||||
visible: configDialog.configPages.length > 0 && globalConfigPages.length > 0
|
||||
visible: configDialog.configModel.count > 0 || globalConfigModel.count > 0
|
||||
width: visible ? 100 : 0
|
||||
implicitWidth: width
|
||||
implicitHeight: theme.defaultFont.mSize.height * 12
|
||||
@ -144,16 +134,12 @@ Rectangle {
|
||||
id: categoriesColumn
|
||||
width: parent.width
|
||||
Repeater {
|
||||
model: configDialog.configPages.length
|
||||
delegate: ConfigCategoryDelegate {
|
||||
dataSource: configDialog.configPages
|
||||
}
|
||||
model: configDialog.configModel
|
||||
delegate: ConfigCategoryDelegate {}
|
||||
}
|
||||
Repeater {
|
||||
model: globalConfigPages.length
|
||||
delegate: ConfigCategoryDelegate {
|
||||
dataSource: globalConfigPages
|
||||
}
|
||||
model: globalConfigModel
|
||||
delegate: ConfigCategoryDelegate {}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -178,9 +164,9 @@ Rectangle {
|
||||
PlasmaComponents.PageStack {
|
||||
id: main
|
||||
anchors.fill: parent
|
||||
property Component sourceComponent
|
||||
onSourceComponentChanged: {
|
||||
replace(sourceComponent)
|
||||
property string sourceFile
|
||||
onSourceFileChanged: {
|
||||
replace(Qt.resolvedUrl(sourceFile))
|
||||
root.width = mainColumn.implicitWidth
|
||||
root.height = mainColumn.implicitHeight
|
||||
}
|
||||
|
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright 2013 Marco Martin <mart@kde.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
import QtQuick 2.0
|
||||
import org.kde.plasma.components 0.1 as PlasmaComponents
|
||||
|
||||
|
||||
Item {
|
||||
id: iconsPage
|
||||
width: childrenRect.width
|
||||
height: childrenRect.height
|
||||
|
||||
PlasmaComponents.Button {
|
||||
iconSource: "settings"
|
||||
text: "None"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user