Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
213 changes: 191 additions & 22 deletions src/DatasetsAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ DatasetsAction::DatasetsAction(QObject* parent, const QString& title) :
GroupAction(parent, title),
_scatterplotPlugin(dynamic_cast<ScatterplotPlugin*>(parent->parent())),
_positionDatasetPickerAction(this, "Position"),
_colorDatasetPickerAction(this, "Color")
_colorDatasetPickerAction(this, "Color"),
_pointSizeDatasetPickerAction(this, "Point size"),
_pointOpacityDatasetPickerAction(this, "Point opacity")
{
setIconByName("database");
setToolTip("Manage loaded datasets for position and color");
Expand All @@ -23,36 +25,32 @@ DatasetsAction::DatasetsAction(QObject* parent, const QString& title) :

addAction(&_positionDatasetPickerAction);
addAction(&_colorDatasetPickerAction);
addAction(&_pointSizeDatasetPickerAction);
addAction(&_pointOpacityDatasetPickerAction);

_positionDatasetPickerAction.setFilterFunction([this](mv::Dataset<DatasetImpl> dataset) -> bool {
return dataset->getDataType() == PointType;
});

_colorDatasetPickerAction.setFilterFunction([this](mv::Dataset<DatasetImpl> dataset) -> bool {
return (dataset->getDataType() == PointType || dataset->getDataType() == ColorType || dataset->getDataType() == ClusterType);
});

_positionDatasetPickerAction.setDefaultWidgetFlag(OptionAction::Clearable);
_colorDatasetPickerAction.setDefaultWidgetFlag(OptionAction::Clearable);
_pointSizeDatasetPickerAction.setDefaultWidgetFlag(OptionAction::Clearable);
_pointOpacityDatasetPickerAction.setDefaultWidgetFlag(OptionAction::Clearable);

auto scatterplotPlugin = dynamic_cast<ScatterplotPlugin*>(parent->parent());

Q_ASSERT(scatterplotPlugin);

if (scatterplotPlugin == nullptr)
return;

setupDatasetPickerActions(scatterplotPlugin);

connect(&_positionDatasetPickerAction, &DatasetPickerAction::datasetPicked, [this, scatterplotPlugin](Dataset<DatasetImpl> pickedDataset) -> void {
scatterplotPlugin->getPositionDataset() = pickedDataset;
_colorDatasetPickerAction.invalidateFilter();
_pointSizeDatasetPickerAction.invalidateFilter();
_pointOpacityDatasetPickerAction.invalidateFilter();
});

connect(&scatterplotPlugin->getPositionDataset(), &Dataset<Points>::changed, this, [this](DatasetImpl* dataset) -> void {
_positionDatasetPickerAction.setCurrentDataset(dataset);
});

connect(&_colorDatasetPickerAction, &DatasetPickerAction::datasetPicked, [this, scatterplotPlugin](Dataset<DatasetImpl> pickedDataset) -> void {
scatterplotPlugin->getSettingsAction().getColoringAction().setCurrentColorDataset(pickedDataset);
});

connect(&scatterplotPlugin->getSettingsAction().getColoringAction(), &ColoringAction::currentColorDatasetChanged, this, [this](Dataset<DatasetImpl> currentColorDataset) -> void {
_colorDatasetPickerAction.setCurrentDataset(currentColorDataset);
});
_colorDatasetPickerAction.invalidateFilter();
_pointSizeDatasetPickerAction.invalidateFilter();
_pointOpacityDatasetPickerAction.invalidateFilter();
}

