qlayer: Create a layer

Description Usage Arguments Details Value Author(s) Examples

View source: R/layer.R

Description

This function constructs a Layer, an item in the canvas that may paint part of the plot and/or respond to user input. The behavior of the layer is implemented using R functions, which are passed to the constructor. Other arguments determine the scaling and positioning of the layer, and whether the drawing of the layer is cached and/or clipped.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
qlayer(parent=NULL, paintFun=NULL, keyPressFun=NULL,
              keyReleaseFun=NULL, mouseDoubleClickFun=NULL,
              mouseMoveFun=NULL, mousePressFun=NULL,
              mouseReleaseFun=NULL, wheelFun=NULL,
              hoverMoveFun=NULL, hoverEnterFun=NULL, hoverLeaveFun=NULL,
              contextMenuFun=NULL, dragEnterFun=NULL, dragLeaveFun=NULL,
              dragMoveFun=NULL, dropFun=NULL, focusInFun=NULL,
              focusOutFun=NULL, sizeHintFun=NULL, limits=qrect(),
              row=0, col=0, rowSpan=1,
              colSpan=1, geometry=defaultLayerGeometry(parent),
              clip=cache, cache=FALSE)

Arguments

parent

The scene, for a top-level layer, or the parent layer that contains the new layer in a grid layout

paintFun

The function that implements painting, called whenever the layer needs to be repainted. All drawing occurs in data/layer coordinates.

keyPressFun

The function called when a key is pressed

keyReleaseFun

The function called when a key is released

mouseDoubleClickFun

The function called when a mouse button is double-clicked

mouseMoveFun

The function called when the mouse is moved while holding down a button

mousePressFun

The function called when a mouse button is pressed

mouseReleaseFun

The function called when a mouse button is released

wheelFun

The function called when the mouse wheel is turned

hoverMoveFun

The function called when the mouse moves without any buttons pressed

hoverEnterFun

The function called when the mouse pointer enters the layer

hoverLeaveFun

The function called when the mouse pointer leaves the layer

contextMenuFun

The function called when a context menu is requested, such as through a right mouse button click

dragEnterFun

The function called when the pointer enters the layer while dragging something

dragLeaveFun

The function called when the pointer leaves the layer while dragging something

dragMoveFun

The function called when the pointer moves within the layer while dragging something

dropFun

The function called when something is dropped on the layer

focusInFun

The function called when the layer gains the keyboard focus

focusOutFun

The function called when the layer loses the keyboard focus

sizeHintFun

The function called to determine the size constraints of the layer. Not currently documented.

limits

A QRectF, possibly created by qrect, indicating the X and Y scales of the layer in data/layer coordinates

row

The 0-based row index of the layer in the parent grid layout

col

The 0-based column index of the layer in the parent grid layout

rowSpan

The 0-based number of rows spanned by the layer in the layout

colSpan

The 0-based number of cols spanned by the layer in the layout

geometry

A QRectF, possibly created by qrect, indicating the position and size of the layer in figure/scene coordinates. This is overridden by the parent grid layout, so is really only useful for a top-level layer. A warning will be issued if the geometry is specified along with a parent layer. We also issue a warning if this argument is specified when the scene has a view in "geometry" rescale mode, because the view determines the geometry. The default geometry is the bounding rectangle of the scene, if not null, or 600x400 otherwise.

clip

Logical indicating whether to clip drawing to within the layer

cache

Logical indicating whether to cache drawing, which helps performance for relatively static layers sitting under more dynamic ones

Details

All drawing and user input handling is performed by R callbacks, which must accept a specific set of arguments. The paint callback, passed as paintFun, must take at least two arguments, conventionally named layer and painter. The layer argument is a C++ RLayer object, the same instance that was created by calling the constructor. All painting is performed through the painter argument, which is a C++ Painter object. See the paint functions for more details. The paintFun may take one additional, optional argument, conventionally named exposed, which is the rectangle, in layer coordinates, that needs to be drawn.

All of the other callbacks, except for sizeHintFun, are event handlers. Two arguments are passed, conventionally named layer and event. The former is the layer constructed in the call to qlayer, and the latter describes the event as an instance of C++ QGraphicsSceneEvent. The exact subclass depends on the event. Manipulating an event currently requires low-level calls through the qtbase package. See its documentation.

Value

The layer, a C++ instance of RLayer

Author(s)

Michael Lawrence

Examples

1
2
3
4
5
scene <- qscene()
layer <- qlayer(scene, function(layer, painter) {
qdrawCircle(painter, 1:10, 1:10, 1)
}, limits = qtbase::qrect(0, 0, 11, 11))
qplotView(scene)

ggobi/qtpaint documentation built on May 17, 2019, 3:15 a.m.