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 methods
package.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()), ...)
RQtClass
representing the parent. Only
single inheritance is supported.setClass
. Usually not specified.RQtClass
on which to define the method.public
methods
may be invoked from any context, protected
only by methods of
this class or a subclass, and private
only by methods of this
class.int myMethod(int, const
char*)
for a method named myMethod
that accepts two
parameters, one an integer and one a string, and then returns an
integer. We are essentially using C++ as a DSL for specifying
signatures; the types must be C++ types, because this method is made
available to external systems (like DBus and Javascript via
QtWebKit)..name
..name
.NULL
for none.QDataWidgetMapper
.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.
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).
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()
Run the code above in your browser using DataLab