From aeff8b3a4d6f160c4bd8947ee727932c592560fc Mon Sep 17 00:00:00 2001 From: arkpar Date: Thu, 15 Jan 2015 19:21:41 +0100 Subject: [PATCH] change ProjectModel to be a context property instead of a singleton to work around issue #809 --- mix/AppContext.cpp | 10 ++++++++-- mix/qml/CodeEditorView.qml | 3 +-- mix/qml/ProjectList.qml | 17 ++++++++--------- mix/qml/ProjectModel.qml | 2 -- mix/qml/StateList.qml | 5 ++--- mix/qml/main.qml | 29 ++++++++++++++--------------- 6 files changed, 33 insertions(+), 33 deletions(-) diff --git a/mix/AppContext.cpp b/mix/AppContext.cpp index 4c8e61510..ff631208b 100644 --- a/mix/AppContext.cpp +++ b/mix/AppContext.cpp @@ -22,16 +22,17 @@ * - KeyEventManager */ +#include #include #include #include #include #include +#include #include "CodeModel.h" #include "FileIo.h" #include "ClientModel.h" #include "AppContext.h" -#include using namespace dev; using namespace dev::eth; @@ -48,7 +49,12 @@ AppContext::AppContext(QQmlApplicationEngine* _engine) m_fileIo.reset(new FileIo()); m_applicationEngine->rootContext()->setContextProperty("appContext", this); qmlRegisterType("org.ethereum.qml", 1, 0, "FileIo"); - qmlRegisterSingletonType(QUrl("qrc:/qml/ProjectModel.qml"), "org.ethereum.qml.ProjectModel", 1, 0, "ProjectModel"); + QQmlComponent projectModelComponent(m_applicationEngine, QUrl("qrc:/qml/ProjectModel.qml")); + QObject* projectModel = projectModelComponent.create(); + if (projectModelComponent.isError()) + throw std::runtime_error("Error loading ProjectModel: " + projectModelComponent.errorString().toStdString()); + QQmlEngine::setObjectOwnership(projectModel, QQmlEngine::JavaScriptOwnership); + m_applicationEngine->rootContext()->setContextProperty("projectModel", projectModel); m_applicationEngine->rootContext()->setContextProperty("codeModel", m_codeModel.get()); m_applicationEngine->rootContext()->setContextProperty("fileIo", m_fileIo.get()); diff --git a/mix/qml/CodeEditorView.qml b/mix/qml/CodeEditorView.qml index 4e95bd49c..c84d89bfe 100644 --- a/mix/qml/CodeEditorView.qml +++ b/mix/qml/CodeEditorView.qml @@ -2,7 +2,6 @@ import QtQuick 2.0 import QtQuick.Window 2.0 import QtQuick.Layouts 1.0 import QtQuick.Controls 1.0 -import org.ethereum.qml.ProjectModel 1.0 Item { @@ -40,7 +39,7 @@ Item { } Connections { - target: ProjectModel + target: projectModel onDocumentOpened: { openDocument(document); } diff --git a/mix/qml/ProjectList.qml b/mix/qml/ProjectList.qml index af3f4b155..34eaf3286 100644 --- a/mix/qml/ProjectList.qml +++ b/mix/qml/ProjectList.qml @@ -2,7 +2,6 @@ import QtQuick 2.0 import QtQuick.Window 2.0 import QtQuick.Layouts 1.0 import QtQuick.Controls 1.0 -import org.ethereum.qml.ProjectModel 1.0 Item { property bool renameMode: false; @@ -11,16 +10,16 @@ Item { Text { Layout.fillWidth: true color: "blue" - text: ProjectModel.projectData ? ProjectModel.projectData.title : "" + text: projectModel.projectData ? projectModel.projectData.title : "" horizontalAlignment: Text.AlignHCenter - visible: !ProjectModel.isEmpty; + visible: !projectModel.isEmpty; } ListView { id: projectList Layout.fillWidth: true Layout.fillHeight: true - model: ProjectModel.listModel + model: projectModel.listModel delegate: renderDelegate highlight: Rectangle { @@ -31,8 +30,8 @@ Item { clip: true onCurrentIndexChanged: { - if (currentIndex >= 0 && currentIndex < ProjectModel.listModel.count) - ProjectModel.openDocument(ProjectModel.listModel.get(currentIndex).documentId); + if (currentIndex >= 0 && currentIndex < projectModel.listModel.count) + projectModel.openDocument(projectModel.listModel.get(currentIndex).documentId); } } Menu { @@ -46,7 +45,7 @@ Item { MenuItem { text: qsTr("Delete") onTriggered: { - ProjectModel.removeDocument(projectList.model.get(projectList.currentIndex).documentId); + projectModel.removeDocument(projectList.model.get(projectList.currentIndex).documentId); } } } @@ -103,7 +102,7 @@ Item { function close(accept) { renameMode = false; if (accept) - ProjectModel.renameDocument(projectList.model.get(projectList.currentIndex).documentId, textInput.text); + projectModel.renameDocument(projectList.model.get(projectList.currentIndex).documentId, textInput.text); } } MouseArea { @@ -119,7 +118,7 @@ Item { } } Connections { - target: ProjectModel + target: projectModel onProjectLoaded: { projectList.currentIndex = 0; } diff --git a/mix/qml/ProjectModel.qml b/mix/qml/ProjectModel.qml index 5337e2780..4ffa4a8b0 100644 --- a/mix/qml/ProjectModel.qml +++ b/mix/qml/ProjectModel.qml @@ -1,5 +1,3 @@ -pragma Singleton - import QtQuick 2.0 import QtQuick.Window 2.0 import QtQuick.Layouts 1.0 diff --git a/mix/qml/StateList.qml b/mix/qml/StateList.qml index 519e533d5..cdd48017a 100644 --- a/mix/qml/StateList.qml +++ b/mix/qml/StateList.qml @@ -3,7 +3,6 @@ import QtQuick.Controls.Styles 1.1 import QtQuick.Controls 1.1 import QtQuick.Dialogs 1.1 import QtQuick.Layouts 1.1 -import org.ethereum.qml.ProjectModel 1.0 Rectangle { color: "#ededed" @@ -16,7 +15,7 @@ Rectangle { property var stateList: [] Connections { - target: ProjectModel + target: projectModel onProjectClosed: { stateListModel.clear(); } @@ -91,7 +90,7 @@ Rectangle { } function save() { - ProjectModel.saveProject(); + projectModel.saveProject(); } } diff --git a/mix/qml/main.qml b/mix/qml/main.qml index 469a6d1f4..e234d6344 100644 --- a/mix/qml/main.qml +++ b/mix/qml/main.qml @@ -5,7 +5,6 @@ import QtQuick.Dialogs 1.1 import QtQuick.Layouts 1.1 import QtQuick.Window 2.1 import CodeEditorExtensionManager 1.0 -import org.ethereum.qml.ProjectModel 1.0 ApplicationWindow { id: mainApplication @@ -101,7 +100,7 @@ ApplicationWindow { text: qsTr("&New project") shortcut: "Ctrl+N" enabled: true; - onTriggered: ProjectModel.createProject(); + onTriggered: projectModel.createProject(); } Action { @@ -109,54 +108,54 @@ ApplicationWindow { text: qsTr("&Open project") shortcut: "Ctrl+O" enabled: true; - onTriggered: ProjectModel.browseProject(); + onTriggered: projectModel.browseProject(); } Action { id: addNewJsFileAction text: qsTr("New JavaScript file") shortcut: "Ctrl+Alt+J" - enabled: !ProjectModel.isEmpty - onTriggered: ProjectModel.newJsFile(); + enabled: !projectModel.isEmpty + onTriggered: projectModel.newJsFile(); } Action { id: addNewHtmlFileAction text: qsTr("New HTML file") shortcut: "Ctrl+Alt+H" - enabled: !ProjectModel.isEmpty - onTriggered: ProjectModel.newHtmlFile(); + enabled: !projectModel.isEmpty + onTriggered: projectModel.newHtmlFile(); } Action { id: addNewContractAction text: qsTr("New contract") shortcut: "Ctrl+Alt+C" - enabled: !ProjectModel.isEmpty - onTriggered: ProjectModel.newContract(); + enabled: !projectModel.isEmpty + onTriggered: projectModel.newContract(); } Action { id: addExistingFileAction text: qsTr("Add existing file") shortcut: "Ctrl+Alt+A" - enabled: !ProjectModel.isEmpty - onTriggered: ProjectModel.addExistingFile(); + enabled: !projectModel.isEmpty + onTriggered: projectModel.addExistingFile(); } Action { id: saveAllFilesAction text: qsTr("Save all") shortcut: "Ctrl+S" - enabled: !ProjectModel.isEmpty - onTriggered: ProjectModel.saveAll(); + enabled: !projectModel.isEmpty + onTriggered: projectModel.saveAll(); } Action { id: closeProjectAction text: qsTr("Close project") shortcut: "Ctrl+W" - enabled: !ProjectModel.isEmpty - onTriggered: ProjectModel.closeProject(); + enabled: !projectModel.isEmpty + onTriggered: projectModel.closeProject(); } }