summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2018-08-01 08:27:54 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2018-08-01 10:51:41 +0000
commit901c06d93561f28ede76d26513cf99e450f8b237 (patch)
tree3fa281c62ed7fa930ef6f4930f9749fa54818a5a /src
parente85b6a3ff1b8b3f21a75209c2bff1bf02c7fdb1b (diff)
Qt Designer: Refactor WidgetFactory::isPassiveInteractor()
Factor out a helper routine to check on the widget so that the caching pattern becomes clearer. Change the heap-allocated QPointer<QWidget> to a static variable. Change-Id: I5dfc5a9ebc791dbd2e13a9cbde72f77c3e2c6104 Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/designer/src/lib/shared/widgetfactory.cpp86
-rw-r--r--src/designer/src/lib/shared/widgetfactory_p.h4
2 files changed, 44 insertions, 46 deletions
diff --git a/src/designer/src/lib/shared/widgetfactory.cpp b/src/designer/src/lib/shared/widgetfactory.cpp
index 003096228..c467aeaaf 100644
--- a/src/designer/src/lib/shared/widgetfactory.cpp
+++ b/src/designer/src/lib/shared/widgetfactory.cpp
@@ -69,6 +69,7 @@
#include <QtWidgets/qwizard.h>
#include <QtCore/qdebug.h>
#include <QtCore/qmetaobject.h>
+#include <QtCore/qpointer.h>
QT_BEGIN_NAMESPACE
@@ -188,8 +189,6 @@ WidgetFactory::Strings::Strings() :
{
}
// ---------------- WidgetFactory
-QPointer<QWidget> *WidgetFactory::m_lastPassiveInteractor = new QPointer<QWidget>();
-bool WidgetFactory::m_lastWasAPassiveInteractor = false;
const char *WidgetFactory::disableStyleCustomPaintingPropertyC = "_q_custom_style_disabled";
WidgetFactory::WidgetFactory(QDesignerFormEditorInterface *core, QObject *parent)
@@ -789,59 +788,62 @@ static bool isTabBarInteractor(const QTabBar *tabBar)
return false;
}
-bool WidgetFactory::isPassiveInteractor(QWidget *widget)
+static bool isPassiveInteractorHelper(const QWidget *widget)
{
static const QString qtPassive = QStringLiteral("__qt__passive_");
static const QString qtMainWindowSplitter = QStringLiteral("qt_qmainwindow_extended_splitter");
- if (m_lastPassiveInteractor != 0 && (QWidget*)(*m_lastPassiveInteractor) == widget)
- return m_lastWasAPassiveInteractor;
- if (QApplication::activePopupWidget() || widget == 0) // if a popup is open, we have to make sure that this one is closed, else X might do funny things
+ if (qobject_cast<const QMenuBar*>(widget)
+#if QT_CONFIG(sizegrip)
+ || qobject_cast<const QSizeGrip*>(widget)
+#endif
+ || qobject_cast<const QMdiSubWindow*>(widget)
+ || qobject_cast<const QToolBar*>(widget)) {
return true;
+ }
- m_lastWasAPassiveInteractor = false;
- (*m_lastPassiveInteractor) = widget;
-
- if (const QTabBar *tabBar = qobject_cast<const QTabBar*>(widget)) {
+ if (qobject_cast<const QAbstractButton*>(widget)) {
+ auto parent = widget->parent();
+ if (qobject_cast<const QTabBar*>(parent) || qobject_cast<const QToolBox*>(parent))
+ return true;
+ } else if (const auto tabBar = qobject_cast<const QTabBar*>(widget)) {
if (isTabBarInteractor(tabBar))
- m_lastWasAPassiveInteractor = true;
- return m_lastWasAPassiveInteractor;
- }
-#ifndef QT_NO_SIZEGRIP
- if (qobject_cast<QSizeGrip*>(widget))
- return (m_lastWasAPassiveInteractor = true);
-#endif
- if (qobject_cast<QMdiSubWindow*>(widget))
- return (m_lastWasAPassiveInteractor = true);
- if (qobject_cast<QAbstractButton*>(widget)
- && (qobject_cast<QTabBar*>(widget->parent()) || qobject_cast<QToolBox*>(widget->parent()))) {
- return (m_lastWasAPassiveInteractor = true);
- }
- if (qobject_cast<QMenuBar*>(widget))
- return (m_lastWasAPassiveInteractor = true);
- if (qobject_cast<QToolBar*>(widget))
- return (m_lastWasAPassiveInteractor = true);
- if (qobject_cast<QScrollBar*>(widget)) {
+ return true;
+ } else if (qobject_cast<const QScrollBar*>(widget)) {
// A scroll bar is an interactor on a QAbstractScrollArea only.
- if (const QWidget *parent = widget->parentWidget()) {
+ if (auto parent = widget->parentWidget()) {
const QString objectName = parent->objectName();
static const QString scrollAreaVContainer = QStringLiteral("qt_scrollarea_vcontainer");
static const QString scrollAreaHContainer = QStringLiteral("qt_scrollarea_hcontainer");
- if (objectName == scrollAreaVContainer || objectName == scrollAreaHContainer) {
- m_lastWasAPassiveInteractor = true;
- return m_lastWasAPassiveInteractor;
- }
+ if (objectName == scrollAreaVContainer || objectName == scrollAreaHContainer)
+ return true;
}
- } else if (qstrcmp(widget->metaObject()->className(), "QDockWidgetTitle") == 0)
- return (m_lastWasAPassiveInteractor = true);
- else if (qstrcmp(widget->metaObject()->className(), "QWorkspaceTitleBar") == 0)
- return (m_lastWasAPassiveInteractor = true);
- const QString name = widget->objectName();
- if (name.startsWith(qtPassive) || name == qtMainWindowSplitter) {
- m_lastWasAPassiveInteractor = true;
- return m_lastWasAPassiveInteractor;
+ } else if (qstrcmp(widget->metaObject()->className(), "QDockWidgetTitle") == 0) {
+ return true;
+ } else if (qstrcmp(widget->metaObject()->className(), "QWorkspaceTitleBar") == 0) {
+ return true;
}
- return m_lastWasAPassiveInteractor;
+ const QString &name = widget->objectName();
+ return name.startsWith(qtPassive) || name == qtMainWindowSplitter;
+}
+
+bool WidgetFactory::isPassiveInteractor(QWidget *widget)
+{
+ static bool lastWasAPassiveInteractor = false;
+ static QPointer<QWidget> lastPassiveInteractor;
+
+ if (!lastPassiveInteractor.isNull() && lastPassiveInteractor.data() == widget)
+ return lastWasAPassiveInteractor;
+
+ // if a popup is open, we have to make sure that this one is closed,
+ // else X might do funny things
+ if (QApplication::activePopupWidget() || widget == nullptr)
+ return true;
+
+ lastWasAPassiveInteractor = isPassiveInteractorHelper(widget);
+ lastPassiveInteractor = widget;
+
+ return lastWasAPassiveInteractor;
}
void WidgetFactory::formWindowAdded(QDesignerFormWindowInterface *formWindow)
diff --git a/src/designer/src/lib/shared/widgetfactory_p.h b/src/designer/src/lib/shared/widgetfactory_p.h
index 1d45e17cd..1d3c17bdf 100644
--- a/src/designer/src/lib/shared/widgetfactory_p.h
+++ b/src/designer/src/lib/shared/widgetfactory_p.h
@@ -49,7 +49,6 @@
#include <QtCore/qmap.h>
#include <QtCore/qhash.h>
#include <QtCore/qvariant.h>
-#include <QtCore/qpointer.h>
QT_BEGIN_NAMESPACE
@@ -163,9 +162,6 @@ private:
QStyle *m_currentStyle;
typedef QHash<QString, QStyle *> StyleCache;
StyleCache m_styleCache;
-
- static QPointer<QWidget> *m_lastPassiveInteractor;
- static bool m_lastWasAPassiveInteractor;
};
} // namespace qdesigner_internal