aboutsummaryrefslogtreecommitdiffstats
path: root/src/quicktemplates2/qquickcheckdelegate.cpp
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@qt.io>2017-11-08 10:36:00 +0100
committerJ-P Nurmi <jpnurmi@qt.io>2017-11-08 10:13:55 +0000
commit03155ec2e2fd6cc60b4293af19964d2e1a65b7d9 (patch)
tree9aacfeca5df6f8e65ee3f66d8434bed392733b96 /src/quicktemplates2/qquickcheckdelegate.cpp
parentf246314b21604c5fe2a2abe0aec8af89f06eb610 (diff)
Expose QQuickCheckDelegate::nextCheckState() to QML
Same as 043e3d24 for CheckBox. [ChangeLog][Controls][CheckDelegate] Made it possible to implement nextCheckState() in QML. Task-number: QTBUG-63238 Change-Id: Id765191b1e5559393696183ffea9ed9c69eed475 Reviewed-by: Liang Qi <liang.qi@qt.io>
Diffstat (limited to 'src/quicktemplates2/qquickcheckdelegate.cpp')
-rw-r--r--src/quicktemplates2/qquickcheckdelegate.cpp50
1 files changed, 49 insertions, 1 deletions
diff --git a/src/quicktemplates2/qquickcheckdelegate.cpp b/src/quicktemplates2/qquickcheckdelegate.cpp
index 78d55e1d..9fd8c183 100644
--- a/src/quicktemplates2/qquickcheckdelegate.cpp
+++ b/src/quicktemplates2/qquickcheckdelegate.cpp
@@ -38,6 +38,7 @@
#include "qquickitemdelegate_p_p.h"
#include <QtGui/qpa/qplatformtheme.h>
+#include <QtQml/qjsvalue.h>
QT_BEGIN_NAMESPACE
@@ -94,10 +95,20 @@ public:
{
}
+ void setNextCheckState(const QJSValue &callback);
+
bool tristate;
Qt::CheckState checkState;
+ QJSValue nextCheckState;
};
+void QQuickCheckDelegatePrivate::setNextCheckState(const QJSValue &callback)
+{
+ Q_Q(QQuickCheckDelegate);
+ nextCheckState = callback;
+ emit q->nextCheckStateChanged();
+}
+
QQuickCheckDelegate::QQuickCheckDelegate(QQuickItem *parent)
: QQuickItemDelegate(*(new QQuickCheckDelegatePrivate), parent)
{
@@ -179,10 +190,45 @@ void QQuickCheckDelegate::buttonChange(ButtonChange change)
QQuickAbstractButton::buttonChange(change);
}
+/*!
+ \since QtQuick.Controls 2.4 (Qt 5.11)
+ \qmlproperty function QtQuick.Controls::CheckDelegate::nextCheckState
+
+ This property holds a callback function that is called to determine
+ the next check state whenever the check delegate is interactively toggled
+ by the user via touch, mouse, or keyboard.
+
+ By default, a normal check delegate cycles between \c Qt.Unchecked and
+ \c Qt.Checked states, and a tri-state check delegate cycles between
+ \c Qt.Unchecked, \c Qt.PartiallyChecked, and \c Qt.Checked states.
+
+ The \c nextCheckState callback function can override the default behavior.
+ The following example implements a tri-state check delegate that can present
+ a partially checked state depending on external conditions, but never
+ cycles to the partially checked state when interactively toggled by
+ the user.
+
+ \code
+ CheckDelegate {
+ tristate: true
+ checkState: allChildrenChecked ? Qt.Checked :
+ anyChildChecked ? Qt.PartiallyChecked : Qt.Unchecked
+
+ nextCheckState: function() {
+ if (checkState === Qt.Checked)
+ return Qt.Unchecked
+ else
+ return Qt.Checked
+ }
+ }
+ \endcode
+*/
void QQuickCheckDelegate::nextCheckState()
{
Q_D(QQuickCheckDelegate);
- if (d->tristate)
+ if (d->nextCheckState.isCallable())
+ setCheckState(static_cast<Qt::CheckState>(d->nextCheckState.call().toInt()));
+ else if (d->tristate)
setCheckState(static_cast<Qt::CheckState>((d->checkState + 1) % 3));
else
QQuickItemDelegate::nextCheckState();
@@ -196,3 +242,5 @@ QAccessible::Role QQuickCheckDelegate::accessibleRole() const
#endif
QT_END_NAMESPACE
+
+#include "moc_qquickcheckdelegate_p.cpp"