From 111edc82743369fd1557784566a46c8e03dc4bbd Mon Sep 17 00:00:00 2001 From: Michael Weghorn Date: Wed, 18 Dec 2024 20:46:32 +0100 Subject: tdf#130857 qt weld: Map ID to to parent QWidget for layouts QBoxLayout (created for "GtkBox" in .ui files) and QGridLayout (created for "GtkGrid" in .ui files) are QLayout subclasses, not QWidgets. So far, QtBuilder::m_aChildren was containing QObjects that could be either QWidgets or QLayouts. QtInstanceBuilder::weld_container and QtInstanceBuilder::weld_grid were retrieving the corresponding QLayout using QtBuilder::get, all other QtInstanceBuilder::weld_* methods the corresponding QWidget. However, for a "GtkBox" or "GtkGrid", it's not only possible to call QtInstanceBuilder::weld_container or QtInstanceBuilder::weld_grid, but it's also possible to just get a pointer to the weld::Widget subclass by calling QtInstanceBuilder::weld_widget with the ID of the grid/box. So far, this would have resulted in QtInstanceBuilder::weld_widget calling QtBuilder::get, in which case the latter would incorrectly `static_cast` the QLayout to a QWidget. Since commit bf42162fc50d0c6f8e567d8765f8b14b96d7cc50 Author: Michael Weghorn Date: Mon Nov 4 19:06:15 2024 +0100 tdf#130857 qt weld: Add extra QWidget parents for layouts , extra parent widgets for the layouts (except for the top-level ones in dialogs) are created. Insert these into QtBuilder::m_aChildren instead and retrieve them by the ID, which allows to uniformly use QWidget. Adjust QtInstanceBuilder::weld_{container,grid} accordingly. (Special handling for top-level layouts in containers can still be added as needed later.) This fixes an assert seen in a WIP branch where suport for the FontFeaturesDialog (open context menu for paragraph in Writer, select "Character" -> "Character" to open the "Character" dialog, in the "Font" tab, click on the "Features" button) is declared. Backtrace, where FontFeaturesDialog::m_xContainer is a weld::Widget referring to the "fontentry" GtkGrid in cui/uiconfig/ui/fontfragment.ui: 1 __pthread_kill_implementation pthread_kill.c 44 0x7ffff789dc8c 2 __pthread_kill_internal pthread_kill.c 78 0x7ffff789dcef 3 __GI_raise raise.c 26 0x7ffff7849c42 4 __GI_abort abort.c 79 0x7ffff78324f0 5 __assert_fail_base assert.c 94 0x7ffff7832418 6 __assert_fail assert.c 103 0x7ffff7842552 7 QtInstanceGrid::set_child_left_attach(weld::Widget&, int)::$_0::operator()() const QtInstanceGrid.cxx 25 0x7fffe438b5e1 8 std::__invoke_impl(std::__invoke_other, QtInstanceGrid::set_child_left_attach(weld::Widget&, int)::$_0&) invoke.h 61 0x7fffe438b4f5 9 std::__invoke_r(QtInstanceGrid::set_child_left_attach(weld::Widget&, int)::$_0&) invoke.h 111 0x7fffe438b4b5 10 std::_Function_handler::_M_invoke std_function.h 290 0x7fffe438b39d 11 std::function::operator() std_function.h 591 0x7fffe4345aee 12 QtInstance::RunInMainThread QtInstance.cxx 226 0x7fffe433d67a 13 QtInstanceGrid::set_child_left_attach QtInstanceGrid.cxx 23 0x7fffe438aa63 14 cui::FontFeaturesDialog::fillGrid FontFeaturesDialog.cxx 142 0x7fff6db25fb1 15 cui::FontFeaturesDialog::initialize FontFeaturesDialog.cxx 73 0x7fff6db2541d 16 cui::FontFeaturesDialog::FontFeaturesDialog FontFeaturesDialog.cxx 35 0x7fff6db24f61 17 SvxCharNamePage::FontFeatureButtonClicked chardlg.cxx 1154 0x7fff6de651d1 18 SvxCharNamePage::LinkStubFontFeatureButtonClicked chardlg.cxx 1131 0x7fff6de5fa7d 19 Link::Call link.hxx 111 0x7fffeec54551 20 weld::Button::signal_clicked weld.hxx 1558 0x7fffeec3078c 21 SalInstanceButton::ClickHdl salvtables.cxx 2955 0x7fffeec018ee 22 SalInstanceButton::LinkStubClickHdl salvtables.cxx 2943 0x7fffeec00e2d 23 Link