From c6e457d3d689aff5fe52e0e5c8f17b845cbb3a7c 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 | 4 +--- src/lay/lay/layMacroEditorDialog.cc | 25 +++++++++++++++++++-- src/layui/layui/layPropertiesDialog.cc | 31 +++++++++++++++++--------- src/layui/layui/layPropertiesDialog.h | 1 + 4 files changed, 46 insertions(+), 15 deletions(-) diff --git a/src/ant/ant/antPropertiesPage.cc b/src/ant/ant/antPropertiesPage.cc index 4037d5442..d81ed6638 100644 --- a/src/ant/ant/antPropertiesPage.cc +++ b/src/ant/ant/antPropertiesPage.cc @@ -27,8 +27,6 @@ #include "layQtTools.h" #include "tlException.h" -#include - namespace ant { @@ -483,7 +481,7 @@ PropertiesPage::update_with (const ant::Object &obj) text += "\n"; } - QSignalBlocker blocker (points_edit); + lay::SignalBlocker blocker (points_edit); points_edit->setPlainText (tl::to_qstring (text)); } diff --git a/src/lay/lay/layMacroEditorDialog.cc b/src/lay/lay/layMacroEditorDialog.cc index eb6d5697c..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 @@ -324,7 +341,11 @@ MacroEditorDialog::MacroEditorDialog (lay::Dispatcher *pr, lym::MacroCollection 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)); @@ -1546,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); @@ -2306,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.cc b/src/layui/layui/layPropertiesDialog.cc index 24550dafd..84b867137 100644 --- a/src/layui/layui/layPropertiesDialog.cc +++ b/src/layui/layui/layPropertiesDialog.cc @@ -33,10 +33,17 @@ #include #include +#include namespace lay { +#if QT_VERSION >= 0x50000 +typedef qint64 tree_id_type; +#else +typedef qint32 tree_id_type; +#endif + // ---------------------------------------------------------------------------------------------------------- // PropertiesTreeModel definition and implementation @@ -56,14 +63,14 @@ public: QVariant data (const QModelIndex &index, int role) const { if (role == Qt::DisplayRole) { - if (index.internalId () < mp_dialog->properties_pages ().size ()) { + if (tree_id_type (index.internalId ()) < tree_id_type (mp_dialog->properties_pages ().size ())) { return tl::to_qstring (mp_dialog->properties_pages () [index.internalId ()]->description (index.row ())); } else if (index.row () < int (mp_dialog->properties_pages ().size ())) { return tl::to_qstring (mp_dialog->properties_pages () [index.row ()]->description ()); } } else if (role == Qt::DecorationRole) { QIcon icon; - if (index.internalId () < mp_dialog->properties_pages ().size ()) { + if (tree_id_type (index.internalId ()) < tree_id_type (mp_dialog->properties_pages ().size ())) { icon = mp_dialog->properties_pages () [index.internalId ()]->icon (index.row (), m_icon_width, m_icon_height); } else if (index.row () < int (mp_dialog->properties_pages ().size ())) { icon = mp_dialog->properties_pages () [index.row ()]->icon (m_icon_width, m_icon_height); @@ -78,7 +85,7 @@ public: Qt::ItemFlags flags (const QModelIndex &index) const { Qt::ItemFlags f = QAbstractItemModel::flags (index); - if (index.internalId () >= mp_dialog->properties_pages ().size () && ! mp_dialog->properties_pages () [index.row ()]->can_apply_to_all ()) { + if (tree_id_type (index.internalId ()) >= tree_id_type (mp_dialog->properties_pages ().size ()) && ! mp_dialog->properties_pages () [index.row ()]->can_apply_to_all ()) { f &= ~Qt::ItemIsSelectable; } return f; @@ -86,22 +93,22 @@ public: bool hasChildren (const QModelIndex &parent) const { - return (! parent.isValid () || parent.internalId () >= mp_dialog->properties_pages ().size ()); + return (! parent.isValid () || tree_id_type (parent.internalId ()) >= tree_id_type (mp_dialog->properties_pages ().size ())); } QModelIndex index (int row, int column, const QModelIndex &parent) const { if (! parent.isValid ()) { - return createIndex (row, column, qint64 (mp_dialog->properties_pages ().size ())); + return createIndex (row, column, tree_id_type (mp_dialog->properties_pages ().size ())); } else { - return createIndex (row, column, qint64 (parent.row ())); + return createIndex (row, column, tree_id_type (parent.row ())); } } QModelIndex parent (const QModelIndex &child) const { - if (child.internalId () < mp_dialog->properties_pages ().size ()) { - return createIndex (int (child.internalId ()), child.column (), qint64 (mp_dialog->properties_pages ().size ())); + if (tree_id_type (child.internalId ()) < tree_id_type (mp_dialog->properties_pages ().size ())) { + return createIndex (int (child.internalId ()), child.column (), tree_id_type (mp_dialog->properties_pages ().size ())); } else { return QModelIndex (); } @@ -133,7 +140,7 @@ public: if (page_index < 0) { return QModelIndex (); } else { - return createIndex (object_index, 0, qint64 (page_index)); + return createIndex (object_index, 0, tree_id_type (page_index)); } } @@ -142,7 +149,7 @@ public: if (page_index < 0) { return QModelIndex (); } else { - return createIndex (page_index, 0, qint64 (mp_dialog->properties_pages ().size ())); + return createIndex (page_index, 0, tree_id_type (mp_dialog->properties_pages ().size ())); } } @@ -214,7 +221,11 @@ PropertiesDialog::PropertiesDialog (QWidget * /*parent*/, db::Manager *manager, // if at end disable the "Next" button and return (this may only happen at the first call) mp_tree_model = new PropertiesTreeModel (this, mp_ui->tree->iconSize ().width (), mp_ui->tree->iconSize ().height ()); mp_ui->tree->setModel (mp_tree_model); +#if QT_VERSION >= 0x50000 mp_ui->tree->header()->setSectionResizeMode (QHeaderView::ResizeToContents); +#else + mp_ui->tree->header()->setResizeMode (QHeaderView::ResizeToContents); +#endif mp_ui->tree->expandAll (); if (mp_properties_pages.empty ()) { diff --git a/src/layui/layui/layPropertiesDialog.h b/src/layui/layui/layPropertiesDialog.h index ee396ec8f..2f69f6591 100644 --- a/src/layui/layui/layPropertiesDialog.h +++ b/src/layui/layui/layPropertiesDialog.h @@ -40,6 +40,7 @@ #include class QStackedLayout; +class QModelIndex; namespace Ui {