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 {
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
height: 480
visible: true
@ -19,13 +29,6 @@ ApplicationWindow {
TabView {
id: tabView
anchors.fill: parent
onCountChanged: {
for (var i = 0; i < tabView.count; ++i) {
if (tabView.getTab(i).title === initialTab) {
tabView.currentIndex = i;
}
}
}
Tab {
title: "style"
Column {
@ -36,7 +39,7 @@ ApplicationWindow {
model: styles
textRole: "display"
onCurrentIndexChanged: {
if (currentIndex != qtquickIndex) {
if (currentIndex !== qtquickIndex) {
widgets.currentIndex = currentIndex;
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("demo", &model->demo);
c->setContextProperty("sortedFileSystem", &model->sortedFileSystem);
c->setContextProperty("processes", &model->sortedProcesses);
c->setContextProperty("widgets", widgets);
c->setContextProperty("qtquickIndex",
QVariant(model->styles.stringList().indexOf(name)));
c->setContextProperty("initialTab", initialTab);
QRect geometry;
QWindow* window = getWindow(widgets);
if (window) {
geometry = window->geometry();
}
engine->load(QUrl(qml));
auto root = engine->rootObjects().first();
QObject* root = engine->rootObjects().first();
copyWindowGeometry(geometry, root);
root->setProperty("initialTab", initialTab);
root->setProperty("qtquickIndex",
QVariant(model->styles.stringList().indexOf(name)));
root->setProperty("processes",
QVariant::fromValue(&model->sortedProcesses));
}
#endif