API reference - Class Plugin

Notation used in Ruby API documentation

Description: The plugin object

This class provides the actual plugin implementation. Each view gets it's own instance of the plugin class. The plugin factory PluginFactory class must be specialized to provide a factory for new objects of the Plugin class. See the documentation there for details about the plugin mechanism and the basic concepts.

This class has been introduced in version 0.22.

Public constructors

new Plugin ptrnewCreates a new object of this class

Public methods

void_createEnsures the C++ object is created
void_destroyExplicitly destroys the object
[const]bool_destroyed?Returns a value indicating whether the object was already destroyed
[const]bool_is_const_object?Returns a value indicating whether the reference is a const reference
void_manageMarks the object as managed by the script side.
void_unmanageMarks the object as no longer owned by the script side.
[virtual]voidactivatedGets called when the plugin is activated (selected in the tool bar)
[virtual]voidconfig_finalizeSends the post-configuration request to the plugin
[virtual]boolconfigure(string name,
string value)
Sends configuration requests to the plugin
[virtual]voiddeactivatedGets called when the plugin is deactivated and another plugin is activated
[virtual]voiddrag_cancelGets called on various occasions when a drag operation should be canceled
[virtual]boolenter_event(bool prio)Handles the enter event (mouse enters canvas area of view)
voidgrab_mouseRedirects mouse events to this plugin, even if the plugin is not active.
[virtual]boolkey_event(unsigned int key,
unsigned int buttons)
Handles the key pressed event
[virtual]boolleave_event(bool prio)Handles the leave event (mouse leaves canvas area of view)
[virtual]voidmenu_activated(string symbol)Gets called when a custom menu item is selected
[virtual]boolmouse_button_pressed_event(const DPoint p,
unsigned int buttons,
bool prio)
Handles the mouse button pressed event
[virtual]boolmouse_button_released_event(const DPoint p,
unsigned int buttons,
bool prio)
Handles the mouse button release event
[virtual]boolmouse_click_event(const DPoint p,
unsigned int buttons,
bool prio)
Handles the mouse button click event (after the button has been released)
[virtual]boolmouse_double_click_event(const DPoint p,
unsigned int buttons,
bool prio)
Handles the mouse button double-click event
[virtual]boolmouse_moved_event(const DPoint p,
unsigned int buttons,
bool prio)
Handles the mouse move event
voidset_cursor(int cursor_type)Sets the cursor in the view area to the given type
voidungrab_mouseRemoves a mouse grab registered with grab_mouse.
[virtual]voidupdateGets called when the view has changed
[virtual]boolwheel_event(int delta,
bool horizontal,
const DPoint p,
unsigned int buttons,
bool prio)

Deprecated methods (protected, public, static, non-static and constructors)

voidcreateUse of this method is deprecated. Use _create instead
voiddestroyUse of this method is deprecated. Use _destroy instead
[const]booldestroyed?Use of this method is deprecated. Use _destroyed? instead
[const]boolis_const_object?Use of this method is deprecated. Use _is_const_object? instead

Detailed description

_create

Signature: void _create

Description: Ensures the C++ object is created

Use this method to ensure the C++ object is created, for example to ensure that resources are allocated. Usually C++ objects are created on demand and not necessarily when the script object is created.

_destroy

Signature: void _destroy

Description: Explicitly destroys the object

Explicitly destroys the object on C++ side if it was owned by the script interpreter. Subsequent access to this object will throw an exception. If the object is not owned by the script, this method will do nothing.

_destroyed?

Signature: [const] bool _destroyed?

Description: Returns a value indicating whether the object was already destroyed

This method returns true, if the object was destroyed, either explicitly or by the C++ side. The latter may happen, if the object is owned by a C++ object which got destroyed itself.

_is_const_object?

Signature: [const] bool _is_const_object?

Description: Returns a value indicating whether the reference is a const reference

This method returns true, if self is a const reference. In that case, only const methods may be called on self.

_manage

Signature: void _manage

Description: Marks the object as managed by the script side.

After calling this method on an object, the script side will be responsible for the management of the object. This method may be called if an object is returned from a C++ function and the object is known not to be owned by any C++ instance. If necessary, the script side may delete the object if the script's reference is no longer required.

Usually it's not required to call this method. It has been introduced in version 0.24.

_unmanage

Signature: void _unmanage

Description: Marks the object as no longer owned by the script side.

Calling this method will make this object no longer owned by the script's memory management. Instead, the object must be managed in some other way. Usually this method may be called if it is known that some C++ object holds and manages this object. Technically speaking, this method will turn the script's reference into a weak reference. After the script engine decides to delete the reference, the object itself will still exist. If the object is not managed otherwise, memory leaks will occur.

Usually it's not required to call this method. It has been introduced in version 0.24.

activated

Signature: [virtual] void activated

Description: Gets called when the plugin is activated (selected in the tool bar)

config_finalize

Signature: [virtual] void config_finalize

Description: Sends the post-configuration request to the plugin

After all configuration parameters have been sent, 'config_finalize' is called to given the plugin a chance to update it's internal state according to the new configuration.

configure

Signature: [virtual] bool configure (string name,string value)

Description: Sends configuration requests to the plugin

name:The name of the configuration variable as registered in the plugin factory
value:The value of the configuration variable

When a configuration variable is changed, the new value is reported to the plugin by calling the 'configure' method.

create

Signature: void create

Description: Ensures the C++ object is created

Use of this method is deprecated. Use _create instead

deactivated

Signature: [virtual] void deactivated

Description: Gets called when the plugin is deactivated and another plugin is activated

destroy

Signature: void destroy

Description: Explicitly destroys the object

