QgsLayoutViewTool class

Abstract base class for all layout view tools.

Layout view tools are user interactive tools for manipulating and adding items to QgsLayoutView widgets.

Derived classes

class QgsLayoutViewToolAddItem
Layout view tool for adding items to a layout.
class QgsLayoutViewToolAddNodeItem
Layout view tool for adding node based items to a layout.
class QgsLayoutViewToolEditNodes
Layout view tool for edit node based items in the layout.
class QgsLayoutViewToolMoveItemContent
Layout view tool for moving and zooming item content.
class QgsLayoutViewToolPan
Layout view tool for panning the layout.
class QgsLayoutViewToolSelect
Layout view tool for selecting items in the layout.
class QgsLayoutViewToolTemporaryKeyPan
Layout view tool for temporarily panning a layout while a key is depressed.
class QgsLayoutViewToolTemporaryMousePan
Layout view tool for temporarily panning a layout while a mouse button is depressed.
class QgsLayoutViewToolZoom
Layout view tool for zooming into and out of the layout.

Public types

enum Flag { FlagSnaps = 1 << 1 }
Flags for controlling how a tool behaves.

Constructors, destructors, conversion operators

QgsLayoutViewTool(QgsLayoutView* view, const QString& name) protected
Constructor for QgsLayoutViewTool, taking a layout view and tool name as parameters.

Public functions

auto action() -> QAction*
Returns the action associated with the tool or nullptr if no action is associated.
void activate() virtual
Called when tool is set as the currently active layout tool.
void deactivate() virtual
Called when tool is deactivated.
auto flags() const -> QgsLayoutViewTool::Flags
Returns the current combination of flags set for the tool.
auto ignoredSnapItems() const -> QList<QgsLayoutItem*> virtual
Returns a list of items which should be ignored while snapping events for this tool.
void keyPressEvent(QKeyEvent* event) virtual
Key press event for overriding.
void keyReleaseEvent(QKeyEvent* event) virtual
Key release event for overriding.
auto layout() const -> QgsLayout*
Returns the layout associated with the tool.
void layoutDoubleClickEvent(QgsLayoutViewMouseEvent* event) virtual
Mouse double-click event for overriding.
void layoutMoveEvent(QgsLayoutViewMouseEvent* event) virtual
Mouse move event for overriding.
void layoutPressEvent(QgsLayoutViewMouseEvent* event) virtual
Mouse press event for overriding.
void layoutReleaseEvent(QgsLayoutViewMouseEvent* event) virtual
Mouse release event for overriding.
void setAction(QAction* action)
Associates an action with this tool.
void setCursor(const QCursor& cursor)
Sets a user defined cursor for use when the tool is active.
auto toolName() const -> QString
Returns a user-visible, translated name for the tool.
auto view() const -> QgsLayoutView*
Returns the view associated with the tool.
void wheelEvent(QWheelEvent* event) virtual
Mouse wheel event for overriding.

Signals

void activated()
Emitted when the tool is activated.
void deactivated()
Emitted when the tool is deactivated.
void itemFocused(QgsLayoutItem* item)
Emitted when an item is "focused" by the tool, i.e.

Protected functions

auto isClickAndDrag(QPoint startViewPoint, QPoint endViewPoint) const -> bool
Returns true if a mouse press/release operation which started at startViewPoint and ended at endViewPoint should be considered a "click and drag".
void setFlags(QgsLayoutViewTool::Flags flags)
Sets the combination of flags that will be used for the tool.

Enum documentation

enum QgsLayoutViewTool::Flag

Flags for controlling how a tool behaves.

Enumerators
FlagSnaps

Tool utilizes snapped coordinates.

Function documentation

QAction* QgsLayoutViewTool::action()

Returns the action associated with the tool or nullptr if no action is associated.

void QgsLayoutViewTool::activate() virtual

Called when tool is set as the currently active layout tool.

Overridden implementations must take care to call the base class implementation.

void QgsLayoutViewTool::deactivate() virtual

Called when tool is deactivated.

Overridden implementations must take care to call the base class implementation.

QgsLayoutViewTool::Flags QgsLayoutViewTool::flags() const

Returns the current combination of flags set for the tool.

void QgsLayoutViewTool::keyPressEvent(QKeyEvent* event) virtual

Key press event for overriding.

Default implementation does nothing.

void QgsLayoutViewTool::keyReleaseEvent(QKeyEvent* event) virtual

Key release event for overriding.

Default implementation does nothing.

QgsLayout* QgsLayoutViewTool::layout() const

Returns the layout associated with the tool.

void QgsLayoutViewTool::layoutDoubleClickEvent(QgsLayoutViewMouseEvent* event) virtual

Mouse double-click event for overriding.

Default implementation does nothing.

void QgsLayoutViewTool::layoutMoveEvent(QgsLayoutViewMouseEvent* event) virtual

Mouse move event for overriding.

Default implementation does nothing.

void QgsLayoutViewTool::layoutPressEvent(QgsLayoutViewMouseEvent* event) virtual

Mouse press event for overriding.

Default implementation does nothing. Note that subclasses must ensure that they correctly handle cases when a layoutPressEvent is called without a corresponding layoutReleaseEvent (e.g. due to tool being changed mid way through a press-release operation).

void QgsLayoutViewTool::layoutReleaseEvent(QgsLayoutViewMouseEvent* event) virtual

Mouse release event for overriding.

Default implementation does nothing. Note that subclasses must ensure that they correctly handle cases when a layoutPressEvent is called without a corresponding layoutReleaseEvent (e.g. due to tool being changed mid way through a press-release operation).

void QgsLayoutViewTool::setAction(QAction* action)

Associates an action with this tool.

When the setLayoutTool method of QgsLayoutView is called the action's state will be set to on. Usually this will cause a toolbutton to appear pressed in and the previously used toolbutton to pop out.

QgsLayoutView* QgsLayoutViewTool::view() const

Returns the view associated with the tool.

void QgsLayoutViewTool::wheelEvent(QWheelEvent* event) virtual

Mouse wheel event for overriding.

Default implementation does nothing.

void QgsLayoutViewTool::itemFocused(QgsLayoutItem* item) signal

Emitted when an item is "focused" by the tool, i.e.

it should become the active item and should have its properties displayed in any designer windows.

bool QgsLayoutViewTool::isClickAndDrag(QPoint startViewPoint, QPoint endViewPoint) const protected

Returns true if a mouse press/release operation which started at startViewPoint and ended at endViewPoint should be considered a "click and drag".

If false is returned, the operation should be instead treated as just a click on startViewPoint.

void QgsLayoutViewTool::setFlags(QgsLayoutViewTool::Flags flags) protected

Sets the combination of flags that will be used for the tool.