void DatasetsAction::connectToPublicAction(WidgetAction* publicAction, bool recursive)
Expand All @@ -67,6 +65,8 @@ void DatasetsAction::connectToPublicAction(WidgetAction* publicAction, bool recu
if (recursive) {
actions().connectPrivateActionToPublicAction(&_positionDatasetPickerAction, &publicDatasetsAction->getPositionDatasetPickerAction(), recursive);
actions().connectPrivateActionToPublicAction(&_colorDatasetPickerAction, &publicDatasetsAction->getColorDatasetPickerAction(), recursive);
actions().connectPrivateActionToPublicAction(&_pointSizeDatasetPickerAction, &publicDatasetsAction->getPointSizeDatasetPickerAction(), recursive);
actions().connectPrivateActionToPublicAction(&_pointOpacityDatasetPickerAction, &publicDatasetsAction->getPointOpacityDatasetPickerAction(), recursive);
}

GroupAction::connectToPublicAction(publicAction, recursive);
Expand All @@ -80,6 +80,8 @@ void DatasetsAction::disconnectFromPublicAction(bool recursive)
if (recursive) {
actions().disconnectPrivateActionFromPublicAction(&_positionDatasetPickerAction, recursive);
actions().disconnectPrivateActionFromPublicAction(&_colorDatasetPickerAction, recursive);
actions().disconnectPrivateActionFromPublicAction(&_pointSizeDatasetPickerAction, recursive);
actions().disconnectPrivateActionFromPublicAction(&_pointOpacityDatasetPickerAction, recursive);
}

GroupAction::disconnectFromPublicAction(recursive);
Expand All @@ -101,4 +103,171 @@ QVariantMap DatasetsAction::toVariantMap() const
_colorDatasetPickerAction.insertIntoVariantMap(variantMap);

return variantMap;
}
}

void DatasetsAction::setupDatasetPickerActions(ScatterplotPlugin* scatterplotPlugin)
{
setupPositionDatasetPickerAction(scatterplotPlugin);
setupColorDatasetPickerAction(scatterplotPlugin);
setupPointSizeDatasetPickerAction(scatterplotPlugin);
setupPointOpacityDatasetPickerAction(scatterplotPlugin);
}

void DatasetsAction::setupPositionDatasetPickerAction(ScatterplotPlugin* scatterplotPlugin)
{
_positionDatasetPickerAction.setFilterFunction([this](mv::Dataset<DatasetImpl> dataset) -> bool {
return dataset->getDataType() == PointType;
});

connect(&_positionDatasetPickerAction, &DatasetPickerAction::datasetPicked, [this, scatterplotPlugin](Dataset<DatasetImpl> pickedDataset) -> void {
scatterplotPlugin->getPositionDataset() = pickedDataset;
});

connect(&scatterplotPlugin->getPositionDataset(), &Dataset<Points>::changed, this, [this](DatasetImpl* dataset) -> void {
_positionDatasetPickerAction.setCurrentDataset(dataset);
});
}

void DatasetsAction::setupColorDatasetPickerAction(ScatterplotPlugin* scatterplotPlugin)
{
auto& settingsAction = scatterplotPlugin->getSettingsAction();

_colorDatasetPickerAction.setFilterFunction([this, scatterplotPlugin](mv::Dataset<DatasetImpl> dataset) -> bool {
if (!(dataset->getDataType() == PointType || dataset->getDataType() == ColorType || dataset->getDataType() == ClusterType))
return false;

const auto positionDataset = scatterplotPlugin->getPositionDataset();

if (!positionDataset.isValid())
return false;

return true;
});

auto& coloringAction = settingsAction.getColoringAction();

connect(&_colorDatasetPickerAction, &DatasetPickerAction::datasetPicked, [this, &coloringAction, scatterplotPlugin](Dataset<DatasetImpl> pickedDataset) -> void {
if (_colorDataset.isValid())
disconnect(&_colorDataset, &Dataset<>::guiNameChanged, this, nullptr);

_colorDataset = pickedDataset;

connect(&_colorDataset, &Dataset<>::guiNameChanged, scatterplotPlugin, &ScatterplotPlugin::updateHeadsUpDisplay);

coloringAction.setCurrentColorDataset(pickedDataset);

if (!pickedDataset.isValid())
coloringAction.getColorByAction().setCurrentIndex(0);
});

connect(&settingsAction.getColoringAction(), &ColoringAction::currentColorDatasetChanged, this, [this](Dataset<DatasetImpl> currentColorDataset) -> void {
_colorDatasetPickerAction.setCurrentDataset(currentColorDataset);
});
}

