From 7e19dd1a92839360d1a8acdd8575c4d1b4b00d47 Mon Sep 17 00:00:00 2001 From: Jaidyn Ann <10477760+JadedCtrl@users.noreply.github.com> Date: Sat, 24 Feb 2024 12:14:19 -0600 Subject: [PATCH] =?UTF-8?q?Add=20qt:inherits;=20qt:find=20returns=20?= =?UTF-8?q?=E2=80=9Clowest=E2=80=9D=20type?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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:find will return the most-specific supported type, i.e. or . --- main.cpp | 1 + prototypes.h | 1 + qt-light.scm | 23 +++++++++++++++++++---- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/main.cpp b/main.cpp index ef37ee6..39dd024 100644 --- a/main.cpp +++ b/main.cpp @@ -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(); } diff --git a/prototypes.h b/prototypes.h index 161e7c7..1c86110 100644 --- a/prototypes.h +++ b/prototypes.h @@ -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); diff --git a/qt-light.scm b/qt-light.scm index 5941fb6..0324a72 100644 --- a/qt-light.scm +++ b/qt-light.scm @@ -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:classname + qt:clear qt:add qt:item qt:classname qt:inherits @@ -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)))