From 6e2c17b8c1013bb3ea55a7d3f6657d10360657db Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Sun, 16 Oct 2022 21:53:17 +0200 Subject: [PATCH] [consider merging] Qt4 compatibility --- src/ant/ant/antPropertiesPage.cc | 1 + src/lay/lay/layMacroEditorDialog.cc | 28 +++++++++++++++++++++++++-- src/layui/layui/layPropertiesDialog.h | 1 + 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/ant/ant/antPropertiesPage.cc b/src/ant/ant/antPropertiesPage.cc index b381c9c11..63bb9406b 100644 --- a/src/ant/ant/antPropertiesPage.cc +++ b/src/ant/ant/antPropertiesPage.cc @@ -25,6 +25,7 @@ #include "antPropertiesPage.h" #include "layLayoutViewBase.h" #include "layQtTools.h" +#include "tlException.h" namespace ant { diff --git a/src/lay/lay/layMacroEditorDialog.cc b/src/lay/lay/layMacroEditorDialog.cc index 8b50c5cd9..62640266a 100644 --- a/src/lay/lay/layMacroEditorDialog.cc +++ b/src/lay/lay/layMacroEditorDialog.cc @@ -82,6 +82,23 @@ const std::string cfg_macro_editor_watch_expressions ("macro-editor-watch-expres const std::string cfg_macro_editor_debugging_enabled ("macro-editor-debugging-enabled"); const std::string cfg_macro_editor_ignore_exception_list ("macro-editor-ignore-exception-list"); +// ----------------------------------------------------------------------------------------- + +/** + * @brief Finds the tab bar widget for a QTabWidget + */ +static QTabBar *tab_bar_of (QTabWidget *tab) +{ +#if QT_VERSION >= 0x50000 + return tab->tabBar (); +#else + // Qt 4 does not have a public method for getting the QTabBar + QTabBar *tb = tab->findChild (); + tl_assert (tb != 0); + return tb; +#endif +} + // ----------------------------------------------------------------------------------------- // Implementation of the macro template selection dialog @@ -322,6 +339,13 @@ MacroEditorDialog::MacroEditorDialog (lay::Dispatcher *pr, lym::MacroCollection macro_tree->addAction (actionSaveAs); macro_tree->header ()->hide (); + // TODO: that is supposed to enable the horizontal scroll bar, but it doesn't: + macro_tree->header ()->setStretchLastSection (false); +#if QT_VERSION >= 0x50000 + macro_tree->header ()->setSectionResizeMode (QHeaderView::ResizeToContents); +#else + macro_tree->header ()->setResizeMode (QHeaderView::ResizeToContents); +#endif macro_tree->setItemDelegate (new EditRoleDelegate (macro_tree)); @@ -1543,7 +1567,7 @@ MacroEditorDialog::eventFilter (QObject *obj, QEvent *event) } - } else if (obj == tabWidget->tabBar () && dynamic_cast (event) != 0) { + } else if (obj == tab_bar_of (tabWidget) && dynamic_cast (event) != 0) { // just spy on the events, don't eat them QMouseEvent *mouse_event = dynamic_cast (event); @@ -2303,7 +2327,7 @@ MacroEditorDialog::close_many (int r2c) BEGIN_PROTECTED - int ci = tabWidget->tabBar ()->tabAt (m_mouse_pos); + int ci = tab_bar_of (tabWidget)->tabAt (m_mouse_pos); if (ci < 0) { return; } diff --git a/src/layui/layui/layPropertiesDialog.h b/src/layui/layui/layPropertiesDialog.h index 94fab9db2..c59f3975b 100644 --- a/src/layui/layui/layPropertiesDialog.h +++ b/src/layui/layui/layPropertiesDialog.h @@ -40,6 +40,7 @@ #include class QStackedLayout; +class QModelIndex; namespace Ui {