diff options
author | Leander Beernaert <leander.beernaert@qt.io> | 2019-12-09 13:20:36 +0100 |
---|---|---|
committer | Leander Beernaert <leander.beernaert@qt.io> | 2019-12-09 14:10:55 +0100 |
commit | 86c2949b41dc7dde2ac6538c7fa04db4343601d4 (patch) | |
tree | 6c35d5b4a42ce25f367799762a35cb1d52a451a0 /src/designer/src/designer | |
parent | 7ee63f412379f55287aa471f284f3a49f9796b60 (diff) | |
parent | aa40303166b8596bf21cdcf4286cb3d548b7ac9e (diff) |
Merge remote-tracking branch 'origin/dev' into wip/cmake
Change-Id: I6368c62aaf33bff9d9f41d7830ee7411c2cfd827
Diffstat (limited to 'src/designer/src/designer')
-rw-r--r-- | src/designer/src/designer/appfontdialog.cpp | 10 | ||||
-rw-r--r-- | src/designer/src/designer/doc/qtdesigner.qdocconf | 1 | ||||
-rw-r--r-- | src/designer/src/designer/doc/src/qtdesigner-module.qdoc | 5 | ||||
-rw-r--r-- | src/designer/src/designer/mainwindow.cpp | 13 | ||||
-rw-r--r-- | src/designer/src/designer/newform.cpp | 11 | ||||
-rw-r--r-- | src/designer/src/designer/qdesigner.cpp | 2 | ||||
-rw-r--r-- | src/designer/src/designer/qdesigner_actions.cpp | 139 | ||||
-rw-r--r-- | src/designer/src/designer/qdesigner_formwindow.cpp | 2 | ||||
-rw-r--r-- | src/designer/src/designer/qdesigner_settings.cpp | 1 | ||||
-rw-r--r-- | src/designer/src/designer/qdesigner_workbench.cpp | 22 |
10 files changed, 75 insertions, 131 deletions
diff --git a/src/designer/src/designer/appfontdialog.cpp b/src/designer/src/designer/appfontdialog.cpp index b1a3942df..12dd80bed 100644 --- a/src/designer/src/designer/appfontdialog.cpp +++ b/src/designer/src/designer/appfontdialog.cpp @@ -82,7 +82,7 @@ public: // Store loaded fonts as pair of file name and Id using FileNameFontIdPair = QPair<QString,int>; - using FileNameFontIdPairs = QList<FileNameFontIdPair>; + using FileNameFontIdPairs = QVector<FileNameFontIdPair>; const FileNameFontIdPairs &fonts() const; private: @@ -122,7 +122,7 @@ void AppFontManager::restore(const QDesignerSettingsInterface *s, const QString if (debugAppFontWidget) qDebug() << "AppFontManager::restoring" << fontFiles.size() << "fonts from " << prefix; - if (!fontFiles.empty()) { + if (!fontFiles.isEmpty()) { QString errorMessage; const QStringList::const_iterator cend = fontFiles.constEnd(); for (QStringList::const_iterator it = fontFiles.constBegin(); it != cend; ++it) @@ -311,7 +311,7 @@ void AppFontWidget::addFiles() const QStringList files = QFileDialog::getOpenFileNames(this, tr("Add Font Files"), QString(), tr("Font files (*.ttf)")); - if (files.empty()) + if (files.isEmpty()) return; QString errorMessage; @@ -331,7 +331,7 @@ void AppFontWidget::addFiles() static void removeFonts(const QModelIndexList &selectedIndexes, AppFontModel *model, QWidget *dialogParent) { - if (selectedIndexes.empty()) + if (selectedIndexes.isEmpty()) return; // Reverse sort top level rows and remove @@ -382,7 +382,7 @@ void AppFontWidget::slotRemoveAll() void AppFontWidget::selectionChanged(const QItemSelection &selected, const QItemSelection & /*deselected*/) { - m_removeButton->setEnabled(!selected.indexes().empty()); + m_removeButton->setEnabled(!selected.indexes().isEmpty()); } void AppFontWidget::save(QDesignerSettingsInterface *s, const QString &prefix) diff --git a/src/designer/src/designer/doc/qtdesigner.qdocconf b/src/designer/src/designer/doc/qtdesigner.qdocconf index cc0d881aa..f524537ab 100644 --- a/src/designer/src/designer/doc/qtdesigner.qdocconf +++ b/src/designer/src/designer/doc/qtdesigner.qdocconf @@ -1,4 +1,5 @@ include($QT_INSTALL_DOCS/global/qt-module-defaults.qdocconf) +include($QT_INSTALL_DOCS/config/exampleurl-qttools.qdocconf) project = QtDesigner description = Qt Designer Manual diff --git a/src/designer/src/designer/doc/src/qtdesigner-module.qdoc b/src/designer/src/designer/doc/src/qtdesigner-module.qdoc index eaf816f42..b13f2ae9f 100644 --- a/src/designer/src/designer/doc/src/qtdesigner-module.qdoc +++ b/src/designer/src/designer/doc/src/qtdesigner-module.qdoc @@ -46,3 +46,8 @@ \snippet plugins/doc_src_qtdesigner.pro 1 */ + +/*! + \namespace qdesigner_internal + \internal +*/ diff --git a/src/designer/src/designer/mainwindow.cpp b/src/designer/src/designer/mainwindow.cpp index 3a1ae3ce9..dba96fd86 100644 --- a/src/designer/src/designer/mainwindow.cpp +++ b/src/designer/src/designer/mainwindow.cpp @@ -150,12 +150,11 @@ QStringList DockedMdiArea::uiFiles(const QMimeData *d) const QStringList rc; if (!d->hasFormat(QLatin1String(uriListMimeFormatC))) return rc; - const QList<QUrl> urls = d->urls(); - if (urls.empty()) + const auto urls = d->urls(); + if (urls.isEmpty()) return rc; - const QList<QUrl>::const_iterator cend = urls.constEnd(); - for (QList<QUrl>::const_iterator it = urls.constBegin(); it != cend; ++it) { - const QString fileName = it->toLocalFile(); + for (const auto &url : urls) { + const QString fileName = url.toLocalFile(); if (!fileName.isEmpty() && fileName.endsWith(m_extension)) rc.push_back(fileName); } @@ -169,7 +168,7 @@ bool DockedMdiArea::event(QEvent *event) switch (event->type()) { case QEvent::DragEnter: { QDragEnterEvent *e = static_cast<QDragEnterEvent*>(event); - if (!uiFiles(e->mimeData()).empty()) { + if (!uiFiles(e->mimeData()).isEmpty()) { e->acceptProposedAction(); return true; } @@ -338,7 +337,7 @@ QMdiSubWindow *DockedMainWindow::createMdiSubWindow(QWidget *fw, Qt::WindowFlags // designer menu actions if (designerCloseActionShortCut == QKeySequence(QKeySequence::Close)) { const ActionList systemMenuActions = rc->systemMenu()->actions(); - if (!systemMenuActions.empty()) { + if (!systemMenuActions.isEmpty()) { const ActionList::const_iterator cend = systemMenuActions.constEnd(); for (ActionList::const_iterator it = systemMenuActions.constBegin(); it != cend; ++it) { if ( (*it)->shortcut() == designerCloseActionShortCut) { diff --git a/src/designer/src/designer/newform.cpp b/src/designer/src/designer/newform.cpp index 797e60149..35199927a 100644 --- a/src/designer/src/designer/newform.cpp +++ b/src/designer/src/designer/newform.cpp @@ -103,13 +103,10 @@ QDialogButtonBox *NewForm::createButtonBox() QDesignerActions *da = m_workbench->actionManager(); QMenu *recentFilesMenu = new QMenu(tr("&Recent Forms"), m_recentButton); // Pop the "Recent Files" stuff in here. - const QList<QAction *> recentActions = da->recentFilesActions()->actions(); - if (!recentActions.empty()) { - const QList<QAction *>::const_iterator acend = recentActions.constEnd(); - for (QList<QAction *>::const_iterator it = recentActions.constBegin(); it != acend; ++it) { - recentFilesMenu->addAction(*it); - connect(*it, &QAction::triggered, this, &NewForm::recentFileChosen); - } + const auto recentActions = da->recentFilesActions()->actions(); + for (auto action : recentActions) { + recentFilesMenu->addAction(action); + connect(action, &QAction::triggered, this, &NewForm::recentFileChosen); } m_recentButton->setMenu(recentFilesMenu); connect(buttonBox, &QDialogButtonBox::clicked, this, &NewForm::slotButtonBoxClicked); diff --git a/src/designer/src/designer/qdesigner.cpp b/src/designer/src/designer/qdesigner.cpp index ff244ec29..4344b1c07 100644 --- a/src/designer/src/designer/qdesigner.cpp +++ b/src/designer/src/designer/qdesigner.cpp @@ -252,7 +252,7 @@ QDesigner::ParseArgumentsResult QDesigner::parseCommandLineArguments() m_suppressNewFormShow = m_workbench->readInBackup(); - if (!options.files.empty()) { + if (!options.files.isEmpty()) { const QStringList::const_iterator cend = options.files.constEnd(); for (QStringList::const_iterator it = options.files.constBegin(); it != cend; ++it) { // Ensure absolute paths for recent file list to be unique diff --git a/src/designer/src/designer/qdesigner_actions.cpp b/src/designer/src/designer/qdesigner_actions.cpp index 970599f14..ea296fc27 100644 --- a/src/designer/src/designer/qdesigner_actions.cpp +++ b/src/designer/src/designer/qdesigner_actions.cpp @@ -92,6 +92,8 @@ #include <QtCore/qtimer.h> #include <QtCore/qmetaobject.h> #include <QtCore/qfileinfo.h> +#include <QtCore/qsavefile.h> +#include <QtCore/qscopedpointer.h> #include <QtWidgets/qstatusbar.h> #include <QtWidgets/qdesktopwidget.h> #include <QtXml/qdom.h> @@ -129,36 +131,18 @@ static inline QString savedMessage(const QString &fileName) return QDesignerActions::tr("Saved %1.").arg(fileName); } -// Prompt for a file and make sure an extension is added -// unless the user explicitly specifies another one. - -static QString getSaveFileNameWithExtension(QWidget *parent, const QString &title, QString dir, const QString &filter, const QString &extension) +static QString fileDialogFilters(const QString &extension) { - const QChar dot = QLatin1Char('.'); - - QString saveFile; - while (true) { - saveFile = QFileDialog::getSaveFileName(parent, title, dir, filter, nullptr, QFileDialog::DontConfirmOverwrite); - if (saveFile.isEmpty()) - return saveFile; - - const QFileInfo fInfo(saveFile); - if (fInfo.suffix().isEmpty() && !fInfo.fileName().endsWith(dot)) { - saveFile += dot; - saveFile += extension; - } - - const QFileInfo fi(saveFile); - if (!fi.exists()) - break; - - const QString prompt = QDesignerActions::tr("%1 already exists.\nDo you want to replace it?").arg(fi.fileName()); - if (QMessageBox::warning(parent, title, prompt, QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) - break; + return QDesignerActions::tr("Designer UI files (*.%1);;All Files (*)").arg(extension); +} - dir = saveFile; - } - return saveFile; +QFileDialog *createSaveAsDialog(QWidget *parent, const QString &dir, const QString &extension) +{ + auto result = new QFileDialog(parent, QDesignerActions::tr("Save Form As"), + dir, fileDialogFilters(extension)); + result->setAcceptMode(QFileDialog::AcceptSave); + result->setDefaultSuffix(extension); + return result; } QDesignerActions::QDesignerActions(QDesignerWorkbench *workbench) @@ -604,7 +588,7 @@ bool QDesignerActions::openForm(QWidget *parent) closePreview(); const QString extension = uiExtension(); const QStringList fileNames = QFileDialog::getOpenFileNames(parent, tr("Open Form"), - m_openDirectory, tr("Designer UI files (*.%1);;All Files (*)").arg(extension), nullptr); + m_openDirectory, fileDialogFilters(extension), nullptr); if (fileNames.isEmpty()) return false; @@ -641,10 +625,13 @@ bool QDesignerActions::saveFormAs(QDesignerFormWindowInterface *fw) dir += extension; } - const QString saveFile = getSaveFileNameWithExtension(fw, tr("Save Form As"), dir, tr("Designer UI files (*.%1);;All Files (*)").arg(extension), extension); - if (saveFile.isEmpty()) + QScopedPointer<QFileDialog> saveAsDialog(createSaveAsDialog(fw, dir, extension)); + if (saveAsDialog->exec() != QDialog::Accepted) return false; + const QString saveFile = saveAsDialog->selectedFiles().constFirst(); + saveAsDialog.reset(); // writeOutForm potentially shows other dialogs + fw->setFileName(saveFile); return writeOutForm(fw, saveFile); } @@ -786,7 +773,7 @@ bool QDesignerActions::readInForm(const QString &fileName) const QString extension = uiExtension(); fn = QFileDialog::getOpenFileName(core()->topLevel(), tr("Open Form"), m_openDirectory, - tr("Designer UI files (*.%1);;All Files (*)").arg(extension), nullptr); + fileDialogFilters(extension), nullptr); if (fn.isEmpty()) return false; @@ -812,37 +799,10 @@ bool QDesignerActions::readInForm(const QString &fileName) return true; } -static QString createBackup(const QString &fileName) -{ - const QString suffix = QStringLiteral(".bak"); - QString backupFile = fileName + suffix; - QFileInfo fi(backupFile); - int i = 0; - while (fi.exists()) { - backupFile = fileName + suffix + QString::number(++i); - fi.setFile(backupFile); - } - - if (QFile::copy(fileName, backupFile)) - return backupFile; - return QString(); -} - -static void removeBackup(const QString &backupFile) -{ - if (!backupFile.isEmpty()) - QFile::remove(backupFile); -} - bool QDesignerActions::writeOutForm(QDesignerFormWindowInterface *fw, const QString &saveFile, bool check) { Q_ASSERT(fw && !saveFile.isEmpty()); - QString backupFile; - QFileInfo fi(saveFile); - if (fi.exists()) - backupFile = createBackup(saveFile); - if (check) { const QStringList problems = fw->checkContents(); if (!problems.isEmpty()) @@ -854,10 +814,9 @@ bool QDesignerActions::writeOutForm(QDesignerFormWindowInterface *fw, const QStr if (fwb->lineTerminatorMode() == qdesigner_internal::FormWindowBase::CRLFLineTerminator) contents.replace(QLatin1Char('\n'), QStringLiteral("\r\n")); } - const QByteArray utf8Array = contents.toUtf8(); m_workbench->updateBackup(fw); - QFile f(saveFile); + QSaveFile f(saveFile); while (!f.open(QFile::WriteOnly)) { QMessageBox box(QMessageBox::Warning, tr("Save Form?"), @@ -875,52 +834,33 @@ bool QDesignerActions::writeOutForm(QDesignerFormWindowInterface *fw, const QStr QPushButton *cancelButton = box.addButton(QMessageBox::Cancel); box.exec(); - if (box.clickedButton() == cancelButton) { - removeBackup(backupFile); + if (box.clickedButton() == cancelButton) return false; - } if (box.clickedButton() == switchButton) { - QString extension = uiExtension(); - const QString fileName = QFileDialog::getSaveFileName(fw, tr("Save Form As"), - QDir::current().absolutePath(), - QStringLiteral("*.") + extension); - if (fileName.isEmpty()) { - removeBackup(backupFile); + QScopedPointer<QFileDialog> saveAsDialog(createSaveAsDialog(fw, QDir::currentPath(), uiExtension())); + if (saveAsDialog->exec() != QDialog::Accepted) return false; - } - if (f.fileName() != fileName) { - removeBackup(backupFile); - fi.setFile(fileName); - backupFile.clear(); - if (fi.exists()) - backupFile = createBackup(fileName); - } + + const QString fileName = saveAsDialog->selectedFiles().constFirst(); f.setFileName(fileName); fw->setFileName(fileName); } // loop back around... } - while (f.write(utf8Array, utf8Array.size()) != utf8Array.size()) { - QMessageBox box(QMessageBox::Warning, tr("Save Form?"), + f.write(contents.toUtf8()); + if (!f.commit()) { + QMessageBox box(QMessageBox::Warning, tr("Save Form"), tr("Could not write file"), - QMessageBox::Retry|QMessageBox::Cancel, fw); + QMessageBox::Cancel, fw); box.setWindowModality(Qt::WindowModal); - box.setInformativeText(tr("It was not possible to write the entire file %1 to disk." - "\nReason:%2\nWould you like to retry?") + box.setInformativeText(tr("It was not possible to write the file %1 to disk." + "\nReason: %2") .arg(f.fileName(), f.errorString())); - box.setDefaultButton(QMessageBox::Retry); - switch (box.exec()) { - case QMessageBox::Retry: - f.resize(0); - break; - default: - return false; - } + box.exec(); + return false; } - f.close(); - removeBackup(backupFile); addRecentFile(saveFile); - m_saveDirectory = QFileInfo(f).absolutePath(); + m_saveDirectory = QFileInfo(f.fileName()).absolutePath(); fw->setDirty(false); fw->parentWidget()->setWindowModified(false); @@ -967,7 +907,7 @@ void QDesignerActions::updateRecentFileActions() QStringList files = m_settings.recentFilesList(); const int originalSize = files.size(); int numRecentFiles = qMin(files.size(), int(MaxRecentFiles)); - const QList<QAction *> recentFilesActs = m_recentFilesActions->actions(); + const auto recentFilesActs = m_recentFilesActions->actions(); for (int i = 0; i < numRecentFiles; ++i) { const QFileInfo fi(files[i]); @@ -1330,10 +1270,15 @@ void QDesignerActions::savePreviewImage() suggestion += QLatin1Char('.'); suggestion += extension; } + + QFileDialog dialog(fw, tr("Save Image"), suggestion, filter); + dialog.setAcceptMode(QFileDialog::AcceptSave); + dialog.setDefaultSuffix(extension); + do { - const QString fileName = getSaveFileNameWithExtension(fw, tr("Save Image"), suggestion, filter, extension); - if (fileName.isEmpty()) + if (dialog.exec() != QDialog::Accepted) break; + const QString fileName = dialog.selectedFiles().constFirst(); if (image.isNull()) { const QPixmap pixmap = createPreviewPixmap(fw); diff --git a/src/designer/src/designer/qdesigner_formwindow.cpp b/src/designer/src/designer/qdesigner_formwindow.cpp index 77223e416..19c79e52d 100644 --- a/src/designer/src/designer/qdesigner_formwindow.cpp +++ b/src/designer/src/designer/qdesigner_formwindow.cpp @@ -173,7 +173,7 @@ int QDesignerFormWindow::getNumberOfUntitledWindows() const if (maxUntitled == 0) ++maxUntitled; if (match.lastCapturedIndex() >= 2) { - const QStringRef numberCapture = match.capturedRef(2); + const auto numberCapture = match.capturedRef(2); if (!numberCapture.isEmpty()) maxUntitled = qMax(numberCapture.toInt(), maxUntitled); } diff --git a/src/designer/src/designer/qdesigner_settings.cpp b/src/designer/src/designer/qdesigner_settings.cpp index 8ac61c52a..e8ac4be54 100644 --- a/src/designer/src/designer/qdesigner_settings.cpp +++ b/src/designer/src/designer/qdesigner_settings.cpp @@ -40,7 +40,6 @@ #include <QtCore/qvariant.h> #include <QtCore/qdir.h> -#include <QtWidgets/qdesktopwidget.h> #include <QtWidgets/qstyle.h> #include <QtWidgets/qlistview.h> diff --git a/src/designer/src/designer/qdesigner_workbench.cpp b/src/designer/src/designer/qdesigner_workbench.cpp index f2a8b5d1c..d18d2a179 100644 --- a/src/designer/src/designer/qdesigner_workbench.cpp +++ b/src/designer/src/designer/qdesigner_workbench.cpp @@ -58,7 +58,6 @@ #include <QtWidgets/qactiongroup.h> #include <QtGui/qevent.h> #include <QtGui/qscreen.h> -#include <QtWidgets/qdesktopwidget.h> #include <QtWidgets/qdockwidget.h> #include <QtWidgets/qmenu.h> #include <QtWidgets/qmenubar.h> @@ -236,7 +235,7 @@ QDesignerWorkbench::QDesignerWorkbench() : { // Add application specific options pages QDesignerAppearanceOptionsPage *appearanceOptions = new QDesignerAppearanceOptionsPage(m_core); connect(appearanceOptions, &QDesignerAppearanceOptionsPage::settingsChanged, this, &QDesignerWorkbench::notifyUISettingsChanged); - QList<QDesignerOptionsPageInterface*> optionsPages = m_core->optionsPages(); + auto optionsPages = m_core->optionsPages(); optionsPages.push_front(appearanceOptions); m_core->setOptionsPages(optionsPages); } @@ -330,7 +329,7 @@ Qt::WindowFlags QDesignerWorkbench::magicalWindowFlags(const QWidget *widgetForF return Qt::Window; default: Q_ASSERT(0); - return nullptr; + return {}; } } @@ -569,9 +568,9 @@ QRect QDesignerWorkbench::desktopGeometry() const case NeutralMode: break; } - const int screenNumber = widget ? QApplication::desktop()->screenNumber(widget) : 0; - auto screen = QGuiApplication::screens().value(screenNumber, QGuiApplication::primaryScreen()); - return screen->availableGeometry(); + const auto screen = widget ? widget->screen() : QGuiApplication::primaryScreen(); + return screen ? screen->availableGeometry() + : QGuiApplication::primaryScreen()->availableGeometry(); } QRect QDesignerWorkbench::availableGeometry() const @@ -579,9 +578,8 @@ QRect QDesignerWorkbench::availableGeometry() const if (m_mode == DockedMode) return m_dockedMainWindow->mdiArea()->geometry(); - const int screenNumber = QApplication::desktop()->screenNumber(widgetBoxToolWindow()); - auto screen = QGuiApplication::screens().value(screenNumber, QGuiApplication::primaryScreen()); - return screen->availableGeometry(); + const auto screen = widgetBoxToolWindow()->screen(); + return screen ? screen->availableGeometry() : QGuiApplication::primaryScreen()->availableGeometry() ; } int QDesignerWorkbench::marginHint() const @@ -608,7 +606,7 @@ void QDesignerWorkbench::removeFormWindow(QDesignerFormWindow *formWindow) m_windowMenu->removeAction(action); } - if (m_formWindows.empty()) { + if (m_formWindows.isEmpty()) { m_actionManager->setWindowListSeparatorVisible(false); // Show up new form dialog unless closing if (loadOk && m_state == StateUp @@ -689,7 +687,7 @@ QDesignerFormWindow *QDesignerWorkbench::findFormWindow(QWidget *widget) const bool QDesignerWorkbench::handleClose() { m_state = StateClosing; - QList<QDesignerFormWindow *> dirtyForms; + QVector<QDesignerFormWindow *> dirtyForms; for (QDesignerFormWindow *w : qAsConst(m_formWindows)) { if (w->editor()->isDirty()) dirtyForms << w; @@ -1079,7 +1077,7 @@ void QDesignerWorkbench::restoreUISettings() ToolWindowFontSettings fontSettings = QDesignerSettings(m_core).toolWindowFont(); const QFont &font = fontSettings.m_useFont ? fontSettings.m_font : qApp->font(); - if (font == m_toolWindows.front()->font()) + if (font == m_toolWindows.constFirst()->font()) return; for (QDesignerToolWindow *tw : qAsConst(m_toolWindows)) |