summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKonstantin Ritt <ritt.ks@gmail.com>2016-12-30 20:03:31 +0300
committerJani Heikkinen <jani.heikkinen@qt.io>2017-01-05 10:46:38 +0000
commitfc083796ad8b02bf9d995ee22b6d60090e1e284d (patch)
treef1afdfa0e9369cb5f5a2e0bf3aee8486df98c32f
parenta13dce3d471c77474ce4b0f6bae115a015139229 (diff)
Implement QQuickDialogButtonBox::standardButton(StandardButton)
Change-Id: I25935a069127a48c00dae951bc77665be6a429e1 Reviewed-by: J-P Nurmi <jpnurmi@qt.io>
-rw-r--r--src/quicktemplates2/qquickdialogbuttonbox.cpp12
-rw-r--r--tests/auto/controls/data/tst_dialogbuttonbox.qml4
2 files changed, 15 insertions, 1 deletions
diff --git a/src/quicktemplates2/qquickdialogbuttonbox.cpp b/src/quicktemplates2/qquickdialogbuttonbox.cpp
index 10603d58..1e7a5fd7 100644
--- a/src/quicktemplates2/qquickdialogbuttonbox.cpp
+++ b/src/quicktemplates2/qquickdialogbuttonbox.cpp
@@ -500,7 +500,17 @@ void QQuickDialogButtonBox::setStandardButtons(QPlatformDialogHelper::StandardBu
*/
QQuickAbstractButton *QQuickDialogButtonBox::standardButton(QPlatformDialogHelper::StandardButton button) const
{
- Q_UNUSED(button);
+ Q_D(const QQuickDialogButtonBox);
+ if (Q_UNLIKELY(!(d->standardButtons & button)))
+ return nullptr;
+ for (int i = 0, n = count(); i < n; ++i) {
+ QQuickAbstractButton *btn = qobject_cast<QQuickAbstractButton *>(d->itemAt(i));
+ if (Q_LIKELY(btn)) {
+ QQuickDialogButtonBoxAttached *attached = qobject_cast<QQuickDialogButtonBoxAttached *>(qmlAttachedPropertiesObject<QQuickDialogButtonBox>(btn, false));
+ if (attached && QQuickDialogButtonBoxAttachedPrivate::get(attached)->standardButton == button)
+ return btn;
+ }
+ }
return nullptr;
}
diff --git a/tests/auto/controls/data/tst_dialogbuttonbox.qml b/tests/auto/controls/data/tst_dialogbuttonbox.qml
index 8474e89b..295ce460 100644
--- a/tests/auto/controls/data/tst_dialogbuttonbox.qml
+++ b/tests/auto/controls/data/tst_dialogbuttonbox.qml
@@ -104,9 +104,13 @@ TestCase {
verify(cancelButton)
compare(okButton.text.toUpperCase(), "OK")
compare(cancelButton.text.toUpperCase(), "CANCEL")
+ compare(control.standardButton(DialogButtonBox.Ok), okButton)
+ compare(control.standardButton(DialogButtonBox.Cancel), cancelButton)
control.standardButtons = 0
compare(control.count, 0)
+ compare(control.standardButton(DialogButtonBox.Ok), null)
+ compare(control.standardButton(DialogButtonBox.Cancel), null)
control.destroy()
}