[Kde-bindings] KDE/kdebindings/perl

Chris Michael Burel chrisburel at gmail.com
Mon Aug 16 05:36:42 UTC 2010


SVN commit 1164153 by burel:

Add a macro, DEF_ABSTRACT_ITEM_MODEL_FLAGS, that will make a function to call flags() for a subclass of QAbstractItemModel.  This is necessary for calls to this->SUPER::flags() when subclassing one of those classes in Perl.
Use that macro to define methods for all subclasses of QAbstractItemModel that reimplement the flags() method.
This workflow may be necessary for other methods of QAbstractItemModel as well.
Update the sql examples to use the new Qt::Sql Perl module.

CCMAIL: kde-bindings at kde.org


 M  +2 -0      qtcore/src/QtCore4.xs  
 M  +2 -22     qtcore/src/util.cpp  
 M  +46 -1     qtcore/src/util.h  
 M  +1 -0      qtgui/examples/sql/Connection.pm  
 M  +1 -0      qtgui/examples/sql/cachedtable/TableEditor.pm  
 M  +2 -0      qtgui/examples/sql/drilldown/InformationWindow.pm  
 M  +1 -0      qtgui/examples/sql/masterdetail/Database.pm  
 M  +1 -0      qtgui/examples/sql/masterdetail/Dialog.pm  
 M  +5 -1      qtgui/examples/sql/masterdetail/MainWindow.pm  
 M  +1 -0      qtgui/examples/sql/querymodel/CustomSqlModel.pm  
 M  +1 -0      qtgui/examples/sql/querymodel/EditableSqlModel.pm  
 M  +1 -0      qtgui/examples/sql/sqlwidgetmapper/Window.pm  
 M  +24 -0     qtgui/src/QtGui4.xs  
 M  +6 -0      qtsql/src/QtSql4.xs  


--- trunk/KDE/kdebindings/perl/qtcore/src/QtCore4.xs #1164152:1164153
@@ -435,6 +435,8 @@
     newXS("Qt::Object::qobject_cast", XS_qobject_qt_metacast, __FILE__);
     newXS(" Qt::AbstractItemModel::columnCount", XS_qabstract_item_model_columncount, __FILE__);
     newXS(" Qt::AbstractItemModel::data", XS_qabstract_item_model_data, __FILE__);
+    newXS(" Qt::AbstractItemModel::flags", XS_QAbstractItemModel_flags, __FILE__);
+    newXS("Qt::AbstractItemModel::flags", XS_QAbstractItemModel_flags, __FILE__);
     newXS(" Qt::AbstractItemModel::insertColumns", XS_qabstract_item_model_insertcolumns, __FILE__);
     newXS(" Qt::AbstractItemModel::insertRows", XS_qabstract_item_model_insertrows, __FILE__);
     newXS(" Qt::AbstractItemModel::removeColumns", XS_qabstract_item_model_removecolumns, __FILE__);
--- trunk/KDE/kdebindings/perl/qtcore/src/util.cpp #1164152:1164153
@@ -34,6 +34,7 @@
 #include "QtCore4.h"
 #include "binding.h"
 #include "smokeperl.h"
+#include "util.h"
 #include "marshall_types.h" // Method call classes
 #include "handlers.h" // for install_handlers function
 
@@ -1169,29 +1170,8 @@
     }
 }
 