void DatasetsAction::setupPointSizeDatasetPickerAction(ScatterplotPlugin* scatterplotPlugin)
{
auto& settingsAction = scatterplotPlugin->getSettingsAction();
auto& pointPlotAction = settingsAction.getPlotAction().getPointPlotAction();
auto& pointSizeAction = pointPlotAction.getSizeAction();

_pointSizeDatasetPickerAction.setFilterFunction([this, scatterplotPlugin](mv::Dataset<DatasetImpl> dataset) -> bool {
if (dataset->getDataType() != PointType)
return false;

qDebug() << dataset->getGuiName() << "A";
const auto positionDataset = scatterplotPlugin->getPositionDataset();

if (!positionDataset.isValid())
return false;

qDebug() << dataset->getGuiName() << "B";

const mv::Dataset<Points> candidatePoints(dataset);

if (candidatePoints->getNumPoints() != positionDataset->getNumPoints())
return false;

qDebug() << dataset->getGuiName() << "C";

return true;
});

connect(&_pointSizeDatasetPickerAction, &DatasetPickerAction::currentIndexChanged, this, [this, &pointPlotAction, &pointSizeAction, scatterplotPlugin](const int32_t& currentIndex) -> void {
const auto& pointSizeDataset = _pointSizeDatasetPickerAction.getCurrentDataset();

if (pointSizeDataset.isValid())
disconnect(&_pointSizeDataset, &Dataset<>::guiNameChanged, this, nullptr);

_pointSizeDataset = pointSizeDataset;

connect(&_pointSizeDataset, &Dataset<>::guiNameChanged, scatterplotPlugin, &ScatterplotPlugin::updateHeadsUpDisplay);

pointPlotAction.setCurrentPointSizeDataset(_pointSizeDataset);

if (!_pointSizeDataset.isValid())
pointSizeAction.setCurrentSourceIndex(ScalarSourceModel::DefaultRow::Constant);
});

connect(&pointSizeAction, &ScalarAction::sourceSelectionChanged, this, [this, &pointSizeAction](const uint32_t& sourceSelectionIndex) -> void {
_pointSizeDatasetPickerAction.setCurrentDataset(pointSizeAction.isSourceDataset() ? pointSizeAction.getCurrentDataset() : nullptr);

if (!pointSizeAction.isSourceDataset())
_pointSizeDatasetPickerAction.setCurrentIndex(-1);
});
}

void DatasetsAction::setupPointOpacityDatasetPickerAction(ScatterplotPlugin* scatterplotPlugin)
{
auto& settingsAction = scatterplotPlugin->getSettingsAction();
auto& pointPlotAction = settingsAction.getPlotAction().getPointPlotAction();
auto& pointOpacityAction = pointPlotAction.getOpacityAction();

_pointOpacityDatasetPickerAction.setFilterFunction([this, scatterplotPlugin](mv::Dataset<DatasetImpl> dataset) -> bool {
if (dataset->getDataType() != PointType)
return false;

const auto positionDataset = scatterplotPlugin->getPositionDataset();

if (!positionDataset.isValid())
return false;

const mv::Dataset<Points> candidatePoints(dataset);

if (candidatePoints->getNumPoints() != positionDataset->getNumPoints())
return false;

return true;
});

connect(&_pointOpacityDatasetPickerAction, &DatasetPickerAction::currentIndexChanged, this, [this, &pointPlotAction, &pointOpacityAction, scatterplotPlugin](const int32_t& currentIndex) -> void {
const auto& pointOpacityDataset = _pointOpacityDatasetPickerAction.getCurrentDataset();

if (pointOpacityDataset.isValid())
disconnect(&_pointOpacityDataset, &Dataset<>::guiNameChanged, this, nullptr);

_pointOpacityDataset = pointOpacityDataset;

connect(&_pointOpacityDataset, &Dataset<>::guiNameChanged, scatterplotPlugin, &ScatterplotPlugin::updateHeadsUpDisplay);

pointPlotAction.setCurrentPointOpacityDataset(_pointOpacityDataset);

if (!_pointOpacityDataset.isValid())
pointOpacityAction.setCurrentSourceIndex(ScalarSourceModel::DefaultRow::Constant);
});

connect(&pointOpacityAction, &ScalarAction::sourceSelectionChanged, this, [this, &pointOpacityAction](const uint32_t& sourceSelectionIndex) -> void {
_pointOpacityDatasetPickerAction.setCurrentDataset(pointOpacityAction.isSourceDataset() ? pointOpacityAction.getCurrentDataset() : nullptr);

if (!pointOpacityAction.isSourceDataset())
_pointOpacityDatasetPickerAction.setCurrentIndex(-1);
});
}

void DatasetsAction::invalidateDatasetPickerActionFilters()
{
_positionDatasetPickerAction.invalidateFilter();
_colorDatasetPickerAction.invalidateFilter();
_pointSizeDatasetPickerAction.invalidateFilter();
_pointOpacityDatasetPickerAction.invalidateFilter();
}
55 changes: 51 additions & 4 deletions src/DatasetsAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ class DatasetsAction : public GroupAction
*/
Q_INVOKABLE DatasetsAction(QObject* parent, const QString& title);

