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>
This commit is contained in:
Mikolaj Boc 2022-09-13 13:23:09 +02:00
parent 9ec7cbc774
commit 701852e17b
10 changed files with 97 additions and 42 deletions

View File

@ -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();
}

View File

@ -21,7 +21,7 @@ public:
public slots:
void execModal();
void showModal();
void showModal(Qt::WindowModality modality);
void showNonModal();
void deleteNonModalDialog();
void deleteModalDialog();

View File

@ -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();
}

View File

@ -26,7 +26,7 @@ public:
public slots:
void execModal();
void showModal();
void showModal(Qt::WindowModality modality);
void showNonModal();
void deleteNonModalDialog();
void deleteModalDialog();

View File

@ -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();
}

View File

@ -22,7 +22,7 @@ public:
public slots:
void execModal();
void showModal();
void showModal(Qt::WindowModality modality);
void showNonModal();
void deleteNonModalDialog();
void deleteModalDialog();

View File

@ -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;
}

View File

@ -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

View File

@ -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);

View File

@ -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();