Make demo.qml depend less on externally supplied values

master
Jos van den Oever 2017-09-02 01:34:32 +02:00
parent 0ea99bff54
commit f2dc67008f
2 changed files with 17 additions and 14 deletions

View File

@ -5,6 +5,16 @@ import QtQuick.Layouts 1.3
ApplicationWindow { ApplicationWindow {
id: application id: application
property string initialTab: "style"
property int qtquickIndex: 0
property var processes: ListModel { ListElement{ name: "init"} }
onInitialTabChanged: {
for (var i = 0; i < tabView.count; ++i) {
if (tabView.getTab(i).title === initialTab) {
tabView.currentIndex = i;
}
}
}
width: 640 width: 640
height: 480 height: 480
visible: true visible: true
@ -19,13 +29,6 @@ ApplicationWindow {
TabView { TabView {
id: tabView id: tabView
anchors.fill: parent anchors.fill: parent
onCountChanged: {
for (var i = 0; i < tabView.count; ++i) {
if (tabView.getTab(i).title === initialTab) {
tabView.currentIndex = i;
}
}
}
Tab { Tab {
title: "style" title: "style"
Column { Column {
@ -36,7 +39,7 @@ ApplicationWindow {
model: styles model: styles
textRole: "display" textRole: "display"
onCurrentIndexChanged: { onCurrentIndexChanged: {
if (currentIndex != qtquickIndex) { if (currentIndex !== qtquickIndex) {
widgets.currentIndex = currentIndex; widgets.currentIndex = currentIndex;
application.close(); application.close();
} }

View File

@ -79,20 +79,20 @@ void createQtQuick(const QString& name, const QString& qml, Model* model,
c->setContextProperty("styles", &model->styles); c->setContextProperty("styles", &model->styles);
c->setContextProperty("demo", &model->demo); c->setContextProperty("demo", &model->demo);
c->setContextProperty("sortedFileSystem", &model->sortedFileSystem); c->setContextProperty("sortedFileSystem", &model->sortedFileSystem);
c->setContextProperty("processes", &model->sortedProcesses);
c->setContextProperty("widgets", widgets); c->setContextProperty("widgets", widgets);
c->setContextProperty("qtquickIndex",
QVariant(model->styles.stringList().indexOf(name)));
c->setContextProperty("initialTab", initialTab);
QRect geometry; QRect geometry;
QWindow* window = getWindow(widgets); QWindow* window = getWindow(widgets);
if (window) { if (window) {
geometry = window->geometry(); geometry = window->geometry();
} }
engine->load(QUrl(qml)); engine->load(QUrl(qml));
auto root = engine->rootObjects().first(); QObject* root = engine->rootObjects().first();
copyWindowGeometry(geometry, root); copyWindowGeometry(geometry, root);
root->setProperty("initialTab", initialTab);
root->setProperty("qtquickIndex",
QVariant(model->styles.stringList().indexOf(name)));
root->setProperty("processes",
QVariant::fromValue(&model->sortedProcesses));
} }
#endif #endif