diff options
Diffstat (limited to 'src/widgets')
88 files changed, 1671 insertions, 527 deletions
diff --git a/src/widgets/accessible/itemviews.cpp b/src/widgets/accessible/itemviews.cpp index 4f6cb56060..ca2fd62994 100644 --- a/src/widgets/accessible/itemviews.cpp +++ b/src/widgets/accessible/itemviews.cpp @@ -198,7 +198,9 @@ QList<QAccessibleInterface *> QAccessibleTable::selectedCells() const QList<QAccessibleInterface*> cells; if (!view()->selectionModel()) return cells; - Q_FOREACH (const QModelIndex &index, view()->selectionModel()->selectedIndexes()) + const QModelIndexList selectedIndexes = view()->selectionModel()->selectedIndexes(); + cells.reserve(selectedIndexes.size()); + Q_FOREACH (const QModelIndex &index, selectedIndexes) cells.append(child(logicalIndex(index))); return cells; } @@ -208,9 +210,11 @@ QList<int> QAccessibleTable::selectedColumns() const if (!view()->selectionModel()) return QList<int>(); QList<int> columns; - Q_FOREACH (const QModelIndex &index, view()->selectionModel()->selectedColumns()) { + const QModelIndexList selectedColumns = view()->selectionModel()->selectedColumns(); + columns.reserve(selectedColumns.size()); + Q_FOREACH (const QModelIndex &index, selectedColumns) columns.append(index.column()); - } + return columns; } @@ -219,9 +223,11 @@ QList<int> QAccessibleTable::selectedRows() const if (!view()->selectionModel()) return QList<int>(); QList<int> rows; - Q_FOREACH (const QModelIndex &index, view()->selectionModel()->selectedRows()) { + const QModelIndexList selectedRows = view()->selectionModel()->selectedRows(); + rows.reserve(selectedRows.size()); + Q_FOREACH (const QModelIndex &index, selectedRows) rows.append(index.row()); - } + return rows; } @@ -1010,6 +1016,9 @@ QAccessible::Role QAccessibleTableCell::role() const QAccessible::State QAccessibleTableCell::state() const { QAccessible::State st; + if (!view) + return st; + QRect globalRect = view->rect(); globalRect.translate(view->mapToGlobal(QPoint(0,0))); if (!globalRect.intersects(rect())) diff --git a/src/widgets/accessible/qaccessiblewidgets.cpp b/src/widgets/accessible/qaccessiblewidgets.cpp index a2bf14b25b..c598a5b4cb 100644 --- a/src/widgets/accessible/qaccessiblewidgets.cpp +++ b/src/widgets/accessible/qaccessiblewidgets.cpp @@ -826,6 +826,9 @@ QString QAccessibleTextWidget::attributes(int offset, int *startOffset, int *end attrs["text-underline-type"] = QStringLiteral("single"); // if underlineStyleValue is set, there is an underline, and Qt does not support other than single ones } // else both are "none" which is the default - no need to set them + if (block.textDirection() == Qt::RightToLeft) + attrs["writing-mode"] = QStringLiteral("rl"); + QTextCharFormat::VerticalAlignment alignment = charFormat.verticalAlignment(); attrs["text-position"] = QString::fromLatin1((alignment == QTextCharFormat::AlignSubScript) ? "sub" : ((alignment == QTextCharFormat::AlignSuperScript) ? "super" : "baseline" )); 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..43c7716ef6 100644 --- a/src/widgets/dialogs/qcolordialog.h +++ b/src/widgets/dialogs/qcolordialog.h @@ -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/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/qfiledialog.cpp b/src/widgets/dialogs/qfiledialog.cpp index d2666026bb..d83f6609b8 100644 --- a/src/widgets/dialogs/qfiledialog.cpp +++ b/src/widgets/dialogs/qfiledialog.cpp @@ -1189,12 +1189,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; } @@ -1228,7 +1233,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(); @@ -1252,7 +1259,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(); @@ -1277,7 +1286,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; } @@ -1356,7 +1367,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) @@ -1391,7 +1404,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); @@ -2186,6 +2201,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; @@ -2662,7 +2678,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()); @@ -3774,7 +3792,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/qfilesystemmodel.cpp b/src/widgets/dialogs/qfilesystemmodel.cpp index 4859231d95..3d767971a4 100644 --- a/src/widgets/dialogs/qfilesystemmodel.cpp +++ b/src/widgets/dialogs/qfilesystemmodel.cpp @@ -1183,8 +1183,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,9 +1200,10 @@ 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); + for (int i = 0; i < nodeCount; ++i) { + const QPair<QFileSystemModelPrivate::QFileSystemNode*, int> &oldNode = oldNodes.at(i); + QModelIndex idx = d->index(oldNode.first); + idx = idx.sibling(idx.row(), oldNode.second); newList.append(idx); } changePersistentIndexList(oldList, newList); @@ -1648,7 +1652,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/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/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/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..680d29443d 100644 --- a/src/widgets/dialogs/qwizard.cpp +++ b/src/widgets/dialogs/qwizard.cpp @@ -751,6 +751,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/doc/images/listview.png b/src/widgets/doc/images/listview.png Binary files differindex fa49c52c62..fa49c52c62 100755..100644 --- a/src/widgets/doc/images/listview.png +++ b/src/widgets/doc/images/listview.png diff --git a/src/widgets/doc/images/modelview-combobox.png b/src/widgets/doc/images/modelview-combobox.png Binary files differindex d172b413eb..d172b413eb 100755..100644 --- a/src/widgets/doc/images/modelview-combobox.png +++ b/src/widgets/doc/images/modelview-combobox.png diff --git a/src/widgets/doc/images/tableview.png b/src/widgets/doc/images/tableview.png Binary files differindex 8be1b6ce62..8be1b6ce62 100755..100644 --- a/src/widgets/doc/images/tableview.png +++ b/src/widgets/doc/images/tableview.png diff --git a/src/widgets/doc/snippets/macmainwindow.mm b/src/widgets/doc/snippets/macmainwindow.mm index d0d74631ab..d0d74631ab 100755..100644 --- a/src/widgets/doc/snippets/macmainwindow.mm +++ b/src/widgets/doc/snippets/macmainwindow.mm diff --git a/src/widgets/effects/qgraphicseffect.cpp b/src/widgets/effects/qgraphicseffect.cpp index f53804e494..5a97be3d96 100644 --- a/src/widgets/effects/qgraphicseffect.cpp +++ b/src/widgets/effects/qgraphicseffect.cpp @@ -111,6 +111,10 @@ #ifndef QT_NO_GRAPHICSEFFECT QT_BEGIN_NAMESPACE +QGraphicsEffectPrivate::~QGraphicsEffectPrivate() +{ +} + /*! \internal \class QGraphicsEffectSource diff --git a/src/widgets/effects/qgraphicseffect_p.h b/src/widgets/effects/qgraphicseffect_p.h index 6e990cc52e..35264c0d30 100644 --- a/src/widgets/effects/qgraphicseffect_p.h +++ b/src/widgets/effects/qgraphicseffect_p.h @@ -142,6 +142,7 @@ class Q_WIDGETS_EXPORT QGraphicsEffectPrivate : public QObjectPrivate Q_DECLARE_PUBLIC(QGraphicsEffect) public: QGraphicsEffectPrivate() : source(0), isEnabled(1) {} + ~QGraphicsEffectPrivate(); inline void setGraphicsEffectSource(QGraphicsEffectSource *newSource) { diff --git a/src/widgets/graphicsview/qgraphicsanchorlayout_p.cpp b/src/widgets/graphicsview/qgraphicsanchorlayout_p.cpp index 8327777217..dac8e61645 100644 --- a/src/widgets/graphicsview/qgraphicsanchorlayout_p.cpp +++ b/src/widgets/graphicsview/qgraphicsanchorlayout_p.cpp @@ -751,9 +751,12 @@ static AnchorData *createSequence(Graph<AnchorVertex, AnchorData> *graph, AnchorVertex *prev = before; QVector<AnchorData *> edges; + edges.reserve(vertices.count() + 1); + const int numVertices = vertices.count(); + edges.reserve(numVertices + 1); // Take from the graph, the edges that will be simplificated - for (int i = 0; i < vertices.count(); ++i) { + for (int i = 0; i < numVertices; ++i) { AnchorVertex *next = vertices.at(i); AnchorData *ad = graph->takeEdge(prev, next); Q_ASSERT(ad); @@ -2569,6 +2572,7 @@ QGraphicsAnchorLayoutPrivate::getGraphParts(Orientation orientation) if (!remainingConstraints.isEmpty()) { QList<QSimplexConstraint *> nonTrunkConstraints; + nonTrunkConstraints.reserve(remainingConstraints.size()); QLinkedList<QSimplexConstraint *>::iterator it = remainingConstraints.begin(); while (it != remainingConstraints.end()) { nonTrunkConstraints += *it; diff --git a/src/widgets/graphicsview/qgraphicsitem.cpp b/src/widgets/graphicsview/qgraphicsitem.cpp index cd30410097..1fdbe0fc18 100644 --- a/src/widgets/graphicsview/qgraphicsitem.cpp +++ b/src/widgets/graphicsview/qgraphicsitem.cpp @@ -10829,9 +10829,7 @@ void QGraphicsSimpleTextItem::paint(QPainter *painter, const QStyleOptionGraphic range.start = 0; range.length = layout.text().length(); range.format.setTextOutline(d->pen); - QList<QTextLayout::FormatRange> formats; - formats.append(range); - layout.setAdditionalFormats(formats); + layout.setFormats(QVector<QTextLayout::FormatRange>(1, range)); } setupTextLayout(&layout); diff --git a/src/widgets/graphicsview/qgraphicsitemanimation.cpp b/src/widgets/graphicsview/qgraphicsitemanimation.cpp index 0a6fccf559..585539de94 100644 --- a/src/widgets/graphicsview/qgraphicsitemanimation.cpp +++ b/src/widgets/graphicsview/qgraphicsitemanimation.cpp @@ -116,7 +116,6 @@ public: qreal step; struct Pair { - Pair(qreal a, qreal b) : step(a), value(b) {} bool operator <(const Pair &other) const { return step < other.step; } bool operator==(const Pair &other) const @@ -124,21 +123,22 @@ public: qreal step; qreal value; }; - QList<Pair> xPosition; - QList<Pair> yPosition; - QList<Pair> rotation; - QList<Pair> verticalScale; - QList<Pair> horizontalScale; - QList<Pair> verticalShear; - QList<Pair> horizontalShear; - QList<Pair> xTranslation; - QList<Pair> yTranslation; - - qreal linearValueForStep(qreal step, QList<Pair> *source, qreal defaultValue = 0); - void insertUniquePair(qreal step, qreal value, QList<Pair> *binList, const char* method); + QVector<Pair> xPosition; + QVector<Pair> yPosition; + QVector<Pair> rotation; + QVector<Pair> verticalScale; + QVector<Pair> horizontalScale; + QVector<Pair> verticalShear; + QVector<Pair> horizontalShear; + QVector<Pair> xTranslation; + QVector<Pair> yTranslation; + + qreal linearValueForStep(qreal step, QVector<Pair> *source, qreal defaultValue = 0); + void insertUniquePair(qreal step, qreal value, QVector<Pair> *binList, const char* method); }; +Q_DECLARE_TYPEINFO(QGraphicsItemAnimationPrivate::Pair, Q_PRIMITIVE_TYPE); -qreal QGraphicsItemAnimationPrivate::linearValueForStep(qreal step, QList<Pair> *source, qreal defaultValue) +qreal QGraphicsItemAnimationPrivate::linearValueForStep(qreal step, QVector<Pair> *source, qreal defaultValue) { if (source->isEmpty()) return defaultValue; @@ -168,20 +168,18 @@ qreal QGraphicsItemAnimationPrivate::linearValueForStep(qreal step, QList<Pair> return valueBefore + (valueAfter - valueBefore) * ((step - stepBefore) / (stepAfter - stepBefore)); } -void QGraphicsItemAnimationPrivate::insertUniquePair(qreal step, qreal value, QList<Pair> *binList, const char* method) +void QGraphicsItemAnimationPrivate::insertUniquePair(qreal step, qreal value, QVector<Pair> *binList, const char* method) { if (!check_step_valid(step, method)) return; - Pair pair(step, value); + const Pair pair = { step, value }; - QList<Pair>::iterator result = std::lower_bound(binList->begin(), binList->end(), pair); - if ((result != binList->end()) && !(pair < *result)) + const QVector<Pair>::iterator result = std::lower_bound(binList->begin(), binList->end(), pair); + if (result == binList->end() || pair < *result) + binList->insert(result, pair); + else result->value = value; - else { - *binList << pair; - std::sort(binList->begin(), binList->end()); - } } /*! @@ -284,7 +282,9 @@ void QGraphicsItemAnimation::setPosAt(qreal step, const QPointF &pos) QList<QPair<qreal, QPointF> > QGraphicsItemAnimation::posList() const { QList<QPair<qreal, QPointF> > list; - for (int i = 0; i < d->xPosition.size(); ++i) + const int xPosCount = d->xPosition.size(); + list.reserve(xPosCount); + for (int i = 0; i < xPosCount; ++i) list << QPair<qreal, QPointF>(d->xPosition.at(i).step, QPointF(d->xPosition.at(i).value, d->yPosition.at(i).value)); return list; @@ -338,7 +338,9 @@ void QGraphicsItemAnimation::setRotationAt(qreal step, qreal angle) QList<QPair<qreal, qreal> > QGraphicsItemAnimation::rotationList() const { QList<QPair<qreal, qreal> > list; - for (int i = 0; i < d->rotation.size(); ++i) + const int numRotations = d->rotation.size(); + list.reserve(numRotations); + for (int i = 0; i < numRotations; ++i) list << QPair<qreal, qreal>(d->rotation.at(i).step, d->rotation.at(i).value); return list; @@ -386,7 +388,9 @@ void QGraphicsItemAnimation::setTranslationAt(qreal step, qreal dx, qreal dy) QList<QPair<qreal, QPointF> > QGraphicsItemAnimation::translationList() const { QList<QPair<qreal, QPointF> > list; - for (int i = 0; i < d->xTranslation.size(); ++i) + const int numTranslations = d->xTranslation.size(); + list.reserve(numTranslations); + for (int i = 0; i < numTranslations; ++i) list << QPair<qreal, QPointF>(d->xTranslation.at(i).step, QPointF(d->xTranslation.at(i).value, d->yTranslation.at(i).value)); return list; @@ -435,7 +439,9 @@ void QGraphicsItemAnimation::setScaleAt(qreal step, qreal sx, qreal sy) QList<QPair<qreal, QPointF> > QGraphicsItemAnimation::scaleList() const { QList<QPair<qreal, QPointF> > list; - for (int i = 0; i < d->horizontalScale.size(); ++i) + const int numScales = d->horizontalScale.size(); + list.reserve(numScales); + for (int i = 0; i < numScales; ++i) list << QPair<qreal, QPointF>(d->horizontalScale.at(i).step, QPointF(d->horizontalScale.at(i).value, d->verticalScale.at(i).value)); return list; @@ -483,7 +489,9 @@ void QGraphicsItemAnimation::setShearAt(qreal step, qreal sh, qreal sv) QList<QPair<qreal, QPointF> > QGraphicsItemAnimation::shearList() const { QList<QPair<qreal, QPointF> > list; - for (int i = 0; i < d->horizontalShear.size(); ++i) + const int numShears = d->horizontalShear.size(); + list.reserve(numShears); + for (int i = 0; i < numShears; ++i) list << QPair<qreal, QPointF>(d->horizontalShear.at(i).step, QPointF(d->horizontalShear.at(i).value, d->verticalShear.at(i).value)); return list; diff --git a/src/widgets/graphicsview/qgraphicsproxywidget.cpp b/src/widgets/graphicsview/qgraphicsproxywidget.cpp index db4d18299b..08ea1ea0e3 100644 --- a/src/widgets/graphicsview/qgraphicsproxywidget.cpp +++ b/src/widgets/graphicsview/qgraphicsproxywidget.cpp @@ -269,8 +269,7 @@ void QGraphicsProxyWidgetPrivate::sendWidgetMouseEvent(QGraphicsSceneMouseEvent // Send mouse event. QMouseEvent mouseEvent(type, pos, receiver->mapTo(receiver->topLevelWidget(), pos.toPoint()), receiver->mapToGlobal(pos.toPoint()), - event->button(), event->buttons(), event->modifiers()); - QGuiApplicationPrivate::setMouseEventSource(&mouseEvent, event->source()); + event->button(), event->buttons(), event->modifiers(), event->source()); QWidget *embeddedMouseGrabberPtr = (QWidget *)embeddedMouseGrabber; QApplicationPrivate::sendMouseEvent(receiver, &mouseEvent, alienWidget, widget, diff --git a/src/widgets/graphicsview/qgraphicssceneevent.h b/src/widgets/graphicsview/qgraphicssceneevent.h index 1e3554fa36..ffa708ea23 100644 --- a/src/widgets/graphicsview/qgraphicssceneevent.h +++ b/src/widgets/graphicsview/qgraphicssceneevent.h @@ -40,7 +40,9 @@ #include <QtCore/qrect.h> #include <QtGui/qpolygon.h> #include <QtCore/qset.h> +#if QT_DEPRECATED_SINCE(5, 5) #include <QtCore/qhash.h> +#endif QT_BEGIN_NAMESPACE diff --git a/src/widgets/graphicsview/qgraphicssceneindex.cpp b/src/widgets/graphicsview/qgraphicssceneindex.cpp index 8662f73d64..a76f6b6565 100644 --- a/src/widgets/graphicsview/qgraphicssceneindex.cpp +++ b/src/widgets/graphicsview/qgraphicssceneindex.cpp @@ -520,7 +520,9 @@ QList<QGraphicsItem *> QGraphicsSceneIndex::estimateTopLevelItems(const QRectF & scened->ensureSortedTopLevelItems(); if (order == Qt::DescendingOrder) { QList<QGraphicsItem *> sorted; - for (int i = scened->topLevelItems.size() - 1; i >= 0; --i) + const int numTopLevelItems = scened->topLevelItems.size(); + sorted.reserve(numTopLevelItems); + for (int i = numTopLevelItems - 1; i >= 0; --i) sorted << scened->topLevelItems.at(i); return sorted; } diff --git a/src/widgets/graphicsview/qgraphicstransform.cpp b/src/widgets/graphicsview/qgraphicstransform.cpp index 67564b5a8b..fe963fbf3c 100644 --- a/src/widgets/graphicsview/qgraphicstransform.cpp +++ b/src/widgets/graphicsview/qgraphicstransform.cpp @@ -89,6 +89,11 @@ #ifndef QT_NO_GRAPHICSVIEW QT_BEGIN_NAMESPACE + +QGraphicsTransformPrivate::~QGraphicsTransformPrivate() +{ +} + void QGraphicsTransformPrivate::setItem(QGraphicsItem *i) { if (item == i) diff --git a/src/widgets/graphicsview/qgraphicstransform_p.h b/src/widgets/graphicsview/qgraphicstransform_p.h index dde085935f..c81a95fd3d 100644 --- a/src/widgets/graphicsview/qgraphicstransform_p.h +++ b/src/widgets/graphicsview/qgraphicstransform_p.h @@ -51,12 +51,14 @@ QT_BEGIN_NAMESPACE class QGraphicsItem; -class QGraphicsTransformPrivate : public QObjectPrivate { +// ### Qt 6: unexport again, if QtQuick1's QDeclarativeTranslatePrivate is gone by then +class Q_WIDGETS_EXPORT QGraphicsTransformPrivate : public QObjectPrivate { public: Q_DECLARE_PUBLIC(QGraphicsTransform) QGraphicsTransformPrivate() : QObjectPrivate(), item(0) {} + ~QGraphicsTransformPrivate(); QGraphicsItem *item; diff --git a/src/widgets/graphicsview/qgraphicsview.cpp b/src/widgets/graphicsview/qgraphicsview.cpp index c270c4be88..ac8cd45f9e 100644 --- a/src/widgets/graphicsview/qgraphicsview.cpp +++ b/src/widgets/graphicsview/qgraphicsview.cpp @@ -362,6 +362,10 @@ QGraphicsViewPrivate::QGraphicsViewPrivate() styleOptions.reserve(QGRAPHICSVIEW_PREALLOC_STYLE_OPTIONS); } +QGraphicsViewPrivate::~QGraphicsViewPrivate() +{ +} + /*! \internal */ @@ -2460,6 +2464,7 @@ QPolygonF QGraphicsView::mapToScene(const QRect &rect) const QPolygonF QGraphicsView::mapToScene(const QPolygon &polygon) const { QPolygonF poly; + poly.reserve(polygon.count()); foreach (const QPoint &point, polygon) poly << mapToScene(point); return poly; @@ -2555,6 +2560,7 @@ QPolygon QGraphicsView::mapFromScene(const QRectF &rect) const QPolygon QGraphicsView::mapFromScene(const QPolygonF &polygon) const { QPolygon poly; + poly.reserve(polygon.count()); foreach (const QPointF &point, polygon) poly << mapFromScene(point); return poly; @@ -2669,7 +2675,9 @@ void QGraphicsView::updateScene(const QList<QRectF> &rects) // Extract and reset dirty scene rect info. QVector<QRect> dirtyViewportRects; const QVector<QRect> &dirtyRects = d->dirtyRegion.rects(); - for (int i = 0; i < dirtyRects.size(); ++i) + const int dirtyRectsCount = dirtyRects.size(); + dirtyViewportRects.reserve(dirtyRectsCount + rects.count()); + for (int i = 0; i < dirtyRectsCount; ++i) dirtyViewportRects += dirtyRects.at(i); d->dirtyRegion = QRegion(); d->dirtyBoundingRect = QRect(); diff --git a/src/widgets/graphicsview/qgraphicsview_p.h b/src/widgets/graphicsview/qgraphicsview_p.h index fec8336695..dcbffb1c39 100644 --- a/src/widgets/graphicsview/qgraphicsview_p.h +++ b/src/widgets/graphicsview/qgraphicsview_p.h @@ -63,6 +63,7 @@ class Q_WIDGETS_EXPORT QGraphicsViewPrivate : public QAbstractScrollAreaPrivate Q_DECLARE_PUBLIC(QGraphicsView) public: QGraphicsViewPrivate(); + ~QGraphicsViewPrivate(); void recalculateContentSize(); void centerView(QGraphicsView::ViewportAnchor anchor); diff --git a/src/widgets/itemviews/qabstractitemview.cpp b/src/widgets/itemviews/qabstractitemview.cpp index 2caf5d1eb3..276e185457 100644 --- a/src/widgets/itemviews/qabstractitemview.cpp +++ b/src/widgets/itemviews/qabstractitemview.cpp @@ -1882,8 +1882,7 @@ void QAbstractItemView::mouseDoubleClickEvent(QMouseEvent *event) || (d->pressedIndex != index)) { QMouseEvent me(QEvent::MouseButtonPress, event->localPos(), event->windowPos(), event->screenPos(), - event->button(), event->buttons(), event->modifiers()); - QGuiApplicationPrivate::setMouseEventSource(&me, event->source()); + event->button(), event->buttons(), event->modifiers(), event->source()); mousePressEvent(&me); return; } @@ -3017,9 +3016,8 @@ int QAbstractItemView::sizeHintForRow(int row) const QStyleOptionViewItem option = d->viewOptionsV1(); int height = 0; int colCount = d->model->columnCount(d->root); - QModelIndex index; for (int c = 0; c < colCount; ++c) { - index = d->model->index(row, c, d->root); + const QModelIndex index = d->model->index(row, c, d->root); if (QWidget *editor = d->editorForIndex(index).widget.data()) height = qMax(height, editor->height()); int hint = d->delegateForIndex(index)->sizeHint(option, index).height(); @@ -3048,9 +3046,8 @@ int QAbstractItemView::sizeHintForColumn(int column) const QStyleOptionViewItem option = d->viewOptionsV1(); int width = 0; int rows = d->model->rowCount(d->root); - QModelIndex index; for (int r = 0; r < rows; ++r) { - index = d->model->index(r, column, d->root); + const QModelIndex index = d->model->index(r, column, d->root); if (QWidget *editor = d->editorForIndex(index).widget.data()) width = qMax(width, editor->sizeHint().width()); int hint = d->delegateForIndex(index)->sizeHint(option, index).width(); diff --git a/src/widgets/itemviews/qcolumnview.cpp b/src/widgets/itemviews/qcolumnview.cpp index 5c317bbb0c..92bbdf6b69 100644 --- a/src/widgets/itemviews/qcolumnview.cpp +++ b/src/widgets/itemviews/qcolumnview.cpp @@ -861,11 +861,15 @@ void QColumnView::setColumnWidths(const QList<int> &list) { Q_D(QColumnView); int i = 0; - for (; (i < list.count() && i < d->columns.count()); ++i) { + const int listCount = list.count(); + const int count = qMin(listCount, d->columns.count()); + for (; i < count; ++i) { d->columns.at(i)->resize(list.at(i), d->columns.at(i)->height()); d->columnSizes[i] = list.at(i); } - for (; i < list.count(); ++i) + + d->columnSizes.reserve(listCount); + for (; i < listCount; ++i) d->columnSizes.append(list.at(i)); } @@ -878,7 +882,9 @@ QList<int> QColumnView::columnWidths() const { Q_D(const QColumnView); QList<int> list; - for (int i = 0; i < d->columns.count(); ++i) + const int columnCount = d->columns.count(); + list.reserve(columnCount); + for (int i = 0; i < columnCount; ++i) list.append(d->columnSizes.at(i)); return list; } diff --git a/src/widgets/itemviews/qdatawidgetmapper.cpp b/src/widgets/itemviews/qdatawidgetmapper.cpp index c9fdf9967a..ee7b3613a2 100644 --- a/src/widgets/itemviews/qdatawidgetmapper.cpp +++ b/src/widgets/itemviews/qdatawidgetmapper.cpp @@ -756,7 +756,7 @@ void QDataWidgetMapper::clearMapping() QList<QDataWidgetMapperPrivate::WidgetMapper> copy; d->widgetMap.swap(copy); // a C++98 move - for (std::reverse_iterator<QList<QDataWidgetMapperPrivate::WidgetMapper>::const_iterator> it(copy.cend()), end(copy.cbegin()); it != end; ++it) { + for (QList<QDataWidgetMapperPrivate::WidgetMapper>::const_reverse_iterator it = copy.crbegin(), end = copy.crend(); it != end; ++it) { if (it->widget) it->widget->removeEventFilter(d->delegate); } diff --git a/src/widgets/itemviews/qfileiconprovider.cpp b/src/widgets/itemviews/qfileiconprovider.cpp index 051cb8e7cc..f43bcd5d5a 100644 --- a/src/widgets/itemviews/qfileiconprovider.cpp +++ b/src/widgets/itemviews/qfileiconprovider.cpp @@ -117,6 +117,7 @@ public: if (themeSizes.isEmpty()) return sizes; + sizes.reserve(themeSizes.count()); foreach (int size, themeSizes) sizes << QSize(size, size); } diff --git a/src/widgets/itemviews/qlistview.cpp b/src/widgets/itemviews/qlistview.cpp index f3fd3e75a1..9b07564db9 100644 --- a/src/widgets/itemviews/qlistview.cpp +++ b/src/widgets/itemviews/qlistview.cpp @@ -53,6 +53,8 @@ QT_BEGIN_NAMESPACE +extern bool qt_sendSpontaneousEvent(QObject *receiver, QEvent *event); + /*! \class QListView @@ -796,6 +798,35 @@ void QListView::mouseReleaseEvent(QMouseEvent *e) } } +#ifndef QT_NO_WHEELEVENT +/*! + \reimp +*/ +void QListView::wheelEvent(QWheelEvent *e) +{ + Q_D(QListView); + if (e->orientation() == Qt::Vertical) { + if (e->angleDelta().x() == 0 + && ((d->flow == TopToBottom && d->wrap) || (d->flow == LeftToRight && !d->wrap)) + && d->vbar->minimum() == 0 && d->vbar->maximum() == 0) { + QPoint pixelDelta(e->pixelDelta().y(), e->pixelDelta().x()); + QPoint angleDelta(e->angleDelta().y(), e->angleDelta().x()); + QWheelEvent hwe(e->pos(), e->globalPos(), pixelDelta, angleDelta, e->delta(), + Qt::Horizontal, e->buttons(), e->modifiers(), e->phase()); + if (e->spontaneous()) + qt_sendSpontaneousEvent(d->hbar, &hwe); + else + QApplication::sendEvent(d->hbar, &hwe); + e->setAccepted(hwe.isAccepted()); + } else { + QApplication::sendEvent(d->vbar, e); + } + } else { + QApplication::sendEvent(d->hbar, e); + } +} +#endif // QT_NO_WHEELEVENT + /*! \reimp */ diff --git a/src/widgets/itemviews/qlistview.h b/src/widgets/itemviews/qlistview.h index f62c96067f..ac65a47d9f 100644 --- a/src/widgets/itemviews/qlistview.h +++ b/src/widgets/itemviews/qlistview.h @@ -146,6 +146,9 @@ protected: void mouseMoveEvent(QMouseEvent *e) Q_DECL_OVERRIDE; void mouseReleaseEvent(QMouseEvent *e) Q_DECL_OVERRIDE; +#ifndef QT_NO_WHEELEVENT + void wheelEvent(QWheelEvent *e) Q_DECL_OVERRIDE; +#endif void timerEvent(QTimerEvent *e) Q_DECL_OVERRIDE; void resizeEvent(QResizeEvent *e) Q_DECL_OVERRIDE; diff --git a/src/widgets/itemviews/qlistwidget.cpp b/src/widgets/itemviews/qlistwidget.cpp index 66f965aa54..0e1e56e966 100644 --- a/src/widgets/itemviews/qlistwidget.cpp +++ b/src/widgets/itemviews/qlistwidget.cpp @@ -299,7 +299,10 @@ void QListModel::sort(int column, Qt::SortOrder order) std::sort(sorting.begin(), sorting.end(), compare); QModelIndexList fromIndexes; QModelIndexList toIndexes; - for (int r = 0; r < sorting.count(); ++r) { + const int sortingCount = sorting.count(); + fromIndexes.reserve(sortingCount); + toIndexes.reserve(sortingCount); + for (int r = 0; r < sortingCount; ++r) { QListWidgetItem *item = sorting.at(r).first; toIndexes.append(createIndex(r, 0, item)); fromIndexes.append(createIndex(sorting.at(r).second, 0, sorting.at(r).first)); @@ -423,7 +426,9 @@ QMimeData *QListModel::internalMimeData() const QMimeData *QListModel::mimeData(const QModelIndexList &indexes) const { QList<QListWidgetItem*> itemlist; - for (int i = 0; i < indexes.count(); ++i) + const int indexesCount = indexes.count(); + itemlist.reserve(indexesCount); + for (int i = 0; i < indexesCount; ++i) itemlist << at(indexes.at(i).row()); const QListWidget *view = qobject_cast<const QListWidget*>(QObject::parent()); @@ -1694,7 +1699,9 @@ QList<QListWidgetItem*> QListWidget::selectedItems() const Q_D(const QListWidget); QModelIndexList indexes = selectionModel()->selectedIndexes(); QList<QListWidgetItem*> items; - for (int i = 0; i < indexes.count(); ++i) + const int numIndexes = indexes.count(); + items.reserve(numIndexes); + for (int i = 0; i < numIndexes; ++i) items.append(d->listModel()->at(indexes.at(i).row())); return items; } @@ -1710,7 +1717,9 @@ QList<QListWidgetItem*> QListWidget::findItems(const QString &text, Qt::MatchFla QModelIndexList indexes = d->listModel()->match(model()->index(0, 0, QModelIndex()), Qt::DisplayRole, text, -1, flags); QList<QListWidgetItem*> items; - for (int i = 0; i < indexes.size(); ++i) + const int indexesSize = indexes.size(); + items.reserve(indexesSize); + for (int i = 0; i < indexesSize; ++i) items.append(d->listModel()->at(indexes.at(i).row())); return items; } @@ -1795,6 +1804,7 @@ QMimeData *QListWidget::mimeData(const QList<QListWidgetItem*> items) const // if non empty, it's called from the model's own mimeData if (cachedIndexes.isEmpty()) { + cachedIndexes.reserve(items.count()); foreach (QListWidgetItem *item, items) cachedIndexes << indexFromItem(item); @@ -1845,7 +1855,9 @@ void QListWidget::dropEvent(QDropEvent *event) { if (d->dropOn(event, &row, &col, &topIndex)) { QList<QModelIndex> selIndexes = selectedIndexes(); QList<QPersistentModelIndex> persIndexes; - for (int i = 0; i < selIndexes.count(); i++) + const int selIndexesCount = selIndexes.count(); + persIndexes.reserve(selIndexesCount); + for (int i = 0; i < selIndexesCount; i++) persIndexes.append(selIndexes.at(i)); if (persIndexes.contains(topIndex)) diff --git a/src/widgets/itemviews/qtableview.cpp b/src/widgets/itemviews/qtableview.cpp index ae31387faf..238cbf3bcd 100644 --- a/src/widgets/itemviews/qtableview.cpp +++ b/src/widgets/itemviews/qtableview.cpp @@ -1884,6 +1884,7 @@ void QTableView::setSelection(const QRect &rect, QItemSelectionModel::SelectionF break; } } while (expanded); + selection.reserve((right - left + 1) * (bottom - top + 1)); for (int horizontal = left; horizontal <= right; ++horizontal) { int column = d->logicalColumn(horizontal); for (int vertical = top; vertical <= bottom; ++vertical) { @@ -1897,6 +1898,7 @@ void QTableView::setSelection(const QRect &rect, QItemSelectionModel::SelectionF int left = d->visualColumn(tl.column()); int bottom = d->visualRow(br.row()); int right = d->visualColumn(br.column()); + selection.reserve((right - left + 1) * (bottom - top + 1)); for (int horizontal = left; horizontal <= right; ++horizontal) { int column = d->logicalColumn(horizontal); for (int vertical = top; vertical <= bottom; ++vertical) { @@ -1908,6 +1910,7 @@ void QTableView::setSelection(const QRect &rect, QItemSelectionModel::SelectionF } else if (horizontalMoved) { int left = d->visualColumn(tl.column()); int right = d->visualColumn(br.column()); + selection.reserve(right - left + 1); for (int visual = left; visual <= right; ++visual) { int column = d->logicalColumn(visual); QModelIndex topLeft = d->model->index(tl.row(), column, d->root); @@ -1917,6 +1920,7 @@ void QTableView::setSelection(const QRect &rect, QItemSelectionModel::SelectionF } else if (verticalMoved) { int top = d->visualRow(tl.row()); int bottom = d->visualRow(br.row()); + selection.reserve(bottom - top + 1); for (int visual = top; visual <= bottom; ++visual) { int row = d->logicalRow(visual); QModelIndex topLeft = d->model->index(row, tl.column(), d->root); diff --git a/src/widgets/itemviews/qtablewidget.cpp b/src/widgets/itemviews/qtablewidget.cpp index 9ebcbc35a7..f0c7ac0d32 100644 --- a/src/widgets/itemviews/qtablewidget.cpp +++ b/src/widgets/itemviews/qtablewidget.cpp @@ -507,11 +507,15 @@ void QTableModel::sort(int column, Qt::SortOrder order) QVector<QTableWidgetItem*> sorted_table(tableItems.count()); QModelIndexList from; QModelIndexList to; - for (int i = 0; i < rowCount(); ++i) { + const int numRows = rowCount(); + const int numColumns = columnCount(); + from.reserve(numRows * numColumns); + to.reserve(numRows * numColumns); + for (int i = 0; i < numRows; ++i) { int r = (i < sortable.count() ? sortable.at(i).second : unsortable.at(i - sortable.count())); - for (int c = 0; c < columnCount(); ++c) { + for (int c = 0; c < numColumns; ++c) { sorted_table[tableIndex(i, c)] = item(r, c); from.append(createIndex(r, c)); to.append(createIndex(i, c)); @@ -812,7 +816,9 @@ QMimeData *QTableModel::internalMimeData() const QMimeData *QTableModel::mimeData(const QModelIndexList &indexes) const { QList<QTableWidgetItem*> items; - for (int i = 0; i < indexes.count(); ++i) + const int indexesCount = indexes.count(); + items.reserve(indexesCount); + for (int i = 0; i < indexesCount; ++i) items << item(indexes.at(i)); const QTableWidget *view = qobject_cast<const QTableWidget*>(QObject::parent()); @@ -2326,7 +2332,9 @@ QList<QTableWidgetSelectionRange> QTableWidget::selectedRanges() const { const QList<QItemSelectionRange> ranges = selectionModel()->selection(); QList<QTableWidgetSelectionRange> result; - for (int i = 0; i < ranges.count(); ++i) + const int rangesCount = ranges.count(); + result.reserve(rangesCount); + for (int i = 0; i < rangesCount; ++i) result.append(QTableWidgetSelectionRange(ranges.at(i).top(), ranges.at(i).left(), ranges.at(i).bottom(), @@ -2372,7 +2380,9 @@ QList<QTableWidgetItem*> QTableWidget::findItems(const QString &text, Qt::MatchF indexes += d->model->match(model()->index(0, column, QModelIndex()), Qt::DisplayRole, text, -1, flags); QList<QTableWidgetItem*> items; - for (int i = 0; i < indexes.size(); ++i) + const int indexCount = indexes.size(); + items.reserve(indexCount); + for (int i = 0; i < indexCount; ++i) items.append(d->tableModel()->item(indexes.at(i))); return items; } @@ -2565,6 +2575,7 @@ QMimeData *QTableWidget::mimeData(const QList<QTableWidgetItem*> items) const // if non empty, it's called from the model's own mimeData if (cachedIndexes.isEmpty()) { + cachedIndexes.reserve(items.count()); foreach (QTableWidgetItem *item, items) cachedIndexes << indexFromItem(item); @@ -2676,7 +2687,9 @@ void QTableWidget::dropEvent(QDropEvent *event) { } QList<QTableWidgetItem *> taken; - for (int i = 0; i < indexes.count(); ++i) + const int indexesCount = indexes.count(); + taken.reserve(indexesCount); + for (int i = 0; i < indexesCount; ++i) taken.append(takeItem(indexes.at(i).row(), indexes.at(i).column())); for (int i = 0; i < indexes.count(); ++i) { diff --git a/src/widgets/itemviews/qtreewidget.cpp b/src/widgets/itemviews/qtreewidget.cpp index bf736bc387..5970e94292 100644 --- a/src/widgets/itemviews/qtreewidget.cpp +++ b/src/widgets/itemviews/qtreewidget.cpp @@ -1720,12 +1720,12 @@ void QTreeWidgetItem::setData(int column, int role, const QVariant &value) } } break; case Qt::CheckStateRole: - if ((itemFlags & Qt::ItemIsTristate) && value != Qt::PartiallyChecked) { + if ((itemFlags & Qt::ItemIsAutoTristate) && value != Qt::PartiallyChecked) { for (int i = 0; i < children.count(); ++i) { QTreeWidgetItem *child = children.at(i); if (child->data(column, role).isValid()) {// has a CheckState Qt::ItemFlags f = itemFlags; // a little hack to avoid multiple dataChanged signals - itemFlags &= ~Qt::ItemIsTristate; + itemFlags &= ~Qt::ItemIsAutoTristate; child->setData(column, role, value); itemFlags = f; } @@ -1760,7 +1760,7 @@ void QTreeWidgetItem::setData(int column, int role, const QVariant &value) model->emitDataChanged(this, column); if (role == Qt::CheckStateRole) { QTreeWidgetItem *p; - for (p = par; p && (p->itemFlags & Qt::ItemIsTristate); p = p->par) + for (p = par; p && (p->itemFlags & Qt::ItemIsAutoTristate); p = p->par) model->emitDataChanged(p, column); } } @@ -1779,7 +1779,7 @@ QVariant QTreeWidgetItem::data(int column, int role) const break; case Qt::CheckStateRole: // special case for check state in tristate - if (children.count() && (itemFlags & Qt::ItemIsTristate)) + if (children.count() && (itemFlags & Qt::ItemIsAutoTristate)) return childrenCheckState(column); // fallthrough intended default: @@ -3042,7 +3042,9 @@ QList<QTreeWidgetItem*> QTreeWidget::findItems(const QString &text, Qt::MatchFla QModelIndexList indexes = d->model->match(model()->index(0, column, QModelIndex()), Qt::DisplayRole, text, -1, flags); QList<QTreeWidgetItem*> items; - for (int i = 0; i < indexes.size(); ++i) + const int indexesSize = indexes.size(); + items.reserve(indexesSize); + for (int i = 0; i < indexesSize; ++i) items.append(d->item(indexes.at(i))); return items; } @@ -3371,7 +3373,9 @@ void QTreeWidget::dropEvent(QDropEvent *event) { if (d->dropOn(event, &row, &col, &topIndex)) { QList<QModelIndex> idxs = selectedIndexes(); QList<QPersistentModelIndex> indexes; - for (int i = 0; i < idxs.count(); i++) + const int indexesCount = idxs.count(); + indexes.reserve(indexesCount); + for (int i = 0; i < indexesCount; i++) indexes.append(idxs.at(i)); if (indexes.contains(topIndex)) diff --git a/src/widgets/kernel/qapplication.cpp b/src/widgets/kernel/qapplication.cpp index b9fd6312e7..504932dc53 100644 --- a/src/widgets/kernel/qapplication.cpp +++ b/src/widgets/kernel/qapplication.cpp @@ -3250,12 +3250,11 @@ bool QApplication::notify(QObject *receiver, QEvent *e) QPointer<QWidget> pw = w; while (w) { - QMouseEvent me(mouse->type(), relpos, mouse->windowPos(), mouse->globalPos(), mouse->button(), mouse->buttons(), - mouse->modifiers()); + QMouseEvent me(mouse->type(), relpos, mouse->windowPos(), mouse->globalPos(), + mouse->button(), mouse->buttons(), mouse->modifiers(), mouse->source()); me.spont = mouse->spontaneous(); me.setTimestamp(mouse->timestamp()); QGuiApplicationPrivate::setMouseEventFlags(&me, mouse->flags()); - QGuiApplicationPrivate::setMouseEventSource(&me, mouse->source()); // throw away any mouse-tracking-only mouse events if (!w->hasMouseTracking() && mouse->type() == QEvent::MouseMove && mouse->buttons() == 0) { diff --git a/src/widgets/kernel/qgesturemanager.cpp b/src/widgets/kernel/qgesturemanager.cpp index b5d3a56d3f..8cb7c2b560 100644 --- a/src/widgets/kernel/qgesturemanager.cpp +++ b/src/widgets/kernel/qgesturemanager.cpp @@ -569,18 +569,19 @@ void QGestureManager::getGestureTargets(const QSet<QGesture*> &gestures, } // for each gesture type - foreach (Qt::GestureType type, gestureByTypes.keys()) { - QHash<QWidget *, QGesture *> gestures = gestureByTypes.value(type); - foreach (QWidget *widget, gestures.keys()) { + for (GestureByTypes::const_iterator git = gestureByTypes.cbegin(), gend = gestureByTypes.cend(); git != gend; ++git) { + const QHash<QWidget *, QGesture *> &gestures = git.value(); + for (QHash<QWidget *, QGesture *>::const_iterator wit = gestures.cbegin(), wend = gestures.cend(); wit != wend; ++wit) { + QWidget *widget = wit.key(); QWidget *w = widget->parentWidget(); while (w) { QMap<Qt::GestureType, Qt::GestureFlags>::const_iterator it - = w->d_func()->gestureContext.constFind(type); + = w->d_func()->gestureContext.constFind(git.key()); if (it != w->d_func()->gestureContext.constEnd()) { // i.e. 'w' listens to gesture 'type' if (!(it.value() & Qt::DontStartGestureOnChildren) && w != widget) { // conflicting gesture! - (*conflicts)[widget].append(gestures[widget]); + (*conflicts)[widget].append(wit.value()); break; } } @@ -591,7 +592,7 @@ void QGestureManager::getGestureTargets(const QSet<QGesture*> &gestures, w = w->parentWidget(); } if (!w) - (*normal)[widget].append(gestures[widget]); + (*normal)[widget].append(wit.value()); } } } diff --git a/src/widgets/kernel/qlayout.cpp b/src/widgets/kernel/qlayout.cpp index d3e5986103..e74f17b6f7 100644 --- a/src/widgets/kernel/qlayout.cpp +++ b/src/widgets/kernel/qlayout.cpp @@ -1175,13 +1175,12 @@ QLayoutItem *QLayout::replaceWidget(QWidget *from, QWidget *to, Qt::FindChildOpt if (index == -1) return 0; + addChildWidget(to); QLayoutItem *newitem = new QWidgetItem(to); newitem->setAlignment(item->alignment()); QLayoutItem *r = d->replaceAt(index, newitem); if (!r) delete newitem; - else - addChildWidget(to); return r; } diff --git a/src/widgets/kernel/qsizepolicy.cpp b/src/widgets/kernel/qsizepolicy.cpp index 1476b4c5d7..3c28f5ccf7 100644 --- a/src/widgets/kernel/qsizepolicy.cpp +++ b/src/widgets/kernel/qsizepolicy.cpp @@ -332,6 +332,15 @@ void QSizePolicy::setControlType(ControlType type) */ /*! + \fn uint qHash(QSizePolicy key, uint seed = 0) + \since 5.6 + \relates QSizePolicy + + Returns the hash value for \a key, using + \a seed to seed the calculation. +*/ + +/*! \fn int QSizePolicy::horizontalStretch() const Returns the horizontal stretch factor of the size policy. diff --git a/src/widgets/kernel/qsizepolicy.h b/src/widgets/kernel/qsizepolicy.h index 6cd511f513..7c9a356973 100644 --- a/src/widgets/kernel/qsizepolicy.h +++ b/src/widgets/kernel/qsizepolicy.h @@ -40,6 +40,9 @@ QT_BEGIN_NAMESPACE class QVariant; +class QSizePolicy; + +Q_DECL_CONST_FUNCTION inline uint qHash(QSizePolicy key, uint seed = 0) Q_DECL_NOTHROW; class Q_WIDGETS_EXPORT QSizePolicy { @@ -112,6 +115,9 @@ public: bool operator==(const QSizePolicy& s) const { return data == s.data; } bool operator!=(const QSizePolicy& s) const { return data != s.data; } + + friend Q_DECL_CONST_FUNCTION uint qHash(QSizePolicy key, uint seed) Q_DECL_NOTHROW { return qHash(key.data, seed); } + operator QVariant() const; int horizontalStretch() const { return static_cast<int>(bits.horStretch); } diff --git a/src/widgets/kernel/qtooltip.cpp b/src/widgets/kernel/qtooltip.cpp index 8a800ab9d0..51bf6e4684 100644 --- a/src/widgets/kernel/qtooltip.cpp +++ b/src/widgets/kernel/qtooltip.cpp @@ -37,7 +37,6 @@ #include <qapplication.h> #include <qdesktopwidget.h> #include <qevent.h> -#include <qhash.h> #include <qlabel.h> #include <qpointer.h> #include <qstyle.h> diff --git a/src/widgets/kernel/qwhatsthis.cpp b/src/widgets/kernel/qwhatsthis.cpp index 5fb4695687..1e437c4fb7 100644 --- a/src/widgets/kernel/qwhatsthis.cpp +++ b/src/widgets/kernel/qwhatsthis.cpp @@ -42,7 +42,6 @@ #include "qscreen.h" #include "qpainter.h" #include "qtimer.h" -#include "qhash.h" #include "qaction.h" #include "qcursor.h" #include "qbitmap.h" diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index bd77e7f616..9ea5fd6018 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -37,7 +37,6 @@ #include "qcursor.h" #include "qdesktopwidget_p.h" #include "qevent.h" -#include "qhash.h" #include "qlayout.h" #include "qmenu.h" #include "qmetaobject.h" @@ -100,6 +99,7 @@ #include "qwindowcontainer_p.h" +#include <QtPlatformHeaders/qxcbwindowfunctions.h> // widget/widget data creation count //#define QWIDGET_EXTRA_DEBUG @@ -704,7 +704,7 @@ void QWidget::setAutoFillBackground(bool enabled) close(). \row \li Top-level windows \li - \l windowModified, \l windowTitle, \l windowIcon, \l windowIconText, + \l windowModified, \l windowTitle, \l windowIcon, \l isActiveWindow, activateWindow(), \l minimized, showMinimized(), \l maximized, showMaximized(), \l fullScreen, showFullScreen(), showNormal(). @@ -5939,7 +5939,7 @@ void QWidget::unsetLocale() window title, if set. This is done by the QPA plugin, so it is shown to the user, but isn't part of the windowTitle string. - \sa windowIcon, windowIconText, windowModified, windowFilePath + \sa windowIcon, windowModified, windowFilePath */ QString QWidget::windowTitle() const { @@ -6034,7 +6034,11 @@ void QWidgetPrivate::setWindowIconText_helper(const QString &title) void QWidgetPrivate::setWindowIconText_sys(const QString &iconText) { - Q_UNUSED(iconText); + Q_Q(QWidget); + // ### The QWidget property is deprecated, but the XCB window function is not. + // It should remain available for the rare application that needs it. + if (QWindow *window = q->windowHandle()) + QXcbWindowFunctions::setWmWindowIconText(window, iconText); } /*! @@ -6044,6 +6048,9 @@ void QWidgetPrivate::setWindowIconText_sys(const QString &iconText) new \a iconText as an argument. \since 5.2 + \obsolete + + This signal is deprecated. */ void QWidget::setWindowIconText(const QString &iconText) @@ -6094,7 +6101,7 @@ void QWidget::setWindowTitle(const QString &title) has been set, windowIcon() returns the application icon (QApplication::windowIcon()). - \sa windowIconText, windowTitle + \sa windowTitle */ QIcon QWidget::windowIcon() const { @@ -6110,8 +6117,15 @@ QIcon QWidget::windowIcon() const void QWidgetPrivate::setWindowIcon_helper() { + Q_Q(QWidget); QEvent e(QEvent::WindowIconChange); - QApplication::sendEvent(q_func(), &e); + + // Do not send the event if the widget is a top level. + // In that case, setWindowIcon_sys does it, and event propagation from + // QWidgetWindow to the top level QWidget ensures that the event reaches + // the top level anyhow + if (!q->windowHandle()) + QApplication::sendEvent(q, &e); for (int i = 0; i < children.size(); ++i) { QWidget *w = qobject_cast<QWidget *>(children.at(i)); if (w && !w->isWindow()) @@ -6154,10 +6168,15 @@ void QWidgetPrivate::setWindowIcon_sys() /*! \property QWidget::windowIconText - \brief the widget's icon text + \brief the text to be displayed on the icon of a minimized window This property only makes sense for windows. If no icon - text has been set, this functions returns an empty string. + text has been set, this accessor returns an empty string. + It is only implemented on the X11 platform, and only certain + window managers use this window property. + + \obsolete + This property is deprecated. \sa windowIcon, windowTitle */ @@ -9711,6 +9730,8 @@ void QWidget::setInputMethodHints(Qt::InputMethodHints hints) d->imHints = hints; if (this == QGuiApplication::focusObject()) QGuiApplication::inputMethod()->update(Qt::ImHints); +#else + Q_UNUSED(hints); #endif //QT_NO_IM } @@ -12798,6 +12819,65 @@ void QWidgetPrivate::setWidgetParentHelper(QObject *widgetAsObject, QObject *new widget->setParent(static_cast<QWidget*>(newParent)); } +#ifndef QT_NO_DEBUG_STREAM + +static inline void formatWidgetAttributes(QDebug debug, const QWidget *widget) +{ + const QMetaObject *qtMo = qt_getEnumMetaObject(Qt::WA_AttributeCount); + const QMetaEnum me = qtMo->enumerator(qtMo->indexOfEnumerator("WidgetAttribute")); + debug << ", attributes=["; + int count = 0; + for (int a = 0; a < Qt::WA_AttributeCount; ++a) { + if (widget->testAttribute(static_cast<Qt::WidgetAttribute>(a))) { + if (count++) + debug << ','; + debug << me.valueToKey(a); + } + } + debug << ']'; +} + +QDebug operator<<(QDebug debug, const QWidget *widget) +{ + const QDebugStateSaver saver(debug); + debug.nospace(); + if (widget) { + debug << widget->metaObject()->className() << '(' << (void *)widget; + if (!widget->objectName().isEmpty()) + debug << ", name=" << widget->objectName(); + if (debug.verbosity() > 2) { + const QRect geometry = widget->geometry(); + const QRect frameGeometry = widget->frameGeometry(); + if (widget->isVisible()) + debug << ", visible"; + if (!widget->isEnabled()) + debug << ", disabled"; + debug << ", states=" << widget->windowState() + << ", type=" << widget->windowType() << ", flags=" << widget->windowFlags(); + formatWidgetAttributes(debug, widget); + if (widget->isWindow()) + debug << ", window"; + debug << ", " << geometry.width() << 'x' << geometry.height() + << forcesign << geometry.x() << geometry.y() << noforcesign; + if (frameGeometry != geometry) { + const QMargins margins(geometry.x() - frameGeometry.x(), + geometry.y() - frameGeometry.y(), + frameGeometry.right() - geometry.right(), + frameGeometry.bottom() - geometry.bottom()); + debug << ", margins=" << margins; + } + debug << ", devicePixelRatio=" << widget->devicePixelRatio(); + if (const WId wid = widget->internalWinId()) + debug << ", winId=0x" << hex << wid << dec; + } + debug << ')'; + } else { + debug << "QWidget(0x0)"; + } + return debug; +} +#endif // !QT_NO_DEBUG_STREAM + QT_END_NAMESPACE #include "moc_qwidget.cpp" diff --git a/src/widgets/kernel/qwidget.h b/src/widgets/kernel/qwidget.h index c3913e9d45..782c892a32 100644 --- a/src/widgets/kernel/qwidget.h +++ b/src/widgets/kernel/qwidget.h @@ -89,6 +89,9 @@ class QGraphicsEffect; class QRasterWindowSurface; class QUnifiedToolbarSurface; class QPixmap; +#ifndef QT_NO_DEBUG_STREAM +class QDebug; +#endif class QWidgetData { @@ -165,7 +168,7 @@ class Q_WIDGETS_EXPORT QWidget : public QObject, public QPaintDevice Q_PROPERTY(bool acceptDrops READ acceptDrops WRITE setAcceptDrops) Q_PROPERTY(QString windowTitle READ windowTitle WRITE setWindowTitle NOTIFY windowTitleChanged DESIGNABLE isWindow) Q_PROPERTY(QIcon windowIcon READ windowIcon WRITE setWindowIcon NOTIFY windowIconChanged DESIGNABLE isWindow) - Q_PROPERTY(QString windowIconText READ windowIconText WRITE setWindowIconText NOTIFY windowIconTextChanged DESIGNABLE isWindow) + Q_PROPERTY(QString windowIconText READ windowIconText WRITE setWindowIconText NOTIFY windowIconTextChanged DESIGNABLE isWindow) // deprecated Q_PROPERTY(double windowOpacity READ windowOpacity WRITE setWindowOpacity DESIGNABLE isWindow) Q_PROPERTY(bool windowModified READ isWindowModified WRITE setWindowModified DESIGNABLE isWindow) #ifndef QT_NO_TOOLTIP @@ -858,6 +861,10 @@ inline bool QWidget::testAttribute(Qt::WidgetAttribute attribute) const #define QWIDGETSIZE_MAX ((1<<24)-1) +#ifndef QT_NO_DEBUG_STREAM +Q_WIDGETS_EXPORT QDebug operator<<(QDebug, const QWidget *); +#endif + QT_END_NAMESPACE #endif // QWIDGET_H diff --git a/src/widgets/kernel/qwidgetwindow.cpp b/src/widgets/kernel/qwidgetwindow.cpp index ba8c16e838..01d6d89857 100644 --- a/src/widgets/kernel/qwidgetwindow.cpp +++ b/src/widgets/kernel/qwidgetwindow.cpp @@ -51,7 +51,6 @@ QT_BEGIN_NAMESPACE Q_WIDGETS_EXPORT extern bool qt_tab_all_widgets(); QWidget *qt_button_down = 0; // widget got last button-down -static QPointer<QWidget> qt_tablet_target = 0; // popup control QWidget *qt_popup_down = 0; // popup that contains the pressed widget @@ -161,7 +160,7 @@ bool QWidgetWindow::event(QEvent *event) if (m_widget->testAttribute(Qt::WA_DontShowOnScreen)) { // \a event is uninteresting for QWidgetWindow, the event was probably // generated before WA_DontShowOnScreen was set - return m_widget->event(event); + return QCoreApplication::sendEvent(m_widget, event); } switch (event->type()) { @@ -303,7 +302,7 @@ bool QWidgetWindow::event(QEvent *event) break; } - if (m_widget->event(event) && event->type() != QEvent::Timer) + if (QCoreApplication::sendEvent(m_widget, event) && event->type() != QEvent::Timer) return true; return QWindow::event(event); @@ -446,8 +445,8 @@ void QWidgetWindow::handleMouseEvent(QMouseEvent *event) if (receiver != popup) widgetPos = receiver->mapFromGlobal(event->globalPos()); QWidget *alien = m_widget->childAt(m_widget->mapFromGlobal(event->globalPos())); - QMouseEvent e(event->type(), widgetPos, event->windowPos(), event->screenPos(), event->button(), event->buttons(), event->modifiers()); - QGuiApplicationPrivate::setMouseEventSource(&e, QGuiApplicationPrivate::mouseEventSource(event)); + QMouseEvent e(event->type(), widgetPos, event->windowPos(), event->screenPos(), + event->button(), event->buttons(), event->modifiers(), event->source()); e.setTimestamp(event->timestamp()); QApplicationPrivate::sendMouseEvent(receiver, &e, alien, m_widget, &qt_button_down, qt_last_mouse_receiver); qt_last_mouse_receiver = receiver; @@ -489,9 +488,9 @@ void QWidgetWindow::handleMouseEvent(QMouseEvent *event) if (globalGeometry.contains(event->globalPos())) { // Use postEvent() to ensure the local QEventLoop terminates when called from QMenu::exec() const QPoint localPos = win->mapFromGlobal(event->globalPos()); - QMouseEvent *e = new QMouseEvent(QEvent::MouseButtonPress, localPos, localPos, event->globalPos(), event->button(), event->buttons(), event->modifiers()); + QMouseEvent *e = new QMouseEvent(QEvent::MouseButtonPress, localPos, localPos, event->globalPos(), + event->button(), event->buttons(), event->modifiers(), event->source()); QCoreApplicationPrivate::setEventSpontaneous(e, true); - QGuiApplicationPrivate::setMouseEventSource(e, QGuiApplicationPrivate::mouseEventSource(event)); e->setTimestamp(event->timestamp()); QCoreApplication::postEvent(win, e); } @@ -548,8 +547,7 @@ void QWidgetWindow::handleMouseEvent(QMouseEvent *event) // The preceding statement excludes MouseButtonPress events which caused // creation of a MouseButtonDblClick event. QTBUG-25831 QMouseEvent translated(event->type(), mapped, event->windowPos(), event->screenPos(), - event->button(), event->buttons(), event->modifiers()); - QGuiApplicationPrivate::setMouseEventSource(&translated, QGuiApplicationPrivate::mouseEventSource(event)); + event->button(), event->buttons(), event->modifiers(), event->source()); translated.setTimestamp(event->timestamp()); QApplicationPrivate::sendMouseEvent(receiver, &translated, widget, m_widget, &qt_button_down, qt_last_mouse_receiver); @@ -874,6 +872,7 @@ bool QWidgetWindow::nativeEvent(const QByteArray &eventType, void *message, long #ifndef QT_NO_TABLETEVENT void QWidgetWindow::handleTabletEvent(QTabletEvent *event) { + static QPointer<QWidget> qt_tablet_target = 0; if (event->type() == QEvent::TabletPress) { QWidget *widget = m_widget->childAt(event->pos()); if (!widget) diff --git a/src/widgets/styles/qfusionstyle.cpp b/src/widgets/styles/qfusionstyle.cpp index 6d722c680b..f87542ffa8 100644 --- a/src/widgets/styles/qfusionstyle.cpp +++ b/src/widgets/styles/qfusionstyle.cpp @@ -40,7 +40,6 @@ #include <qpushbutton.h> #include <qpainter.h> #include <qdir.h> -#include <qhash.h> #include <qstyleoption.h> #include <qapplication.h> #include <qmainwindow.h> diff --git a/src/widgets/styles/qgtk2painter.cpp b/src/widgets/styles/qgtk2painter.cpp index 489d456617..ea8afbc93c 100644 --- a/src/widgets/styles/qgtk2painter.cpp +++ b/src/widgets/styles/qgtk2painter.cpp @@ -93,6 +93,7 @@ namespace QGtk2PainterPrivate { static void initGtk() { +#ifndef QT_NO_LIBRARY static bool initialized = false; if (!initialized) { // enforce the "0" suffix, so we'll open libgtk-x11-2.0.so.0 @@ -123,6 +124,7 @@ static void initGtk() initialized = true; } +#endif // !QT_NO_LIBRARY } // To recover alpha we apply the gtk painting function two times to diff --git a/src/widgets/styles/qgtkstyle_p.cpp b/src/widgets/styles/qgtkstyle_p.cpp index 0e119a11ae..00682c1c0f 100644 --- a/src/widgets/styles/qgtkstyle_p.cpp +++ b/src/widgets/styles/qgtkstyle_p.cpp @@ -326,6 +326,7 @@ void QGtkStylePrivate::gtkWidgetSetFocus(GtkWidget *widget, bool focus) */ void QGtkStylePrivate::resolveGtk() const { +#ifndef QT_NO_LIBRARY // enforce the "0" suffix, so we'll open libgtk-x11-2.0.so.0 QLibrary libgtk(QLS("gtk-x11-2.0"), 0, 0); @@ -427,6 +428,7 @@ void QGtkStylePrivate::resolveGtk() const gnome_icon_lookup_sync = (Ptr_gnome_icon_lookup_sync)QLibrary::resolve(QLS("gnomeui-2"), 0, "gnome_icon_lookup_sync"); gnome_vfs_init= (Ptr_gnome_vfs_init)QLibrary::resolve(QLS("gnomevfs-2"), 0, "gnome_vfs_init"); +#endif // !QT_NO_LIBRARY } /* \internal @@ -593,11 +595,13 @@ void QGtkStylePrivate::cleanupGtkWidgets() static bool resolveGConf() { +#ifndef QT_NO_LIBRARY if (!QGtkStylePrivate::gconf_client_get_default) { QGtkStylePrivate::gconf_client_get_default = (Ptr_gconf_client_get_default)QLibrary::resolve(QLS("gconf-2"), 4, "gconf_client_get_default"); QGtkStylePrivate::gconf_client_get_string = (Ptr_gconf_client_get_string)QLibrary::resolve(QLS("gconf-2"), 4, "gconf_client_get_string"); QGtkStylePrivate::gconf_client_get_bool = (Ptr_gconf_client_get_bool)QLibrary::resolve(QLS("gconf-2"), 4, "gconf_client_get_bool"); } +#endif // !QT_NO_LIBRARY return (QGtkStylePrivate::gconf_client_get_default !=0); } diff --git a/src/widgets/styles/qmacstyle_mac.mm b/src/widgets/styles/qmacstyle_mac.mm index d9238dc9d5..f4686f2810 100644 --- a/src/widgets/styles/qmacstyle_mac.mm +++ b/src/widgets/styles/qmacstyle_mac.mm @@ -93,18 +93,6 @@ QT_USE_NAMESPACE -namespace { -class AutoReleasePool -{ -public: - AutoReleasePool(): pool([[NSAutoreleasePool alloc] init]) {} - ~AutoReleasePool() { [pool release]; } - -private: - NSAutoreleasePool *pool; -}; -} - @interface QT_MANGLE_NAMESPACE(NotificationReceiver) : NSObject { QMacStylePrivate *mPrivate; } @@ -126,7 +114,7 @@ QT_NAMESPACE_ALIAS_OBJC_CLASS(NotificationReceiver); { Q_UNUSED(notification); QEvent event(QEvent::StyleChange); - QMutableSetIterator<QPointer<QObject> > it(QMacStylePrivate::scrollBars); + QMutableVectorIterator<QPointer<QObject> > it(QMacStylePrivate::scrollBars); while (it.hasNext()) { if (!it.next()) it.remove(); @@ -150,12 +138,7 @@ const int QMacStylePrivate::BevelButtonW = 50; const int QMacStylePrivate::BevelButtonH = 22; const int QMacStylePrivate::PushButtonContentPadding = 6; -QSet<QPointer<QObject> > QMacStylePrivate::scrollBars; - -static uint qHash(const QPointer<QObject> &ptr) -{ - return qHash(ptr.data()); -} +QVector<QPointer<QObject> > QMacStylePrivate::scrollBars; // Title bar gradient colors for Lion were determined by inspecting PSDs exported // using CoreUI's CoreThemeDocument; there is no public API to retrieve them @@ -1753,7 +1736,7 @@ QMacStylePrivate::QMacStylePrivate() QMacStylePrivate::~QMacStylePrivate() { - AutoReleasePool pool; + QMacAutoReleasePool pool; Q_FOREACH (NSView *b, cocoaControls) [b release]; } @@ -2135,7 +2118,7 @@ QMacStyle::QMacStyle() : QCommonStyle(*new QMacStylePrivate) { Q_D(QMacStyle); - AutoReleasePool pool; + QMacAutoReleasePool pool; d->receiver = [[NotificationReceiver alloc] initWithPrivate:d]; NotificationReceiver *receiver = static_cast<NotificationReceiver *>(d->receiver); @@ -2152,7 +2135,7 @@ QMacStyle::QMacStyle() QMacStyle::~QMacStyle() { Q_D(QMacStyle); - AutoReleasePool pool; + QMacAutoReleasePool pool; [reinterpret_cast<NSScroller*>(d->nsscroller) release]; @@ -2169,7 +2152,7 @@ QMacStyle::~QMacStyle() */ QPixmap QMacStylePrivate::generateBackgroundPattern() const { - AutoReleasePool pool; + QMacAutoReleasePool pool; QPixmap px(4, 4); QMacCGContext cg(&px); HIThemeSetFill(kThemeBrushDialogBackgroundActive, 0, cg, kHIThemeOrientationNormal); @@ -2767,7 +2750,7 @@ QPalette QMacStyle::standardPalette() const int QMacStyle::styleHint(StyleHint sh, const QStyleOption *opt, const QWidget *w, QStyleHintReturn *hret) const { - AutoReleasePool pool; + QMacAutoReleasePool pool; SInt32 ret = 0; switch (sh) { @@ -5379,7 +5362,7 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex // there is not enough space for them. if (cc == CC_ScrollBar) { if (opt && opt->styleObject && !QMacStylePrivate::scrollBars.contains(opt->styleObject)) - QMacStylePrivate::scrollBars.insert(QPointer<QObject>(opt->styleObject)); + QMacStylePrivate::scrollBars.append(QPointer<QObject>(opt->styleObject)); const int scrollBarLength = (slider->orientation == Qt::Horizontal) ? slider->rect.width() : slider->rect.height(); const QMacStyle::WidgetSizePolicy sizePolicy = widgetSizePolicy(widget, opt); diff --git a/src/widgets/styles/qmacstyle_mac_p_p.h b/src/widgets/styles/qmacstyle_mac_p_p.h index b09e81d595..33818568ec 100644 --- a/src/widgets/styles/qmacstyle_mac_p_p.h +++ b/src/widgets/styles/qmacstyle_mac_p_p.h @@ -86,7 +86,7 @@ #include <qdatetimeedit.h> #include <qmath.h> #include <qpair.h> -#include <qset.h> +#include <qvector.h> #include <QtWidgets/qgraphicsproxywidget.h> #include <QtWidgets/qgraphicsview.h> @@ -213,7 +213,7 @@ public: mutable QPointer<QObject> pressedButton; mutable QPointer<QObject> defaultButton; mutable QPointer<QObject> autoDefaultButton; - static QSet<QPointer<QObject> > scrollBars; + static QVector<QPointer<QObject> > scrollBars; struct ButtonState { int frame; diff --git a/src/widgets/styles/qstylesheetstyle.cpp b/src/widgets/styles/qstylesheetstyle.cpp index ae7accf7d0..40b8aaae9a 100644 --- a/src/widgets/styles/qstylesheetstyle.cpp +++ b/src/widgets/styles/qstylesheetstyle.cpp @@ -2393,6 +2393,13 @@ static bool unstylable(const QWidget *w) return true; } #endif + +#ifndef QT_NO_TABBAR + if (w->metaObject() == &QWidget::staticMetaObject + && qobject_cast<const QTabBar*>(w->parentWidget())) + return true; // The moving tab of a QTabBar +#endif + return false; } diff --git a/src/widgets/styles/qwindowsstyle.cpp b/src/widgets/styles/qwindowsstyle.cpp index 14af5ede39..db8a649931 100644 --- a/src/widgets/styles/qwindowsstyle.cpp +++ b/src/widgets/styles/qwindowsstyle.cpp @@ -1796,7 +1796,7 @@ void QWindowsStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPai QColor left, right; //Titlebar gradient - if (widget && widget->isWindow()) { + if (opt->state & QStyle::State_Window) { floating = true; if (active) { left = d->activeCaptionColor; diff --git a/src/widgets/styles/qwindowsstyle_p_p.h b/src/widgets/styles/qwindowsstyle_p_p.h index f1a4a390e1..3d1206b369 100644 --- a/src/widgets/styles/qwindowsstyle_p_p.h +++ b/src/widgets/styles/qwindowsstyle_p_p.h @@ -50,7 +50,6 @@ #ifndef QT_NO_STYLE_WINDOWS #include <qlist.h> -#include <qhash.h> QT_BEGIN_NAMESPACE diff --git a/src/widgets/util/qflickgesture.cpp b/src/widgets/util/qflickgesture.cpp index 0e598717c8..8eadc42625 100644 --- a/src/widgets/util/qflickgesture.cpp +++ b/src/widgets/util/qflickgesture.cpp @@ -66,8 +66,8 @@ static QMouseEvent *copyMouseEvent(QEvent *e) case QEvent::MouseButtonRelease: case QEvent::MouseMove: { QMouseEvent *me = static_cast<QMouseEvent *>(e); - QMouseEvent *cme = new QMouseEvent(me->type(), QPoint(0, 0), me->windowPos(), me->screenPos(), me->button(), me->buttons(), me->modifiers()); - QGuiApplicationPrivate::setMouseEventSource(cme, me->source()); + QMouseEvent *cme = new QMouseEvent(me->type(), QPoint(0, 0), me->windowPos(), me->screenPos(), + me->button(), me->buttons(), me->modifiers(), me->source()); return cme; } #ifndef QT_NO_GRAPHICSVIEW @@ -78,8 +78,8 @@ static QMouseEvent *copyMouseEvent(QEvent *e) #if 1 QEvent::Type met = me->type() == QEvent::GraphicsSceneMousePress ? QEvent::MouseButtonPress : (me->type() == QEvent::GraphicsSceneMouseRelease ? QEvent::MouseButtonRelease : QEvent::MouseMove); - QMouseEvent *cme = new QMouseEvent(met, QPoint(0, 0), QPoint(0, 0), me->screenPos(), me->button(), me->buttons(), me->modifiers()); - QGuiApplicationPrivate::setMouseEventSource(cme, me->source()); + QMouseEvent *cme = new QMouseEvent(met, QPoint(0, 0), QPoint(0, 0), me->screenPos(), + me->button(), me->buttons(), me->modifiers(), me->source()); return cme; #else QGraphicsSceneMouseEvent *copy = new QGraphicsSceneMouseEvent(me->type()); @@ -240,8 +240,7 @@ public: qFGDebug() << "QFG: sending a fake mouse release at far-far-away to " << mouseTarget; QMouseEvent re(QEvent::MouseButtonRelease, QPoint(), farFarAway, farFarAway, mouseButton, QApplication::mouseButtons() & ~mouseButton, - QApplication::keyboardModifiers()); - QGuiApplicationPrivate::setMouseEventSource(&re, mouseEventSource); + QApplication::keyboardModifiers(), mouseEventSource); sendMouseEvent(&re, RegrabMouseAfterwards); // don't clear the mouseTarget just yet, since we need to explicitly ungrab the mouse on release! } @@ -291,8 +290,7 @@ protected: if (me) { QMouseEvent copy(me->type(), mouseTarget->mapFromGlobal(me->globalPos()), mouseTarget->topLevelWidget()->mapFromGlobal(me->globalPos()), me->screenPos(), - me->button(), me->buttons(), me->modifiers()); - QGuiApplicationPrivate::setMouseEventSource(©, me->source()); + me->button(), me->buttons(), me->modifiers(), me->source()); qt_sendSpontaneousEvent(mouseTarget, ©); } diff --git a/src/widgets/util/qscroller_mac.mm b/src/widgets/util/qscroller_mac.mm index 9120c43075..07de07de52 100644 --- a/src/widgets/util/qscroller_mac.mm +++ b/src/widgets/util/qscroller_mac.mm @@ -43,7 +43,7 @@ QT_BEGIN_NAMESPACE QPointF QScrollerPrivate::realDpi(int screen) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + QMacAutoReleasePool pool; NSArray *nsscreens = [NSScreen screens]; if (screen < 0 || screen >= int([nsscreens count])) @@ -59,7 +59,6 @@ QPointF QScrollerPrivate::realDpi(int screen) } else { return QPointF(); } - [pool release]; } QT_END_NAMESPACE diff --git a/src/widgets/util/qsystemtrayicon_x11.cpp b/src/widgets/util/qsystemtrayicon_x11.cpp index 4060655d45..9a69db1bc8 100644 --- a/src/widgets/util/qsystemtrayicon_x11.cpp +++ b/src/widgets/util/qsystemtrayicon_x11.cpp @@ -52,6 +52,8 @@ #include <private/qguiapplication_p.h> #include <qdebug.h> +#include <QtPlatformHeaders/qxcbwindowfunctions.h> +#include <QtPlatformHeaders/qxcbintegrationfunctions.h> #ifndef QT_NO_SYSTEMTRAYICON QT_BEGIN_NAMESPACE @@ -112,17 +114,11 @@ QSystemTrayIconSys::QSystemTrayIconSys(QSystemTrayIcon *qIn) // window to ParentRelative (so that it inherits the background of its X11 parent window), call // xcb_clear_region before painting (so that the inherited background is visible) and then grab // the just-drawn background from the X11 server. - bool hasAlphaChannel = false; - QMetaObject::invokeMethod(QGuiApplication::platformNativeInterface(), - "systrayVisualHasAlphaChannel", Qt::DirectConnection, - Q_RETURN_ARG(bool, hasAlphaChannel)); + bool hasAlphaChannel = QXcbIntegrationFunctions::xEmbedSystemTrayVisualHasAlphaChannel(); setAttribute(Qt::WA_TranslucentBackground, hasAlphaChannel); if (!hasAlphaChannel) { createWinId(); - QMetaObject::invokeMethod(QGuiApplication::platformNativeInterface(), - "setParentRelativeBackPixmap", Qt::DirectConnection, - Q_ARG(const QWindow *, windowHandle()) - ); + QXcbWindowFunctions::setParentRelativeBackPixmap(windowHandle()); // XXX: This is actually required, but breaks things ("QWidget::paintEngine: Should no // longer be called"). Why is this needed? When the widget is drawn, we use tricks to grab @@ -143,15 +139,9 @@ bool QSystemTrayIconSys::addToTray() createWinId(); setMouseTracking(true); - bool requestResult = false; - if (!QMetaObject::invokeMethod(QGuiApplication::platformNativeInterface(), - "requestSystemTrayWindowDock", Qt::DirectConnection, - Q_RETURN_ARG(bool, requestResult), - Q_ARG(const QWindow *, windowHandle())) - || !requestResult) { - qWarning("requestSystemTrayWindowDock failed."); + if (!QXcbWindowFunctions::requestSystemTrayWindowDock(windowHandle())) return false; - } + if (!background.isNull()) background = QPixmap(); show(); @@ -171,15 +161,7 @@ void QSystemTrayIconSys::systemTrayWindowChanged(QScreen *) QRect QSystemTrayIconSys::globalGeometry() const { - QRect result; - if (!QMetaObject::invokeMethod(QGuiApplication::platformNativeInterface(), - "systemTrayWindowGlobalGeometry", Qt::DirectConnection, - Q_RETURN_ARG(QRect, result), - Q_ARG(const QWindow *, windowHandle())) - || !result.isValid()) { - qWarning("systemTrayWindowGlobalGeometry failed."); - } - return result; + return QXcbWindowFunctions::systemTrayWindowGlobalGeometry(windowHandle()); } void QSystemTrayIconSys::mousePressEvent(QMouseEvent *ev) diff --git a/src/widgets/widgets/qabstractbutton.cpp b/src/widgets/widgets/qabstractbutton.cpp index e413b3b87a..292bbc3325 100644 --- a/src/widgets/widgets/qabstractbutton.cpp +++ b/src/widgets/widgets/qabstractbutton.cpp @@ -221,13 +221,12 @@ void QButtonGroup::addButton(QAbstractButton *button, int id) button->d_func()->group = this; d->buttonList.append(button); if (id == -1) { - QList<int> ids = d->mapping.values(); - if (ids.isEmpty()) - d->mapping[button] = -2; - else { - std::sort(ids.begin(), ids.end()); - d->mapping[button] = ids.first()-1; - } + const QHash<QAbstractButton*, int>::const_iterator it + = std::min_element(d->mapping.cbegin(), d->mapping.cend()); + if (it == d->mapping.cend()) + d->mapping[button] = -2; + else + d->mapping[button] = *it - 1; } else { d->mapping[button] = id; } diff --git a/src/widgets/widgets/qabstractscrollarea.cpp b/src/widgets/widgets/qabstractscrollarea.cpp index 2e1caedde7..65d06eafc5 100644 --- a/src/widgets/widgets/qabstractscrollarea.cpp +++ b/src/widgets/widgets/qabstractscrollarea.cpp @@ -168,6 +168,10 @@ QAbstractScrollAreaPrivate::QAbstractScrollAreaPrivate() { } +QAbstractScrollAreaPrivate::~QAbstractScrollAreaPrivate() +{ +} + QAbstractScrollAreaScrollBarContainer::QAbstractScrollAreaScrollBarContainer(Qt::Orientation orientation, QWidget *parent) :QWidget(parent), scrollBar(new QScrollBar(orientation, this)), layout(new QBoxLayout(orientation == Qt::Horizontal ? QBoxLayout::LeftToRight : QBoxLayout::TopToBottom)), @@ -206,10 +210,12 @@ QWidgetList QAbstractScrollAreaScrollBarContainer::widgets(LogicalPosition posit QWidgetList list; const int scrollBarIndex = scrollBarLayoutIndex(); if (position == LogicalLeft) { + list.reserve(scrollBarIndex); for (int i = 0; i < scrollBarIndex; ++i) list.append(layout->itemAt(i)->widget()); } else if (position == LogicalRight) { const int layoutItemCount = layout->count(); + list.reserve(layoutItemCount - (scrollBarIndex + 1)); for (int i = scrollBarIndex + 1; i < layoutItemCount; ++i) list.append(layout->itemAt(i)->widget()); } diff --git a/src/widgets/widgets/qabstractscrollarea_p.h b/src/widgets/widgets/qabstractscrollarea_p.h index f770bb69f8..33222573f4 100644 --- a/src/widgets/widgets/qabstractscrollarea_p.h +++ b/src/widgets/widgets/qabstractscrollarea_p.h @@ -54,12 +54,15 @@ QT_BEGIN_NAMESPACE class QScrollBar; class QAbstractScrollAreaScrollBarContainer; + +// ### Qt 6: is the export still needed? If not, unexport QFramePrivate, too. class Q_WIDGETS_EXPORT QAbstractScrollAreaPrivate: public QFramePrivate { Q_DECLARE_PUBLIC(QAbstractScrollArea) public: QAbstractScrollAreaPrivate(); + ~QAbstractScrollAreaPrivate(); void replaceScrollBar(QScrollBar *scrollBar, Qt::Orientation orientation); diff --git a/src/widgets/widgets/qcombobox.cpp b/src/widgets/widgets/qcombobox.cpp index ba19b63c12..0ecbb8a435 100644 --- a/src/widgets/widgets/qcombobox.cpp +++ b/src/widgets/widgets/qcombobox.cpp @@ -2263,6 +2263,7 @@ void QComboBox::insertItems(int index, const QStringList &list) // construct a QStandardItem, reducing the number of expensive signals from the model if (QStandardItemModel *m = qobject_cast<QStandardItemModel*>(d->model)) { QList<QStandardItem *> items; + items.reserve(insertCount); QStandardItem *hiddenRoot = m->invisibleRootItem(); for (int i = 0; i < insertCount; ++i) items.append(new QStandardItem(list.at(i))); diff --git a/src/widgets/widgets/qcombobox_p.h b/src/widgets/widgets/qcombobox_p.h index 3fdfdcc22f..b69b94f3b9 100644 --- a/src/widgets/widgets/qcombobox_p.h +++ b/src/widgets/widgets/qcombobox_p.h @@ -57,7 +57,6 @@ #include "QtGui/qpainter.h" #include "QtWidgets/qstyle.h" #include "QtWidgets/qstyleoption.h" -#include "QtCore/qhash.h" #include "QtCore/qpair.h" #include "QtCore/qtimer.h" #include "private/qwidget_p.h" diff --git a/src/widgets/widgets/qdockarealayout.cpp b/src/widgets/widgets/qdockarealayout.cpp index e71b9616fc..c61984a457 100644 --- a/src/widgets/widgets/qdockarealayout.cpp +++ b/src/widgets/widgets/qdockarealayout.cpp @@ -1,6 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2015 Olivier Goffart <ogoffart@woboq.com> ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtWidgets module of the Qt Toolkit. @@ -1017,7 +1018,7 @@ QLayoutItem *QDockAreaLayoutInfo::plug(const QList<int> &path) index = -index - 1; if (path.count() > 1) { - const QDockAreaLayoutItem &item = item_list.at(index); + QDockAreaLayoutItem &item = item_list[index]; Q_ASSERT(item.subinfo != 0); return item.subinfo->plug(path.mid(1)); } @@ -1063,7 +1064,7 @@ QLayoutItem *QDockAreaLayoutInfo::unplug(const QList<int> &path) const int index = path.first(); if (path.count() > 1) { - const QDockAreaLayoutItem &item = item_list.at(index); + QDockAreaLayoutItem &item = item_list[index]; Q_ASSERT(item.subinfo != 0); return item.subinfo->unplug(path.mid(1)); } @@ -1854,20 +1855,6 @@ static Qt::DockWidgetArea toDockWidgetArea(QInternal::DockPosition pos) return Qt::NoDockWidgetArea; } -static QRect constrainedRect(QRect rect, const QRect &desktop) -{ - if (desktop.isValid()) { - rect.setWidth(qMin(rect.width(), desktop.width())); - rect.setHeight(qMin(rect.height(), desktop.height())); - rect.moveLeft(qMax(rect.left(), desktop.left())); - rect.moveTop(qMax(rect.top(), desktop.top())); - rect.moveRight(qMin(rect.right(), desktop.right())); - rect.moveBottom(qMin(rect.bottom(), desktop.bottom())); - } - - return rect; -} - bool QDockAreaLayoutInfo::restoreState(QDataStream &stream, QList<QDockWidget*> &widgets, bool testing) { uchar marker; @@ -1958,11 +1945,7 @@ bool QDockAreaLayoutInfo::restoreState(QDataStream &stream, QList<QDockWidget*> #endif if (!testing) { QRect r(x, y, w, h); - QDesktopWidget *desktop = QApplication::desktop(); - if (desktop->isVirtualDesktop()) - r = constrainedRect(r, desktop->screenGeometry(desktop->screenNumber(r.topLeft()))); - else - r = constrainedRect(r, desktop->screenGeometry(widget)); + r = QDockAreaLayout::constrainedRect(r, widget); widget->move(r.topLeft()); widget->resize(r.size()); } @@ -2075,6 +2058,36 @@ void QDockAreaLayoutInfo::updateSeparatorWidgets() const #endif //QT_NO_TABBAR #ifndef QT_NO_TABBAR +/*! \internal + reparent all the widgets contained in this layout portion to the + specified parent. This is used to reparent dock widgets and tabbars + to the floating window or the main window + */ +void QDockAreaLayoutInfo::reparentWidgets(QWidget *parent) +{ + if (tabBar) + tabBar->setParent(parent); + + for (int i = 0; i < item_list.count(); ++i) { + const QDockAreaLayoutItem &item = item_list.at(i); + if (item.flags & QDockAreaLayoutItem::GapItem) + continue; + if (item.skip()) + continue; + if (item.subinfo) + item.subinfo->reparentWidgets(parent); + if (item.widgetItem) { + QWidget *w = item.widgetItem->widget(); + if (w->parent() != parent) { + bool hidden = w->isHidden(); + w->setParent(parent); + if (!hidden) + w->show(); + } + } + } +} + //returns whether the tabbar is visible or not bool QDockAreaLayoutInfo::updateTabBar() const { @@ -2198,8 +2211,10 @@ QSet<QTabBar*> QDockAreaLayoutInfo::usedTabBars() const QSet<QWidget*> QDockAreaLayoutInfo::usedSeparatorWidgets() const { QSet<QWidget*> result; + const int numSeparatorWidgets = separatorWidgets.count(); + result.reserve(numSeparatorWidgets); - for (int i = 0; i < separatorWidgets.count(); ++i) + for (int i = 0; i < numSeparatorWidgets; ++i) result << separatorWidgets.at(i); for (int i = 0; i < item_list.count(); ++i) { @@ -2244,6 +2259,22 @@ QRect QDockAreaLayoutInfo::tabContentRect() const return result; } + +int QDockAreaLayoutInfo::tabIndexToListIndex(int tabIndex) const +{ + Q_ASSERT(tabbed && tabBar); + quintptr data = qvariant_cast<quintptr>(tabBar->tabData(tabIndex)); + for (int i = 0; i < item_list.count(); ++i) { + if (tabId(item_list.at(i)) == data) + return i; + } + return -1; +} + +void QDockAreaLayoutInfo::moveTab(int from, int to) +{ + item_list.move(tabIndexToListIndex(from), tabIndexToListIndex(to)); +} #endif // QT_NO_TABBAR /****************************************************************************** @@ -2965,6 +2996,33 @@ QSize QDockAreaLayout::minimumSize() const return QSize(qMax(row1, row2, row3), qMax(col1, col2, col3)); } +/*! \internal + Try to fit the given rectangle \a rect on the screen which contains + the window \a widget. + Used to compute the geometry of a dragged a dock widget that should + be shown with \a rect, but needs to be visible on the screen + */ +QRect QDockAreaLayout::constrainedRect(QRect rect, QWidget* widget) +{ + QRect desktop; + QDesktopWidget *desktopW = QApplication::desktop(); + if (desktopW->isVirtualDesktop()) + desktop = desktopW->screenGeometry(rect.topLeft()); + else + desktop = desktopW->screenGeometry(widget); + + if (desktop.isValid()) { + rect.setWidth(qMin(rect.width(), desktop.width())); + rect.setHeight(qMin(rect.height(), desktop.height())); + rect.moveLeft(qMax(rect.left(), desktop.left())); + rect.moveTop(qMax(rect.top(), desktop.top())); + rect.moveRight(qMin(rect.right(), desktop.right())); + rect.moveBottom(qMin(rect.bottom(), desktop.bottom())); + } + + return rect; +} + bool QDockAreaLayout::restoreDockWidget(QDockWidget *dockWidget) { QList<int> index = indexOfPlaceHolder(dockWidget->objectName()); @@ -2978,9 +3036,7 @@ bool QDockAreaLayout::restoreDockWidget(QDockWidget *dockWidget) item.widgetItem = new QDockWidgetItem(dockWidget); if (placeHolder->window) { - const QRect screenGeometry = - QApplication::desktop()->screenGeometry(placeHolder->topLevelRect.center()); - const QRect r = constrainedRect(placeHolder->topLevelRect, screenGeometry); + const QRect r = constrainedRect(placeHolder->topLevelRect, dockWidget); dockWidget->d_func()->setWindowState(true, true, r); } dockWidget->setVisible(!placeHolder->hidden); diff --git a/src/widgets/widgets/qdockarealayout_p.h b/src/widgets/widgets/qdockarealayout_p.h index 7c67466c7b..93b005f64f 100644 --- a/src/widgets/widgets/qdockarealayout_p.h +++ b/src/widgets/widgets/qdockarealayout_p.h @@ -202,12 +202,16 @@ public: QTabBar *tabBar; int tabBarShape; + void reparentWidgets(QWidget *p); bool updateTabBar() const; void setTabBarShape(int shape); QSize tabBarMinimumSize() const; QSize tabBarSizeHint() const; QSet<QTabBar*> usedTabBars() const; + + int tabIndexToListIndex(int) const; + void moveTab(int from, int to); #endif // QT_NO_TABBAR }; @@ -229,7 +233,8 @@ public: bool isValid() const; - enum { DockWidgetStateMarker = 0xfd }; + enum { DockWidgetStateMarker = 0xfd, FloatingDockWidgetTabMarker = 0xf9 }; + static QRect constrainedRect(QRect rect, QWidget *widget); void saveState(QDataStream &stream) const; bool restoreState(QDataStream &stream, const QList<QDockWidget*> &widgets, bool testing = false); diff --git a/src/widgets/widgets/qdockwidget.cpp b/src/widgets/widgets/qdockwidget.cpp index 21b0904cc0..1b7473fbd7 100644 --- a/src/widgets/widgets/qdockwidget.cpp +++ b/src/widgets/widgets/qdockwidget.cpp @@ -65,6 +65,18 @@ extern QString qt_setWindowTitle_helperHelper(const QString&, const QWidget*); / // qmainwindow.cpp extern QMainWindowLayout *qt_mainwindow_layout(const QMainWindow *window); +static inline QMainWindowLayout *qt_mainwindow_layout_from_dock(const QDockWidget *dock) +{ + const QWidget *p = dock->parentWidget(); + while (p) { + const QMainWindow *window = qobject_cast<const QMainWindow*>(p); + if (window) + return qt_mainwindow_layout(window); + p = p->parentWidget(); + } + return Q_NULLPTR; +} + static inline bool hasFeature(const QDockWidgetPrivate *priv, QDockWidget::DockWidgetFeature feature) { return (priv->features & feature) == feature; } @@ -194,25 +206,40 @@ QDockWidgetLayout::~QDockWidgetLayout() qDeleteAll(item_list); } +/*! \internal + Returns true if the dock widget managed by this layout should have a native + window decoration or if Qt needs to draw it. + */ bool QDockWidgetLayout::nativeWindowDeco() const { - return nativeWindowDeco(parentWidget()->isWindow()); + bool floating = parentWidget()->isWindow(); + if (!floating && qobject_cast<QDockWidgetGroupWindow*>(parentWidget()->parentWidget())) + return wmSupportsNativeWindowDeco(); + return nativeWindowDeco(floating); } -static bool isXcb() +/*! \internal + Returns true if the window manager can draw natively the windows decoration + of a dock widget + */ +bool QDockWidgetLayout::wmSupportsNativeWindowDeco() { +#if defined(Q_OS_WINCE) || defined(Q_OS_ANDROID) + return false; +#else static const bool xcb = !QGuiApplication::platformName().compare(QLatin1String("xcb"), Qt::CaseInsensitive); - return xcb; + return !xcb; +#endif } +/*! \internal + Returns true if the dock widget managed by this layout should have a native + window decoration or if Qt needs to draw it. The \a floating parameter + overrides the floating current state of the dock widget. + */ bool QDockWidgetLayout::nativeWindowDeco(bool floating) const { -#if defined(Q_OS_WINCE) || defined(Q_OS_ANDROID) - Q_UNUSED(floating) - return false; -#else - return !isXcb() && (floating && item_list[QDockWidgetLayout::TitleBar] == 0); -#endif + return wmSupportsNativeWindowDeco() && floating && item_list.at(QDockWidgetLayout::TitleBar) == 0; } @@ -611,7 +638,10 @@ void QDockWidget::initStyleOption(QStyleOptionDockWidget *option) const return; QDockWidgetLayout *dwlayout = qobject_cast<QDockWidgetLayout*>(layout()); - option->initFrom(this); + QDockWidgetGroupWindow *floatingTab = qobject_cast<QDockWidgetGroupWindow*>(parent()); + // If we are in a floating tab, init from the parent because the attributes and the geometry + // of the title bar should be taken from the floating window. + option->initFrom(floatingTab && !isFloating() ? parentWidget() : this); option->rect = dwlayout->titleArea(); option->title = d->fixedWindowTitle; option->closable = hasFeature(this, QDockWidget::DockWidgetClosable); @@ -681,14 +711,20 @@ void QDockWidgetPrivate::_q_toggleTopLevel() q->setFloating(!q->isFloating()); } +/*! \internal + Initialize the drag state structure and remember the position of the click. + This is called when the mouse is pressed, but the dock is not yet dragged out. + + \a nca specify that the event comes from NonClientAreaMouseButtonPress + */ void QDockWidgetPrivate::initDrag(const QPoint &pos, bool nca) { + Q_Q(QDockWidget); + if (state != 0) return; - QMainWindow *win = qobject_cast<QMainWindow*>(parent); - Q_ASSERT(win != 0); - QMainWindowLayout *layout = qt_mainwindow_layout(win); + QMainWindowLayout *layout = qt_mainwindow_layout_from_dock(q); Q_ASSERT(layout != 0); if (layout->pluggingWidget != 0) // the main window is animating a docking operation return; @@ -702,17 +738,23 @@ void QDockWidgetPrivate::initDrag(const QPoint &pos, bool nca) state->ctrlDrag = false; } -void QDockWidgetPrivate::startDrag() +/*! \internal + Actually start the drag and detach the dockwidget. + The \a group parameter is true when we should potentially drag a group of + tabbed widgets, and false if the dock widget should always be dragged + alone. + */ +void QDockWidgetPrivate::startDrag(bool group) { Q_Q(QDockWidget); if (state == 0 || state->dragging) return; - QMainWindowLayout *layout = qt_mainwindow_layout(qobject_cast<QMainWindow *>(q->parentWidget())); + QMainWindowLayout *layout = qt_mainwindow_layout_from_dock(q); Q_ASSERT(layout != 0); - state->widgetItem = layout->unplug(q); + state->widgetItem = layout->unplug(q, group); if (state->widgetItem == 0) { /* I have a QMainWindow parent, but I was never inserted with QMainWindow::addDockWidget, so the QMainWindowLayout has no @@ -728,6 +770,11 @@ void QDockWidgetPrivate::startDrag() state->dragging = true; } +/*! \internal + Ends the drag end drop operation of the QDockWidget. + The \a abort parameter specifies that it ends because of programmatic state + reset rather than mouse release event. + */ void QDockWidgetPrivate::endDrag(bool abort) { Q_Q(QDockWidget); @@ -736,29 +783,31 @@ void QDockWidgetPrivate::endDrag(bool abort) q->releaseMouse(); if (state->dragging) { - QMainWindowLayout *mwLayout = qt_mainwindow_layout(qobject_cast<QMainWindow *>(q->parentWidget())); + QMainWindowLayout *mwLayout = qt_mainwindow_layout_from_dock(q); Q_ASSERT(mwLayout != 0); if (abort || !mwLayout->plug(state->widgetItem)) { if (hasFeature(this, QDockWidget::DockWidgetFloatable)) { + // This QDockWidget will now stay in the floating state. if (state->ownWidgetItem) delete state->widgetItem; mwLayout->restore(); - if (isXcb()) { + QDockWidgetLayout *dwLayout = qobject_cast<QDockWidgetLayout*>(layout); + if (!dwLayout->nativeWindowDeco()) { // get rid of the X11BypassWindowManager window flag and activate the resizer Qt::WindowFlags flags = q->windowFlags(); flags &= ~Qt::X11BypassWindowManagerHint; q->setWindowFlags(flags); - setResizerActive(true); + setResizerActive(q->isFloating()); q->show(); } else { - QDockWidgetLayout *myLayout - = qobject_cast<QDockWidgetLayout*>(layout); - setResizerActive(myLayout->widgetForRole(QDockWidgetLayout::TitleBar) != 0); + setResizerActive(false); } undockedGeometry = q->geometry(); q->activateWindow(); } else { + // The tab was not plugged back in the QMainWindow but the QDockWidget cannot + // stay floating, revert to the previous state. mwLayout->revert(state->widgetItem); } } @@ -782,11 +831,7 @@ bool QDockWidgetPrivate::isAnimating() const { Q_Q(const QDockWidget); - QMainWindow *mainWin = qobject_cast<QMainWindow*>(parent); - if (mainWin == 0) - return false; - - QMainWindowLayout *mainWinLayout = qt_mainwindow_layout(mainWin); + QMainWindowLayout *mainWinLayout = qt_mainwindow_layout_from_dock(q); if (mainWinLayout == 0) return false; @@ -804,12 +849,14 @@ bool QDockWidgetPrivate::mousePressEvent(QMouseEvent *event) if (!dwLayout->nativeWindowDeco()) { QRect titleArea = dwLayout->titleArea(); + QDockWidgetGroupWindow *floatingTab = qobject_cast<QDockWidgetGroupWindow*>(parent); + if (event->button() != Qt::LeftButton || !titleArea.contains(event->pos()) || // check if the tool window is movable... do nothing if it // is not (but allow moving if the window is floating) (!hasFeature(this, QDockWidget::DockWidgetMovable) && !q->isFloating()) || - qobject_cast<QMainWindow*>(parent) == 0 || + (qobject_cast<QMainWindow*>(parent) == 0 && !floatingTab) || isAnimating() || state != 0) { return false; } @@ -853,7 +900,7 @@ bool QDockWidgetPrivate::mouseMoveEvent(QMouseEvent *event) QDockWidgetLayout *dwlayout = qobject_cast<QDockWidgetLayout *>(layout); - QMainWindowLayout *mwlayout = qt_mainwindow_layout(qobject_cast<QMainWindow *>(q->parentWidget())); + QMainWindowLayout *mwlayout = qt_mainwindow_layout_from_dock(q); if (!dwlayout->nativeWindowDeco()) { if (!state->dragging && mwlayout->pluggingWidget == 0 @@ -871,7 +918,12 @@ bool QDockWidgetPrivate::mouseMoveEvent(QMouseEvent *event) if (state->dragging && !state->nca) { QPoint pos = event->globalPos() - state->pressPos; - q->move(pos); + + QDockWidgetGroupWindow *floatingTab = qobject_cast<QDockWidgetGroupWindow*>(parent); + if (floatingTab && !q->isFloating()) + floatingTab->move(pos); + else + q->move(pos); if (state && !state->ctrlDrag) mwlayout->hover(state->widgetItem, event->globalPos()); @@ -902,8 +954,9 @@ void QDockWidgetPrivate::nonClientAreaMouseEvent(QMouseEvent *event) int fw = q->style()->pixelMetric(QStyle::PM_DockWidgetFrameWidth, 0, q); - QRect geo = q->geometry(); - QRect titleRect = q->frameGeometry(); + QWidget *tl = q->topLevelWidget(); + QRect geo = tl->geometry(); + QRect titleRect = tl->frameGeometry(); #ifdef Q_DEAD_CODE_FROM_QT4_MAC if ((features & QDockWidget::DockWidgetVerticalTitleBar)) { titleRect.setTop(geo.top()); @@ -924,7 +977,7 @@ void QDockWidgetPrivate::nonClientAreaMouseEvent(QMouseEvent *event) break; if (state != 0) break; - if (qobject_cast<QMainWindow*>(parent) == 0) + if (qobject_cast<QMainWindow*>(parent) == 0 && qobject_cast<QDockWidgetGroupWindow*>(parent) == 0) break; if (isAnimating()) break; @@ -958,11 +1011,17 @@ void QDockWidgetPrivate::nonClientAreaMouseEvent(QMouseEvent *event) } } +/*! \internal + Called when the QDockWidget or the QDockWidgetGroupWindow is moved + */ void QDockWidgetPrivate::moveEvent(QMoveEvent *event) { Q_Q(QDockWidget); - if (state == 0 || !state->dragging || !state->nca || !q->isWindow()) + if (state == 0 || !state->dragging || !state->nca) + return; + + if (!q->isWindow() && qobject_cast<QDockWidgetGroupWindow*>(parent) == 0) return; // When the native window frame is being dragged, all we get is these mouse @@ -971,7 +1030,7 @@ void QDockWidgetPrivate::moveEvent(QMoveEvent *event) if (state->ctrlDrag) return; - QMainWindowLayout *layout = qt_mainwindow_layout(qobject_cast<QMainWindow *>(q->parentWidget())); + QMainWindowLayout *layout = qt_mainwindow_layout_from_dock(q); Q_ASSERT(layout != 0); QPoint globalMousePos = event->pos() + state->pressPos; @@ -999,8 +1058,9 @@ void QDockWidgetPrivate::setWindowState(bool floating, bool unplug, const QRect Q_Q(QDockWidget); if (!floating && parent) { - QMainWindowLayout *mwlayout = qt_mainwindow_layout(qobject_cast<QMainWindow *>(q->parentWidget())); - if (mwlayout && mwlayout->dockWidgetArea(q) == Qt::NoDockWidgetArea) + QMainWindowLayout *mwlayout = qt_mainwindow_layout_from_dock(q); + if (mwlayout && mwlayout->dockWidgetArea(q) == Qt::NoDockWidgetArea + && !qobject_cast<QDockWidgetGroupWindow *>(parent)) return; // this dockwidget can't be redocked } @@ -1048,7 +1108,7 @@ void QDockWidgetPrivate::setWindowState(bool floating, bool unplug, const QRect if (floating != wasFloating) { emit q->topLevelChanged(floating); if (!floating && parent) { - QMainWindowLayout *mwlayout = qt_mainwindow_layout(qobject_cast<QMainWindow *>(q->parentWidget())); + QMainWindowLayout *mwlayout = qt_mainwindow_layout_from_dock(q); if (mwlayout) emit q->dockLocationChanged(mwlayout->dockWidgetArea(q)); } @@ -1230,8 +1290,11 @@ void QDockWidget::setFeatures(QDockWidget::DockWidgetFeatures features) emit featuresChanged(d->features); update(); if (closableChanged && layout->nativeWindowDeco()) { - //this ensures the native decoration is drawn - d->setWindowState(true /*floating*/, true /*unplug*/); + QDockWidgetGroupWindow *floatingTab = qobject_cast<QDockWidgetGroupWindow *>(parent()); + if (floatingTab && !isFloating()) + floatingTab->adjustFlags(); + else + d->setWindowState(true /*floating*/, true /*unplug*/); //this ensures the native decoration is drawn } } @@ -1323,11 +1386,12 @@ void QDockWidget::changeEvent(QEvent *event) #endif #ifndef QT_NO_TABBAR { - QMainWindow *win = qobject_cast<QMainWindow*>(parentWidget()); - if (QMainWindowLayout *winLayout = qt_mainwindow_layout(win)) { + if (QMainWindowLayout *winLayout = qt_mainwindow_layout_from_dock(this)) { if (QDockAreaLayoutInfo *info = winLayout->layoutState.dockAreaLayout.info(this)) info->updateTabBar(); } + if (QDockWidgetGroupWindow *p = qobject_cast<QDockWidgetGroupWindow *>(parent())) + p->adjustFlags(); } #endif // QT_NO_TABBAR break; @@ -1380,7 +1444,7 @@ bool QDockWidget::event(QEvent *event) Q_D(QDockWidget); QMainWindow *win = qobject_cast<QMainWindow*>(parentWidget()); - QMainWindowLayout *layout = qt_mainwindow_layout(win); + QMainWindowLayout *layout = qt_mainwindow_layout_from_dock(this); switch (event->type()) { #ifndef QT_NO_ACTION @@ -1417,6 +1481,9 @@ bool QDockWidget::event(QEvent *event) } if (!isFloating() && layout != 0 && onTop) layout->raise(this); + if (QDockWidgetGroupWindow *p = qobject_cast<QDockWidgetGroupWindow *>(parent())) + p->adjustFlags(); + break; } case QEvent::WindowActivate: diff --git a/src/widgets/widgets/qdockwidget_p.h b/src/widgets/widgets/qdockwidget_p.h index 752d6519e5..9c68bc5fb1 100644 --- a/src/widgets/widgets/qdockwidget_p.h +++ b/src/widgets/widgets/qdockwidget_p.h @@ -108,7 +108,7 @@ public: void setWindowState(bool floating, bool unplug = false, const QRect &rect = QRect()); void nonClientAreaMouseEvent(QMouseEvent *event); void initDrag(const QPoint &pos, bool nca); - void startDrag(); + void startDrag(bool group = true); void endDrag(bool abort = false); void moveEvent(QMoveEvent *event); @@ -151,6 +151,7 @@ public: int minimumTitleWidth() const; int titleHeight() const; void updateMaxSize(); + static bool wmSupportsNativeWindowDeco(); bool nativeWindowDeco() const; bool nativeWindowDeco(bool floating) const; diff --git a/src/widgets/widgets/qframe.cpp b/src/widgets/widgets/qframe.cpp index 0861ea70b5..755b03a4ca 100644 --- a/src/widgets/widgets/qframe.cpp +++ b/src/widgets/widgets/qframe.cpp @@ -45,7 +45,7 @@ QT_BEGIN_NAMESPACE QFramePrivate::QFramePrivate() - : frect(QRect(0, 0, 0, 0)), + : frect(0, 0, 0, 0), frameStyle(QFrame::NoFrame | QFrame::Plain), lineWidth(1), midLineWidth(0), @@ -55,6 +55,10 @@ QFramePrivate::QFramePrivate() { } +QFramePrivate::~QFramePrivate() +{ +} + inline void QFramePrivate::init() { setLayoutItemMargins(QStyle::SE_FrameLayoutItem); diff --git a/src/widgets/widgets/qframe_p.h b/src/widgets/widgets/qframe_p.h index 2b80e9abbe..eb04bbed4a 100644 --- a/src/widgets/widgets/qframe_p.h +++ b/src/widgets/widgets/qframe_p.h @@ -50,11 +50,13 @@ QT_BEGIN_NAMESPACE -class QFramePrivate : public QWidgetPrivate +// ### unexport this class when and if QAbstractScrollAreaPrivate is unexported +class Q_WIDGETS_EXPORT QFramePrivate : public QWidgetPrivate { Q_DECLARE_PUBLIC(QFrame) public: QFramePrivate(); + ~QFramePrivate(); void updateFrameWidth(); void updateStyledFrameWidths(); diff --git a/src/widgets/widgets/qlabel.cpp b/src/widgets/widgets/qlabel.cpp index 83e94c4128..409e4a34f9 100644 --- a/src/widgets/widgets/qlabel.cpp +++ b/src/widgets/widgets/qlabel.cpp @@ -53,6 +53,10 @@ QT_BEGIN_NAMESPACE +QLabelPrivate::~QLabelPrivate() +{ +} + /*! \class QLabel \brief The QLabel widget provides a text or image display. diff --git a/src/widgets/widgets/qlabel_p.h b/src/widgets/widgets/qlabel_p.h index 3778cb9d47..2eb4ff9fc6 100644 --- a/src/widgets/widgets/qlabel_p.h +++ b/src/widgets/widgets/qlabel_p.h @@ -65,6 +65,7 @@ class QLabelPrivate : public QFramePrivate Q_DECLARE_PUBLIC(QLabel) public: QLabelPrivate() {} + ~QLabelPrivate(); void init(); void clearContents(); diff --git a/src/widgets/widgets/qmainwindow.cpp b/src/widgets/widgets/qmainwindow.cpp index 4d5d3e5ec1..935177867d 100644 --- a/src/widgets/widgets/qmainwindow.cpp +++ b/src/widgets/widgets/qmainwindow.cpp @@ -420,6 +420,13 @@ QMainWindow::~QMainWindow() at the bottom. Implies AllowTabbedDocks. See also \l setTabPosition(). + \value GroupedDragging When dragging the titlebar of a dock, all the tabs + that are tabbed with it are going to be dragged. + Implies AllowTabbedDocks. Does not work well if + some QDockWidgets have restrictions in which area + they are allowed. (This enum value was added in Qt + 5.6.) + These options only control how dock widgets may be dropped in a QMainWindow. They do not re-arrange the dock widgets to conform with the specified options. For this reason they should be set before any dock widgets @@ -1080,7 +1087,7 @@ void QMainWindow::addDockWidget(Qt::DockWidgetArea area, QDockWidget *dockwidget addDockWidget(area, dockwidget, orientation); #ifdef Q_DEAD_CODE_FROM_QT4_MAC //drawer support - QMacCocoaAutoReleasePool pool; + QMacAutoReleasePool pool; extern bool qt_mac_is_macdrawer(const QWidget *); //qwidget_mac.cpp if (qt_mac_is_macdrawer(dockwidget)) { extern bool qt_mac_set_drawer_preferred_edge(QWidget *, Qt::DockWidgetArea); //qwidget_mac.cpp diff --git a/src/widgets/widgets/qmainwindow.h b/src/widgets/widgets/qmainwindow.h index cbbea74b9b..0bd70c87a6 100644 --- a/src/widgets/widgets/qmainwindow.h +++ b/src/widgets/widgets/qmainwindow.h @@ -77,7 +77,8 @@ public: AllowNestedDocks = 0x02, AllowTabbedDocks = 0x04, ForceTabbedDocks = 0x08, // implies AllowTabbedDocks, !AllowNestedDocks - VerticalTabs = 0x10 // implies AllowTabbedDocks + VerticalTabs = 0x10, // implies AllowTabbedDocks + GroupedDragging = 0x20 // implies AllowTabbedDocks }; Q_ENUM(DockOption) Q_DECLARE_FLAGS(DockOptions, DockOption) diff --git a/src/widgets/widgets/qmainwindowlayout.cpp b/src/widgets/widgets/qmainwindowlayout.cpp index 046666f571..ee76720a27 100644 --- a/src/widgets/widgets/qmainwindowlayout.cpp +++ b/src/widgets/widgets/qmainwindowlayout.cpp @@ -1,6 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2015 Olivier Goffart <ogoffart@woboq.com> ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtWidgets module of the Qt Toolkit. @@ -49,6 +50,7 @@ #include <qstatusbar.h> #include <qstring.h> #include <qstyle.h> +#include <qstylepainter.h> #include <qvarlengtharray.h> #include <qstack.h> #include <qmap.h> @@ -61,6 +63,7 @@ #include <private/qapplication_p.h> #include <private/qlayoutengine_p.h> +#include <private/qwidgetresizehandler_p.h> #ifdef Q_DEAD_CODE_FROM_QT4_MAC # include <private/qcore_mac_p.h> # include <private/qt_cocoa_helpers_mac_p.h> @@ -68,9 +71,7 @@ QT_BEGIN_NAMESPACE -#ifdef QT_NO_DOCKWIDGET extern QMainWindowLayout *qt_mainwindow_layout(const QMainWindow *window); -#endif /****************************************************************************** ** debug @@ -165,6 +166,242 @@ QDebug operator<<(QDebug debug, const QMainWindowLayout *layout) #endif // !defined(QT_NO_DOCKWIDGET) && !defined(QT_NO_DEBUG) /****************************************************************************** + ** QDockWidgetGroupWindow + */ +// QDockWidgetGroupWindow is the floating window containing the tabbed dockwidgets in case several +// dockwidgets are dragged together (QMainWindow::GroupedDragging feature). +// QDockWidgetGroupLayout is the layout of that window and use a QDockAreaLayoutInfo to layout +// the tabs inside it. +#ifndef QT_NO_DOCKWIDGET +class QDockWidgetGroupLayout : public QLayout { + QDockAreaLayoutInfo info; + QWidgetResizeHandler *resizer; +public: + QDockWidgetGroupLayout(QWidget* parent) : QLayout(parent) { + setSizeConstraint(QLayout::SetMinAndMaxSize); + resizer = new QWidgetResizeHandler(parent); + resizer->setMovingEnabled(false); + } + ~QDockWidgetGroupLayout() { + info.deleteAllLayoutItems(); + } + + void addItem(QLayoutItem*) Q_DECL_OVERRIDE { Q_UNREACHABLE(); } + int count() const Q_DECL_OVERRIDE { return 0; } + QLayoutItem* itemAt(int index) const Q_DECL_OVERRIDE + { + int x = 0; + return info.itemAt(&x, index); + } + QLayoutItem* takeAt(int index) Q_DECL_OVERRIDE + { + int x = 0; + return info.takeAt(&x, index); + } + QSize sizeHint() const Q_DECL_OVERRIDE + { + int fw = frameWidth(); + return info.sizeHint() + QSize(fw, fw); + } + QSize minimumSize() const Q_DECL_OVERRIDE + { + int fw = frameWidth(); + return info.minimumSize() + QSize(fw, fw); + } + QSize maximumSize() const Q_DECL_OVERRIDE + { + int fw = frameWidth(); + return info.maximumSize() + QSize(fw, fw); + } + void setGeometry(const QRect&r) Q_DECL_OVERRIDE + { + QDockAreaLayoutInfo *li = layoutInfo(); + if (li->isEmpty()) { + static_cast<QDockWidgetGroupWindow *>(parent())->destroyIfEmpty(); + return; + } + int fw = frameWidth(); + li->reparentWidgets(parentWidget()); + li->rect = r.adjusted(fw, fw, -fw, -fw); + li->fitItems(); + li->apply(false); + resizer->setActive(QWidgetResizeHandler::Resize, !nativeWindowDeco()); + } + + QDockAreaLayoutInfo *layoutInfo() { + return &info; + } + + bool nativeWindowDeco() const + { + return QDockWidgetLayout::wmSupportsNativeWindowDeco(); + } + + int frameWidth() const + { + return nativeWindowDeco() ? 0 : + parentWidget()->style()->pixelMetric(QStyle::PM_DockWidgetFrameWidth, 0, parentWidget()); + } +}; + +// This item will be used in the layout for the gap item. We cannot use QWidgetItem directly +// because QWidgetItem functions return an empty size for widgets are are floating. +class QDockWidgetGroupWindowItem : public QWidgetItem +{ +public: + QDockWidgetGroupWindowItem(QDockWidgetGroupWindow *parent) : QWidgetItem(parent) {} + QSize minimumSize() const Q_DECL_OVERRIDE { return lay()->minimumSize(); } + QSize maximumSize() const Q_DECL_OVERRIDE { return lay()->maximumSize(); } + QSize sizeHint() const Q_DECL_OVERRIDE { return lay()->sizeHint(); } + +private: + QLayout *lay() const { return const_cast<QDockWidgetGroupWindowItem *>(this)->widget()->layout(); } +}; + +bool QDockWidgetGroupWindow::event(QEvent *e) +{ + switch (e->type()) { + case QEvent::Close: + // Forward the close to the QDockWidget just as if its close button was pressed + if (QDockWidget *dw = topDockWidget()) { + e->ignore(); + dw->close(); + adjustFlags(); + } + return true; + case QEvent::Move: + // Let QDockWidgetPrivate::moseEvent handle the dragging + if (QDockWidget *dw = topDockWidget()) + static_cast<QDockWidgetPrivate *>(QObjectPrivate::get(dw))->moveEvent(static_cast<QMoveEvent*>(e)); + return true; + case QEvent::NonClientAreaMouseMove: + case QEvent::NonClientAreaMouseButtonPress: + case QEvent::NonClientAreaMouseButtonRelease: + case QEvent::NonClientAreaMouseButtonDblClick: + // Let the QDockWidgetPrivate of the currently visible dock widget handle the drag and drop + if (QDockWidget *dw = topDockWidget()) + static_cast<QDockWidgetPrivate *>(QObjectPrivate::get(dw))->nonClientAreaMouseEvent(static_cast<QMouseEvent*>(e)); + return true; + case QEvent::ChildAdded: + if (qobject_cast<QDockWidget *>(static_cast<QChildEvent*>(e)->child())) + adjustFlags(); + break; + default: + break; + } + return QWidget::event(e); +} + +void QDockWidgetGroupWindow::paintEvent(QPaintEvent *) +{ + QDockWidgetGroupLayout *lay = static_cast<QDockWidgetGroupLayout *>(layout()); + bool nativeDeco = lay->nativeWindowDeco(); + + if (!nativeDeco) { + QStyleOptionFrame framOpt; + framOpt.init(this); + QStylePainter p(this); + p.drawPrimitive(QStyle::PE_FrameDockWidget, framOpt); + } +} + +QDockAreaLayoutInfo *QDockWidgetGroupWindow::layoutInfo() const +{ + return static_cast<QDockWidgetGroupLayout*>(layout())->layoutInfo(); +} + +/*! \internal + Returns the currently active QDockWidget. + */ +QDockWidget *QDockWidgetGroupWindow::topDockWidget() const +{ + QDockAreaLayoutInfo *info = layoutInfo(); + QDockWidget *dw = 0; + if (info->tabBar && info->tabBar->currentIndex() >= 0) { + int i = info->tabIndexToListIndex(info->tabBar->currentIndex()); + if (i >= 0) { + const QDockAreaLayoutItem &item = info->item_list.at(i); + if (item.widgetItem) + dw = qobject_cast<QDockWidget *>(item.widgetItem->widget()); + } + } + if (!dw) { + for (int i = 0; !dw && i < info->item_list.count(); ++i) { + const QDockAreaLayoutItem &item = info->item_list.at(i); + if (item.skip()) + continue; + if (!item.widgetItem) + continue; + dw = qobject_cast<QDockWidget *>(item.widgetItem->widget()); + } + } + return dw; +} + +/*! \internal + Destroy this window if there is no more QDockWidget in it. + */ +void QDockWidgetGroupWindow::destroyIfEmpty() +{ + if (layoutInfo()->isEmpty()) { + // Make sure to reparent the possibly floating or hidden QDockWidgets to the parent + foreach (QDockWidget *dw, + findChildren<QDockWidget *>(QString(), Qt::FindDirectChildrenOnly)) { + bool wasFloating = dw->isFloating(); + bool wasHidden = dw->isHidden(); + dw->setParent(parentWidget()); + if (wasFloating) { + dw->setFloating(true); + } else { + // maybe it was hidden, we still have to put it back in the main layout. + QMainWindowLayout *ml = qt_mainwindow_layout(static_cast<QMainWindow*>(parentWidget())); + Qt::DockWidgetArea area = ml->dockWidgetArea(this); + if (area == Qt::NoDockWidgetArea) + area = Qt::LeftDockWidgetArea; + static_cast<QMainWindow*>(parentWidget())->addDockWidget(area, dw); + } + if (!wasHidden) + dw->show(); + } + foreach (QTabBar *tb, findChildren<QTabBar *>(QString(), Qt::FindDirectChildrenOnly)) + tb->setParent(parentWidget()); + deleteLater(); + } +} + +/*! \internal + Sets the flags of this window in accordence to the capabilities of the dock widgets + */ +void QDockWidgetGroupWindow::adjustFlags() +{ + QDockWidget *top = topDockWidget(); + if (!top) + return; + const bool nativeDeco = static_cast<QDockWidgetGroupLayout *>(layout())->nativeWindowDeco(); + + Qt::WindowFlags oldFlags = windowFlags(); + Qt::WindowFlags flags = oldFlags; + if (nativeDeco) { + flags |= Qt::CustomizeWindowHint | Qt::WindowTitleHint; + if (top->features() & QDockWidget::DockWidgetClosable) + flags |= Qt::WindowCloseButtonHint; + else + flags &= ~Qt::WindowCloseButtonHint; + flags &= ~Qt::FramelessWindowHint; + } else { + flags |= Qt::FramelessWindowHint; + } + if (oldFlags != flags) { + setWindowFlags(flags); + show(); // setWindowFlags hides the window + } + + setWindowTitle(top->windowTitle()); + setWindowIcon(top->windowIcon()); +} +#endif + +/****************************************************************************** ** QMainWindowLayoutState */ @@ -335,8 +572,8 @@ QList<int> QMainWindowLayoutState::indexOf(QWidget *widget) const #ifndef QT_NO_DOCKWIDGET // is it a dock widget? - if (QDockWidget *dockWidget = qobject_cast<QDockWidget *>(widget)) { - result = dockAreaLayout.indexOf(dockWidget); + if (qobject_cast<QDockWidget *>(widget) || qobject_cast<QDockWidgetGroupWindow *>(widget)) { + result = dockAreaLayout.indexOf(widget); if (!result.isEmpty()) result.prepend(1); return result; @@ -413,7 +650,8 @@ QList<int> QMainWindowLayoutState::gapIndex(QWidget *widget, #ifndef QT_NO_DOCKWIDGET // is it a dock widget? - if (qobject_cast<QDockWidget *>(widget) != 0) { + if (qobject_cast<QDockWidget *>(widget) != 0 + || qobject_cast<QDockWidgetGroupWindow *>(widget)) { result = dockAreaLayout.gapIndex(pos); if (!result.isEmpty()) result.prepend(1); @@ -440,7 +678,7 @@ bool QMainWindowLayoutState::insertGap(const QList<int> &path, QLayoutItem *item #ifndef QT_NO_DOCKWIDGET if (i == 1) { - Q_ASSERT(qobject_cast<QDockWidget*>(item->widget()) != 0); + Q_ASSERT(qobject_cast<QDockWidget*>(item->widget()) || qobject_cast<QDockWidgetGroupWindow*>(item->widget())); return dockAreaLayout.insertGap(path.mid(1), item); } #endif //QT_NO_DOCKWIDGET @@ -593,6 +831,17 @@ void QMainWindowLayoutState::saveState(QDataStream &stream) const { #ifndef QT_NO_DOCKWIDGET dockAreaLayout.saveState(stream); +#ifndef QT_NO_TABBAR + QList<QDockWidgetGroupWindow *> floatingTabs = + mainWindow->findChildren<QDockWidgetGroupWindow *>(QString(), Qt::FindDirectChildrenOnly); + + foreach (QDockWidgetGroupWindow *floating, floatingTabs) { + if (floating->layoutInfo()->isEmpty()) + continue; + stream << uchar(QDockAreaLayout::FloatingDockWidgetTabMarker) << floating->geometry(); + floating->layoutInfo()->saveState(stream); + } +#endif #endif #ifndef QT_NO_TOOLBAR toolBarAreaLayout.saveState(stream); @@ -638,12 +887,28 @@ bool QMainWindowLayoutState::checkFormat(QDataStream &stream) case QDockAreaLayout::DockWidgetStateMarker: { QList<QDockWidget *> dockWidgets = findChildrenHelper<QDockWidget*>(mainWindow); + foreach (QDockWidgetGroupWindow *floating, findChildrenHelper<QDockWidgetGroupWindow*>(mainWindow)) + dockWidgets += findChildrenHelper<QDockWidget*>(floating); if (!dockAreaLayout.restoreState(stream, dockWidgets, true /*testing*/)) { return false; } } break; -#endif +#ifndef QT_NO_TABBAR + case QDockAreaLayout::FloatingDockWidgetTabMarker: + { + QRect geom; + stream >> geom; + QDockAreaLayoutInfo info; + QList<QDockWidget *> dockWidgets = findChildrenHelper<QDockWidget*>(mainWindow); + foreach (QDockWidgetGroupWindow *floating, findChildrenHelper<QDockWidgetGroupWindow*>(mainWindow)) + dockWidgets += findChildrenHelper<QDockWidget*>(floating); + if (!info.restoreState(stream, dockWidgets, true /* testing*/)) + return false; + } + break; +#endif // QT_NO_TABBAR +#endif // QT_NO_DOCKWIDGET default: //there was an error during the parsing return false; @@ -682,6 +947,8 @@ bool QMainWindowLayoutState::restoreState(QDataStream &_stream, case QDockAreaLayout::DockWidgetStateMarker: { QList<QDockWidget *> dockWidgets = findChildrenHelper<QDockWidget*>(mainWindow); + foreach (QDockWidgetGroupWindow *floating, findChildrenHelper<QDockWidgetGroupWindow*>(mainWindow)) + dockWidgets += findChildrenHelper<QDockWidget*>(floating); if (!dockAreaLayout.restoreState(stream, dockWidgets)) return false; @@ -702,6 +969,26 @@ bool QMainWindowLayoutState::restoreState(QDataStream &_stream, } } break; +#ifndef QT_NO_TABBAR + case QDockAreaLayout::FloatingDockWidgetTabMarker: + { + QList<QDockWidget *> dockWidgets = findChildrenHelper<QDockWidget*>(mainWindow); + foreach (QDockWidgetGroupWindow *floating, findChildrenHelper<QDockWidgetGroupWindow*>(mainWindow)) + dockWidgets += findChildrenHelper<QDockWidget*>(floating); + QDockWidgetGroupWindow* floatingTab = qt_mainwindow_layout(mainWindow)->createTabbedDockWindow(); + *floatingTab->layoutInfo() = QDockAreaLayoutInfo(&dockAreaLayout.sep, QInternal::LeftDock, + Qt::Horizontal, QTabBar::RoundedSouth, mainWindow); + QRect geometry; + stream >> geometry; + if (!floatingTab->layoutInfo()->restoreState(stream, dockWidgets, false)) + return false; + geometry = QDockAreaLayout::constrainedRect(geometry, floatingTab); + floatingTab->move(geometry.topLeft()); + floatingTab->resize(geometry.size()); + floatingTab->show(); + } + break; +#endif // QT_NO_TABBAR #endif // QT_NO_DOCKWIDGET #ifndef QT_NO_TOOLBAR @@ -1223,7 +1510,7 @@ void QMainWindowLayout::splitDockWidget(QDockWidget *after, invalidate(); } -Qt::DockWidgetArea QMainWindowLayout::dockWidgetArea(QDockWidget *widget) const +Qt::DockWidgetArea QMainWindowLayout::dockWidgetArea(QWidget *widget) const { QList<int> pathToWidget = layoutState.dockAreaLayout.indexOf(widget); if (pathToWidget.isEmpty()) @@ -1238,20 +1525,88 @@ void QMainWindowLayout::keepSize(QDockWidget *w) #ifndef QT_NO_TABBAR +// Handle custom tooltip, and allow to drag tabs away. class QMainWindowTabBar : public QTabBar { + QMainWindow *mainWindow; + QDockWidget *draggingDock; // Currently dragging (detached) dock widget public: - QMainWindowTabBar(QWidget *parent); + QMainWindowTabBar(QMainWindow *parent); protected: bool event(QEvent *e) Q_DECL_OVERRIDE; + void mouseReleaseEvent(QMouseEvent*) Q_DECL_OVERRIDE; + void mouseMoveEvent(QMouseEvent*) Q_DECL_OVERRIDE; + }; -QMainWindowTabBar::QMainWindowTabBar(QWidget *parent) - : QTabBar(parent) +QMainWindowTabBar::QMainWindowTabBar(QMainWindow *parent) + : QTabBar(parent), mainWindow(parent), draggingDock(0) { setExpanding(false); } +void QMainWindowTabBar::mouseMoveEvent(QMouseEvent *e) +{ + // The QTabBar handles the moving (reordering) of tabs. + // When QTabBarPrivate::dragInProgress is true, and that the mouse is outside of a region + // around the QTabBar, we will consider the user wants to drag that QDockWidget away from this + // tab area. + + QTabBarPrivate *d = static_cast<QTabBarPrivate*>(d_ptr.data()); + if (!draggingDock && (mainWindow->dockOptions() & QMainWindow::GroupedDragging)) { + int offset = QApplication::startDragDistance() + 1; + offset *= 3; + QRect r = rect().adjusted(-offset, -offset, offset, offset); + if (d->dragInProgress && !r.contains(e->pos()) && d->validIndex(d->pressedIndex)) { + QMainWindowLayout* mlayout = qt_mainwindow_layout(mainWindow); + QDockAreaLayoutInfo *info = mlayout->dockInfo(this); + Q_ASSERT(info); + int idx = info->tabIndexToListIndex(d->pressedIndex); + const QDockAreaLayoutItem &item = info->item_list.at(idx); + if (item.widgetItem + && (draggingDock = qobject_cast<QDockWidget *>(item.widgetItem->widget()))) { + // We should drag this QDockWidget away by unpluging it. + // First cancel the QTabBar's internal move + d->moveTabFinished(d->pressedIndex); + d->pressedIndex = -1; + if (d->movingTab) + d->movingTab->setVisible(false); + d->dragStartPosition = QPoint(); + + // Then starts the drag using QDockWidgetPrivate's API + QDockWidgetPrivate *dockPriv = static_cast<QDockWidgetPrivate *>(QObjectPrivate::get(draggingDock)); + QDockWidgetLayout *dwlayout = static_cast<QDockWidgetLayout *>(draggingDock->layout()); + dockPriv->initDrag(dwlayout->titleArea().center(), true); + dockPriv->startDrag(false); + if (dockPriv->state) + dockPriv->state->ctrlDrag = e->modifiers() & Qt::ControlModifier; + } + } + } + + if (draggingDock) { + QDockWidgetPrivate *dockPriv = static_cast<QDockWidgetPrivate *>(QObjectPrivate::get(draggingDock)); + if (dockPriv->state && dockPriv->state->dragging) { + QPoint pos = e->globalPos() - dockPriv->state->pressPos; + draggingDock->move(pos); + // move will call QMainWindowLayout::hover + } + } + QTabBar::mouseMoveEvent(e); +} + +void QMainWindowTabBar::mouseReleaseEvent(QMouseEvent *e) +{ + if (draggingDock && e->button() == Qt::LeftButton) { + QDockWidgetPrivate *dockPriv = static_cast<QDockWidgetPrivate *>(QObjectPrivate::get(draggingDock)); + if (dockPriv->state && dockPriv->state->dragging) { + dockPriv->endDrag(); + } + draggingDock = 0; + } + QTabBar::mouseReleaseEvent(e); +} + bool QMainWindowTabBar::event(QEvent *e) { // show the tooltip if tab is too small to fit label @@ -1276,11 +1631,13 @@ QTabBar *QMainWindowLayout::getTabBar() if (!unusedTabBars.isEmpty()) { result = unusedTabBars.takeLast(); } else { - result = new QMainWindowTabBar(parentWidget()); + result = new QMainWindowTabBar(static_cast<QMainWindow *>(parentWidget())); result->setDrawBase(true); result->setElideMode(Qt::ElideRight); result->setDocumentMode(_documentMode); + result->setMovable(true); connect(result, SIGNAL(currentChanged(int)), this, SLOT(tabChanged())); + connect(result, &QTabBar::tabMoved, this, &QMainWindowLayout::tabMoved); } usedTabBars.insert(result); @@ -1303,12 +1660,30 @@ QWidget *QMainWindowLayout::getSeparatorWidget() return result; } +/*! \internal + Returns a pointer QDockAreaLayoutInfo which contains this \a widget directly + (in its internal list) + */ +QDockAreaLayoutInfo *QMainWindowLayout::dockInfo(QWidget *widget) +{ + QDockAreaLayoutInfo *info = layoutState.dockAreaLayout.info(widget); + if (info) + return info; + foreach (QDockWidgetGroupWindow *dwgw, + parent()->findChildren<QDockWidgetGroupWindow*>(QString(), Qt::FindDirectChildrenOnly)) { + info = dwgw->layoutInfo()->info(widget); + if (info) + return info; + } + return 0; +} + void QMainWindowLayout::tabChanged() { QTabBar *tb = qobject_cast<QTabBar*>(sender()); if (tb == 0) return; - QDockAreaLayoutInfo *info = layoutState.dockAreaLayout.info(tb); + QDockAreaLayoutInfo *info = dockInfo(tb); if (info == 0) return; info->apply(false); @@ -1316,6 +1691,16 @@ void QMainWindowLayout::tabChanged() if (QWidget *w = centralWidget()) w->raise(); } + +void QMainWindowLayout::tabMoved(int from, int to) +{ + QTabBar *tb = qobject_cast<QTabBar*>(sender()); + Q_ASSERT(tb); + QDockAreaLayoutInfo *info = dockInfo(tb); + Q_ASSERT(info); + + info->moveTab(from, to); +} #endif // QT_NO_TABBAR bool QMainWindowLayout::startSeparatorMove(const QPoint &pos) @@ -1353,7 +1738,7 @@ bool QMainWindowLayout::endSeparatorMove(const QPoint&) void QMainWindowLayout::raise(QDockWidget *widget) { - QDockAreaLayoutInfo *info = layoutState.dockAreaLayout.info(widget); + QDockAreaLayoutInfo *info = dockInfo(widget); if (info == 0) return; #ifndef QT_NO_TABBAR @@ -1537,6 +1922,8 @@ void QMainWindowLayout::revert(QLayoutItem *widgetItem) QWidget *widget = widgetItem->widget(); layoutState = savedState; currentGapPos = layoutState.indexOf(widget); + if (currentGapPos.isEmpty()) + return; fixToolBarOrientation(widgetItem, currentGapPos.at(1)); layoutState.unplug(currentGapPos); layoutState.fitLayout(); @@ -1601,6 +1988,42 @@ void QMainWindowLayout::animationFinished(QWidget *widget) if (widget == pluggingWidget) { #ifndef QT_NO_DOCKWIDGET + if (QDockWidgetGroupWindow *dwgw = qobject_cast<QDockWidgetGroupWindow *>(widget)) { + // When the animated widget was a QDockWidgetGroupWindow, it means each of the + // embedded QDockWidget needs to be plugged back into the QMainWindow layout. + savedState.clear(); + QDockAreaLayoutInfo* info = dwgw->layoutInfo(); + QList<int> path = layoutState.dockAreaLayout.indexOf(widget); + Q_ASSERT(path.size() >= 2); + + QDockAreaLayoutInfo* parentInfo = layoutState.dockAreaLayout.info(path); + Q_ASSERT(parentInfo); + if (parentInfo->tabbed) { + // merge the two tab widgets + int idx = path.last(); + Q_ASSERT(parentInfo->item_list[idx].widgetItem->widget() == dwgw); + delete parentInfo->item_list[idx].widgetItem; + parentInfo->item_list.removeAt(idx); + std::copy(info->item_list.cbegin(), info->item_list.cend(), + std::inserter(parentInfo->item_list, parentInfo->item_list.begin() + idx)); + quintptr currentId = info->currentTabId(); + *info = QDockAreaLayoutInfo(); + parentInfo->reparentWidgets(parentWidget()); + parentInfo->updateTabBar(); + parentInfo->setCurrentTabId(currentId); + } else { + QDockAreaLayoutItem &item = layoutState.dockAreaLayout.item(path); + Q_ASSERT(item.widgetItem->widget() == dwgw); + delete item.widgetItem; + item.widgetItem = 0; + item.subinfo = new QDockAreaLayoutInfo(qMove(*info)); + *info = QDockAreaLayoutInfo(); + item.subinfo->reparentWidgets(parentWidget()); + item.subinfo->setTabBarShape(parentInfo->tabBarShape); + } + dwgw->destroyIfEmpty(); + } + if (QDockWidget *dw = qobject_cast<QDockWidget*>(widget)) dw->d_func()->plug(currentGapRect); #endif @@ -1621,7 +2044,7 @@ void QMainWindowLayout::animationFinished(QWidget *widget) if (qobject_cast<QDockWidget*>(widget) != 0) { // info() might return null if the widget is destroyed while // animating but before the animationFinished signal is received. - if (QDockAreaLayoutInfo *info = layoutState.dockAreaLayout.info(widget)) + if (QDockAreaLayoutInfo *info = dockInfo(widget)) info->setCurrentTab(widget); } #endif @@ -1765,8 +2188,33 @@ void QMainWindowLayout::setCentralWidget(QWidget *widget) invalidate(); } -QLayoutItem *QMainWindowLayout::unplug(QWidget *widget) -{ +/*! \internal + Unplug \a widget (QDockWidget or QToolBar) from it's parent container. + + If \a group is true we might actually unplug the group of tabs this + widget is part if QMainWindow::GroupedDragging is set. When \a group + is false, the widget itself is always unplugged alone + + Returns the QLayoutItem of the dragged element. + The layout item is kept in the layout but set as a gap item. + */ +QLayoutItem *QMainWindowLayout::unplug(QWidget *widget, bool group) +{ +#if !defined(QT_NO_DOCKWIDGET) && !defined(QT_NO_TABBAR) + QDockWidgetGroupWindow *floatingParent = qobject_cast<QDockWidgetGroupWindow *>(widget->parentWidget()); + if (group && floatingParent && !widget->isWindow()) { + // We are just dragging a floating window as it, not need to do anything, we just have to + // look up the corresponding QWidgetItem* if it exists + QList<int> tabbedWindowPath = layoutState.indexOf(widget->parentWidget()); + return tabbedWindowPath.isEmpty() ? 0 : layoutState.item(tabbedWindowPath); + } else if (floatingParent) { + // We are unplugging a dock widget from a floating window. + if (QDockWidget *dw = qobject_cast<QDockWidget*>(widget)) { + dw->d_func()->unplug(widget->geometry()); + return 0; + } + } +#endif QList<int> path = layoutState.indexOf(widget); if (path.isEmpty()) return 0; @@ -1780,9 +2228,35 @@ QLayoutItem *QMainWindowLayout::unplug(QWidget *widget) #ifndef QT_NO_DOCKWIDGET if (QDockWidget *dw = qobject_cast<QDockWidget*>(widget)) { - dw->d_func()->unplug(r); + Q_ASSERT(path.first() == 1); + bool actualGroup = false; +#ifndef QT_NO_TABBAR + if (group && (dockOptions & QMainWindow::GroupedDragging) && path.size() > 3) { + QDockAreaLayoutItem &parentItem = layoutState.dockAreaLayout.item(path.mid(1, path.size() - 2)); + if (parentItem.subinfo && parentItem.subinfo->tabbed) { + // The QDockWidget is part of a group of tab and we need to unplug them all. + actualGroup = true; + path.removeLast(); + + QDockWidgetGroupWindow* floatingTabs = createTabbedDockWindow(); + QDockAreaLayoutInfo* info = floatingTabs->layoutInfo(); + *info = qMove(*parentItem.subinfo); + delete parentItem.subinfo; + parentItem.subinfo = 0; + floatingTabs->setGeometry(info->rect.translated(parentWidget()->pos())); + floatingTabs->show(); + floatingTabs->raise(); + item = new QDockWidgetGroupWindowItem(floatingTabs); + parentItem.widgetItem = item; + savedState = layoutState; + } + } +#endif // QT_NO_TABBAR + if (!actualGroup) { + dw->d_func()->unplug(r); + } } -#endif +#endif // QT_NO_DOCKWIDGET #ifndef QT_NO_TOOLBAR if (QToolBar *tb = qobject_cast<QToolBar*>(widget)) { tb->d_func()->unplug(r); @@ -1829,6 +2303,9 @@ QList<int> QMainWindowLayout::hover(QLayoutItem *widgetItem, const QPoint &mouse #ifndef QT_NO_DOCKWIDGET if (QDockWidget *dw = qobject_cast<QDockWidget*>(widget)) allowed = dw->isAreaAllowed(toDockWidgetArea(path.at(1))); + + if (qobject_cast<QDockWidgetGroupWindow *>(widget)) + allowed = true; #endif #ifndef QT_NO_TOOLBAR if (QToolBar *tb = qobject_cast<QToolBar*>(widget)) @@ -1881,11 +2358,23 @@ QList<int> QMainWindowLayout::hover(QLayoutItem *widgetItem, const QPoint &mouse return path; } +QDockWidgetGroupWindow *QMainWindowLayout::createTabbedDockWindow() +{ + QDockWidgetGroupWindow* f = new QDockWidgetGroupWindow(parentWidget(), Qt::Tool); + new QDockWidgetGroupLayout(f); + return f; +} + void QMainWindowLayout::applyState(QMainWindowLayoutState &newState, bool animate) { #ifndef QT_NO_DOCKWIDGET #ifndef QT_NO_TABBAR QSet<QTabBar*> used = newState.dockAreaLayout.usedTabBars(); + foreach (QDockWidgetGroupWindow *dwgw, + parent()->findChildren<QDockWidgetGroupWindow*>(QString(), Qt::FindDirectChildrenOnly)) { + used += dwgw->layoutInfo()->usedTabBars(); + } + QSet<QTabBar*> retired = usedTabBars - used; usedTabBars = used; foreach (QTabBar *tab_bar, retired) { @@ -1904,6 +2393,8 @@ void QMainWindowLayout::applyState(QMainWindowLayoutState &newState, bool animat } } + for (int i = 0; i < QInternal::DockCount; ++i) + newState.dockAreaLayout.docks[i].reparentWidgets(parentWidget()); #endif // QT_NO_TABBAR #endif // QT_NO_DOCKWIDGET diff --git a/src/widgets/widgets/qmainwindowlayout_p.h b/src/widgets/widgets/qmainwindowlayout_p.h index 9f84ee95db..9155c5fb23 100644 --- a/src/widgets/widgets/qmainwindowlayout_p.h +++ b/src/widgets/widgets/qmainwindowlayout_p.h @@ -77,6 +77,23 @@ QT_BEGIN_NAMESPACE class QToolBar; class QRubberBand; +#ifndef QT_NO_DOCKWIDGET +class QDockWidgetGroupWindow : public QWidget +{ + Q_OBJECT +public: + explicit QDockWidgetGroupWindow(QWidget* parent = 0, Qt::WindowFlags f = 0) + : QWidget(parent, f) {} + QDockAreaLayoutInfo *layoutInfo() const; + QDockWidget *topDockWidget() const; + void destroyIfEmpty(); + void adjustFlags(); +protected: + bool event(QEvent *) Q_DECL_OVERRIDE; + void paintEvent(QPaintEvent*) Q_DECL_OVERRIDE; +}; +#endif + /* This data structure represents the state of all the tool-bars and dock-widgets. It's value based so it can be easilly copied into a temporary variable. All operations are performed without moving any widgets. Only when we are sure we have the desired state, we call apply(), which moves the @@ -196,10 +213,11 @@ public: QDockWidget *dockwidget, Qt::Orientation orientation); void tabifyDockWidget(QDockWidget *first, QDockWidget *second); - Qt::DockWidgetArea dockWidgetArea(QDockWidget *dockwidget) const; + Qt::DockWidgetArea dockWidgetArea(QWidget* widget) const; void raise(QDockWidget *widget); void setVerticalTabsEnabled(bool enabled); bool restoreDockWidget(QDockWidget *dockwidget); + QDockAreaLayoutInfo *dockInfo(QWidget *w); #ifndef QT_NO_TABBAR bool _documentMode; @@ -224,6 +242,8 @@ public: void setTabShape(QTabWidget::TabShape tabShape); QTabWidget::TabPosition tabPosition(Qt::DockWidgetArea area) const; void setTabPosition(Qt::DockWidgetAreas areas, QTabWidget::TabPosition tabPosition); + + QDockWidgetGroupWindow *createTabbedDockWindow(); #endif // QT_NO_TABWIDGET #endif // QT_NO_TABBAR @@ -273,7 +293,7 @@ public: QList<int> hover(QLayoutItem *widgetItem, const QPoint &mousePos); bool plug(QLayoutItem *widgetItem); - QLayoutItem *unplug(QWidget *widget); + QLayoutItem *unplug(QWidget *widget, bool group = false); void revert(QLayoutItem *widgetItem); void updateGapIndicator(); void paintDropIndicator(QPainter *p, QWidget *widget, const QRegion &clip); @@ -286,6 +306,7 @@ private Q_SLOTS: #ifndef QT_NO_DOCKWIDGET #ifndef QT_NO_TABBAR void tabChanged(); + void tabMoved(int from, int to); #endif #endif private: diff --git a/src/widgets/widgets/qmdiarea_p.h b/src/widgets/widgets/qmdiarea_p.h index 7f28879f8d..f6bdf61492 100644 --- a/src/widgets/widgets/qmdiarea_p.h +++ b/src/widgets/widgets/qmdiarea_p.h @@ -142,8 +142,8 @@ public: #endif QMdiAreaTabBar *tabBar; QList<QMdi::Rearranger *> pendingRearrangements; - QList< QPointer<QMdiSubWindow> > pendingPlacements; - QList< QPointer<QMdiSubWindow> > childWindows; + QVector< QPointer<QMdiSubWindow> > pendingPlacements; + QVector< QPointer<QMdiSubWindow> > childWindows; QList<int> indicesToActivatedChildren; QPointer<QMdiSubWindow> active; QPointer<QMdiSubWindow> aboutToBecomeActive; diff --git a/src/widgets/widgets/qmdisubwindow.cpp b/src/widgets/widgets/qmdisubwindow.cpp index 1808030639..c3b31ea5a4 100644 --- a/src/widgets/widgets/qmdisubwindow.cpp +++ b/src/widgets/widgets/qmdisubwindow.cpp @@ -1091,8 +1091,8 @@ void QMdiSubWindowPrivate::updateDirtyRegions() if (!parent) return; - foreach (Operation operation, operationMap.keys()) - operationMap.find(operation).value().region = getRegion(operation); + for (OperationInfoMap::iterator it = operationMap.begin(), end = operationMap.end(); it != end; ++it) + it.value().region = getRegion(it.key()); } /*! diff --git a/src/widgets/widgets/qmenu.cpp b/src/widgets/widgets/qmenu.cpp index e81359feac..3148b140bc 100644 --- a/src/widgets/widgets/qmenu.cpp +++ b/src/widgets/widgets/qmenu.cpp @@ -1110,8 +1110,7 @@ bool QMenuPrivate::mouseEventTaken(QMouseEvent *e) handleEnterLeaveEvents(&previousMouseMenu,qobject_cast<QMenu *>(caused)); if(e->type() != QEvent::MouseButtonRelease || mouseDown == caused) { QMouseEvent new_e(e->type(), cpos, caused->mapTo(caused->topLevelWidget(), cpos), e->screenPos(), - e->button(), e->buttons(), e->modifiers()); - QGuiApplicationPrivate::setMouseEventSource(&new_e, e->source()); + e->button(), e->buttons(), e->modifiers(), e->source()); QApplication::sendEvent(caused, &new_e); return true; } @@ -1572,6 +1571,100 @@ QAction *QMenu::addAction(const QString &text, const QObject *receiver, const ch return action; } +/*!\fn QAction *QMenu::addAction(const QString &text, const QObject *receiver, PointerToMemberFunction method, const QKeySequence &shortcut = 0) + + \since 5.6 + + \overload + + This convenience function creates a new action with the text \a + text and an optional shortcut \a shortcut. The action's + \l{QAction::triggered()}{triggered()} signal is connected to the + \a method of the \a receiver. The function adds the newly created + action to the menu's list of actions and returns it. + + QMenu takes ownership of the returned QAction. +*/ + +/*!\fn QAction *QMenu::addAction(const QString &text, Functor functor, const QKeySequence &shortcut = 0) + + \since 5.6 + + \overload + + This convenience function creates a new action with the text \a + text and an optional shortcut \a shortcut. The action's + \l{QAction::triggered()}{triggered()} signal is connected to the + \a functor. The function adds the newly created + action to the menu's list of actions and returns it. + + QMenu takes ownership of the returned QAction. +*/ + +/*!\fn QAction *QMenu::addAction(const QString &text, const QObject *context, Functor functor, const QKeySequence &shortcut = 0) + + \since 5.6 + + \overload + + This convenience function creates a new action with the text \a + text and an optional shortcut \a shortcut. The action's + \l{QAction::triggered()}{triggered()} signal is connected to the + \a functor. The function adds the newly created + action to the menu's list of actions and returns it. + + If \a context is destroyed, the functor will not be called. + + QMenu takes ownership of the returned QAction. +*/ + +/*!\fn QAction *QMenu::addAction(const QIcon &icon, const QString &text, const QObject *receiver, PointerToMemberFunction method, const QKeySequence &shortcut = 0) + + \since 5.6 + + \overload + + This convenience function creates a new action with an \a icon + and some \a text and an optional shortcut \a shortcut. The action's + \l{QAction::triggered()}{triggered()} signal is connected to the + \a method of the \a receiver. The function adds the newly created + action to the menu's list of actions and returns it. + + QMenu takes ownership of the returned QAction. +*/ + +/*!\fn QAction *QMenu::addAction(const QIcon &icon, const QString &text, Functor functor, const QKeySequence &shortcut = 0) + + \since 5.6 + + \overload + + This convenience function creates a new action with an \a icon + and some \a text and an optional shortcut \a shortcut. The action's + \l{QAction::triggered()}{triggered()} signal is connected to the + \a functor. The function adds the newly created + action to the menu's list of actions and returns it. + + QMenu takes ownership of the returned QAction. +*/ + +/*!\fn QAction *QMenu::addAction(const QIcon &icon, const QString &text, const QObject *context, Functor functor, const QKeySequence &shortcut = 0) + + \since 5.6 + + \overload + + This convenience function creates a new action with an \a icon + and some \a text and an optional shortcut \a shortcut. The action's + \l{QAction::triggered()}{triggered()} signal is connected to the + \a functor. The function adds the newly created + action to the menu's list of actions and returns it. + + If \a context is destroyed, the functor will not be called. + + QMenu takes ownership of the returned QAction. +*/ + /*! \overload diff --git a/src/widgets/widgets/qmenu.h b/src/widgets/widgets/qmenu.h index 5dda8b2370..21e1432d2a 100644 --- a/src/widgets/widgets/qmenu.h +++ b/src/widgets/widgets/qmenu.h @@ -78,6 +78,72 @@ public: QAction *addAction(const QString &text, const QObject *receiver, const char* member, const QKeySequence &shortcut = 0); QAction *addAction(const QIcon &icon, const QString &text, const QObject *receiver, const char* member, const QKeySequence &shortcut = 0); +#ifdef Q_QDOC + QAction *addAction(const QString &text, const QObject *receiver, PointerToMemberFunction method, const QKeySequence &shortcut = 0); + QAction *addAction(const QString &text, Functor functor, const QKeySequence &shortcut = 0); + QAction *addAction(const QString &text, const QObject *context, Functor functor, const QKeySequence &shortcut = 0); + QAction *addAction(const QIcon &icon, const QString &text, const QObject *receiver, PointerToMemberFunction method, const QKeySequence &shortcut = 0); + QAction *addAction(const QIcon &icon, const QString &text, Functor functor, const QKeySequence &shortcut = 0); + QAction *addAction(const QIcon &icon, const QString &text, const QObject *context, Functor functor, const QKeySequence &shortcut = 0); +#else + // addAction(QString): Connect to a QObject slot / functor or function pointer (with context) + template<class Obj, typename Func1> + inline typename QtPrivate::QEnableIf<!QtPrivate::is_same<const char*, Func1>::value + && QtPrivate::IsPointerToTypeDerivedFromQObject<Obj*>::Value, QAction *>::Type + addAction(const QString &text, const Obj *object, Func1 slot, const QKeySequence &shortcut = 0) + { + QAction *result = addAction(text); +#ifdef QT_NO_SHORTCUT + Q_UNUSED(shortcut) +#else + result->setShortcut(shortcut); +#endif + connect(result, &QAction::triggered, object, slot); + return result; + } + // addAction(QString): Connect to a functor or function pointer (without context) + template <typename Func1> + inline QAction *addAction(const QString &text, Func1 slot, const QKeySequence &shortcut = 0) + { + QAction *result = addAction(text); +#ifdef QT_NO_SHORTCUT + Q_UNUSED(shortcut) +#else + result->setShortcut(shortcut); +#endif + connect(result, &QAction::triggered, slot); + return result; + } + // addAction(QIcon, QString): Connect to a QObject slot / functor or function pointer (with context) + template<class Obj, typename Func1> + inline typename QtPrivate::QEnableIf<!QtPrivate::is_same<const char*, Func1>::value + && QtPrivate::IsPointerToTypeDerivedFromQObject<Obj*>::Value, QAction *>::Type + addAction(const QIcon &actionIcon, const QString &text, const Obj *object, Func1 slot, const QKeySequence &shortcut = 0) + { + QAction *result = addAction(actionIcon, text); +#ifdef QT_NO_SHORTCUT + Q_UNUSED(shortcut) +#else + result->setShortcut(shortcut); +#endif + connect(result, &QAction::triggered, object, slot); + return result; + } + // addAction(QIcon, QString): Connect to a functor or function pointer (without context) + template <typename Func1> + inline QAction *addAction(const QIcon &actionIcon, const QString &text, Func1 slot, const QKeySequence &shortcut = 0) + { + QAction *result = addAction(actionIcon, text); +#ifdef QT_NO_SHORTCUT + Q_UNUSED(shortcut) +#else + result->setShortcut(shortcut); +#endif + connect(result, &QAction::triggered, slot); + return result; + } +#endif // !Q_QDOC + QAction *addMenu(QMenu *menu); QMenu *addMenu(const QString &title); QMenu *addMenu(const QIcon &icon, const QString &title); diff --git a/src/widgets/widgets/qmenubar.cpp b/src/widgets/widgets/qmenubar.cpp index 1ad99bed9c..9e76ff082c 100644 --- a/src/widgets/widgets/qmenubar.cpp +++ b/src/widgets/widgets/qmenubar.cpp @@ -195,7 +195,9 @@ void QMenuBarPrivate::updateGeometries() for(int j = 0; j < shortcutIndexMap.size(); ++j) q->releaseShortcut(shortcutIndexMap.value(j)); shortcutIndexMap.resize(0); // faster than clear - for(int i = 0; i < actions.count(); i++) + const int actionsCount = actions.count(); + shortcutIndexMap.reserve(actionsCount); + for (int i = 0; i < actionsCount; i++) shortcutIndexMap.append(q->grabShortcut(QKeySequence::mnemonic(actions.at(i)->text()))); } #endif diff --git a/src/widgets/widgets/qsplitter.cpp b/src/widgets/widgets/qsplitter.cpp index de6e45234c..c2081c15f8 100644 --- a/src/widgets/widgets/qsplitter.cpp +++ b/src/widgets/widgets/qsplitter.cpp @@ -58,6 +58,10 @@ QT_BEGIN_NAMESPACE //#define QSPLITTER_DEBUG +QSplitterPrivate::~QSplitterPrivate() +{ +} + /*! \class QSplitterHandle \brief The QSplitterHandle class provides handle functionality for the splitter. @@ -1498,8 +1502,11 @@ QList<int> QSplitter::sizes() const Q_D(const QSplitter); ensurePolished(); + const int numSizes = d->list.size(); QList<int> list; - for (int i = 0; i < d->list.size(); ++i) { + list.reserve(numSizes); + + for (int i = 0; i < numSizes; ++i) { QSplitterLayoutStruct *s = d->list.at(i); list.append(d->pick(s->rect.size())); } @@ -1594,8 +1601,10 @@ QByteArray QSplitter::saveState() const stream << qint32(SplitterMagic); stream << qint32(version); + const int numSizes = d->list.size(); QList<int> list; - for (int i = 0; i < d->list.size(); ++i) { + list.reserve(numSizes); + for (int i = 0; i < numSizes; ++i) { QSplitterLayoutStruct *s = d->list.at(i); list.append(s->sizer); } diff --git a/src/widgets/widgets/qsplitter_p.h b/src/widgets/widgets/qsplitter_p.h index a45f776da1..890bd535ec 100644 --- a/src/widgets/widgets/qsplitter_p.h +++ b/src/widgets/widgets/qsplitter_p.h @@ -76,6 +76,7 @@ class QSplitterPrivate : public QFramePrivate public: QSplitterPrivate() : rubberBand(0), opaque(true), firstShow(true), childrenCollapsible(true), compatMode(false), handleWidth(-1), blockChildAdd(false), opaqueResizeSet(false) {} + ~QSplitterPrivate(); QPointer<QRubberBand> rubberBand; mutable QList<QSplitterLayoutStruct *> list; diff --git a/src/widgets/widgets/qtoolbar.cpp b/src/widgets/widgets/qtoolbar.cpp index ecba6f1974..1e4a39088c 100644 --- a/src/widgets/widgets/qtoolbar.cpp +++ b/src/widgets/widgets/qtoolbar.cpp @@ -793,6 +793,82 @@ QAction *QToolBar::addAction(const QIcon &icon, const QString &text, return action; } +/*!\fn QAction *QToolBar::addAction(const QString &text, const QObject *receiver, PointerToMemberFunction method) + + \since 5.6 + + \overload + + Creates a new action with the given \a text. This action is added to + the end of the toolbar. The action's + \l{QAction::triggered()}{triggered()} signal is connected to the + \a method of the \a receiver. +*/ + +/*!\fn QAction *QToolBar::addAction(const QString &text, Functor functor) + + \since 5.6 + + \overload + + Creates a new action with the given \a text. This action is added to + the end of the toolbar. The action's + \l{QAction::triggered()}{triggered()} signal is connected to the + \a functor. +*/ + +/*!\fn QAction *QToolBar::addAction(const QString &text, const QObject *context, Functor functor) + + \since 5.6 + + \overload + + Creates a new action with the given \a text. This action is added to + the end of the toolbar. The action's + \l{QAction::triggered()}{triggered()} signal is connected to the + \a functor. + + If \a context is destroyed, the functor will not be called. +*/ + +/*!\fn QAction *QToolBar::addAction(const QIcon &icon, const QString &text, const QObject *receiver, PointerToMemberFunction method) + + \since 5.6 + + \overload + + Creates a new action with the given \a icon and \a text. This + action is added to the end of the toolbar. The action's + \l{QAction::triggered()}{triggered()} signal is connected to the + \a method of the \a receiver. +*/ + +/*!\fn QAction *QToolBar::addAction(const QIcon &icon, const QString &text, Functor functor) + + \since 5.6 + + \overload + + Creates a new action with the given \a icon and \a text. This + action is added to the end of the toolbar. The action's + \l{QAction::triggered()}{triggered()} signal is connected to the + \a functor. +*/ + +/*!\fn QAction *QToolBar::addAction(const QIcon &icon, const QString &text, const QObject *context, Functor functor) + + \since 5.6 + + \overload + + Creates a new action with the given \a icon and \a text. This + action is added to the end of the toolbar. The action's + \l{QAction::triggered()}{triggered()} signal is connected to the + \a functor. + + If \a context is destroyed, the functor will not be called. +*/ + /*! Adds a separator to the end of the toolbar. diff --git a/src/widgets/widgets/qtoolbar.h b/src/widgets/widgets/qtoolbar.h index f925577646..f4ed13d399 100644 --- a/src/widgets/widgets/qtoolbar.h +++ b/src/widgets/widgets/qtoolbar.h @@ -34,6 +34,7 @@ #ifndef QDYNAMICTOOLBAR_H #define QDYNAMICTOOLBAR_H +#include <QtWidgets/qaction.h> #include <QtWidgets/qwidget.h> QT_BEGIN_NAMESPACE @@ -92,6 +93,51 @@ public: QAction *addAction(const QString &text, const QObject *receiver, const char* member); QAction *addAction(const QIcon &icon, const QString &text, const QObject *receiver, const char* member); +#ifdef Q_QDOC + QAction *addAction(const QString &text, const QObject *receiver, PointerToMemberFunction method); + QAction *addAction(const QString &text, Functor functor); + QAction *addAction(const QString &text, const QObject *context, Functor functor); + QAction *addAction(const QIcon &icon, const QString &text, const QObject *receiver, PointerToMemberFunction method); + QAction *addAction(const QIcon &icon, const QString &text, Functor functor); + QAction *addAction(const QIcon &icon, const QString &text, const QObject *context, Functor functor); +#else + // addAction(QString): Connect to a QObject slot / functor or function pointer (with context) + template<class Obj, typename Func1> + inline typename QtPrivate::QEnableIf<!QtPrivate::is_same<const char*, Func1>::value + && QtPrivate::IsPointerToTypeDerivedFromQObject<Obj*>::Value, QAction *>::Type + addAction(const QString &text, const Obj *object, Func1 slot) + { + QAction *result = addAction(text); + connect(result, &QAction::triggered, object, slot); + return result; + } + // addAction(QString): Connect to a functor or function pointer (without context) + template <typename Func1> + inline QAction *addAction(const QString &text, Func1 slot) + { + QAction *result = addAction(text); + connect(result, &QAction::triggered, slot); + return result; + } + // addAction(QString): Connect to a QObject slot / functor or function pointer (with context) + template<class Obj, typename Func1> + inline typename QtPrivate::QEnableIf<!QtPrivate::is_same<const char*, Func1>::value + && QtPrivate::IsPointerToTypeDerivedFromQObject<Obj*>::Value, QAction *>::Type + addAction(const QIcon &actionIcon, const QString &text, const Obj *object, Func1 slot) + { + QAction *result = addAction(actionIcon, text); + connect(result, &QAction::triggered, object, slot); + return result; + } + // addAction(QIcon, QString): Connect to a functor or function pointer (without context) + template <typename Func1> + inline QAction *addAction(const QIcon &actionIcon, const QString &text, Func1 slot) + { + QAction *result = addAction(actionIcon, text); + connect(result, &QAction::triggered, slot); + return result; + } +#endif // !Q_QDOC QAction *addSeparator(); QAction *insertSeparator(QAction *before); diff --git a/src/widgets/widgets/qwidgetlinecontrol.cpp b/src/widgets/widgets/qwidgetlinecontrol.cpp index 759e41a5fa..436937be72 100644 --- a/src/widgets/widgets/qwidgetlinecontrol.cpp +++ b/src/widgets/widgets/qwidgetlinecontrol.cpp @@ -189,7 +189,7 @@ void QWidgetLineControl::commitPreedit() m_preeditCursor = 0; setPreeditArea(-1, QString()); - m_textLayout.clearAdditionalFormats(); + m_textLayout.clearFormats(); updateDisplayText(/*force*/ true); #endif } @@ -557,7 +557,8 @@ void QWidgetLineControl::processInputMethodEvent(QInputMethodEvent *event) const int oldPreeditCursor = m_preeditCursor; m_preeditCursor = event->preeditString().length(); m_hideCursor = false; - QList<QTextLayout::FormatRange> formats; + QVector<QTextLayout::FormatRange> formats; + formats.reserve(event->attributes().size()); for (int i = 0; i < event->attributes().size(); ++i) { const QInputMethodEvent::Attribute &a = event->attributes().at(i); if (a.type == QInputMethodEvent::Cursor) { @@ -574,7 +575,7 @@ void QWidgetLineControl::processInputMethodEvent(QInputMethodEvent *event) } } } - m_textLayout.setAdditionalFormats(formats); + m_textLayout.setFormats(formats); updateDisplayText(/*force*/ true); if (cursorPositionChanged) emitCursorPositionChanged(); diff --git a/src/widgets/widgets/qwidgettextcontrol.cpp b/src/widgets/widgets/qwidgettextcontrol.cpp index 72007ac3e8..deca002bf5 100644 --- a/src/widgets/widgets/qwidgettextcontrol.cpp +++ b/src/widgets/widgets/qwidgettextcontrol.cpp @@ -883,7 +883,8 @@ void QWidgetTextControl::setTextCursor(const QTextCursor &cursor) const bool posChanged = cursor.position() != d->cursor.position(); const QTextCursor oldSelection = d->cursor; d->cursor = cursor; - d->cursorOn = d->hasFocus && (d->interactionFlags & Qt::TextEditable); + d->cursorOn = d->hasFocus + && (d->interactionFlags & (Qt::TextSelectableByKeyboard | Qt::TextEditable)); d->_q_updateCurrentCharFormatAndSelection(); ensureCursorVisible(); d->repaintOldAndNewSelection(oldSelection); @@ -2028,7 +2029,8 @@ void QWidgetTextControlPrivate::inputMethodEvent(QInputMethodEvent *e) QTextLayout *layout = block.layout(); if (isGettingInput) layout->setPreeditArea(cursor.position() - block.position(), e->preeditString()); - QList<QTextLayout::FormatRange> overrides; + QVector<QTextLayout::FormatRange> overrides; + overrides.reserve(e->attributes().size()); const int oldPreeditCursor = preeditCursor; preeditCursor = e->preeditString().length(); hideCursor = false; @@ -2048,7 +2050,7 @@ void QWidgetTextControlPrivate::inputMethodEvent(QInputMethodEvent *e) } } } - layout->setAdditionalFormats(overrides); + layout->setFormats(overrides); cursor.endEditBlock(); @@ -2138,7 +2140,7 @@ void QWidgetTextControlPrivate::focusEvent(QFocusEvent *e) #ifdef QT_KEYPAD_NAVIGATION if (!QApplication::keypadNavigationEnabled() || (hasEditFocus && (e->reason() == Qt::PopupFocusReason))) { #endif - cursorOn = (interactionFlags & Qt::TextSelectableByKeyboard); + cursorOn = (interactionFlags & (Qt::TextSelectableByKeyboard | Qt::TextEditable)); if (interactionFlags & Qt::TextEditable) { setBlinkingCursorEnabled(true); } @@ -2437,10 +2439,13 @@ QList<QTextEdit::ExtraSelection> QWidgetTextControl::extraSelections() const { Q_D(const QWidgetTextControl); QList<QTextEdit::ExtraSelection> selections; - for (int i = 0; i < d->extraSelections.count(); ++i) { + const int numExtraSelections = d->extraSelections.count(); + selections.reserve(numExtraSelections); + for (int i = 0; i < numExtraSelections; ++i) { QTextEdit::ExtraSelection sel; - sel.cursor = d->extraSelections.at(i).cursor; - sel.format = d->extraSelections.at(i).format; + const QAbstractTextDocumentLayout::Selection &sel2 = d->extraSelections.at(i); + sel.cursor = sel2.cursor; + sel.format = sel2.format; selections.append(sel); } return selections; @@ -2877,7 +2882,7 @@ void QWidgetTextControlPrivate::commitPreedit() QTextBlock block = cursor.block(); QTextLayout *layout = block.layout(); layout->setPreeditArea(-1, QString()); - layout->clearAdditionalFormats(); + layout->clearFormats(); cursor.endEditBlock(); } |