diff options
Diffstat (limited to 'src/widgets/dialogs')
22 files changed, 338 insertions, 334 deletions
diff --git a/src/widgets/dialogs/dialogs.pri b/src/widgets/dialogs/dialogs.pri index a5b4883db8..4f4a9b1517 100644 --- a/src/widgets/dialogs/dialogs.pri +++ b/src/widgets/dialogs/dialogs.pri @@ -2,7 +2,6 @@ HEADERS += \ dialogs/qcolordialog.h \ - dialogs/qcolordialog_p.h \ dialogs/qfscompleter_p.h \ dialogs/qdialog.h \ dialogs/qdialog_p.h \ diff --git a/src/widgets/dialogs/qcolordialog.cpp b/src/widgets/dialogs/qcolordialog.cpp index 5f3161f39f..914ee8ec9c 100644 --- a/src/widgets/dialogs/qcolordialog.cpp +++ b/src/widgets/dialogs/qcolordialog.cpp @@ -31,7 +31,7 @@ ** ****************************************************************************/ -#include "qcolordialog_p.h" +#include "qcolordialog.h" #ifndef QT_NO_COLORDIALOG @@ -49,6 +49,7 @@ #include "qpixmap.h" #include "qpushbutton.h" #include "qsettings.h" +#include "qsharedpointer.h" #include "qstyle.h" #include "qstyleoption.h" #include "qvalidator.h" @@ -58,13 +59,132 @@ #include "qscreen.h" #include "qcursor.h" #include "qtimer.h" +#include "qwindow.h" + +#include "private/qdialog_p.h" #include <algorithm> QT_BEGIN_NAMESPACE +namespace { +class QColorLuminancePicker; +class QColorPicker; +class QColorShower; +class QWellArray; +class QColorPickingEventFilter; +} // unnamed namespace + +class QColorDialogPrivate : public QDialogPrivate +{ + Q_DECLARE_PUBLIC(QColorDialog) + +public: + enum SetColorMode { + ShowColor = 0x1, + SelectColor = 0x2, + SetColorAll = ShowColor | SelectColor + }; + + QColorDialogPrivate() : options(new QColorDialogOptions) +#ifdef Q_OS_WIN32 + , updateTimer(0) +#endif + {} + + QPlatformColorDialogHelper *platformColorDialogHelper() const + { return static_cast<QPlatformColorDialogHelper *>(platformHelper()); } + + void init(const QColor &initial); + void initWidgets(); + QRgb currentColor() const; + QColor currentQColor() const; + void setCurrentColor(const QColor &color, SetColorMode setColorMode = SetColorAll); + void setCurrentRgbColor(QRgb rgb); + void setCurrentQColor(const QColor &color); + bool selectColor(const QColor &color); + QColor grabScreenColor(const QPoint &p); + + int currentAlpha() const; + void setCurrentAlpha(int a); + void showAlpha(bool b); + bool isAlphaVisible() const; + void retranslateStrings(); + + void _q_addCustom(); + + void _q_newHsv(int h, int s, int v); + void _q_newColorTypedIn(QRgb rgb); + void _q_nextCustom(int, int); + void _q_newCustom(int, int); + void _q_newStandard(int, int); + void _q_pickScreenColor(); + void _q_updateColorPicking(); + void updateColorLabelText(const QPoint &); + void updateColorPicking(const QPoint &pos); + void releaseColorPicking(); + bool handleColorPickingMouseMove(QMouseEvent *e); + bool handleColorPickingMouseButtonRelease(QMouseEvent *e); + bool handleColorPickingKeyPress(QKeyEvent *e); + + bool canBeNativeDialog() const Q_DECL_OVERRIDE; + + QWellArray *custom; + QWellArray *standard; + + QDialogButtonBox *buttons; + QVBoxLayout *leftLay; + QColorPicker *cp; + QColorLuminancePicker *lp; + QColorShower *cs; + QLabel *lblBasicColors; + QLabel *lblCustomColors; + QLabel *lblScreenColorInfo; + QPushButton *ok; + QPushButton *cancel; + QPushButton *addCusBt; + QPushButton *screenColorPickerButton; + QColor selectedQColor; + int nextCust; + bool smallDisplay; + bool screenColorPicking; + QColorPickingEventFilter *colorPickingEventFilter; + QRgb beforeScreenColorPicking; + QSharedPointer<QColorDialogOptions> options; + + QPointer<QObject> receiverToDisconnectOnClose; + QByteArray memberToDisconnectOnClose; +#ifdef Q_OS_WIN32 + QTimer *updateTimer; + QWindow dummyTransparentWindow; +#endif + +#ifdef Q_DEAD_CODE_FROM_QT4_MAC + void openCocoaColorPanel(const QColor &initial, + QWidget *parent, const QString &title, QColorDialog::ColorDialogOptions options); + void closeCocoaColorPanel(); + void releaseCocoaColorPanelDelegate(); + void setCocoaPanelColor(const QColor &color); + + inline void done(int result) { q_func()->done(result); } + inline QColorDialog *colorDialog() { return q_func(); } + + void *delegate; + + static bool sharedColorPanelAvailable; + + void _q_macRunNativeAppModalPanel(); + void mac_nativeDialogModalHelp(); +#endif +private: + virtual void initHelper(QPlatformDialogHelper *h) Q_DECL_OVERRIDE; + virtual void helperPrepareShow(QPlatformDialogHelper *h) Q_DECL_OVERRIDE; +}; + //////////// QWellArray BEGIN +namespace { + struct QWellArrayData; class QWellArray : public QWidget @@ -446,6 +566,8 @@ private: QColorDialogPrivate *m_dp; }; +} // unnamed namespace + /*! Returns the number of custom colors supported by QColorDialog. All color dialogs share the same custom colors. @@ -506,6 +628,8 @@ static inline void rgb2hsv(QRgb rgb, int &h, int &s, int &v) c.getHsv(&h, &s, &v); } +namespace { + class QColorWell : public QWellArray { public: @@ -975,8 +1099,8 @@ private: QColorDialog *colorDialog; QGridLayout *gl; - friend class QColorDialog; - friend class QColorDialogPrivate; + friend class QT_PREPEND_NAMESPACE(QColorDialog); + friend class QT_PREPEND_NAMESPACE(QColorDialogPrivate); }; class QColorShowLabel : public QFrame @@ -1265,6 +1389,8 @@ QColorShower::QColorShower(QColorDialog *parent) retranslateStrings(); } +} // unnamed namespace + inline QRgb QColorDialogPrivate::currentColor() const { return cs->currentColor(); } inline int QColorDialogPrivate::currentAlpha() const { return cs->currentAlpha(); } inline void QColorDialogPrivate::setCurrentAlpha(int a) { cs->setCurrentAlpha(a); } diff --git a/src/widgets/dialogs/qcolordialog.h b/src/widgets/dialogs/qcolordialog.h index 16339f56c4..de18e6f9ed 100644 --- a/src/widgets/dialogs/qcolordialog.h +++ b/src/widgets/dialogs/qcolordialog.h @@ -61,8 +61,8 @@ public: Q_DECLARE_FLAGS(ColorDialogOptions, ColorDialogOption) - explicit QColorDialog(QWidget *parent = 0); - explicit QColorDialog(const QColor &initial, QWidget *parent = 0); + explicit QColorDialog(QWidget *parent = Q_NULLPTR); + explicit QColorDialog(const QColor &initial, QWidget *parent = Q_NULLPTR); ~QColorDialog(); void setCurrentColor(const QColor &color); @@ -81,12 +81,12 @@ public: void setVisible(bool visible) Q_DECL_OVERRIDE; static QColor getColor(const QColor &initial = Qt::white, - QWidget *parent = 0, + QWidget *parent = Q_NULLPTR, const QString &title = QString(), - ColorDialogOptions options = 0); + ColorDialogOptions options = ColorDialogOptions()); // obsolete - static QRgb getRgba(QRgb rgba = 0xffffffff, bool *ok = 0, QWidget *parent = 0); + static QRgb getRgba(QRgb rgba = 0xffffffff, bool *ok = Q_NULLPTR, QWidget *parent = Q_NULLPTR); static int customCount(); static QColor customColor(int index); @@ -113,7 +113,6 @@ private: Q_PRIVATE_SLOT(d_func(), void _q_newStandard(int, int)) Q_PRIVATE_SLOT(d_func(), void _q_pickScreenColor()) Q_PRIVATE_SLOT(d_func(), void _q_updateColorPicking()) - friend class QColorShower; }; Q_DECLARE_OPERATORS_FOR_FLAGS(QColorDialog::ColorDialogOptions) diff --git a/src/widgets/dialogs/qcolordialog_p.h b/src/widgets/dialogs/qcolordialog_p.h deleted file mode 100644 index 1a881eae70..0000000000 --- a/src/widgets/dialogs/qcolordialog_p.h +++ /dev/null @@ -1,179 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the QtWidgets module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL21$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** As a special exception, The Qt Company gives you certain additional -** rights. These rights are described in The Qt Company LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QCOLORDIALOG_P_H -#define QCOLORDIALOG_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// to version without notice, or even be removed. -// -// We mean it. -// -// - -#include "private/qdialog_p.h" -#include "qcolordialog.h" -#include "qsharedpointer.h" -#include "qwindow.h" - -#ifndef QT_NO_COLORDIALOG - -QT_BEGIN_NAMESPACE - -class QColorLuminancePicker; -class QColorPicker; -class QColorShower; -class QDialogButtonBox; -class QLabel; -class QVBoxLayout; -class QPushButton; -class QWellArray; -class QColorPickingEventFilter; -class QTimer; - -class QColorDialogPrivate : public QDialogPrivate -{ - Q_DECLARE_PUBLIC(QColorDialog) - -public: - enum SetColorMode { - ShowColor = 0x1, - SelectColor = 0x2, - SetColorAll = ShowColor | SelectColor - }; - - QColorDialogPrivate() : options(new QColorDialogOptions) -#ifdef Q_OS_WIN32 - , updateTimer(0) -#endif - {} - - QPlatformColorDialogHelper *platformColorDialogHelper() const - { return static_cast<QPlatformColorDialogHelper *>(platformHelper()); } - - void init(const QColor &initial); - void initWidgets(); - QRgb currentColor() const; - QColor currentQColor() const; - void setCurrentColor(const QColor &color, SetColorMode setColorMode = SetColorAll); - void setCurrentRgbColor(QRgb rgb); - void setCurrentQColor(const QColor &color); - bool selectColor(const QColor &color); - QColor grabScreenColor(const QPoint &p); - - int currentAlpha() const; - void setCurrentAlpha(int a); - void showAlpha(bool b); - bool isAlphaVisible() const; - void retranslateStrings(); - - void _q_addCustom(); - - void _q_newHsv(int h, int s, int v); - void _q_newColorTypedIn(QRgb rgb); - void _q_nextCustom(int, int); - void _q_newCustom(int, int); - void _q_newStandard(int, int); - void _q_pickScreenColor(); - void _q_updateColorPicking(); - void updateColorLabelText(const QPoint &); - void updateColorPicking(const QPoint &pos); - void releaseColorPicking(); - bool handleColorPickingMouseMove(QMouseEvent *e); - bool handleColorPickingMouseButtonRelease(QMouseEvent *e); - bool handleColorPickingKeyPress(QKeyEvent *e); - - bool canBeNativeDialog() const Q_DECL_OVERRIDE; - - QWellArray *custom; - QWellArray *standard; - - QDialogButtonBox *buttons; - QVBoxLayout *leftLay; - QColorPicker *cp; - QColorLuminancePicker *lp; - QColorShower *cs; - QLabel *lblBasicColors; - QLabel *lblCustomColors; - QLabel *lblScreenColorInfo; - QPushButton *ok; - QPushButton *cancel; - QPushButton *addCusBt; - QPushButton *screenColorPickerButton; - QColor selectedQColor; - int nextCust; - bool smallDisplay; - bool screenColorPicking; - QColorPickingEventFilter *colorPickingEventFilter; - QRgb beforeScreenColorPicking; - QSharedPointer<QColorDialogOptions> options; - - QPointer<QObject> receiverToDisconnectOnClose; - QByteArray memberToDisconnectOnClose; -#ifdef Q_OS_WIN32 - QTimer *updateTimer; - QWindow dummyTransparentWindow; -#endif - -#ifdef Q_DEAD_CODE_FROM_QT4_MAC - void openCocoaColorPanel(const QColor &initial, - QWidget *parent, const QString &title, QColorDialog::ColorDialogOptions options); - void closeCocoaColorPanel(); - void releaseCocoaColorPanelDelegate(); - void setCocoaPanelColor(const QColor &color); - - inline void done(int result) { q_func()->done(result); } - inline QColorDialog *colorDialog() { return q_func(); } - - void *delegate; - - static bool sharedColorPanelAvailable; - - void _q_macRunNativeAppModalPanel(); - void mac_nativeDialogModalHelp(); -#endif -private: - virtual void initHelper(QPlatformDialogHelper *h) Q_DECL_OVERRIDE; - virtual void helperPrepareShow(QPlatformDialogHelper *h) Q_DECL_OVERRIDE; -}; - -#endif // QT_NO_COLORDIALOG - -QT_END_NAMESPACE - -#endif // QCOLORDIALOG_P_H diff --git a/src/widgets/dialogs/qdialog.h b/src/widgets/dialogs/qdialog.h index cd53378f9a..5ea5375387 100644 --- a/src/widgets/dialogs/qdialog.h +++ b/src/widgets/dialogs/qdialog.h @@ -51,7 +51,7 @@ class Q_WIDGETS_EXPORT QDialog : public QWidget Q_PROPERTY(bool modal READ isModal WRITE setModal) public: - explicit QDialog(QWidget *parent = 0, Qt::WindowFlags f = 0); + explicit QDialog(QWidget *parent = Q_NULLPTR, Qt::WindowFlags f = Qt::WindowFlags()); ~QDialog(); enum DialogCode { Rejected, Accepted }; @@ -90,7 +90,7 @@ public Q_SLOTS: void showExtension(bool); protected: - QDialog(QDialogPrivate &, QWidget *parent, Qt::WindowFlags f = 0); + QDialog(QDialogPrivate &, QWidget *parent, Qt::WindowFlags f = Qt::WindowFlags()); #if defined(Q_OS_WINCE) bool event(QEvent *e); diff --git a/src/widgets/dialogs/qerrormessage.cpp b/src/widgets/dialogs/qerrormessage.cpp index 4c3a5497d4..855bae3c9f 100644 --- a/src/widgets/dialogs/qerrormessage.cpp +++ b/src/widgets/dialogs/qerrormessage.cpp @@ -47,9 +47,10 @@ #include "qpixmap.h" #include "qmetaobject.h" #include "qthread.h" -#include "qqueue.h" #include "qset.h" +#include <queue> + #include <stdio.h> #include <stdlib.h> @@ -68,16 +69,18 @@ public: QCheckBox * again; QTextEdit * errors; QLabel * icon; - QQueue<QPair<QString, QString> > pending; + std::queue<QPair<QString, QString> > pending; QSet<QString> doNotShow; QSet<QString> doNotShowType; QString currentMessage; QString currentType; + bool isMessageToBeShown(const QString &message, const QString &type) const; bool nextPending(); void retranslateStrings(); }; +namespace { class QErrorMessageTextView : public QTextEdit { public: @@ -87,6 +90,7 @@ public: virtual QSize minimumSizeHint() const Q_DECL_OVERRIDE; virtual QSize sizeHint() const Q_DECL_OVERRIDE; }; +} // unnamed namespace QSize QErrorMessageTextView::minimumSizeHint() const { @@ -217,29 +221,32 @@ QErrorMessage::QErrorMessage(QWidget * parent) : QDialog(*new QErrorMessagePrivate, parent) { Q_D(QErrorMessage); - QGridLayout * grid = new QGridLayout(this); + d->icon = new QLabel(this); -#ifndef QT_NO_MESSAGEBOX - d->icon->setPixmap(QMessageBox::standardIcon(QMessageBox::Information)); - d->icon->setAlignment(Qt::AlignHCenter | Qt::AlignTop); -#endif - grid->addWidget(d->icon, 0, 0, Qt::AlignTop); d->errors = new QErrorMessageTextView(this); - grid->addWidget(d->errors, 0, 1); d->again = new QCheckBox(this); - d->again->setChecked(true); - grid->addWidget(d->again, 1, 1, Qt::AlignTop); d->ok = new QPushButton(this); + QGridLayout * grid = new QGridLayout(this); + + connect(d->ok, SIGNAL(clicked()), this, SLOT(accept())); + grid->addWidget(d->icon, 0, 0, Qt::AlignTop); + grid->addWidget(d->errors, 0, 1); + grid->addWidget(d->again, 1, 1, Qt::AlignTop); + grid->addWidget(d->ok, 2, 0, 1, 2, Qt::AlignCenter); + grid->setColumnStretch(1, 42); + grid->setRowStretch(0, 42); +#ifndef QT_NO_MESSAGEBOX + d->icon->setPixmap(QMessageBox::standardIcon(QMessageBox::Information)); + d->icon->setAlignment(Qt::AlignHCenter | Qt::AlignTop); +#endif + d->again->setChecked(true); #if defined(Q_OS_WINCE) d->ok->setFixedSize(0,0); #endif - connect(d->ok, SIGNAL(clicked()), this, SLOT(accept())); d->ok->setFocus(); - grid->addWidget(d->ok, 2, 0, 1, 2, Qt::AlignCenter); - grid->setColumnStretch(1, 42); - grid->setRowStretch(0, 42); + d->retranslateStrings(); } @@ -265,11 +272,13 @@ QErrorMessage::~QErrorMessage() void QErrorMessage::done(int a) { Q_D(QErrorMessage); - if (!d->again->isChecked() && !d->currentMessage.isEmpty() && d->currentType.isEmpty()) { - d->doNotShow.insert(d->currentMessage); - } - if (!d->again->isChecked() && !d->currentType.isEmpty()) { - d->doNotShowType.insert(d->currentType); + if (!d->again->isChecked()) { + if (d->currentType.isEmpty()) { + if (!d->currentMessage.isEmpty()) + d->doNotShow.insert(d->currentMessage); + } else { + d->doNotShowType.insert(d->currentType); + } } d->currentMessage.clear(); d->currentType.clear(); @@ -301,20 +310,27 @@ QErrorMessage * QErrorMessage::qtHandler() /*! \internal */ +bool QErrorMessagePrivate::isMessageToBeShown(const QString &message, const QString &type) const +{ + return !message.isEmpty() + && (type.isEmpty() ? !doNotShow.contains(message) : !doNotShowType.contains(type)); +} + bool QErrorMessagePrivate::nextPending() { - while (!pending.isEmpty()) { - QPair<QString,QString> pendingMessage = pending.dequeue(); - QString message = pendingMessage.first; - QString type = pendingMessage.second; - if (!message.isEmpty() && ((type.isEmpty() && !doNotShow.contains(message)) || (!type.isEmpty() && !doNotShowType.contains(type)))) { + while (!pending.empty()) { + QPair<QString,QString> &pendingMessage = pending.front(); + QString message = qMove(pendingMessage.first); + QString type = qMove(pendingMessage.second); + pending.pop(); + if (isMessageToBeShown(message, type)) { #ifndef QT_NO_TEXTHTMLPARSER errors->setHtml(message); #else errors->setPlainText(message); #endif - currentMessage = message; - currentType = type; + currentMessage = qMove(message); + currentType = qMove(type); return true; } } @@ -333,12 +349,7 @@ bool QErrorMessagePrivate::nextPending() void QErrorMessage::showMessage(const QString &message) { - Q_D(QErrorMessage); - if (d->doNotShow.contains(message)) - return; - d->pending.enqueue(qMakePair(message,QString())); - if (!isVisible() && d->nextPending()) - show(); + showMessage(message, QString()); } /*! @@ -358,9 +369,9 @@ void QErrorMessage::showMessage(const QString &message) void QErrorMessage::showMessage(const QString &message, const QString &type) { Q_D(QErrorMessage); - if (d->doNotShow.contains(message) && d->doNotShowType.contains(type)) + if (!d->isMessageToBeShown(message, type)) return; - d->pending.push_back(qMakePair(message,type)); + d->pending.push(qMakePair(message, type)); if (!isVisible() && d->nextPending()) show(); } diff --git a/src/widgets/dialogs/qerrormessage.h b/src/widgets/dialogs/qerrormessage.h index 55d0b389b1..1d69515dfb 100644 --- a/src/widgets/dialogs/qerrormessage.h +++ b/src/widgets/dialogs/qerrormessage.h @@ -48,7 +48,7 @@ class Q_WIDGETS_EXPORT QErrorMessage: public QDialog Q_OBJECT Q_DECLARE_PRIVATE(QErrorMessage) public: - explicit QErrorMessage(QWidget* parent = 0); + explicit QErrorMessage(QWidget* parent = Q_NULLPTR); ~QErrorMessage(); static QErrorMessage * qtHandler(); diff --git a/src/widgets/dialogs/qfiledialog.cpp b/src/widgets/dialogs/qfiledialog.cpp index 64e3f5069e..81beccd5c8 100644 --- a/src/widgets/dialogs/qfiledialog.cpp +++ b/src/widgets/dialogs/qfiledialog.cpp @@ -330,14 +330,8 @@ Q_GLOBAL_STATIC(QUrl, lastVisitedDir) */ QT_BEGIN_INCLUDE_NAMESPACE -#ifdef Q_DEAD_CODE_FROM_QT4_WIN -#include <qwindowsstyle_p.h> -#endif #include <QMetaEnum> #include <qshortcut.h> -#ifdef Q_DEAD_CODE_FROM_QT4_MAC -#include <qmacstyle_mac_p.h> -#endif QT_END_INCLUDE_NAMESPACE /*! @@ -1191,12 +1185,17 @@ QList<QUrl> QFileDialogPrivate::userSelectedFiles() const if (!usingWidgets()) return addDefaultSuffixToUrls(selectedFiles_sys()); - foreach (const QModelIndex &index, qFileDialogUi->listView->selectionModel()->selectedRows()) + const QModelIndexList selectedRows = qFileDialogUi->listView->selectionModel()->selectedRows(); + files.reserve(selectedRows.size()); + foreach (const QModelIndex &index, selectedRows) files.append(QUrl::fromLocalFile(index.data(QFileSystemModel::FilePathRole).toString())); - if (files.isEmpty() && !lineEdit()->text().isEmpty()) - foreach (const QString &path, typedFiles()) + if (files.isEmpty() && !lineEdit()->text().isEmpty()) { + const QStringList typedFilesList = typedFiles(); + files.reserve(typedFilesList.size()); + foreach (const QString &path, typedFilesList) files.append(QUrl::fromLocalFile(path)); + } return files; } @@ -1230,7 +1229,9 @@ QStringList QFileDialogPrivate::addDefaultSuffixToFiles(const QStringList &files QList<QUrl> QFileDialogPrivate::addDefaultSuffixToUrls(const QList<QUrl> &urlsToFix) const { QList<QUrl> urls; - for (int i=0; i<urlsToFix.size(); ++i) { + const int numUrlsToFix = urlsToFix.size(); + urls.reserve(numUrlsToFix); + for (int i = 0; i < numUrlsToFix; ++i) { QUrl url = urlsToFix.at(i); // if the filename has no suffix, add the default suffix const QString defaultSuffix = options->defaultSuffix(); @@ -1254,7 +1255,9 @@ QStringList QFileDialog::selectedFiles() const Q_D(const QFileDialog); QStringList files; - foreach (const QUrl &file, d->userSelectedFiles()) + const QList<QUrl> userSelectedFiles = d->userSelectedFiles(); + files.reserve(userSelectedFiles.size()); + foreach (const QUrl &file, userSelectedFiles) files.append(file.toLocalFile()); if (files.isEmpty() && d->usingWidgets()) { const FileMode fm = fileMode(); @@ -1279,7 +1282,9 @@ QList<QUrl> QFileDialog::selectedUrls() const return d->userSelectedFiles(); } else { QList<QUrl> urls; - foreach (const QString &file, selectedFiles()) + const QStringList selectedFileList = selectedFiles(); + urls.reserve(selectedFileList.size()); + foreach (const QString &file, selectedFileList) urls.append(QUrl::fromLocalFile(file)); return urls; } @@ -1358,7 +1363,9 @@ QStringList qt_strip_filters(const QStringList &filters) { QStringList strippedFilters; QRegExp r(QString::fromLatin1(QPlatformFileDialogHelper::filterRegExp)); - for (int i = 0; i < filters.count(); ++i) { + const int numFilters = filters.count(); + strippedFilters.reserve(numFilters); + for (int i = 0; i < numFilters; ++i) { QString filterName; int index = r.indexIn(filters[i]); if (index >= 0) @@ -1393,7 +1400,9 @@ void QFileDialog::setNameFilters(const QStringList &filters) Q_D(QFileDialog); d->defaultFileTypes = (filters == QStringList(QFileDialog::tr("All Files (*)"))); QStringList cleanedFilters; - for (int i = 0; i < filters.count(); ++i) { + const int numFilters = filters.count(); + cleanedFilters.reserve(numFilters); + for (int i = 0; i < numFilters; ++i) { cleanedFilters << filters[i].simplified(); } d->options->setNameFilters(cleanedFilters); @@ -1693,6 +1702,30 @@ void QFileDialog::setAcceptMode(QFileDialog::AcceptMode mode) d->retranslateWindowTitle(); } +/*! + \property QFileDialog::supportedSchemes + \brief the URL schemes that the file dialog should allow navigating to. + \since 5.6 + + Setting this property allows to restrict the type of URLs the + user will be able to select. It is a way for the application to declare + the protocols it will support to fetch the file content. An empty list + means that no restriction is applied (the default). + Supported for local files ("file" scheme) is implicit and always enabled; + it is not necessary to include it in the restriction. +*/ + +void QFileDialog::setSupportedSchemes(const QStringList &schemes) +{ + Q_D(QFileDialog); + d->options->setSupportedSchemes(schemes); +} + +QStringList QFileDialog::supportedSchemes() const +{ + return d_func()->options->supportedSchemes(); +} + /* Returns the file system model index that is the root index in the views @@ -2089,8 +2122,8 @@ QString QFileDialog::getOpenFileName(QWidget *parent, user will be able to select. It is a way for the application to declare the protocols it will support to fetch the file content. An empty list means that no restriction is applied (the default). - Supported for local files ("file" scheme) is implicit and always enabled. - it is not necessary to include in the restriction. + Supported for local files ("file" scheme) is implicit and always enabled; + it is not necessary to include it in the restriction. When possible, this static function will use the native file dialog and not a QFileDialog. On platforms which don't support selecting remote @@ -2107,8 +2140,6 @@ QUrl QFileDialog::getOpenFileUrl(QWidget *parent, Options options, const QStringList &supportedSchemes) { - Q_UNUSED(supportedSchemes); // TODO - QFileDialogArgs args; args.parent = parent; args.caption = caption; @@ -2119,6 +2150,7 @@ QUrl QFileDialog::getOpenFileUrl(QWidget *parent, args.options = options; QFileDialog dialog(args); + dialog.setSupportedSchemes(supportedSchemes); if (selectedFilter && !selectedFilter->isEmpty()) dialog.selectNameFilter(*selectedFilter); if (dialog.exec() == QDialog::Accepted) { @@ -2167,11 +2199,6 @@ QUrl QFileDialog::getOpenFileUrl(QWidget *parent, see the QFileDialog::Option enum for more information on the flags you can pass. - \note If you want to iterate over the list of files, you should iterate - over a copy. For example: - - \snippet code/src_gui_dialogs_qfiledialog.cpp 10 - \warning Do not delete \a parent during the execution of the dialog. If you want to do this, you should create the dialog yourself using one of the QFileDialog constructors. @@ -2188,6 +2215,7 @@ QStringList QFileDialog::getOpenFileNames(QWidget *parent, const QStringList schemes = QStringList(QStringLiteral("file")); const QList<QUrl> selectedUrls = getOpenFileUrls(parent, caption, QUrl::fromLocalFile(dir), filter, selectedFilter, options, schemes); QStringList fileNames; + fileNames.reserve(selectedUrls.size()); foreach (const QUrl &url, selectedUrls) fileNames << url.toLocalFile(); return fileNames; @@ -2211,8 +2239,8 @@ QStringList QFileDialog::getOpenFileNames(QWidget *parent, user will be able to select. It is a way for the application to declare the protocols it will support to fetch the file content. An empty list means that no restriction is applied (the default). - Supported for local files ("file" scheme) is implicit and always enabled. - it is not necessary to include in the restriction. + Supported for local files ("file" scheme) is implicit and always enabled; + it is not necessary to include it in the restriction. When possible, this static function will use the native file dialog and not a QFileDialog. On platforms which don't support selecting remote @@ -2229,8 +2257,6 @@ QList<QUrl> QFileDialog::getOpenFileUrls(QWidget *parent, Options options, const QStringList &supportedSchemes) { - Q_UNUSED(supportedSchemes); - QFileDialogArgs args; args.parent = parent; args.caption = caption; @@ -2241,6 +2267,7 @@ QList<QUrl> QFileDialog::getOpenFileUrls(QWidget *parent, args.options = options; QFileDialog dialog(args); + dialog.setSupportedSchemes(supportedSchemes); if (selectedFilter && !selectedFilter->isEmpty()) dialog.selectNameFilter(*selectedFilter); if (dialog.exec() == QDialog::Accepted) { @@ -2330,8 +2357,8 @@ QString QFileDialog::getSaveFileName(QWidget *parent, user will be able to select. It is a way for the application to declare the protocols it will support to save the file content. An empty list means that no restriction is applied (the default). - Supported for local files ("file" scheme) is implicit and always enabled. - it is not necessary to include in the restriction. + Supported for local files ("file" scheme) is implicit and always enabled; + it is not necessary to include it in the restriction. When possible, this static function will use the native file dialog and not a QFileDialog. On platforms which don't support selecting remote @@ -2348,8 +2375,6 @@ QUrl QFileDialog::getSaveFileUrl(QWidget *parent, Options options, const QStringList &supportedSchemes) { - Q_UNUSED(supportedSchemes); - QFileDialogArgs args; args.parent = parent; args.caption = caption; @@ -2360,6 +2385,7 @@ QUrl QFileDialog::getSaveFileUrl(QWidget *parent, args.options = options; QFileDialog dialog(args); + dialog.setSupportedSchemes(supportedSchemes); dialog.setAcceptMode(AcceptSave); if (selectedFilter && !selectedFilter->isEmpty()) dialog.selectNameFilter(*selectedFilter); @@ -2440,8 +2466,8 @@ QString QFileDialog::getExistingDirectory(QWidget *parent, user will be able to select. It is a way for the application to declare the protocols it will support to fetch the file content. An empty list means that no restriction is applied (the default). - Supported for local files ("file" scheme) is implicit and always enabled. - it is not necessary to include in the restriction. + Supported for local files ("file" scheme) is implicit and always enabled; + it is not necessary to include it in the restriction. When possible, this static function will use the native file dialog and not a QFileDialog. On platforms which don't support selecting remote @@ -2456,8 +2482,6 @@ QUrl QFileDialog::getExistingDirectoryUrl(QWidget *parent, Options options, const QStringList &supportedSchemes) { - Q_UNUSED(supportedSchemes); - QFileDialogArgs args; args.parent = parent; args.caption = caption; @@ -2466,6 +2490,7 @@ QUrl QFileDialog::getExistingDirectoryUrl(QWidget *parent, args.options = options; QFileDialog dialog(args); + dialog.setSupportedSchemes(supportedSchemes); if (dialog.exec() == QDialog::Accepted) return dialog.selectedUrls().value(0); return QUrl(); @@ -2667,7 +2692,9 @@ void QFileDialogPrivate::saveSettings() settings.setValue(QLatin1String("treeViewHeader"), qFileDialogUi->treeView->header()->saveState()); } QStringList historyUrls; - foreach (const QString &path, q->history()) + const QStringList history = q->history(); + historyUrls.reserve(history.size()); + foreach (const QString &path, history) historyUrls << QUrl::fromLocalFile(path).toString(); settings.setValue(QLatin1String("history"), historyUrls); settings.setValue(QLatin1String("lastVisited"), lastVisitedDir()->toString()); @@ -2959,7 +2986,7 @@ void QFileDialogPrivate::createWidgets() q->setHistory(options->history()); if (options->initiallySelectedFiles().count() == 1) q->selectFile(options->initiallySelectedFiles().first().fileName()); - foreach (QUrl url, options->initiallySelectedFiles()) + foreach (const QUrl &url, options->initiallySelectedFiles()) q->selectUrl(url); lineEdit()->selectAll(); _q_updateOkButton(); @@ -3779,7 +3806,7 @@ QString QFileDialogPrivate::getEnvironmentVariable(const QString &string) { #ifdef Q_OS_UNIX if (string.size() > 1 && string.startsWith(QLatin1Char('$'))) { - return QString::fromLocal8Bit(getenv(string.mid(1).toLatin1().constData())); + return QString::fromLocal8Bit(qgetenv(string.mid(1).toLatin1().constData())); } #else if (string.size() > 2 && string.startsWith(QLatin1Char('%')) && string.endsWith(QLatin1Char('%'))) { diff --git a/src/widgets/dialogs/qfiledialog.h b/src/widgets/dialogs/qfiledialog.h index 95209bceb5..ffe49a2dd2 100644 --- a/src/widgets/dialogs/qfiledialog.h +++ b/src/widgets/dialogs/qfiledialog.h @@ -66,6 +66,7 @@ class Q_WIDGETS_EXPORT QFileDialog : public QDialog Q_PROPERTY(bool nameFilterDetailsVisible READ isNameFilterDetailsVisible WRITE setNameFilterDetailsVisible DESIGNABLE false) Q_PROPERTY(Options options READ options WRITE setOptions) + Q_PROPERTY(QStringList supportedSchemes READ supportedSchemes WRITE setSupportedSchemes) public: enum ViewMode { Detail, List }; @@ -91,7 +92,7 @@ public: Q_DECLARE_FLAGS(Options, Option) QFileDialog(QWidget *parent, Qt::WindowFlags f); - explicit QFileDialog(QWidget *parent = 0, + explicit QFileDialog(QWidget *parent = Q_NULLPTR, const QString &caption = QString(), const QString &directory = QString(), const QString &filter = QString()); @@ -167,6 +168,9 @@ public: void setLabelText(DialogLabel label, const QString &text); QString labelText(DialogLabel label) const; + void setSupportedSchemes(const QStringList &schemes); + QStringList supportedSchemes() const; + #ifndef QT_NO_PROXYMODEL void setProxyModel(QAbstractProxyModel *model); QAbstractProxyModel *proxyModel() const; @@ -196,60 +200,60 @@ Q_SIGNALS: public: - static QString getOpenFileName(QWidget *parent = 0, + static QString getOpenFileName(QWidget *parent = Q_NULLPTR, const QString &caption = QString(), const QString &dir = QString(), const QString &filter = QString(), - QString *selectedFilter = 0, - Options options = 0); + QString *selectedFilter = Q_NULLPTR, + Options options = Options()); - static QUrl getOpenFileUrl(QWidget *parent = 0, + static QUrl getOpenFileUrl(QWidget *parent = Q_NULLPTR, const QString &caption = QString(), const QUrl &dir = QUrl(), const QString &filter = QString(), - QString *selectedFilter = 0, - Options options = 0, + QString *selectedFilter = Q_NULLPTR, + Options options = Options(), const QStringList &supportedSchemes = QStringList()); - static QString getSaveFileName(QWidget *parent = 0, + static QString getSaveFileName(QWidget *parent = Q_NULLPTR, const QString &caption = QString(), const QString &dir = QString(), const QString &filter = QString(), - QString *selectedFilter = 0, - Options options = 0); + QString *selectedFilter = Q_NULLPTR, + Options options = Options()); - static QUrl getSaveFileUrl(QWidget *parent = 0, + static QUrl getSaveFileUrl(QWidget *parent = Q_NULLPTR, const QString &caption = QString(), const QUrl &dir = QUrl(), const QString &filter = QString(), - QString *selectedFilter = 0, - Options options = 0, + QString *selectedFilter = Q_NULLPTR, + Options options = Options(), const QStringList &supportedSchemes = QStringList()); - static QString getExistingDirectory(QWidget *parent = 0, + static QString getExistingDirectory(QWidget *parent = Q_NULLPTR, const QString &caption = QString(), const QString &dir = QString(), Options options = ShowDirsOnly); - static QUrl getExistingDirectoryUrl(QWidget *parent = 0, + static QUrl getExistingDirectoryUrl(QWidget *parent = Q_NULLPTR, const QString &caption = QString(), const QUrl &dir = QUrl(), Options options = ShowDirsOnly, const QStringList &supportedSchemes = QStringList()); - static QStringList getOpenFileNames(QWidget *parent = 0, + static QStringList getOpenFileNames(QWidget *parent = Q_NULLPTR, const QString &caption = QString(), const QString &dir = QString(), const QString &filter = QString(), - QString *selectedFilter = 0, - Options options = 0); + QString *selectedFilter = Q_NULLPTR, + Options options = Options()); - static QList<QUrl> getOpenFileUrls(QWidget *parent = 0, + static QList<QUrl> getOpenFileUrls(QWidget *parent = Q_NULLPTR, const QString &caption = QString(), const QUrl &dir = QUrl(), const QString &filter = QString(), - QString *selectedFilter = 0, - Options options = 0, + QString *selectedFilter = Q_NULLPTR, + Options options = Options(), const QStringList &supportedSchemes = QStringList()); diff --git a/src/widgets/dialogs/qfilesystemmodel.cpp b/src/widgets/dialogs/qfilesystemmodel.cpp index 4859231d95..fd49246e9f 100644 --- a/src/widgets/dialogs/qfilesystemmodel.cpp +++ b/src/widgets/dialogs/qfilesystemmodel.cpp @@ -259,10 +259,7 @@ QModelIndex QFileSystemModel::index(const QString &path, int column) const { Q_D(const QFileSystemModel); QFileSystemModelPrivate::QFileSystemNode *node = d->node(path, false); - QModelIndex idx = d->index(node); - if (idx.column() != column) - idx = idx.sibling(idx.row(), column); - return idx; + return d->index(node, column); } /*! @@ -562,7 +559,7 @@ QModelIndex QFileSystemModel::parent(const QModelIndex &index) const return the index for node */ -QModelIndex QFileSystemModelPrivate::index(const QFileSystemModelPrivate::QFileSystemNode *node) const +QModelIndex QFileSystemModelPrivate::index(const QFileSystemModelPrivate::QFileSystemNode *node, int column) const { Q_Q(const QFileSystemModel); QFileSystemModelPrivate::QFileSystemNode *parentNode = (node ? node->parent : 0); @@ -575,7 +572,7 @@ QModelIndex QFileSystemModelPrivate::index(const QFileSystemModelPrivate::QFileS return QModelIndex(); int visualRow = translateVisibleLocation(parentNode, parentNode->visibleLocation(node->fileName)); - return q->createIndex(visualRow, 0, const_cast<QFileSystemNode*>(node)); + return q->createIndex(visualRow, column, const_cast<QFileSystemNode*>(node)); } /*! @@ -643,7 +640,7 @@ int QFileSystemModel::rowCount(const QModelIndex &parent) const */ int QFileSystemModel::columnCount(const QModelIndex &parent) const { - return (parent.column() > 0) ? 0 : 4; + return (parent.column() > 0) ? 0 : QFileSystemModelPrivate::NumColumns; } /*! @@ -1183,8 +1180,11 @@ void QFileSystemModel::sort(int column, Qt::SortOrder order) emit layoutAboutToBeChanged(); QModelIndexList oldList = persistentIndexList(); QList<QPair<QFileSystemModelPrivate::QFileSystemNode*, int> > oldNodes; - for (int i = 0; i < oldList.count(); ++i) { - QPair<QFileSystemModelPrivate::QFileSystemNode*, int> pair(d->node(oldList.at(i)), oldList.at(i).column()); + const int nodeCount = oldList.count(); + oldNodes.reserve(nodeCount); + for (int i = 0; i < nodeCount; ++i) { + const QModelIndex &oldNode = oldList.at(i); + QPair<QFileSystemModelPrivate::QFileSystemNode*, int> pair(d->node(oldNode), oldNode.column()); oldNodes.append(pair); } @@ -1197,10 +1197,11 @@ void QFileSystemModel::sort(int column, Qt::SortOrder order) d->sortOrder = order; QModelIndexList newList; - for (int i = 0; i < oldNodes.count(); ++i) { - QModelIndex idx = d->index(oldNodes.at(i).first); - idx = idx.sibling(idx.row(), oldNodes.at(i).second); - newList.append(idx); + const int numOldNodes = oldNodes.size(); + newList.reserve(numOldNodes); + for (int i = 0; i < numOldNodes; ++i) { + const QPair<QFileSystemModelPrivate::QFileSystemNode*, int> &oldNode = oldNodes.at(i); + newList.append(d->index(oldNode.first, oldNode.second)); } changePersistentIndexList(oldList, newList); emit layoutChanged(); @@ -1648,7 +1649,9 @@ QStringList QFileSystemModel::nameFilters() const Q_D(const QFileSystemModel); QStringList filters; #ifndef QT_NO_REGEXP - for (int i = 0; i < d->nameFilters.size(); ++i) { + const int numNameFilters = d->nameFilters.size(); + filters.reserve(numNameFilters); + for (int i = 0; i < numNameFilters; ++i) { filters << d->nameFilters.at(i).pattern(); } #endif diff --git a/src/widgets/dialogs/qfilesystemmodel.h b/src/widgets/dialogs/qfilesystemmodel.h index 7c98a102f3..f749c97bcb 100644 --- a/src/widgets/dialogs/qfilesystemmodel.h +++ b/src/widgets/dialogs/qfilesystemmodel.h @@ -69,7 +69,7 @@ public: FilePermissions = Qt::UserRole + 3 }; - explicit QFileSystemModel(QObject *parent = 0); + explicit QFileSystemModel(QObject *parent = Q_NULLPTR); ~QFileSystemModel(); QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; @@ -136,7 +136,7 @@ public: bool remove(const QModelIndex &index); protected: - QFileSystemModel(QFileSystemModelPrivate &, QObject *parent = 0); + QFileSystemModel(QFileSystemModelPrivate &, QObject *parent = Q_NULLPTR); void timerEvent(QTimerEvent *event) Q_DECL_OVERRIDE; bool event(QEvent *event) Q_DECL_OVERRIDE; diff --git a/src/widgets/dialogs/qfilesystemmodel_p.h b/src/widgets/dialogs/qfilesystemmodel_p.h index dd4b25d59c..57fb457071 100644 --- a/src/widgets/dialogs/qfilesystemmodel_p.h +++ b/src/widgets/dialogs/qfilesystemmodel_p.h @@ -70,6 +70,8 @@ class Q_AUTOTEST_EXPORT QFileSystemModelPrivate : public QAbstractItemModelPriva Q_DECLARE_PUBLIC(QFileSystemModel) public: + enum { NumColumns = 4 }; + class QFileSystemNode { public: @@ -220,8 +222,8 @@ public: } QFileSystemNode *node(const QModelIndex &index) const; QFileSystemNode *node(const QString &path, bool fetch = true) const; - inline QModelIndex index(const QString &path) { return index(node(path)); } - QModelIndex index(const QFileSystemNode *node) const; + inline QModelIndex index(const QString &path, int column = 0) { return index(node(path), column); } + QModelIndex index(const QFileSystemNode *node, int column = 0) const; bool filtersAcceptsNode(const QFileSystemNode *node) const; bool passNameFilters(const QFileSystemNode *node) const; void removeNode(QFileSystemNode *parentNode, const QString &name); @@ -318,6 +320,7 @@ public: QList<Fetching> toFetch; }; +Q_DECLARE_TYPEINFO(QFileSystemModelPrivate::Fetching, Q_MOVABLE_TYPE); #endif // QT_NO_FILESYSTEMMODEL QT_END_NAMESPACE diff --git a/src/widgets/dialogs/qfontdialog.cpp b/src/widgets/dialogs/qfontdialog.cpp index d47dd3562f..688e8f5c13 100644 --- a/src/widgets/dialogs/qfontdialog.cpp +++ b/src/widgets/dialogs/qfontdialog.cpp @@ -619,6 +619,7 @@ void QFontDialogPrivate::updateSizes() int i = 0; int current = -1; QStringList str_sizes; + str_sizes.reserve(sizes.size()); for(QList<int>::const_iterator it = sizes.constBegin(); it != sizes.constEnd(); ++it) { str_sizes.append(QString::number(*it)); if (current == -1 && *it == size) diff --git a/src/widgets/dialogs/qfontdialog.h b/src/widgets/dialogs/qfontdialog.h index 8ca9bf14dd..c3c3050174 100644 --- a/src/widgets/dialogs/qfontdialog.h +++ b/src/widgets/dialogs/qfontdialog.h @@ -65,8 +65,8 @@ public: Q_DECLARE_FLAGS(FontDialogOptions, FontDialogOption) - explicit QFontDialog(QWidget *parent = 0); - explicit QFontDialog(const QFont &initial, QWidget *parent = 0); + explicit QFontDialog(QWidget *parent = Q_NULLPTR); + explicit QFontDialog(const QFont &initial, QWidget *parent = Q_NULLPTR); ~QFontDialog(); void setCurrentFont(const QFont &font); @@ -84,9 +84,9 @@ public: void setVisible(bool visible) Q_DECL_OVERRIDE; - static QFont getFont(bool *ok, QWidget *parent = 0); - static QFont getFont(bool *ok, const QFont &initial, QWidget *parent = 0, const QString &title = QString(), - FontDialogOptions options = 0); + static QFont getFont(bool *ok, QWidget *parent = Q_NULLPTR); + static QFont getFont(bool *ok, const QFont &initial, QWidget *parent = Q_NULLPTR, const QString &title = QString(), + FontDialogOptions options = FontDialogOptions()); Q_SIGNALS: void currentFontChanged(const QFont &font); diff --git a/src/widgets/dialogs/qinputdialog.cpp b/src/widgets/dialogs/qinputdialog.cpp index 9c78f5e9ac..fb52fa4651 100644 --- a/src/widgets/dialogs/qinputdialog.cpp +++ b/src/widgets/dialogs/qinputdialog.cpp @@ -791,6 +791,7 @@ QStringList QInputDialog::comboBoxItems() const QStringList result; if (d->comboBox) { const int count = d->comboBox->count(); + result.reserve(count); for (int i = 0; i < count; ++i) result.append(d->comboBox->itemText(i)); } diff --git a/src/widgets/dialogs/qinputdialog.h b/src/widgets/dialogs/qinputdialog.h index 84130d5f90..600f6c9753 100644 --- a/src/widgets/dialogs/qinputdialog.h +++ b/src/widgets/dialogs/qinputdialog.h @@ -83,7 +83,7 @@ public: DoubleInput }; - QInputDialog(QWidget *parent = 0, Qt::WindowFlags flags = 0); + QInputDialog(QWidget *parent = Q_NULLPTR, Qt::WindowFlags flags = Qt::WindowFlags()); ~QInputDialog(); void setInputMode(InputMode mode); @@ -153,27 +153,29 @@ public: static QString getText(QWidget *parent, const QString &title, const QString &label, QLineEdit::EchoMode echo = QLineEdit::Normal, - const QString &text = QString(), bool *ok = 0, Qt::WindowFlags flags = 0, + const QString &text = QString(), bool *ok = Q_NULLPTR, + Qt::WindowFlags flags = Qt::WindowFlags(), Qt::InputMethodHints inputMethodHints = Qt::ImhNone); static QString getMultiLineText(QWidget *parent, const QString &title, const QString &label, - const QString &text = QString(), bool *ok = 0, Qt::WindowFlags flags = 0, - Qt::InputMethodHints inputMethodHints = Qt::ImhNone); + const QString &text = QString(), bool *ok = Q_NULLPTR, + Qt::WindowFlags flags = Qt::WindowFlags(), + Qt::InputMethodHints inputMethodHints = Qt::ImhNone); static QString getItem(QWidget *parent, const QString &title, const QString &label, const QStringList &items, int current = 0, bool editable = true, - bool *ok = 0, Qt::WindowFlags flags = 0, + bool *ok = Q_NULLPTR, Qt::WindowFlags flags = Qt::WindowFlags(), Qt::InputMethodHints inputMethodHints = Qt::ImhNone); static int getInt(QWidget *parent, const QString &title, const QString &label, int value = 0, int minValue = -2147483647, int maxValue = 2147483647, - int step = 1, bool *ok = 0, Qt::WindowFlags flags = 0); + int step = 1, bool *ok = Q_NULLPTR, Qt::WindowFlags flags = Qt::WindowFlags()); static double getDouble(QWidget *parent, const QString &title, const QString &label, double value = 0, double minValue = -2147483647, double maxValue = 2147483647, - int decimals = 1, bool *ok = 0, Qt::WindowFlags flags = 0); + int decimals = 1, bool *ok = Q_NULLPTR, Qt::WindowFlags flags = Qt::WindowFlags()); #if QT_DEPRECATED_SINCE(5, 0) QT_DEPRECATED static inline int getInteger(QWidget *parent, const QString &title, const QString &label, int value = 0, int minValue = -2147483647, int maxValue = 2147483647, - int step = 1, bool *ok = 0, Qt::WindowFlags flags = 0) + int step = 1, bool *ok = Q_NULLPTR, Qt::WindowFlags flags = Qt::WindowFlags()) { return getInt(parent, title, label, value, minValue, maxValue, step, ok, flags); } diff --git a/src/widgets/dialogs/qmessagebox.h b/src/widgets/dialogs/qmessagebox.h index 464bf734dc..b108354466 100644 --- a/src/widgets/dialogs/qmessagebox.h +++ b/src/widgets/dialogs/qmessagebox.h @@ -125,9 +125,9 @@ public: Q_DECLARE_FLAGS(StandardButtons, StandardButton) - explicit QMessageBox(QWidget *parent = 0); + explicit QMessageBox(QWidget *parent = Q_NULLPTR); QMessageBox(Icon icon, const QString &title, const QString &text, - StandardButtons buttons = NoButton, QWidget *parent = 0, + StandardButtons buttons = NoButton, QWidget *parent = Q_NULLPTR, Qt::WindowFlags flags = Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint); ~QMessageBox(); @@ -198,7 +198,7 @@ public: QMessageBox(const QString &title, const QString &text, Icon icon, int button0, int button1, int button2, - QWidget *parent = 0, + QWidget *parent = Q_NULLPTR, Qt::WindowFlags f = Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint); static int information(QWidget *parent, const QString &title, diff --git a/src/widgets/dialogs/qprogressdialog.cpp b/src/widgets/dialogs/qprogressdialog.cpp index 4e8e245813..97e9267a9d 100644 --- a/src/widgets/dialogs/qprogressdialog.cpp +++ b/src/widgets/dialogs/qprogressdialog.cpp @@ -697,9 +697,6 @@ void QProgressDialog::setValue(int progress) d->shown_once = true; } } -#ifdef Q_DEAD_CODE_FROM_QT4_MAC - QApplication::flush(); -#endif } if (progress == d->bar->maximum() && d->autoReset) diff --git a/src/widgets/dialogs/qprogressdialog.h b/src/widgets/dialogs/qprogressdialog.h index 51c45f5d30..28de623385 100644 --- a/src/widgets/dialogs/qprogressdialog.h +++ b/src/widgets/dialogs/qprogressdialog.h @@ -61,9 +61,10 @@ class Q_WIDGETS_EXPORT QProgressDialog : public QDialog Q_PROPERTY(QString labelText READ labelText WRITE setLabelText) public: - explicit QProgressDialog(QWidget *parent = 0, Qt::WindowFlags flags = 0); + explicit QProgressDialog(QWidget *parent = Q_NULLPTR, Qt::WindowFlags flags = Qt::WindowFlags()); QProgressDialog(const QString &labelText, const QString &cancelButtonText, - int minimum, int maximum, QWidget *parent = 0, Qt::WindowFlags flags = 0); + int minimum, int maximum, QWidget *parent = Q_NULLPTR, + Qt::WindowFlags flags = Qt::WindowFlags()); ~QProgressDialog(); void setLabel(QLabel *label); diff --git a/src/widgets/dialogs/qsidebar.cpp b/src/widgets/dialogs/qsidebar.cpp index 6fbcce801d..be3c060ba1 100644 --- a/src/widgets/dialogs/qsidebar.cpp +++ b/src/widgets/dialogs/qsidebar.cpp @@ -274,7 +274,9 @@ void QUrlModel::addUrls(const QList<QUrl> &list, int row, bool move) QList<QUrl> QUrlModel::urls() const { QList<QUrl> list; - for (int i = 0; i < rowCount(); ++i) + const int numRows = rowCount(); + list.reserve(numRows); + for (int i = 0; i < numRows; ++i) list.append(data(index(i, 0), UrlRole).toUrl()); return list; } @@ -334,10 +336,12 @@ void QUrlModel::dataChanged(const QModelIndex &topLeft, const QModelIndex &botto void QUrlModel::layoutChanged() { QStringList paths; - for (int i = 0; i < watching.count(); ++i) + const int numPaths = watching.count(); + paths.reserve(numPaths); + for (int i = 0; i < numPaths; ++i) paths.append(watching.at(i).second); watching.clear(); - for (int i = 0; i < paths.count(); ++i) { + for (int i = 0; i < numPaths; ++i) { QString path = paths.at(i); QModelIndex newIndex = fileSystemModel->index(path); watching.append(QPair<QModelIndex, QString>(newIndex, path)); @@ -453,12 +457,14 @@ void QSidebar::removeEntry() { QList<QModelIndex> idxs = selectionModel()->selectedIndexes(); QList<QPersistentModelIndex> indexes; - for (int i = 0; i < idxs.count(); i++) + const int numIndexes = idxs.count(); + for (int i = 0; i < numIndexes; i++) indexes.append(idxs.at(i)); - for (int i = 0; i < indexes.count(); ++i) + for (int i = 0; i < numIndexes; ++i) { if (!indexes.at(i).data(QUrlModel::UrlRole).toUrl().path().isEmpty()) model()->removeRow(indexes.at(i).row()); + } } /*! diff --git a/src/widgets/dialogs/qwizard.cpp b/src/widgets/dialogs/qwizard.cpp index 139fbc3843..6a1c0eb592 100644 --- a/src/widgets/dialogs/qwizard.cpp +++ b/src/widgets/dialogs/qwizard.cpp @@ -170,6 +170,7 @@ public: const char *changedSignal) : className(className), property(property), changedSignal(changedSignal) {} }; +Q_DECLARE_TYPEINFO(QWizardDefaultProperty, Q_MOVABLE_TYPE); class QWizardField { @@ -189,6 +190,7 @@ public: QByteArray changedSignal; QVariant initialValue; }; +Q_DECLARE_TYPEINFO(QWizardField, Q_MOVABLE_TYPE); QWizardField::QWizardField(QWizardPage *page, const QString &spec, QObject *object, const char *property, const char *changedSignal) @@ -751,6 +753,7 @@ void QWizardPrivate::init() updateButtonLayout(); + defaultPropertyTable.reserve(NFallbackDefaultProperties); for (uint i = 0; i < NFallbackDefaultProperties; ++i) defaultPropertyTable.append(QWizardDefaultProperty(fallbackProperties[i].className, fallbackProperties[i].property, diff --git a/src/widgets/dialogs/qwizard.h b/src/widgets/dialogs/qwizard.h index 517edde377..9193f0b659 100644 --- a/src/widgets/dialogs/qwizard.h +++ b/src/widgets/dialogs/qwizard.h @@ -114,7 +114,7 @@ public: Q_DECLARE_FLAGS(WizardOptions, WizardOption) - explicit QWizard(QWidget *parent = 0, Qt::WindowFlags flags = 0); + explicit QWizard(QWidget *parent = Q_NULLPTR, Qt::WindowFlags flags = Qt::WindowFlags()); ~QWizard(); int addPage(QWizardPage *page); @@ -209,7 +209,7 @@ class Q_WIDGETS_EXPORT QWizardPage : public QWidget Q_PROPERTY(QString subTitle READ subTitle WRITE setSubTitle) public: - explicit QWizardPage(QWidget *parent = 0); + explicit QWizardPage(QWidget *parent = Q_NULLPTR); ~QWizardPage(); void setTitle(const QString &title); @@ -237,8 +237,8 @@ Q_SIGNALS: protected: void setField(const QString &name, const QVariant &value); QVariant field(const QString &name) const; - void registerField(const QString &name, QWidget *widget, const char *property = 0, - const char *changedSignal = 0); + void registerField(const QString &name, QWidget *widget, const char *property = Q_NULLPTR, + const char *changedSignal = Q_NULLPTR); QWizard *wizard() const; private: |