summaryrefslogtreecommitdiffstats
path: root/tests/manual/dialogs
diff options
context:
space:
mode:
authorMikolaj Boc <mikolaj.boc@qt.io>2022-09-13 13:23:09 +0200
committerMikolaj Boc <mikolaj.boc@qt.io>2022-09-13 18:13:00 +0200
commit701852e17b6440540bda4cbfb83743cf8fd2d4ba (patch)
treeb0545059e9e4ca201fcf87b117679eed887bed27 /tests/manual/dialogs
parent9ec7cbc77462938969e9569deeb5a106d321ce21 (diff)
Add window-modal show option to dialogs manual test
This provides an easy way to test window modality using a ready available test. Change-Id: Ia23736c61fd56dda8f72ae19f5f102163951271b Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'tests/manual/dialogs')
-rw-r--r--tests/manual/dialogs/colordialogpanel.cpp17
-rw-r--r--tests/manual/dialogs/colordialogpanel.h2
-rw-r--r--tests/manual/dialogs/filedialogpanel.cpp21
-rw-r--r--tests/manual/dialogs/filedialogpanel.h2
-rw-r--r--tests/manual/dialogs/fontdialogpanel.cpp17
-rw-r--r--tests/manual/dialogs/fontdialogpanel.h2
-rw-r--r--tests/manual/dialogs/utils.cpp37
-rw-r--r--tests/manual/dialogs/utils.h16
-rw-r--r--tests/manual/dialogs/wizardpanel.cpp22
-rw-r--r--tests/manual/dialogs/wizardpanel.h3
10 files changed, 97 insertions, 42 deletions
diff --git a/tests/manual/dialogs/colordialogpanel.cpp b/tests/manual/dialogs/colordialogpanel.cpp
index 100edd76a1..2508193e0a 100644
--- a/tests/manual/dialogs/colordialogpanel.cpp
+++ b/tests/manual/dialogs/colordialogpanel.cpp
@@ -2,6 +2,7 @@
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "colordialogpanel.h"
+#include "utils.h"
#include <QGroupBox>
#include <QCheckBox>
@@ -44,15 +45,6 @@ static inline QStringList svgColorNames()
<< "turquoise" << "violet" << "wheat" << "white" << "whitesmoke" << "yellow" << "yellowgreen";
}
-static inline QPushButton *addButton(const QString &description, QVBoxLayout *layout,
- QObject *receiver, const char *slotFunc)
-{
- QPushButton *button = new QPushButton(description);
- QObject::connect(button, SIGNAL(clicked()), receiver, slotFunc);
- layout->addWidget(button);
- return button;
-}
-
class ColorProxyModel : public QSortFilterProxyModel
{
public:
@@ -103,7 +95,9 @@ ColorDialogPanel::ColorDialogPanel(QWidget *parent)
QGroupBox *buttonsGroupBox = new QGroupBox(tr("Show"));
QVBoxLayout *buttonsLayout = new QVBoxLayout(buttonsGroupBox);
addButton(tr("Exec modal"), buttonsLayout, this, SLOT(execModal()));
- addButton(tr("Show modal"), buttonsLayout, this, SLOT(showModal()));
+ addButton(tr("Show application modal"), buttonsLayout,
+ [this]() { showModal(Qt::ApplicationModal); });
+ addButton(tr("Show window modal"), buttonsLayout, [this]() { showModal(Qt::WindowModal); });
m_deleteModalDialogButton =
addButton(tr("Delete modal"), buttonsLayout, this, SLOT(deleteModalDialog()));
addButton(tr("Show non-modal"), buttonsLayout, this, SLOT(showNonModal()));
@@ -137,7 +131,7 @@ void ColorDialogPanel::execModal()
dialog.exec();
}
-void ColorDialogPanel::showModal()
+void ColorDialogPanel::showModal(Qt::WindowModality modality)
{
if (m_modalDialog.isNull()) {
static int n = 0;
@@ -151,6 +145,7 @@ void ColorDialogPanel::showModal()
.arg(QLatin1String(QT_VERSION_STR)));
enableDeleteModalDialogButton();
}
+ m_modalDialog->setWindowModality(modality);
applySettings(m_modalDialog);
m_modalDialog->show();
}
diff --git a/tests/manual/dialogs/colordialogpanel.h b/tests/manual/dialogs/colordialogpanel.h
index ea2dff97e0..3f61df5acd 100644
--- a/tests/manual/dialogs/colordialogpanel.h
+++ b/tests/manual/dialogs/colordialogpanel.h
@@ -21,7 +21,7 @@ public:
public slots:
void execModal();
- void showModal();
+ void showModal(Qt::WindowModality modality);
void showNonModal();
void deleteNonModalDialog();
void deleteModalDialog();
diff --git a/tests/manual/dialogs/filedialogpanel.cpp b/tests/manual/dialogs/filedialogpanel.cpp
index 64a7bc2d8d..f7e2cfa638 100644
--- a/tests/manual/dialogs/filedialogpanel.cpp
+++ b/tests/manual/dialogs/filedialogpanel.cpp
@@ -43,15 +43,6 @@ const FlagData fileModeComboData[] =
{"Directory", QFileDialog::Directory}
};
-static inline QPushButton *addButton(const QString &description, QGridLayout *layout,
- int &row, int column, QObject *receiver, const char *slotFunc)
-{
- QPushButton *button = new QPushButton(description);
- QObject::connect(button, SIGNAL(clicked()), receiver, slotFunc);
- layout->addWidget(button, row++, column);
- return button;
-}
-
// A line edit for editing the label fields of the dialog, keeping track of whether it has
// been modified by the user to avoid applying Qt's default texts to native dialogs.
@@ -152,9 +143,12 @@ FileDialogPanel::FileDialogPanel(QWidget *parent)
int row = 0;
int column = 0;
addButton(tr("Exec modal"), buttonLayout, row, column, this, SLOT(execModal()));
- addButton(tr("Show modal"), buttonLayout, row, column, this, SLOT(showModal()));
- m_deleteModalDialogButton =
- addButton(tr("Delete modal"), buttonLayout, row, column, this, SLOT(deleteModalDialog()));
+ addButton(tr("Show application modal"), buttonLayout, row, column,
+ [this]() { showModal(Qt::ApplicationModal); });
+ addButton(tr("Show window modal"), buttonLayout, row, column,
+ [this]() { showModal(Qt::WindowModal); });
+ m_deleteModalDialogButton = addButton(tr("Delete modal"), buttonLayout, row, column, this,
+ SLOT(deleteModalDialog()));
addButton(tr("Show non-modal"), buttonLayout, row, column, this, SLOT(showNonModal()));
m_deleteNonModalDialogButton =
addButton(tr("Delete non-modal"), buttonLayout, row, column, this, SLOT(deleteNonModalDialog()));
@@ -193,7 +187,7 @@ void FileDialogPanel::execModal()
dialog.exec();
}
-void FileDialogPanel::showModal()
+void FileDialogPanel::showModal(Qt::WindowModality modality)
{
if (m_modalDialog.isNull()) {
static int n = 0;
@@ -205,6 +199,7 @@ void FileDialogPanel::showModal()
.arg(QLatin1String(QT_VERSION_STR)));
enableDeleteModalDialogButton();
}
+ m_modalDialog->setWindowModality(modality);
applySettings(m_modalDialog);
m_modalDialog->show();
}
diff --git a/tests/manual/dialogs/filedialogpanel.h b/tests/manual/dialogs/filedialogpanel.h
index 42d6f09705..1cce1dfdd1 100644
--- a/tests/manual/dialogs/filedialogpanel.h
+++ b/tests/manual/dialogs/filedialogpanel.h
@@ -26,7 +26,7 @@ public:
public slots:
void execModal();
- void showModal();
+ void showModal(Qt::WindowModality modality);
void showNonModal();
void deleteNonModalDialog();
void deleteModalDialog();
diff --git a/tests/manual/dialogs/fontdialogpanel.cpp b/tests/manual/dialogs/fontdialogpanel.cpp
index 63bef18513..df896fcccd 100644
--- a/tests/manual/dialogs/fontdialogpanel.cpp
+++ b/tests/manual/dialogs/fontdialogpanel.cpp
@@ -2,6 +2,7 @@
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "fontdialogpanel.h"
+#include "utils.h"
#include <QGroupBox>
#include <QCheckBox>
@@ -14,15 +15,6 @@
#include <QTimer>
#include <QDebug>
-static inline QPushButton *addButton(const QString &description, QVBoxLayout *layout,
- QObject *receiver, const char *slotFunc)
-{
- QPushButton *button = new QPushButton(description);
- QObject::connect(button, SIGNAL(clicked()), receiver, slotFunc);
- layout->addWidget(button);
- return button;
-}
-
FontDialogPanel::FontDialogPanel(QWidget *parent)
: QWidget(parent)
, m_fontFamilyBox(new QFontComboBox)
@@ -55,7 +47,9 @@ FontDialogPanel::FontDialogPanel(QWidget *parent)
QGroupBox *buttonsGroupBox = new QGroupBox(tr("Show"));
QVBoxLayout *buttonsLayout = new QVBoxLayout(buttonsGroupBox);
addButton(tr("Exec modal"), buttonsLayout, this, SLOT(execModal()));
- addButton(tr("Show modal"), buttonsLayout, this, SLOT(showModal()));
+ addButton(tr("Show application modal"), buttonsLayout,
+ [this]() { showModal(Qt::ApplicationModal); });
+ addButton(tr("Show window modal"), buttonsLayout, [this]() { showModal(Qt::WindowModal); });
m_deleteModalDialogButton =
addButton(tr("Delete modal"), buttonsLayout, this, SLOT(deleteModalDialog()));
addButton(tr("Show non-modal"), buttonsLayout, this, SLOT(showNonModal()));
@@ -87,7 +81,7 @@ void FontDialogPanel::execModal()
dialog.exec();
}
-void FontDialogPanel::showModal()
+void FontDialogPanel::showModal(Qt::WindowModality modality)
{
if (m_modalDialog.isNull()) {
static int n = 0;
@@ -99,6 +93,7 @@ void FontDialogPanel::showModal()
.arg(QLatin1String(QT_VERSION_STR)));
enableDeleteModalDialogButton();
}
+ m_modalDialog->setWindowModality(modality);
applySettings(m_modalDialog);
m_modalDialog->show();
}
diff --git a/tests/manual/dialogs/fontdialogpanel.h b/tests/manual/dialogs/fontdialogpanel.h
index 3ba581cf1e..895d741f2f 100644
--- a/tests/manual/dialogs/fontdialogpanel.h
+++ b/tests/manual/dialogs/fontdialogpanel.h
@@ -22,7 +22,7 @@ public:
public slots:
void execModal();
- void showModal();
+ void showModal(Qt::WindowModality modality);
void showNonModal();
void deleteNonModalDialog();
void deleteModalDialog();
diff --git a/tests/manual/dialogs/utils.cpp b/tests/manual/dialogs/utils.cpp
index 871940cf2a..9ac5f66a85 100644
--- a/tests/manual/dialogs/utils.cpp
+++ b/tests/manual/dialogs/utils.cpp
@@ -4,6 +4,8 @@
#include "utils.h"
#include <QCheckBox>
+#include <QGridLayout>
+#include <QPushButton>
#include <QVBoxLayout>
QComboBox *createCombo(QWidget *parent, const FlagData *d, size_t size)
@@ -66,3 +68,38 @@ int OptionsControl::intValue() const
}
return result;
}
+
+QPushButton *addButton(const QString &description, QGridLayout *layout, int &row, int column,
+ QObject *receiver, const char *slotFunc)
+{
+ QPushButton *button = new QPushButton(description);
+ QObject::connect(button, SIGNAL(clicked()), receiver, slotFunc);
+ layout->addWidget(button, row++, column);
+ return button;
+}
+
+QPushButton *addButton(const QString &description, QGridLayout *layout, int &row, int column,
+ std::function<void()> fn)
+{
+ QPushButton *button = new QPushButton(description);
+ QObject::connect(button, &QPushButton::clicked, fn);
+ layout->addWidget(button, row++, column);
+ return button;
+}
+
+QPushButton *addButton(const QString &description, QVBoxLayout *layout, QObject *receiver,
+ const char *slotFunc)
+{
+ QPushButton *button = new QPushButton(description);
+ QObject::connect(button, SIGNAL(clicked()), receiver, slotFunc);
+ layout->addWidget(button);
+ return button;
+}
+
+QPushButton *addButton(const QString &description, QVBoxLayout *layout, std::function<void()> fn)
+{
+ QPushButton *button = new QPushButton(description);
+ QObject::connect(button, &QPushButton::clicked, fn);
+ layout->addWidget(button);
+ return button;
+}
diff --git a/tests/manual/dialogs/utils.h b/tests/manual/dialogs/utils.h
index 7d257eea02..83362958b2 100644
--- a/tests/manual/dialogs/utils.h
+++ b/tests/manual/dialogs/utils.h
@@ -10,7 +10,12 @@
#include <QPair>
#include <QList>
+#include <functional>
+
QT_FORWARD_DECLARE_CLASS(QCheckBox)
+QT_FORWARD_DECLARE_CLASS(QGridLayout)
+QT_FORWARD_DECLARE_CLASS(QVBoxLayout)
+QT_FORWARD_DECLARE_CLASS(QPushButton)
// Associate enum/flag value with a description.
struct FlagData
@@ -51,4 +56,15 @@ private:
QList<CheckBoxFlagPair> m_checkBoxes;
};
+QPushButton *addButton(const QString &description, QGridLayout *layout, int &row, int column,
+ QObject *receiver, const char *slotFunc);
+
+QPushButton *addButton(const QString &description, QGridLayout *layout, int &row, int column,
+ std::function<void()> fn);
+
+QPushButton *addButton(const QString &description, QVBoxLayout *layout, QObject *receiver,
+ const char *slotFunc);
+
+QPushButton *addButton(const QString &description, QVBoxLayout *layout, std::function<void()> fn);
+
#endif // UTILS_H
diff --git a/tests/manual/dialogs/wizardpanel.cpp b/tests/manual/dialogs/wizardpanel.cpp
index f5f8f1b77a..36605de9fa 100644
--- a/tests/manual/dialogs/wizardpanel.cpp
+++ b/tests/manual/dialogs/wizardpanel.cpp
@@ -271,8 +271,14 @@ WizardPanel::WizardPanel(QWidget *parent)
gridLayout->addWidget(m_styleControl, 0, 1);
QGroupBox *buttonGroupBox = new QGroupBox(this);
QVBoxLayout *vLayout = new QVBoxLayout(buttonGroupBox);
- QPushButton *button = new QPushButton(tr("Show modal"), this);
- connect(button, SIGNAL(clicked()), this, SLOT(showModal()));
+ QPushButton *button = new QPushButton(tr("Exec modal"), this);
+ connect(button, SIGNAL(clicked()), this, SLOT(execModal()));
+ vLayout->addWidget(button);
+ button = new QPushButton(tr("Show application modal"), this);
+ connect(button, &QPushButton::clicked, [this]() { showModal(Qt::ApplicationModal); });
+ vLayout->addWidget(button);
+ button = new QPushButton(tr("Show window modal"), this);
+ connect(button, &QPushButton::clicked, [this]() { showModal(Qt::WindowModal); });
vLayout->addWidget(button);
button = new QPushButton(tr("Show non-modal"), this);
connect(button, SIGNAL(clicked()), this, SLOT(showNonModal()));
@@ -285,13 +291,23 @@ WizardPanel::WizardPanel(QWidget *parent)
gridLayout->addWidget(buttonGroupBox, 1, 1);
}
-void WizardPanel::showModal()
+void WizardPanel::execModal()
{
Wizard wizard(this);
applyParameters(&wizard);
wizard.exec();
}
+void WizardPanel::showModal(Qt::WindowModality modality)
+{
+ Wizard *wizard = new Wizard(this);
+ applyParameters(wizard);
+ wizard->setModal(true);
+ wizard->setAttribute(Qt::WA_DeleteOnClose);
+ wizard->setWindowModality(modality);
+ wizard->show();
+}
+
void WizardPanel::showNonModal()
{
Wizard *wizard = new Wizard(this);
diff --git a/tests/manual/dialogs/wizardpanel.h b/tests/manual/dialogs/wizardpanel.h
index d17f4dee8a..e802fb10ea 100644
--- a/tests/manual/dialogs/wizardpanel.h
+++ b/tests/manual/dialogs/wizardpanel.h
@@ -19,7 +19,8 @@ public:
explicit WizardPanel(QWidget *parent = nullptr);
public slots:
- void showModal();
+ void execModal();
+ void showModal(Qt::WindowModality modality);
void showNonModal();
void showEmbedded();