Use of this method is deprecated. Use _destroy instead

destroyed?

Signature: [const] bool destroyed?

Description: Returns a value indicating whether the object was already destroyed

Use of this method is deprecated. Use _destroyed? instead

drag_cancel

Signature: [virtual] void drag_cancel

Description: Gets called on various occasions when a drag operation should be canceled

If the plugin implements some press-and-drag or a click-and-drag operation, this callback should cancel this operation and return in some state waiting for a new mouse event.

enter_event

Signature: [virtual] bool enter_event (bool prio)

Description: Handles the enter event (mouse enters canvas area of view)

The behaviour of this callback is the same than for mouse_press_event, except that it is called when the mouse enters the canvas area. This method does not have a position nor button flags.

grab_mouse

Signature: void grab_mouse

Description: Redirects mouse events to this plugin, even if the plugin is not active.

is_const_object?

Signature: [const] bool is_const_object?

Description: Returns a value indicating whether the reference is a const reference

Use of this method is deprecated. Use _is_const_object? instead

key_event

Signature: [virtual] bool key_event (unsigned int key,unsigned int buttons)

Description: Handles the key pressed event

key:The Qt key code of the key that was pressed
buttons:A combination of the constants in the ButtonState class which codes both the mouse buttons and the key modifiers (.e. ShiftButton etc).
Returns:True to terminate dispatcher

This method will called by the view on the active plugin when a button is pressed on the mouse.

If the plugin handles the event, it should return true to indicate that the event should not be processed further.

leave_event

Signature: [virtual] bool leave_event (bool prio)

Description: Handles the leave event (mouse leaves canvas area of view)

The behaviour of this callback is the same than for mouse_press_event, except that it is called when the mouse leaves the canvas area. This method does not have a position nor button flags.

menu_activated

Signature: [virtual] void menu_activated (string symbol)

Description: Gets called when a custom menu item is selected

When a menu item is clicked which was registered with the plugin factory, the plugin's 'menu_activated' method is called for the current view. The symbol registered for the menu item is passed in the 'symbol' argument.

mouse_button_pressed_event

Signature: [virtual] bool mouse_button_pressed_event (const DPoint p,unsigned int buttons,bool prio)

Description: Handles the mouse button pressed event

p:The point at which the button was pressed
buttons:A combination of the constants in the ButtonState class which codes both the mouse buttons and the key modifiers (.e. LeftButton, ShiftButton etc).
Returns:True to terminate dispatcher

This method will called by the view when a button is pressed on the mouse.

First, the plugins that grabbed the mouse with grab_mouse will receive this event with 'prio' set to true in the reverse order the plugins grabbed the mouse. The loop will terminate if one of the mouse event handlers returns true.

If that is not the case or no plugin has grabbed the mouse, the active plugin receives the mouse event with 'prio' set to true.

If no receiver accepted the mouse event by returning true, it is sent again to all plugins with 'prio' set to false. Again, the loop terminates if one of the receivers returns true. The second pass gives inactive plugins a chance to monitor the mouse and implement specific actions - i.e. displaying the current position.

This event is not sent immediately when the mouse button is pressed but when a signification movement for the mouse cursor away from the original position is detected. If the mouse button is released before that, a mouse_clicked_event is sent rather than a press-move-release sequence.

mouse_button_released_event

Signature: [virtual] bool mouse_button_released_event (const DPoint p,unsigned int buttons,bool prio)

Description: Handles the mouse button release event

The behaviour of this callback is the same than for mouse_press_event, except that it is called when the mouse button is released.

mouse_click_event

Signature: [virtual] bool mouse_click_event (const DPoint p,unsigned int buttons,bool prio)

Description: Handles the mouse button click event (after the button has been released)

The behaviour of this callback is the same than for mouse_press_event, except that it is called when the mouse button has been released without moving it.

mouse_double_click_event

Signature: [virtual] bool mouse_double_click_event (const DPoint p,unsigned int buttons,bool prio)

Description: Handles the mouse button double-click event

The behaviour of this callback is the same than for mouse_press_event, except that it is called when the mouse button has been double-clicked.

mouse_moved_event

Signature: [virtual] bool mouse_moved_event (const DPoint p,unsigned int buttons,bool prio)

Description: Handles the mouse move event

The behaviour of this callback is the same than for mouse_press_event, except that it is called when the mouse is moved in the canvas area.

new

Signature: [static] new Plugin ptr new

Description: Creates a new object of this class

Python specific notes:
This method is the default initializer of the object

set_cursor

Signature: void set_cursor (int cursor_type)

Description: Sets the cursor in the view area to the given type

Setting the cursor has an effect only inside event handlers, i.e. mouse_press_event. The cursor is not set permanently. Is is reset in the mouse move handler unless a button is pressed or the cursor is explicitly set again in the mouse_move_event.

The cursor type is one of the cursor constants in the Cursor class, i.e. 'CursorArrow' for the normal cursor.

ungrab_mouse

Signature: void ungrab_mouse

Description: Removes a mouse grab registered with grab_mouse.

update

Signature: [virtual] void update

Description: Gets called when the view has changed

This method is called in particular if the view has changed the visible rectangle, i.e. after zooming in or out or panning. This callback can be used to update any internal states that depend on the view's state.

wheel_event

Signature: [virtual] bool wheel_event (int delta,bool horizontal,const DPoint p,unsigned int buttons,bool prio)

Description:

The behaviour of this callback is the same than for mouse_press_event, except that it is called when the mouse wheel is rotated. Additional parameters for this event are 'delta' (the rotation angle in units of 1/8th degree) and 'horizontal' which is true when the horizontal wheel was rotated and false if the vertical wheel was rotated.