-XS(XS_qabstract_item_model_flags) {
-    dXSARGS;
-    smokeperl_object *o = sv_obj_info(ST(0));
-    if(!o)
-        croak( "%s", "Qt::AbstractItemModel::flags called on a non-Qt4"
-            " object");
-    if(isDerivedFrom(o, "QAbstractItemModel") == -1)
-        croak( "%s", "Qt::AbstractItemModel::flags called on a"
-            " non-AbstractItemModel object");
-	QAbstractItemModel * model = (QAbstractItemModel *) o->ptr;
+DEF_ABSTRACT_ITEM_MODEL_FLAGS(AbstractItemModel)
 
-    smokeperl_object * mi = sv_obj_info(ST(1));
-    if(!mi)
-        croak( "%s", "1st argument to Qt::AbstractItemModel::flags is"
-            " not a Qt4 object");
-    if(isDerivedFrom(mi, "QModelIndex") == -1)
-        croak( "%s", "1st argument to Qt::AbstractItemModel::flags is"
-            " not a Qt::ModelIndex" );
-	const QModelIndex * modelIndex = (const QModelIndex *) mi->ptr;
-
-	XSRETURN_IV((IV)model->flags(*modelIndex));
-}
-
 XS(XS_qabstract_item_model_insertrows) {
     dXSARGS;
     smokeperl_object *o = sv_obj_info(ST(0));
--- trunk/KDE/kdebindings/perl/qtcore/src/util.h #1164152:1164153
@@ -71,6 +71,51 @@
 
 void unmapPointer(smokeperl_object* o, Smoke::Index classId, void* lastptr);
 
+/*
+This define will make a function to call flags() for a subclass of
+QAbstractItemModel.  This is necessary for calls to this->SUPER::flags() when
+subclassing one of those classes in Perl.  The last line is what is important.
+If you just write model->flags(), the virtual method call will go to the smoke
+subclass, which will look for a perl override of that method, which would end
+up coming back to this method = infinite recursion.  So we have to bypass the
+smoke subclass, to bypass calling a perl method again.  We get around it by
+calling model->(super class)::flags().  But for that to work correctly, we need
+separate methods for each subclass of QAbstractItemModel that reimplements
+flags(), to call the correct super class.
+*/
+
+#define DEF_ABSTRACT_ITEM_MODEL_FLAGS( CLASSNAME )\
+XS(XS_Q##CLASSNAME##_flags) {\
+    dXSARGS;\
+    int shiftStack = 0;\
+    if(items == 1)\
+        shiftStack = 1;\
+    smokeperl_object *o;\
+    if (shiftStack)\
+        o = sv_obj_info(sv_this);\
+    else\
+        o = sv_obj_info(ST(0));\
+\
+    if(!o)\
+        croak( "%s", "Qt::" #CLASSNAME "::flags called on a non-Qt4"\
+            " object");\
+    if(!Smoke::isDerivedFrom(o->smoke->classes[o->classId].className, "Q" #CLASSNAME))\
+        croak( "%s", "Qt::" #CLASSNAME "::flags called on a"\
+            " non-" #CLASSNAME " object");\
+	Q##CLASSNAME * model = (Q##CLASSNAME *) o->ptr;\
+\
+    smokeperl_object * modelindex = sv_obj_info(ST(1-shiftStack));\
+    if(!modelindex)\
+        croak( "%s", "1st argument to Qt::" #CLASSNAME "::flags is"\
+            " not a Qt4 object");\
+    if(!Smoke::isDerivedFrom(modelindex->smoke->classes[modelindex->classId].className, "QModelIndex"))\
+        croak( "%s", "1st argument to Qt::" #CLASSNAME "::flags is"\
+            " not a Qt::ModelIndex" );\
+	const QModelIndex * modelIndex = (const QModelIndex *) modelindex->ptr;\
+\
+	XSRETURN_IV((IV)model->Q##CLASSNAME::flags(*modelIndex));\
+}
+
 XS(XS_qobject_qt_metacast);
 XS(XS_find_qobject_children);
 
@@ -78,7 +123,7 @@
 XS(XS_qabstract_item_model_columncount);
 XS(XS_qabstract_item_model_data);
 XS(XS_qabstract_item_model_setdata);
-XS(XS_qabstract_item_model_flags);
+XS(XS_QAbstractItemModel_flags);
 XS(XS_qabstract_item_model_insertrows);
 XS(XS_qabstract_item_model_insertcolumns);
 XS(XS_qabstract_item_model_removerows);
--- trunk/KDE/kdebindings/perl/qtgui/examples/sql/Connection.pm #1164152:1164153
@@ -4,6 +4,7 @@
 use warnings;
 use QtCore4;
 use QtGui4;
+use QtSql4;
 
 =begin
 
--- trunk/KDE/kdebindings/perl/qtgui/examples/sql/cachedtable/TableEditor.pm #1164152:1164153
@@ -4,6 +4,7 @@
 use warnings;
 use QtCore4;
 use QtGui4;
+use QtSql4;
 
 # [0]
 use QtCore4::isa qw( Qt::Dialog );
--- trunk/KDE/kdebindings/perl/qtgui/examples/sql/drilldown/InformationWindow.pm #1164152:1164153
@@ -4,6 +4,8 @@
 use warnings;
 use QtCore4;
 use QtGui4;
+use QtSql4;
+use QtCore4::debug qw(ambiguous);
 
 # [0]
 use QtCore4::isa qw( Qt::Dialog );
--- trunk/KDE/kdebindings/perl/qtgui/examples/sql/masterdetail/Database.pm #1164152:1164153
@@ -4,6 +4,7 @@
 use warnings;
 use QtCore4;
 use QtGui4;
+use QtSql4;
 
 sub createConnection
 {
--- trunk/KDE/kdebindings/perl/qtgui/examples/sql/masterdetail/Dialog.pm #1164152:1164153
@@ -4,6 +4,7 @@
 use warnings;
 use QtCore4;
 use QtGui4;
+use QtSql4;
 
 use QtCore4::isa qw( Qt::Dialog );
 use QtCore4::slots
--- trunk/KDE/kdebindings/perl/qtgui/examples/sql/masterdetail/MainWindow.pm #1164152:1164153
@@ -4,6 +4,8 @@
 use warnings;
 use QtCore4;
 use QtGui4;
+use QtSql4;
+use QtXml4;
 use QtCore4::isa qw( Qt::MainWindow );
 use QtCore4::slots
     about => [],
@@ -77,6 +79,7 @@
 sub showArtistProfile
 {
     my ($index) = @_;
+    $DB::single=1;
     my $record = this->{model}->relationModel(2)->record($index->row());
 
     my $name = $record->value('artist')->toString();
@@ -102,6 +105,7 @@
     my $year = $record->value('year')->toString();
     my $albumId = $record->value('albumid')->toString();
 
+    $DB::single=1;
     this->showArtistProfile(this->indexOfArtist($artist));
     this->{titleLabel}->setText(sprintf this->tr('Title: %s (%s)'), $title, $year);
     this->{titleLabel}->show();
@@ -373,7 +377,7 @@
 
     foreach my $i (0..$artistModel->rowCount()-1) {
         my $record = $artistModel->record($i);
-        if ($record->value('artist') eq $artist) {
+        if ($record->value('artist')->toString() eq $artist) {
             return $artistModel->index($i, 1);
         }
     }
--- trunk/KDE/kdebindings/perl/qtgui/examples/sql/querymodel/CustomSqlModel.pm #1164152:1164153
@@ -4,6 +4,7 @@
 use warnings;
 use QtCore4;
 use QtGui4;
+use QtSql4;
 use QtCore4::isa qw( Qt::SqlQueryModel );
 
 sub NEW
--- trunk/KDE/kdebindings/perl/qtgui/examples/sql/querymodel/EditableSqlModel.pm #1164152:1164153
@@ -4,6 +4,7 @@
 use warnings;
 use QtCore4;
 use QtGui4;
+use QtSql4;
 use QtCore4::isa qw( Qt::SqlQueryModel );
 
 sub NEW
--- trunk/KDE/kdebindings/perl/qtgui/examples/sql/sqlwidgetmapper/Window.pm #1164152:1164153
@@ -4,6 +4,7 @@
 use warnings;
 use QtCore4;
 use QtGui4;
+use QtSql4;
 
 # [Window definition]
 use QtCore4::isa qw( Qt::Widget );
--- trunk/KDE/kdebindings/perl/qtgui/src/QtGui4.xs #1164152:1164153
@@ -18,6 +18,13 @@
 #include <QHash>
 #include <QList>
 #include <QtDebug>
+#include <QtGui/QAbstractProxyModel>
+#include <QtGui/QSortFilterProxyModel>
+#include <QtGui/QDirModel>
+#include <QtGui/QFileSystemModel>
+#include <QtGui/QProxyModel>
+#include <QtGui/QStandardItemModel>
+#include <QtGui/QStringListModel>
 
 #include <iostream>
 
@@ -33,6 +40,7 @@
 
 #include <smokeperl.h>
 #include <handlers.h>
+#include <util.h>
 
 extern QList<Smoke*> smokeList;
 
@@ -46,6 +54,14 @@
 
 static PerlQt4::Binding bindingqtgui;
 
+DEF_ABSTRACT_ITEM_MODEL_FLAGS(AbstractProxyModel)
+DEF_ABSTRACT_ITEM_MODEL_FLAGS(DirModel)
+DEF_ABSTRACT_ITEM_MODEL_FLAGS(FileSystemModel)
+DEF_ABSTRACT_ITEM_MODEL_FLAGS(ProxyModel)
+DEF_ABSTRACT_ITEM_MODEL_FLAGS(SortFilterProxyModel)
+DEF_ABSTRACT_ITEM_MODEL_FLAGS(StandardItemModel)
+DEF_ABSTRACT_ITEM_MODEL_FLAGS(StringListModel)
+
 MODULE = QtGui4            PACKAGE = QtGui4::_internal
 
 PROTOTYPES: DISABLE
@@ -91,3 +107,11 @@
     perlqt_modules[qtgui_Smoke] = module;
 
     install_handlers(QtGui4_handlers);
+    newXS("Qt::AbstractProxyModel::flags", XS_QAbstractProxyModel_flags, __FILE__);
+    newXS("Qt::DirModel::flags", XS_QDirModel_flags, __FILE__);
+    newXS("Qt::FileSystemModel::flags", XS_QFileSystemModel_flags, __FILE__);
+    newXS("Qt::ProxyModel::flags", XS_QProxyModel_flags, __FILE__);
+    newXS("Qt::SortFilterProxyModel::flags", XS_QSortFilterProxyModel_flags, __FILE__);
+    newXS("Qt::StandardItemModel::flags", XS_QStandardItemModel_flags, __FILE__);
+    newXS("Qt::StringListModel::flags", XS_QStringListModel_flags, __FILE__);
+
--- trunk/KDE/kdebindings/perl/qtsql/src/QtSql4.xs #1164152:1164153
@@ -18,6 +18,7 @@
 #include <QHash>
 #include <QList>
 #include <QtDebug>
+#include <QSqlTableModel>
 
 #include <iostream>
 
@@ -33,6 +34,7 @@
 
 #include <smokeperl.h>
 #include <handlers.h>
+#include <util.h>
 
 extern QList<Smoke*> smokeList;
 
@@ -46,6 +48,8 @@
 
 static PerlQt4::Binding bindingqtsql;
 
+DEF_ABSTRACT_ITEM_MODEL_FLAGS(SqlTableModel);
+
 MODULE = QtSql4            PACKAGE = QtSql4::_internal
 
 PROTOTYPES: DISABLE
@@ -89,3 +93,5 @@
     perlqt_modules[qtsql_Smoke] = module;
 
     install_handlers(QtSql4_handlers);
+
+    newXS("Qt::SqlTableModel::flags", XS_QSqlTableModel_flags, __FILE__);



More information about the Kde-bindings mailing list