Walls And Holes  1
ToolManager Class Reference

The ToolManager class represents a group of mutually exclusive tools out of which only one can be active at a time. More...

#include <toolmanager.h>

Inheritance diagram for ToolManager:
Collaboration diagram for ToolManager:

Public Slots

void activateTool (QString name)
 Activates the desired tool. More...
 
void deactivateTool (QString name)
 Deactivates the tool if it is active. NOTE: A ToolManager is exclusive, so activateTool() automatically deactivates the previous tool. More...
 
QToolBar * contextToolBar ()
 Returns the context toolBar of the current active tool. More...
 
void mousePressEvent (QMouseEvent *event)
 
void mouseReleaseEvent (QMouseEvent *event)
 
void mouseMoveEvent (QMouseEvent *event)
 
void wheelEvent (QWheelEvent *event)
 

Signals

void toolWasActivated (AbstractTool *tool, QString name)
 Signal emitted when a new tool is activated. More...
 

Public Member Functions

 ToolManager (QObject *parent=nullptr)
 
QAction * registerTool (AbstractTool *tool, QString name, QIcon icon=QIcon(), QKeySequence ks=QKeySequence())
 Registers the tool with the given identifier. More...
 
QAction * getAction (QString name)
 Finds the action associated with the name. More...
 

Protected Attributes

QMap< QString, AbstractTool * > mTools
 
QMap< QString, QAction * > mToolActions
 A map from tool names to tool objects. More...
 
QActionGroup * mActionGroup
 The actions associated to each tool. All pointers delete selves when the ToolManager is destructed. More...
 
AbstractToolmActiveTool
 The action group containing all of the ToolManager's actions. More...
 
QToolBar * mContextToolBar
 The active tool. More...
 

Detailed Description

The ToolManager class represents a group of mutually exclusive tools out of which only one can be active at a time.

The object that owns the ToolManager (and therefore sends its events to the ToolManager) must be the object in which the tools are used. For example, one window may contain several different kind of views, including a map view. The map view should own the ToolManager for rectangle / line / point brush tools because these tools only make sense within the map view.

A UI element which desires to use the ToolManager should forward mouse events to the ToolManager so that they can reach the active tool.

Constructor & Destructor Documentation

◆ ToolManager()

ToolManager::ToolManager ( QObject *  parent = nullptr)

Member Function Documentation

◆ activateTool

void ToolManager::activateTool ( QString  name)
slot

Activates the desired tool.

Parameters
nameThe name of the tool.

This slot can be activated directly from a UI element to enable a tool.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ contextToolBar

QToolBar * ToolManager::contextToolBar ( )
slot

Returns the context toolBar of the current active tool.

Here is the caller graph for this function:

◆ deactivateTool

void ToolManager::deactivateTool ( QString  name)
slot

Deactivates the tool if it is active. NOTE: A ToolManager is exclusive, so activateTool() automatically deactivates the previous tool.

Parameters
nameThe name of the tool.
Here is the caller graph for this function:

◆ getAction()

QAction * ToolManager::getAction ( QString  name)

Finds the action associated with the name.

Parameters
nameThe tool name.
Returns
The action associated, or nullptr if name does not match anything.

◆ mouseMoveEvent

void ToolManager::mouseMoveEvent ( QMouseEvent *  event)
slot
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mousePressEvent

void ToolManager::mousePressEvent ( QMouseEvent *  event)
slot
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mouseReleaseEvent

void ToolManager::mouseReleaseEvent ( QMouseEvent *  event)
slot
Here is the call graph for this function:
Here is the caller graph for this function:

◆ registerTool()

QAction * ToolManager::registerTool ( AbstractTool tool,
QString  name,
QIcon  icon = QIcon(),
QKeySequence  ks = QKeySequence() 
)

Registers the tool with the given identifier.

Parameters
toolThe tool to be registered.
nameThe identifier to be given to the tool.
Iconof the tool, an icon is not necessary
KeySequence for the tool, not necessary
Returns
A QAction that, when toggled, will call either activateTool(name) or deactivateTool(name).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ toolWasActivated

void ToolManager::toolWasActivated ( AbstractTool tool,
QString  name 
)
signal

Signal emitted when a new tool is activated.

Parameters
toolThe tool that was activated.
nameThe name of the tool.
Here is the caller graph for this function:

◆ wheelEvent

void ToolManager::wheelEvent ( QWheelEvent *  event)
slot
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ mActionGroup

QActionGroup* ToolManager::mActionGroup
protected

The actions associated to each tool. All pointers delete selves when the ToolManager is destructed.

◆ mActiveTool

AbstractTool* ToolManager::mActiveTool
protected

The action group containing all of the ToolManager's actions.

◆ mContextToolBar

QToolBar* ToolManager::mContextToolBar
protected

The active tool.

◆ mToolActions

QMap<QString, QAction *> ToolManager::mToolActions
protected

A map from tool names to tool objects.

◆ mTools

QMap<QString, AbstractTool *> ToolManager::mTools
protected

The documentation for this class was generated from the following files: