diff --git a/Jenkinsfile b/Jenkinsfile index 2bbadf168..1b3f64cff 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -31,8 +31,10 @@ node("master") { parallel( "Publish": { - // from shared library - publish(BRANCH_NAME, target, target_dir) + // from shared library - only publish for normal branch, not for PR + if (! BRANCH_NAME.startsWith('PR')) { + publish(BRANCH_NAME, target, target_dir) + } }, "Unit testing": { diff --git a/scripts/mkqtdecl.sh b/scripts/mkqtdecl.sh index d7b9605ee..a0b86ccb3 100755 --- a/scripts/mkqtdecl.sh +++ b/scripts/mkqtdecl.sh @@ -170,7 +170,7 @@ if [ $update != 0 ]; then if [ $reuse == 0 ]; then - for d in Qt*; do + for d in $qt_mods; do echo "--------------------------------------------------------" echo "Parsing $d ..." @@ -181,7 +181,7 @@ if [ $update != 0 ]; then echo "Running gcc preprocessor .." # By using -D_GCC_LIMITS_H_ we make the gcc not include constants such as ULONG_MAX which will # remain as such. This way the generated code is more generic. - gcc -I$qt -fPIC -D_GCC_LIMITS_H_ -E -o allofqt.x allofqt.cpp + gcc -std=gnu++98 -I$qt -fPIC -D_GCC_LIMITS_H_ -E -o allofqt.x allofqt.cpp echo "Stripping hash lines .." egrep -v '^#' allofqt.e @@ -225,7 +225,7 @@ else cd $work_dir fi -for d in Qt*; do +for d in $qt_mods; do echo "--------------------------------------------------------" echo "Processing $d ..." diff --git a/scripts/mkqtdecl4/mkqtdecl.conf b/scripts/mkqtdecl4/mkqtdecl.conf index edb13c79e..768518232 100644 --- a/scripts/mkqtdecl4/mkqtdecl.conf +++ b/scripts/mkqtdecl4/mkqtdecl.conf @@ -482,6 +482,10 @@ drop_method "QClipboardEvent", /QClipboardEvent::data/ drop_method "QClipboardEvent", /QClipboardEvent::QClipboardEvent\(QEventPrivate/ drop_method "QCursor", /QCursor::QCursor\s*\(\s*Qt::HANDLE/ # not available on WIN drop_method "QApplication", /QApplication::compressEvent/ # QPostEventList is missing +drop_method "QApplication", /QApplication::commitDataRequest/ # Signal with a out argument (QSessionManager &) +drop_method "QApplication", /QApplication::saveStateRequest/ # Signal with a out argument (QSessionManager &) +drop_method "QApplication", /QApplication::saveState\s*\(/ # QSessionManager is not always available +drop_method "QApplication", /QApplication::commitData\s*\(/ # QSessionManager is not always available drop_method "QWidget", /QWidget::painters/ # whatever that is, it's not a method .. drop_method "QWidget", /QWidget::handle/ # not available on WIN drop_method "QPixmap", /QPixmap::handle/ # not available on WIN @@ -597,6 +601,7 @@ rename "QIcon", /QIcon::pixmap\(int\s+extent/, "pixmap_ext" rename "QKeySequence", /QKeySequence::QKeySequence\(QKeySequence::StandardKey/, "new_std" keep_arg "QBoxLayout", /::addLayout/, 0 # will take ownership of layout keep_arg "QGridLayout", /::addLayout/, 0 # will take ownership of layout +keep_arg "QWidget", /::setLayout\s*\(/, 0 # will take ownership of layout keep_arg "QLayout", /::addChildLayout/, 0 # will take ownership of layout keep_arg "QLayout", /::addItem/, 0 # will take ownership of item keep_arg "QTreeWidgetItem", /::addChild\(/, 0 # will take ownership of the child @@ -618,6 +623,8 @@ keep_arg "QGraphicsScene", /::addItem\(/, 0 # will take ownership of the item owner_arg "QTreeWidgetItem", /::QTreeWidgetItem\(QTreeWidgetItem\s+\*/, 0 # will construct a new object owned by arg #0 owner_arg "QTreeWidgetItem", /::QTreeWidgetItem\(QTreeWidget\s+\*/, 0 # will construct a new object owned by arg #0 owner_arg "QListWidgetItem", /::QListWidgetItem\(QListWidget\s+\*/, 0 # will construct a new object owned by arg #0 +owner_arg "QObject", /::setParent\(QObject\s+\*/, 0 # will make self owned by arg #0 +owner_arg "QWidget", /::setParent\(QWidget\s+\*/, 0 # will make self owned by arg #0 # this would make sense, but the pointer is const: so how can setItemPrototype take # over ownership of it? # keep_arg "QTableWidget", /::setItemPrototype\(/, 0 # will take ownership of the child diff --git a/scripts/mkqtdecl5/mkqtdecl.conf b/scripts/mkqtdecl5/mkqtdecl.conf index 097ebb151..f82d80d16 100644 --- a/scripts/mkqtdecl5/mkqtdecl.conf +++ b/scripts/mkqtdecl5/mkqtdecl.conf @@ -713,6 +713,7 @@ rename "QIcon", /QIcon::pixmap\(int\s+extent/, "pixmap_ext" rename "QKeySequence", /QKeySequence::QKeySequence\(QKeySequence::StandardKey/, "new_std" keep_arg "QBoxLayout", /::addLayout/, 0 # will take ownership of layout keep_arg "QGridLayout", /::addLayout/, 0 # will take ownership of layout +keep_arg "QWidget", /::setLayout\s*\(/, 0 # will take ownership of layout keep_arg "QLayout", /::addChildLayout/, 0 # will take ownership of layout keep_arg "QLayout", /::addItem/, 0 # will take ownership of item keep_arg "QTreeWidgetItem", /::addChild\(/, 0 # will take ownership of the child @@ -734,6 +735,8 @@ keep_arg "QGraphicsScene", /::addItem\(/, 0 # will take ownership of the item owner_arg "QTreeWidgetItem", /::QTreeWidgetItem\(QTreeWidgetItem\s+\*/, 0 # will construct a new object owned by arg #0 owner_arg "QTreeWidgetItem", /::QTreeWidgetItem\(QTreeWidget\s+\*/, 0 # will construct a new object owned by arg #0 owner_arg "QListWidgetItem", /::QListWidgetItem\(QListWidget\s+\*/, 0 # will construct a new object owned by arg #0 +owner_arg "QObject", /::setParent\(QObject\s+\*/, 0 # will make self owned by arg #0 +owner_arg "QWidget", /::setParent\(QWidget\s+\*/, 0 # will make self owned by arg #0 # this would make sense, but the pointer is const: so how can setItemPrototype take # over ownership of it? # keep_arg "QTableWidget", /::setItemPrototype\(/, 0 # will take ownership of the child diff --git a/scripts/mkqtdecl_common/c++.treetop b/scripts/mkqtdecl_common/c++.treetop index 23115130a..a4603c21e 100644 --- a/scripts/mkqtdecl_common/c++.treetop +++ b/scripts/mkqtdecl_common/c++.treetop @@ -50,7 +50,7 @@ grammar CPP end rule a - s ( "__attribute__" s attribute_value s / "__asm" s attribute_value s / "__extension__" s )* + s ( "__attribute__" s attribute_value s / "__asm" s attribute_value s / "__extension__" s / "decltype" s attribute_value s )* end rule unary_op @@ -110,11 +110,11 @@ grammar CPP end rule bool_type - "bool" + "bool" ![a-zA-Z0-9_] end rule void_type - "void" + "void" ![a-zA-Z0-9_] end rule float_type @@ -134,12 +134,20 @@ grammar CPP end rule virtual_spec - "virtual" + "virtual" ![a-zA-Z0-9_] + end + + rule explicit_key + "explicit" ![a-zA-Z0-9_] + end + + rule mutable_key + "mutable" ![a-zA-Z0-9_] end rule member_declaration_wo_semicolon template:( d:template_decl s )? - attr:( ( "explicit" / "mutable" / storage_class / inline_spec / virtual_spec ) s )* + attr:( ( explicit_key / mutable_key / storage_class / inline_spec / virtual_spec / constexpr_key ) s )* t:type # type declaration ends with a } .. does not need a semicolon # (i.e. nested struct or enum) @@ -155,7 +163,7 @@ grammar CPP rule member_declaration_w_semicolon template:( d:template_decl s )? - attr:( ( "explicit" / "mutable" / storage_class / inline_spec / virtual_spec ) s )* + attr:( ( explicit_key / mutable_key / storage_class / inline_spec / virtual_spec / constexpr_key ) s )* t:type # opposite case (member_see declaration_wo_semicolon) # (i.e. nested struct or enum) @@ -214,11 +222,11 @@ grammar CPP end rule concrete_type - ( class_or_struct_type / enum_type / float_type / char_type / int_type / bool_type / void_type / typeof / class_id )? + ( constexpr_key / class_or_struct_type / enum_type / float_type / char_type / int_type / bool_type / void_type / typeof / class_id )? end rule cv - ( "const" ![a-zA-Z0-9_] / "__const" ![a-zA-Z0-9_] / "volatile" ![a-zA-Z0-9_] / "__volatile" ![a-zA-Z0-9_] ) + ( constexpr_key / "const" ![a-zA-Z0-9_] / "__const" ![a-zA-Z0-9_] / "volatile" ![a-zA-Z0-9_] / "__volatile" ![a-zA-Z0-9_] ) end rule pointer @@ -247,8 +255,12 @@ grammar CPP ellipsis end + rule noexcept_spec + "noexcept" ( s "=" s block / s "(" s block ")" )? + end + rule func_spec - "(" s fa:( a:func_args )? s ")" cvspec:( s cv:cv )? ( s "throw" s "(" s ( type_wo_comma s )? ")" )* a + "(" s fa:( a:func_args )? s ")" cvspec:( s cv:cv )? ( s "throw" s "(" s ( type_wo_comma s )? ")" / s noexcept_spec )* ( s override_key )? a end rule member_pointer @@ -308,6 +320,14 @@ grammar CPP ( "static" ![a-zA-Z0-9_] / "extern" ![a-zA-Z0-9_] ( s '"C"' / s '"C++"' / s '"Pascal"' )? ) end + rule override_key + "override" ![a-zA-Z0-9_] + end + + rule constexpr_key + "constexpr" ![a-zA-Z0-9_] + end + rule inline_spec "inline" ![a-zA-Z0-9_] end @@ -346,6 +366,10 @@ grammar CPP "using" ![a-zA-Z0-9_] ( s "namespace" )? ![a-zA-Z0-9_] s id:qualified_id a ";" end + rule static_assert + "static_assert" s "(" s block s ")" + end + rule typedef a "typedef" ![a-zA-Z0-9_] s t:type a ";" end @@ -362,8 +386,9 @@ grammar CPP rule declaration_w_semicolon template:( d:template_decl s )? template_member:( d_member:template_decl s )? - attr:( ( storage_class / inline_spec ) s )* + attr:( ( storage_class / inline_spec / constexpr_key ) s )* a + ( constexpr_key s )? t:type # type declaration ends with a } .. does not need a semicolon # (i.e. nested struct or enum) @@ -378,8 +403,9 @@ grammar CPP rule declaration_wo_semicolon template:( d:template_decl s )? - attr:( ( storage_class / inline_spec ) s )* + attr:( ( storage_class / inline_spec / constexpr_key ) s )* a + ( constexpr_key s )? t:type # opposite case (see declaration_wo_semicolon) # (i.e. nested struct or enum) @@ -398,7 +424,7 @@ grammar CPP rule namespace "namespace" ![a-zA-Z0-9_] s n:id - a "{" decls:( a ( ";" / using / typedef / namespace / declaration ) )* s "}" + a "{" decls:( a ( ";" / static_assert / using / typedef / namespace / declaration ) )* s "}" end rule extern_decl @@ -407,7 +433,7 @@ grammar CPP end rule module - ( a ( ";" / using / typedef / namespace / extern_decl / declaration ) )* s + ( a ( ";" / static_assert / using / typedef / namespace / extern_decl / declaration ) )* s end end diff --git a/scripts/mkqtdecl_common/produce.rb b/scripts/mkqtdecl_common/produce.rb index 4ab12220c..cd0fe496e 100755 --- a/scripts/mkqtdecl_common/produce.rb +++ b/scripts/mkqtdecl_common/produce.rb @@ -1669,6 +1669,18 @@ END end + def produce_keep_self(ofile, alist, obj, owner_args = []) + + owner_args.each do |a| + ofile.puts(" if (#{alist[a]}) {"); + ofile.puts(" qt_gsi::qt_keep (#{obj});") + ofile.puts(" } else {"); + ofile.puts(" qt_gsi::qt_release (#{obj});") + ofile.puts(" }"); + end + + end + def produce_arg_read(ofile, decl_obj, func, alist, kept_args = []) n_args = func.max_args @@ -2005,6 +2017,7 @@ END ofile.puts("{") ofile.puts(" __SUPPRESS_UNUSED_WARNING(args);") produce_arg_read(ofile, decl_obj, func, alist, conf.kept_args(bd)) + produce_keep_self(ofile, alist, "(#{cls} *)cls", conf.owner_args(bd)) if !rt.is_void? ofile.puts(" ret.write<#{rt.gsi_decl_return(decl_obj)} > ((#{rt.gsi_decl_return(decl_obj)})" + rt.access_gsi_return(decl_obj, "((#{cls} *)cls)->#{mid} (#{qt_alist.join(', ')})") + ");") else @@ -2615,11 +2628,7 @@ END produce_arg_read(ofile, decl_obj, func, alist, conf.kept_args(bd)) if conf.owner_args(bd).size > 0 ofile.puts(" #{clsn}_Adaptor *obj = new #{clsn}_Adaptor (#{qt_alist.join(', ')});") - conf.owner_args(bd).each do |a| - ofile.puts(" if (#{alist[a]}) {"); - ofile.puts(" qt_gsi::qt_keep (obj);") - ofile.puts(" }"); - end + produce_keep_self(ofile, alist, "obj", conf.owner_args(bd)) ofile.puts(" ret.write<#{clsn}_Adaptor *> (obj);") else ofile.puts(" ret.write<#{clsn}_Adaptor *> (new #{clsn}_Adaptor (#{qt_alist.join(', ')}));") diff --git a/src/gsiqt/qt4/QtCore/gsiDeclQObject.cc b/src/gsiqt/qt4/QtCore/gsiDeclQObject.cc index 600ea5c8d..8f699bde4 100644 --- a/src/gsiqt/qt4/QtCore/gsiDeclQObject.cc +++ b/src/gsiqt/qt4/QtCore/gsiDeclQObject.cc @@ -465,6 +465,11 @@ static void _call_f_setParent_1302 (const qt_gsi::GenericMethod * /*decl*/, void __SUPPRESS_UNUSED_WARNING(args); tl::Heap heap; QObject *arg1 = gsi::arg_reader() (args, heap); + if (arg1) { + qt_gsi::qt_keep ((QObject *)cls); + } else { + qt_gsi::qt_release ((QObject *)cls); + } __SUPPRESS_UNUSED_WARNING(ret); ((QObject *)cls)->setParent (arg1); } diff --git a/src/gsiqt/qt4/QtGui/gsiDeclQApplication.cc b/src/gsiqt/qt4/QtGui/gsiDeclQApplication.cc index 90a79d432..26dec4122 100644 --- a/src/gsiqt/qt4/QtGui/gsiDeclQApplication.cc +++ b/src/gsiqt/qt4/QtGui/gsiDeclQApplication.cc @@ -86,6 +86,21 @@ static void _call_f_inputContext_c0 (const qt_gsi::GenericMethod * /*decl*/, voi } +// bool QApplication::isSessionRestored() + + +static void _init_f_isSessionRestored_c0 (qt_gsi::GenericMethod *decl) +{ + decl->set_return (); +} + +static void _call_f_isSessionRestored_c0 (const qt_gsi::GenericMethod * /*decl*/, void *cls, gsi::SerialArgs &args, gsi::SerialArgs &ret) +{ + __SUPPRESS_UNUSED_WARNING(args); + ret.write ((bool)((QApplication *)cls)->isSessionRestored ()); +} + + // bool QApplication::notify(QObject *, QEvent *) @@ -108,6 +123,36 @@ static void _call_f_notify_2411 (const qt_gsi::GenericMethod * /*decl*/, void *c } +// QString QApplication::sessionId() + + +static void _init_f_sessionId_c0 (qt_gsi::GenericMethod *decl) +{ + decl->set_return (); +} + +static void _call_f_sessionId_c0 (const qt_gsi::GenericMethod * /*decl*/, void *cls, gsi::SerialArgs &args, gsi::SerialArgs &ret) +{ + __SUPPRESS_UNUSED_WARNING(args); + ret.write ((QString)((QApplication *)cls)->sessionId ()); +} + + +// QString QApplication::sessionKey() + + +static void _init_f_sessionKey_c0 (qt_gsi::GenericMethod *decl) +{ + decl->set_return (); +} + +static void _call_f_sessionKey_c0 (const qt_gsi::GenericMethod * /*decl*/, void *cls, gsi::SerialArgs &args, gsi::SerialArgs &ret) +{ + __SUPPRESS_UNUSED_WARNING(args); + ret.write ((QString)((QApplication *)cls)->sessionKey ()); +} + + // void QApplication::setAutoSipEnabled(const bool enabled) @@ -1488,7 +1533,10 @@ static gsi::Methods methods_QApplication () { methods += new qt_gsi::GenericStaticMethod ("staticMetaObject", "@brief Obtains the static MetaObject for this class.", &_init_smo, &_call_smo); methods += new qt_gsi::GenericMethod (":autoSipEnabled", "@brief Method bool QApplication::autoSipEnabled()\n", true, &_init_f_autoSipEnabled_c0, &_call_f_autoSipEnabled_c0); methods += new qt_gsi::GenericMethod (":inputContext", "@brief Method QInputContext *QApplication::inputContext()\n", true, &_init_f_inputContext_c0, &_call_f_inputContext_c0); + methods += new qt_gsi::GenericMethod ("isSessionRestored?", "@brief Method bool QApplication::isSessionRestored()\n", true, &_init_f_isSessionRestored_c0, &_call_f_isSessionRestored_c0); methods += new qt_gsi::GenericMethod ("notify", "@brief Method bool QApplication::notify(QObject *, QEvent *)\nThis is a reimplementation of QCoreApplication::notify", false, &_init_f_notify_2411, &_call_f_notify_2411); + methods += new qt_gsi::GenericMethod ("sessionId", "@brief Method QString QApplication::sessionId()\n", true, &_init_f_sessionId_c0, &_call_f_sessionId_c0); + methods += new qt_gsi::GenericMethod ("sessionKey", "@brief Method QString QApplication::sessionKey()\n", true, &_init_f_sessionKey_c0, &_call_f_sessionKey_c0); methods += new qt_gsi::GenericMethod ("setAutoSipEnabled|autoSipEnabled=", "@brief Method void QApplication::setAutoSipEnabled(const bool enabled)\n", false, &_init_f_setAutoSipEnabled_1559, &_call_f_setAutoSipEnabled_1559); methods += new qt_gsi::GenericMethod ("setInputContext|inputContext=", "@brief Method void QApplication::setInputContext(QInputContext *)\n", false, &_init_f_setInputContext_1972, &_call_f_setInputContext_1972); methods += new qt_gsi::GenericMethod ("setStyleSheet|styleSheet=", "@brief Method void QApplication::setStyleSheet(const QString &sheet)\n", false, &_init_f_setStyleSheet_2025, &_call_f_setStyleSheet_2025); diff --git a/src/gsiqt/qt4/QtGui/gsiDeclQListWidgetItem.cc b/src/gsiqt/qt4/QtGui/gsiDeclQListWidgetItem.cc index 4a6576d4f..f6e436e28 100644 --- a/src/gsiqt/qt4/QtGui/gsiDeclQListWidgetItem.cc +++ b/src/gsiqt/qt4/QtGui/gsiDeclQListWidgetItem.cc @@ -1028,6 +1028,8 @@ static void _call_ctor_QListWidgetItem_Adaptor_2386 (const qt_gsi::GenericStatic QListWidgetItem_Adaptor *obj = new QListWidgetItem_Adaptor (arg1, arg2); if (arg1) { qt_gsi::qt_keep (obj); + } else { + qt_gsi::qt_release (obj); } ret.write (obj); } diff --git a/src/gsiqt/qt4/QtGui/gsiDeclQTreeWidgetItem.cc b/src/gsiqt/qt4/QtGui/gsiDeclQTreeWidgetItem.cc index 3a1766447..868208584 100644 --- a/src/gsiqt/qt4/QtGui/gsiDeclQTreeWidgetItem.cc +++ b/src/gsiqt/qt4/QtGui/gsiDeclQTreeWidgetItem.cc @@ -1600,6 +1600,8 @@ static void _call_ctor_QTreeWidgetItem_Adaptor_2374 (const qt_gsi::GenericStatic QTreeWidgetItem_Adaptor *obj = new QTreeWidgetItem_Adaptor (arg1, arg2); if (arg1) { qt_gsi::qt_keep (obj); + } else { + qt_gsi::qt_release (obj); } ret.write (obj); } @@ -1628,6 +1630,8 @@ static void _call_ctor_QTreeWidgetItem_Adaptor_4703 (const qt_gsi::GenericStatic QTreeWidgetItem_Adaptor *obj = new QTreeWidgetItem_Adaptor (arg1, arg2, arg3); if (arg1) { qt_gsi::qt_keep (obj); + } else { + qt_gsi::qt_release (obj); } ret.write (obj); } @@ -1656,6 +1660,8 @@ static void _call_ctor_QTreeWidgetItem_Adaptor_4380 (const qt_gsi::GenericStatic QTreeWidgetItem_Adaptor *obj = new QTreeWidgetItem_Adaptor (arg1, arg2, arg3); if (arg1) { qt_gsi::qt_keep (obj); + } else { + qt_gsi::qt_release (obj); } ret.write (obj); } @@ -1681,6 +1687,8 @@ static void _call_ctor_QTreeWidgetItem_Adaptor_2773 (const qt_gsi::GenericStatic QTreeWidgetItem_Adaptor *obj = new QTreeWidgetItem_Adaptor (arg1, arg2); if (arg1) { qt_gsi::qt_keep (obj); + } else { + qt_gsi::qt_release (obj); } ret.write (obj); } @@ -1709,6 +1717,8 @@ static void _call_ctor_QTreeWidgetItem_Adaptor_5102 (const qt_gsi::GenericStatic QTreeWidgetItem_Adaptor *obj = new QTreeWidgetItem_Adaptor (arg1, arg2, arg3); if (arg1) { qt_gsi::qt_keep (obj); + } else { + qt_gsi::qt_release (obj); } ret.write (obj); } @@ -1737,6 +1747,8 @@ static void _call_ctor_QTreeWidgetItem_Adaptor_4779 (const qt_gsi::GenericStatic QTreeWidgetItem_Adaptor *obj = new QTreeWidgetItem_Adaptor (arg1, arg2, arg3); if (arg1) { qt_gsi::qt_keep (obj); + } else { + qt_gsi::qt_release (obj); } ret.write (obj); } diff --git a/src/gsiqt/qt4/QtGui/gsiDeclQWidget.cc b/src/gsiqt/qt4/QtGui/gsiDeclQWidget.cc index 415ee9fa0..b93f0777d 100644 --- a/src/gsiqt/qt4/QtGui/gsiDeclQWidget.cc +++ b/src/gsiqt/qt4/QtGui/gsiDeclQWidget.cc @@ -2775,6 +2775,7 @@ static void _call_f_setLayout_1341 (const qt_gsi::GenericMethod * /*decl*/, void __SUPPRESS_UNUSED_WARNING(args); tl::Heap heap; QLayout *arg1 = gsi::arg_reader() (args, heap); + qt_gsi::qt_keep (arg1); __SUPPRESS_UNUSED_WARNING(ret); ((QWidget *)cls)->setLayout (arg1); } @@ -3081,6 +3082,11 @@ static void _call_f_setParent_1315 (const qt_gsi::GenericMethod * /*decl*/, void __SUPPRESS_UNUSED_WARNING(args); tl::Heap heap; QWidget *arg1 = gsi::arg_reader() (args, heap); + if (arg1) { + qt_gsi::qt_keep ((QWidget *)cls); + } else { + qt_gsi::qt_release ((QWidget *)cls); + } __SUPPRESS_UNUSED_WARNING(ret); ((QWidget *)cls)->setParent (arg1); } @@ -3104,6 +3110,11 @@ static void _call_f_setParent_3702 (const qt_gsi::GenericMethod * /*decl*/, void tl::Heap heap; QWidget *arg1 = gsi::arg_reader() (args, heap); QFlags arg2 = gsi::arg_reader >() (args, heap); + if (arg1) { + qt_gsi::qt_keep ((QWidget *)cls); + } else { + qt_gsi::qt_release ((QWidget *)cls); + } __SUPPRESS_UNUSED_WARNING(ret); ((QWidget *)cls)->setParent (arg1, arg2); } diff --git a/src/gsiqt/qt5/QtCore/gsiDeclQObject.cc b/src/gsiqt/qt5/QtCore/gsiDeclQObject.cc index e05a3c50b..86e4470f3 100644 --- a/src/gsiqt/qt5/QtCore/gsiDeclQObject.cc +++ b/src/gsiqt/qt5/QtCore/gsiDeclQObject.cc @@ -501,6 +501,11 @@ static void _call_f_setParent_1302 (const qt_gsi::GenericMethod * /*decl*/, void __SUPPRESS_UNUSED_WARNING(args); tl::Heap heap; QObject *arg1 = gsi::arg_reader() (args, heap); + if (arg1) { + qt_gsi::qt_keep ((QObject *)cls); + } else { + qt_gsi::qt_release ((QObject *)cls); + } __SUPPRESS_UNUSED_WARNING(ret); ((QObject *)cls)->setParent (arg1); } diff --git a/src/gsiqt/qt5/QtWidgets/gsiDeclQListWidgetItem.cc b/src/gsiqt/qt5/QtWidgets/gsiDeclQListWidgetItem.cc index 24d583fab..e63ec3a87 100644 --- a/src/gsiqt/qt5/QtWidgets/gsiDeclQListWidgetItem.cc +++ b/src/gsiqt/qt5/QtWidgets/gsiDeclQListWidgetItem.cc @@ -1028,6 +1028,8 @@ static void _call_ctor_QListWidgetItem_Adaptor_2386 (const qt_gsi::GenericStatic QListWidgetItem_Adaptor *obj = new QListWidgetItem_Adaptor (arg1, arg2); if (arg1) { qt_gsi::qt_keep (obj); + } else { + qt_gsi::qt_release (obj); } ret.write (obj); } diff --git a/src/gsiqt/qt5/QtWidgets/gsiDeclQTreeWidgetItem.cc b/src/gsiqt/qt5/QtWidgets/gsiDeclQTreeWidgetItem.cc index 70c179c4d..275ee21fd 100644 --- a/src/gsiqt/qt5/QtWidgets/gsiDeclQTreeWidgetItem.cc +++ b/src/gsiqt/qt5/QtWidgets/gsiDeclQTreeWidgetItem.cc @@ -1600,6 +1600,8 @@ static void _call_ctor_QTreeWidgetItem_Adaptor_2374 (const qt_gsi::GenericStatic QTreeWidgetItem_Adaptor *obj = new QTreeWidgetItem_Adaptor (arg1, arg2); if (arg1) { qt_gsi::qt_keep (obj); + } else { + qt_gsi::qt_release (obj); } ret.write (obj); } @@ -1628,6 +1630,8 @@ static void _call_ctor_QTreeWidgetItem_Adaptor_4703 (const qt_gsi::GenericStatic QTreeWidgetItem_Adaptor *obj = new QTreeWidgetItem_Adaptor (arg1, arg2, arg3); if (arg1) { qt_gsi::qt_keep (obj); + } else { + qt_gsi::qt_release (obj); } ret.write (obj); } @@ -1656,6 +1660,8 @@ static void _call_ctor_QTreeWidgetItem_Adaptor_4380 (const qt_gsi::GenericStatic QTreeWidgetItem_Adaptor *obj = new QTreeWidgetItem_Adaptor (arg1, arg2, arg3); if (arg1) { qt_gsi::qt_keep (obj); + } else { + qt_gsi::qt_release (obj); } ret.write (obj); } @@ -1681,6 +1687,8 @@ static void _call_ctor_QTreeWidgetItem_Adaptor_2773 (const qt_gsi::GenericStatic QTreeWidgetItem_Adaptor *obj = new QTreeWidgetItem_Adaptor (arg1, arg2); if (arg1) { qt_gsi::qt_keep (obj); + } else { + qt_gsi::qt_release (obj); } ret.write (obj); } @@ -1709,6 +1717,8 @@ static void _call_ctor_QTreeWidgetItem_Adaptor_5102 (const qt_gsi::GenericStatic QTreeWidgetItem_Adaptor *obj = new QTreeWidgetItem_Adaptor (arg1, arg2, arg3); if (arg1) { qt_gsi::qt_keep (obj); + } else { + qt_gsi::qt_release (obj); } ret.write (obj); } @@ -1737,6 +1747,8 @@ static void _call_ctor_QTreeWidgetItem_Adaptor_4779 (const qt_gsi::GenericStatic QTreeWidgetItem_Adaptor *obj = new QTreeWidgetItem_Adaptor (arg1, arg2, arg3); if (arg1) { qt_gsi::qt_keep (obj); + } else { + qt_gsi::qt_release (obj); } ret.write (obj); } diff --git a/src/gsiqt/qt5/QtWidgets/gsiDeclQWidget.cc b/src/gsiqt/qt5/QtWidgets/gsiDeclQWidget.cc index 66f01eff9..36627b800 100644 --- a/src/gsiqt/qt5/QtWidgets/gsiDeclQWidget.cc +++ b/src/gsiqt/qt5/QtWidgets/gsiDeclQWidget.cc @@ -2792,6 +2792,7 @@ static void _call_f_setLayout_1341 (const qt_gsi::GenericMethod * /*decl*/, void __SUPPRESS_UNUSED_WARNING(args); tl::Heap heap; QLayout *arg1 = gsi::arg_reader() (args, heap); + qt_gsi::qt_keep (arg1); __SUPPRESS_UNUSED_WARNING(ret); ((QWidget *)cls)->setLayout (arg1); } @@ -3098,6 +3099,11 @@ static void _call_f_setParent_1315 (const qt_gsi::GenericMethod * /*decl*/, void __SUPPRESS_UNUSED_WARNING(args); tl::Heap heap; QWidget *arg1 = gsi::arg_reader() (args, heap); + if (arg1) { + qt_gsi::qt_keep ((QWidget *)cls); + } else { + qt_gsi::qt_release ((QWidget *)cls); + } __SUPPRESS_UNUSED_WARNING(ret); ((QWidget *)cls)->setParent (arg1); } @@ -3121,6 +3127,11 @@ static void _call_f_setParent_3702 (const qt_gsi::GenericMethod * /*decl*/, void tl::Heap heap; QWidget *arg1 = gsi::arg_reader() (args, heap); QFlags arg2 = gsi::arg_reader >() (args, heap); + if (arg1) { + qt_gsi::qt_keep ((QWidget *)cls); + } else { + qt_gsi::qt_release ((QWidget *)cls); + } __SUPPRESS_UNUSED_WARNING(ret); ((QWidget *)cls)->setParent (arg1, arg2); } diff --git a/src/gsiqt/qtbasic/gsiQt.h b/src/gsiqt/qtbasic/gsiQt.h index 803629cff..da9fe7101 100644 --- a/src/gsiqt/qtbasic/gsiQt.h +++ b/src/gsiqt/qtbasic/gsiQt.h @@ -488,6 +488,20 @@ inline void qt_keep (T *obj) } } +/** + * @brief An implementation helper for the "keep arg" feature + * This helper will call release on the object, hence returning the + * ownership to the script framework. + */ +template +inline void qt_release (T *obj) +{ + QtObjectBase *qt_obj = dynamic_cast(obj); + if (qt_obj) { + qt_obj->release (); + } +} + template inline void qt_keep (const QList &list) { diff --git a/testdata/ruby/qtbinding.rb b/testdata/ruby/qtbinding.rb index 457c26acb..6a9eb9531 100644 --- a/testdata/ruby/qtbinding.rb +++ b/testdata/ruby/qtbinding.rb @@ -613,6 +613,66 @@ class QtBinding_TestClass < TestBase end + def test_46 + + # Layout becomes owned by widget + + w = RBA::QWidget::new + + l = RBA::QHBoxLayout::new + w.setLayout(l) + + w._destroy + assert_equal(l.destroyed?, true) + + end + + def test_47 + + # setParent will attach ownership for QWidget + + w = RBA::QWidget::new + wc = RBA::QWidget::new + + wc.setParent(w) + + w._destroy + assert_equal(wc.destroyed?, true) + + end + + def test_48 + + # setParent will attach ownership for QObject + + w = RBA::QObject::new + wc = RBA::QObject::new + + wc.setParent(w) + + w._destroy + assert_equal(wc.destroyed?, true) + + end + + def test_49 + + # setParent to nil will release ownership for QObject + + w = RBA::QObject::new + wc = RBA::QObject::new + + wc.setParent(w) + assert_equal(wc.parent == w, true) + wc.setParent(nil) + + w._destroy + assert_equal(wc.destroyed?, false) + wc._destroy + assert_equal(wc.destroyed?, true) + + end + end load("test_epilogue.rb")