From cdb4e84bfbf182250a50b2860efd889df7949068 Mon Sep 17 00:00:00 2001 From: yann300 Date: Tue, 10 Mar 2015 19:24:20 +0100 Subject: [PATCH] - Clear code model when project changes (#1262). - Small changes. --- mix/CodeModel.h | 2 ++ mix/qml/ProjectModel.qml | 10 +++++++++- mix/qml/StateListModel.qml | 5 +++++ mix/qml/js/ProjectModel.js | 1 - 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/mix/CodeModel.h b/mix/CodeModel.h index de9a07bab..92111996c 100644 --- a/mix/CodeModel.h +++ b/mix/CodeModel.h @@ -164,6 +164,8 @@ public: /// Find a contract by document id /// @returns CompiledContract object or null if not found Q_INVOKABLE CompiledContract* contractByDocumentId(QString _documentId) const; + /// Reset code model + Q_INVOKABLE void reset() { reset(QVariantMap()); } signals: /// Emited on compilation state change diff --git a/mix/qml/ProjectModel.qml b/mix/qml/ProjectModel.qml index d3b4070aa..cca2c834b 100644 --- a/mix/qml/ProjectModel.qml +++ b/mix/qml/ProjectModel.qml @@ -64,7 +64,7 @@ Item { Connections { target: appContext onAppLoaded: { - if (projectSettings.lastProjectPath) + if (projectSettings.lastProjectPath && projectSettings.lastProjectPath !== "") projectModel.loadProject(projectSettings.lastProjectPath) } } @@ -130,6 +130,14 @@ Item { id: projectStateListModel } + Connections + { + target: projectModel + onProjectClosed: { + projectSettings.lastProjectPath = ""; + } + } + Settings { id: projectSettings property string lastProjectPath; diff --git a/mix/qml/StateListModel.qml b/mix/qml/StateListModel.qml index 61307826c..6deeb9790 100644 --- a/mix/qml/StateListModel.qml +++ b/mix/qml/StateListModel.qml @@ -134,6 +134,7 @@ Item { onProjectClosed: { stateListModel.clear(); stateList = []; + codeModel.reset(); } onProjectLoading: stateListModel.loadStatesFromProject(projectData); onProjectSaving: { @@ -148,6 +149,7 @@ Item { state.title = qsTr("Default"); projectData.states = [ state ]; projectData.defaultStateIndex = 0; + stateListModel.loadStatesFromProject(projectData); } } @@ -264,6 +266,7 @@ Item { defaultStateIndex--; save(); + } function save() { @@ -284,6 +287,8 @@ Item { else defaultStateIndex = 0; var items = projectData.states; + stateListModel.clear(); + stateList = []; for(var i = 0; i < items.length; i++) { var item = fromPlainStateItem(items[i]); stateListModel.append(item); diff --git a/mix/qml/js/ProjectModel.js b/mix/qml/js/ProjectModel.js index d308119ae..d4e3a8417 100644 --- a/mix/qml/js/ProjectModel.js +++ b/mix/qml/js/ProjectModel.js @@ -105,7 +105,6 @@ function loadProject(path) { contractSources[doc.documentId] = fileIo.readFile(doc.path); } codeModel.reset(contractSources); - } function addFile(fileName) {