From 5d757a26be72ccbc608108f9a906e13f13963c16 Mon Sep 17 00:00:00 2001 From: Thomas Kroes Date: Mon, 22 Jan 2024 13:05:23 +0100 Subject: [PATCH] Add plugin global settings for ExampleViewOpenGl plugin (#17) * Add ExampleViewGL global settings action Add default point size action to the global settings action Initialize point size from global settings default point size Simplified the SettingsAction (derive from group action instead of WidgetAction) Correctly connect lambdas to ExampleViewGLPlugin::updatePlot() in SettingsAction Add ExampleViewGLPlugin SettingsAction as a docking widget * Fix small typo * Fix small typo * Add example OpenGL view default point opacity global setting --- ExampleViewOpenGL/CMakeLists.txt | 2 + ExampleViewOpenGL/src/ExampleViewGLPlugin.cpp | 17 +++++- ExampleViewOpenGL/src/ExampleViewGLPlugin.h | 7 ++- .../src/GlobalSettingsAction.cpp | 19 ++++++ ExampleViewOpenGL/src/GlobalSettingsAction.h | 41 +++++++++++++ ExampleViewOpenGL/src/SettingsAction.cpp | 59 +++++-------------- ExampleViewOpenGL/src/SettingsAction.h | 17 ++---- 7 files changed, 99 insertions(+), 63 deletions(-) create mode 100644 ExampleViewOpenGL/src/GlobalSettingsAction.cpp create mode 100644 ExampleViewOpenGL/src/GlobalSettingsAction.h diff --git a/ExampleViewOpenGL/CMakeLists.txt b/ExampleViewOpenGL/CMakeLists.txt index ddfe122..6b3b823 100644 --- a/ExampleViewOpenGL/CMakeLists.txt +++ b/ExampleViewOpenGL/CMakeLists.txt @@ -57,6 +57,8 @@ set(EXAMPLEVIEWGL_WIDGET set(EXAMPLEVIEWGL_ACTIONS src/SettingsAction.h src/SettingsAction.cpp + src/GlobalSettingsAction.h + src/GlobalSettingsAction.cpp ) source_group( Plugin FILES ${EXAMPLEVIEWGL_SOURCES}) diff --git a/ExampleViewOpenGL/src/ExampleViewGLPlugin.cpp b/ExampleViewOpenGL/src/ExampleViewGLPlugin.cpp index 059b69b..50ec7b8 100644 --- a/ExampleViewOpenGL/src/ExampleViewGLPlugin.cpp +++ b/ExampleViewOpenGL/src/ExampleViewGLPlugin.cpp @@ -1,6 +1,8 @@ #include "ExampleViewGLPlugin.h" #include "ExampleGLWidget.h" +#include "GlobalSettingsAction.h" + #include #include @@ -119,12 +121,13 @@ void ExampleViewGLPlugin::init() layout->setContentsMargins(0, 0, 0, 0); layout->setSpacing(0); - layout->addWidget(_settingsAction.createWidget(&getWidget())); layout->addWidget(_exampleGLWidget, 100); // Apply the layout getWidget().setLayout(layout); + addDockingAction(&_settingsAction); + // Update the data when the scatter plot widget is initialized connect(_exampleGLWidget, &ExampleGLWidget::initialized, this, []() { qDebug() << "ExampleGLWidget is initialized."; } ); @@ -168,7 +171,7 @@ void ExampleViewGLPlugin::loadData(const mv::Datasets& datasets) if (datasets.isEmpty()) return; - qDebug() << "ExampleViewJSPlugin::loadData: Load data set from ManiVault core"; + qDebug() << "ExampleViewGLPlugin::loadData: Load data set from ManiVault core"; _dropWidget->setShowDropIndicator(false); // Load the first dataset, changes to _currentDataSet are connected with convertDataAndUpdateChart @@ -194,7 +197,7 @@ void ExampleViewGLPlugin::createData() int numDimensions = 3; const std::vector dimNames {"Dim 1", "Dim 2", "Dim 3"}; - qDebug() << "ExampleViewJSPlugin::createData: Create some example data. " << numPoints << " points, each with " << numDimensions << " dimensions"; + qDebug() << "ExampleViewGLPlugin::createData: Create some example data. " << numPoints << " points, each with " << numDimensions << " dimensions"; // Create random example data std::vector exampleData; @@ -227,6 +230,14 @@ ViewPlugin* ExampleViewGLPluginFactory::produce() return new ExampleViewGLPlugin(this); } +void ExampleViewGLPluginFactory::initialize() +{ + ViewPluginFactory::initialize(); + + // Create an instance of our GlobalSettingsAction (derived from PluginGlobalSettingsGroupAction) and assign it to the factory + setGlobalSettingsGroupAction(new GlobalSettingsAction(this, this)); +} + QIcon ExampleViewGLPluginFactory::getIcon(const QColor& color /*= Qt::black*/) const { return mv::Application::getIconFont("FontAwesome").getIcon("braille", color); diff --git a/ExampleViewOpenGL/src/ExampleViewGLPlugin.h b/ExampleViewOpenGL/src/ExampleViewGLPlugin.h index d070315..25d4e43 100644 --- a/ExampleViewOpenGL/src/ExampleViewGLPlugin.h +++ b/ExampleViewOpenGL/src/ExampleViewGLPlugin.h @@ -68,7 +68,7 @@ class ExampleViewGLPlugin : public ViewPlugin DropWidget* _dropWidget; /** Widget for drag and drop behavior */ ExampleGLWidget* _exampleGLWidget; /** The OpenGL widget */ SettingsAction _settingsAction; /** Settings action */ - mv::Dataset _currentDataSet; /** Points smart pointer */ + mv::Dataset _currentDataSet; /** Points smart pointer */ std::vector _currentDimensions; /** Stores which dimensions of the current data are shown */ }; @@ -91,7 +91,10 @@ class ExampleViewGLPluginFactory : public ViewPluginFactory /** Destructor */ ~ExampleViewGLPluginFactory() override {} - + + /** Perform post-construction initialization */ + void initialize() override; + /** Get plugin icon */ QIcon getIcon(const QColor& color = Qt::black) const override; diff --git a/ExampleViewOpenGL/src/GlobalSettingsAction.cpp b/ExampleViewOpenGL/src/GlobalSettingsAction.cpp new file mode 100644 index 0000000..fd74942 --- /dev/null +++ b/ExampleViewOpenGL/src/GlobalSettingsAction.cpp @@ -0,0 +1,19 @@ +#include "GlobalSettingsAction.h" + +#include + +using namespace mv; +using namespace mv::gui; + +GlobalSettingsAction::GlobalSettingsAction(QObject* parent, const plugin::PluginFactory* pluginFactory) : + PluginGlobalSettingsGroupAction(parent, pluginFactory), + _defaultPointSizeAction(this, "Default point Size", 1, 50, 10), + _defaultPointOpacityAction(this, "Default point opacity", 0.f, 1.f, 0.5f) +{ + _defaultPointSizeAction.setToolTip("Default size of individual points"); + _defaultPointOpacityAction.setToolTip("Default opacity of individual points"); + + // The add action automatically assigns a settings prefix to _pointSizeAction so there is no need to do this manually + addAction(&_defaultPointSizeAction); + addAction(&_defaultPointOpacityAction); +} diff --git a/ExampleViewOpenGL/src/GlobalSettingsAction.h b/ExampleViewOpenGL/src/GlobalSettingsAction.h new file mode 100644 index 0000000..c88b8b3 --- /dev/null +++ b/ExampleViewOpenGL/src/GlobalSettingsAction.h @@ -0,0 +1,41 @@ +#pragma once + +#include + +#include + +namespace mv { + namespace plugin { + class PluginFactory; + } +} + +/** + * Global settings action class + * + * Action class for configuring global settings + * + * This group action (once assigned to the plugin factory, see ExampleViewGLPluginFactory::initialize()) is + * added to the global settings panel, accessible through the file > settings menu. + * + */ +class GlobalSettingsAction : public mv::gui::PluginGlobalSettingsGroupAction +{ +public: + + /** + * Construct with pointer to \p parent object and \p pluginFactory + * @param parent Pointer to parent object + * @param pluginFactory Pointer to plugin factory + */ + Q_INVOKABLE GlobalSettingsAction(QObject* parent, const mv::plugin::PluginFactory* pluginFactory); + +public: // Action getters + + mv::gui::DecimalAction& getDefaultPointSizeAction() { return _defaultPointSizeAction; } + mv::gui::DecimalAction& getDefaultPointOpacityAction() { return _defaultPointOpacityAction; } + +private: + mv::gui::DecimalAction _defaultPointSizeAction; /** Default point size action */ + mv::gui::DecimalAction _defaultPointOpacityAction; /** Default point opacity action */ +}; diff --git a/ExampleViewOpenGL/src/SettingsAction.cpp b/ExampleViewOpenGL/src/SettingsAction.cpp index 82cf297..653b18f 100644 --- a/ExampleViewOpenGL/src/SettingsAction.cpp +++ b/ExampleViewOpenGL/src/SettingsAction.cpp @@ -1,4 +1,5 @@ #include "SettingsAction.h" +#include "GlobalSettingsAction.h" #include "ExampleViewGLPlugin.h" @@ -7,7 +8,7 @@ using namespace mv::gui; SettingsAction::SettingsAction(QObject* parent, const QString& title) : - WidgetAction(parent, title), + GroupAction(parent, title), _exampleViewGLPlugin(dynamic_cast(parent)), _datasetNameAction(this, "Dataset Name"), _xDimensionPickerAction(this, "X"), @@ -17,6 +18,12 @@ SettingsAction::SettingsAction(QObject* parent, const QString& title) : { setText("Settings"); + addAction(&_datasetNameAction); + addAction(&_xDimensionPickerAction); + addAction(&_yDimensionPickerAction); + addAction(&_pointSizeAction); + addAction(&_pointOpacityAction); + _datasetNameAction.setToolTip("Name of currently shown dataset"); _xDimensionPickerAction.setToolTip("X dimension"); _yDimensionPickerAction.setToolTip("Y dimension"); @@ -27,50 +34,12 @@ SettingsAction::SettingsAction(QObject* parent, const QString& title) : _datasetNameAction.setText("Dataset name"); _datasetNameAction.setString(" (No data loaded yet)"); - connect(&_xDimensionPickerAction, &DimensionPickerAction::currentDimensionIndexChanged, [this](const std::uint32_t& currentDimensionIndex) { - _exampleViewGLPlugin->updatePlot(); - }); - - connect(&_yDimensionPickerAction, &DimensionPickerAction::currentDimensionIndexChanged, [this](const std::uint32_t& currentDimensionIndex) { - _exampleViewGLPlugin->updatePlot(); - }); + _pointSizeAction.setValue(mv::settings().getPluginGlobalSettingsGroupAction(_exampleViewGLPlugin)->getDefaultPointSizeAction().getValue()); + _pointOpacityAction.setValue(mv::settings().getPluginGlobalSettingsGroupAction(_exampleViewGLPlugin)->getDefaultPointOpacityAction().getValue()); - connect(&_pointSizeAction, &DecimalAction::valueChanged, [this](float val) { - _exampleViewGLPlugin->updatePlot(); - }); - - connect(&_pointOpacityAction, &DecimalAction::valueChanged, [this](float val) { - _exampleViewGLPlugin->updatePlot(); - }); + connect(&_xDimensionPickerAction, &DimensionPickerAction::currentDimensionIndexChanged, _exampleViewGLPlugin, &ExampleViewGLPlugin::updatePlot); + connect(&_yDimensionPickerAction, &DimensionPickerAction::currentDimensionIndexChanged, _exampleViewGLPlugin, &ExampleViewGLPlugin::updatePlot); + connect(&_pointSizeAction, &DecimalAction::valueChanged, _exampleViewGLPlugin, &ExampleViewGLPlugin::updatePlot); + connect(&_pointOpacityAction, &DecimalAction::valueChanged, _exampleViewGLPlugin, &ExampleViewGLPlugin::updatePlot); } - -SettingsAction::Widget::Widget(QWidget* parent, SettingsAction* settingsAction) : - WidgetActionWidget(parent, settingsAction) -{ - setAutoFillBackground(true); - setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding)); - - auto layout = new QHBoxLayout(); - - const int margin = 5; - layout->setContentsMargins(margin, margin, margin, margin); - layout->setSpacing(2); - - layout->addWidget(settingsAction->getDatasetNameAction().createLabelWidget(this)); - layout->addWidget(settingsAction->getDatasetNameAction().createWidget(this)); - - layout->addWidget(settingsAction->getXDimensionPickerAction().createLabelWidget(this)); - layout->addWidget(settingsAction->getXDimensionPickerAction().createWidget(this)); - - layout->addWidget(settingsAction->getYDimensionPickerAction().createLabelWidget(this)); - layout->addWidget(settingsAction->getYDimensionPickerAction().createWidget(this)); - - layout->addWidget(settingsAction->getPointSizeAction().createLabelWidget(this)); - layout->addWidget(settingsAction->getPointSizeAction().createWidget(this)); - - layout->addWidget(settingsAction->getPointOpacityAction().createLabelWidget(this)); - layout->addWidget(settingsAction->getPointOpacityAction().createWidget(this)); - - setLayout(layout); -} \ No newline at end of file diff --git a/ExampleViewOpenGL/src/SettingsAction.h b/ExampleViewOpenGL/src/SettingsAction.h index 85d0777..9b7072a 100644 --- a/ExampleViewOpenGL/src/SettingsAction.h +++ b/ExampleViewOpenGL/src/SettingsAction.h @@ -1,6 +1,6 @@ #pragma once -#include +#include #include #include #include @@ -8,14 +8,16 @@ using namespace mv::gui; class ExampleViewGLPlugin; + /** * Settings action class * * Action class for configuring settings */ -class SettingsAction : public WidgetAction +class SettingsAction : public GroupAction { public: + /** * Construct with \p parent object and \p title * @param parent Pointer to parent object @@ -31,17 +33,6 @@ class SettingsAction : public WidgetAction DecimalAction& getPointSizeAction() { return _pointSizeAction; } DecimalAction& getPointOpacityAction() { return _pointOpacityAction; } -protected: - - class Widget : public WidgetActionWidget { - public: - Widget(QWidget* parent, SettingsAction* settingsAction); - }; - - QWidget* getWidget(QWidget* parent, const std::int32_t& widgetFlags) override { - return new SettingsAction::Widget(parent, this); - }; - private: ExampleViewGLPlugin* _exampleViewGLPlugin; /** Pointer to Example OpenGL Viewer Plugin */ StringAction _datasetNameAction; /** Action for displaying the current data set name */