mv::Dataset<mv::DatasetImpl> getColorDataset() { return _colorDataset; }
mv::Dataset<mv::DatasetImpl> getPointSizeDataset() { return _pointSizeDataset; }
mv::Dataset<mv::DatasetImpl> getPointOpacityDataset() { return _pointOpacityDataset; }

protected: // Linking

/**
Expand All @@ -39,7 +43,7 @@ class DatasetsAction : public GroupAction

/**
* Load widget action from variant map
* @param Variant map representation of the widget action
* @param variantMap Variant map representation of the widget action
*/
void fromVariantMap(const QVariantMap& variantMap) override;

Expand All @@ -49,17 +53,60 @@ class DatasetsAction : public GroupAction
*/
QVariantMap toVariantMap() const override;

protected: // Dataset picker action setup

/**
* Set up the dataset picker actions with the datasets from the scatter plot plugin
* @param scatterplotPlugin Pointer to scatter plot plugin whose datasets are used to populate the dataset picker actions
*/
void setupDatasetPickerActions(ScatterplotPlugin* scatterplotPlugin);

/**
* Set up the position dataset picker action with the position datasets from the scatter plot plugin
* @param scatterplotPlugin Pointer to scatter plot plugin whose position datasets are used to populate the dataset picker action
*/
void setupPositionDatasetPickerAction(ScatterplotPlugin* scatterplotPlugin);

/**
* Set up the color dataset picker action with the color datasets from the scatter plot plugin
* @param scatterplotPlugin Pointer to scatter plot plugin whose color datasets are used to populate the dataset picker action
*/
void setupColorDatasetPickerAction(ScatterplotPlugin* scatterplotPlugin);

/**
* Set up the point size dataset picker action with the point size datasets from the scatter plot plugin
* @param scatterplotPlugin Pointer to scatter plot plugin whose point size datasets are used to populate the dataset picker action
*/
void setupPointSizeDatasetPickerAction(ScatterplotPlugin* scatterplotPlugin);

/**
* Set up the point opacity dataset picker action with the point opacity datasets from the scatter plot plugin
* @param scatterplotPlugin Pointer to scatter plot plugin whose point opacity datasets are used to populate the dataset picker action
*/
void setupPointOpacityDatasetPickerAction(ScatterplotPlugin* scatterplotPlugin);

/** Update the filters of the dataset picker actions based on the current datasets in the scatter plot plugin */
void invalidateDatasetPickerActionFilters();

public: // Action getters

DatasetPickerAction& getPositionDatasetPickerAction() { return _positionDatasetPickerAction; }
DatasetPickerAction& getColorDatasetPickerAction() { return _colorDatasetPickerAction; }
DatasetPickerAction& getPointSizeDatasetPickerAction() { return _pointSizeDatasetPickerAction; }
DatasetPickerAction& getPointOpacityDatasetPickerAction() { return _pointOpacityDatasetPickerAction; }

private:
ScatterplotPlugin* _scatterplotPlugin; /** Pointer to scatter plot plugin */
DatasetPickerAction _positionDatasetPickerAction; /** Dataset picker action for position dataset */
DatasetPickerAction _colorDatasetPickerAction; /** Dataset picker action for color dataset */
ScatterplotPlugin* _scatterplotPlugin; /** Pointer to scatter plot plugin */
DatasetPickerAction _positionDatasetPickerAction; /** Dataset picker action for position dataset */
DatasetPickerAction _colorDatasetPickerAction; /** Dataset picker action for color dataset */
DatasetPickerAction _pointSizeDatasetPickerAction; /** Dataset picker action for point size */
DatasetPickerAction _pointOpacityDatasetPickerAction; /** Dataset picker action for point opacity */
mv::Dataset<mv::DatasetImpl> _colorDataset; /** Smart pointer to dataset used for coloring (if any) */
mv::Dataset<mv::DatasetImpl> _pointSizeDataset; /** Smart pointer to dataset for driving point size (if any) */
mv::Dataset<mv::DatasetImpl> _pointOpacityDataset; /** Smart pointer to dataset for driving point opacity (if any) */

friend class mv::AbstractActionsManager;
friend class ScatterplotPlugin;
};

Q_DECLARE_METATYPE(DatasetsAction)
Expand Down
Loading
Loading