aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@qt.io>2016-10-22 20:46:33 +0200
committerJ-P Nurmi <jpnurmi@qt.io>2016-10-26 09:17:17 +0000
commitfa71ef5a2ccfa4666db9338c4ba8f34d19f2faf1 (patch)
tree69f0e465ea5f5baf38a22631fe8d178fde8a795b
parent791d521a3008695f834d5aa8c9bb61f9075b37a8 (diff)
QQuickDialog: simplify the button box handling
Just fill in the footer with a button box by default from the styles. This makes the next step easier, to provide also a default title bar in the header. Task-number: QTBUG-56711 Change-Id: I621a61f29f9ba2fe4b7e907d81da5988133a98c8 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
-rw-r--r--src/imports/controls/Dialog.qml4
-rw-r--r--src/imports/controls/material/Dialog.qml4
-rw-r--r--src/imports/controls/universal/Dialog.qml4
-rw-r--r--src/quicktemplates2/qquickdialog.cpp101
-rw-r--r--src/quicktemplates2/qquickdialog_p.h7
-rw-r--r--src/quicktemplates2/qquickdialog_p_p.h6
-rw-r--r--tests/auto/controls/data/tst_dialog.qml51
7 files changed, 22 insertions, 155 deletions
diff --git a/src/imports/controls/Dialog.qml b/src/imports/controls/Dialog.qml
index ce6df0f6..3322a6ea 100644
--- a/src/imports/controls/Dialog.qml
+++ b/src/imports/controls/Dialog.qml
@@ -59,7 +59,7 @@ T.Dialog {
border.color: Default.frameDarkColor
}
- buttonBox: DialogButtonBox {
- position: DialogButtonBox.Footer
+ footer: DialogButtonBox {
+ visible: count > 0
}
}
diff --git a/src/imports/controls/material/Dialog.qml b/src/imports/controls/material/Dialog.qml
index 1e2e50ac..7e9fafbe 100644
--- a/src/imports/controls/material/Dialog.qml
+++ b/src/imports/controls/material/Dialog.qml
@@ -80,7 +80,7 @@ T.Dialog {
}
}
- buttonBox: DialogButtonBox {
- position: DialogButtonBox.Footer
+ footer: DialogButtonBox {
+ visible: count > 0
}
}
diff --git a/src/imports/controls/universal/Dialog.qml b/src/imports/controls/universal/Dialog.qml
index 0f00b760..bff289d9 100644
--- a/src/imports/controls/universal/Dialog.qml
+++ b/src/imports/controls/universal/Dialog.qml
@@ -63,7 +63,7 @@ T.Dialog {
border.width: 1 // FlyoutBorderThemeThickness
}
- buttonBox: DialogButtonBox {
- position: DialogButtonBox.Footer
+ footer: DialogButtonBox {
+ visible: count > 0
}
}
diff --git a/src/quicktemplates2/qquickdialog.cpp b/src/quicktemplates2/qquickdialog.cpp
index eaa7dbb2..356e6c27 100644
--- a/src/quicktemplates2/qquickdialog.cpp
+++ b/src/quicktemplates2/qquickdialog.cpp
@@ -38,10 +38,6 @@
#include "qquickdialog_p_p.h"
#include "qquickdialogbuttonbox_p.h"
-#include <QtQml/qqmlinfo.h>
-#include <QtQml/qqmlcontext.h>
-#include <QtQml/qqmlcomponent.h>
-
QT_BEGIN_NAMESPACE
/*!
@@ -62,20 +58,14 @@ QT_BEGIN_NAMESPACE
\section1 Dialog Buttons
- Dialog's standard buttons are managed by \l DialogButtonBox. When a button box
- is assigned as a dialog \l footer or \l header, the dialog's \l standardButtons
- property is forwarded to the respective property of the button box. Furthermore,
- the \l {DialogButtonBox::}{accepted()} and \l {DialogButtonBox::}{rejected()}
+ Dialog's standard buttons are managed by a \l DialogButtonBox that is assigned
+ as a dialog \l footer by default. The dialog's \l standardButtons property is
+ forwarded to the respective property of the button box. Furthermore, the
+ \l {DialogButtonBox::}{accepted()} and \l {DialogButtonBox::}{rejected()}
signals of the button box are connected to the respective signals in Dialog.
\snippet qtquickcontrols2-dialog.qml 1
- \note If any standard buttons are specified for the dialog but no button box has
- been assigned as a footer or header, Dialog automatically creates an instance of
- \l buttonBox, and assigns it as a footer or header of the dialog depending on the
- value of the \l {DialogButtonBox::}{position} property. All built-in Dialog styles
- assign the button box as a footer.
-
\section1 Modal Dialogs
A \l {Popup::}{modal} dialog blocks input to other content beneath
@@ -121,40 +111,6 @@ QT_BEGIN_NAMESPACE
\sa accepted()
*/
-void QQuickDialogPrivate::createButtonBox()
-{
- Q_Q(QQuickDialog);
- QQmlContext *context = qmlContext(q);
- if (!context || !buttonBoxComponent)
- return;
-
- QObject *object = buttonBoxComponent->create(context);
- QQuickDialogButtonBox *buttonBox = qobject_cast<QQuickDialogButtonBox *>(object);
- if (!buttonBox) {
- if (object) {
- qmlInfo(q) << "buttonBox must be an instance of DialogButtonBox";
- delete object;
- }
- return;
- }
-
- if (buttonBox->position() == QQuickDialogButtonBox::Header) {
- if (layout->header()) {
- qmlInfo(q) << "Custom header detected. Cannot assign buttonBox as a header. No standard buttons will appear in the header.";
- delete buttonBox;
- } else {
- q->setHeader(buttonBox);
- }
- } else {
- if (layout->footer()) {
- qmlInfo(q) << "Custom footer detected. Cannot assign buttonBox as a footer. No standard buttons will appear in the footer.";
- delete buttonBox;
- } else {
- q->setFooter(buttonBox);
- }
- }
-}
-
QQuickDialog::QQuickDialog(QObject *parent) :
QQuickPopup(*(new QQuickDialogPrivate), parent)
{
@@ -176,7 +132,7 @@ QQuickDialog::QQuickDialog(QObject *parent) :
header automatically sets the respective \l DialogButtonBox::position,
\l ToolBar::position, or \l TabBar::position property to \c Header.
- \sa footer, buttonBox
+ \sa footer
*/
QQuickItem *QQuickDialog::header() const
{
@@ -223,7 +179,7 @@ void QQuickDialog::setHeader(QQuickItem *header)
footer automatically sets the respective \l DialogButtonBox::position,
\l ToolBar::position, or \l TabBar::position property to \c Footer.
- \sa header, buttonBox
+ \sa header
*/
QQuickItem *QQuickDialog::footer() const
{
@@ -257,33 +213,6 @@ void QQuickDialog::setFooter(QQuickItem *footer)
}
/*!
- \qmlproperty Component QtQuick.Controls::Dialog::buttonBox
-
- This property holds a delegate for creating a button box.
-
- A button box is only created if any standard buttons are set.
- The \l {DialogButtonBox::}{position} property determines whether
- the button box is assigned as a \l header or \l footer.
-
- \sa standardButtons, header, footer, DialogButtonBox
-*/
-QQmlComponent *QQuickDialog::buttonBox() const
-{
- Q_D(const QQuickDialog);
- return d->buttonBoxComponent;
-}
-
-void QQuickDialog::setButtonBox(QQmlComponent *box)
-{
- Q_D(QQuickDialog);
- if (d->buttonBoxComponent == box)
- return;
-
- d->buttonBoxComponent = box;
- emit buttonBoxChanged();
-}
-
-/*!
\qmlproperty enumeration QtQuick.Controls::Dialog::standardButtons
This property holds a combination of standard buttons that are used by the dialog.
@@ -311,7 +240,7 @@ void QQuickDialog::setButtonBox(QQmlComponent *box)
\value Dialog.Ignore An "Ignore" button defined with the \c AcceptRole.
\value Dialog.NoButton An invalid button.
- \sa buttonBox, DialogButtonBox
+ \sa DialogButtonBox
*/
QPlatformDialogHelper::StandardButtons QQuickDialog::standardButtons() const
{
@@ -326,12 +255,8 @@ void QQuickDialog::setStandardButtons(QPlatformDialogHelper::StandardButtons but
return;
d->standardButtons = buttons;
- if (isComponentComplete()) {
- if (d->buttonBox)
- d->buttonBox->setStandardButtons(buttons);
- else if (buttons)
- d->createButtonBox();
- }
+ if (d->buttonBox)
+ d->buttonBox->setStandardButtons(buttons);
emit standardButtonsChanged();
}
@@ -361,14 +286,6 @@ void QQuickDialog::reject()
emit rejected();
}
-void QQuickDialog::componentComplete()
-{
- Q_D(QQuickDialog);
- QQuickPopup::componentComplete();
- if (!d->buttonBox && d->standardButtons)
- d->createButtonBox();
-}
-
void QQuickDialog::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
{
Q_D(QQuickDialog);
diff --git a/src/quicktemplates2/qquickdialog_p.h b/src/quicktemplates2/qquickdialog_p.h
index 2c7eee95..1cd50f4a 100644
--- a/src/quicktemplates2/qquickdialog_p.h
+++ b/src/quicktemplates2/qquickdialog_p.h
@@ -53,7 +53,6 @@
QT_BEGIN_NAMESPACE
-class QQmlComponent;
class QQuickDialogPrivate;
class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickDialog : public QQuickPopup
@@ -61,7 +60,6 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickDialog : public QQuickPopup
Q_OBJECT
Q_PROPERTY(QQuickItem *header READ header WRITE setHeader NOTIFY headerChanged FINAL)
Q_PROPERTY(QQuickItem *footer READ footer WRITE setFooter NOTIFY footerChanged FINAL)
- Q_PROPERTY(QQmlComponent *buttonBox READ buttonBox WRITE setButtonBox NOTIFY buttonBoxChanged FINAL)
Q_PROPERTY(QPlatformDialogHelper::StandardButtons standardButtons READ standardButtons WRITE setStandardButtons NOTIFY standardButtonsChanged FINAL)
Q_FLAGS(QPlatformDialogHelper::StandardButtons)
@@ -74,9 +72,6 @@ public:
QQuickItem *footer() const;
void setFooter(QQuickItem *footer);
- QQmlComponent *buttonBox() const;
- void setButtonBox(QQmlComponent *box);
-
QPlatformDialogHelper::StandardButtons standardButtons() const;
void setStandardButtons(QPlatformDialogHelper::StandardButtons buttons);
@@ -90,11 +85,9 @@ Q_SIGNALS:
void headerChanged();
void footerChanged();
- void buttonBoxChanged();
void standardButtonsChanged();
protected:
- void componentComplete() override;
void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) override;
void paddingChange(const QMarginsF &newPadding, const QMarginsF &oldPadding) override;
diff --git a/src/quicktemplates2/qquickdialog_p_p.h b/src/quicktemplates2/qquickdialog_p_p.h
index a893690d..e5ac7066 100644
--- a/src/quicktemplates2/qquickdialog_p_p.h
+++ b/src/quicktemplates2/qquickdialog_p_p.h
@@ -53,7 +53,6 @@
QT_BEGIN_NAMESPACE
-class QQmlComponent;
class QQuickDialogButtonBox;
class QQuickDialogPrivate : public QQuickPopupPrivate
@@ -61,17 +60,14 @@ class QQuickDialogPrivate : public QQuickPopupPrivate
Q_DECLARE_PUBLIC(QQuickDialog)
public:
- QQuickDialogPrivate() : buttonBox(nullptr), buttonBoxComponent(nullptr) { }
+ QQuickDialogPrivate() : buttonBox(nullptr) { }
static QQuickDialogPrivate *get(QQuickDialog *dialog)
{
return dialog->d_func();
}
- void createButtonBox();
-
QQuickDialogButtonBox *buttonBox;
- QQmlComponent *buttonBoxComponent;
QScopedPointer<QQuickPageLayout> layout;
QPlatformDialogHelper::StandardButtons standardButtons;
};
diff --git a/tests/auto/controls/data/tst_dialog.qml b/tests/auto/controls/data/tst_dialog.qml
index d4cbc222..632bb0c4 100644
--- a/tests/auto/controls/data/tst_dialog.qml
+++ b/tests/auto/controls/data/tst_dialog.qml
@@ -62,16 +62,6 @@ TestCase {
}
Component {
- id: headerBox
- DialogButtonBox { position: DialogButtonBox.Header }
- }
-
- Component {
- id: footerBox
- DialogButtonBox { position: DialogButtonBox.Footer }
- }
-
- Component {
id: signalSpy
SignalSpy { }
}
@@ -80,8 +70,7 @@ TestCase {
var control = dialog.createObject(testCase)
verify(control)
verify(!control.header)
- verify(!control.footer)
- verify(control.buttonBox)
+ verify(control.footer)
compare(control.standardButtons, 0)
control.destroy()
}
@@ -122,22 +111,18 @@ TestCase {
function test_buttonBox_data() {
return [
- { tag: "default header", property: "header", buttonBox: headerBox },
- { tag: "default footer", property: "footer", buttonBox: footerBox },
- { tag: "custom header", property: "header", position: DialogButtonBox.Header },
- { tag: "custom footer", property: "footer", position: DialogButtonBox.Footer }
+ { tag: "default" },
+ { tag: "custom", custom: true }
]
}
function test_buttonBox(data) {
var control = dialog.createObject(testCase)
- if (data.buttonBox)
- control.buttonBox = data.buttonBox
- else
- control[data.property] = buttonBox.createObject(testCase, {position: data.position})
+ if (data.custom)
+ control.footer = buttonBox.createObject(testCase)
control.standardButtons = Dialog.Ok | Dialog.Cancel
- var box = control[data.property]
+ var box = control.footer
verify(box)
compare(box.standardButtons, Dialog.Ok | Dialog.Cancel)
@@ -192,30 +177,6 @@ TestCase {
control.destroy()
}
- function test_warnings() {
- var control = dialog.createObject(testCase)
- verify(control)
-
- var testComponent = Qt.createComponent("TestItem.qml")
- verify(testComponent)
-
- control.buttonBox = headerBox
- control.header = testComponent.createObject(testCase)
- ignoreWarning(Qt.resolvedUrl("tst_dialog.qml") + ":56:9: QML Dialog: Custom header detected. Cannot assign buttonBox as a header. No standard buttons will appear in the header.")
- control.standardButtons = Dialog.Apply
-
- control.buttonBox = footerBox
- control.footer = testComponent.createObject(testCase)
- ignoreWarning(Qt.resolvedUrl("tst_dialog.qml") + ":56:9: QML Dialog: Custom footer detected. Cannot assign buttonBox as a footer. No standard buttons will appear in the footer.")
- control.standardButtons = Dialog.Cancel
-
- control.buttonBox = testComponent
- ignoreWarning(Qt.resolvedUrl("tst_dialog.qml") + ":56:9: QML Dialog: buttonBox must be an instance of DialogButtonBox")
- control.standardButtons = Dialog.Ok
-
- control.destroy()
- }
-
function test_layout() {
var control = dialog.createObject(testCase, {width: 100, height: 100})
verify(control)