Workspace 6.21.5
Public Slots | Signals | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
PluginMenu Class Referenceabstract

An interface for integrating a custom plugin menu into the Workspace editor. More...

#include <Workspace/Application/Plugins/pluginmenu.h>

Inheritance diagram for PluginMenu:
[legend]

Public Slots

virtual void onCurrentWorkflowChanged (const QString &workflowFileName)
 

Signals

void openWorkflow (const QString &filePath)
 Sends a request to the Workspace editor to open a new workflow.
 

Public Member Functions

virtual void createMenu ()=0
 Here is where the menu items are created and connections made.
 
virtual void destroy ()=0
 
virtual QMenu * getMenu ()
 This returns a pointer to the main plugin menu.
 
virtual QString getMenuName () const =0
 
virtual bool isTopLevelMenu () const
 Returns true if the menu is to be directly inserted into the application's main menu bar.
 

Protected Member Functions

 PluginMenu ()
 
 ~PluginMenu () override=default
 
QMainWindow * applicationWindow ()
 Returns a pointer to the main application window.
 

Protected Attributes

QString currentWorkflow_
 
std::unique_ptr< QMenu > mainMenu_
 

Detailed Description

To add a custom menu, create an implementation of PluginMenu and return it from the createPluginMenu() method of your main plugin class (replace the EmptyPluginMenu that is returned by default)

PluginMenu& SimplePlugin::createPluginMenu()
{
return *new EmptyPluginMenu;
}
A default implementation of PluginMenu for plugins that do not supply a custom menu for the Workspace...
Definition: emptypluginmenu.h:48
An interface for integrating a custom plugin menu into the Workspace editor.
Definition: pluginmenu.h:56

You can use the Developer wizard to generate a stub implementation of this class. See Integrating a custom plugin menu into the Workspace Editor

Constructor & Destructor Documentation

◆ PluginMenu()

PluginMenu ( )
explicitprotected

◆ ~PluginMenu()

~PluginMenu ( )
overrideprotecteddefault

Only subclasses may delete PluginMenu objects, and it should always be from inside destroy().

Member Function Documentation

◆ applicationWindow()

QMainWindow * applicationWindow ( )
protected

Use this inside createMenu() if you want to make SIGNAL/SLOT connections between your plugin and the main application

See also
createMenu()

◆ createMenu()

virtual void createMenu ( )
pure virtual

You must implement this to create your menu items, and create connections between them, the application and your plugin slots

Add menu items like this:

QMenu* menu = mainMenu_.get();
QAction* myAction = new QAction("Do new action", menu);
newAction->setObjectName(QString::fromUtf8("myAction"));
newAction->setStatusTip(tr("Carries out my action"));
connect(newAction, SIGNAL(triggered()), this, SLOT(doAction()));
menu->insertAction(0, newAction);
std::unique_ptr< QMenu > mainMenu_
Definition: pluginmenu.h:79

You can open a workflow up in the Workspace editor by emitting the openWorkflow(const QString&) signal or create connections between your plugin and the application like this:

connect(applicationWindow()->findChild<QObject*>("actionOpenWorkflow"), SIGNAL(triggered()), this, SLOT(myNewSlot()));
QMainWindow * applicationWindow()
Returns a pointer to the main application window.
Definition: pluginmenu.cpp:70
See also
applicationWindow()

Implemented in WorkflowToolsPluginMenu, and EmptyPluginMenu.

◆ destroy()

virtual void destroy ( )
pure virtual

Subclasses will almost always implement this function simply as a call to the delete operator, or to some kind of factory singleton which does this. Since PluginMenu subclass objects are usually instantiated by a singleton within the plugin, the destroy() function is necessary to ensure that the plugin also deletes instances.

Implemented in WorkflowToolsPluginMenu, and EmptyPluginMenu.

◆ getMenu()

QMenu * getMenu ( )
virtual
Returns
A pointer to its QMenu object. By default this calls createMenu() and creates any default connections.

Reimplemented in EmptyPluginMenu.

◆ getMenuName()

virtual QString getMenuName ( ) const
pure virtual
Returns
You must implement this and supply a title for your menu.

Implemented in WorkflowToolsPluginMenu, and EmptyPluginMenu.

◆ isTopLevelMenu()

virtual bool isTopLevelMenu ( ) const
inlinevirtual

The menu can be either directly inserted into the main menu bar or inserted as a submenu into a "Plugins" menu. The base class implementation returns true: override this to return false

Reimplemented in WorkflowToolsPluginMenu, and EmptyPluginMenu.

◆ onCurrentWorkflowChanged

void onCurrentWorkflowChanged ( const QString &  workflowFileName)
virtualslot

◆ openWorkflow

void openWorkflow ( const QString &  filePath)
signal
Parameters
filePathfull path of the workflow to be opened

Member Data Documentation

◆ currentWorkflow_

QString currentWorkflow_
protected

Name of the current workflow, if there is one

◆ mainMenu_

std::unique_ptr<QMenu> mainMenu_
protected

Pointer to the top menu item supplied