From f6199cc49527537bff558f799bbc091840ad767c Mon Sep 17 00:00:00 2001 From: Rens Dofferhoff Date: Wed, 8 Mar 2023 11:20:40 +0100 Subject: [PATCH] add hide dependencies to resultmenu --- Desktop/analysis/analyses.cpp | 9 +++++++++ Desktop/analysis/analyses.h | 1 + Desktop/analysis/analysis.cpp | 7 +++++++ Desktop/analysis/analysis.h | 1 + Desktop/components/JASP/Widgets/MainPage.qml | 3 ++- Desktop/html/js/analysis.js | 2 +- Desktop/html/js/collection.js | 2 ++ Desktop/html/js/image.js | 2 ++ Desktop/html/js/jaspwidgets.js | 1 + Desktop/html/js/main.js | 2 ++ Desktop/html/js/object.js | 1 + Desktop/html/js/table.js | 1 + Desktop/mainwindow.cpp | 1 + Desktop/results/resultmenumodel.cpp | 19 ++++++++++++++----- Desktop/results/resultmenumodel.h | 2 ++ Desktop/results/resultsjsinterface.h | 1 + 16 files changed, 48 insertions(+), 7 deletions(-) diff --git a/Desktop/analysis/analyses.cpp b/Desktop/analysis/analyses.cpp index b37bb65d160..7b6bf0fb136 100644 --- a/Desktop/analysis/analyses.cpp +++ b/Desktop/analysis/analyses.cpp @@ -741,6 +741,15 @@ void Analyses::showDependenciesInAnalysis(size_t analysis_id, QString optionName get(analysis_id)->showDependenciesOnQMLForObject(optionName); } +void Analyses::hideDependenciesInAnalysis(size_t analysis_id, QString optionName) +{ + //just hide it for all analysis, probably desired + for (auto& analysis : _analysisMap) + { + analysis.second->hideDependencies(); + } +} + void Analyses::analysisTitleChangedHandler(string moduleName, string oldTitle, string newTitle) { applyToAll([&](Analysis * a) diff --git a/Desktop/analysis/analyses.h b/Desktop/analysis/analyses.h index fe22faecf27..cdd9db618cf 100644 --- a/Desktop/analysis/analyses.h +++ b/Desktop/analysis/analyses.h @@ -130,6 +130,7 @@ public slots: void move(int fromIndex, int toIndex); void duplicateAnalysis(size_t id); void showDependenciesInAnalysis(size_t analysis_id, QString optionName); + void hideDependenciesInAnalysis(size_t analysis_id, QString optionName); void analysisTitleChangedHandler(std::string moduleName, std::string oldTitle, std::string newTitlesendRScriptHandler); void prepareForLanguageChange(); void languageChangedHandler(); diff --git a/Desktop/analysis/analysis.cpp b/Desktop/analysis/analysis.cpp index 7606069e488..3cd0c812fa2 100644 --- a/Desktop/analysis/analysis.cpp +++ b/Desktop/analysis/analysis.cpp @@ -574,6 +574,13 @@ void Analysis::showDependenciesOnQMLForObject(QString uniqueName) processResultsForDependenciesToBeShown(); } +void Analysis::hideDependencies() +{ + _analysisForm->setMustBe({}); + _analysisForm->setMustContain({}); +} + + bool Analysis::processResultsForDependenciesToBeShownMetaTraverser(const Json::Value & array) { if(!array.isArray()) diff --git a/Desktop/analysis/analysis.h b/Desktop/analysis/analysis.h index 8f9d88ff63c..0fd761ebfac 100644 --- a/Desktop/analysis/analysis.h +++ b/Desktop/analysis/analysis.h @@ -188,6 +188,7 @@ public slots: void setDynamicModule( Modules::DynamicModule * module); void emitDuplicationSignals(); void showDependenciesOnQMLForObject(QString uniqueName); //uniqueName is basically "name" in meta in results. + void hideDependencies(); void boundValueChangedHandler() override; void requestComputedColumnCreationHandler( const std::string & columnName) override; void requestColumnCreationHandler( const std::string & columnName, columnType colType) override { emit requestColumnCreation(columnName, this, colType); } diff --git a/Desktop/components/JASP/Widgets/MainPage.qml b/Desktop/components/JASP/Widgets/MainPage.qml index c1d709250c5..12febd35a80 100644 --- a/Desktop/components/JASP/Widgets/MainPage.qml +++ b/Desktop/components/JASP/Widgets/MainPage.qml @@ -339,7 +339,8 @@ Item function setAllUserDataFromJavascript(json) { resultsJsInterface.setAllUserDataFromJavascript(json) } function setResultsMetaFromJavascript(json) { resultsJsInterface.setResultsMetaFromJavascript(json) } function duplicateAnalysis(id) { resultsJsInterface.duplicateAnalysis(id) } - function showDependenciesInAnalysis(id, optName) { resultsJsInterface.showDependenciesInAnalysis(id, optName) } + function showDependenciesInAnalysis(id, optName) { resultsJsInterface.showDependenciesInAnalysis(id, optName); resultMenuModel.setDependenciesShown(true) } + function hideDependenciesInAnalysis(id, optName) { resultsJsInterface.hideDependenciesInAnalysis(id, optName); resultMenuModel.setDependenciesShown(false) } function showAnalysesMenu(options) { diff --git a/Desktop/html/js/analysis.js b/Desktop/html/js/analysis.js index 787f8e9313c..29499b35423 100644 --- a/Desktop/html/js/analysis.js +++ b/Desktop/html/js/analysis.js @@ -102,7 +102,7 @@ JASPWidgets.AnalysisView = JASPWidgets.View.extend({ this.model.on("SaveImage:clicked", function (options) { this.trigger("saveimage", this.model.get("id"), options) }, this); this.model.on("EditImage:clicked", function (image, options) { this.imageBeingEdited = image; this.trigger("editimage", this.model.get("id"), options) }, this); this.model.on("ShowDependencies:clicked", function (optName) { this.trigger("showDependencies", this.model.get("id"), optName) }, this); - + this.model.on("HideDependencies:clicked", function (optName) { this.trigger("hideDependencies", this.model.get("id"), optName) }, this); this.$el.on("changed:userData", this, this.onUserDataChanged); }, diff --git a/Desktop/html/js/collection.js b/Desktop/html/js/collection.js index ad1875e2bb1..49c40541175 100644 --- a/Desktop/html/js/collection.js +++ b/Desktop/html/js/collection.js @@ -88,6 +88,8 @@ JASPWidgets.collectionView = JASPWidgets.View.extend({ }, showDependenciesClicked: function() { this.model.trigger("ShowDependencies:clicked", this.model.get("name")); }, + hideDependenciesClicked: function() { this.model.trigger("HideDependencies:clicked", this.model.get("name")); }, + collapseMenuClicked: function() { this.setCollapsedState(!this.model.get('collapsed')); }, noteOptions: function() { return [ { key: this.noteBoxKey, visible: this.noteBox.visible } ]; }, hasNotes: function() { return this.model.get('name') !== null; }, diff --git a/Desktop/html/js/image.js b/Desktop/html/js/image.js index be5ac2ff40e..2e9179989eb 100644 --- a/Desktop/html/js/image.js +++ b/Desktop/html/js/image.js @@ -45,6 +45,8 @@ JASPWidgets.imageView = JASPWidgets.objectView.extend({ saveImageClicked: function() { this.model.trigger("SaveImage:clicked", { data: this.model.get("data"), width: this.model.get("width"), height: this.model.get("height"), name: this.model.get("name") }); }, editImageClicked: function() { this.model.trigger("EditImage:clicked", this.myView, { data: this.model.get("data"), width: this.model.get("width"), height: this.model.get("height"), name: this.model.get("name"), title: this.model.get("title"), type: "interactive" }); }, showDependenciesClicked: function() { this.model.trigger("ShowDependencies:clicked", this.model.get("name")); }, + hideDependenciesClicked: function() { this.model.trigger("HideDependencies:clicked", this.model.get("name")); }, + menuName: "Plot", myView: undefined, diff --git a/Desktop/html/js/jaspwidgets.js b/Desktop/html/js/jaspwidgets.js index 8f07f9180dc..afb59f26cba 100644 --- a/Desktop/html/js/jaspwidgets.js +++ b/Desktop/html/js/jaspwidgets.js @@ -967,6 +967,7 @@ JASPWidgets.Toolbar = JASPWidgets.View.extend({ hasRemove: (parent.hasRemove === undefined || parent.hasRemove()) && parent.removeMenuClicked !== undefined, hasDuplicate: (parent.hasDuplicate === undefined || parent.hasDuplicate()) && parent.duplicateMenuClicked !== undefined, hasShowDeps: (parent.hasShowDeps === undefined || parent.hasShowDeps()) && parent.showDependenciesClicked !== undefined, + hasHideDeps: true, hasCollapse: (parent.hasCollapse === undefined || parent.hasCollapse()) && parent.collapseMenuClicked !== undefined, hasLaTeXCode: (parent.hasLaTeXCode === undefined || parent.hasLaTeXCode()) && parent.latexCodeMenuClicked !== undefined, hasRemoveAllAnalyses: parent.menuName === 'All', diff --git a/Desktop/html/js/main.js b/Desktop/html/js/main.js index bea00b55e72..e305061d78b 100644 --- a/Desktop/html/js/main.js +++ b/Desktop/html/js/main.js @@ -146,6 +146,7 @@ $(document).ready(function () { window.editTitleMenuClicked = function () { window.menuObjectFunctionCaller( window.menuObject.editTitleClicked .bind(window.menuObject) ); } window.collapseMenuClicked = function () { window.menuObjectFunctionCaller( window.menuObject.collapseMenuClicked .bind(window.menuObject) ); } window.showDependenciesClicked = function () { window.menuObjectFunctionCaller( window.menuObject.showDependenciesClicked .bind(window.menuObject) ); } + window.hideDependenciesClicked = function () { window.menuObjectFunctionCaller( window.menuObject.hideDependenciesClicked .bind(window.menuObject) ); } window.duplicateMenuClicked = function () { window.menuObjectFunctionCaller( window.menuObject.duplicateMenuClicked .bind(window.menuObject) ); } window.removeMenuClicked = function () { window.menuObjectFunctionCaller( window.menuObject.removeMenuClicked .bind(window.menuObject) ); } window.citeMenuClicked = function () { window.menuObjectFunctionCaller( window.menuObject.citeMenuClicked .bind(window.menuObject), "Citations copied to clipboard" ); } @@ -471,6 +472,7 @@ $(document).ready(function () { jaspWidget.on("saveimage", function (id, options) { jasp.analysisSaveImage(id, JSON.stringify(options)) }); jaspWidget.on("editimage", function (id, options) { jasp.analysisEditImage(id, JSON.stringify(options)) }); jaspWidget.on("showDependencies", function (id, optName) { jasp.showDependenciesInAnalysis(id, optName); }); + jaspWidget.on("hideDependencies", function (id, optName) { jasp.hideDependenciesInAnalysis(id, optName); }); jaspWidget.on("analysis:remove", function (id) { jasp.removeAnalysisRequest(id); }); jaspWidget.on("analysis:duplicate", function (id) { jasp.duplicateAnalysis(id); }); jaspWidget.on("analysis:userDataChanged", function () { window.getAllUserData(); }); diff --git a/Desktop/html/js/object.js b/Desktop/html/js/object.js index b639d7e4614..509d568b59c 100644 --- a/Desktop/html/js/object.js +++ b/Desktop/html/js/object.js @@ -73,6 +73,7 @@ JASPWidgets.objectConstructor = function (results, params, ignoreEvents) { itemModel.on("SaveImage:clicked", function (options) { this.trigger("SaveImage:clicked", options) }, this.model); itemModel.on("EditImage:clicked", function (image, options) { this.trigger("EditImage:clicked", image, options) }, this.model); itemModel.on("ShowDependencies:clicked", function (options) { this.trigger("ShowDependencies:clicked", options) }, this.model); + itemModel.on("HideDependencies:clicked", function (options) { this.trigger("HideDependencies:clicked", options) }, this.model); itemModel.on("analysis:resizeStarted", function (image) { this.trigger("analysis:resizeStarted", image) }, this.model); if (!ignoreEvents) { this.listenTo(itemView, "toolbar:showMenu", function (obj, options) { this.trigger("toolbar:showMenu", obj, options); }); } diff --git a/Desktop/html/js/table.js b/Desktop/html/js/table.js index 95a14749713..f724db24904 100644 --- a/Desktop/html/js/table.js +++ b/Desktop/html/js/table.js @@ -38,6 +38,7 @@ JASPWidgets.tableView = JASPWidgets.objectView.extend({ }, showDependenciesClicked: function() { this.model.trigger("ShowDependencies:clicked", this.model.get("name")); }, + hideDependenciesClicked: function() { this.model.trigger("HideDependencies:clicked", this.model.get("name")); }, hasLaTeXCode: function () { var optLaTeXCode = this.model.get("latexCode"); diff --git a/Desktop/mainwindow.cpp b/Desktop/mainwindow.cpp index e82ab0c2caf..67e4739296d 100644 --- a/Desktop/mainwindow.cpp +++ b/Desktop/mainwindow.cpp @@ -327,6 +327,7 @@ void MainWindow::makeConnections() connect(_resultsJsInterface, &ResultsJsInterface::analysisTitleChangedInResults, _analyses, &Analyses::analysisTitleChangedInResults ); connect(_resultsJsInterface, &ResultsJsInterface::duplicateAnalysis, _analyses, &Analyses::duplicateAnalysis ); connect(_resultsJsInterface, &ResultsJsInterface::showDependenciesInAnalysis, _analyses, &Analyses::showDependenciesInAnalysis ); + connect(_resultsJsInterface, &ResultsJsInterface::hideDependenciesInAnalysis, _analyses, &Analyses::hideDependenciesInAnalysis ); connect(_resultsJsInterface, &ResultsJsInterface::showPlotEditor, _plotEditorModel, &PlotEditorModel::showPlotEditor ); connect(_resultsJsInterface, &ResultsJsInterface::resultsMetaChanged, _analyses, &Analyses::resultsMetaChanged ); connect(_resultsJsInterface, &ResultsJsInterface::allUserDataChanged, _analyses, &Analyses::allUserDataChanged ); diff --git a/Desktop/results/resultmenumodel.cpp b/Desktop/results/resultmenumodel.cpp index f10d8cab097..6be8fc304fc 100644 --- a/Desktop/results/resultmenumodel.cpp +++ b/Desktop/results/resultmenumodel.cpp @@ -48,8 +48,9 @@ void ResultMenuModel::_generateCorrectlyTranslatedResultEntries() { "hasRemoveAllAnalyses", ResultMenuEntry(tr("Remove All"), "hasRemoveAllAnalyses", "close-button.png", "") }, { "hasRefreshAllAnalyses", ResultMenuEntry(tr("Refresh All"), "hasRefreshAllAnalyses", "", "") }, { "hasShowDeps", ResultMenuEntry(tr("Show Dependencies"), "hasShowDeps", "", "window.showDependenciesClicked()") }, - { "hasExportResults", ResultMenuEntry(tr("Export Results"), "hasExportResults", "", "") } - }; + { "hasExportResults", ResultMenuEntry(tr("Export Results"), "hasExportResults", "", "") }, + { "hasHideDeps", ResultMenuEntry(tr("Hide Dependencies"), "hasHideDeps", "", "window.hideDependenciesClicked()") } + }; } QVariant ResultMenuModel::data(const QModelIndex &index, int role) const @@ -126,11 +127,19 @@ void ResultMenuModel::setOptions(QString options, QStringList selected) } else if (key == "hasShowDeps") { - if(Settings::value(Settings::DEVELOPER_MODE).toBool()) + if (Settings::value(Settings::DEVELOPER_MODE).toBool()) { //It's developerMode time! - entries.push_back(separator); - entries.push_back(entry); + if (!_dependenciesShown) + { + entries.push_back(separator); + entries.push_back(entry); + } + else + { + entries.push_back(separator); + entries.push_back(_allResultEntries.find("hasHideDeps")->second); + } } } else diff --git a/Desktop/results/resultmenumodel.h b/Desktop/results/resultmenumodel.h index 026f7f9072f..187c3cbd4a9 100644 --- a/Desktop/results/resultmenumodel.h +++ b/Desktop/results/resultmenumodel.h @@ -51,6 +51,7 @@ class ResultMenuModel : public QAbstractListModel Q_INVOKABLE void setOptions(QString, QStringList); Q_INVOKABLE QString getJSFunction(int index) const { return _resultMenuEntries.at(index).jsFunction(); } Q_INVOKABLE QString getName(int index) const { return _resultMenuEntries.at(index).name(); } + Q_INVOKABLE void setDependenciesShown(bool value) { _dependenciesShown = value; } private slots: void _generateCorrectlyTranslatedResultEntries(); @@ -59,6 +60,7 @@ private slots: std::vector _resultMenuEntries; std::map _allResultEntries; QStringList _entriesOrder; + bool _dependenciesShown = false; }; diff --git a/Desktop/results/resultsjsinterface.h b/Desktop/results/resultsjsinterface.h index 274584ce2b0..2d5b64aea58 100644 --- a/Desktop/results/resultsjsinterface.h +++ b/Desktop/results/resultsjsinterface.h @@ -81,6 +81,7 @@ class ResultsJsInterface : public QObject Q_INVOKABLE void removeAnalysisRequest( int id); Q_INVOKABLE void duplicateAnalysis( int id); Q_INVOKABLE void showDependenciesInAnalysis( int id, QString optionName); + Q_INVOKABLE void hideDependenciesInAnalysis( int id, QString optionName); Q_INVOKABLE void packageModified(); Q_INVOKABLE void refreshAllAnalyses(); Q_INVOKABLE void removeAllAnalyses();