summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@qt.io>2017-07-05 12:53:01 +0200
committerJ-P Nurmi <jpnurmi@qt.io>2017-07-11 04:40:06 +0000
commit286f14f1e29e7f4e2db4517d087dd5c92606f971 (patch)
treee52791e53ddda3e0dab82ffa8dc85832475beeb8
parent17ded188f76c0e5272763d342490dcb6dda40c80 (diff)
Add QQuickItem::ItemEnabledHasChanged
The itemChange() method has been very useful for Qt Quick Controls 2 to efficiently react to various item changes, but a notification for the enabled state was missing, so it always had to be handled as a special case using signals and slots. This change allows QQC2 to handle enabled state changes the same way e.g. visibility changes are handled. It's also nice to be able to update a control's internal state before the actual notifier signal is emitted. [ChangeLog][QtQuick][QQuickItem] Added a ItemEnabledHasChanged value to the ItemChange enum. QQuickItem::itemChange(ItemEnabledHasChanged) gets called when the item's effective enabled state has changed. The new enabled state is stored in ItemChangeData::boolValue. Change-Id: Iae96ec21f2b94f453632282473decd1c66097a75 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io> Reviewed-by: Robin Burchell <robin.burchell@crimson.no>
-rw-r--r--src/quick/items/qquickitem.cpp16
-rw-r--r--src/quick/items/qquickitem.h3
-rw-r--r--src/quick/items/qquickitem_p.h3
-rw-r--r--src/quick/items/qquickitemchangelistener_p.h1
4 files changed, 21 insertions, 2 deletions
diff --git a/src/quick/items/qquickitem.cpp b/src/quick/items/qquickitem.cpp
index a8a862bb2f..1e71c20ff3 100644
--- a/src/quick/items/qquickitem.cpp
+++ b/src/quick/items/qquickitem.cpp
@@ -2138,6 +2138,9 @@ void QQuickItemPrivate::updateSubFocusItem(QQuickItem *scope, bool focus)
\value ItemAntialiasingHasChanged The antialiasing has changed. The current
(boolean) value can be found in QQuickItem::antialiasing.
+
+ \value ItemEnabledHasChanged The item's enabled state has changed.
+ ItemChangeData::boolValue contains the new enabled state. (since Qt 5.10)
*/
/*!
@@ -5927,6 +5930,7 @@ void QQuickItemPrivate::setEffectiveEnableRecur(QQuickItem *scope, bool newEffec
scope, q, Qt::OtherFocusReason, QQuickWindowPrivate::DontChangeFocusProperty | QQuickWindowPrivate::DontChangeSubFocusItem);
}
+ itemChange(QQuickItem::ItemEnabledHasChanged, effectiveEnable);
emit q->enabledChanged();
}
@@ -6099,6 +6103,18 @@ void QQuickItemPrivate::itemChange(QQuickItem::ItemChange change, const QQuickIt
}
break;
}
+ case QQuickItem::ItemEnabledHasChanged: {
+ q->itemChange(change, data);
+ if (!changeListeners.isEmpty()) {
+ const auto listeners = changeListeners; // NOTE: intentional copy (QTBUG-54732)
+ for (const QQuickItemPrivate::ChangeListener &change : listeners) {
+ if (change.types & QQuickItemPrivate::Enabled) {
+ change.listener->itemEnabledChanged(q);
+ }
+ }
+ }
+ break;
+ }
case QQuickItem::ItemParentHasChanged: {
q->itemChange(change, data);
if (!changeListeners.isEmpty()) {
diff --git a/src/quick/items/qquickitem.h b/src/quick/items/qquickitem.h
index f58946d01d..4a832bbf6f 100644
--- a/src/quick/items/qquickitem.h
+++ b/src/quick/items/qquickitem.h
@@ -173,7 +173,8 @@ public:
ItemActiveFocusHasChanged, // value.boolValue
ItemRotationHasChanged, // value.realValue
ItemAntialiasingHasChanged, // value.boolValue
- ItemDevicePixelRatioHasChanged // value.realValue
+ ItemDevicePixelRatioHasChanged, // value.realValue
+ ItemEnabledHasChanged // value.boolValue
};
union ItemChangeData {
diff --git a/src/quick/items/qquickitem_p.h b/src/quick/items/qquickitem_p.h
index e56d839de9..74d70da2bc 100644
--- a/src/quick/items/qquickitem_p.h
+++ b/src/quick/items/qquickitem_p.h
@@ -321,7 +321,8 @@ public:
Children = 0x40,
Rotation = 0x80,
ImplicitWidth = 0x100,
- ImplicitHeight = 0x200
+ ImplicitHeight = 0x200,
+ Enabled = 0x400,
};
Q_DECLARE_FLAGS(ChangeTypes, ChangeType)
diff --git a/src/quick/items/qquickitemchangelistener_p.h b/src/quick/items/qquickitemchangelistener_p.h
index 83c69a9330..cb0af75c4c 100644
--- a/src/quick/items/qquickitemchangelistener_p.h
+++ b/src/quick/items/qquickitemchangelistener_p.h
@@ -125,6 +125,7 @@ public:
virtual void itemGeometryChanged(QQuickItem *, QQuickGeometryChange, const QRectF & /* oldGeometry */) {}
virtual void itemSiblingOrderChanged(QQuickItem *) {}
virtual void itemVisibilityChanged(QQuickItem *) {}
+ virtual void itemEnabledChanged(QQuickItem *) {}
virtual void itemOpacityChanged(QQuickItem *) {}
virtual void itemDestroyed(QQuickItem *) {}
virtual void itemChildAdded(QQuickItem *, QQuickItem * /* child */ ) {}