Add qt:inherits; qt:find returns “lowest” type

qt:inherits returns whether or not a QObject
inherits a class of the given name.
Rather than checking equality with qt:classname
internally for qt:add, we now check for
inheritance with qt:inherits.

Now, rather than returning solely <qt-object>,
qt:find will return the most-specific supported
type, i.e. <qt-widget> or <qt-action>.
This commit is contained in:
Jaidyn Ann 2024-02-24 12:14:19 -06:00
parent 694da457b0
commit 7e19dd1a92
3 changed files with 21 additions and 4 deletions

View File

@ -464,6 +464,7 @@ int qt_propertytype(qtwidget w, char *prop)
const char *qt_classname(qtobject w) { return w->metaObject()->className(); }
___bool qt_inherits(qtobject w, const char *classname) { return w->inherits(classname); }
qtwidget qt_gl(char *name, qtwidget parent, C_word proc) { return new OpenGLWidget(name, parent, proc); }
void qt_update(qtwidget w) { w->update(); }

View File

@ -19,6 +19,7 @@ qtobject qt_find(qtobject parent, char *name);
qtobject qt_receiver(char *name, C_word proc);
int qt_message(char *caption, char *text, qtwidget parent, char *b0, char *b1, char *b2, int msg_type);
const char *qt_classname(qtobject w);
___bool qt_inherits(qtobject w, const char *classname);
___bool qt_setstringproperty(qtwidget w, char *prop, char *val);
___bool qt_setboolproperty(qtwidget w, char *prop, ___bool val);
___bool qt_setintproperty(qtwidget w, char *prop, int val);

View File

@ -7,7 +7,7 @@
qt:widget qt:receiver qt:pixmap qt:icon qt:theme-icon qt:timer
qt:icon->pixmap qt:pixmap->icon
qt:property qt:gl qt:update qt:start qt:stop
qt:clear qt:add qt:item <qt> qt:classname
qt:clear qt:add qt:item <qt> qt:classname qt:inherits
<qt-object> <qt-widget> <qt-pixmap> <qt-icon> <qt-application>
<qt-receiver> <qt-timer> <qt-sound> <qt-text-edit>
<qt-action>
@ -107,6 +107,21 @@ extern "C" {
(if (procedure? to) (qt:receiver to) to)
(string-append "1" slot)) ) ) )
(define qt:find
(let ((qt:find qt:find))
(lambda (o name)
(let ((result (qt:find o name)))
(if result
(cond ((qt:inherits result "QTextEdit")
(qt:pointer->textedit (qt:->pointer result)))
((qt:inherits result "QWidget")
(qt:pointer->widget (qt:->pointer result)))
((qt:inherits result "QAction")
(qt:pointer->action (qt:->pointer result)))
(#t
result))
result)))))
(define qt:receiver
(let ((qt:receiver qt:receiver))
(lambda (thunk #!optional (name (gensym "qt:receiver")))
@ -197,9 +212,9 @@ extern "C" {
(qt:run once) ) ) )
(define (qt:add w x)
(cond ((string=? "QComboBox" (qt:classname w)) (qt:addcomboboxitem w x))
((string=? "QListWidget" (qt:classname w)) (qt:addlistwidgetitem w x))
((string=? "QTreeWidget" (qt:classname w)) (qt:addtreewidgetitem w x))
(cond ((qt:inherits w "QComboBox") (qt:addcomboboxitem w x))
((qt:inherits w "QListWidget") (qt:addlistwidgetitem w x))
((qt:inherits w "QTreeWidget") (qt:addtreewidgetitem w x))
(else (error 'qt:add "invalid widget" w x)) ) )
(define (qt:item w i) (and (positive? i) (qt:listwidgetitem w i)))