| | 250 | |
| | 251 | === Mapping Qt Classes to JavaScript === |
| | 252 | |
| | 253 | Qt's introspection capabilities can be used to set up a JS inheritance chain that corresponds to the C++ inheritance. |
| | 254 | |
| | 255 | * QMetaObject::superClass() provides the meta-object of a class's super class. |
| | 256 | * QMetaObject::propertyOffset() provides the offset of a class's own properties. QMetaObject::propertyCount() - QMetaObject::propertyOffset() gives the number of properties defined by the class itself (i.e. not including inherited properties). |
| | 257 | * QMetaObject::methodOffset() provides the offset of a class's own methods. QMetaObject::methodCount() - QMetaObject::methodOffset() gives the number of methods defined by the class itself (i.e. not including inherited methods). |
| | 258 | |
| | 259 | The idea is to define a JS class (JSClassCreate() and friends in the JSC C API) that defines the class's own properties (corresponding to C++ properties), and that inherits the JS super-class. Each JS class also has a prototype object that contains the class's own methods (corresponding to C++ methods). |
| | 260 | |
| | 261 | Example: QPushButton; see http://doc.trolltech.com/4.6/qpushbutton.html. (This would probably work better as a diagram:) |
| | 262 | |
| | 263 | * JSClass(QPushButton).properties = autoDefault, default, flat |
| | 264 | * JSPrototype(QPushButton).properties = showMenu |
| | 265 | * JSPrototype(QPushButton).__proto__ = JSPrototype(QAbstractButton) |
| | 266 | * JSClass(QPushButton).superClass = JSClass(QAbstractButton) |
| | 267 | |
| | 268 | * JSClass(QAbstractButton).properties = autoExclusive, autoRepeat, ... |
| | 269 | * JSPrototype(QAbstractButton).properties = animateClick, click, setChecked, setIconSize, toggle |
| | 270 | * JSPrototype(QAbstractButton).__proto__ = JSPrototype(QWidget) |
| | 271 | * JSClass(QAbstractButton).superClass = JSClass(QWidget) |
| | 272 | |
| | 273 | ... and so on, all the way down to QObject. |
| | 274 | |
| | 275 | These class definitions and prototype objects can be created on demand, and cached so that they can be shared by all wrapped objects of the same type. |