From 63037a14df85e51d3b127e5fc86925ed11a3f2cc Mon Sep 17 00:00:00 2001 From: Thomas Kroes Date: Wed, 18 Dec 2024 11:39:53 +0100 Subject: [PATCH 1/2] Silent warning (console) when a dataset is not found by the data manager --- ManiVault/src/private/DataManager.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ManiVault/src/private/DataManager.cpp b/ManiVault/src/private/DataManager.cpp index 641d3d39e..9b48dd7c8 100644 --- a/ManiVault/src/private/DataManager.cpp +++ b/ManiVault/src/private/DataManager.cpp @@ -556,7 +556,7 @@ Dataset DataManager::createSubsetFromSelection(const Dataset DataManager::getDataset(const QString& datasetId) +Dataset<> DataManager::getDataset(const QString& datasetId) { try { @@ -574,10 +574,10 @@ Dataset DataManager::getDataset(const QString& datasetId) } catch (std::exception& e) { - exceptionMessageBox("Unable to get set from data manager", e); + qDebug() << QString("Unable to get set from data manager: %1").arg(e.what()); } catch (...) { - exceptionMessageBox("Unable to get set from data manager"); + qDebug() << "Unable to get set from data manager due to unhandled exception"; } return {}; @@ -585,7 +585,7 @@ Dataset DataManager::getDataset(const QString& datasetId) Datasets DataManager::getAllDatasets(const std::vector& dataTypes /*= std::vector()*/) const { - QVector> allDatasets; + QVector> allDatasets; for (const auto& dataset : _datasets) { if (dataTypes.empty()) { From 9d68da641edde58e4eebab922e62594667bd99c5 Mon Sep 17 00:00:00 2001 From: Thomas Kroes Date: Wed, 18 Dec 2024 11:47:18 +0100 Subject: [PATCH 2/2] Add DatasetPickerAction API to temporarily disable value serialization --- ManiVault/src/actions/DatasetPickerAction.cpp | 39 +++++++++++++---- ManiVault/src/actions/DatasetPickerAction.h | 43 +++++++++++++++---- ManiVault/src/actions/PresetsAction.cpp | 4 ++ 3 files changed, 70 insertions(+), 16 deletions(-) diff --git a/ManiVault/src/actions/DatasetPickerAction.cpp b/ManiVault/src/actions/DatasetPickerAction.cpp index 191efbf41..e56c99dbd 100644 --- a/ManiVault/src/actions/DatasetPickerAction.cpp +++ b/ManiVault/src/actions/DatasetPickerAction.cpp @@ -3,13 +3,9 @@ // Copyright (C) 2023 BioVault (Biomedical Visual Analytics Unit LUMC - TU Delft) #include "DatasetPickerAction.h" -#include "Application.h" -#include "DataHierarchyItem.h" #include "event/Event.h" -#include - #ifdef _DEBUG //#define DATASET_PICKER_ACTION_VERBOSE #endif @@ -18,6 +14,8 @@ using namespace mv::util; namespace mv::gui { +bool DatasetPickerAction::noValueSerialization = false; + DatasetPickerAction::DatasetPickerAction(QObject* parent, const QString& title) : OptionAction(parent, title), _populationMode(AbstractDatasetsModel::PopulationMode::Automatic), @@ -306,7 +304,10 @@ void DatasetPickerAction::fromVariantMap(const QVariantMap& variantMap) { WidgetAction::fromVariantMap(variantMap); - variantMapMustContain(variantMap, "Value"); + if (isValueSerializationDisabled()) + return; + + variantMapMustContain(variantMap, "Value"); setCurrentDataset(variantMap["Value"].toString()); } @@ -315,11 +316,33 @@ QVariantMap DatasetPickerAction::toVariantMap() const { QVariantMap variantMap = WidgetAction::toVariantMap(); - variantMap.insert({ - { "Value", getCurrentDatasetId() } - }); + if (!isValueSerializationDisabled()) { + variantMap.insert({ + { "Value", getCurrentDatasetId() } + }); + } return variantMap; } +bool DatasetPickerAction::isValueSerializationDisabled() +{ + return noValueSerialization; +} + +void DatasetPickerAction::setValueSerializationDisabled(bool valueSerializationDisabled) +{ + noValueSerialization = valueSerializationDisabled; +} + +void DatasetPickerAction::disableValueSerialization() +{ + setValueSerializationDisabled(true); +} + +void DatasetPickerAction::enableValueSerialization() +{ + setValueSerializationDisabled(false); +} + } diff --git a/ManiVault/src/actions/DatasetPickerAction.h b/ManiVault/src/actions/DatasetPickerAction.h index 6f63cbbfe..b884654c0 100644 --- a/ManiVault/src/actions/DatasetPickerAction.h +++ b/ManiVault/src/actions/DatasetPickerAction.h @@ -7,7 +7,6 @@ #include "Dataset.h" #include "Set.h" -#include "actions/WidgetAction.h" #include "actions/OptionAction.h" #include "event/EventListener.h" @@ -22,14 +21,22 @@ namespace mv::gui { /** * Dataset picker action class * - * Action class for picking a dataset from a list + * For picking a dataset from a list * Automatically removes items when datasets are removed and renamed * * @author Thomas Kroes */ class CORE_EXPORT DatasetPickerAction : public OptionAction { -Q_OBJECT + Q_OBJECT + +public: + + /** Helper class for scoped value serialization disabling */ + struct CORE_EXPORT ValueSerializationDisabler { + ValueSerializationDisabler() { disableValueSerialization(); } + virtual ~ValueSerializationDisabler() { enableValueSerialization(); } + }; public: @@ -56,16 +63,16 @@ Q_OBJECT /** * Set datasets filter function - * @param datasetsFilterFunction Filter lambda (triggered when datasets are added and/or removed from the global datasets model) + * @param filterFunction Filter lambda (triggered when datasets are added and/or removed from the global datasets model) */ void setFilterFunction(const DatasetsFilterModel::FilterFunction& filterFunction); /** Get the current dataset */ - mv::Dataset getCurrentDataset() const; + mv::Dataset<> getCurrentDataset() const; /** Get the current dataset */ template - inline mv::Dataset getCurrentDataset() const + mv::Dataset getCurrentDataset() const { return getCurrentDataset(); } @@ -148,13 +155,31 @@ Q_OBJECT */ QVariantMap toVariantMap() const override; + /** + * Get whether value serialization is disabled + * @return Boolean determining whether value serialization is disabled + */ + static bool isValueSerializationDisabled(); + + /** + * Set value serialization to \p valueSerializationDisabled + * @param valueSerializationDisabled Boolean determining whether value serialization is disabled + */ + static void setValueSerializationDisabled(bool valueSerializationDisabled = true); + + /** Disables serialization */ + static void disableValueSerialization(); + + /** Disables serialization */ + static void enableValueSerialization(); + signals: /** * Signals that a dataset has been picked - * @param Smart pointer to picked dataset + * @param pickedDataset Smart pointer to picked dataset */ - void datasetPicked(mv::Dataset pickedDataset); + void datasetPicked(mv::Dataset<> pickedDataset); /** * Signals that selectable datasets changed @@ -176,6 +201,8 @@ Q_OBJECT bool _blockDatasetsChangedSignal; /** Boolean determining whether the DatasetPickerAction::datasetsChanged(...) signal may be engaged in reponse to change in the DatasetPickerAction#_filterModel */ QStringList _currentDatasetsIds; /** Keep a list of current datasets identifiers so that we can avoid unnecessary emits of the DatasetPickerAction::datasetsChanged(...) signal */ + static bool noValueSerialization; /** Prevent the value from being serialized (used by preset serialization) */ + friend class AbstractActionsManager; }; diff --git a/ManiVault/src/actions/PresetsAction.cpp b/ManiVault/src/actions/PresetsAction.cpp index f0697a054..b943ca14f 100644 --- a/ManiVault/src/actions/PresetsAction.cpp +++ b/ManiVault/src/actions/PresetsAction.cpp @@ -196,6 +196,8 @@ void PresetsAction::loadPreset(const QString& name) emit presetAboutToBeLoaded(name); { + const DatasetPickerAction::ValueSerializationDisabler valueSerializationDisabler; + _sourceAction->fromVariantMap(_presets[name].toMap()); } emit presetLoaded(name); @@ -210,6 +212,8 @@ void PresetsAction::savePreset(const QString& name) if (name.isEmpty()) return; + const DatasetPickerAction::ValueSerializationDisabler valueSerializationDisabler; + auto sourceActionVariantMap = _sourceAction->toVariantMap(); sourceActionVariantMap["DateTime"] = QDateTime::currentDateTime();