Skip to content

Commit

Permalink
Merge branch 'master' into feature/duplicate_parameter_names_warning
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasKroes committed Dec 18, 2024
2 parents 676ec8a + 0959bdd commit da5be94
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 20 deletions.
39 changes: 31 additions & 8 deletions ManiVault/src/actions/DatasetPickerAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <QHBoxLayout>

#ifdef _DEBUG
//#define DATASET_PICKER_ACTION_VERBOSE
#endif
Expand All @@ -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),
Expand Down Expand Up @@ -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());
}
Expand All @@ -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);
}

}
43 changes: 35 additions & 8 deletions ManiVault/src/actions/DatasetPickerAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "Dataset.h"
#include "Set.h"

#include "actions/WidgetAction.h"
#include "actions/OptionAction.h"

#include "event/EventListener.h"
Expand All @@ -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:

Expand All @@ -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<mv::DatasetImpl> getCurrentDataset() const;
mv::Dataset<> getCurrentDataset() const;

/** Get the current dataset */
template<typename DatasetType>
inline mv::Dataset<DatasetType> getCurrentDataset() const
mv::Dataset<DatasetType> getCurrentDataset() const
{
return getCurrentDataset();
}
Expand Down Expand Up @@ -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<mv::DatasetImpl> pickedDataset);
void datasetPicked(mv::Dataset<> pickedDataset);

/**
* Signals that selectable datasets changed
Expand All @@ -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;
};

Expand Down
4 changes: 4 additions & 0 deletions ManiVault/src/actions/PresetsAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();
Expand Down
8 changes: 4 additions & 4 deletions ManiVault/src/private/DataManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ Dataset<DatasetImpl> DataManager::createSubsetFromSelection(const Dataset<Datase
return {};
}

Dataset<DatasetImpl> DataManager::getDataset(const QString& datasetId)
Dataset<> DataManager::getDataset(const QString& datasetId)
{
try
{
Expand All @@ -574,18 +574,18 @@ Dataset<DatasetImpl> 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 {};
}

Datasets DataManager::getAllDatasets(const std::vector<DataType>& dataTypes /*= std::vector<DataType>()*/) const
{
QVector<Dataset<DatasetImpl>> allDatasets;
QVector<Dataset<>> allDatasets;

for (const auto& dataset : _datasets) {
if (dataTypes.empty()) {
Expand Down

0 comments on commit da5be94

Please sign in to comment.