In this section, we're going to understand the code that was automatically generated by Workspace so that we know how to customise our widget, and implement its custom configuration capability
The first thing we need to understand is that the wizard has generated two classes:
- SimplePluginConfig This is subclassed from the Workspace class Application::PluginConfig which handles inserting the code into the Settings menu.
- SimplePluginConfigWidget The widget itself. It knows how to display the configuration setting data.
simplepluginconfig.cpp
The Application::PluginConfig class is an abstract class that is part of the Workspace code set and defines an interface between the plugin and the Workspace editor's Settings menu. Subclasses need to implement the following functions:
QWidget& getQWidget();
void applyConfig();
void resetConfig();
void destroy();
and it supports reimplementation of
Each plugin can have only one PluginConfig subclass. The wizard creates a new class that subclasses PluginConfig and provides default functions implementations based on the plugin. If the user does not edit the generated code than the configuration widget will contain an empty group box with the title "Custom Settings". The existing files modified are simpleplugin.h, simpleplugin.cpp and CMakeLists.txt
simplepluginconfig.h
class SIMPLEPLUGIN_API SimplePluginConfig :
{
Q_OBJECT
std::unique_ptr<SimplePluginConfigWidget> widget_;
private slots:
virtual void onModified();
public:
SimplePluginConfig();
~SimplePluginConfig() override;
};
Provider of a QWidget for configuring a plugin. You can use the Developer wizard to generate a stub i...
Definition: pluginconfig.h:43
virtual void resetConfig()=0
virtual void applyConfig()=0
virtual bool isTopLevelConfig() const
Definition: pluginconfig.h:96
virtual QWidget & getQWidget()=0
Rebuilding (continue on with tutorial Integrating a custom plugin settings widget into the Workspace Editor )
simplepluginconfigwidget.h
class SIMPLEPLUGIN_API SimplePluginConfigWidget : public QWidget
{
Q_OBJECT
public:
SimplePluginConfigWidget(QWidget* parent = Q_NULLPTR);
~SimplePluginConfigWidget() override;
public slots:
void save();
void reload();
signals:
private:
std::unique_ptr<Ui::SimplePluginConfigWidget> ui_;
};
Rebuilding (continue on with tutorial Integrating a custom plugin settings widget into the Workspace Editor )
simplepluginconfigwidget.cpp
widget_ = std::make_unique<SimplePluginConfigWidget>();
connect(widget_.get(), &SimplePluginConfigWidget::modified, this, &SimplePluginConfig::onModified);
}
return *widget_;
}
void SimplePluginConfig::onModified()
{
emit modified();
}
void SimplePluginConfig::applyConfig()
{
if (widget_)
widget_->save();
}
void SimplePluginConfig::resetConfig()
{
if (widget_)
widget_->reload();
}
void SimplePluginConfig::destroy()
{
delete this;
}
bool SimplePluginConfig::isTopLevelConfig() const
{
return false;
}
}
Rebuilding (continue on with tutorial Integrating a custom plugin settings widget into the Workspace Editor )
simplepluginconfigwidget.ui
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CSIRO::SimplePluginConfigWidget</class>
<widget class="QWidget" name="CSIRO::SimplePluginConfigWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>SimplePlugin Configuration Widget</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Custom Settings</string>
</property>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>10</x>
<y>30</y>
<width>47</width>
<height>13</height>
</rect>
</property>
<property name="text">
<string>Project</string>
</property>
</widget>
<widget class="QLineEdit" name="project">
<property name="geometry">
<rect>
<x>110</x>
<y>30</y>
<width>251</width>
<height>20</height>
</rect>
</property>
</widget>
<widget class="QCheckBox" name="enableLogging">
<property name="geometry">
<rect>
<x>10</x>
<y>70</y>
<width>111</width>
<height>17</height>
</rect>
</property>
<property name="text">
<string>Enable Logging</string>
</property>
</widget>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
Rebuilding (continue on with tutorial Integrating a custom plugin settings widget into the Workspace Editor )
simpleplugin.h
Change to the simpleplugin.h file An override of createPluginConfig() is added
SimplePlugin();
~SimplePlugin() override;
simpleplugin.cpp
Changes to the simpleplugin.cpp file simplepluginconfig.h is added to the headers and createPluginConfig defined
Note that an include directive for "simplepluginconfig.h" has been added to the included files
#include "simpleplugin.h"
#include <memory>
#include <QString>
#include <QStringList>
#include "calculaterectanglearea.h"
Also the createPluginConfig has been included so that the framework creates the custom configuration widget
{
return *new SimplePluginConfig;
}
CMakeLists.txt
Changes to the CMakeLists.txt file The CMakeLists.txt file has also been modified to contain references to the new files. As we can see below, the HEADERS, INSTALL_HEADERS, MOC_HEADERS, SOURCES and UI_SOURCES have all been updated to refer to our newly generated files:
set(HEADERS
${SIMPLEPLUGIN_SOURCE_DIR}/simplepluginconfig.h
${SIMPLEPLUGIN_SOURCE_DIR}/simplepluginconfigwidget.h
${SIMPLEPLUGIN_SOURCE_DIR}/rectanglewidgetconnector.h
${SIMPLEPLUGIN_SOURCE_DIR}/rectanglewidgetfactory.h
${SIMPLEPLUGIN_SOURCE_DIR}/rectanglewidget.h
${SIMPLEPLUGIN_SOURCE_DIR}/rectangle.h
${SIMPLEPLUGIN_SOURCE_DIR}/calculaterectanglearea.h
${SIMPLEPLUGIN_SOURCE_DIR}/simpleplugin_api.h
${SIMPLEPLUGIN_SOURCE_DIR}/simpleplugin.h
)
set(INSTALL_HEADERS
${SIMPLEPLUGIN_SOURCE_DIR}/simplepluginconfig.h
${SIMPLEPLUGIN_SOURCE_DIR}/simplepluginconfigwidget.h
${SIMPLEPLUGIN_SOURCE_DIR}/rectanglewidgetconnector.h
${SIMPLEPLUGIN_SOURCE_DIR}/rectanglewidgetfactory.h
${SIMPLEPLUGIN_SOURCE_DIR}/rectanglewidget.h
${SIMPLEPLUGIN_SOURCE_DIR}/rectangle.h
${SIMPLEPLUGIN_SOURCE_DIR}/calculaterectanglearea.h
${SIMPLEPLUGIN_SOURCE_DIR}/simpleplugin_api.h
${SIMPLEPLUGIN_SOURCE_DIR}/simpleplugin.h
)
set(MOC_HEADERS
${SIMPLEPLUGIN_SOURCE_DIR}/simplepluginconfig.h
${SIMPLEPLUGIN_SOURCE_DIR}/simplepluginconfigwidget.h
${SIMPLEPLUGIN_SOURCE_DIR}/rectanglewidgetconnector.h
${SIMPLEPLUGIN_SOURCE_DIR}/rectanglewidget.h
)
set(SOURCES
${SIMPLEPLUGIN_SOURCE_DIR}/simplepluginconfig.cpp
${SIMPLEPLUGIN_SOURCE_DIR}/simplepluginconfigwidget.cpp
${SIMPLEPLUGIN_SOURCE_DIR}/rectanglewidgetconnector.cpp
${SIMPLEPLUGIN_SOURCE_DIR}/rectanglewidgetfactory.cpp
${SIMPLEPLUGIN_SOURCE_DIR}/rectanglewidget.cpp
${SIMPLEPLUGIN_SOURCE_DIR}/rectangle.cpp
${SIMPLEPLUGIN_SOURCE_DIR}/calculaterectanglearea.cpp
${SIMPLEPLUGIN_SOURCE_DIR}/simpleplugin.cpp
)
set(UI_SOURCES
${SIMPLEPLUGIN_SOURCE_DIR}/simplepluginconfigwidget.ui
${SIMPLEPLUGIN_SOURCE_DIR}/rectanglewidget.ui
Rebuilding (continue on with tutorial Integrating a custom plugin settings widget into the Workspace Editor )