Description Usage Arguments Details Value Author(s) Examples
C++ libraries like Qt often expect/require clients to extend classes
in the API. qsetClass will define a class in terms of its name,
parent (single inheritance) and constructor. Methods are added with
with qsetMethod, qsetSlot, and qsetSignal. The
qsetProperty function defines new
properties. Calling qsetRefClass on an RQtClass creates
a corresponding “R5” reference class, thus unifying R/Qt
classes with the methods package.
1 2 3 4 5 6 7 8 9 10 11 12 | qsetClass(name, parent, constructor = function(...) parent(...),
where = topenv(parent.frame()))
qsetMethod(name, class, FUN,
access = c("public", "protected", "private"))
qsetSlot(signature, class, FUN,
access = c("public", "protected", "private"))
qsetSignal(signature, class,
access = c("public", "protected", "private"))
qsetProperty(name, class, type = NULL, read = function() this[[.name]],
write = function(val) this[[.name]] <- val, notify = NULL,
constant = FALSE, final = FALSE, stored = TRUE, user = FALSE)
qsetRefClass(Class, where = topenv(parent.frame()), ...)
|
name |
The name of the class or method. |
parent |
Object of |
constructor |
A function for constructing an instance. By default, arguments are passed to parent constructor. See details. |
where |
The environment in which to define the class. Behaves like
|
class, Class |
Object of |
FUN |
The function that implements the method. |
access |
The access modifier; same meaning as in C++. |
signature |
The name and types of the arguments. If there are no arguments, and
the no return value, this is just the name. Otherwise, provide the
signature in C++ syntax, as in: |
type |
The type name for the property |
read |
The function for reading (getting) the value of this
property. By default, this assumes the property is stored as a
field named of the form |
write |
The function for writing (setting) the value of this
property. By default, this assumes the property is stored as a
field named of the form |
notify |
The name of a previously defined signal that is emitted
when the property is modified, or |
constant |
A hint to Qt that the property does not change; not actually enforced and rarely used. |
final |
A hint to Qt that the property is not to be overridden; not actually enforced and rarely used. |
stored |
A hint to Qt that the property is stored in the object, i.e., not dynamically computed. Could be helpful when serializing objects. |
user |
Whether the property is the primary user-facing property for this
class. Like the current value for a scrollbar. Used when autowiring
widgets to data models, as in |
... |
Additional arguments to pass to |
The side-effect of qsetClass is that a RQtClass object
for the new R class is assigned into the where argument.
Within the scope of a method or constructor, the symbols are first resolved against the members of the class (including inherited members). The search then procedes to the enclosure of the R function, and on up the conventional search path.
For chaining up, there is a special function named super that
is defined differently for methods and constructors. Within a
constructor, super will invoke the constructor of the super
class, as in Java. For a method, the first argument passed to
super should be the name of the method in the parent class to
invoke (also similar to Java).
For qsetClass, the RQtClass object (supports chaining
with qsetMethod).
For qsetMethod, qsetSlot, qsetSignal, and
qsetProperty, the name of the method/property (supports
chaining).
For qsetRefClass, the reference class generator object
corresponding to the R/C++ class.
Michael Lawrence
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | e <- Qt$QLineEdit()
qsetClass("positiveValidator", Qt$QValidator)
qsetMethod("validate", positiveValidator, function(input, pos) {
val <- suppressWarnings(as.integer(input))
if (!is.na(val)) {
if (val > 0)
Qt$QValidator$Acceptable
else Qt$QValidator$Invalid
} else {
if (input == "")
Qt$QValidator$Acceptable
else Qt$QValidator$Invalid
}
})
v <- positiveValidator(e)
e$setValidator(v)
e$show()
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.