diff options
author | Jarek Kobus <jaroslaw.kobus@qt.io> | 2023-01-30 10:03:01 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2023-01-30 11:31:18 +0000 |
commit | b737601cc5860f9269fbcc4dc18f1888c7ec9743 (patch) | |
tree | f1b86aeea29b0b8bc3437f4f9e08912ebd1a22c2 | |
parent | bc759caf84b61631106e69ee582404b42c5ccdc3 (diff) | |
download | qttools-b737601cc5860f9269fbcc4dc18f1888c7ec9743.tar.gz |
QtPropertyBrowser: Remove private slots - part 1
Do it inside QtPropertyBrowser and subclasses.
Replace them with lambdas.
Remove unneeded includes.
Fix return values.
Change-Id: I8a04fcc411741ebf132955b8d084fa13b65cf65d
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
(cherry picked from commit f1a09d17d309a2bb88582f0a34927329a00eb4a8)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
8 files changed, 55 insertions, 90 deletions
diff --git a/src/shared/qtpropertybrowser/qtbuttonpropertybrowser.cpp b/src/shared/qtpropertybrowser/qtbuttonpropertybrowser.cpp index 60ff786f7..a2bfe661e 100644 --- a/src/shared/qtpropertybrowser/qtbuttonpropertybrowser.cpp +++ b/src/shared/qtpropertybrowser/qtbuttonpropertybrowser.cpp @@ -2,13 +2,11 @@ // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include "qtbuttonpropertybrowser.h" -#include <QtCore/QSet> + +#include <QtCore/QMap> #include <QtWidgets/QGridLayout> #include <QtWidgets/QLabel> -#include <QtCore/QTimer> -#include <QtCore/QMap> #include <QtWidgets/QToolButton> -#include <QtWidgets/QStyle> QT_BEGIN_NAMESPACE @@ -196,7 +194,7 @@ void QtButtonPropertyBrowserPrivate::slotToggled(bool checked) void QtButtonPropertyBrowserPrivate::updateLater() { - QTimer::singleShot(0, q_ptr, SLOT(slotUpdate())); + QMetaObject::invokeMethod(q_ptr, [this] { slotUpdate(); }, Qt::QueuedConnection); } void QtButtonPropertyBrowserPrivate::propertyInserted(QtBrowserItem *index, QtBrowserItem *afterIndex) @@ -244,7 +242,8 @@ void QtButtonPropertyBrowserPrivate::propertyInserted(QtBrowserItem *index, QtBr parentItem->container = container; parentItem->button = createButton(); m_buttonToItem[parentItem->button] = parentItem; - q_ptr->connect(parentItem->button, SIGNAL(toggled(bool)), q_ptr, SLOT(slotToggled(bool))); + q_ptr->connect(parentItem->button, &QAbstractButton::toggled, + q_ptr, [this](bool checked) { slotToggled(checked); }); parentItem->layout = new QGridLayout(); container->setLayout(parentItem->layout); if (parentItem->label) { @@ -266,7 +265,8 @@ void QtButtonPropertyBrowserPrivate::propertyInserted(QtBrowserItem *index, QtBr newItem->label->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed)); newItem->widget = createEditor(index->property(), parentWidget); if (newItem->widget) { - QObject::connect(newItem->widget, SIGNAL(destroyed()), q_ptr, SLOT(slotEditorDestroyed())); + QObject::connect(newItem->widget, &QWidget::destroyed, + q_ptr, [this] { slotEditorDestroyed(); }); m_widgetToItem[newItem->widget] = newItem; } else if (index->property()->hasValue()) { newItem->widgetLabel = new QLabel(parentWidget); diff --git a/src/shared/qtpropertybrowser/qtbuttonpropertybrowser.h b/src/shared/qtpropertybrowser/qtbuttonpropertybrowser.h index 88df58f6d..2a02405aa 100644 --- a/src/shared/qtpropertybrowser/qtbuttonpropertybrowser.h +++ b/src/shared/qtpropertybrowser/qtbuttonpropertybrowser.h @@ -14,7 +14,6 @@ class QtButtonPropertyBrowser : public QtAbstractPropertyBrowser { Q_OBJECT public: - QtButtonPropertyBrowser(QWidget *parent = 0); ~QtButtonPropertyBrowser(); @@ -22,7 +21,6 @@ public: bool isExpanded(QtBrowserItem *item) const; Q_SIGNALS: - void collapsed(QtBrowserItem *item); void expanded(QtBrowserItem *item); @@ -32,14 +30,9 @@ protected: void itemChanged(QtBrowserItem *item) override; private: - QScopedPointer<QtButtonPropertyBrowserPrivate> d_ptr; Q_DECLARE_PRIVATE(QtButtonPropertyBrowser) Q_DISABLE_COPY_MOVE(QtButtonPropertyBrowser) - Q_PRIVATE_SLOT(d_func(), void slotUpdate()) - Q_PRIVATE_SLOT(d_func(), void slotEditorDestroyed()) - Q_PRIVATE_SLOT(d_func(), void slotToggled(bool)) - }; QT_END_NAMESPACE diff --git a/src/shared/qtpropertybrowser/qtgroupboxpropertybrowser.cpp b/src/shared/qtpropertybrowser/qtgroupboxpropertybrowser.cpp index 29e994089..6c72771b5 100644 --- a/src/shared/qtpropertybrowser/qtgroupboxpropertybrowser.cpp +++ b/src/shared/qtpropertybrowser/qtgroupboxpropertybrowser.cpp @@ -2,12 +2,11 @@ // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include "qtgroupboxpropertybrowser.h" -#include <QtCore/QSet> + +#include <QtCore/QMap> #include <QtWidgets/QGridLayout> -#include <QtWidgets/QLabel> #include <QtWidgets/QGroupBox> -#include <QtCore/QTimer> -#include <QtCore/QMap> +#include <QtWidgets/QLabel> QT_BEGIN_NAMESPACE @@ -119,7 +118,7 @@ void QtGroupBoxPropertyBrowserPrivate::slotUpdate() void QtGroupBoxPropertyBrowserPrivate::updateLater() { - QTimer::singleShot(0, q_ptr, SLOT(slotUpdate())); + QMetaObject::invokeMethod(q_ptr, [this] { slotUpdate(); }, Qt::QueuedConnection); } void QtGroupBoxPropertyBrowserPrivate::propertyInserted(QtBrowserItem *index, QtBrowserItem *afterIndex) @@ -208,7 +207,8 @@ void QtGroupBoxPropertyBrowserPrivate::propertyInserted(QtBrowserItem *index, Qt if (!newItem->widget) { newItem->widgetLabel = new QLabel(parentWidget); } else { - QObject::connect(newItem->widget, SIGNAL(destroyed()), q_ptr, SLOT(slotEditorDestroyed())); + QObject::connect(newItem->widget, &QWidget::destroyed, + q_ptr, [this] { slotEditorDestroyed(); }); m_widgetToItem[newItem->widget] = newItem; } @@ -332,9 +332,7 @@ void QtGroupBoxPropertyBrowserPrivate::removeRow(QGridLayout *layout, int row) c bool QtGroupBoxPropertyBrowserPrivate::hasHeader(WidgetItem *item) const { - if (item->widget) - return true; - return false; + return item->widget; } void QtGroupBoxPropertyBrowserPrivate::propertyChanged(QtBrowserItem *index) diff --git a/src/shared/qtpropertybrowser/qtgroupboxpropertybrowser.h b/src/shared/qtpropertybrowser/qtgroupboxpropertybrowser.h index df1792a94..44b790989 100644 --- a/src/shared/qtpropertybrowser/qtgroupboxpropertybrowser.h +++ b/src/shared/qtpropertybrowser/qtgroupboxpropertybrowser.h @@ -14,7 +14,6 @@ class QtGroupBoxPropertyBrowser : public QtAbstractPropertyBrowser { Q_OBJECT public: - QtGroupBoxPropertyBrowser(QWidget *parent = 0); ~QtGroupBoxPropertyBrowser(); @@ -24,13 +23,9 @@ protected: void itemChanged(QtBrowserItem *item) override; private: - QScopedPointer<QtGroupBoxPropertyBrowserPrivate> d_ptr; Q_DECLARE_PRIVATE(QtGroupBoxPropertyBrowser) Q_DISABLE_COPY_MOVE(QtGroupBoxPropertyBrowser) - Q_PRIVATE_SLOT(d_func(), void slotUpdate()) - Q_PRIVATE_SLOT(d_func(), void slotEditorDestroyed()) - }; QT_END_NAMESPACE diff --git a/src/shared/qtpropertybrowser/qtpropertybrowser.cpp b/src/shared/qtpropertybrowser/qtpropertybrowser.cpp index 1be34a1dd..5ab0660fb 100644 --- a/src/shared/qtpropertybrowser/qtpropertybrowser.cpp +++ b/src/shared/qtpropertybrowser/qtpropertybrowser.cpp @@ -2,7 +2,6 @@ // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include "qtpropertybrowser.h" -#include <QtCore/QSet> #include <QtCore/QMap> #include <QtGui/QIcon> @@ -693,7 +692,7 @@ bool QtAbstractPropertyManager::hasValue(const QtProperty *property) const QIcon QtAbstractPropertyManager::valueIcon(const QtProperty *property) const { Q_UNUSED(property); - return QIcon(); + return {}; } /*! @@ -708,7 +707,7 @@ QIcon QtAbstractPropertyManager::valueIcon(const QtProperty *property) const QString QtAbstractPropertyManager::valueText(const QtProperty *property) const { Q_UNUSED(property); - return QString(); + return {}; } /*! @@ -1228,17 +1227,16 @@ void QtAbstractPropertyBrowserPrivate::insertSubTree(QtProperty *property, QtAbstractPropertyManager *manager = property->propertyManager(); if (m_managerToProperties[manager].isEmpty()) { // connect manager's signals - q_ptr->connect(manager, SIGNAL(propertyInserted(QtProperty *, - QtProperty *, QtProperty *)), - q_ptr, SLOT(slotPropertyInserted(QtProperty *, - QtProperty *, QtProperty *))); - q_ptr->connect(manager, SIGNAL(propertyRemoved(QtProperty *, - QtProperty *)), - q_ptr, SLOT(slotPropertyRemoved(QtProperty*,QtProperty*))); - q_ptr->connect(manager, SIGNAL(propertyDestroyed(QtProperty*)), - q_ptr, SLOT(slotPropertyDestroyed(QtProperty*))); - q_ptr->connect(manager, SIGNAL(propertyChanged(QtProperty*)), - q_ptr, SLOT(slotPropertyDataChanged(QtProperty*))); + q_ptr->connect(manager, &QtAbstractPropertyManager::propertyInserted, + q_ptr, [this](QtProperty *property, QtProperty *parent, QtProperty *after) + { slotPropertyInserted(property, parent, after); }); + q_ptr->connect(manager, &QtAbstractPropertyManager::propertyRemoved, + q_ptr, [this](QtProperty *property, QtProperty *parent) + { slotPropertyRemoved(property, parent); }); + q_ptr->connect(manager, &QtAbstractPropertyManager::propertyDestroyed, + q_ptr, [this](QtProperty *property) { slotPropertyDestroyed(property); }); + q_ptr->connect(manager, &QtAbstractPropertyManager::propertyChanged, + q_ptr, [this](QtProperty *property) { slotPropertyDataChanged(property); }); } m_managerToProperties[manager].append(property); m_propertyToParents[property].append(parentProperty); @@ -1265,17 +1263,10 @@ void QtAbstractPropertyBrowserPrivate::removeSubTree(QtProperty *property, m_managerToProperties[manager].removeAll(property); if (m_managerToProperties[manager].isEmpty()) { // disconnect manager's signals - q_ptr->disconnect(manager, SIGNAL(propertyInserted(QtProperty *, - QtProperty *, QtProperty *)), - q_ptr, SLOT(slotPropertyInserted(QtProperty *, - QtProperty *, QtProperty *))); - q_ptr->disconnect(manager, SIGNAL(propertyRemoved(QtProperty *, - QtProperty *)), - q_ptr, SLOT(slotPropertyRemoved(QtProperty*,QtProperty*))); - q_ptr->disconnect(manager, SIGNAL(propertyDestroyed(QtProperty*)), - q_ptr, SLOT(slotPropertyDestroyed(QtProperty*))); - q_ptr->disconnect(manager, SIGNAL(propertyChanged(QtProperty*)), - q_ptr, SLOT(slotPropertyDataChanged(QtProperty*))); + q_ptr->disconnect(manager, &QtAbstractPropertyManager::propertyInserted, q_ptr, nullptr); + q_ptr->disconnect(manager, &QtAbstractPropertyManager::propertyRemoved, q_ptr, nullptr); + q_ptr->disconnect(manager, &QtAbstractPropertyManager::propertyDestroyed, q_ptr, nullptr); + q_ptr->disconnect(manager, &QtAbstractPropertyManager::propertyChanged, q_ptr, nullptr); m_managerToProperties.remove(manager); } @@ -1732,7 +1723,7 @@ QtBrowserItem *QtAbstractPropertyBrowser::insertProperty(QtProperty *property, QtProperty *afterProperty) { if (!property) - return 0; + return nullptr; // if item is already inserted in this item then cannot add. auto pendingList = properties(); @@ -1741,7 +1732,7 @@ QtBrowserItem *QtAbstractPropertyBrowser::insertProperty(QtProperty *property, while (pos < pendingList.size()) { QtProperty *prop = pendingList.at(pos); if (prop == property) - return 0; + return nullptr; if (prop == afterProperty) { newPos = pos + 1; } @@ -1822,7 +1813,7 @@ QWidget *QtAbstractPropertyBrowser::createEditor(QtProperty *property, } if (!factory) - return 0; + return nullptr; QWidget *w = factory->createEditor(property, parent); // Since some editors can be QComboBoxes, and we changed their focus policy in Qt 5 // to make them feel more native on Mac, we need to relax the focus policy to something diff --git a/src/shared/qtpropertybrowser/qtpropertybrowser.h b/src/shared/qtpropertybrowser/qtpropertybrowser.h index d60758ef3..d2731feb4 100644 --- a/src/shared/qtpropertybrowser/qtpropertybrowser.h +++ b/src/shared/qtpropertybrowser/qtpropertybrowser.h @@ -69,9 +69,7 @@ public: QtProperty *addProperty(const QString &name = QString()); Q_SIGNALS: - - void propertyInserted(QtProperty *property, - QtProperty *parent, QtProperty *after); + void propertyInserted(QtProperty *property, QtProperty *parent, QtProperty *after); void propertyChanged(QtProperty *property); void propertyRemoved(QtProperty *property, QtProperty *parent); void propertyDestroyed(QtProperty *property); @@ -253,13 +251,6 @@ private: QScopedPointer<QtAbstractPropertyBrowserPrivate> d_ptr; Q_DECLARE_PRIVATE(QtAbstractPropertyBrowser) Q_DISABLE_COPY_MOVE(QtAbstractPropertyBrowser) - Q_PRIVATE_SLOT(d_func(), void slotPropertyInserted(QtProperty *, - QtProperty *, QtProperty *)) - Q_PRIVATE_SLOT(d_func(), void slotPropertyRemoved(QtProperty *, - QtProperty *)) - Q_PRIVATE_SLOT(d_func(), void slotPropertyDestroyed(QtProperty *)) - Q_PRIVATE_SLOT(d_func(), void slotPropertyDataChanged(QtProperty *)) - }; QT_END_NAMESPACE diff --git a/src/shared/qtpropertybrowser/qttreepropertybrowser.cpp b/src/shared/qtpropertybrowser/qttreepropertybrowser.cpp index 1a867ee15..e9d3c2545 100644 --- a/src/shared/qtpropertybrowser/qttreepropertybrowser.cpp +++ b/src/shared/qtpropertybrowser/qttreepropertybrowser.cpp @@ -2,18 +2,18 @@ // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include "qttreepropertybrowser.h" -#include <QtCore/QSet> + #include <QtCore/QMap> +#include <QtGui/QFocusEvent> #include <QtGui/QIcon> -#include <QtWidgets/QTreeWidget> -#include <QtWidgets/QItemDelegate> -#include <QtWidgets/QHBoxLayout> -#include <QtWidgets/QHeaderView> #include <QtGui/QPainter> +#include <QtGui/QPalette> #include <QtWidgets/QApplication> -#include <QtGui/QFocusEvent> +#include <QtWidgets/QHBoxLayout> +#include <QtWidgets/QHeaderView> +#include <QtWidgets/QItemDelegate> #include <QtWidgets/QStyle> -#include <QtGui/QPalette> +#include <QtWidgets/QTreeWidget> QT_BEGIN_NAMESPACE @@ -282,7 +282,7 @@ QWidget *QtPropertyEditorDelegate::createEditor(QWidget *parent, return editor; } } - return 0; + return nullptr; } void QtPropertyEditorDelegate::updateEditorGeometry(QWidget *editor, @@ -414,16 +414,20 @@ void QtTreePropertyBrowserPrivate::init(QWidget *parent) m_expandIcon = drawIndicatorIcon(q_ptr->palette(), q_ptr->style()); - QObject::connect(m_treeWidget, SIGNAL(collapsed(QModelIndex)), q_ptr, SLOT(slotCollapsed(QModelIndex))); - QObject::connect(m_treeWidget, SIGNAL(expanded(QModelIndex)), q_ptr, SLOT(slotExpanded(QModelIndex))); - QObject::connect(m_treeWidget, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)), q_ptr, SLOT(slotCurrentTreeItemChanged(QTreeWidgetItem*,QTreeWidgetItem*))); + QObject::connect(m_treeWidget, &QTreeView::collapsed, + q_ptr, [this](const QModelIndex &index) { slotCollapsed(index); }); + QObject::connect(m_treeWidget, &QTreeView::expanded, + q_ptr, [this](const QModelIndex &index) { slotExpanded(index); }); + QObject::connect(m_treeWidget, &QTreeWidget::currentItemChanged, + q_ptr, [this](QTreeWidgetItem *current, QTreeWidgetItem *previous) + { slotCurrentTreeItemChanged(current, previous); }); } QtBrowserItem *QtTreePropertyBrowserPrivate::currentItem() const { if (QTreeWidgetItem *treeItem = m_treeWidget->currentItem()) return m_itemToIndex.value(treeItem); - return 0; + return nullptr; } void QtTreePropertyBrowserPrivate::setCurrentItem(QtBrowserItem *browserItem, bool block) @@ -443,7 +447,7 @@ QtProperty *QtTreePropertyBrowserPrivate::indexToProperty(const QModelIndex &ind QtBrowserItem *idx = m_itemToIndex.value(item); if (idx) return idx->property(); - return 0; + return nullptr; } QtBrowserItem *QtTreePropertyBrowserPrivate::indexToBrowserItem(const QModelIndex &index) const @@ -593,7 +597,7 @@ QColor QtTreePropertyBrowserPrivate::calculatedBackgroundColor(QtBrowserItem *it return it.value(); i = i->parent(); } - return QColor(); + return {}; } void QtTreePropertyBrowserPrivate::slotCollapsed(const QModelIndex &index) @@ -694,7 +698,9 @@ QtTreePropertyBrowser::QtTreePropertyBrowser(QWidget *parent) d_ptr->q_ptr = this; d_ptr->init(this); - connect(this, SIGNAL(currentItemChanged(QtBrowserItem*)), this, SLOT(slotCurrentBrowserItemChanged(QtBrowserItem*))); + QObject::connect(this, &QtAbstractPropertyBrowser::currentItemChanged, + this, [this](QtBrowserItem *current) + { d_ptr->slotCurrentBrowserItemChanged(current); }); } /*! diff --git a/src/shared/qtpropertybrowser/qttreepropertybrowser.h b/src/shared/qtpropertybrowser/qttreepropertybrowser.h index 194ef5d8d..f86e7b826 100644 --- a/src/shared/qtpropertybrowser/qttreepropertybrowser.h +++ b/src/shared/qtpropertybrowser/qttreepropertybrowser.h @@ -22,7 +22,6 @@ class QtTreePropertyBrowser : public QtAbstractPropertyBrowser Q_PROPERTY(int splitterPosition READ splitterPosition WRITE setSplitterPosition) Q_PROPERTY(bool propertiesWithoutValueMarked READ propertiesWithoutValueMarked WRITE setPropertiesWithoutValueMarked) public: - enum ResizeMode { Interactive, @@ -69,7 +68,6 @@ public: void editItem(QtBrowserItem *item); Q_SIGNALS: - void collapsed(QtBrowserItem *item); void expanded(QtBrowserItem *item); @@ -79,16 +77,9 @@ protected: void itemChanged(QtBrowserItem *item) override; private: - QScopedPointer<QtTreePropertyBrowserPrivate> d_ptr; Q_DECLARE_PRIVATE(QtTreePropertyBrowser) Q_DISABLE_COPY_MOVE(QtTreePropertyBrowser) - - Q_PRIVATE_SLOT(d_func(), void slotCollapsed(const QModelIndex &)) - Q_PRIVATE_SLOT(d_func(), void slotExpanded(const QModelIndex &)) - Q_PRIVATE_SLOT(d_func(), void slotCurrentBrowserItemChanged(QtBrowserItem *)) - Q_PRIVATE_SLOT(d_func(), void slotCurrentTreeItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)) - }; QT_END_NAMESPACE |