In this section, we're going to understand the code that was automatically generated by Workspace so that we know how to customise our menu.
simplepluginmenu.cpp
The wizard has generated one new class, SimplePluginMenu. This is subclassed from the Workspace class Application::PluginMenu which handles inserting the new menu into the Workspace editor.
The Application::PluginMenu 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 menu bar. Subclasses need to implement the following functions:
QString& getMenuName();
QMenu& getMenu();
void destroy();
and it supports reimplementation of
Each plugin can have only one PluginMenu subclass. The wizard creates a new class that subclasses PluginMenu and provides default functions implementations based on the plugin. If the user does not edit the generated code than the configuration widget will add a new empty menu to the Workspace editor's menu bar, and give it the plugin's display name. The existing files modified are simpleplugin.h, simpleplugin.cpp and CMakeLists.txt
Rebuilding (continue on with tutorial Integrating a custom plugin menu into the Workspace Editor )
simplepluginmenu.h
The code provides default values for the menu name, and whether the menu should be displayed in the main menu bar. You can change these, and create a real menu inside the simpleplugin.cpp file
{
Q_OBJECT
public:
SimplePluginMenu();
~SimplePluginMenu() override;
QString getMenuName() const override;
void createMenu() override;
void destroy() override;
bool isTopLevelMenu() const override;
Rebuilding (continue on with tutorial Integrating a custom plugin menu into the Workspace Editor )
simpleplugin.h
Change to the simpleplugin.h file. An override of createPluginMenu() is added
SimplePlugin();
~SimplePlugin() override;
Provider of a QWidget for configuring a plugin. You can use the Developer wizard to generate a stub i...
Definition: pluginconfig.h:43
simpleplugin.cpp
Changes to the simpleplugin.cpp file: simplepluginmenu.h is added to the headers and createPluginMenu defined
#include "simpleplugin.h"
#include <memory>
#include <QString>
#include <QStringList>
#include "calculaterectanglearea.h"
{
return *new SimplePluginMenu;
}
Rebuilding (continue on with tutorial Integrating a custom plugin menu into the Workspace Editor )
CMakeLists.txt
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, and SOURCES have all been updated to refer to our newly generated files:
set(HEADERS
${SIMPLEPLUGIN_SOURCE_DIR}/simplepluginmenu.h
${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}/simplepluginmenu.h
${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}/simplepluginmenu.h
${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}/simplepluginmenu.cpp
${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 menu into the Workspace Editor )