From 9c6a91d07bae5517a9909ef5b6f4acb1e99ec948 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Thu, 17 Jan 2013 15:49:42 +0100 Subject: [PATCH] Manual file dialog test: Add showModal(). Modal dialogs can now tested by just showing or running exec(). Remove connection of accept() from applySettings(). Change-Id: I5e3c0e6405ce5682f39d10a9c06b9d61be10ed3f Reviewed-by: Joerg Bornemann --- tests/manual/dialogs/filedialogpanel.cpp | 71 ++++++++++++++++++------ tests/manual/dialogs/filedialogpanel.h | 5 ++ 2 files changed, 58 insertions(+), 18 deletions(-) diff --git a/tests/manual/dialogs/filedialogpanel.cpp b/tests/manual/dialogs/filedialogpanel.cpp index ba582414ce..aa90465e2c 100644 --- a/tests/manual/dialogs/filedialogpanel.cpp +++ b/tests/manual/dialogs/filedialogpanel.cpp @@ -44,6 +44,7 @@ #include #include #include +#include #include #include #include @@ -105,11 +106,12 @@ inline void setComboBoxValue(QComboBox *c, int v) c->setCurrentIndex(c->findData(QVariant(v))); } -static inline QPushButton *addButton(const QString &description, QBoxLayout *layout, QObject *receiver, const char *slotFunc) +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); + layout->addWidget(button, row++, column); return button; } @@ -161,6 +163,7 @@ FileDialogPanel::FileDialogPanel(QWidget *parent) , m_nameFilters(new QPlainTextEdit) , m_selectedNameFilter(new QLineEdit(this)) , m_deleteNonModalDialogButton(0) + , m_deleteModalDialogButton(0) { // Options QGroupBox *optionsGroupBox = new QGroupBox(tr("Options")); @@ -199,21 +202,24 @@ FileDialogPanel::FileDialogPanel(QWidget *parent) labelsLayout->addRow(tr("Reject label:"), m_labelLineEdits.back()); // Buttons - QVBoxLayout *buttonLayout = new QVBoxLayout; - buttonLayout->addSpacerItem(new QSpacerItem(0, 0, QSizePolicy::Ignored, QSizePolicy::MinimumExpanding)); - addButton(tr("Show modal"), buttonLayout, this, SLOT(showModal())); - addButton(tr("Show non-modal"), buttonLayout, this, SLOT(showNonModal())); - m_deleteNonModalDialogButton = - addButton(tr("Delete non-modal"), buttonLayout, this, SLOT(deleteNonModalDialog())); - addButton(tr("getOpenFileName"), buttonLayout, this, SLOT(getOpenFileName())); - addButton(tr("getOpenFileNames"), buttonLayout, this, SLOT(getOpenFileNames())); - addButton(tr("getSaveFileName"), buttonLayout, this, SLOT(getSaveFileName())); - addButton(tr("getExistingDirectory"), buttonLayout, this, SLOT(getExistingDirectory())); - addButton(tr("Restore defaults"), buttonLayout, this, SLOT(restoreDefaults())); QGroupBox *buttonsGroupBox = new QGroupBox(tr("Show")); - QHBoxLayout *buttonsGroupLayout = new QHBoxLayout(buttonsGroupBox); - buttonsGroupLayout->addSpacerItem(new QSpacerItem(0, 0, QSizePolicy::MinimumExpanding, QSizePolicy::Ignored)); - buttonsGroupLayout->addLayout(buttonLayout); + QGridLayout *buttonLayout = new QGridLayout(buttonsGroupBox); + 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 non-modal"), buttonLayout, row, column, this, SLOT(showNonModal())); + m_deleteNonModalDialogButton = + addButton(tr("Delete non-modal"), buttonLayout, row, column, this, SLOT(deleteNonModalDialog())); + row = 0; + column++; + addButton(tr("getOpenFileName"), buttonLayout, row, column, this, SLOT(getOpenFileName())); + addButton(tr("getOpenFileNames"), buttonLayout, row, column, this, SLOT(getOpenFileNames())); + addButton(tr("getSaveFileName"), buttonLayout, row, column, this, SLOT(getSaveFileName())); + addButton(tr("getExistingDirectory"), buttonLayout, row, column, this, SLOT(getExistingDirectory())); + addButton(tr("Restore defaults"), buttonLayout, row, column, this, SLOT(restoreDefaults())); // Main layout QGridLayout *gridLayout = new QGridLayout(this); @@ -226,19 +232,36 @@ FileDialogPanel::FileDialogPanel(QWidget *parent) restoreDefaults(); } -void FileDialogPanel::showModal() +void FileDialogPanel::execModal() { QFileDialog dialog(this); applySettings(&dialog); + connect(&dialog, SIGNAL(accepted()), this, SLOT(accepted())); dialog.setWindowTitle(tr("Modal File Dialog Qt %1").arg(QLatin1String(QT_VERSION_STR))); dialog.exec(); } +void FileDialogPanel::showModal() +{ + if (m_modalDialog.isNull()) { + static int n = 0; + m_modalDialog = new QFileDialog(this); + m_modalDialog->setModal(true); + connect(m_modalDialog.data(), SIGNAL(accepted()), this, SLOT(accepted())); + m_modalDialog->setWindowTitle(tr("Modal File Dialog #%1 Qt %2") + .arg(++n) + .arg(QLatin1String(QT_VERSION_STR))); + } + applySettings(m_modalDialog); + m_modalDialog->show(); +} + void FileDialogPanel::showNonModal() { if (m_nonModalDialog.isNull()) { static int n = 0; m_nonModalDialog = new QFileDialog(this); + connect(m_nonModalDialog.data(), SIGNAL(accepted()), this, SLOT(accepted())); m_nonModalDialog->setWindowTitle(tr("Non-Modal File Dialog #%1 Qt %2") .arg(++n) .arg(QLatin1String(QT_VERSION_STR))); @@ -255,11 +278,24 @@ void FileDialogPanel::deleteNonModalDialog() enableDeleteNonModalDialogButton(); } +void FileDialogPanel::deleteModalDialog() +{ + if (!m_modalDialog.isNull()) + delete m_modalDialog; + enableDeleteModalDialogButton(); +} + void FileDialogPanel::enableDeleteNonModalDialogButton() { m_deleteNonModalDialogButton->setEnabled(!m_nonModalDialog.isNull()); } +void FileDialogPanel::enableDeleteModalDialogButton() +{ + m_deleteModalDialogButton->setEnabled(!m_modalDialog.isNull()); +} + + QString FileDialogPanel::filterString() const { return m_nameFilters->toPlainText().trimmed().replace(QLatin1String("\n"), QLatin1String(";;")); @@ -372,7 +408,6 @@ void FileDialogPanel::applySettings(QFileDialog *d) const d->selectNameFilter(filter); foreach (LabelLineEdit *l, m_labelLineEdits) l->apply(d); - connect(d, SIGNAL(accepted()), this, SLOT(accepted())); } void FileDialogPanel::accepted() diff --git a/tests/manual/dialogs/filedialogpanel.h b/tests/manual/dialogs/filedialogpanel.h index e52324f99d..7ee7cb3f60 100644 --- a/tests/manual/dialogs/filedialogpanel.h +++ b/tests/manual/dialogs/filedialogpanel.h @@ -60,9 +60,11 @@ public: explicit FileDialogPanel(QWidget *parent = 0); public slots: + void execModal(); void showModal(); void showNonModal(); void deleteNonModalDialog(); + void deleteModalDialog(); void getOpenFileNames(); void getOpenFileName(); void getSaveFileName(); @@ -73,6 +75,7 @@ public slots: private slots: void enableDeleteNonModalDialogButton(); + void enableDeleteModalDialogButton(); private: QString filterString() const; @@ -94,7 +97,9 @@ private: QPlainTextEdit *m_nameFilters; QLineEdit *m_selectedNameFilter; QPushButton *m_deleteNonModalDialogButton; + QPushButton *m_deleteModalDialogButton; QString m_result; + QPointer m_modalDialog; QPointer m_nonModalDialog; };