summaryrefslogtreecommitdiffstats
path: root/src/widgets
diff options
context:
space:
mode:
Diffstat (limited to 'src/widgets')
-rw-r--r--src/widgets/dialogs/qcolordialog.cpp15
-rw-r--r--src/widgets/dialogs/qdialog.cpp37
-rw-r--r--src/widgets/dialogs/qdialog.h15
-rw-r--r--src/widgets/dialogs/qfiledialog.cpp157
-rw-r--r--src/widgets/dialogs/qfiledialog.h25
-rw-r--r--src/widgets/dialogs/qfiledialog_p.h10
-rw-r--r--src/widgets/dialogs/qfontdialog.cpp2
-rw-r--r--src/widgets/dialogs/qmessagebox.cpp16
-rw-r--r--src/widgets/dialogs/qmessagebox.h4
-rw-r--r--src/widgets/dialogs/qprogressdialog.cpp10
-rw-r--r--src/widgets/dialogs/qsidebar.cpp2
-rw-r--r--src/widgets/dialogs/qwizard.cpp26
-rw-r--r--src/widgets/dialogs/qwizard_win_p.h2
-rw-r--r--src/widgets/doc/snippets/code/doc_src_examples_dropsite.qdoc55
-rw-r--r--src/widgets/doc/snippets/code/doc_src_stylesheet.qdoc16
-rw-r--r--src/widgets/doc/snippets/code/src_gui_dialogs_qfiledialog.cpp11
-rw-r--r--src/widgets/doc/snippets/code/src_gui_itemviews_qdatawidgetmapper.cpp8
-rw-r--r--src/widgets/doc/snippets/code/src_gui_kernel_qapplication.cpp12
-rw-r--r--src/widgets/doc/snippets/code/src_gui_widgets_qmenu.cpp2
-rw-r--r--src/widgets/doc/snippets/dialogs/dialogs.cpp9
-rw-r--r--src/widgets/doc/snippets/dockwidgets/mainwindow.cpp8
-rw-r--r--src/widgets/doc/snippets/mdiareasnippets.cpp4
-rw-r--r--src/widgets/doc/snippets/qlistview-dnd/mainwindow.cpp3
-rw-r--r--src/widgets/doc/snippets/qlistview-dnd/model.cpp8
-rw-r--r--src/widgets/doc/snippets/qlistwidget-dnd/mainwindow.cpp4
-rw-r--r--src/widgets/doc/snippets/qlistwidget-using/mainwindow.cpp17
-rw-r--r--src/widgets/doc/snippets/qsortfilterproxymodel/main.cpp7
-rw-r--r--src/widgets/doc/snippets/qstackedlayout/main.cpp9
-rw-r--r--src/widgets/doc/snippets/qstackedwidget/main.cpp7
-rw-r--r--src/widgets/doc/snippets/qtablewidget-resizing/mainwindow.cpp8
-rw-r--r--src/widgets/doc/snippets/qtablewidget-using/mainwindow.cpp20
-rw-r--r--src/widgets/doc/snippets/qtreewidget-using/mainwindow.cpp35
-rw-r--r--src/widgets/doc/snippets/qtreewidgetitemiterator-using/mainwindow.cpp21
-rw-r--r--src/widgets/doc/snippets/reading-selections/window.cpp18
-rw-r--r--src/widgets/doc/snippets/updating-selections/window.cpp17
-rw-r--r--src/widgets/doc/src/model-view-programming.qdoc21
-rw-r--r--src/widgets/doc/src/widgets-and-layouts/stylesheet.qdoc18
-rw-r--r--src/widgets/effects/qgraphicseffect_p.h2
-rw-r--r--src/widgets/effects/qpixmapfilter.cpp5
-rw-r--r--src/widgets/graphicsview/qgraphicsgridlayout.cpp11
-rw-r--r--src/widgets/graphicsview/qgraphicsitem.cpp105
-rw-r--r--src/widgets/graphicsview/qgraphicsitem.h8
-rw-r--r--src/widgets/graphicsview/qgraphicsitemanimation.cpp2
-rw-r--r--src/widgets/graphicsview/qgraphicsitemanimation.h3
-rw-r--r--src/widgets/graphicsview/qgraphicslayout.h2
-rw-r--r--src/widgets/graphicsview/qgraphicslayoutitem.cpp14
-rw-r--r--src/widgets/graphicsview/qgraphicslayoutitem.h2
-rw-r--r--src/widgets/graphicsview/qgraphicslayoutstyleinfo.cpp8
-rw-r--r--src/widgets/graphicsview/qgraphicslayoutstyleinfo_p.h4
-rw-r--r--src/widgets/graphicsview/qgraphicsproxywidget.cpp4
-rw-r--r--src/widgets/graphicsview/qgraphicsscene.cpp54
-rw-r--r--src/widgets/graphicsview/qgraphicsscene.h8
-rw-r--r--src/widgets/graphicsview/qgraphicsscenebsptreeindex_p.h2
-rw-r--r--src/widgets/graphicsview/qgraphicssceneevent.cpp4
-rw-r--r--src/widgets/graphicsview/qgraphicssceneindex_p.h4
-rw-r--r--src/widgets/graphicsview/qgraphicsview.cpp2
-rw-r--r--src/widgets/graphicsview/qgraphicswidget.cpp37
-rw-r--r--src/widgets/graphicsview/qsimplex_p.h2
-rw-r--r--src/widgets/itemviews/qabstractitemdelegate.cpp6
-rw-r--r--src/widgets/itemviews/qabstractitemdelegate.h3
-rw-r--r--src/widgets/itemviews/qabstractitemview.cpp21
-rw-r--r--src/widgets/itemviews/qabstractitemview.h10
-rw-r--r--src/widgets/itemviews/qcolumnview.cpp2
-rw-r--r--src/widgets/itemviews/qcolumnview_p.h1
-rw-r--r--src/widgets/itemviews/qcolumnviewgrip_p.h2
-rw-r--r--src/widgets/itemviews/qdatawidgetmapper.cpp1
-rw-r--r--src/widgets/itemviews/qdirmodel.cpp3
-rw-r--r--src/widgets/itemviews/qheaderview.cpp29
-rw-r--r--src/widgets/itemviews/qitemdelegate.cpp42
-rw-r--r--src/widgets/itemviews/qitemdelegate.h5
-rw-r--r--src/widgets/itemviews/qitemeditorfactory.cpp16
-rw-r--r--src/widgets/itemviews/qitemeditorfactory.h4
-rw-r--r--src/widgets/itemviews/qlistview.cpp35
-rw-r--r--src/widgets/itemviews/qlistview_p.h8
-rw-r--r--src/widgets/itemviews/qlistwidget.cpp180
-rw-r--r--src/widgets/itemviews/qlistwidget.h45
-rw-r--r--src/widgets/itemviews/qlistwidget_p.h4
-rw-r--r--src/widgets/itemviews/qstyleditemdelegate.cpp4
-rw-r--r--src/widgets/itemviews/qtableview.cpp52
-rw-r--r--src/widgets/itemviews/qtableview.h6
-rw-r--r--src/widgets/itemviews/qtableview_p.h1
-rw-r--r--src/widgets/itemviews/qtablewidget.cpp122
-rw-r--r--src/widgets/itemviews/qtablewidget.h33
-rw-r--r--src/widgets/itemviews/qtablewidget_p.h3
-rw-r--r--src/widgets/itemviews/qtreeview.cpp131
-rw-r--r--src/widgets/itemviews/qtreeview.h6
-rw-r--r--src/widgets/itemviews/qtreeview_p.h2
-rw-r--r--src/widgets/itemviews/qtreewidget.cpp270
-rw-r--r--src/widgets/itemviews/qtreewidget.h65
-rw-r--r--src/widgets/itemviews/qtreewidget_p.h4
-rw-r--r--src/widgets/kernel/qactiongroup.cpp4
-rw-r--r--src/widgets/kernel/qapplication.cpp25
-rw-r--r--src/widgets/kernel/qapplication.h8
-rw-r--r--src/widgets/kernel/qdesktopwidget.cpp24
-rw-r--r--src/widgets/kernel/qdesktopwidget.h2
-rw-r--r--src/widgets/kernel/qformlayout.cpp15
-rw-r--r--src/widgets/kernel/qgesturemanager.cpp10
-rw-r--r--src/widgets/kernel/qgridlayout.cpp6
-rw-r--r--src/widgets/kernel/qlayout.cpp37
-rw-r--r--src/widgets/kernel/qlayout.h8
-rw-r--r--src/widgets/kernel/qlayoutitem.cpp18
-rw-r--r--src/widgets/kernel/qopenglwidget.cpp4
-rw-r--r--src/widgets/kernel/qstackedlayout.cpp12
-rw-r--r--src/widgets/kernel/qtooltip.cpp4
-rw-r--r--src/widgets/kernel/qwhatsthis.cpp6
-rw-r--r--src/widgets/kernel/qwidget.cpp128
-rw-r--r--src/widgets/kernel/qwidget.h5
-rw-r--r--src/widgets/kernel/qwidget_p.h17
-rw-r--r--src/widgets/kernel/qwidgetbackingstore.cpp270
-rw-r--r--src/widgets/kernel/qwidgetbackingstore_p.h8
-rw-r--r--src/widgets/statemachine/qbasickeyeventtransition_p.h2
-rw-r--r--src/widgets/statemachine/qbasicmouseeventtransition_p.h2
-rw-r--r--src/widgets/styles/qcommonstyle.cpp94
-rw-r--r--src/widgets/styles/qdrawutil.cpp2
-rw-r--r--src/widgets/styles/qfusionstyle.cpp76
-rw-r--r--src/widgets/styles/qfusionstyle_p_p.h2
-rw-r--r--src/widgets/styles/qstyle.h29
-rw-r--r--src/widgets/styles/qstyle_p.h2
-rw-r--r--src/widgets/styles/qstyleoption.cpp8
-rw-r--r--src/widgets/styles/qstylesheetstyle.cpp42
-rw-r--r--src/widgets/styles/qstylesheetstyle_p.h2
-rw-r--r--src/widgets/styles/qwindowsstyle.cpp52
-rw-r--r--src/widgets/styles/qwindowsstyle_p.h2
-rw-r--r--src/widgets/util/qcompleter_p.h1
-rw-r--r--src/widgets/util/qflickgesture.cpp2
-rw-r--r--src/widgets/util/qflickgesture_p.h3
-rw-r--r--src/widgets/util/qsystemtrayicon.cpp2
-rw-r--r--src/widgets/util/qundostack.cpp12
-rw-r--r--src/widgets/widgets/qabstractscrollarea.cpp10
-rw-r--r--src/widgets/widgets/qabstractspinbox.cpp2
-rw-r--r--src/widgets/widgets/qbuttongroup.cpp8
-rw-r--r--src/widgets/widgets/qcalendarwidget.cpp11
-rw-r--r--src/widgets/widgets/qcombobox.cpp29
-rw-r--r--src/widgets/widgets/qcombobox.h7
-rw-r--r--src/widgets/widgets/qcombobox_p.h3
-rw-r--r--src/widgets/widgets/qcommandlinkbutton.h6
-rw-r--r--src/widgets/widgets/qdatetimeedit.cpp2
-rw-r--r--src/widgets/widgets/qdialogbuttonbox.cpp2
-rw-r--r--src/widgets/widgets/qdockwidget.cpp11
-rw-r--r--src/widgets/widgets/qdockwidget_p.h1
-rw-r--r--src/widgets/widgets/qfontcombobox.cpp16
-rw-r--r--src/widgets/widgets/qlabel.cpp2
-rw-r--r--src/widgets/widgets/qlineedit.cpp2
-rw-r--r--src/widgets/widgets/qlineedit_p.cpp2
-rw-r--r--src/widgets/widgets/qmainwindow.cpp6
-rw-r--r--src/widgets/widgets/qmainwindow.h6
-rw-r--r--src/widgets/widgets/qmainwindowlayout.cpp2
-rw-r--r--src/widgets/widgets/qmainwindowlayout_p.h2
-rw-r--r--src/widgets/widgets/qmdiarea.cpp32
-rw-r--r--src/widgets/widgets/qmdisubwindow.cpp14
-rw-r--r--src/widgets/widgets/qmenu.cpp60
-rw-r--r--src/widgets/widgets/qmenu.h4
-rw-r--r--src/widgets/widgets/qmenu_p.h8
-rw-r--r--src/widgets/widgets/qplaintextedit.cpp26
-rw-r--r--src/widgets/widgets/qplaintextedit.h4
-rw-r--r--src/widgets/widgets/qpushbutton.cpp4
-rw-r--r--src/widgets/widgets/qscrollarea.cpp2
-rw-r--r--src/widgets/widgets/qsplitter.cpp6
-rw-r--r--src/widgets/widgets/qsplitter.h4
-rw-r--r--src/widgets/widgets/qstackedwidget.cpp6
-rw-r--r--src/widgets/widgets/qstatusbar.cpp6
-rw-r--r--src/widgets/widgets/qtabbar.cpp9
-rw-r--r--src/widgets/widgets/qtabwidget.cpp8
-rw-r--r--src/widgets/widgets/qtextbrowser.cpp6
-rw-r--r--src/widgets/widgets/qtextedit.cpp29
-rw-r--r--src/widgets/widgets/qtextedit.h4
-rw-r--r--src/widgets/widgets/qtoolbar.cpp40
-rw-r--r--src/widgets/widgets/qtoolbar.h8
-rw-r--r--src/widgets/widgets/qtoolbararealayout.cpp8
-rw-r--r--src/widgets/widgets/qtoolbararealayout_p.h2
-rw-r--r--src/widgets/widgets/qtoolbarlayout.cpp45
-rw-r--r--src/widgets/widgets/qtoolbox.cpp15
-rw-r--r--src/widgets/widgets/qtoolbutton.cpp5
-rw-r--r--src/widgets/widgets/qwidgetresizehandler_p.h2
-rw-r--r--src/widgets/widgets/qwidgettextcontrol.cpp31
-rw-r--r--src/widgets/widgets/qwidgettextcontrol_p.h6
176 files changed, 2057 insertions, 1471 deletions
diff --git a/src/widgets/dialogs/qcolordialog.cpp b/src/widgets/dialogs/qcolordialog.cpp
index 7132bb3297..c0bacd553d 100644
--- a/src/widgets/dialogs/qcolordialog.cpp
+++ b/src/widgets/dialogs/qcolordialog.cpp
@@ -646,7 +646,7 @@ void QColorWell::mouseMoveEvent(QMouseEvent *e)
drg->setMimeData(mime);
drg->setPixmap(pix);
mousePressed = false;
- drg->start();
+ drg->exec(Qt::CopyAction);
}
#endif
}
@@ -842,8 +842,8 @@ void QColorLuminancePicker::paintEvent(QPaintEvent *)
p.drawPixmap(1, coff, *pix);
const QPalette &g = palette();
qDrawShadePanel(&p, r, g, true);
- p.setPen(g.foreground().color());
- p.setBrush(g.foreground());
+ p.setPen(g.windowText().color());
+ p.setBrush(g.windowText());
QPolygon a;
int y = val2y(val);
a.setPoints(3, w, y, w+5, y+5, w+5, y-5);
@@ -1131,7 +1131,7 @@ void QColorShowLabel::mouseMoveEvent(QMouseEvent *e)
drg->setMimeData(mime);
drg->setPixmap(pix);
mousePressed = false;
- drg->start();
+ drg->exec(Qt::CopyAction);
}
#endif
}
@@ -1179,7 +1179,8 @@ QColorShower::QColorShower(QColorDialog *parent)
curQColor = Qt::white;
gl = new QGridLayout(this);
- gl->setMargin(gl->spacing());
+ const int s = gl->spacing();
+ gl->setContentsMargins(s, s, s, s);
lab = new QColorShowLabel(this);
#ifdef QT_SMALL_COLORDIALOG
@@ -1807,7 +1808,7 @@ void QColorDialogPrivate::initWidgets()
rightLay->addStretch();
cs = new QColorShower(q);
- pickLay->setMargin(cs->gl->margin());
+ pickLay->setContentsMargins(cs->gl->contentsMargins());
QObject::connect(cs, SIGNAL(newCol(QRgb)), q, SLOT(_q_newColorTypedIn(QRgb)));
QObject::connect(cs, SIGNAL(currentColorChanged(QColor)),
q, SIGNAL(currentColorChanged(QColor)));
@@ -1816,7 +1817,7 @@ void QColorDialogPrivate::initWidgets()
#else
rightLay->addWidget(cs);
if (leftLay)
- leftLay->addSpacing(cs->gl->margin());
+ leftLay->addSpacing(cs->gl->contentsMargins().right());
#endif
buttons = new QDialogButtonBox(q);
diff --git a/src/widgets/dialogs/qdialog.cpp b/src/widgets/dialogs/qdialog.cpp
index 1c10e3e786..caab6c16ba 100644
--- a/src/widgets/dialogs/qdialog.cpp
+++ b/src/widgets/dialogs/qdialog.cpp
@@ -148,7 +148,7 @@ bool QDialogPrivate::canBeNativeDialog() const
/*!
\internal
- Properly hides dialog and sets the \p resultCode
+ Properly hides dialog and sets the \a resultCode.
*/
void QDialogPrivate::hide(int resultCode)
{
@@ -164,8 +164,8 @@ void QDialogPrivate::hide(int resultCode)
/*!
\internal
- Emits finished() signal with \p resultCode. If the \p dialogCode
- is equal to 0 emits rejected(), if the \p dialogCode is equal to
+ Emits finished() signal with \a resultCode. If the \a dialogCode
+ is equal to 0 emits rejected(), if the \a dialogCode is equal to
1 emits accepted().
*/
void QDialogPrivate::finalize(int resultCode, int dialogCode)
@@ -429,7 +429,7 @@ QDialog::~QDialog()
/*!
\internal
This function is called by the push button \a pushButton when it
- becomes the default button. If \a pushButton is 0, the dialogs
+ becomes the default button. If \a pushButton is \nullptr, the dialogs
default default button becomes the default button. This is what a
push button calls when it loses focus.
*/
@@ -767,12 +767,31 @@ void QDialog::setVisible(bool visible)
if (!testAttribute(Qt::WA_DontShowOnScreen) && d->canBeNativeDialog() && d->setNativeDialogVisible(visible))
return;
+ // We should not block windows by the invisible modal dialog
+ // if a platform-specific dialog is implemented as an in-process
+ // Qt window, because in this case it will also be blocked.
+ const bool dontBlockWindows = testAttribute(Qt::WA_DontShowOnScreen)
+ && d->styleHint(QPlatformDialogHelper::DialogIsQtWindow).toBool();
+ Qt::WindowModality oldModality;
+ bool wasModalitySet;
+
+ if (dontBlockWindows) {
+ oldModality = windowModality();
+ wasModalitySet = testAttribute(Qt::WA_SetWindowModality);
+ setWindowModality(Qt::NonModal);
+ }
+
if (visible) {
if (testAttribute(Qt::WA_WState_ExplicitShowHide) && !testAttribute(Qt::WA_WState_Hidden))
return;
QWidget::setVisible(visible);
+#if QT_DEPRECATED_SINCE(5, 13)
+QT_WARNING_PUSH
+QT_WARNING_DISABLE_DEPRECATED
showExtension(d->doShowExtension);
+QT_WARNING_POP
+#endif
QWidget *fw = window()->focusWidget();
if (!fw)
fw = this;
@@ -833,6 +852,11 @@ void QDialog::setVisible(bool visible)
d->eventLoop->exit();
}
+ if (dontBlockWindows) {
+ setWindowModality(oldModality);
+ setAttribute(Qt::WA_SetWindowModality, wasModalitySet);
+ }
+
#if QT_CONFIG(pushbutton)
const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme();
if (d->mainDef && isActiveWindow()
@@ -934,6 +958,7 @@ void QDialog::adjustPosition(QWidget* w)
move(p);
}
+#if QT_DEPRECATED_SINCE(5, 13)
/*!
\obsolete
@@ -1002,7 +1027,7 @@ void QDialog::setExtension(QWidget* extension)
/*!
\obsolete
- Returns the dialog's extension or 0 if no extension has been
+ Returns the dialog's extension or \nullptr if no extension has been
defined.
Instead of using this functionality, we recommend that you simply call
@@ -1078,7 +1103,7 @@ void QDialog::showExtension(bool showIt)
#endif
}
}
-
+#endif
/*! \reimp */
QSize QDialog::sizeHint() const
diff --git a/src/widgets/dialogs/qdialog.h b/src/widgets/dialogs/qdialog.h
index 7f267dd939..ce57ce5de7 100644
--- a/src/widgets/dialogs/qdialog.h
+++ b/src/widgets/dialogs/qdialog.h
@@ -69,11 +69,12 @@ public:
void setVisible(bool visible) override;
- void setOrientation(Qt::Orientation orientation);
- Qt::Orientation orientation() const;
-
- void setExtension(QWidget* extension);
- QWidget* extension() const;
+#if QT_DEPRECATED_SINCE(5, 13)
+ QT_DEPRECATED void setOrientation(Qt::Orientation orientation);
+ QT_DEPRECATED Qt::Orientation orientation() const;
+ QT_DEPRECATED void setExtension(QWidget* extension);
+ QT_DEPRECATED QWidget* extension() const;
+#endif
QSize sizeHint() const override;
QSize minimumSizeHint() const override;
@@ -96,7 +97,9 @@ public Q_SLOTS:
virtual void accept();
virtual void reject();
- void showExtension(bool);
+#if QT_DEPRECATED_SINCE(5, 13)
+ QT_DEPRECATED void showExtension(bool);
+#endif
protected:
QDialog(QDialogPrivate &, QWidget *parent, Qt::WindowFlags f = Qt::WindowFlags());
diff --git a/src/widgets/dialogs/qfiledialog.cpp b/src/widgets/dialogs/qfiledialog.cpp
index eb3479b3e0..f772eb1241 100644
--- a/src/widgets/dialogs/qfiledialog.cpp
+++ b/src/widgets/dialogs/qfiledialog.cpp
@@ -73,6 +73,9 @@
#elif defined(Q_OS_WIN)
# include <QtCore/qt_windows.h>
#endif
+#if defined(Q_OS_WASM)
+#include <private/qwasmlocalfileaccess_p.h>
+#endif
QT_BEGIN_NAMESPACE
@@ -584,10 +587,13 @@ void QFileDialogPrivate::retranslateWindowTitle()
return;
if (q->acceptMode() == QFileDialog::AcceptOpen) {
const QFileDialog::FileMode fileMode = q->fileMode();
+QT_WARNING_PUSH
+QT_WARNING_DISABLE_DEPRECATED
if (fileMode == QFileDialog::DirectoryOnly || fileMode == QFileDialog::Directory)
q->setWindowTitle(QFileDialog::tr("Find Directory"));
else
q->setWindowTitle(QFileDialog::tr("Open"));
+QT_WARNING_POP
} else
q->setWindowTitle(QFileDialog::tr("Save As"));
@@ -611,7 +617,10 @@ void QFileDialogPrivate::updateFileNameLabel()
setLabelTextControl(QFileDialog::FileName, options->labelText(QFileDialogOptions::FileName));
} else {
switch (q_func()->fileMode()) {
+QT_WARNING_PUSH
+QT_WARNING_DISABLE_DEPRECATED
case QFileDialog::DirectoryOnly:
+QT_WARNING_POP
case QFileDialog::Directory:
setLabelTextControl(QFileDialog::FileName, QFileDialog::tr("Directory:"));
break;
@@ -639,7 +648,10 @@ void QFileDialogPrivate::updateOkButtonText(bool saveAsOnFolder)
return;
} else {
switch (q->fileMode()) {
+QT_WARNING_PUSH
+QT_WARNING_DISABLE_DEPRECATED
case QFileDialog::DirectoryOnly:
+QT_WARNING_POP
case QFileDialog::Directory:
setLabelTextControl(QFileDialog::Accept, QFileDialog::tr("&Choose"));
break;
@@ -1359,6 +1371,7 @@ void QFileDialog::setNameFilter(const QString &filter)
}
+#if QT_DEPRECATED_SINCE(5, 13)
/*!
\property QFileDialog::nameFilterDetailsVisible
\obsolete
@@ -1380,6 +1393,7 @@ bool QFileDialog::isNameFilterDetailsVisible() const
{
return !testOption(HideNameFilterDetails);
}
+#endif
/*
@@ -1704,7 +1718,10 @@ void QFileDialog::setFileMode(QFileDialog::FileMode mode)
d->options->setFileMode(static_cast<QFileDialogOptions::FileMode>(mode));
// keep ShowDirsOnly option in sync with fileMode (BTW, DirectoryOnly is obsolete)
+QT_WARNING_PUSH
+QT_WARNING_DISABLE_DEPRECATED
setOption(ShowDirsOnly, mode == DirectoryOnly);
+QT_WARNING_POP
if (!d->usingWidgets())
return;
@@ -1722,11 +1739,14 @@ void QFileDialog::setFileMode(QFileDialog::FileMode mode)
// set filter
d->model->setFilter(d->filterForMode(filter()));
// setup file type for directory
+QT_WARNING_PUSH
+QT_WARNING_DISABLE_DEPRECATED
if (mode == DirectoryOnly || mode == Directory) {
d->qFileDialogUi->fileTypeCombo->clear();
d->qFileDialogUi->fileTypeCombo->addItem(tr("Directories"));
d->qFileDialogUi->fileTypeCombo->setEnabled(false);
}
+QT_WARNING_POP
d->updateFileNameLabel();
d->updateOkButtonText();
d->qFileDialogUi->fileTypeCombo->setEnabled(!testOption(ShowDirsOnly));
@@ -1859,6 +1879,7 @@ QFileDialog::AcceptMode QFileDialog::acceptMode() const
return static_cast<AcceptMode>(d->options->acceptMode());
}
+#if QT_DEPRECATED_SINCE(5, 13)
/*!
\property QFileDialog::readOnly
\obsolete
@@ -1918,6 +1939,7 @@ bool QFileDialog::confirmOverwrite() const
{
return !testOption(DontConfirmOverwrite);
}
+#endif
/*!
\property QFileDialog::defaultSuffix
@@ -2122,8 +2144,8 @@ QString QFileDialog::labelText(DialogLabel label) const
\snippet code/src_gui_dialogs_qfiledialog.cpp 8
The function creates a modal file dialog with the given \a parent widget.
- If \a parent is not 0, the dialog will be shown centered over the parent
- widget.
+ If \a parent is not \nullptr, the dialog will be shown centered over the
+ parent widget.
The file dialog's working directory will be set to \a dir. If \a dir
includes a file name, the file will be selected. Only files that match the
@@ -2145,8 +2167,8 @@ QString QFileDialog::labelText(DialogLabel label) const
native file dialog and not a QFileDialog.
On Windows the dialog will spin a blocking modal event loop that will not
- dispatch any QTimers, and if \a parent is not 0 then it will position the
- dialog just below the parent's title bar.
+ dispatch any QTimers, and if \a parent is not \nullptr then it will position
+ the dialog just below the parent's title bar.
On Unix/X11, the normal behavior of the file dialog is to resolve and
follow symlinks. For example, if \c{/usr/tmp} is a symlink to \c{/var/tmp},
@@ -2235,8 +2257,8 @@ QUrl QFileDialog::getOpenFileUrl(QWidget *parent,
\snippet code/src_gui_dialogs_qfiledialog.cpp 9
This function creates a modal file dialog with the given \a parent widget.
- If \a parent is not 0, the dialog will be shown centered over the parent
- widget.
+ If \a parent is not \nullptr, the dialog will be shown centered over the
+ parent widget.
The file dialog's working directory will be set to \a dir. If \a dir
includes a file name, the file will be selected. The filter is set to
@@ -2254,8 +2276,8 @@ QUrl QFileDialog::getOpenFileUrl(QWidget *parent,
native file dialog and not a QFileDialog.
On Windows the dialog will spin a blocking modal event loop that will not
- dispatch any QTimers, and if \a parent is not 0 then it will position the
- dialog just below the parent's title bar.
+ dispatch any QTimers, and if \a parent is not \nullptr then it will position
+ the dialog just below the parent's title bar.
On Unix/X11, the normal behavior of the file dialog is to resolve and
follow symlinks. For example, if \c{/usr/tmp} is a symlink to \c{/var/tmp},
@@ -2344,12 +2366,91 @@ QList<QUrl> QFileDialog::getOpenFileUrls(QWidget *parent,
}
/*!
+ This is a convenience static function that will return the content of a file
+ selected by the user.
+
+ This function is used to access local files on Qt for WebAssembly, where the web
+ sandbox places restrictions on how such access may happen. Its implementation will
+ make the browser display a native file dialog, where the user makes the file selection.
+
+ It can also be used on other platforms, where it will fall back to using QFileDialog.
+
+ The function is asynchronous and returns immediately. The \a fileOpenCompleted
+ callback will be called when a file has been selected and its contents has been
+ read into memory.
+
+ \snippet code/src_gui_dialogs_qfiledialog.cpp 14
+ \since 5.13
+*/
+void QFileDialog::getOpenFileContent(const QString &nameFilter, const std::function<void(const QString &, const QByteArray &)> &fileOpenCompleted)
+{
+#ifdef Q_OS_WASM
+ auto openFileImpl = std::make_shared<std::function<void(void)>>();
+ QString fileName;
+ QByteArray fileContent;
+ *openFileImpl = [=]() mutable {
+ auto fileDialogClosed = [&](bool fileSelected) {
+ if (!fileSelected) {
+ fileOpenCompleted(fileName, fileContent);
+ openFileImpl.reset();
+ }
+ };
+ auto acceptFile = [&](uint64_t size, const std::string name) -> char * {
+ const uint64_t twoGB = 1ULL << 31; // QByteArray limit
+ if (size > twoGB)
+ return nullptr;
+
+ fileName = QString::fromStdString(name);
+ fileContent.resize(size);
+ return fileContent.data();
+ };
+ auto fileContentReady = [&]() mutable {
+ fileOpenCompleted(fileName, fileContent);
+ openFileImpl.reset();
+ };
+
+ auto qtFilterStringToWebAcceptString = [](const QString &qtString) {
+ // The Qt and Web name filter string formats are similar, but
+ // not identical.
+ return qtString.toStdString(); // ### TODO
+ };
+
+ QWasmLocalFileAccess::openFile(qtFilterStringToWebAcceptString(nameFilter), fileDialogClosed, acceptFile, fileContentReady);
+ };
+
+ (*openFileImpl)();
+#else
+ QFileDialog *dialog = new QFileDialog();
+ dialog->selectNameFilter(nameFilter);
+
+ auto fileSelected = [=](const QString &fileName) {
+ QByteArray fileContent;
+ if (!fileName.isNull()) {
+ QFile selectedFile(fileName);
+ selectedFile.open(QIODevice::ReadOnly);
+ fileContent = selectedFile.readAll();
+ }
+ fileOpenCompleted(fileName, fileContent);
+ };
+
+ auto dialogClosed = [=](int code) {
+ Q_UNUSED(code);
+ delete dialog;
+ };
+
+ connect(dialog, &QFileDialog::fileSelected, fileSelected);
+ connect(dialog, &QFileDialog::finished, dialogClosed);
+ dialog->show();
+#endif
+}
+
+/*!
This is a convenience static function that will return a file name selected
by the user. The file does not have to exist.
It creates a modal file dialog with the given \a parent widget. If
- \a parent is not 0, the dialog will be shown centered over the parent
- widget.
+ \a parent is not \nullptr, the dialog will be shown centered over the
+ parent widget.
\snippet code/src_gui_dialogs_qfiledialog.cpp 11
@@ -2375,9 +2476,9 @@ QList<QUrl> QFileDialog::getOpenFileUrls(QWidget *parent,
native file dialog and not a QFileDialog.
On Windows the dialog will spin a blocking modal event loop that will not
- dispatch any QTimers, and if \a parent is not 0 then it will position the
- dialog just below the parent's title bar. On \macos, with its native file
- dialog, the filter argument is ignored.
+ dispatch any QTimers, and if \a parent is not \nullptr then it will
+ position the dialog just below the parent's title bar. On \macos, with its
+ native file dialog, the filter argument is ignored.
On Unix/X11, the normal behavior of the file dialog is to resolve and
follow symlinks. For example, if \c{/usr/tmp} is a symlink to \c{/var/tmp},
@@ -2467,8 +2568,8 @@ QUrl QFileDialog::getSaveFileUrl(QWidget *parent,
\snippet code/src_gui_dialogs_qfiledialog.cpp 12
This function creates a modal file dialog with the given \a parent widget.
- If \a parent is not 0, the dialog will be shown centered over the parent
- widget.
+ If \a parent is not \nullptr, the dialog will be shown centered over the
+ parent widget.
The dialog's working directory is set to \a dir, and the caption is set to
\a caption. Either of these may be an empty string in which case the
@@ -2492,8 +2593,8 @@ QUrl QFileDialog::getSaveFileUrl(QWidget *parent,
symlinks as regular directories.
On Windows, the dialog will spin a blocking modal event loop that will not
- dispatch any QTimers, and if \a parent is not 0 then it will position the
- dialog just below the parent's title bar.
+ dispatch any QTimers, and if \a parent is not \nullptr then it will position
+ the dialog just below the parent's title bar.
\warning Do not delete \a parent during the execution of the dialog. If you
want to do this, you should create the dialog yourself using one of the
@@ -2548,7 +2649,10 @@ QUrl QFileDialog::getExistingDirectoryUrl(QWidget *parent,
args.parent = parent;
args.caption = caption;
args.directory = QFileDialogPrivate::workingDirectory(dir);
+QT_WARNING_PUSH
+QT_WARNING_DISABLE_DEPRECATED
args.mode = (options & ShowDirsOnly ? DirectoryOnly : Directory);
+QT_WARNING_POP
args.options = options;
QFileDialog dialog(args);
@@ -2661,7 +2765,10 @@ void QFileDialog::accept()
}
switch (fileMode()) {
+QT_WARNING_PUSH
+QT_WARNING_DISABLE_DEPRECATED
case DirectoryOnly:
+QT_WARNING_POP
case Directory: {
QString fn = files.first();
QFileInfo info(fn);
@@ -2697,7 +2804,7 @@ void QFileDialog::accept()
}
// check if we have to ask for permission to overwrite the file
- if (!info.exists() || !confirmOverwrite() || acceptMode() == AcceptOpen) {
+ if (!info.exists() || testOption(DontConfirmOverwrite) || acceptMode() == AcceptOpen) {
d->emitFilesSelected(QStringList(fn));
QDialog::accept();
#if QT_CONFIG(messagebox)
@@ -3565,7 +3672,10 @@ void QFileDialogPrivate::_q_updateOkButton()
isOpenDirectory = true;
} else {
switch (fileMode) {
+QT_WARNING_PUSH
+QT_WARNING_DISABLE_DEPRECATED
case QFileDialog::DirectoryOnly:
+QT_WARNING_POP
case QFileDialog::Directory: {
QString fn = files.first();
QModelIndex idx = model->index(fn);
@@ -3657,12 +3767,15 @@ void QFileDialogPrivate::_q_enterDirectory(const QModelIndex &index)
const QFileDialog::FileMode fileMode = q->fileMode();
q->setDirectory(path);
emit q->directoryEntered(path);
+QT_WARNING_PUSH
+QT_WARNING_DISABLE_DEPRECATED
if (fileMode == QFileDialog::Directory
|| fileMode == QFileDialog::DirectoryOnly) {
// ### find out why you have to do both of these.
lineEdit()->setText(QString());
lineEdit()->clear();
}
+QT_WARNING_POP
} else {
// Do not accept when shift-clicking to multi-select a file in environments with single-click-activation (KDE)
if (!q->style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick, nullptr, qFileDialogUi->treeView)
@@ -3695,7 +3808,7 @@ void QFileDialogPrivate::_q_goToDirectory(const QString &path)
}
QDir dir(path2);
if (!dir.exists())
- dir = getEnvironmentVariable(path2);
+ dir.setPath(getEnvironmentVariable(path2));
if (dir.exists() || path2.isEmpty() || path2 == model->myComputer().toString()) {
_q_enterDirectory(index);
@@ -3754,7 +3867,10 @@ void QFileDialogPrivate::_q_selectionChanged()
{
const QFileDialog::FileMode fileMode = q_func()->fileMode();
const QModelIndexList indexes = qFileDialogUi->listView->selectionModel()->selectedRows();
+QT_WARNING_PUSH
+QT_WARNING_DISABLE_DEPRECATED
bool stripDirs = (fileMode != QFileDialog::DirectoryOnly && fileMode != QFileDialog::Directory);
+QT_WARNING_POP
QStringList allFiles;
for (const auto &index : indexes) {
@@ -3806,10 +3922,13 @@ void QFileDialogPrivate::_q_rowsInserted(const QModelIndex &parent)
void QFileDialogPrivate::_q_fileRenamed(const QString &path, const QString &oldName, const QString &newName)
{
const QFileDialog::FileMode fileMode = q_func()->fileMode();
+QT_WARNING_PUSH
+QT_WARNING_DISABLE_DEPRECATED
if (fileMode == QFileDialog::Directory || fileMode == QFileDialog::DirectoryOnly) {
if (path == rootPath() && lineEdit()->text() == oldName)
lineEdit()->setText(newName);
}
+QT_WARNING_POP
}
void QFileDialogPrivate::_q_emitUrlSelected(const QUrl &file)
diff --git a/src/widgets/dialogs/qfiledialog.h b/src/widgets/dialogs/qfiledialog.h
index a4d289a77a..95e03618ac 100644
--- a/src/widgets/dialogs/qfiledialog.h
+++ b/src/widgets/dialogs/qfiledialog.h
@@ -46,6 +46,8 @@
#include <QtCore/qurl.h>
#include <QtWidgets/qdialog.h>
+#include <functional>
+
QT_REQUIRE_CONFIG(filedialog);
QT_BEGIN_NAMESPACE
@@ -64,19 +66,22 @@ class Q_WIDGETS_EXPORT QFileDialog : public QDialog
Q_PROPERTY(ViewMode viewMode READ viewMode WRITE setViewMode)
Q_PROPERTY(FileMode fileMode READ fileMode WRITE setFileMode)
Q_PROPERTY(AcceptMode acceptMode READ acceptMode WRITE setAcceptMode)
+ Q_PROPERTY(QString defaultSuffix READ defaultSuffix WRITE setDefaultSuffix)
+#if QT_DEPRECATED_SINCE(5, 13)
Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly DESIGNABLE false)
- Q_PROPERTY(bool resolveSymlinks READ resolveSymlinks WRITE setResolveSymlinks DESIGNABLE false)
Q_PROPERTY(bool confirmOverwrite READ confirmOverwrite WRITE setConfirmOverwrite DESIGNABLE false)
- Q_PROPERTY(QString defaultSuffix READ defaultSuffix WRITE setDefaultSuffix)
+ Q_PROPERTY(bool resolveSymlinks READ resolveSymlinks WRITE setResolveSymlinks DESIGNABLE false)
Q_PROPERTY(bool nameFilterDetailsVisible READ isNameFilterDetailsVisible
WRITE setNameFilterDetailsVisible DESIGNABLE false)
+#endif
Q_PROPERTY(Options options READ options WRITE setOptions)
Q_PROPERTY(QStringList supportedSchemes READ supportedSchemes WRITE setSupportedSchemes)
public:
enum ViewMode { Detail, List };
Q_ENUM(ViewMode)
- enum FileMode { AnyFile, ExistingFile, Directory, ExistingFiles, DirectoryOnly };
+ enum FileMode { AnyFile, ExistingFile, Directory, ExistingFiles,
+ DirectoryOnly Q_DECL_ENUMERATOR_DEPRECATED_X("Use setOption(ShowDirsOnly, true) instead")};
Q_ENUM(FileMode)
enum AcceptMode { AcceptOpen, AcceptSave };
Q_ENUM(AcceptMode)
@@ -117,8 +122,12 @@ public:
void selectUrl(const QUrl &url);
QList<QUrl> selectedUrls() const;
+#if QT_DEPRECATED_SINCE(5, 13)
+ QT_DEPRECATED_X("Use setOption(HideNameFilterDetails, !enabled) instead")
void setNameFilterDetailsVisible(bool enabled);
+ QT_DEPRECATED_X("Use !testOption(HideNameFilterDetails) instead")
bool isNameFilterDetailsVisible() const;
+#endif
void setNameFilter(const QString &filter);
void setNameFilters(const QStringList &filters);
@@ -145,11 +154,15 @@ public:
void setAcceptMode(AcceptMode mode);
AcceptMode acceptMode() const;
+#if QT_DEPRECATED_SINCE(5, 13)
void setReadOnly(bool enabled);
bool isReadOnly() const;
+ QT_DEPRECATED_X("Use setOption(DontResolveSymlinks, !enabled) instead")
void setResolveSymlinks(bool enabled);
+ QT_DEPRECATED_X("Use !testOption(DontResolveSymlinks) instead")
bool resolveSymlinks() const;
+#endif
void setSidebarUrls(const QList<QUrl> &urls);
QList<QUrl> sidebarUrls() const;
@@ -157,8 +170,12 @@ public:
QByteArray saveState() const;
bool restoreState(const QByteArray &state);
+#if QT_DEPRECATED_SINCE(5, 13)
+ QT_DEPRECATED_X("Use setOption(DontConfirmOverwrite, !enabled) instead")
void setConfirmOverwrite(bool enabled);
+ QT_DEPRECATED_X("Use !testOption(DontConfirmOverwrite) instead")
bool confirmOverwrite() const;
+#endif
void setDefaultSuffix(const QString &suffix);
QString defaultSuffix() const;
@@ -263,6 +280,8 @@ public:
Options options = Options(),
const QStringList &supportedSchemes = QStringList());
+ static void getOpenFileContent(const QString &nameFilter,
+ const std::function<void(const QString &, const QByteArray &)> &fileContentsReady);
protected:
QFileDialog(const QFileDialogArgs &args);
diff --git a/src/widgets/dialogs/qfiledialog_p.h b/src/widgets/dialogs/qfiledialog_p.h
index 2e49696b77..463c77aa23 100644
--- a/src/widgets/dialogs/qfiledialog_p.h
+++ b/src/widgets/dialogs/qfiledialog_p.h
@@ -164,13 +164,9 @@ public:
QDir::Filters filterForMode(QDir::Filters filters) const
{
- const QFileDialog::FileMode fileMode = q_func()->fileMode();
- if (fileMode == QFileDialog::DirectoryOnly) {
- filters |= QDir::Drives | QDir::AllDirs | QDir::Dirs;
+ filters |= QDir::Drives | QDir::AllDirs | QDir::Dirs | QDir::Files;
+ if (q_func()->testOption(QFileDialog::ShowDirsOnly))
filters &= ~QDir::Files;
- } else {
- filters |= QDir::Drives | QDir::AllDirs | QDir::Files | QDir::Dirs;
- }
return filters;
}
@@ -290,7 +286,7 @@ private:
virtual void helperPrepareShow(QPlatformDialogHelper *) override;
virtual void helperDone(QDialog::DialogCode, QPlatformDialogHelper *) override;
- Q_DISABLE_COPY(QFileDialogPrivate)
+ Q_DISABLE_COPY_MOVE(QFileDialogPrivate)
};
class QFileDialogLineEdit : public QLineEdit
diff --git a/src/widgets/dialogs/qfontdialog.cpp b/src/widgets/dialogs/qfontdialog.cpp
index 477c6bd540..2b81180ecb 100644
--- a/src/widgets/dialogs/qfontdialog.cpp
+++ b/src/widgets/dialogs/qfontdialog.cpp
@@ -534,7 +534,7 @@ void QFontDialogPrivate::updateFamilies()
//and try some fall backs
match_t type = MATCH_NONE;
- if (bestFamilyType <= MATCH_NONE && familyName2 == f.lastResortFamily())
+ if (bestFamilyType <= MATCH_NONE && familyName2 == QStringLiteral("helvetica"))
type = MATCH_LAST_RESORT;
if (bestFamilyType <= MATCH_LAST_RESORT && familyName2 == f.family())
type = MATCH_APP;
diff --git a/src/widgets/dialogs/qmessagebox.cpp b/src/widgets/dialogs/qmessagebox.cpp
index ac1952a642..f143e3b527 100644
--- a/src/widgets/dialogs/qmessagebox.cpp
+++ b/src/widgets/dialogs/qmessagebox.cpp
@@ -113,7 +113,7 @@ public:
, copyAvailable(false)
{
QVBoxLayout *layout = new QVBoxLayout;
- layout->setMargin(0);
+ layout->setContentsMargins(QMargins());
QFrame *line = new QFrame(this);
line->setFrameShape(QFrame::HLine);
line->setFrameShadow(QFrame::Sunken);
@@ -834,7 +834,7 @@ QMessageBox::QMessageBox(QWidget *parent)
The message box is an \l{Qt::ApplicationModal} {application modal}
dialog box.
- On \macos, if \a parent is not 0 and you want your message box
+ On \macos, if \a parent is not \nullptr and you want your message box
to appear as a Qt::Sheet of that parent, set the message box's
\l{setWindowModality()} {window modality} to Qt::WindowModal
(default). Otherwise, the message box will be a standard dialog.
@@ -983,7 +983,7 @@ QMessageBox::StandardButton QMessageBox::standardButton(QAbstractButton *button)
\since 4.2
Returns a pointer corresponding to the standard button \a which,
- or 0 if the standard button doesn't exist in this message box.
+ or \nullptr if the standard button doesn't exist in this message box.
\sa standardButtons, standardButton()
*/
@@ -1106,7 +1106,7 @@ void QMessageBoxPrivate::detectEscapeButton()
\since 4.2
Returns the button that was clicked by the user,
- or 0 if the user hit the \uicontrol Esc key and
+ or \nullptr if the user hit the \uicontrol Esc key and
no \l{setEscapeButton()}{escape button} was set.
If exec() hasn't been called yet, returns nullptr.
@@ -1173,7 +1173,7 @@ void QMessageBox::setDefaultButton(QMessageBox::StandardButton button)
/*! \since 5.2
Sets the checkbox \a cb on the message dialog. The message box takes ownership of the checkbox.
- The argument \a cb can be 0 to remove an existing checkbox from the message box.
+ The argument \a cb can be \nullptr to remove an existing checkbox from the message box.
\sa checkBox()
*/
@@ -1205,7 +1205,7 @@ void QMessageBox::setCheckBox(QCheckBox *cb)
/*! \since 5.2
- Returns the checkbox shown on the dialog. This is 0 if no checkbox is set.
+ Returns the checkbox shown on the dialog. This is \nullptr if no checkbox is set.
\sa setCheckBox()
*/
@@ -1570,7 +1570,7 @@ QList<QAbstractButton *> QMessageBox::buttons() const
\since 4.5
Returns the button role for the specified \a button. This function returns
- \l InvalidRole if \a button is 0 or has not been added to the message box.
+ \l InvalidRole if \a button is \nullptr or has not been added to the message box.
\sa buttons(), addButton()
*/
@@ -1835,7 +1835,7 @@ void QMessageBox::about(QWidget *parent, const QString &title, const QString &te
/*!
Displays a simple message box about Qt, with the given \a title
- and centered over \a parent (if \a parent is not 0). The message
+ and centered over \a parent (if \a parent is not \nullptr). The message
includes the version number of Qt being used by the application.
This is useful for inclusion in the \uicontrol Help menu of an application,
diff --git a/src/widgets/dialogs/qmessagebox.h b/src/widgets/dialogs/qmessagebox.h
index 4b993a9e65..0a2edb1eee 100644
--- a/src/widgets/dialogs/qmessagebox.h
+++ b/src/widgets/dialogs/qmessagebox.h
@@ -284,9 +284,9 @@ public:
Q_SIGNALS:
void buttonClicked(QAbstractButton *button);
-#ifdef Q_QDOC
+#ifdef Q_CLANG_QDOC
public Q_SLOTS:
- int exec();
+ int exec() override;
#endif
protected:
diff --git a/src/widgets/dialogs/qprogressdialog.cpp b/src/widgets/dialogs/qprogressdialog.cpp
index e1fb1055ae..078dd6463b 100644
--- a/src/widgets/dialogs/qprogressdialog.cpp
+++ b/src/widgets/dialogs/qprogressdialog.cpp
@@ -47,7 +47,6 @@
#include "qapplication.h"
#include "qstyle.h"
#include "qpushbutton.h"
-#include "qcursor.h"
#include "qtimer.h"
#include "qelapsedtimer.h"
#include <private/qdialog_p.h>
@@ -94,9 +93,6 @@ public:
bool cancellation_flag;
bool setValue_called;
QElapsedTimer starttime;
-#ifndef QT_NO_CURSOR
- QCursor parentCursor;
-#endif
int showTime;
bool autoClose;
bool autoReset;
@@ -597,12 +593,6 @@ void QProgressDialog::setRange(int minimum, int maximum)
void QProgressDialog::reset()
{
Q_D(QProgressDialog);
-#ifndef QT_NO_CURSOR
- if (value() >= 0) {
- if (parentWidget())
- parentWidget()->setCursor(d->parentCursor);
- }
-#endif
if (d->autoClose || d->forceHide)
hide();
d->bar->reset();
diff --git a/src/widgets/dialogs/qsidebar.cpp b/src/widgets/dialogs/qsidebar.cpp
index d52f18b406..2c8c66e1e2 100644
--- a/src/widgets/dialogs/qsidebar.cpp
+++ b/src/widgets/dialogs/qsidebar.cpp
@@ -381,8 +381,6 @@ QSidebar::QSidebar(QWidget *parent) : QListView(parent)
void QSidebar::setModelAndUrls(QFileSystemModel *model, const QList<QUrl> &newUrls)
{
- // ### TODO make icon size dynamic
- setIconSize(QSize(24,24));
setUniformItemSizes(true);
urlModel = new QUrlModel(this);
urlModel->setFileSystemModel(model);
diff --git a/src/widgets/dialogs/qwizard.cpp b/src/widgets/dialogs/qwizard.cpp
index 21e1ff2778..88b187cd7f 100644
--- a/src/widgets/dialogs/qwizard.cpp
+++ b/src/widgets/dialogs/qwizard.cpp
@@ -331,7 +331,7 @@ QWizardHeader::QWizardHeader(QWidget *parent)
titleLabel->setFont(font);
layout = new QGridLayout(this);
- layout->setMargin(0);
+ layout->setContentsMargins(QMargins());
layout->setSpacing(0);
layout->setRowMinimumHeight(3, 1);
@@ -769,7 +769,7 @@ void QWizardPrivate::reset()
for (int i = history.count() - 1; i >= 0; --i)
q->cleanupPage(history.at(i));
history.clear();
- for (QWizardPage *page : pageMap)
+ for (QWizardPage *page : qAsConst(pageMap))
page->d_func()->initialized = false;
current = -1;
@@ -1032,13 +1032,13 @@ void QWizardPrivate::recreateLayout(const QWizardLayoutInfo &info)
int pageColumn = qMin(1, numColumns - 1);
if (mac) {
- mainLayout->setMargin(0);
+ mainLayout->setContentsMargins(QMargins());
mainLayout->setSpacing(0);
buttonLayout->setContentsMargins(MacLayoutLeftMargin, MacButtonTopMargin, MacLayoutRightMargin, MacLayoutBottomMargin);
- pageVBoxLayout->setMargin(7);
+ pageVBoxLayout->setContentsMargins(7, 7, 7, 7);
} else {
if (modern) {
- mainLayout->setMargin(0);
+ mainLayout->setContentsMargins(QMargins());
mainLayout->setSpacing(0);
pageVBoxLayout->setContentsMargins(deltaMarginLeft, deltaMarginTop,
deltaMarginRight, deltaMarginBottom);
@@ -2374,8 +2374,8 @@ void QWizard::removePage(int id)
/*!
\fn QWizardPage *QWizard::page(int id) const
- Returns the page with the given \a id, or 0 if there is no such
- page.
+ Returns the page with the given \a id, or \nullptr if there is no
+ such page.
\sa addPage(), setPage()
*/
@@ -2462,8 +2462,8 @@ int QWizard::startId() const
}
/*!
- Returns a pointer to the current page, or 0 if there is no current
- page (e.g., before the wizard is shown).
+ Returns a pointer to the current page, or \nullptr if there is no
+ current page (e.g., before the wizard is shown).
This is equivalent to calling page(currentId()).
@@ -2954,7 +2954,7 @@ void QWizard::setDefaultProperty(const char *className, const char *property,
Passing 0 shows no side widget.
- When the \a widget is not 0 the wizard reparents it.
+ When the \a widget is not \nullptr the wizard reparents it.
Any previous side widget is hidden.
@@ -2963,7 +2963,7 @@ void QWizard::setDefaultProperty(const char *className, const char *property,
All widgets set here will be deleted by the wizard when it is
destroyed unless you separately reparent the widget after setting
- some other side widget (or 0).
+ some other side widget (or \nullptr).
By default, no side widget is present.
*/
@@ -2981,7 +2981,7 @@ void QWizard::setSideWidget(QWidget *widget)
/*!
\since 4.7
- Returns the widget on the left side of the wizard or 0.
+ Returns the widget on the left side of the wizard or \nullptr.
By default, no side widget is present.
*/
@@ -3969,7 +3969,7 @@ void QWizardPage::registerField(const QString &name, QWidget *widget, const char
}
/*!
- Returns the wizard associated with this page, or 0 if this page
+ Returns the wizard associated with this page, or \nullptr if this page
hasn't been inserted into a QWizard yet.
\sa QWizard::addPage(), QWizard::setPage()
diff --git a/src/widgets/dialogs/qwizard_win_p.h b/src/widgets/dialogs/qwizard_win_p.h
index d302dedaa3..02c5e52c2c 100644
--- a/src/widgets/dialogs/qwizard_win_p.h
+++ b/src/widgets/dialogs/qwizard_win_p.h
@@ -84,7 +84,7 @@ class QWizard;
class QVistaHelper : public QObject
{
- Q_DISABLE_COPY(QVistaHelper)
+ Q_DISABLE_COPY_MOVE(QVistaHelper)
public:
QVistaHelper(QWizard *wizard);
~QVistaHelper() override;
diff --git a/src/widgets/doc/snippets/code/doc_src_examples_dropsite.qdoc b/src/widgets/doc/snippets/code/doc_src_examples_dropsite.qdoc
deleted file mode 100644
index a91933cdce..0000000000
--- a/src/widgets/doc/snippets/code/doc_src_examples_dropsite.qdoc
+++ /dev/null
@@ -1,55 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** 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 https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-//! [0]
-\code
-foreach(variable, container)
-\endcode
-//! [0]
diff --git a/src/widgets/doc/snippets/code/doc_src_stylesheet.qdoc b/src/widgets/doc/snippets/code/doc_src_stylesheet.qdoc
index 9af04f6b4c..098eaf4717 100644
--- a/src/widgets/doc/snippets/code/doc_src_stylesheet.qdoc
+++ b/src/widgets/doc/snippets/code/doc_src_stylesheet.qdoc
@@ -514,13 +514,15 @@ QLabel { border-width: 1px 2px 3px 4px } /* 1px 2px 3px 4px */
//! [84]
-QLabel { border-color: red } /* opaque red */
-QLabel { border-color: #FF0000 } /* opaque red */
-QLabel { border-color: rgba(255, 0, 0, 75%) } /* 75% opaque red */
-QLabel { border-color: rgb(255, 0, 0) } /* opaque red */
-QLabel { border-color: rgb(100%, 0%, 0%) } /* opaque red */
-QLabel { border-color: hsv(60, 255, 255) } /* opaque yellow */
-QLabel { border-color: hsva(240, 255, 255, 75%) } /* 75% blue */
+QLabel { border-color: red } /* opaque red */
+QLabel { border-color: #FF0000 } /* opaque red */
+QLabel { border-color: rgba(255, 0, 0, 75%) } /* 75% opaque red */
+QLabel { border-color: rgb(255, 0, 0) } /* opaque red */
+QLabel { border-color: rgb(100%, 0%, 0%) } /* opaque red */
+QLabel { border-color: hsv(60, 100%, 100%) } /* opaque yellow */
+QLabel { border-color: hsva(240, 255, 255, 75%) } /* 75% blue */
+QLabel { border-color: hsl(60, 100%, 50%) } /* opaque yellow */
+QLabel { border-color: hsla(240, 255, 50%, 75%) } /* 75% blue */
//! [84]
diff --git a/src/widgets/doc/snippets/code/src_gui_dialogs_qfiledialog.cpp b/src/widgets/doc/snippets/code/src_gui_dialogs_qfiledialog.cpp
index 06cca37111..1e9daf824b 100644
--- a/src/widgets/doc/snippets/code/src_gui_dialogs_qfiledialog.cpp
+++ b/src/widgets/doc/snippets/code/src_gui_dialogs_qfiledialog.cpp
@@ -144,3 +144,14 @@ dialog.exec();
//! [14]
"Images (*.png *.xpm *.jpg);;Text files (*.txt);;XML files (*.xml)"
//! [14]
+
+//! [14]
+auto fileOpenCompleted = [](const QSting &fileName, const QByteArray &fileContent) {
+ if (fileName.isEmpty()) {
+ // No file was selected
+ } else {
+ // Use fileName and fileContent
+ }
+}
+QFileDialog::getOpenFileContent("Images (*.png *.xpm *.jpg)", fileContentReady);
+//! [14]
diff --git a/src/widgets/doc/snippets/code/src_gui_itemviews_qdatawidgetmapper.cpp b/src/widgets/doc/snippets/code/src_gui_itemviews_qdatawidgetmapper.cpp
index 4dad563660..cc1568cb9d 100644
--- a/src/widgets/doc/snippets/code/src_gui_itemviews_qdatawidgetmapper.cpp
+++ b/src/widgets/doc/snippets/code/src_gui_itemviews_qdatawidgetmapper.cpp
@@ -59,7 +59,7 @@ mapper->toFirst();
//! [1]
-QDataWidgetMapper *mapper = new QDataWidgetMapper();
+QDataWidgetMapper *mapper = new QDataWidgetMapper;
mapper->setModel(myModel);
mapper->addMapping(nameLineEdit, 0);
mapper->addMapping(ageSpinBox, 1);
@@ -67,7 +67,7 @@ mapper->addMapping(ageSpinBox, 1);
//! [2]
-QDataWidgetMapper *mapper = new QDataWidgetMapper();
-connect(myTableView->selectionModel(), SIGNAL(currentRowChanged(QModelIndex,QModelIndex)),
- mapper, SLOT(setCurrentModelIndex(QModelIndex)));
+QDataWidgetMapper *mapper = new QDataWidgetMapper;
+connect(myTableView->selectionModel(), &QItemSelectionModel::currentRowChanged,
+ mapper, &QDataWidgetMapper::setCurrentModelIndex);
//! [2]
diff --git a/src/widgets/doc/snippets/code/src_gui_kernel_qapplication.cpp b/src/widgets/doc/snippets/code/src_gui_kernel_qapplication.cpp
index a907a0421f..0a70c1d32a 100644
--- a/src/widgets/doc/snippets/code/src_gui_kernel_qapplication.cpp
+++ b/src/widgets/doc/snippets/code/src_gui_kernel_qapplication.cpp
@@ -100,7 +100,8 @@ QSize MyWidget::sizeHint() const
//! [4]
void showAllHiddenTopLevelWidgets()
{
- foreach (QWidget *widget, QApplication::topLevelWidgets()) {
+ const QWidgetList topLevelWidgets = QApplication::topLevelWidgets();
+ for (QWidget *widget : topLevelWidgets) {
if (widget->isHidden())
widget->show();
}
@@ -111,7 +112,8 @@ void showAllHiddenTopLevelWidgets()
//! [5]
void updateAllWidgets()
{
- foreach (QWidget *widget, QApplication::allWidgets())
+ const QWidgetList allWidgets = QApplication::allWidgets();
+ for (QWidget *widget : allWidgets)
widget->update();
}
//! [5]
@@ -171,13 +173,15 @@ appname -session id
//! [10]
-foreach (const QString &command, mySession.restartCommand())
+const QStringList commands = mySession.restartCommand();
+for (const QString &command : commands)
do_something(command);
//! [10]
//! [11]
-foreach (const QString &command, mySession.discardCommand())
+const QStringList commands = mySession.discardCommand();
+for (const QString &command : commands)
do_something(command);
//! [11]
diff --git a/src/widgets/doc/snippets/code/src_gui_widgets_qmenu.cpp b/src/widgets/doc/snippets/code/src_gui_widgets_qmenu.cpp
index 4b1c4cd645..da3fd28056 100644
--- a/src/widgets/doc/snippets/code/src_gui_widgets_qmenu.cpp
+++ b/src/widgets/doc/snippets/code/src_gui_widgets_qmenu.cpp
@@ -81,7 +81,7 @@ exec(e->globalPos());
//! [6]
QMenu menu;
QAction *at = actions[0]; // Assumes actions is not empty
-foreach (QAction *a, actions)
+for (QAction *a : qAsConst(actions))
menu.addAction(a);
menu.exec(pos, at);
//! [6]
diff --git a/src/widgets/doc/snippets/dialogs/dialogs.cpp b/src/widgets/doc/snippets/dialogs/dialogs.cpp
index cca3ac8d75..7fa793c70f 100644
--- a/src/widgets/doc/snippets/dialogs/dialogs.cpp
+++ b/src/widgets/doc/snippets/dialogs/dialogs.cpp
@@ -48,7 +48,7 @@
**
****************************************************************************/
-#include <QtGui>
+#include <QtWidgets>
typedef QDialog WordCountDialog;
typedef QDialog FindDialog;
@@ -76,7 +76,8 @@ void EditorWindow::find()
{
if (!findDialog) {
findDialog = new FindDialog(this);
- connect(findDialog, SIGNAL(findNext()), this, SLOT(findNext()));
+ connect(findDialog, &FindDialog::findNext,
+ this, &EditorWindow::findNext);
}
findDialog->show();
@@ -249,9 +250,9 @@ Operation::Operation(QObject *parent)
: QObject(parent), steps(0)
{
pd = new QProgressDialog("Operation in progress.", "Cancel", 0, 100);
- connect(pd, SIGNAL(canceled()), this, SLOT(cancel()));
+ connect(pd, &QProgressDialog::canceled, this, &Operation::cancel);
t = new QTimer(this);
- connect(t, SIGNAL(timeout()), this, SLOT(perform()));
+ connect(t, &QTimer::timeout, this, &Operation::perform);
t->start(0);
}
//! [4] //! [5]
diff --git a/src/widgets/doc/snippets/dockwidgets/mainwindow.cpp b/src/widgets/doc/snippets/dockwidgets/mainwindow.cpp
index f6959cc12b..53f91589bf 100644
--- a/src/widgets/doc/snippets/dockwidgets/mainwindow.cpp
+++ b/src/widgets/doc/snippets/dockwidgets/mainwindow.cpp
@@ -48,7 +48,7 @@
**
****************************************************************************/
-#include <QtGui>
+#include <QtWidgets>
#include "mainwindow.h"
@@ -63,8 +63,8 @@ MainWindow::MainWindow(QWidget *parent)
textBrowser = new QTextBrowser(this);
- connect(headingList, SIGNAL(itemClicked(QListWidgetItem*)),
- this, SLOT(updateText(QListWidgetItem*)));
+ connect(headingList, &QListWidget::itemClicked,
+ this, &MainWindow::updateText);
updateText(headingList->item(0));
headingList->setCurrentRow(0);
@@ -119,7 +119,7 @@ void MainWindow::setupMenus()
QAction *exitAct = new QAction(tr("E&xit"), this);
exitAct->setShortcut(tr("Ctrl+Q"));
exitAct->setStatusTip(tr("Exit the application"));
- connect(exitAct, SIGNAL(triggered()), qApp, SLOT(closeAllWindows()));
+ connect(exitAct, &QAction::triggered, qApp, &QApplication::closeAllWindows);
QMenu *fileMenu = menuBar()->addMenu(tr("&File"));
fileMenu->addAction(exitAct);
diff --git a/src/widgets/doc/snippets/mdiareasnippets.cpp b/src/widgets/doc/snippets/mdiareasnippets.cpp
index b9d6f05daf..dec7aaa1e7 100644
--- a/src/widgets/doc/snippets/mdiareasnippets.cpp
+++ b/src/widgets/doc/snippets/mdiareasnippets.cpp
@@ -48,7 +48,7 @@
**
****************************************************************************/
-#include <QtGui>
+#include <QtWidgets>
void mainWindowExample()
{
@@ -95,7 +95,7 @@ int main(int argv, char **args)
QAction *act = new QAction(qApp);
act->setShortcut(Qt::ALT + Qt::Key_S);
act->setShortcutContext( Qt::ApplicationShortcut );
- QObject::connect(act, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
+ QObject::connect(act, &QAction::triggered, qApp, &QApplication::aboutQt);
QWidget widget5;
widget5.show();
diff --git a/src/widgets/doc/snippets/qlistview-dnd/mainwindow.cpp b/src/widgets/doc/snippets/qlistview-dnd/mainwindow.cpp
index c2af9c4cf1..45f1eb7aa3 100644
--- a/src/widgets/doc/snippets/qlistview-dnd/mainwindow.cpp
+++ b/src/widgets/doc/snippets/qlistview-dnd/mainwindow.cpp
@@ -73,7 +73,8 @@ listView->setDropIndicatorShown(true);
this->listView = listView;
- connect(quitAction, SIGNAL(triggered()), this, SLOT(close()));
+ connect(quitAction, &QAction::triggered,
+ this, &QWidget::close);
setupListItems();
diff --git a/src/widgets/doc/snippets/qlistview-dnd/model.cpp b/src/widgets/doc/snippets/qlistview-dnd/model.cpp
index 710bbb2964..6835479e7a 100644
--- a/src/widgets/doc/snippets/qlistview-dnd/model.cpp
+++ b/src/widgets/doc/snippets/qlistview-dnd/model.cpp
@@ -54,7 +54,7 @@
A simple model that uses a QStringList as its data source.
*/
-#include <QtGui>
+#include <QtWidgets>
#include "model.h"
@@ -121,7 +121,7 @@ bool DragDropListModel::dropMimeData(const QMimeData *data,
//! [6]
insertRows(beginRow, rows, QModelIndex());
- foreach (const QString &text, newItems) {
+ for (const QString &text : qAsConst(newItems)) {
QModelIndex idx = index(beginRow, 0, QModelIndex());
setData(idx, text);
beginRow++;
@@ -146,12 +146,12 @@ Qt::ItemFlags DragDropListModel::flags(const QModelIndex &index) const
//! [8]
QMimeData *DragDropListModel::mimeData(const QModelIndexList &indexes) const
{
- QMimeData *mimeData = new QMimeData();
+ QMimeData *mimeData = new QMimeData;
QByteArray encodedData;
QDataStream stream(&encodedData, QIODevice::WriteOnly);
- foreach (const QModelIndex &index, indexes) {
+ for (const QModelIndex &index : indexes) {
if (index.isValid()) {
QString text = data(index, Qt::DisplayRole).toString();
stream << text;
diff --git a/src/widgets/doc/snippets/qlistwidget-dnd/mainwindow.cpp b/src/widgets/doc/snippets/qlistwidget-dnd/mainwindow.cpp
index 1153250b17..70df2b112e 100644
--- a/src/widgets/doc/snippets/qlistwidget-dnd/mainwindow.cpp
+++ b/src/widgets/doc/snippets/qlistwidget-dnd/mainwindow.cpp
@@ -48,7 +48,7 @@
**
****************************************************************************/
-#include <QtGui>
+#include <QtWidgets>
#include "mainwindow.h"
@@ -74,7 +74,7 @@ listWidget->setDragDropMode(QAbstractItemView::InternalMove);
this->listWidget = listWidget;
- connect(quitAction, SIGNAL(triggered()), this, SLOT(close()));
+ connect(quitAction, &QAction::triggered, this, &QWidget::close);
setupListItems();
diff --git a/src/widgets/doc/snippets/qlistwidget-using/mainwindow.cpp b/src/widgets/doc/snippets/qlistwidget-using/mainwindow.cpp
index ff69fd2efd..13b20bb856 100644
--- a/src/widgets/doc/snippets/qlistwidget-using/mainwindow.cpp
+++ b/src/widgets/doc/snippets/qlistwidget-using/mainwindow.cpp
@@ -48,7 +48,7 @@
**
****************************************************************************/
-#include <QtGui>
+#include <QtWidgets>
#include "mainwindow.h"
@@ -77,14 +77,13 @@ MainWindow::MainWindow()
listWidget = new QListWidget(this);
listWidget->setSelectionMode(QAbstractItemView::SingleSelection);
- connect(quitAction, SIGNAL(triggered()), this, SLOT(close()));
- connect(ascendingAction, SIGNAL(triggered()), this, SLOT(sortAscending()));
- connect(descendingAction, SIGNAL(triggered()), this, SLOT(sortDescending()));
- connect(insertAction, SIGNAL(triggered()), this, SLOT(insertItem()));
- connect(removeAction, SIGNAL(triggered()), this, SLOT(removeItem()));
- connect(listWidget,
- SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)),
- this, SLOT(updateMenus(QListWidgetItem*)));
+ connect(quitAction, &QAction::triggered, this, &QWidget::close);
+ connect(ascendingAction, &QAction::triggered, this, &MainWindow::sortAscending);
+ connect(descendingAction, &QAction::triggered, this, &MainWindow::sortDescending);
+ connect(insertAction, &QAction::triggered, this, &MainWindow::insertItem);
+ connect(removeAction, &QAction::triggered, this, &MainWindow::removeItem);
+ connect(listWidget, &QListWidget::currentItemChanged,
+ this, &MainWindow::updateMenus);
setupListItems();
updateMenus(listWidget->currentItem());
diff --git a/src/widgets/doc/snippets/qsortfilterproxymodel/main.cpp b/src/widgets/doc/snippets/qsortfilterproxymodel/main.cpp
index a6284bd578..2d4b1023f1 100644
--- a/src/widgets/doc/snippets/qsortfilterproxymodel/main.cpp
+++ b/src/widgets/doc/snippets/qsortfilterproxymodel/main.cpp
@@ -48,7 +48,7 @@
**
****************************************************************************/
-#include <QtGui>
+#include <QtWidgets>
int main(int argc, char *argv[])
{
@@ -74,9 +74,8 @@ int main(int argc, char *argv[])
filteredView->setWindowTitle("Filtered view onto a string list model");
QLineEdit *patternEditor = new QLineEdit;
- QObject::
- connect(patternEditor, SIGNAL(textChanged(QString)),
- filterModel, SLOT(setFilterRegExp(QString)));
+ QObject::connect(patternEditor, &QLineEdit::textChanged,
+ filterModel, &QSortFilterProxyModel::setFilterWildcard);
QVBoxLayout *layout = new QVBoxLayout(window);
layout->addWidget(filteredView);
diff --git a/src/widgets/doc/snippets/qstackedlayout/main.cpp b/src/widgets/doc/snippets/qstackedlayout/main.cpp
index 765608848c..9c61939dee 100644
--- a/src/widgets/doc/snippets/qstackedlayout/main.cpp
+++ b/src/widgets/doc/snippets/qstackedlayout/main.cpp
@@ -48,13 +48,12 @@
**
****************************************************************************/
-#include <QtGui>
-#include <QApplication>
+#include <QtWidgets>
class Widget : public QWidget
{
public:
- Widget(QWidget *parent = 0);
+ Widget(QWidget *parent = nullptr);
};
Widget::Widget(QWidget *parent)
@@ -75,8 +74,8 @@ Widget::Widget(QWidget *parent)
pageComboBox->addItem(tr("Page 1"));
pageComboBox->addItem(tr("Page 2"));
pageComboBox->addItem(tr("Page 3"));
- connect(pageComboBox, SIGNAL(activated(int)),
- stackedLayout, SLOT(setCurrentIndex(int)));
+ connect(pageComboBox, QOverload<int>::of(&QComboBox::activated),
+ stackedLayout, &QStackedLayout::setCurrentIndex);
//! [1]
//! [2]
diff --git a/src/widgets/doc/snippets/qstackedwidget/main.cpp b/src/widgets/doc/snippets/qstackedwidget/main.cpp
index a6c9c7afe3..077c281830 100644
--- a/src/widgets/doc/snippets/qstackedwidget/main.cpp
+++ b/src/widgets/doc/snippets/qstackedwidget/main.cpp
@@ -48,8 +48,7 @@
**
****************************************************************************/
-#include <QtGui>
-#include <QApplication>
+#include <QtWidgets>
class Widget : public QWidget
{
@@ -75,8 +74,8 @@ Widget::Widget(QWidget *parent)
pageComboBox->addItem(tr("Page 1"));
pageComboBox->addItem(tr("Page 2"));
pageComboBox->addItem(tr("Page 3"));
- connect(pageComboBox, SIGNAL(activated(int)),
- stackedWidget, SLOT(setCurrentIndex(int)));
+ connect(pageComboBox, QOverload<int>::of(&QComboBox::activated),
+ stackedWidget, &QStackedWidget::setCurrentIndex);
//! [1] //! [2]
QVBoxLayout *layout = new QVBoxLayout;
diff --git a/src/widgets/doc/snippets/qtablewidget-resizing/mainwindow.cpp b/src/widgets/doc/snippets/qtablewidget-resizing/mainwindow.cpp
index 95113153e1..d2c50336f6 100644
--- a/src/widgets/doc/snippets/qtablewidget-resizing/mainwindow.cpp
+++ b/src/widgets/doc/snippets/qtablewidget-resizing/mainwindow.cpp
@@ -48,7 +48,7 @@
**
****************************************************************************/
-#include <QtGui>
+#include <QtWidgets>
#include "mainwindow.h"
@@ -72,9 +72,9 @@ MainWindow::MainWindow()
//! [0]
tableWidget->setSelectionMode(QAbstractItemView::ExtendedSelection);
- connect(quitAction, SIGNAL(triggered()), this, SLOT(close()));
- connect(tableWidthAction, SIGNAL(triggered()), this, SLOT(changeWidth()));
- connect(tableHeightAction, SIGNAL(triggered()), this, SLOT(changeHeight()));
+ connect(quitAction, &QAction::triggered, this, &QWidget::close);
+ connect(tableWidthAction, &QAction::triggered, this, &MainWindow::changeWidth);
+ connect(tableHeightAction, &QAction::triggered, this, &MainWindow::changeHeight);
setupTableItems();
diff --git a/src/widgets/doc/snippets/qtablewidget-using/mainwindow.cpp b/src/widgets/doc/snippets/qtablewidget-using/mainwindow.cpp
index 15b9457dd5..47b63b2b3f 100644
--- a/src/widgets/doc/snippets/qtablewidget-using/mainwindow.cpp
+++ b/src/widgets/doc/snippets/qtablewidget-using/mainwindow.cpp
@@ -48,8 +48,8 @@
**
****************************************************************************/
-#include <QtGui>
-#include "math.h"
+#include <QtWidgets>
+#include <math.h>
#include "mainwindow.h"
@@ -89,9 +89,9 @@ MainWindow::MainWindow()
tableWidget->setHorizontalHeaderItem(1, squaresHeaderItem);
tableWidget->setHorizontalHeaderItem(2, cubesHeaderItem);
- connect(quitAction, SIGNAL(triggered()), this, SLOT(close()));
- connect(sumItemsAction, SIGNAL(triggered()), this, SLOT(sumItems()));
- connect(averageItemsAction, SIGNAL(triggered()), this, SLOT(averageItems()));
+ connect(quitAction, &QAction::triggered, this, &QWidget::close);
+ connect(sumItemsAction, &QAction::triggered, this, &MainWindow::sumItems);
+ connect(averageItemsAction, &QAction::triggered, this, &MainWindow::averageItems);
setupTableItems();
@@ -119,12 +119,11 @@ void MainWindow::setupTableItems()
void MainWindow::averageItems()
{
- QList<QTableWidgetItem *> selected = tableWidget->selectedItems();
- QTableWidgetItem *item;
+ const QList<QTableWidgetItem *> selected = tableWidget->selectedItems();
int number = 0;
double total = 0;
- foreach (item, selected) {
+ for (QTableWidgetItem *item : selected) {
bool ok;
double value = item->text().toDouble(&ok);
@@ -140,12 +139,11 @@ void MainWindow::averageItems()
void MainWindow::sumItems()
{
//! [4]
- QList<QTableWidgetItem *> selected = tableWidget->selectedItems();
- QTableWidgetItem *item;
+ const QList<QTableWidgetItem *> selected = tableWidget->selectedItems();
int number = 0;
double total = 0;
- foreach (item, selected) {
+ for (QTableWidgetItem *item : selected) {
bool ok;
double value = item->text().toDouble(&ok);
diff --git a/src/widgets/doc/snippets/qtreewidget-using/mainwindow.cpp b/src/widgets/doc/snippets/qtreewidget-using/mainwindow.cpp
index ee7e028a13..b9e258cb03 100644
--- a/src/widgets/doc/snippets/qtreewidget-using/mainwindow.cpp
+++ b/src/widgets/doc/snippets/qtreewidget-using/mainwindow.cpp
@@ -48,7 +48,7 @@
**
****************************************************************************/
-#include <QtGui>
+#include <QtWidgets>
#include "mainwindow.h"
@@ -90,16 +90,15 @@ MainWindow::MainWindow()
treeWidget->setHeaderLabels(headers);
//! [2]
- connect(quitAction, SIGNAL(triggered()), this, SLOT(close()));
- connect(ascendingAction, SIGNAL(triggered()), this, SLOT(sortAscending()));
- connect(autoSortAction, SIGNAL(triggered()), this, SLOT(updateSortItems()));
- connect(descendingAction, SIGNAL(triggered()), this, SLOT(sortDescending()));
- connect(findItemsAction, SIGNAL(triggered()), this, SLOT(findItems()));
- connect(insertAction, SIGNAL(triggered()), this, SLOT(insertItem()));
- connect(removeAction, SIGNAL(triggered()), this, SLOT(removeItem()));
- connect(treeWidget,
- SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)),
- this, SLOT(updateMenus(QTreeWidgetItem*)));
+ connect(quitAction, &QAction::triggered, this, &QWidget::close);
+ connect(ascendingAction, &QAction::triggered, this, &MainWindow::sortAscending);
+ connect(autoSortAction, &QAction::triggered, this, &MainWindow::updateSortItems);
+ connect(descendingAction, &QAction::triggered, this, &MainWindow::sortDescending);
+ connect(findItemsAction, &QAction::triggered, this, &MainWindow::findItems);
+ connect(insertAction, &QAction::triggered, this, &MainWindow::insertItem);
+ connect(removeAction, &QAction::triggered, this, &MainWindow::removeItem);
+ connect(treeWidget, &QTreeWidget::currentItemChanged,
+ this, &MainWindow::updateMenus);
setupTreeItems();
updateMenus(treeWidget->currentItem());
@@ -150,18 +149,16 @@ void MainWindow::findItems()
if (itemText.isEmpty())
return;
-//! [6]
- QTreeWidgetItem *item;
-//! [6]
- foreach (item, treeWidget->selectedItems())
- treeWidget->setItemSelected(item, false);
+ const QList<QTreeWidgetItem *> items = treeWidget->selectedItems();
+ for (QTreeWidgetItem *item : items)
+ item->setSelected(false);
//! [7]
- QList<QTreeWidgetItem *> found = treeWidget->findItems(
+ const QList<QTreeWidgetItem *> found = treeWidget->findItems(
itemText, Qt::MatchWildcard);
- foreach (item, found) {
- treeWidget->setItemSelected(item, true);
+ for (QTreeWidgetItem *item : found) {
+ item->setSelected(true);
// Show the item->text(0) for each item.
}
//! [7]
diff --git a/src/widgets/doc/snippets/qtreewidgetitemiterator-using/mainwindow.cpp b/src/widgets/doc/snippets/qtreewidgetitemiterator-using/mainwindow.cpp
index 5f1f606185..bfe099bbb4 100644
--- a/src/widgets/doc/snippets/qtreewidgetitemiterator-using/mainwindow.cpp
+++ b/src/widgets/doc/snippets/qtreewidgetitemiterator-using/mainwindow.cpp
@@ -48,7 +48,7 @@
**
****************************************************************************/
-#include <QtGui>
+#include <QtWidgets>
#include "mainwindow.h"
@@ -85,16 +85,15 @@ MainWindow::MainWindow()
headers << tr("Subject") << tr("Default");
treeWidget->setHeaderLabels(headers);
- connect(quitAction, SIGNAL(triggered()), this, SLOT(close()));
- connect(ascendingAction, SIGNAL(triggered()), this, SLOT(sortAscending()));
- connect(autoSortAction, SIGNAL(triggered()), this, SLOT(updateSortItems()));
- connect(descendingAction, SIGNAL(triggered()), this, SLOT(sortDescending()));
- connect(findItemsAction, SIGNAL(triggered()), this, SLOT(findItems()));
- connect(insertAction, SIGNAL(triggered()), this, SLOT(insertItem()));
- connect(removeAction, SIGNAL(triggered()), this, SLOT(removeItem()));
- connect(treeWidget,
- SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)),
- this, SLOT(updateMenus(QTreeWidgetItem*)));
+ connect(quitAction, &QAction::triggered, this, &QWidget::close);
+ connect(ascendingAction, &QAction::triggered, this, &MainWindow::sortAscending);
+ connect(autoSortAction, &QAction::triggered, this, &MainWindow::updateSortItems);
+ connect(descendingAction, &QAction::triggered, this, &MainWindow::sortDescending);
+ connect(findItemsAction, &QAction::triggered, this, &MainWindow::findItems);
+ connect(insertAction, &QAction::triggered, this, &MainWindow::insertItem);
+ connect(removeAction, &QAction::triggered, this, &MainWindow::removeItem);
+ connect(treeWidget, &QTreeWidget::currentItemChanged,
+ this, &MainWindow::updateMenus);
setupTreeItems();
updateMenus(treeWidget->currentItem());
diff --git a/src/widgets/doc/snippets/reading-selections/window.cpp b/src/widgets/doc/snippets/reading-selections/window.cpp
index 08805fe4b3..045d66a199 100644
--- a/src/widgets/doc/snippets/reading-selections/window.cpp
+++ b/src/widgets/doc/snippets/reading-selections/window.cpp
@@ -81,9 +81,9 @@ MainWindow::MainWindow(QWidget *parent)
QAction *selectAllAction = actionMenu->addAction(tr("&Select All"));
menuBar()->addMenu(actionMenu);
- connect(fillAction, SIGNAL(triggered()), this, SLOT(fillSelection()));
- connect(clearAction, SIGNAL(triggered()), this, SLOT(clearSelection()));
- connect(selectAllAction, SIGNAL(triggered()), this, SLOT(selectAll()));
+ connect(fillAction, &QAction::triggered, this, &MainWindow::fillSelection);
+ connect(clearAction, &QAction::triggered, this, &MainWindow::clearSelection);
+ connect(selectAllAction, &QAction::triggered, this, &MainWindow::selectAll);
selectionModel = table->selectionModel();
@@ -94,10 +94,9 @@ MainWindow::MainWindow(QWidget *parent)
void MainWindow::fillSelection()
{
//! [0]
- QModelIndexList indexes = selectionModel->selectedIndexes();
- QModelIndex index;
+ const QModelIndexList indexes = selectionModel->selectedIndexes();
- foreach(index, indexes) {
+ for (const QModelIndex &index : indexes) {
QString text = QString("(%1,%2)").arg(index.row()).arg(index.column());
model->setData(index, text);
}
@@ -106,11 +105,10 @@ void MainWindow::fillSelection()
void MainWindow::clearSelection()
{
- QModelIndexList indexes = selectionModel->selectedIndexes();
- QModelIndex index;
+ const QModelIndexList indexes = selectionModel->selectedIndexes();
- foreach(index, indexes)
- model->setData(index, "");
+ for (const QModelIndex &index : indexes)
+ model->setData(index, QString());
}
void MainWindow::selectAll()
diff --git a/src/widgets/doc/snippets/updating-selections/window.cpp b/src/widgets/doc/snippets/updating-selections/window.cpp
index 0bdcf8a64d..26e9b56ae4 100644
--- a/src/widgets/doc/snippets/updating-selections/window.cpp
+++ b/src/widgets/doc/snippets/updating-selections/window.cpp
@@ -74,12 +74,10 @@ MainWindow::MainWindow(QWidget *parent)
table->setModel(model);
selectionModel = table->selectionModel();
- connect(selectionModel,
- SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
- this, SLOT(updateSelection(QItemSelection,QItemSelection)));
- connect(selectionModel,
- SIGNAL(currentChanged(QModelIndex,QModelIndex)),
- this, SLOT(changeCurrent(QModelIndex,QModelIndex)));
+ connect(selectionModel, &QItemSelectionModel::selectionChanged,
+ this, &MainWindow::updateSelection);
+ connect(selectionModel, &QItemSelectionModel::currentChanged,
+ this, &MainWindow::changeCurrent);
statusBar();
setCentralWidget(table);
@@ -89,10 +87,9 @@ MainWindow::MainWindow(QWidget *parent)
void MainWindow::updateSelection(const QItemSelection &selected,
const QItemSelection &deselected)
{
- QModelIndex index;
QModelIndexList items = selected.indexes();
- foreach (index, items) {
+ for (const QModelIndex &index : qAsConst(items)) {
QString text = QString("(%1,%2)").arg(index.row()).arg(index.column());
model->setData(index, text);
//! [0] //! [1]
@@ -102,8 +99,8 @@ void MainWindow::updateSelection(const QItemSelection &selected,
//! [2]
items = deselected.indexes();
- foreach (index, items)
- model->setData(index, "");
+ for (const QModelIndex &index : qAsConst(items)) {
+ model->setData(index, QString());
}
//! [2]
diff --git a/src/widgets/doc/src/model-view-programming.qdoc b/src/widgets/doc/src/model-view-programming.qdoc
index f6b7c80656..9335ff78c9 100644
--- a/src/widgets/doc/src/model-view-programming.qdoc
+++ b/src/widgets/doc/src/model-view-programming.qdoc
@@ -693,9 +693,9 @@
\l QAbstractItemDelegate class.
Delegates are expected to be able to render their contents themselves
- by implementing the \l{QItemDelegate::paint()}{paint()}
- and \l{QItemDelegate::sizeHint()}{sizeHint()} functions.
- However, simple widget-based delegates can subclass \l QItemDelegate
+ by implementing the \l{QStyledItemDelegate::paint()}{paint()}
+ and \l{QStyledItemDelegate::sizeHint()}{sizeHint()} functions.
+ However, simple widget-based delegates can subclass \l QStyledItemDelegate
instead of \l QAbstractItemDelegate, and take advantage of the default
implementations of these functions.
@@ -709,14 +709,14 @@
\section2 Using an existing delegate
- The standard views provided with Qt use instances of \l QItemDelegate
+ The standard views provided with Qt use instances of \l QStyledItemDelegate
to provide editing facilities. This default implementation of the
delegate interface renders items in the usual style for each of the
standard views: \l QListView, \l QTableView, and \l QTreeView.
All the standard roles are handled by the default delegate used by
the standard views. The way these are interpreted is described in the
- QItemDelegate documentation.
+ QStyledItemDelegate documentation.
The delegate used by a view is returned by the
\l{QAbstractItemView::itemDelegate()}{itemDelegate()} function.
@@ -799,7 +799,7 @@
In this case, we ensure that the spin box is up-to-date, and update
the model with the value it contains using the index specified.
- The standard \l QItemDelegate class informs the view when it has
+ The standard \l QStyledItemDelegate class informs the view when it has
finished editing by emitting the
\l{QAbstractItemDelegate::closeEditor()}{closeEditor()} signal.
The view ensures that the editor widget is closed and destroyed. In
@@ -838,11 +838,11 @@
assist any subsequent editing operations. This is achieved by
emitting the \l{QAbstractItemDelegate::closeEditor()}{closeEditor()}
signal with a suitable hint. This is taken care of by the default
- QItemDelegate event filter which we installed on the spin box when
+ QStyledItemDelegate event filter which we installed on the spin box when
it was constructed.
The behavior of the spin box could be adjusted to make it more user
- friendly. In the default event filter supplied by QItemDelegate, if
+ friendly. In the default event filter supplied by QStyledItemDelegate, if
the user hits \uicontrol Return to confirm their choice in the spin box,
the delegate commits the value to the model and closes the spin box.
We can change this behavior by installing our own event filter on the
@@ -1003,8 +1003,8 @@
\snippet reading-selections/window.cpp 0
- The above code uses Qt's convenient \l{Container Classes}{foreach
- keyword} to iterate over, and modify, the items corresponding to the
+ The above code uses a range-based for-loop to iterate over,
+ and modify, the items corresponding to the
indexes returned by the selection model.
The selection model emits signals to indicate changes in the
@@ -1611,7 +1611,6 @@
We can obtain a list of matching items with the \c findItems()
function:
- \snippet qtreewidget-using/mainwindow.cpp 6
\snippet qtreewidget-using/mainwindow.cpp 7
The above code causes items in a tree widget to be selected if they
diff --git a/src/widgets/doc/src/widgets-and-layouts/stylesheet.qdoc b/src/widgets/doc/src/widgets-and-layouts/stylesheet.qdoc
index 43f9dda49a..00323eace6 100644
--- a/src/widgets/doc/src/widgets-and-layouts/stylesheet.qdoc
+++ b/src/widgets/doc/src/widgets-and-layouts/stylesheet.qdoc
@@ -2881,14 +2881,20 @@
| \tt{rgba(\e{r}, \e{g}, \e{b}, \e{a})} \br
| \tt{hsv(\e{h}, \e{s}, \e{v})} \br
| \tt{hsva(\e{h}, \e{s}, \e{v}, \e{a})} \br
+ | \tt{hsl(\e{h}, \e{s}, \e{l})} \br
+ | \tt{hsla(\e{h}, \e{s}, \e{l}, \e{a})} \br
| \tt{#\e{rrggbb}} \br
| \l{QColor::setNamedColor()}{Color Name} \br
- \li Specifies a color as RGB (red, green, blue) or RGBA
- (red, green, blue, alpha) or HSV (hue, saturation, value) or HSVA
- (hue, saturation, value, alpha) or a named color. The \c rgb() or \c rgba()
- syntax can be used with integer values between 0 and 255, or with
- percentages. The value of s, v, and a in \c hsv() or \c hsva() must all
- be in the range 0-255; the value of h must be in the range 0-359.
+ \li Specifies a color as RGB (red, green, blue), RGBA (red,
+ green, blue, alpha), HSV (hue, saturation, value), HSVA
+ (hue, saturation, value, alpha), HSL (hue, saturation,
+ lightness), HSLA (hue, saturation, lightness, alpha) or a
+ named color. The \c rgb() or \c rgba() syntax can be used
+ with integer values between 0 and 255, or with percentages.
+ The value of s, v, l and a in \c hsv(), \c hsva() \c hsl()
+ or \c hsla() must all be in the range 0-255 or with
+ percentages, the value of h must be in the range 0-359.
+ The support for HSL(A) is available since 5.13.
Examples:
diff --git a/src/widgets/effects/qgraphicseffect_p.h b/src/widgets/effects/qgraphicseffect_p.h
index c5c7ff5900..2f3bd2f7fd 100644
--- a/src/widgets/effects/qgraphicseffect_p.h
+++ b/src/widgets/effects/qgraphicseffect_p.h
@@ -88,7 +88,7 @@ protected:
private:
Q_DECLARE_PRIVATE(QGraphicsEffectSource)
- Q_DISABLE_COPY(QGraphicsEffectSource)
+ Q_DISABLE_COPY_MOVE(QGraphicsEffectSource)
friend class QGraphicsEffect;
friend class QGraphicsEffectPrivate;
friend class QGraphicsScenePrivate;
diff --git a/src/widgets/effects/qpixmapfilter.cpp b/src/widgets/effects/qpixmapfilter.cpp
index 60edd01d00..e1e8175423 100644
--- a/src/widgets/effects/qpixmapfilter.cpp
+++ b/src/widgets/effects/qpixmapfilter.cpp
@@ -54,6 +54,8 @@
#include "private/qmemrotate_p.h"
#include "private/qdrawhelper_p.h"
+#include <memory>
+
QT_BEGIN_NAMESPACE
class QPixmapFilterPrivate : public QObjectPrivate
@@ -319,7 +321,7 @@ static void convolute(
const QImage processImage = (srcImage.format() != QImage::Format_ARGB32_Premultiplied ) ? srcImage.convertToFormat(QImage::Format_ARGB32_Premultiplied) : srcImage;
// TODO: support also other formats directly without copying
- int *fixedKernel = new int[kernelWidth*kernelHeight];
+ std::unique_ptr<int[]> fixedKernel(new int[kernelWidth * kernelHeight]);
for(int i = 0; i < kernelWidth*kernelHeight; i++)
{
fixedKernel[i] = (int)(65536 * kernel[i]);
@@ -403,7 +405,6 @@ static void convolute(
}
yk++;
}
- delete[] fixedKernel;
}
/*!
diff --git a/src/widgets/graphicsview/qgraphicsgridlayout.cpp b/src/widgets/graphicsview/qgraphicsgridlayout.cpp
index d9005afbef..6b7052a0ab 100644
--- a/src/widgets/graphicsview/qgraphicsgridlayout.cpp
+++ b/src/widgets/graphicsview/qgraphicsgridlayout.cpp
@@ -552,20 +552,19 @@ int QGraphicsGridLayout::count() const
}
/*!
- Returns the layout item at \a index, or 0 if there is no layout item at
- this index.
+ Returns the layout item at \a index, or \nullptr if there is no
+ layout item at this index.
*/
QGraphicsLayoutItem *QGraphicsGridLayout::itemAt(int index) const
{
Q_D(const QGraphicsGridLayout);
if (index < 0 || index >= d->engine.itemCount()) {
qWarning("QGraphicsGridLayout::itemAt: invalid index %d", index);
- return 0;
+ return nullptr;
}
- QGraphicsLayoutItem *item = 0;
if (QGraphicsGridLayoutEngineItem *engineItem = static_cast<QGraphicsGridLayoutEngineItem*>(d->engine.itemAt(index)))
- item = engineItem->layoutItem();
- return item;
+ return engineItem->layoutItem();
+ return nullptr;
}
/*!
diff --git a/src/widgets/graphicsview/qgraphicsitem.cpp b/src/widgets/graphicsview/qgraphicsitem.cpp
index 86f3d6a2f0..6e53ea94f3 100644
--- a/src/widgets/graphicsview/qgraphicsitem.cpp
+++ b/src/widgets/graphicsview/qgraphicsitem.cpp
@@ -661,9 +661,9 @@
\value ItemSceneChange The item is moved to a new scene. This notification is
also sent when the item is added to its initial scene, and when it is removed.
- The item's scene() is the old scene (or 0 if the item has not been added to a
- scene yet). The value argument is the new scene (i.e., a QGraphicsScene
- pointer), or a null pointer if the item is removed from a scene. Do not
+ The item's scene() is the old scene, or \nullptr if the item has not been added
+ to a scene yet. The value argument is the new scene (i.e., a QGraphicsScene
+ pointer), or \nullptr if the item is removed from a scene. Do not
override this change by passing this item to QGraphicsScene::addItem() as this
notification is delivered; instead, you can return the new scene from
itemChange(). Use this feature with caution; objecting to a scene change can
@@ -1542,7 +1542,7 @@ void QGraphicsItemCache::purge()
Constructs a QGraphicsItem with the given \a parent item.
It does not modify the parent object returned by QObject::parent().
- If \a parent is 0, you can add the item to a scene by calling
+ If \a parent is \nullptr, you can add the item to a scene by calling
QGraphicsScene::addItem(). The item will then become a top-level item.
\sa QGraphicsScene::addItem(), setParentItem()
@@ -1650,8 +1650,8 @@ QGraphicsItem::~QGraphicsItem()
}
/*!
- Returns the current scene for the item, or 0 if the item is not stored in
- a scene.
+ Returns the current scene for the item, or \nullptr if the item is
+ not stored in a scene.
To add or move an item to a scene, call QGraphicsScene::addItem().
*/
@@ -1661,15 +1661,15 @@ QGraphicsScene *QGraphicsItem::scene() const
}
/*!
- Returns a pointer to this item's item group, or 0 if this item is not
- member of a group.
+ Returns a pointer to this item's item group, or \nullptr if this
+ item is not member of a group.
\sa QGraphicsItemGroup, QGraphicsScene::createItemGroup()
*/
QGraphicsItemGroup *QGraphicsItem::group() const
{
if (!d_ptr->isMemberOfGroup)
- return 0;
+ return nullptr;
QGraphicsItem *parent = const_cast<QGraphicsItem *>(this);
while ((parent = parent->d_ptr->parent)) {
if (QGraphicsItemGroup *group = qgraphicsitem_cast<QGraphicsItemGroup *>(parent))
@@ -1677,11 +1677,11 @@ QGraphicsItemGroup *QGraphicsItem::group() const
}
// Unreachable; if d_ptr->isMemberOfGroup is != 0, then one parent of this
// item is a group item.
- return 0;
+ return nullptr;
}
/*!
- Adds this item to the item group \a group. If \a group is 0, this item is
+ Adds this item to the item group \a group. If \a group is \nullptr, this item is
removed from any current group and added as a child of the previous
group's parent.
@@ -1699,7 +1699,7 @@ void QGraphicsItem::setGroup(QGraphicsItemGroup *group)
/*!
Returns a pointer to this item's parent item. If this item does not have a
- parent, 0 is returned.
+ parent, \nullptr is returned.
\sa setParentItem(), childItems()
*/
@@ -1710,8 +1710,9 @@ QGraphicsItem *QGraphicsItem::parentItem() const
/*!
Returns this item's top-level item. The top-level item is the item's
- topmost ancestor item whose parent is 0. If an item has no parent, its own
- pointer is returned (i.e., a top-level item is its own top-level item).
+ topmost ancestor item whose parent is \nullptr. If an item has no
+ parent, its own pointer is returned (i.e., a top-level item is its
+ own top-level item).
\sa parentItem()
*/
@@ -1734,7 +1735,7 @@ QGraphicsItem *QGraphicsItem::topLevelItem() const
QGraphicsObject *QGraphicsItem::parentObject() const
{
QGraphicsItem *p = d_ptr->parent;
- return (p && p->d_ptr->isObject) ? static_cast<QGraphicsObject *>(p) : 0;
+ return (p && p->d_ptr->isObject) ? static_cast<QGraphicsObject *>(p) : nullptr;
}
/*!
@@ -1757,23 +1758,24 @@ QGraphicsWidget *QGraphicsItem::parentWidget() const
\since 4.4
Returns a pointer to the item's top level widget (i.e., the item's
- ancestor whose parent is 0, or whose parent is not a widget), or 0 if this
- item does not have a top level widget. If the item is its own top level
- widget, this function returns a pointer to the item itself.
+ ancestor whose parent is \nullptr, or whose parent is not a widget), or
+ \nullptr if this item does not have a top level widget. If the item
+ is its own top level widget, this function returns a pointer to the
+ item itself.
*/
QGraphicsWidget *QGraphicsItem::topLevelWidget() const
{
if (const QGraphicsWidget *p = parentWidget())
return p->topLevelWidget();
- return isWidget() ? static_cast<QGraphicsWidget *>(const_cast<QGraphicsItem *>(this)) : 0;
+ return isWidget() ? static_cast<QGraphicsWidget *>(const_cast<QGraphicsItem *>(this)) : nullptr;
}
/*!
\since 4.4
- Returns the item's window, or 0 if this item does not have a window. If
- the item is a window, it will return itself. Otherwise it will return the
- closest ancestor that is a window.
+ Returns the item's window, or \nullptr if this item does not have a
+ window. If the item is a window, it will return itself. Otherwise
+ it will return the closest ancestor that is a window.
\sa QGraphicsWidget::isWindow()
*/
@@ -1782,15 +1784,15 @@ QGraphicsWidget *QGraphicsItem::window() const
QGraphicsItem *p = panel();
if (p && p->isWindow())
return static_cast<QGraphicsWidget *>(p);
- return 0;
+ return nullptr;
}
/*!
\since 4.6
- Returns the item's panel, or 0 if this item does not have a panel. If the
- item is a panel, it will return itself. Otherwise it will return the
- closest ancestor that is a panel.
+ Returns the item's panel, or \nullptr if this item does not have a
+ panel. If the item is a panel, it will return itself. Otherwise it
+ will return the closest ancestor that is a panel.
\sa isPanel(), ItemIsPanel
*/
@@ -1798,7 +1800,7 @@ QGraphicsItem *QGraphicsItem::panel() const
{
if (d_ptr->flags & ItemIsPanel)
return const_cast<QGraphicsItem *>(this);
- return d_ptr->parent ? d_ptr->parent->panel() : 0;
+ return d_ptr->parent ? d_ptr->parent->panel() : nullptr;
}
/*!
@@ -2397,7 +2399,7 @@ bool QGraphicsItem::isVisible() const
/*!
\since 4.4
Returns \c true if the item is visible to \a parent; otherwise, false is
- returned. \a parent can be 0, in which case this function will return
+ returned. \a parent can be \nullptr, in which case this function will return
whether the item is visible to the scene or not.
An item may not be visible to its ancestors even if isVisible() is true. It
@@ -2925,7 +2927,7 @@ void QGraphicsItem::setOpacity(qreal opacity)
}
/*!
- Returns a pointer to this item's effect if it has one; otherwise 0.
+ Returns a pointer to this item's effect if it has one; otherwise \nullptr.
\since 4.6
*/
@@ -2939,7 +2941,7 @@ QGraphicsEffect *QGraphicsItem::graphicsEffect() const
Sets \a effect as the item's effect. If there already is an effect installed
on this item, QGraphicsItem will delete the existing effect before installing
the new \a effect. You can delete an existing effect by calling
- setGraphicsEffect(0).
+ setGraphicsEffect(\nullptr).
If \a effect is the installed effect on a different item, setGraphicsEffect() will remove
the effect from the item and install it on this item.
@@ -3577,7 +3579,7 @@ void QGraphicsItemPrivate::clearFocusHelper(bool giveFocusToParent, bool hiddenB
/*!
\since 4.6
- Returns this item's focus proxy, or 0 if this item has no
+ Returns this item's focus proxy, or \nullptr if this item has no
focus proxy.
\sa setFocusProxy(), setFocus(), hasFocus()
@@ -3640,7 +3642,7 @@ void QGraphicsItem::setFocusProxy(QGraphicsItem *item)
If this item, a child or descendant of this item currently has input
focus, this function will return a pointer to that item. If
- no descendant has input focus, 0 is returned.
+ no descendant has input focus, \nullptr is returned.
\sa hasFocus(), setFocus(), QWidget::focusWidget()
*/
@@ -3995,6 +3997,7 @@ void QGraphicsItem::ensureVisible(const QRectF &rect, int xmargin, int ymargin)
ensureVisible(QRectF(\a x, \a y, \a w, \a h), \a xmargin, \a ymargin).
*/
+#if QT_DEPRECATED_SINCE(5, 13)
/*!
\obsolete
@@ -4010,6 +4013,7 @@ QMatrix QGraphicsItem::matrix() const
{
return transform().toAffine();
}
+#endif
/*!
\since 4.3
@@ -4320,6 +4324,7 @@ void QGraphicsItem::setTransformOriginPoint(const QPointF &origin)
*/
+#if QT_DEPRECATED_SINCE(5, 13)
/*!
\obsolete
@@ -4332,7 +4337,7 @@ QMatrix QGraphicsItem::sceneMatrix() const
d_ptr->ensureSceneTransform();
return d_ptr->sceneTransform.toAffine();
}
-
+#endif
/*!
\since 4.3
@@ -4544,6 +4549,7 @@ QTransform QGraphicsItem::itemTransform(const QGraphicsItem *other, bool *ok) co
return x;
}
+#if QT_DEPRECATED_SINCE(5, 13)
/*!
\obsolete
@@ -4582,6 +4588,7 @@ void QGraphicsItem::setMatrix(const QMatrix &matrix, bool combine)
// Send post-notification.
itemChange(ItemTransformHasChanged, QVariant::fromValue<QTransform>(newTransform));
}
+#endif
/*!
\since 4.3
@@ -4636,6 +4643,7 @@ void QGraphicsItem::setTransform(const QTransform &matrix, bool combine)
d_ptr->sendScenePosChange();
}
+#if QT_DEPRECATED_SINCE(5, 13)
/*!
\obsolete
@@ -4645,6 +4653,7 @@ void QGraphicsItem::resetMatrix()
{
resetTransform();
}
+#endif
/*!
\since 4.3
@@ -5790,7 +5799,7 @@ void QGraphicsItemPrivate::clearSubFocus(QGraphicsItem *rootItem, QGraphicsItem
/*!
\internal
- Sets the focusProxy pointer to 0 for all items that have this item as their
+ Sets the focusProxy pointer to \nullptr for all items that have this item as their
focusProxy.
*/
void QGraphicsItemPrivate::resetFocusProxy()
@@ -6001,7 +6010,7 @@ void QGraphicsItem::scroll(qreal dx, qreal dy, const QRectF &rect)
Maps the point \a point, which is in this item's coordinate system, to \a
item's coordinate system, and returns the mapped coordinate.
- If \a item is 0, this function returns the same as mapToScene().
+ If \a item is \nullptr, this function returns the same as mapToScene().
\sa itemTransform(), mapToParent(), mapToScene(), transform(), mapFromItem(), {The Graphics
View Coordinate System}
@@ -6071,7 +6080,7 @@ QPointF QGraphicsItem::mapToScene(const QPointF &point) const
Maps the rectangle \a rect, which is in this item's coordinate system, to
\a item's coordinate system, and returns the mapped rectangle as a polygon.
- If \a item is 0, this function returns the same as mapToScene().
+ If \a item is \nullptr, this function returns the same as mapToScene().
\sa itemTransform(), mapToParent(), mapToScene(), mapFromItem(), {The
Graphics View Coordinate System}
@@ -6142,7 +6151,7 @@ QPolygonF QGraphicsItem::mapToScene(const QRectF &rect) const
\a item's coordinate system, and returns the mapped rectangle as a new
rectangle (i.e., the bounding rectangle of the resulting polygon).
- If \a item is 0, this function returns the same as mapRectToScene().
+ If \a item is \nullptr, this function returns the same as mapRectToScene().
\sa itemTransform(), mapToParent(), mapToScene(), mapFromItem(), {The
Graphics View Coordinate System}
@@ -6217,7 +6226,7 @@ QRectF QGraphicsItem::mapRectToScene(const QRectF &rect) const
this item's coordinate system, and returns the mapped rectangle as a new
rectangle (i.e., the bounding rectangle of the resulting polygon).
- If \a item is 0, this function returns the same as mapRectFromScene().
+ If \a item is \nullptr, this function returns the same as mapRectFromScene().
\sa itemTransform(), mapToParent(), mapToScene(), mapFromItem(), {The
Graphics View Coordinate System}
@@ -6290,7 +6299,7 @@ QRectF QGraphicsItem::mapRectFromScene(const QRectF &rect) const
Maps the polygon \a polygon, which is in this item's coordinate system, to
\a item's coordinate system, and returns the mapped polygon.
- If \a item is 0, this function returns the same as mapToScene().
+ If \a item is \nullptr, this function returns the same as mapToScene().
\sa itemTransform(), mapToParent(), mapToScene(), mapFromItem(), {The
Graphics View Coordinate System}
@@ -6337,7 +6346,7 @@ QPolygonF QGraphicsItem::mapToScene(const QPolygonF &polygon) const
Maps the path \a path, which is in this item's coordinate system, to
\a item's coordinate system, and returns the mapped path.
- If \a item is 0, this function returns the same as mapToScene().
+ If \a item is \nullptr, this function returns the same as mapToScene().
\sa itemTransform(), mapToParent(), mapToScene(), mapFromItem(), {The
Graphics View Coordinate System}
@@ -6384,7 +6393,7 @@ QPainterPath QGraphicsItem::mapToScene(const QPainterPath &path) const
Maps the point \a point, which is in \a item's coordinate system, to this
item's coordinate system, and returns the mapped coordinate.
- If \a item is 0, this function returns the same as mapFromScene().
+ If \a item is \nullptr, this function returns the same as mapFromScene().
\sa itemTransform(), mapFromParent(), mapFromScene(), transform(), mapToItem(), {The Graphics
View Coordinate System}
@@ -6456,7 +6465,7 @@ QPointF QGraphicsItem::mapFromScene(const QPointF &point) const
this item's coordinate system, and returns the mapped rectangle as a
polygon.
- If \a item is 0, this function returns the same as mapFromScene()
+ If \a item is \nullptr, this function returns the same as mapFromScene()
\sa itemTransform(), mapToItem(), mapFromParent(), transform(), {The Graphics View Coordinate
System}
@@ -6524,7 +6533,7 @@ QPolygonF QGraphicsItem::mapFromScene(const QRectF &rect) const
Maps the polygon \a polygon, which is in \a item's coordinate system, to
this item's coordinate system, and returns the mapped polygon.
- If \a item is 0, this function returns the same as mapFromScene().
+ If \a item is \nullptr, this function returns the same as mapFromScene().
\sa itemTransform(), mapToItem(), mapFromParent(), transform(), {The
Graphics View Coordinate System}
@@ -6569,7 +6578,7 @@ QPolygonF QGraphicsItem::mapFromScene(const QPolygonF &polygon) const
Maps the path \a path, which is in \a item's coordinate system, to
this item's coordinate system, and returns the mapped path.
- If \a item is 0, this function returns the same as mapFromScene().
+ If \a item is \nullptr, this function returns the same as mapFromScene().
\sa itemTransform(), mapFromParent(), mapFromScene(), mapToItem(), {The
Graphics View Coordinate System}
@@ -6633,15 +6642,15 @@ bool QGraphicsItem::isAncestorOf(const QGraphicsItem *child) const
/*!
\since 4.4
- Returns the closest common ancestor item of this item and \a other, or 0
- if either \a other is 0, or there is no common ancestor.
+ Returns the closest common ancestor item of this item and \a other,
+ or \nullptr if either \a other is \nullptr, or there is no common ancestor.
\sa isAncestorOf()
*/
QGraphicsItem *QGraphicsItem::commonAncestorItem(const QGraphicsItem *other) const
{
if (!other)
- return 0;
+ return nullptr;
if (other == this)
return const_cast<QGraphicsItem *>(this);
const QGraphicsItem *thisw = this;
@@ -6726,7 +6735,7 @@ void QGraphicsItem::setData(int key, const QVariant &value)
\since 4.2
Returns the given \a item cast to type T if \a item is of type T;
- otherwise, 0 is returned.
+ otherwise, \nullptr is returned.
\note To make this function work correctly with custom items, reimplement
the \l{QGraphicsItem::}{type()} function for each custom QGraphicsItem
diff --git a/src/widgets/graphicsview/qgraphicsitem.h b/src/widgets/graphicsview/qgraphicsitem.h
index c228e765d8..7dd4441ae9 100644
--- a/src/widgets/graphicsview/qgraphicsitem.h
+++ b/src/widgets/graphicsview/qgraphicsitem.h
@@ -283,10 +283,16 @@ public:
inline void ensureVisible(qreal x, qreal y, qreal w, qreal h, int xmargin = 50, int ymargin = 50);
// Local transformation
+#if QT_DEPRECATED_SINCE(5, 13)
+ QT_DEPRECATED_X("Use transform() instead")
QMatrix matrix() const;
+ QT_DEPRECATED_X("Use sceneTransform() instead")
QMatrix sceneMatrix() const;
+ QT_DEPRECATED_X("Use setTransform() instead")
void setMatrix(const QMatrix &matrix, bool combine = false);
+ QT_DEPRECATED_X("Use resetTransform() instead")
void resetMatrix();
+#endif
QTransform transform() const;
QTransform sceneTransform() const;
QTransform deviceTransform(const QTransform &viewportTransform) const;
@@ -487,7 +493,9 @@ private:
};
Q_DECLARE_OPERATORS_FOR_FLAGS(QGraphicsItem::GraphicsItemFlags)
+#ifndef Q_CLANG_QDOC
Q_DECLARE_INTERFACE(QGraphicsItem, "org.qt-project.Qt.QGraphicsItem")
+#endif
inline void QGraphicsItem::setPos(qreal ax, qreal ay)
{ setPos(QPointF(ax, ay)); }
diff --git a/src/widgets/graphicsview/qgraphicsitemanimation.cpp b/src/widgets/graphicsview/qgraphicsitemanimation.cpp
index 572ec141bc..78b91d5c39 100644
--- a/src/widgets/graphicsview/qgraphicsitemanimation.cpp
+++ b/src/widgets/graphicsview/qgraphicsitemanimation.cpp
@@ -549,6 +549,7 @@ void QGraphicsItemAnimation::setStep(qreal step)
afterAnimationStep(step);
}
+#if QT_DEPRECATED_SINCE(5, 13)
/*!
Resets the item to its starting position and transformation.
@@ -563,6 +564,7 @@ void QGraphicsItemAnimation::reset()
d->startPos = d->item->pos();
d->startMatrix = d->item->matrix();
}
+#endif
/*!
\fn void QGraphicsItemAnimation::beforeAnimationStep(qreal step)
diff --git a/src/widgets/graphicsview/qgraphicsitemanimation.h b/src/widgets/graphicsview/qgraphicsitemanimation.h
index 7417d7729c..f983bd8026 100644
--- a/src/widgets/graphicsview/qgraphicsitemanimation.h
+++ b/src/widgets/graphicsview/qgraphicsitemanimation.h
@@ -96,7 +96,10 @@ public:
public Q_SLOTS:
void setStep(qreal x);
+#if QT_DEPRECATED_SINCE(5, 13)
+ QT_DEPRECATED_X("Use setStep(0) instead")
void reset();
+#endif
protected:
virtual void beforeAnimationStep(qreal step);
diff --git a/src/widgets/graphicsview/qgraphicslayout.h b/src/widgets/graphicsview/qgraphicslayout.h
index 28b335ceaa..efcafa5e6a 100644
--- a/src/widgets/graphicsview/qgraphicslayout.h
+++ b/src/widgets/graphicsview/qgraphicslayout.h
@@ -83,7 +83,9 @@ private:
friend class QGraphicsWidget;
};
+#ifndef Q_CLANG_QDOC
Q_DECLARE_INTERFACE(QGraphicsLayout, "org.qt-project.Qt.QGraphicsLayout")
+#endif
QT_END_NAMESPACE
diff --git a/src/widgets/graphicsview/qgraphicslayoutitem.cpp b/src/widgets/graphicsview/qgraphicslayoutitem.cpp
index aed154a95f..1192bad51e 100644
--- a/src/widgets/graphicsview/qgraphicslayoutitem.cpp
+++ b/src/widgets/graphicsview/qgraphicslayoutitem.cpp
@@ -193,7 +193,7 @@ QSizeF *QGraphicsLayoutItemPrivate::effectiveSizeHints(const QSizeF &constraint)
/*!
\internal
- Returns the parent item of this layout, or 0 if this layout is
+ Returns the parent item of this layout, or \nullptr if this layout is
not installed on any widget.
If this is the item that the layout is installed on, it will return "itself".
@@ -214,7 +214,7 @@ QGraphicsItem *QGraphicsLayoutItemPrivate::parentItem() const
while (parent && parent->isLayout()) {
parent = parent->parentLayoutItem();
}
- return parent ? parent->graphicsItem() : 0;
+ return parent ? parent->graphicsItem() : nullptr;
}
/*!
@@ -368,7 +368,7 @@ bool QGraphicsLayoutItemPrivate::hasWidthForHeight() const
passing a QGraphicsLayoutItem pointer to QGraphicsLayoutItem's
protected constructor, or by calling setParentLayoutItem(). The
parentLayoutItem() function returns a pointer to the item's layoutItem
- parent. If the item's parent is 0 or if the parent does not inherit
+ parent. If the item's parent is \nullptr or if the parent does not inherit
from QGraphicsItem, the parentLayoutItem() function then returns \nullptr.
isLayout() returns \c true if the QGraphicsLayoutItem subclass is itself a
layout, or false otherwise.
@@ -737,7 +737,7 @@ QRectF QGraphicsLayoutItem::geometry() const
This virtual function provides the \a left, \a top, \a right and \a bottom
contents margins for this QGraphicsLayoutItem. The default implementation
assumes all contents margins are 0. The parameters point to values stored
- in qreals. If any of the pointers is 0, that value will not be updated.
+ in qreals. If any of the pointers is \nullptr, that value will not be updated.
\sa QGraphicsWidget::setContentsMargins()
*/
@@ -826,8 +826,8 @@ void QGraphicsLayoutItem::updateGeometry()
}
/*!
- Returns the parent of this QGraphicsLayoutItem, or 0 if there is no parent,
- or if the parent does not inherit from QGraphicsLayoutItem
+ Returns the parent of this QGraphicsLayoutItem, or \nullptr if there is
+ no parent, or if the parent does not inherit from QGraphicsLayoutItem
(QGraphicsLayoutItem is often used through multiple inheritance with
QObject-derived classes).
@@ -917,7 +917,7 @@ QGraphicsItem *QGraphicsLayoutItem::graphicsItem() const
* advantage of the automatic reparenting capabilities of QGraphicsLayout it
* should set this value.
* Note that if you delete \a item and not delete the layout item, you are
- * responsible of calling setGraphicsItem(0) in order to avoid having a
+ * responsible of calling setGraphicsItem(\nullptr) in order to avoid having a
* dangling pointer.
*
* \sa graphicsItem()
diff --git a/src/widgets/graphicsview/qgraphicslayoutitem.h b/src/widgets/graphicsview/qgraphicslayoutitem.h
index 44f430034b..86a0a87361 100644
--- a/src/widgets/graphicsview/qgraphicslayoutitem.h
+++ b/src/widgets/graphicsview/qgraphicslayoutitem.h
@@ -116,7 +116,9 @@ private:
friend class QGraphicsLayout;
};
+#ifndef Q_CLANG_QDOC
Q_DECLARE_INTERFACE(QGraphicsLayoutItem, "org.qt-project.Qt.QGraphicsLayoutItem")
+#endif
inline void QGraphicsLayoutItem::setMinimumSize(qreal aw, qreal ah)
{ setMinimumSize(QSizeF(aw, ah)); }
diff --git a/src/widgets/graphicsview/qgraphicslayoutstyleinfo.cpp b/src/widgets/graphicsview/qgraphicslayoutstyleinfo.cpp
index af969b346d..da2510a8cb 100644
--- a/src/widgets/graphicsview/qgraphicslayoutstyleinfo.cpp
+++ b/src/widgets/graphicsview/qgraphicslayoutstyleinfo.cpp
@@ -50,15 +50,13 @@ QT_BEGIN_NAMESPACE
QGraphicsLayoutStyleInfo::QGraphicsLayoutStyleInfo(const QGraphicsLayoutPrivate *layout)
: m_layout(layout), m_style(0)
{
- m_widget = new QWidget; // pixelMetric might need a widget ptr
- if (m_widget)
- m_styleOption.initFrom(m_widget);
+ m_widget.reset(new QWidget); // pixelMetric might need a widget ptr
+ m_styleOption.initFrom(m_widget.get());
m_isWindow = m_styleOption.state & QStyle::State_Window;
}
QGraphicsLayoutStyleInfo::~QGraphicsLayoutStyleInfo()
{
- delete m_widget;
}
qreal QGraphicsLayoutStyleInfo::combinedLayoutSpacing(QLayoutPolicy::ControlTypes controls1,
@@ -93,7 +91,7 @@ qreal QGraphicsLayoutStyleInfo::windowMargin(Qt::Orientation orientation) const
const_cast<QStyleOption*>(&m_styleOption), widget());
}
-QWidget *QGraphicsLayoutStyleInfo::widget() const { return m_widget; }
+QWidget *QGraphicsLayoutStyleInfo::widget() const { return m_widget.get(); }
QStyle *QGraphicsLayoutStyleInfo::style() const
{
diff --git a/src/widgets/graphicsview/qgraphicslayoutstyleinfo_p.h b/src/widgets/graphicsview/qgraphicslayoutstyleinfo_p.h
index 7886de432c..c3af9f4554 100644
--- a/src/widgets/graphicsview/qgraphicslayoutstyleinfo_p.h
+++ b/src/widgets/graphicsview/qgraphicslayoutstyleinfo_p.h
@@ -54,6 +54,8 @@
#include <QtGui/private/qabstractlayoutstyleinfo_p.h>
#include <QtWidgets/qstyleoption.h>
+#include <memory>
+
QT_REQUIRE_CONFIG(graphicsview);
QT_BEGIN_NAMESPACE
@@ -93,7 +95,7 @@ private:
const QGraphicsLayoutPrivate *m_layout;
mutable QStyle *m_style;
QStyleOption m_styleOption;
- QWidget *m_widget;
+ std::unique_ptr<QWidget> m_widget;
};
QT_END_NAMESPACE
diff --git a/src/widgets/graphicsview/qgraphicsproxywidget.cpp b/src/widgets/graphicsview/qgraphicsproxywidget.cpp
index 513cf9d361..e9f092020f 100644
--- a/src/widgets/graphicsview/qgraphicsproxywidget.cpp
+++ b/src/widgets/graphicsview/qgraphicsproxywidget.cpp
@@ -556,7 +556,7 @@ QGraphicsProxyWidget::~QGraphicsProxyWidget()
exclusively either inside or outside of Graphics View. You cannot embed a
widget as long as it is is visible elsewhere in the UI, at the same time.
- \a widget must be a top-level widget whose parent is 0.
+ \a widget must be a top-level widget whose parent is \nullptr.
When the widget is embedded, its state (e.g., visible, enabled, geometry,
size hints) is copied into the proxy widget. If the embedded widget is
@@ -739,7 +739,7 @@ QWidget *QGraphicsProxyWidget::widget() const
Returns the rectangle for \a widget, which must be a descendant of
widget(), or widget() itself, in this proxy item's local coordinates.
- If no widget is embedded, \a widget is 0, or \a widget is not a
+ If no widget is embedded, \a widget is \nullptr, or \a widget is not a
descendant of the embedded widget, this function returns an empty QRectF.
\sa widget()
diff --git a/src/widgets/graphicsview/qgraphicsscene.cpp b/src/widgets/graphicsview/qgraphicsscene.cpp
index bba992144d..19d9f25307 100644
--- a/src/widgets/graphicsview/qgraphicsscene.cpp
+++ b/src/widgets/graphicsview/qgraphicsscene.cpp
@@ -1923,12 +1923,13 @@ void QGraphicsScene::setBspTreeDepth(int depth)
QGraphicsSceneBspTreeIndex *bspTree = qobject_cast<QGraphicsSceneBspTreeIndex *>(d->index);
if (!bspTree) {
- qWarning("QGraphicsScene::setBspTreeDepth: can not apply if indexing method is not BSP");
+ qWarning("QGraphicsScene::setBspTreeDepth: cannot apply if indexing method is not BSP");
return;
}
bspTree->setBspTreeDepth(depth);
}
+#if QT_DEPRECATED_SINCE(5, 13)
/*!
\property QGraphicsScene::sortCacheEnabled
\brief whether sort caching is enabled
@@ -1949,6 +1950,7 @@ void QGraphicsScene::setSortCacheEnabled(bool enabled)
return;
d->sortCacheEnabled = enabled;
}
+#endif
/*!
Calculates and returns the bounding rect of all items on the scene. This
@@ -2144,8 +2146,8 @@ QList<QGraphicsItem *> QGraphicsScene::collidingItems(const QGraphicsItem *item,
\overload
\obsolete
- Returns the topmost visible item at the specified \a position, or 0 if
- there are no items at this position.
+ Returns the topmost visible item at the specified \a position, or
+ \nullptr if there are no items at this position.
This function is deprecated and returns incorrect results if the scene
contains items that ignore transformations. Use the overload that takes
@@ -2159,7 +2161,7 @@ QList<QGraphicsItem *> QGraphicsScene::collidingItems(const QGraphicsItem *item,
/*!
\since 4.6
- Returns the topmost visible item at the specified \a position, or 0
+ Returns the topmost visible item at the specified \a position, or \nullptr
if there are no items at this position.
\a deviceTransform is the transformation that applies to the view, and needs to
@@ -2173,7 +2175,7 @@ QGraphicsItem *QGraphicsScene::itemAt(const QPointF &position, const QTransform
{
const QList<QGraphicsItem *> itemsAtPoint = items(position, Qt::IntersectsItemShape,
Qt::DescendingOrder, deviceTransform);
- return itemsAtPoint.isEmpty() ? 0 : itemsAtPoint.first();
+ return itemsAtPoint.isEmpty() ? nullptr : itemsAtPoint.first();
}
/*!
@@ -2182,7 +2184,7 @@ QGraphicsItem *QGraphicsScene::itemAt(const QPointF &position, const QTransform
\since 4.6
Returns the topmost visible item at the position specified by (\a x, \a
- y), or 0 if there are no items at this position.
+ y), or \nullptr if there are no items at this position.
\a deviceTransform is the transformation that applies to the view, and needs to
be provided if the scene contains items that ignore transformations.
@@ -2199,7 +2201,7 @@ QGraphicsItem *QGraphicsScene::itemAt(const QPointF &position, const QTransform
\obsolete
Returns the topmost visible item at the position specified by (\a x, \a
- y), or 0 if there are no items at this position.
+ y), or \nullptr if there are no items at this position.
This convenience function is equivalent to calling \c
{itemAt(QPointF(x, y))}.
@@ -2941,9 +2943,9 @@ void QGraphicsScene::removeItem(QGraphicsItem *item)
/*!
When the scene is active, this functions returns the scene's current focus
- item, or 0 if no item currently has focus. When the scene is inactive, this
- functions returns the item that will gain input focus when the scene becomes
- active.
+ item, or \nullptr if no item currently has focus. When the scene is inactive,
+ this functions returns the item that will gain input focus when the scene
+ becomes active.
The focus item receives keyboard input when the scene receives a
key event.
@@ -2961,12 +2963,12 @@ QGraphicsItem *QGraphicsScene::focusItem() const
focusReason, after removing focus from any previous item that may have had
focus.
- If \a item is 0, or if it either does not accept focus (i.e., it does not
+ If \a item is \nullptr, or if it either does not accept focus (i.e., it does not
have the QGraphicsItem::ItemIsFocusable flag enabled), or is not visible
or not enabled, this function only removes focus from any previous
focusitem.
- If item is not 0, and the scene does not currently have focus (i.e.,
+ If item is not \nullptr, and the scene does not currently have focus (i.e.,
hasFocus() returns \c false), this function will call setFocus()
automatically.
@@ -3062,9 +3064,9 @@ bool QGraphicsScene::stickyFocus() const
}
/*!
- Returns the current mouse grabber item, or 0 if no item is currently
- grabbing the mouse. The mouse grabber item is the item that receives all
- mouse events sent to the scene.
+ Returns the current mouse grabber item, or \nullptr if no item is
+ currently grabbing the mouse. The mouse grabber item is the item
+ that receives all mouse events sent to the scene.
An item becomes a mouse grabber when it receives and accepts a
mouse press event, and it stays the mouse grabber until either of
@@ -3322,6 +3324,9 @@ void QGraphicsScene::advance()
\l{QWidget::}{enterEvent()} and \l{QWidget::}{leaveEvent()}. Use this
function to obtain those events instead.
+ Returns \c true if \a event has been recognized and processed; otherwise,
+ returns \c false.
+
\sa contextMenuEvent(), keyPressEvent(), keyReleaseEvent(),
mousePressEvent(), mouseMoveEvent(), mouseReleaseEvent(),
mouseDoubleClickEvent(), focusInEvent(), focusOutEvent()
@@ -5547,11 +5552,11 @@ bool QGraphicsScene::focusNextPrevChild(bool next)
\a oldFocusItem is a pointer to the item that previously had focus, or
0 if no item had focus before the signal was emitted. \a newFocusItem
- is a pointer to the item that gained input focus, or 0 if focus was lost.
+ is a pointer to the item that gained input focus, or \nullptr if focus was lost.
\a reason is the reason for the focus change (e.g., if the scene was
deactivated while an input field had focus, \a oldFocusItem would point
- to the input field item, \a newFocusItem would be 0, and \a reason would be
- Qt::ActiveWindowFocusReason.
+ to the input field item, \a newFocusItem would be \nullptr, and \a reason
+ would be Qt::ActiveWindowFocusReason.
*/
/*!
@@ -5582,7 +5587,7 @@ QStyle *QGraphicsScene::style() const
the style for all widgets in the scene that do not have a style explicitly
assigned to them.
- If \a style is 0, QGraphicsScene will revert to QApplication::style().
+ If \a style is \nullptr, QGraphicsScene will revert to QApplication::style().
\sa style()
*/
@@ -5703,7 +5708,8 @@ bool QGraphicsScene::isActive() const
/*!
\since 4.6
- Returns the current active panel, or 0 if no panel is currently active.
+ Returns the current active panel, or \nullptr if no panel is
+ currently active.
\sa QGraphicsScene::setActivePanel()
*/
@@ -5720,7 +5726,7 @@ QGraphicsItem *QGraphicsScene::activePanel() const
deactivate any currently active panel.
If the scene is currently inactive, \a item remains inactive until the
- scene becomes active (or, ir \a item is 0, no item will be activated).
+ scene becomes active (or, ir \a item is \nullptr, no item will be activated).
\sa activePanel(), isActive(), QGraphicsItem::isActive()
*/
@@ -5733,8 +5739,8 @@ void QGraphicsScene::setActivePanel(QGraphicsItem *item)
/*!
\since 4.4
- Returns the current active window, or 0 if no window is currently
- active.
+ Returns the current active window, or \nullptr if no window is
+ currently active.
\sa QGraphicsScene::setActiveWindow()
*/
@@ -5743,7 +5749,7 @@ QGraphicsWidget *QGraphicsScene::activeWindow() const
Q_D(const QGraphicsScene);
if (d->activePanel && d->activePanel->isWindow())
return static_cast<QGraphicsWidget *>(d->activePanel);
- return 0;
+ return nullptr;
}
/*!
diff --git a/src/widgets/graphicsview/qgraphicsscene.h b/src/widgets/graphicsview/qgraphicsscene.h
index 287e551db7..3cc00ead08 100644
--- a/src/widgets/graphicsview/qgraphicsscene.h
+++ b/src/widgets/graphicsview/qgraphicsscene.h
@@ -103,7 +103,9 @@ class Q_WIDGETS_EXPORT QGraphicsScene : public QObject
Q_PROPERTY(int bspTreeDepth READ bspTreeDepth WRITE setBspTreeDepth)
Q_PROPERTY(QPalette palette READ palette WRITE setPalette)
Q_PROPERTY(QFont font READ font WRITE setFont)
+#if QT_DEPRECATED_SINCE(5, 13)
Q_PROPERTY(bool sortCacheEnabled READ isSortCacheEnabled WRITE setSortCacheEnabled)
+#endif
Q_PROPERTY(bool stickyFocus READ stickyFocus WRITE setStickyFocus)
Q_PROPERTY(qreal minimumRenderSize READ minimumRenderSize WRITE setMinimumRenderSize)
Q_PROPERTY(bool focusOnTouch READ focusOnTouch WRITE setFocusOnTouch)
@@ -141,8 +143,10 @@ public:
ItemIndexMethod itemIndexMethod() const;
void setItemIndexMethod(ItemIndexMethod method);
- bool isSortCacheEnabled() const;
- void setSortCacheEnabled(bool enabled);
+#if QT_DEPRECATED_SINCE(5, 13)
+ QT_DEPRECATED bool isSortCacheEnabled() const;
+ QT_DEPRECATED void setSortCacheEnabled(bool enabled);
+#endif
int bspTreeDepth() const;
void setBspTreeDepth(int depth);
diff --git a/src/widgets/graphicsview/qgraphicsscenebsptreeindex_p.h b/src/widgets/graphicsview/qgraphicsscenebsptreeindex_p.h
index b6387a2c56..eb6bbbf49b 100644
--- a/src/widgets/graphicsview/qgraphicsscenebsptreeindex_p.h
+++ b/src/widgets/graphicsview/qgraphicsscenebsptreeindex_p.h
@@ -99,7 +99,7 @@ protected:
private :
Q_DECLARE_PRIVATE(QGraphicsSceneBspTreeIndex)
- Q_DISABLE_COPY(QGraphicsSceneBspTreeIndex)
+ Q_DISABLE_COPY_MOVE(QGraphicsSceneBspTreeIndex)
Q_PRIVATE_SLOT(d_func(), void _q_updateSortCache())
Q_PRIVATE_SLOT(d_func(), void _q_updateIndex())
diff --git a/src/widgets/graphicsview/qgraphicssceneevent.cpp b/src/widgets/graphicsview/qgraphicssceneevent.cpp
index 398ef1aaf5..5077a39d67 100644
--- a/src/widgets/graphicsview/qgraphicssceneevent.cpp
+++ b/src/widgets/graphicsview/qgraphicssceneevent.cpp
@@ -319,8 +319,8 @@ QGraphicsSceneEvent::~QGraphicsSceneEvent()
}
/*!
- Returns the widget where the event originated, or 0 if the event
- originates from another application.
+ Returns the widget where the event originated, or \nullptr if the
+ event originates from another application.
*/
QWidget *QGraphicsSceneEvent::widget() const
{
diff --git a/src/widgets/graphicsview/qgraphicssceneindex_p.h b/src/widgets/graphicsview/qgraphicssceneindex_p.h
index bdc57bd9ea..86637e836b 100644
--- a/src/widgets/graphicsview/qgraphicssceneindex_p.h
+++ b/src/widgets/graphicsview/qgraphicssceneindex_p.h
@@ -115,7 +115,7 @@ protected:
friend class QGraphicsItemPrivate;
friend class QGraphicsSceneBspTreeIndex;
private:
- Q_DISABLE_COPY(QGraphicsSceneIndex)
+ Q_DISABLE_COPY_MOVE(QGraphicsSceneIndex)
Q_DECLARE_PRIVATE(QGraphicsSceneIndex)
};
@@ -151,7 +151,7 @@ inline void QGraphicsSceneIndexPrivate::items_helper(const QRectF &rect, QGraphi
if (order == Qt::DescendingOrder) {
const int n = items->size();
for (int i = 0; i < n / 2; ++i)
- items->swap(i, n - i - 1);
+ items->swapItemsAt(i, n - i - 1);
}
}
diff --git a/src/widgets/graphicsview/qgraphicsview.cpp b/src/widgets/graphicsview/qgraphicsview.cpp
index 24647dd74c..5fe520132f 100644
--- a/src/widgets/graphicsview/qgraphicsview.cpp
+++ b/src/widgets/graphicsview/qgraphicsview.cpp
@@ -1676,7 +1676,7 @@ void QGraphicsView::setInteractive(bool allowed)
/*!
Returns a pointer to the scene that is currently visualized in the
- view. If no scene is currently visualized, 0 is returned.
+ view. If no scene is currently visualized, \nullptr is returned.
\sa setScene()
*/
diff --git a/src/widgets/graphicsview/qgraphicswidget.cpp b/src/widgets/graphicsview/qgraphicswidget.cpp
index a4534c73dd..ad3be5766d 100644
--- a/src/widgets/graphicsview/qgraphicswidget.cpp
+++ b/src/widgets/graphicsview/qgraphicswidget.cpp
@@ -159,7 +159,7 @@ QT_BEGIN_NAMESPACE
manage the relationships between parent and child items. These functions
control the stacking order of items as well as their ownership.
- \note The QObject::parent() should always return 0 for QGraphicsWidgets,
+ \note The QObject::parent() should always return \nullptr for QGraphicsWidgets,
but this policy is not strictly defined.
\sa QGraphicsProxyWidget, QGraphicsItem, {Widgets and Layouts}
@@ -518,7 +518,7 @@ void QGraphicsWidget::setContentsMargins(qreal left, qreal top, qreal right, qre
/*!
Gets the widget's contents margins. The margins are stored in \a left, \a
top, \a right and \a bottom, as pointers to qreals. Each argument can
- be \e {omitted} by passing 0.
+ be \e {omitted} by passing \nullptr.
\sa setContentsMargins()
*/
@@ -573,7 +573,7 @@ void QGraphicsWidget::setWindowFrameMargins(qreal left, qreal top, qreal right,
/*!
Gets the widget's window frame margins. The margins are stored in \a left,
\a top, \a right and \a bottom as pointers to qreals. Each argument can
- be \e {omitted} by passing 0.
+ be \e {omitted} by passing \nullptr.
\sa setWindowFrameMargins(), windowFrameRect()
*/
@@ -780,7 +780,7 @@ QSizeF QGraphicsWidget::sizeHint(Qt::SizeHint which, const QSizeF &constraint) c
\brief The layout of the widget
Any existing layout manager is deleted before the new layout is assigned. If
- \a layout is 0, the widget is left without a layout. Existing subwidgets'
+ \a layout is \nullptr, the widget is left without a layout. Existing subwidgets'
geometries will remain unaffected.
QGraphicsWidget takes ownership of \a layout.
@@ -792,7 +792,7 @@ QSizeF QGraphicsWidget::sizeHint(Qt::SizeHint which, const QSizeF &constraint) c
explicitly managed by \a layout remain unaffected by the layout after
it has been assigned to this widget.
- If no layout is currently managing this widget, layout() will return 0.
+ If no layout is currently managing this widget, layout() will return \nullptr.
*/
@@ -803,8 +803,8 @@ QSizeF QGraphicsWidget::sizeHint(Qt::SizeHint which, const QSizeF &constraint) c
*/
/*!
- Returns this widget's layout, or 0 if no layout is currently managing this
- widget.
+ Returns this widget's layout, or \nullptr if no layout is currently
+ managing this widget.
\sa setLayout()
*/
@@ -818,7 +818,7 @@ QGraphicsLayout *QGraphicsWidget::layout() const
\fn void QGraphicsWidget::setLayout(QGraphicsLayout *layout)
Sets the layout for this widget to \a layout. Any existing layout manager
- is deleted before the new layout is assigned. If \a layout is 0, the
+ is deleted before the new layout is assigned. If \a layout is \nullptr, the
widget is left without a layout. Existing subwidgets' geometries will
remain unaffected.
@@ -937,11 +937,11 @@ QStyle *QGraphicsWidget::style() const
Sets the widget's style to \a style. QGraphicsWidget does \e not take
ownership of \a style.
- If no style is assigned, or \a style is 0, the widget will use
+ If no style is assigned, or \a style is \nullptr, the widget will use
QGraphicsScene::style() (if this has been set). Otherwise the widget will
use QApplication::style().
- This function sets the Qt::WA_SetStyle attribute if \a style is not 0;
+ This function sets the Qt::WA_SetStyle attribute if \a style is not \nullptr;
otherwise it clears the attribute.
\sa style()
@@ -1232,6 +1232,9 @@ QVariant QGraphicsWidget::propertyChange(const QString &propertyName, const QVar
event() or in any of the convenience functions; you should not have to
reimplement this function in a subclass of QGraphicsWidget.
+ Returns \c true if \a event has been recognized and processed; otherwise,
+ returns \c false.
+
\sa QGraphicsItem::sceneEvent()
*/
bool QGraphicsWidget::sceneEvent(QEvent *event)
@@ -1871,7 +1874,7 @@ void QGraphicsWidget::setFocusPolicy(Qt::FocusPolicy policy)
/*!
If this widget, a child or descendant of this widget currently has input
focus, this function will return a pointer to that widget. If
- no descendant widget has input focus, 0 is returned.
+ no descendant widget has input focus, \nullptr is returned.
\sa QGraphicsItem::focusItem(), QWidget::focusWidget()
*/
@@ -1880,7 +1883,7 @@ QGraphicsWidget *QGraphicsWidget::focusWidget() const
Q_D(const QGraphicsWidget);
if (d->subFocusItem && d->subFocusItem->d_ptr->isWidget)
return static_cast<QGraphicsWidget *>(d->subFocusItem);
- return 0;
+ return nullptr;
}
#ifndef QT_NO_SHORTCUT
@@ -2022,7 +2025,7 @@ void QGraphicsWidget::addActions(QList<QAction *> actions)
\since 4.5
Inserts the action \a action to this widget's list of actions,
- before the action \a before. It appends the action if \a before is 0 or
+ before the action \a before. It appends the action if \a before is \nullptr or
\a before is not a valid action for this widget.
A QGraphicsWidget should only have one of each action.
@@ -2062,7 +2065,7 @@ void QGraphicsWidget::insertAction(QAction *before, QAction *action)
\since 4.5
Inserts the actions \a actions to this widget's list of actions,
- before the action \a before. It appends the action if \a before is 0 or
+ before the action \a before. It appends the action if \a before is \nullptr or
\a before is not a valid action for this widget.
A QGraphicsWidget can have at most one of each action.
@@ -2131,9 +2134,9 @@ QList<QAction *> QGraphicsWidget::actions() const
\snippet code/src_gui_graphicsview_qgraphicswidget.cpp 2
- If \a first is 0, this indicates that \a second should be the first widget
+ If \a first is \nullptr, this indicates that \a second should be the first widget
to receive input focus should the scene gain Tab focus (i.e., the user
- hits Tab so that focus passes into the scene). If \a second is 0, this
+ hits Tab so that focus passes into the scene). If \a second is \nullptr, this
indicates that \a first should be the first widget to gain focus if the
scene gained BackTab focus.
@@ -2306,7 +2309,7 @@ void QGraphicsWidget::paintWindowFrame(QPainter *painter, const QStyleOptionGrap
QStyleHintReturnMask mask;
bool setMask = style()->styleHint(QStyle::SH_WindowFrame_Mask, &bar, widget, &mask) && !mask.region.isEmpty();
bool hasBorder = !style()->styleHint(QStyle::SH_TitleBar_NoBorder, &bar, widget);
- int frameWidth = style()->pixelMetric(QStyle::PM_MDIFrameWidth, &bar, widget);
+ int frameWidth = style()->pixelMetric(QStyle::PM_MdiSubWindowFrameWidth, &bar, widget);
if (setMask) {
painter->save();
painter->setClipRegion(mask.region, Qt::IntersectClip);
diff --git a/src/widgets/graphicsview/qsimplex_p.h b/src/widgets/graphicsview/qsimplex_p.h
index 2342da2437..369f2f5f82 100644
--- a/src/widgets/graphicsview/qsimplex_p.h
+++ b/src/widgets/graphicsview/qsimplex_p.h
@@ -150,7 +150,7 @@ struct QSimplexConstraint
class QSimplex
{
- Q_DISABLE_COPY(QSimplex)
+ Q_DISABLE_COPY_MOVE(QSimplex)
public:
QSimplex();
~QSimplex();
diff --git a/src/widgets/itemviews/qabstractitemdelegate.cpp b/src/widgets/itemviews/qabstractitemdelegate.cpp
index 9508aed3d3..448e775a71 100644
--- a/src/widgets/itemviews/qabstractitemdelegate.cpp
+++ b/src/widgets/itemviews/qabstractitemdelegate.cpp
@@ -88,7 +88,7 @@ QT_BEGIN_NAMESPACE
and is part of Qt's \l{Model/View Programming}{model/view framework}.
To render an item in a custom way, you must implement paint() and
- sizeHint(). The QItemDelegate class provides default implementations for
+ sizeHint(). The QStyledItemDelegate class provides default implementations for
these functions; if you do not need custom rendering, subclass that
class instead.
@@ -115,7 +115,7 @@ QT_BEGIN_NAMESPACE
The second approach is to handle user events directly by reimplementing
editorEvent().
- \sa {model-view-programming}{Model/View Programming}, QItemDelegate,
+ \sa {model-view-programming}{Model/View Programming}, QStyledItemDelegate,
{Pixelator Example}, QStyledItemDelegate, QStyle
*/
@@ -345,6 +345,7 @@ bool QAbstractItemDelegate::editorEvent(QEvent *,
return false;
}
+#if QT_DEPRECATED_SINCE(5, 13)
/*!
\obsolete
@@ -364,6 +365,7 @@ QString QAbstractItemDelegate::elidedText(const QFontMetrics &fontMetrics, int w
{
return fontMetrics.elidedText(text, mode, width);
}
+#endif
/*!
\since 4.3
diff --git a/src/widgets/itemviews/qabstractitemdelegate.h b/src/widgets/itemviews/qabstractitemdelegate.h
index 575728e806..5696e55691 100644
--- a/src/widgets/itemviews/qabstractitemdelegate.h
+++ b/src/widgets/itemviews/qabstractitemdelegate.h
@@ -103,8 +103,11 @@ public:
const QStyleOptionViewItem &option,
const QModelIndex &index);
+#if QT_DEPRECATED_SINCE(5, 13)
+ QT_DEPRECATED_X("Use QFontMetrics::elidedText() instead")
static QString elidedText(const QFontMetrics &fontMetrics, int width,
Qt::TextElideMode mode, const QString &text);
+#endif
virtual bool helpEvent(QHelpEvent *event,
QAbstractItemView *view,
diff --git a/src/widgets/itemviews/qabstractitemview.cpp b/src/widgets/itemviews/qabstractitemview.cpp
index e1e45143b4..95631ffa5f 100644
--- a/src/widgets/itemviews/qabstractitemview.cpp
+++ b/src/widgets/itemviews/qabstractitemview.cpp
@@ -940,8 +940,8 @@ void QAbstractItemView::setItemDelegateForRow(int row, QAbstractItemDelegate *de
\since 4.2
Returns the item delegate used by this view and model for the given \a row,
- or 0 if no delegate has been assigned. You can call itemDelegate() to get a
- pointer to the current delegate for a given index.
+ or \nullptr if no delegate has been assigned. You can call itemDelegate()
+ to get a pointer to the current delegate for a given index.
\sa setItemDelegateForRow(), itemDelegateForColumn(), setItemDelegate()
*/
@@ -1689,6 +1689,9 @@ bool QAbstractItemView::event(QEvent *event)
This? mode, if the given \a event is a QEvent::ToolTip,or a
QEvent::WhatsThis. It passes all other
events on to its base class viewportEvent() handler.
+
+ Returns \c true if \a event has been recognized and processed; otherwise,
+ returns \c false.
*/
bool QAbstractItemView::viewportEvent(QEvent *event)
{
@@ -2438,8 +2441,14 @@ void QAbstractItemView::keyPressEvent(QKeyEvent *event)
break;
case Qt::Key_Space:
case Qt::Key_Select:
- if (!edit(currentIndex(), AnyKeyPressed, event) && d->selectionModel)
- d->selectionModel->select(currentIndex(), selectionCommand(currentIndex(), event));
+ if (!edit(currentIndex(), AnyKeyPressed, event)) {
+ if (d->selectionModel)
+ d->selectionModel->select(currentIndex(), selectionCommand(currentIndex(), event));
+ if (event->key() == Qt::Key_Space) {
+ keyboardSearch(event->text());
+ event->accept();
+ }
+ }
#ifdef QT_KEYPAD_NAVIGATION
if ( event->key()==Qt::Key_Select ) {
// Also do Key_Enter action.
@@ -2915,6 +2924,7 @@ void QAbstractItemView::editorDestroyed(QObject *editor)
setState(NoState);
}
+#if QT_DEPRECATED_SINCE(5, 13)
/*!
\obsolete
Sets the horizontal scroll bar's steps per item to \a steps.
@@ -2972,6 +2982,7 @@ int QAbstractItemView::verticalStepsPerItem() const
{
return 1;
}
+#endif
/*!
Moves to and selects the item best matching the string \a search.
@@ -3205,7 +3216,7 @@ bool QAbstractItemView::isPersistentEditorOpen(const QModelIndex &index) const
This function should only be used to display static content within the
visible area corresponding to an item of data. If you want to display
custom dynamic content or implement a custom editor widget, subclass
- QItemDelegate instead.
+ QStyledItemDelegate instead.
\sa {Delegate Classes}
*/
diff --git a/src/widgets/itemviews/qabstractitemview.h b/src/widgets/itemviews/qabstractitemview.h
index 981582c166..be8fa07c94 100644
--- a/src/widgets/itemviews/qabstractitemview.h
+++ b/src/widgets/itemviews/qabstractitemview.h
@@ -272,10 +272,12 @@ Q_SIGNALS:
protected:
QAbstractItemView(QAbstractItemViewPrivate &, QWidget *parent = nullptr);
- void setHorizontalStepsPerItem(int steps);
- int horizontalStepsPerItem() const;
- void setVerticalStepsPerItem(int steps);
- int verticalStepsPerItem() const;
+#if QT_DEPRECATED_SINCE(5, 13)
+ QT_DEPRECATED void setHorizontalStepsPerItem(int steps);
+ QT_DEPRECATED int horizontalStepsPerItem() const;
+ QT_DEPRECATED void setVerticalStepsPerItem(int steps);
+ QT_DEPRECATED int verticalStepsPerItem() const;
+#endif
enum CursorAction { MoveUp, MoveDown, MoveLeft, MoveRight,
MoveHome, MoveEnd, MovePageUp, MovePageDown,
diff --git a/src/widgets/itemviews/qcolumnview.cpp b/src/widgets/itemviews/qcolumnview.cpp
index 1fe17721ba..a4eed2d885 100644
--- a/src/widgets/itemviews/qcolumnview.cpp
+++ b/src/widgets/itemviews/qcolumnview.cpp
@@ -801,7 +801,7 @@ void QColumnView::initializeColumn(QAbstractItemView *column) const
}
/*!
- Returns the preview widget, or 0 if there is none.
+ Returns the preview widget, or \nullptr if there is none.
\sa setPreviewWidget(), updatePreviewWidget()
*/
diff --git a/src/widgets/itemviews/qcolumnview_p.h b/src/widgets/itemviews/qcolumnview_p.h
index 9f0d2a40dc..7b36b1f3da 100644
--- a/src/widgets/itemviews/qcolumnview_p.h
+++ b/src/widgets/itemviews/qcolumnview_p.h
@@ -181,6 +181,7 @@ public:
/*!
* This is a delegate that will paint the triangle
*/
+// ### Qt6: QStyledItemDelegate
class QColumnViewDelegate : public QItemDelegate
{
diff --git a/src/widgets/itemviews/qcolumnviewgrip_p.h b/src/widgets/itemviews/qcolumnviewgrip_p.h
index 7e2793074b..5eb8012204 100644
--- a/src/widgets/itemviews/qcolumnviewgrip_p.h
+++ b/src/widgets/itemviews/qcolumnviewgrip_p.h
@@ -82,7 +82,7 @@ protected:
private:
Q_DECLARE_PRIVATE(QColumnViewGrip)
- Q_DISABLE_COPY(QColumnViewGrip)
+ Q_DISABLE_COPY_MOVE(QColumnViewGrip)
};
class QColumnViewGripPrivate : public QWidgetPrivate
diff --git a/src/widgets/itemviews/qdatawidgetmapper.cpp b/src/widgets/itemviews/qdatawidgetmapper.cpp
index 1f0dbff7a9..125ee73194 100644
--- a/src/widgets/itemviews/qdatawidgetmapper.cpp
+++ b/src/widgets/itemviews/qdatawidgetmapper.cpp
@@ -324,6 +324,7 @@ void QDataWidgetMapperPrivate::_q_modelDestroyed()
QDataWidgetMapper::QDataWidgetMapper(QObject *parent)
: QObject(*new QDataWidgetMapperPrivate, parent)
{
+ // ### Qt6: QStyledItemDelegate
setItemDelegate(new QItemDelegate(this));
}
diff --git a/src/widgets/itemviews/qdirmodel.cpp b/src/widgets/itemviews/qdirmodel.cpp
index 78fc623fb5..b94c31fb42 100644
--- a/src/widgets/itemviews/qdirmodel.cpp
+++ b/src/widgets/itemviews/qdirmodel.cpp
@@ -1252,11 +1252,10 @@ void QDirModelPrivate::restorePersistentIndexes()
for (const SavedPersistent &sp : qAsConst(savedPersistent)) {
QPersistentModelIndexData *data = sp.data;
QModelIndex idx = q->index(sp.path, sp.column);
- if (idx != data->index || data->model == 0) {
+ if (idx != data->index || data->index.model() == nullptr) {
//data->model may be equal to 0 if the model is getting destroyed
persistent.indexes.remove(data->index);
data->index = idx;
- data->model = q;
if (idx.isValid())
persistent.indexes.insert(idx, data);
}
diff --git a/src/widgets/itemviews/qheaderview.cpp b/src/widgets/itemviews/qheaderview.cpp
index 7bfa51337d..62abf56751 100644
--- a/src/widgets/itemviews/qheaderview.cpp
+++ b/src/widgets/itemviews/qheaderview.cpp
@@ -2321,9 +2321,10 @@ void QHeaderView::initializeSections()
if (stretchLastSection()) // we've already gotten the size hint
d->maybeRestorePrevLastSectionAndStretchLast();
- //make sure we update the hidden sections
+ // make sure we update the hidden sections
+ // simulate remove from newCount to oldCount
if (newCount < oldCount)
- d->updateHiddenSections(0, newCount-1);
+ d->updateHiddenSections(newCount, oldCount);
}
}
@@ -3116,9 +3117,25 @@ void QHeaderView::scrollContentsBy(int dx, int dy)
\reimp
\internal
*/
-void QHeaderView::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &)
+void QHeaderView::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles)
{
Q_D(QHeaderView);
+ if (!roles.isEmpty()) {
+ const auto doesRoleAffectSize = [](int role) -> bool {
+ switch (role) {
+ case Qt::DisplayRole:
+ case Qt::DecorationRole:
+ case Qt::SizeHintRole:
+ case Qt::FontRole:
+ return true;
+ default:
+ // who knows what a subclass or custom style might do
+ return role >= Qt::UserRole;
+ }
+ };
+ if (std::none_of(roles.begin(), roles.end(), doesRoleAffectSize))
+ return;
+ }
d->invalidateCachedSizeHint();
if (d->hasAutoResizeSections()) {
bool resizeRequired = d->globalResizeMode == ResizeToContents;
@@ -3874,9 +3891,9 @@ void QHeaderViewPrivate::updateDefaultSectionSizeFromStyle()
void QHeaderViewPrivate::recalcSectionStartPos() const // linear (but fast)
{
int pixelpos = 0;
- for (QVector<SectionItem>::const_iterator i = sectionItems.constBegin(); i != sectionItems.constEnd(); ++i) {
- i->calculated_startpos = pixelpos; // write into const mutable
- pixelpos += i->size;
+ for (const SectionItem &i : sectionItems) {
+ i.calculated_startpos = pixelpos; // write into const mutable
+ pixelpos += i.size;
}
sectionStartposRecalc = false;
}
diff --git a/src/widgets/itemviews/qitemdelegate.cpp b/src/widgets/itemviews/qitemdelegate.cpp
index dff4cc4593..460764f1b8 100644
--- a/src/widgets/itemviews/qitemdelegate.cpp
+++ b/src/widgets/itemviews/qitemdelegate.cpp
@@ -266,7 +266,7 @@ QSizeF QItemDelegatePrivate::doTextLayout(int lineWidth) const
\row \li \l Qt::AccessibleDescriptionRole \li QString
\row \li \l Qt::AccessibleTextRole \li QString
\endomit
- \row \li \l Qt::BackgroundRole \li QBrush
+ \row \li \l Qt::BackgroundRole \li QBrush (\since 4.2)
\row \li \l Qt::BackgroundColorRole \li QColor (obsolete; use Qt::BackgroundRole instead)
\row \li \l Qt::CheckStateRole \li Qt::CheckState
\row \li \l Qt::DecorationRole \li QIcon, QPixmap and QColor
@@ -278,7 +278,7 @@ QSizeF QItemDelegatePrivate::doTextLayout(int lineWidth) const
\row \li \l Qt::StatusTipRole \li
\endomit
\row \li \l Qt::TextAlignmentRole \li Qt::Alignment
- \row \li \l Qt::ForegroundRole \li QBrush
+ \row \li \l Qt::ForegroundRole \li QBrush (\since 4.2)
\row \li \l Qt::TextColorRole \li QColor (obsolete; use Qt::ForegroundRole instead)
\omit
\row \li \l Qt::ToolTipRole
@@ -724,8 +724,8 @@ void QItemDelegate::drawDecoration(QPainter *painter, const QStyleOptionViewItem
QPoint p = QStyle::alignedRect(option.direction, option.decorationAlignment,
pixmap.size(), rect).topLeft();
if (option.state & QStyle::State_Selected) {
- QPixmap *pm = selected(pixmap, option.palette, option.state & QStyle::State_Enabled);
- painter->drawPixmap(p, *pm);
+ const QPixmap pm = selectedPixmap(pixmap, option.palette, option.state & QStyle::State_Enabled);
+ painter->drawPixmap(p, pm);
} else {
painter->drawPixmap(p, pixmap);
}
@@ -789,7 +789,7 @@ void QItemDelegate::drawCheck(QPainter *painter,
const QWidget *widget = d->widget(option);
QStyle *style = widget ? widget->style() : QApplication::style();
- style->drawPrimitive(QStyle::PE_IndicatorViewItemCheck, &opt, painter, widget);
+ style->drawPrimitive(QStyle::PE_IndicatorItemViewItemCheck, &opt, painter, widget);
}
/*!
@@ -1001,17 +1001,32 @@ static QString qPixmapSerial(quint64 i, bool enabled)
return QString((const QChar *)ptr, int(&arr[sizeof(arr) / sizeof(ushort)] - ptr));
}
+#if QT_DEPRECATED_SINCE(5, 13)
+QPixmap *QItemDelegate::selected(const QPixmap &pixmap, const QPalette &palette, bool enabled) const
+{
+ const QString key = qPixmapSerial(pixmap.cacheKey(), enabled);
+QT_WARNING_PUSH
+QT_WARNING_DISABLE_DEPRECATED
+ QPixmap *pm = QPixmapCache::find(key);
+ if (pm)
+ return pm;
+ selectedPixmap(pixmap, palette, enabled);
+ return QPixmapCache::find(key);
+QT_WARNING_POP
+}
+#endif
+
/*!
\internal
Returns the selected version of the given \a pixmap using the given \a palette.
The \a enabled argument decides whether the normal or disabled highlight color of
the palette is used.
*/
-QPixmap *QItemDelegate::selected(const QPixmap &pixmap, const QPalette &palette, bool enabled) const
+QPixmap QItemDelegate::selectedPixmap(const QPixmap &pixmap, const QPalette &palette, bool enabled)
{
- QString key = qPixmapSerial(pixmap.cacheKey(), enabled);
- QPixmap *pm = QPixmapCache::find(key);
- if (!pm) {
+ const QString key = qPixmapSerial(pixmap.cacheKey(), enabled);
+ QPixmap pm;
+ if (!QPixmapCache::find(key, &pm)) {
QImage img = pixmap.toImage().convertToFormat(QImage::Format_ARGB32_Premultiplied);
QColor color = palette.color(enabled ? QPalette::Normal : QPalette::Disabled,
@@ -1023,13 +1038,12 @@ QPixmap *QItemDelegate::selected(const QPixmap &pixmap, const QPalette &palette,
painter.fillRect(0, 0, img.width(), img.height(), color);
painter.end();
- QPixmap selected = QPixmap(QPixmap::fromImage(img));
- int n = (img.sizeInBytes() >> 10) + 1;
+ pm = QPixmap(QPixmap::fromImage(img));
+ const int n = (img.sizeInBytes() >> 10) + 1;
if (QPixmapCache::cacheLimit() < n)
QPixmapCache::setCacheLimit(n);
- QPixmapCache::insert(key, selected);
- pm = QPixmapCache::find(key);
+ QPixmapCache::insert(key, pm);
}
return pm;
}
@@ -1089,7 +1103,7 @@ QRect QItemDelegate::doCheck(const QStyleOptionViewItem &option,
opt.rect = bounding;
const QWidget *widget = d->widget(option); // cast
QStyle *style = widget ? widget->style() : QApplication::style();
- return style->subElementRect(QStyle::SE_ViewItemCheckIndicator, &opt, widget);
+ return style->subElementRect(QStyle::SE_ItemViewItemCheckIndicator, &opt, widget);
}
return QRect();
}
diff --git a/src/widgets/itemviews/qitemdelegate.h b/src/widgets/itemviews/qitemdelegate.h
index 539dec4374..e504615fb2 100644
--- a/src/widgets/itemviews/qitemdelegate.h
+++ b/src/widgets/itemviews/qitemdelegate.h
@@ -113,7 +113,12 @@ protected:
const QStyleOptionViewItem &option) const;
QPixmap decoration(const QStyleOptionViewItem &option, const QVariant &variant) const;
+
+#if QT_DEPRECATED_SINCE(5, 13)
+ QT_DEPRECATED_X("Use selectedPixmap() instead")
QPixmap *selected(const QPixmap &pixmap, const QPalette &palette, bool enabled) const;
+#endif
+ static QPixmap selectedPixmap(const QPixmap &pixmap, const QPalette &palette, bool enabled);
QRect doCheck(const QStyleOptionViewItem &option, const QRect &bounding,
const QVariant &variant) const;
diff --git a/src/widgets/itemviews/qitemeditorfactory.cpp b/src/widgets/itemviews/qitemeditorfactory.cpp
index 1465ee71a7..2d49dd4421 100644
--- a/src/widgets/itemviews/qitemeditorfactory.cpp
+++ b/src/widgets/itemviews/qitemeditorfactory.cpp
@@ -122,7 +122,7 @@ Q_SIGNALS:
\inmodule QtWidgets
When editing data in an item view, editors are created and
- displayed by a delegate. QItemDelegate, which is the delegate by
+ displayed by a delegate. QStyledItemDelegate, which is the delegate by
default installed on Qt's item views, uses a QItemEditorFactory to
create editors for it. A default unique instance provided by
QItemEditorFactory is used by all item delegates. If you set a
@@ -156,7 +156,7 @@ Q_SIGNALS:
Additional editors can be registered with the registerEditor() function.
- \sa QItemDelegate, {Model/View Programming}, {Color Editor Factory Example}
+ \sa QStyledItemDelegate, {Model/View Programming}, {Color Editor Factory Example}
*/
/*!
@@ -379,7 +379,7 @@ void QItemEditorFactory::setDefaultFactory(QItemEditorFactory *factory)
QItemEditorCreatorBase objects are specialized widget factories that
provide editor widgets for one particular QVariant data type. They
are used by QItemEditorFactory to create editors for
- \l{QItemDelegate}s. Creator bases must be registered with
+ \l{QStyledItemDelegate}s. Creator bases must be registered with
QItemEditorFactory::registerEditor().
An editor should provide a user property for the data it edits.
@@ -461,7 +461,7 @@ QItemEditorCreatorBase::~QItemEditorCreatorBase()
\snippet code/src_gui_itemviews_qitemeditorfactory.cpp 1
The constructor takes the name of the property that contains the
- editing data. QItemDelegate can then access the property by name
+ editing data. QStyledItemDelegate can then access the property by name
when it sets and retrieves editing data. Only use this class if
your editor does not define a user property (using the USER
keyword in the Q_PROPERTY macro). If the widget has a user
@@ -476,7 +476,7 @@ QItemEditorCreatorBase::~QItemEditorCreatorBase()
Constructs an editor creator object using \a valuePropertyName
as the name of the property to be used for editing. The
- property name is used by QItemDelegate when setting and
+ property name is used by QStyledItemDelegate when setting and
getting editor data.
Note that the \a valuePropertyName is only used if the editor
@@ -512,11 +512,11 @@ QItemEditorCreatorBase::~QItemEditorCreatorBase()
\snippet code/src_gui_itemviews_qitemeditorfactory.cpp 2
Setting the \c editorFactory created above in an item delegate via
- QItemDelegate::setItemEditorFactory() makes sure that all values of type
+ QStyledItemDelegate::setItemEditorFactory() makes sure that all values of type
QVariant::DateTime will be edited in \c{MyFancyDateTimeEdit}.
The editor must provide a user property that will contain the
- editing data. The property is used by \l{QItemDelegate}s to set
+ editing data. The property is used by \l{QStyledItemDelegate}s to set
and retrieve the data (using Qt's \l{Meta-Object
System}{meta-object system}). You set the user property with
the USER keyword:
@@ -524,7 +524,7 @@ QItemEditorCreatorBase::~QItemEditorCreatorBase()
\snippet code/src_gui_itemviews_qitemeditorfactory.cpp 3
\sa QItemEditorCreatorBase, QItemEditorCreator,
- QItemEditorFactory, QItemDelegate, {Color Editor Factory Example}
+ QItemEditorFactory, QStyledItemDelegate, {Color Editor Factory Example}
*/
/*!
diff --git a/src/widgets/itemviews/qitemeditorfactory.h b/src/widgets/itemviews/qitemeditorfactory.h
index f2610ad3de..118f6e45e8 100644
--- a/src/widgets/itemviews/qitemeditorfactory.h
+++ b/src/widgets/itemviews/qitemeditorfactory.h
@@ -66,8 +66,8 @@ class QItemEditorCreator : public QItemEditorCreatorBase
{
public:
inline explicit QItemEditorCreator(const QByteArray &valuePropertyName);
- inline QWidget *createWidget(QWidget *parent) const { return new T(parent); }
- inline QByteArray valuePropertyName() const { return propertyName; }
+ inline QWidget *createWidget(QWidget *parent) const override { return new T(parent); }
+ inline QByteArray valuePropertyName() const override { return propertyName; }
private:
QByteArray propertyName;
diff --git a/src/widgets/itemviews/qlistview.cpp b/src/widgets/itemviews/qlistview.cpp
index e07514f297..641b15f85b 100644
--- a/src/widgets/itemviews/qlistview.cpp
+++ b/src/widgets/itemviews/qlistview.cpp
@@ -2263,8 +2263,8 @@ int QListModeViewBase::verticalScrollToValue(int index, QListView::ScrollHint hi
} else {
int scrollBarValue = verticalScrollBar()->value();
int numHidden = 0;
- for (int i = 0; i < flowPositions.count() - 1 && i <= scrollBarValue; ++i)
- if (isHidden(i))
+ for (const auto &idx : qAsConst(dd->hiddenRows))
+ if (idx.row() <= scrollBarValue)
++numHidden;
value = qBound(0, scrollValueMap.at(verticalScrollBar()->value()) - numHidden, flowPositions.count() - 1);
}
@@ -2704,21 +2704,24 @@ int QListModeViewBase::perItemScrollToValue(int index, int scrollValue, int view
return scrollValue;
itemExtent += spacing();
- QVector<int> visibleFlowPositions;
- visibleFlowPositions.reserve(flowPositions.count() - 1);
- for (int i = 0; i < flowPositions.count() - 1; i++) { // flowPositions count is +1 larger than actual row count
- if (!isHidden(i))
- visibleFlowPositions.append(flowPositions.at(i));
- }
-
+ QVector<int> hiddenRows = dd->hiddenRowIds();
+ std::sort(hiddenRows.begin(), hiddenRows.end());
+ int hiddenRowsBefore = 0;
+ for (int i = 0; i < hiddenRows.size() - 1; ++i)
+ if (hiddenRows.at(i) > index + hiddenRowsBefore)
+ break;
+ else
+ ++hiddenRowsBefore;
if (!wrap) {
int topIndex = index;
const int bottomIndex = topIndex;
- const int bottomCoordinate = visibleFlowPositions.at(index);
-
+ const int bottomCoordinate = flowPositions.at(index + hiddenRowsBefore);
while (topIndex > 0 &&
- (bottomCoordinate - visibleFlowPositions.at(topIndex - 1) + itemExtent) <= (viewportSize)) {
+ (bottomCoordinate - flowPositions.at(topIndex + hiddenRowsBefore - 1) + itemExtent) <= (viewportSize)) {
topIndex--;
+ // will the next one be a hidden row -> skip
+ while (hiddenRowsBefore > 0 && hiddenRows.at(hiddenRowsBefore - 1) >= topIndex + hiddenRowsBefore - 1)
+ hiddenRowsBefore--;
}
const int itemCount = bottomIndex - topIndex + 1;
@@ -2737,7 +2740,7 @@ int QListModeViewBase::perItemScrollToValue(int index, int scrollValue, int view
? Qt::Horizontal : Qt::Vertical);
if (flowOrientation == orientation) { // scrolling in the "flow" direction
// ### wrapped scrolling in the flow direction
- return visibleFlowPositions.at(index); // ### always pixel based for now
+ return flowPositions.at(index + hiddenRowsBefore); // ### always pixel based for now
} else if (!segmentStartRows.isEmpty()) { // we are scrolling in the "segment" direction
int segment = qBinarySearch<int>(segmentStartRows, index, 0, segmentStartRows.count() - 1);
int leftSegment = segment;
@@ -3371,9 +3374,9 @@ int QListView::visualIndex(const QModelIndex &index) const
d->executePostedLayout();
QListViewItem itm = d->indexToListViewItem(index);
int visualIndex = d->commonListView->itemIndex(itm);
- for (int row = 0; row <= index.row() && visualIndex >= 0; row++) {
- if (d->isHidden(row))
- visualIndex--;
+ for (const auto &idx : qAsConst(d->hiddenRows)) {
+ if (idx.row() <= index.row())
+ --visualIndex;
}
return visualIndex;
}
diff --git a/src/widgets/itemviews/qlistview_p.h b/src/widgets/itemviews/qlistview_p.h
index c94357afe9..c6810f8fdc 100644
--- a/src/widgets/itemviews/qlistview_p.h
+++ b/src/widgets/itemviews/qlistview_p.h
@@ -394,6 +394,14 @@ public:
QModelIndex idx = model->index(row, 0, root);
return isPersistent(idx) && hiddenRows.contains(idx);
}
+ // helper to avoid checking for isPersistent and creating persistent indexes as above in isHidden
+ QVector<int> hiddenRowIds() const {
+ QVector<int> rowIds;
+ rowIds.reserve(hiddenRows.size());
+ for (const auto &idx : hiddenRows)
+ rowIds += idx.row();
+ return rowIds;
+ }
inline bool isHiddenOrDisabled(int row) const { return isHidden(row) || !isIndexEnabled(modelIndex(row)); }
void removeCurrentAndDisabled(QVector<QModelIndex> *indexes, const QModelIndex &current) const;
diff --git a/src/widgets/itemviews/qlistwidget.cpp b/src/widgets/itemviews/qlistwidget.cpp
index b9c0e0a4b7..a9899983c2 100644
--- a/src/widgets/itemviews/qlistwidget.cpp
+++ b/src/widgets/itemviews/qlistwidget.cpp
@@ -227,6 +227,22 @@ bool QListModel::setData(const QModelIndex &index, const QVariant &value, int ro
return true;
}
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
+bool QListModel::clearItemData(const QModelIndex &index)
+{
+ if (!checkIndex(index, CheckIndexOption::IndexIsValid))
+ return false;
+ QListWidgetItem *item = items.at(index.row());
+ const auto beginIter = item->d->values.cbegin();
+ const auto endIter = item->d->values.cend();
+ if (std::all_of(beginIter, endIter, [](const QWidgetItemData& data) -> bool { return !data.value.isValid(); }))
+ return true; //it's already cleared
+ item->d->values.clear();
+ emit dataChanged(index, index, QVector<int>{});
+ return true;
+}
+#endif
+
QMap<int, QVariant> QListModel::itemData(const QModelIndex &index) const
{
QMap<int, QVariant> roles;
@@ -277,6 +293,30 @@ bool QListModel::removeRows(int row, int count, const QModelIndex &parent)
return true;
}
+/*!
+ \since 5.13
+ \reimp
+*/
+bool QListModel::moveRows(const QModelIndex &sourceParent, int sourceRow, int count, const QModelIndex &destinationParent, int destinationChild)
+{
+ if (sourceRow < 0
+ || sourceRow + count - 1 >= rowCount(sourceParent)
+ || destinationChild <= 0
+ || destinationChild > rowCount(destinationParent)
+ || sourceRow == destinationChild - 1
+ || count <= 0) {
+ return false;
+ }
+ if (!beginMoveRows(QModelIndex(), sourceRow, sourceRow + count - 1, QModelIndex(), destinationChild))
+ return false;
+ destinationChild--;
+ const int fromRow = destinationChild < sourceRow ? (sourceRow + count - 1) : sourceRow;
+ while (count--)
+ items.move(fromRow, destinationChild);
+ endMoveRows();
+ return true;
+}
+
Qt::ItemFlags QListModel::flags(const QModelIndex &index) const
{
if (!index.isValid() || index.row() >= items.count() || index.model() != this)
@@ -289,7 +329,7 @@ void QListModel::sort(int column, Qt::SortOrder order)
if (column != 0)
return;
- emit layoutAboutToBeChanged();
+ emit layoutAboutToBeChanged({}, QAbstractItemModel::VerticalSortHint);
QVector < QPair<QListWidgetItem*,int> > sorting(items.count());
for (int i = 0; i < items.count(); ++i) {
@@ -313,7 +353,7 @@ void QListModel::sort(int column, Qt::SortOrder order)
}
changePersistentIndexList(fromIndexes, toIndexes);
- emit layoutChanged();
+ emit layoutChanged({}, QAbstractItemModel::VerticalSortHint);
}
/**
@@ -543,24 +583,6 @@ Qt::DropActions QListModel::supportedDropActions() const
*/
/*!
- \fn void QListWidgetItem::setSelected(bool select)
- \since 4.2
-
- Sets the selected state of the item to \a select.
-
- \sa isSelected()
-*/
-
-/*!
- \fn bool QListWidgetItem::isSelected() const
- \since 4.2
-
- Returns \c true if the item is selected; otherwise returns \c false.
-
- \sa setSelected()
-*/
-
-/*!
\fn void QListWidgetItem::setHidden(bool hide)
\since 4.2
@@ -594,14 +616,14 @@ Qt::DropActions QListModel::supportedDropActions() const
\sa type()
*/
-QListWidgetItem::QListWidgetItem(QListWidget *view, int type)
- : rtti(type), view(view), d(new QListWidgetItemPrivate(this)),
+QListWidgetItem::QListWidgetItem(QListWidget *listview, int type)
+ : rtti(type), view(listview), d(new QListWidgetItemPrivate(this)),
itemFlags(Qt::ItemIsSelectable
|Qt::ItemIsUserCheckable
|Qt::ItemIsEnabled
|Qt::ItemIsDragEnabled)
{
- if (QListModel *model = (view ? qobject_cast<QListModel*>(view->model()) : 0))
+ if (QListModel *model = listModel())
model->insert(model->rowCount(), this);
}
@@ -621,16 +643,18 @@ QListWidgetItem::QListWidgetItem(QListWidget *view, int type)
\sa type()
*/
-QListWidgetItem::QListWidgetItem(const QString &text, QListWidget *view, int type)
- : rtti(type), view(0), d(new QListWidgetItemPrivate(this)),
+QListWidgetItem::QListWidgetItem(const QString &text, QListWidget *listview, int type)
+ : rtti(type), view(listview), d(new QListWidgetItemPrivate(this)),
itemFlags(Qt::ItemIsSelectable
|Qt::ItemIsUserCheckable
|Qt::ItemIsEnabled
|Qt::ItemIsDragEnabled)
{
- setData(Qt::DisplayRole, text);
- this->view = view;
- if (QListModel *model = (view ? qobject_cast<QListModel*>(view->model()) : 0))
+ {
+ QSignalBlocker b(view);
+ setData(Qt::DisplayRole, text);
+ }
+ if (QListModel *model = listModel())
model->insert(model->rowCount(), this);
}
@@ -652,17 +676,19 @@ QListWidgetItem::QListWidgetItem(const QString &text, QListWidget *view, int typ
\sa type()
*/
QListWidgetItem::QListWidgetItem(const QIcon &icon,const QString &text,
- QListWidget *view, int type)
- : rtti(type), view(0), d(new QListWidgetItemPrivate(this)),
+ QListWidget *listview, int type)
+ : rtti(type), view(listview), d(new QListWidgetItemPrivate(this)),
itemFlags(Qt::ItemIsSelectable
|Qt::ItemIsUserCheckable
|Qt::ItemIsEnabled
|Qt::ItemIsDragEnabled)
{
- setData(Qt::DisplayRole, text);
- setData(Qt::DecorationRole, icon);
- this->view = view;
- if (QListModel *model = (view ? qobject_cast<QListModel*>(view->model()) : 0))
+ {
+ QSignalBlocker b(view);
+ setData(Qt::DisplayRole, text);
+ setData(Qt::DecorationRole, icon);
+ }
+ if (QListModel *model = listModel())
model->insert(model->rowCount(), this);
}
@@ -671,7 +697,7 @@ QListWidgetItem::QListWidgetItem(const QIcon &icon,const QString &text,
*/
QListWidgetItem::~QListWidgetItem()
{
- if (QListModel *model = (view ? qobject_cast<QListModel*>(view->model()) : 0))
+ if (QListModel *model = listModel())
model->remove(this);
delete d;
}
@@ -708,7 +734,7 @@ void QListWidgetItem::setData(int role, const QVariant &value)
}
if (!found)
d->values.append(QWidgetItemData(role, value));
- if (QListModel *model = (view ? qobject_cast<QListModel*>(view->model()) : nullptr)) {
+ if (QListModel *model = listModel()) {
const QVector<int> roles((role == Qt::DisplayRole) ?
QVector<int>({Qt::DisplayRole, Qt::EditRole}) :
QVector<int>({role}));
@@ -775,7 +801,7 @@ void QListWidgetItem::write(QDataStream &out) const
\sa data(), flags()
*/
QListWidgetItem::QListWidgetItem(const QListWidgetItem &other)
- : rtti(Type), view(0),
+ : rtti(Type), view(nullptr),
d(new QListWidgetItemPrivate(this)),
itemFlags(other.itemFlags)
{
@@ -797,6 +823,15 @@ QListWidgetItem &QListWidgetItem::operator=(const QListWidgetItem &other)
return *this;
}
+/*!
+ \internal
+ returns the QListModel if a view is set
+ */
+QListModel *QListWidgetItem::listModel() const
+{
+ return (view ? qobject_cast<QListModel*>(view->model()) : nullptr);
+}
+
#ifndef QT_NO_DATASTREAM
/*!
@@ -949,6 +984,50 @@ QDataStream &operator>>(QDataStream &in, QListWidgetItem &item)
*/
/*!
+ \fn void QListWidgetItem::setSelected(bool select)
+ \since 4.2
+
+ Sets the selected state of the item to \a select.
+
+ \sa isSelected()
+*/
+void QListWidgetItem::setSelected(bool select)
+{
+ const QListModel *model = listModel();
+ if (!model || !view->selectionModel())
+ return;
+ const QAbstractItemView::SelectionMode selectionMode = view->selectionMode();
+ if (selectionMode == QAbstractItemView::NoSelection)
+ return;
+ const QModelIndex index = model->index(this);
+ if (selectionMode == QAbstractItemView::SingleSelection)
+ view->selectionModel()->select(index, select
+ ? QItemSelectionModel::ClearAndSelect
+ : QItemSelectionModel::Deselect);
+ else
+ view->selectionModel()->select(index, select
+ ? QItemSelectionModel::Select
+ : QItemSelectionModel::Deselect);
+}
+
+/*!
+ \fn bool QListWidgetItem::isSelected() const
+ \since 4.2
+
+ Returns \c true if the item is selected; otherwise returns \c false.
+
+ \sa setSelected()
+*/
+bool QListWidgetItem::isSelected() const
+{
+ const QListModel *model = listModel();
+ if (!model || !view->selectionModel())
+ return false;
+ const QModelIndex index = model->index(this);
+ return view->selectionModel()->isSelected(index);
+}
+
+/*!
\fn void QListWidgetItem::setFlags(Qt::ItemFlags flags)
Sets the item flags for the list item to \a flags.
@@ -958,7 +1037,7 @@ QDataStream &operator>>(QDataStream &in, QListWidgetItem &item)
void QListWidgetItem::setFlags(Qt::ItemFlags aflags)
{
itemFlags = aflags;
- if (QListModel *model = (view ? qobject_cast<QListModel*>(view->model()) : 0))
+ if (QListModel *model = listModel())
model->itemChanged(this);
}
@@ -1678,7 +1757,7 @@ QWidget *QListWidget::itemWidget(QListWidgetItem *item) const
This function should only be used to display static content in the place of
a list widget item. If you want to display custom dynamic content or
- implement a custom editor widget, use QListView and subclass QItemDelegate
+ implement a custom editor widget, use QListView and subclass QStyledItemDelegate
instead.
\sa itemWidget(), removeItemWidget(), {Delegate Classes}
@@ -1690,6 +1769,7 @@ void QListWidget::setItemWidget(QListWidgetItem *item, QWidget *widget)
QAbstractItemView::setIndexWidget(index, widget);
}
+#if QT_DEPRECATED_SINCE(5, 13)
/*!
Returns \c true if \a item is selected; otherwise returns \c false.
@@ -1699,9 +1779,7 @@ void QListWidget::setItemWidget(QListWidgetItem *item, QWidget *widget)
*/
bool QListWidget::isItemSelected(const QListWidgetItem *item) const
{
- Q_D(const QListWidget);
- QModelIndex index = d->listModel()->index(const_cast<QListWidgetItem*>(item));
- return selectionModel()->isSelected(index);
+ return ((item && item->listWidget() == this) ? item->isSelected() : false);
}
/*!
@@ -1714,20 +1792,10 @@ bool QListWidget::isItemSelected(const QListWidgetItem *item) const
*/
void QListWidget::setItemSelected(const QListWidgetItem *item, bool select)
{
- Q_D(QListWidget);
- QModelIndex index = d->listModel()->index(const_cast<QListWidgetItem*>(item));
-
- if (d->selectionMode == SingleSelection) {
- selectionModel()->select(index, select
- ? QItemSelectionModel::ClearAndSelect
- : QItemSelectionModel::Deselect);
- } else if (d->selectionMode != NoSelection) {
- selectionModel()->select(index, select
- ? QItemSelectionModel::Select
- : QItemSelectionModel::Deselect);
- }
-
+ if (item && item->listWidget() == this)
+ const_cast<QListWidgetItem*>(item)->setSelected(select);
}
+#endif
/*!
Returns a list of all selected items in the list widget.
@@ -1763,6 +1831,7 @@ QList<QListWidgetItem*> QListWidget::findItems(const QString &text, Qt::MatchFla
return items;
}
+#if QT_DEPRECATED_SINCE(5, 13)
/*!
Returns \c true if the \a item is explicitly hidden; otherwise returns \c false.
@@ -1786,6 +1855,7 @@ void QListWidget::setItemHidden(const QListWidgetItem *item, bool hide)
{
setRowHidden(row(item), hide);
}
+#endif
/*!
Scrolls the view if necessary to ensure that the \a item is visible.
diff --git a/src/widgets/itemviews/qlistwidget.h b/src/widgets/itemviews/qlistwidget.h
index 947fdb1a2f..c093d13e6d 100644
--- a/src/widgets/itemviews/qlistwidget.h
+++ b/src/widgets/itemviews/qlistwidget.h
@@ -61,10 +61,10 @@ class Q_WIDGETS_EXPORT QListWidgetItem
friend class QListWidget;
public:
enum ItemType { Type = 0, UserType = 1000 };
- explicit QListWidgetItem(QListWidget *view = nullptr, int type = Type);
- explicit QListWidgetItem(const QString &text, QListWidget *view = nullptr, int type = Type);
+ explicit QListWidgetItem(QListWidget *listview = nullptr, int type = Type);
+ explicit QListWidgetItem(const QString &text, QListWidget *listview = nullptr, int type = Type);
explicit QListWidgetItem(const QIcon &icon, const QString &text,
- QListWidget *view = nullptr, int type = Type);
+ QListWidget *listview = nullptr, int type = Type);
QListWidgetItem(const QListWidgetItem &other);
virtual ~QListWidgetItem();
@@ -72,8 +72,8 @@ public:
inline QListWidget *listWidget() const { return view; }
- inline void setSelected(bool select);
- inline bool isSelected() const;
+ void setSelected(bool select);
+ bool isSelected() const;
inline void setHidden(bool hide);
inline bool isHidden() const;
@@ -114,20 +114,28 @@ public:
inline void setTextAlignment(int alignment)
{ setData(Qt::TextAlignmentRole, alignment); }
+#if QT_DEPRECATED_SINCE(5, 13)
+ QT_DEPRECATED_X ("Use QListWidgetItem::background() instead")
inline QColor backgroundColor() const
- { return qvariant_cast<QColor>(data(Qt::BackgroundColorRole)); }
+ { return qvariant_cast<QColor>(data(Qt::BackgroundRole)); }
+ QT_DEPRECATED_X ("Use QListWidgetItem::setBackground() instead")
virtual void setBackgroundColor(const QColor &color)
- { setData(Qt::BackgroundColorRole, color); }
+ { setData(Qt::BackgroundRole, color); }
+#endif
inline QBrush background() const
{ return qvariant_cast<QBrush>(data(Qt::BackgroundRole)); }
inline void setBackground(const QBrush &brush)
{ setData(Qt::BackgroundRole, brush); }
+#if QT_DEPRECATED_SINCE(5, 13)
+ QT_DEPRECATED_X ("Use QListWidgetItem::foreground() instead")
inline QColor textColor() const
- { return qvariant_cast<QColor>(data(Qt::TextColorRole)); }
+ { return qvariant_cast<QColor>(data(Qt::ForegroundRole)); }
+ QT_DEPRECATED_X ("Use QListWidgetItem::setForeground() instead")
inline void setTextColor(const QColor &color)
- { setData(Qt::TextColorRole, color); }
+ { setData(Qt::ForegroundRole, color); }
+#endif
inline QBrush foreground() const
{ return qvariant_cast<QBrush>(data(Qt::ForegroundRole)); }
@@ -158,6 +166,7 @@ public:
inline int type() const { return rtti; }
private:
+ QListModel *listModel() const;
int rtti;
QVector<void *> dummy;
QListWidget *view;
@@ -246,13 +255,21 @@ public:
void setItemWidget(QListWidgetItem *item, QWidget *widget);
inline void removeItemWidget(QListWidgetItem *item);
+#if QT_DEPRECATED_SINCE(5, 13)
+ QT_DEPRECATED_X ("Use QListWidgetItem::isSelected() instead")
bool isItemSelected(const QListWidgetItem *item) const;
+ QT_DEPRECATED_X ("Use QListWidgetItem::setSelected() instead")
void setItemSelected(const QListWidgetItem *item, bool select);
+#endif
QList<QListWidgetItem*> selectedItems() const;
QList<QListWidgetItem*> findItems(const QString &text, Qt::MatchFlags flags) const;
+#if QT_DEPRECATED_SINCE(5, 13)
+ QT_DEPRECATED_X ("Use QListWidgetItem::isHidden() instead")
bool isItemHidden(const QListWidgetItem *item) const;
+ QT_DEPRECATED_X ("Use QListWidgetItem::setHidden() instead")
void setItemHidden(const QListWidgetItem *item, bool hide);
+#endif
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
protected:
#endif
@@ -331,17 +348,11 @@ inline void QListWidget::addItem(QListWidgetItem *aitem)
inline QListWidgetItem *QListWidget::itemAt(int ax, int ay) const
{ return itemAt(QPoint(ax, ay)); }
-inline void QListWidgetItem::setSelected(bool aselect)
-{ if (view) view->setItemSelected(this, aselect); }
-
-inline bool QListWidgetItem::isSelected() const
-{ return (view ? view->isItemSelected(this) : false); }
-
inline void QListWidgetItem::setHidden(bool ahide)
-{ if (view) view->setItemHidden(this, ahide); }
+{ if (view) view->setRowHidden(view->row(this), ahide); }
inline bool QListWidgetItem::isHidden() const
-{ return (view ? view->isItemHidden(this) : false); }
+{ return (view ? view->isRowHidden(view->row(this)) : false); }
QT_END_NAMESPACE
diff --git a/src/widgets/itemviews/qlistwidget_p.h b/src/widgets/itemviews/qlistwidget_p.h
index 9cb3d5966b..65a7124322 100644
--- a/src/widgets/itemviews/qlistwidget_p.h
+++ b/src/widgets/itemviews/qlistwidget_p.h
@@ -100,11 +100,15 @@ public:
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
bool setData(const QModelIndex &index, const QVariant &value, int role) override;
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
+ bool clearItemData(const QModelIndex &index) override;
+#endif
QMap<int, QVariant> itemData(const QModelIndex &index) const override;
bool insertRows(int row, int count = 1, const QModelIndex &parent = QModelIndex()) override;
bool removeRows(int row, int count = 1, const QModelIndex &parent = QModelIndex()) override;
+ bool moveRows(const QModelIndex &sourceParent, int sourceRow, int count, const QModelIndex &destinationParent, int destinationChild) override;
Qt::ItemFlags flags(const QModelIndex &index) const override;
diff --git a/src/widgets/itemviews/qstyleditemdelegate.cpp b/src/widgets/itemviews/qstyleditemdelegate.cpp
index 0f7566e8ec..22067851cb 100644
--- a/src/widgets/itemviews/qstyleditemdelegate.cpp
+++ b/src/widgets/itemviews/qstyleditemdelegate.cpp
@@ -139,7 +139,7 @@ public:
\row \li \l Qt::AccessibleDescriptionRole \li QString
\row \li \l Qt::AccessibleTextRole \li QString
\endomit
- \row \li \l Qt::BackgroundRole \li QBrush
+ \row \li \l Qt::BackgroundRole \li QBrush (\since 4.2)
\row \li \l Qt::BackgroundColorRole \li QColor (obsolete; use Qt::BackgroundRole instead)
\row \li \l Qt::CheckStateRole \li Qt::CheckState
\row \li \l Qt::DecorationRole \li QIcon, QPixmap, QImage and QColor
@@ -151,7 +151,7 @@ public:
\row \li \l Qt::StatusTipRole \li
\endomit
\row \li \l Qt::TextAlignmentRole \li Qt::Alignment
- \row \li \l Qt::ForegroundRole \li QBrush
+ \row \li \l Qt::ForegroundRole \li QBrush (\since 4.2)
\row \li \l Qt::TextColorRole \li QColor (obsolete; use Qt::ForegroundRole instead)
\omit
\row \li \l Qt::ToolTipRole
diff --git a/src/widgets/itemviews/qtableview.cpp b/src/widgets/itemviews/qtableview.cpp
index 9c509583e6..dd43c6d3e4 100644
--- a/src/widgets/itemviews/qtableview.cpp
+++ b/src/widgets/itemviews/qtableview.cpp
@@ -138,20 +138,21 @@ void QSpanCollection::updateSpan(QSpanCollection::Span *span, int old_height)
}
/** \internal
- * \return a spans that spans over cell x,y (column,row) or 0 if there is none.
+ * \return a spans that spans over cell x,y (column,row)
+ * or \nullptr if there is none.
*/
QSpanCollection::Span *QSpanCollection::spanAt(int x, int y) const
{
Index::const_iterator it_y = index.lowerBound(-y);
if (it_y == index.end())
- return 0;
+ return nullptr;
SubIndex::const_iterator it_x = (*it_y).lowerBound(-x);
if (it_x == (*it_y).end())
- return 0;
+ return nullptr;
Span *span = *it_x;
if (span->right() >= x && span->bottom() >= y)
return span;
- return 0;
+ return nullptr;
}
@@ -964,6 +965,15 @@ void QTableViewPrivate::_q_updateSpanRemovedColumns(const QModelIndex &parent, i
/*!
\internal
+ Sort the model when the header sort indicator changed
+*/
+void QTableViewPrivate::_q_sortIndicatorChanged(int column, Qt::SortOrder order)
+{
+ model->sort(column, order);
+}
+
+/*!
+ \internal
Draws a table cell.
*/
void QTableViewPrivate::drawCell(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index)
@@ -1099,7 +1109,7 @@ int QTableViewPrivate::heightHintForIndex(const QModelIndex &index, int hint, QS
\l showGrid property.
The items shown in a table view, like those in the other item views, are
- rendered and edited using standard \l{QItemDelegate}{delegates}. However,
+ rendered and edited using standard \l{QStyledItemDelegate}{delegates}. However,
for some tasks it is sometimes useful to be able to insert widgets in a
table instead. Widgets are set for particular indexes with the
\l{QAbstractItemView::}{setIndexWidget()} function, and
@@ -1171,8 +1181,6 @@ QSize QTableView::viewportSizeHint() const
Q_D(const QTableView);
QSize result( (d->verticalHeader->isHidden() ? 0 : d->verticalHeader->width()) + d->horizontalHeader->length(),
(d->horizontalHeader->isHidden() ? 0 : d->horizontalHeader->height()) + d->verticalHeader->length());
- result += QSize(verticalScrollBar()->isVisible() ? verticalScrollBar()->width() : 0,
- horizontalScrollBar()->isVisible() ? horizontalScrollBar()->height() : 0);
return result;
}
@@ -1443,12 +1451,12 @@ void QTableView::paintEvent(QPaintEvent *event)
//firstVisualRow is the visual index of the first visible row. lastVisualRow is the visual index of the last visible Row.
//same goes for ...VisualColumn
int firstVisualRow = qMax(verticalHeader->visualIndexAt(0),0);
- int lastVisualRow = verticalHeader->visualIndexAt(verticalHeader->viewport()->height());
+ int lastVisualRow = verticalHeader->visualIndexAt(verticalHeader->height());
if (lastVisualRow == -1)
lastVisualRow = d->model->rowCount(d->root) - 1;
int firstVisualColumn = horizontalHeader->visualIndexAt(0);
- int lastVisualColumn = horizontalHeader->visualIndexAt(horizontalHeader->viewport()->width());
+ int lastVisualColumn = horizontalHeader->visualIndexAt(horizontalHeader->width());
if (rightToLeft)
qSwap(firstVisualColumn, lastVisualColumn);
if (firstVisualColumn == -1)
@@ -2634,25 +2642,27 @@ void QTableView::setColumnHidden(int column, bool hide)
void QTableView::setSortingEnabled(bool enable)
{
Q_D(QTableView);
- d->sortingEnabled = enable;
horizontalHeader()->setSortIndicatorShown(enable);
if (enable) {
disconnect(d->horizontalHeader, SIGNAL(sectionEntered(int)),
this, SLOT(_q_selectColumn(int)));
disconnect(horizontalHeader(), SIGNAL(sectionPressed(int)),
this, SLOT(selectColumn(int)));
- connect(horizontalHeader(), SIGNAL(sortIndicatorChanged(int,Qt::SortOrder)),
- this, SLOT(sortByColumn(int)), Qt::UniqueConnection);
+ //sortByColumn has to be called before we connect or set the sortingEnabled flag
+ // because otherwise it will not call sort on the model.
sortByColumn(horizontalHeader()->sortIndicatorSection(),
horizontalHeader()->sortIndicatorOrder());
+ connect(horizontalHeader(), SIGNAL(sortIndicatorChanged(int,Qt::SortOrder)),
+ this, SLOT(_q_sortIndicatorChanged(int,Qt::SortOrder)), Qt::UniqueConnection);
} else {
connect(d->horizontalHeader, SIGNAL(sectionEntered(int)),
this, SLOT(_q_selectColumn(int)), Qt::UniqueConnection);
connect(horizontalHeader(), SIGNAL(sectionPressed(int)),
this, SLOT(selectColumn(int)), Qt::UniqueConnection);
disconnect(horizontalHeader(), SIGNAL(sortIndicatorChanged(int,Qt::SortOrder)),
- this, SLOT(sortByColumn(int)));
+ this, SLOT(_q_sortIndicatorChanged(int,Qt::SortOrder)));
}
+ d->sortingEnabled = enable;
}
bool QTableView::isSortingEnabled() const
@@ -3181,19 +3191,21 @@ void QTableView::resizeColumnsToContents()
d->horizontalHeader->resizeSections(QHeaderView::ResizeToContents);
}
+#if QT_DEPRECATED_SINCE(5, 13)
/*!
\obsolete
\overload
+ This function is deprecated. Use
+ sortByColumn(int column, Qt::SortOrder order) instead.
Sorts the model by the values in the given \a column.
*/
void QTableView::sortByColumn(int column)
{
Q_D(QTableView);
- if (column == -1)
- return;
- d->model->sort(column, d->horizontalHeader->sortIndicatorOrder());
+ sortByColumn(column, d->horizontalHeader->sortIndicatorOrder());
}
+#endif
/*!
\since 4.2
@@ -3205,8 +3217,14 @@ void QTableView::sortByColumn(int column)
void QTableView::sortByColumn(int column, Qt::SortOrder order)
{
Q_D(QTableView);
+ if (column < 0)
+ return;
+ // If sorting is enabled it will emit a signal connected to
+ // _q_sortIndicatorChanged, which then actually sorts
d->horizontalHeader->setSortIndicator(column, order);
- sortByColumn(column);
+ // If sorting is not enabled, force to sort now
+ if (!d->sortingEnabled)
+ d->model->sort(column, order);
}
/*!
diff --git a/src/widgets/itemviews/qtableview.h b/src/widgets/itemviews/qtableview.h
index 60c2f34103..3275c09f88 100644
--- a/src/widgets/itemviews/qtableview.h
+++ b/src/widgets/itemviews/qtableview.h
@@ -118,7 +118,6 @@ public:
int columnSpan(int row, int column) const;
void clearSpans();
- void sortByColumn(int column, Qt::SortOrder order);
public Q_SLOTS:
void selectRow(int row);
@@ -131,7 +130,11 @@ public Q_SLOTS:
void resizeRowsToContents();
void resizeColumnToContents(int column);
void resizeColumnsToContents();
+#if QT_DEPRECATED_SINCE(5, 13)
+ QT_DEPRECATED_X ("Use QTableView::sortByColumn(int column, Qt::SortOrder order) instead")
void sortByColumn(int column);
+#endif
+ void sortByColumn(int column, Qt::SortOrder order);
void setShowGrid(bool show);
protected Q_SLOTS:
@@ -188,6 +191,7 @@ private:
Q_PRIVATE_SLOT(d_func(), void _q_updateSpanInsertedColumns(QModelIndex,int,int))
Q_PRIVATE_SLOT(d_func(), void _q_updateSpanRemovedRows(QModelIndex,int,int))
Q_PRIVATE_SLOT(d_func(), void _q_updateSpanRemovedColumns(QModelIndex,int,int))
+ Q_PRIVATE_SLOT(d_func(), void _q_sortIndicatorChanged(int column, Qt::SortOrder order))
};
QT_END_NAMESPACE
diff --git a/src/widgets/itemviews/qtableview_p.h b/src/widgets/itemviews/qtableview_p.h
index a50e6b6410..d55462c28b 100644
--- a/src/widgets/itemviews/qtableview_p.h
+++ b/src/widgets/itemviews/qtableview_p.h
@@ -257,6 +257,7 @@ public:
void _q_updateSpanInsertedColumns(const QModelIndex &parent, int start, int end);
void _q_updateSpanRemovedRows(const QModelIndex &parent, int start, int end);
void _q_updateSpanRemovedColumns(const QModelIndex &parent, int start, int end);
+ void _q_sortIndicatorChanged(int column, Qt::SortOrder order);
};
QT_END_NAMESPACE
diff --git a/src/widgets/itemviews/qtablewidget.cpp b/src/widgets/itemviews/qtablewidget.cpp
index eee3e91ac3..f99d69d37c 100644
--- a/src/widgets/itemviews/qtablewidget.cpp
+++ b/src/widgets/itemviews/qtablewidget.cpp
@@ -189,7 +189,7 @@ void QTableModel::setItem(int row, int column, QTableWidgetItem *item)
sortedRow = qMax((int)(it - colItems.begin()), 0);
}
if (sortedRow != row) {
- emit layoutAboutToBeChanged();
+ emit layoutAboutToBeChanged({}, QAbstractItemModel::VerticalSortHint);
// move the items @ row to sortedRow
int cc = columnCount();
QVector<QTableWidgetItem*> rowItems(cc);
@@ -209,7 +209,7 @@ void QTableModel::setItem(int row, int column, QTableWidgetItem *item)
changePersistentIndexList(oldPersistentIndexes,
newPersistentIndexes);
- emit layoutChanged();
+ emit layoutChanged({}, QAbstractItemModel::VerticalSortHint);
return;
}
}
@@ -480,6 +480,24 @@ bool QTableModel::setItemData(const QModelIndex &index, const QMap<int, QVariant
return true;
}
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
+bool QTableModel::clearItemData(const QModelIndex &index)
+{
+ if (!checkIndex(index, CheckIndexOption::IndexIsValid))
+ return false;
+ QTableWidgetItem *itm = item(index);
+ if (!itm)
+ return false;
+ const auto beginIter = itm->values.cbegin();
+ const auto endIter = itm->values.cend();
+ if (std::all_of(beginIter, endIter, [](const QWidgetItemData& data) -> bool { return !data.value.isValid(); }))
+ return true; //it's already cleared
+ itm->values.clear();
+ emit dataChanged(index, index, QVector<int>{});
+ return true;
+}
+#endif
+
Qt::ItemFlags QTableModel::flags(const QModelIndex &index) const
{
if (!index.isValid())
@@ -530,12 +548,12 @@ void QTableModel::sort(int column, Qt::SortOrder order)
}
}
- emit layoutAboutToBeChanged();
+ emit layoutAboutToBeChanged({}, QAbstractItemModel::VerticalSortHint);
tableItems = sorted_table;
changePersistentIndexList(from, to); // ### slow
- emit layoutChanged();
+ emit layoutChanged({}, QAbstractItemModel::VerticalSortHint);
}
/*
@@ -580,7 +598,7 @@ void QTableModel::ensureSorted(int column, Qt::SortOrder order,
vit = colItems.insert(vit, item);
if (newRow != oldRow) {
if (!changed) {
- emit layoutAboutToBeChanged();
+ emit layoutAboutToBeChanged({}, QAbstractItemModel::VerticalSortHint);
oldPersistentIndexes = persistentIndexList();
newPersistentIndexes = oldPersistentIndexes;
changed = true;
@@ -615,7 +633,7 @@ void QTableModel::ensureSorted(int column, Qt::SortOrder order,
verticalHeaderItems = newVertical;
changePersistentIndexList(oldPersistentIndexes,
newPersistentIndexes);
- emit layoutChanged();
+ emit layoutChanged({}, QAbstractItemModel::VerticalSortHint);
}
}
@@ -1037,24 +1055,6 @@ QTableWidgetSelectionRange::~QTableWidgetSelectionRange()
*/
/*!
- \fn void QTableWidgetItem::setSelected(bool select)
- \since 4.2
-
- Sets the selected state of the item to \a select.
-
- \sa isSelected()
-*/
-
-/*!
- \fn bool QTableWidgetItem::isSelected() const
- \since 4.2
-
- Returns \c true if the item is selected, otherwise returns \c false.
-
- \sa setSelected()
-*/
-
-/*!
\fn QSize QTableWidgetItem::sizeHint() const
\since 4.1
@@ -1091,6 +1091,44 @@ QTableWidgetSelectionRange::~QTableWidgetSelectionRange()
*/
/*!
+ \fn bool QTableWidgetItem::isSelected() const
+ \since 4.2
+
+ Returns \c true if the item is selected, otherwise returns \c false.
+
+ \sa setSelected()
+*/
+bool QTableWidgetItem::isSelected() const
+{
+ if (!view || !view->selectionModel())
+ return false;
+ const QTableModel *model = qobject_cast<const QTableModel*>(view->model());
+ if (!model)
+ return false;
+ const QModelIndex index = model->index(this);
+ return view->selectionModel()->isSelected(index);
+}
+
+/*!
+ \fn void QTableWidgetItem::setSelected(bool select)
+ \since 4.2
+
+ Sets the selected state of the item to \a select.
+
+ \sa isSelected()
+*/
+void QTableWidgetItem::setSelected(bool select)
+{
+ if (!view || !view->selectionModel())
+ return;
+ const QTableModel *model = qobject_cast<const QTableModel*>(view->model());
+ if (!model)
+ return;
+ const QModelIndex index = model->index(this);
+ view->selectionModel()->select(index, select ? QItemSelectionModel::Select : QItemSelectionModel::Deselect);
+}
+
+/*!
\fn Qt::ItemFlags QTableWidgetItem::flags() const
Returns the flags used to describe the item. These determine whether
@@ -1110,7 +1148,7 @@ QTableWidgetSelectionRange::~QTableWidgetSelectionRange()
void QTableWidgetItem::setFlags(Qt::ItemFlags aflags)
{
itemFlags = aflags;
- if (QTableModel *model = (view ? qobject_cast<QTableModel*>(view->model()) : 0))
+ if (QTableModel *model = tableModel())
model->itemChanged(this);
}
@@ -1301,7 +1339,7 @@ void QTableWidgetItem::setFlags(Qt::ItemFlags aflags)
\sa type()
*/
QTableWidgetItem::QTableWidgetItem(int type)
- : rtti(type), view(0), d(new QTableWidgetItemPrivate(this)),
+ : rtti(type), view(nullptr), d(new QTableWidgetItemPrivate(this)),
itemFlags(Qt::ItemIsEditable
|Qt::ItemIsSelectable
|Qt::ItemIsUserCheckable
@@ -1317,7 +1355,7 @@ QTableWidgetItem::QTableWidgetItem(int type)
\sa type()
*/
QTableWidgetItem::QTableWidgetItem(const QString &text, int type)
- : rtti(type), view(0), d(new QTableWidgetItemPrivate(this)),
+ : rtti(type), view(nullptr), d(new QTableWidgetItemPrivate(this)),
itemFlags(Qt::ItemIsEditable
|Qt::ItemIsSelectable
|Qt::ItemIsUserCheckable
@@ -1334,7 +1372,7 @@ QTableWidgetItem::QTableWidgetItem(const QString &text, int type)
\sa type()
*/
QTableWidgetItem::QTableWidgetItem(const QIcon &icon, const QString &text, int type)
- : rtti(type), view(0), d(new QTableWidgetItemPrivate(this)),
+ : rtti(type), view(nullptr), d(new QTableWidgetItemPrivate(this)),
itemFlags(Qt::ItemIsEditable
|Qt::ItemIsSelectable
|Qt::ItemIsUserCheckable
@@ -1351,9 +1389,8 @@ QTableWidgetItem::QTableWidgetItem(const QIcon &icon, const QString &text, int t
*/
QTableWidgetItem::~QTableWidgetItem()
{
- if (QTableModel *model = (view ? qobject_cast<QTableModel*>(view->model()) : 0))
+ if (QTableModel *model = tableModel())
model->removeItem(this);
- view = 0;
delete d;
}
@@ -1389,7 +1426,7 @@ void QTableWidgetItem::setData(int role, const QVariant &value)
}
if (!found)
values.append(QWidgetItemData(role, value));
- if (QTableModel *model = (view ? qobject_cast<QTableModel*>(view->model()) : nullptr))
+ if (QTableModel *model = tableModel())
{
const QVector<int> roles((role == Qt::DisplayRole) ?
QVector<int>({Qt::DisplayRole, Qt::EditRole}) :
@@ -1444,6 +1481,16 @@ void QTableWidgetItem::write(QDataStream &out) const
}
/*!
+ \internal
+ returns the QTableModel if a view is set
+*/
+QTableModel *QTableWidgetItem::tableModel() const
+{
+ return (view ? qobject_cast<QTableModel*>(view->model()) : nullptr);
+}
+
+
+/*!
\relates QTableWidgetItem
Reads a table widget item from stream \a in into \a item.
@@ -1486,7 +1533,7 @@ QDataStream &operator<<(QDataStream &out, const QTableWidgetItem &item)
\sa data(), flags()
*/
QTableWidgetItem::QTableWidgetItem(const QTableWidgetItem &other)
- : rtti(Type), values(other.values), view(0),
+ : rtti(Type), values(other.values), view(nullptr),
d(new QTableWidgetItemPrivate(this)),
itemFlags(other.itemFlags)
{
@@ -2305,6 +2352,7 @@ void QTableWidget::setCellWidget(int row, int column, QWidget *widget)
QAbstractItemView::setIndexWidget(index, widget);
}
+#if QT_DEPRECATED_SINCE(5, 13)
/*!
Returns \c true if the \a item is selected, otherwise returns \c false.
@@ -2315,9 +2363,7 @@ void QTableWidget::setCellWidget(int row, int column, QWidget *widget)
bool QTableWidget::isItemSelected(const QTableWidgetItem *item) const
{
- Q_D(const QTableWidget);
- QModelIndex index = d->tableModel()->index(item);
- return selectionModel()->isSelected(index);
+ return ((item && item->tableWidget() == this) ? item->isSelected() : false);
}
/*!
@@ -2329,10 +2375,10 @@ bool QTableWidget::isItemSelected(const QTableWidgetItem *item) const
*/
void QTableWidget::setItemSelected(const QTableWidgetItem *item, bool select)
{
- Q_D(QTableWidget);
- QModelIndex index = d->tableModel()->index(item);
- selectionModel()->select(index, select ? QItemSelectionModel::Select : QItemSelectionModel::Deselect);
+ if (item && item->tableWidget() == this)
+ const_cast<QTableWidgetItem*>(item)->setSelected(select);
}
+#endif
/*!
Selects or deselects the \a range depending on \a select.
diff --git a/src/widgets/itemviews/qtablewidget.h b/src/widgets/itemviews/qtablewidget.h
index 9de27d164f..d93032f3f0 100644
--- a/src/widgets/itemviews/qtablewidget.h
+++ b/src/widgets/itemviews/qtablewidget.h
@@ -92,8 +92,8 @@ public:
inline int row() const;
inline int column() const;
- inline void setSelected(bool select);
- inline bool isSelected() const;
+ void setSelected(bool select);
+ bool isSelected() const;
inline Qt::ItemFlags flags() const { return itemFlags; }
void setFlags(Qt::ItemFlags flags);
@@ -131,20 +131,28 @@ public:
inline void setTextAlignment(int alignment)
{ setData(Qt::TextAlignmentRole, alignment); }
+#if QT_DEPRECATED_SINCE(5, 13)
+ QT_DEPRECATED_X ("Use QTableWidgetItem::background() instead")
inline QColor backgroundColor() const
- { return qvariant_cast<QColor>(data(Qt::BackgroundColorRole)); }
+ { return qvariant_cast<QColor>(data(Qt::BackgroundRole)); }
+ QT_DEPRECATED_X ("Use QTableWidgetItem::setBackground() instead")
inline void setBackgroundColor(const QColor &color)
- { setData(Qt::BackgroundColorRole, color); }
+ { setData(Qt::BackgroundRole, color); }
+#endif
inline QBrush background() const
{ return qvariant_cast<QBrush>(data(Qt::BackgroundRole)); }
inline void setBackground(const QBrush &brush)
{ setData(Qt::BackgroundRole, brush); }
+#if QT_DEPRECATED_SINCE(5, 13)
+ QT_DEPRECATED_X ("Use QTableWidgetItem::foreground() instead")
inline QColor textColor() const
- { return qvariant_cast<QColor>(data(Qt::TextColorRole)); }
+ { return qvariant_cast<QColor>(data(Qt::ForegroundRole)); }
+ QT_DEPRECATED_X ("Use QTableWidgetItem::setForeground() instead")
inline void setTextColor(const QColor &color)
- { setData(Qt::TextColorRole, color); }
+ { setData(Qt::ForegroundRole, color); }
+#endif
inline QBrush foreground() const
{ return qvariant_cast<QBrush>(data(Qt::ForegroundRole)); }
@@ -175,6 +183,9 @@ public:
inline int type() const { return rtti; }
private:
+ QTableModel *tableModel() const;
+
+private:
int rtti;
QVector<QWidgetItemData> values;
QTableWidget *view;
@@ -268,8 +279,12 @@ public:
void setCellWidget(int row, int column, QWidget *widget);
inline void removeCellWidget(int row, int column);
+#if QT_DEPRECATED_SINCE(5, 13)
+ QT_DEPRECATED_X ("Use QTableWidgetItem::isSelected() instead")
bool isItemSelected(const QTableWidgetItem *item) const;
+ QT_DEPRECATED_X ("Use QTableWidgetItem::setSelected() instead")
void setItemSelected(const QTableWidgetItem *item, bool select);
+#endif
void setRangeSelected(const QTableWidgetSelectionRange &range, bool select);
QList<QTableWidgetSelectionRange> selectedRanges() const;
@@ -375,12 +390,6 @@ inline int QTableWidgetItem::row() const
inline int QTableWidgetItem::column() const
{ return (view ? view->column(this) : -1); }
-inline void QTableWidgetItem::setSelected(bool aselect)
-{ if (view) view->setItemSelected(this, aselect); }
-
-inline bool QTableWidgetItem::isSelected() const
-{ return (view ? view->isItemSelected(this) : false); }
-
QT_END_NAMESPACE
#endif // QTABLEWIDGET_H
diff --git a/src/widgets/itemviews/qtablewidget_p.h b/src/widgets/itemviews/qtablewidget_p.h
index 9899272fce..d88326f129 100644
--- a/src/widgets/itemviews/qtablewidget_p.h
+++ b/src/widgets/itemviews/qtablewidget_p.h
@@ -129,6 +129,9 @@ public:
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
bool setData(const QModelIndex &index, const QVariant &value, int role) override;
bool setItemData(const QModelIndex &index, const QMap<int, QVariant> &roles) override;
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
+ bool clearItemData(const QModelIndex &index) override;
+#endif
QMap<int, QVariant> itemData(const QModelIndex &index) const override;
diff --git a/src/widgets/itemviews/qtreeview.cpp b/src/widgets/itemviews/qtreeview.cpp
index f3647f656a..3fad6ca3df 100644
--- a/src/widgets/itemviews/qtreeview.cpp
+++ b/src/widgets/itemviews/qtreeview.cpp
@@ -1089,15 +1089,8 @@ void QTreeView::keyboardSearch(const QString &search)
if (start.column() > 0)
index = index.sibling(index.row(), start.column());
- if (index.isValid()) {
- QItemSelectionModel::SelectionFlags flags = (d->selectionMode == SingleSelection
- ? QItemSelectionModel::SelectionFlags(
- QItemSelectionModel::ClearAndSelect
- |d->selectionBehaviorFlags())
- : QItemSelectionModel::SelectionFlags(
- QItemSelectionModel::NoUpdate));
- selectionModel()->setCurrentIndex(index, flags);
- }
+ if (index.isValid())
+ setCurrentIndex(index);
}
/*!
@@ -1773,7 +1766,7 @@ void QTreeView::drawRow(QPainter *painter, const QStyleOptionViewItem &option,
QPalette::ColorGroup cg = (option.state & QStyle::State_Enabled)
? QPalette::Normal : QPalette::Disabled;
o.backgroundColor = option.palette.color(cg, d->selectionModel->isSelected(index)
- ? QPalette::Highlight : QPalette::Background);
+ ? QPalette::Highlight : QPalette::Window);
int x = 0;
if (!option.showDecorationSelected)
x = header->sectionPosition(0) + d->indentationForItem(d->current);
@@ -1992,21 +1985,7 @@ void QTreeView::keyPressEvent(QKeyEvent *event)
if (d->isIndexValid(current) && d->model && d->itemsExpandable) {
switch (event->key()) {
case Qt::Key_Asterisk: {
- // do layouting only once after expanding is done
- d->doDelayedItemsLayout();
- QStack<QModelIndex> parents;
- parents.push(current);
- while (!parents.isEmpty()) {
- QModelIndex parent = parents.pop();
- for (int row = 0; row < d->model->rowCount(parent); ++row) {
- QModelIndex child = d->model->index(row, 0, parent);
- if (!d->isIndexValid(child))
- break;
- parents.push(child);
- expand(child);
- }
- }
- expand(current);
+ expandRecursively(current);
break; }
case Qt::Key_Plus:
expand(current);
@@ -2160,12 +2139,10 @@ int QTreeView::verticalOffset() const
// ### find a faster way to do this
d->executePostedLayout();
int offset = 0;
- for (int i = 0; i < d->viewItems.count(); ++i) {
- if (i == verticalScrollBar()->value())
- return offset;
+ const int cnt = std::min(d->viewItems.count(), verticalScrollBar()->value());
+ for (int i = 0; i < cnt; ++i)
offset += d->itemHeight(i);
- }
- return 0;
+ return offset;
}
// scroll per pixel
return verticalScrollBar()->value();
@@ -2324,9 +2301,9 @@ QModelIndex QTreeView::moveCursor(CursorAction cursorAction, Qt::KeyboardModifie
case MovePageDown:
return d->modelIndex(d->pageDown(vi), current.column());
case MoveHome:
- return d->model->index(0, current.column(), d->root);
+ return d->modelIndex(d->itemForKeyHome(), current.column());
case MoveEnd:
- return d->modelIndex(d->viewItems.count() - 1, current.column());
+ return d->modelIndex(d->itemForKeyEnd(), current.column());
}
return current;
}
@@ -2621,10 +2598,13 @@ void QTreeView::resizeColumnToContents(int column)
d->header->resizeSection(column, qMax(contents, header));
}
+#if QT_DEPRECATED_SINCE(5, 13)
/*!
\obsolete
\overload
+ This function is deprecated. Use
+ sortByColumn(int column, Qt::SortOrder order) instead.
Sorts the model by the values in the given \a column.
*/
void QTreeView::sortByColumn(int column)
@@ -2632,6 +2612,7 @@ void QTreeView::sortByColumn(int column)
Q_D(QTreeView);
sortByColumn(column, d->header->sortIndicatorOrder());
}
+#endif
/*!
\since 4.2
@@ -2647,10 +2628,12 @@ void QTreeView::sortByColumn(int column)
void QTreeView::sortByColumn(int column, Qt::SortOrder order)
{
Q_D(QTreeView);
-
- //If sorting is enabled will emit a signal connected to _q_sortIndicatorChanged, which then actually sorts
+ if (column < 0)
+ return;
+ // If sorting is enabled it will emit a signal connected to
+ // _q_sortIndicatorChanged, which then actually sorts
d->header->setSortIndicator(column, order);
- //If sorting is not enabled, force to sort now.
+ // If sorting is not enabled, force to sort now
if (!d->sortingEnabled)
d->model->sort(column, order);
}
@@ -2694,11 +2677,7 @@ QSize QTreeView::viewportSizeHint() const
QSize result = QSize(d->header->length(), deepestRect.bottom() + 1);
// add size for header
- result += QSize(0, d->header->isVisible() ? d->header->height() : 0);
-
- // add size for scrollbars
- result += QSize(verticalScrollBar()->isVisible() ? verticalScrollBar()->width() : 0,
- horizontalScrollBar()->isVisible() ? horizontalScrollBar()->height() : 0);
+ result += QSize(0, d->header->isHidden() ? 0 : d->header->height());
return result;
}
@@ -2707,7 +2686,7 @@ QSize QTreeView::viewportSizeHint() const
\since 4.2
Expands all expandable items.
- Warning: if the model contains a large number of items,
+ \warning: if the model contains a large number of items,
this function will take some time to execute.
\sa collapseAll(), expand(), collapse(), setExpanded()
@@ -2723,6 +2702,50 @@ void QTreeView::expandAll()
}
/*!
+ \since 5.13
+ Expands the item at the given \a index and all its children to the
+ given \a depth. The \a depth is relative to the given \a index.
+ A \a depth of -1 will expand all children, a \a depth of 0 will
+ only expand the given \a index.
+
+ \warning: if the model contains a large number of items,
+ this function will take some time to execute.
+
+ \sa expandAll()
+*/
+void QTreeView::expandRecursively(const QModelIndex &index, int depth)
+{
+ Q_D(QTreeView);
+
+ if (depth < -1)
+ return;
+ // do layouting only once after expanding is done
+ d->doDelayedItemsLayout();
+ expand(index);
+ if (depth == 0)
+ return;
+ QStack<QPair<QModelIndex, int>> parents;
+ parents.push({index, 0});
+ while (!parents.isEmpty()) {
+ const QPair<QModelIndex, int> elem = parents.pop();
+ const QModelIndex &parent = elem.first;
+ const int curDepth = elem.second;
+ const int rowCount = d->model->rowCount(parent);
+ for (int row = 0; row < rowCount; ++row) {
+ const QModelIndex child = d->model->index(row, 0, parent);
+ if (!d->isIndexValid(child))
+ break;
+ if (depth == -1 || curDepth + 1 < depth)
+ parents.push({child, curDepth + 1});
+ if (d->isIndexExpanded(child))
+ continue;
+ if (d->storeExpanded(child))
+ emit expanded(child);
+ }
+ }
+}
+
+/*!
\since 4.2
Collapses all expanded items.
@@ -3399,7 +3422,11 @@ int QTreeViewPrivate::pageUp(int i) const
int index = itemAtCoordinate(coordinateForItem(i) - viewport->height());
while (isItemHiddenOrDisabled(index))
index--;
- return index == -1 ? 0 : index;
+ if (index == -1)
+ index = 0;
+ while (isItemHiddenOrDisabled(index))
+ index++;
+ return index >= viewItems.count() ? 0 : index;
}
int QTreeViewPrivate::pageDown(int i) const
@@ -3407,6 +3434,26 @@ int QTreeViewPrivate::pageDown(int i) const
int index = itemAtCoordinate(coordinateForItem(i) + viewport->height());
while (isItemHiddenOrDisabled(index))
index++;
+ if (index == -1 || index >= viewItems.count())
+ index = viewItems.count() - 1;
+ while (isItemHiddenOrDisabled(index))
+ index--;
+ return index == -1 ? viewItems.count() - 1 : index;
+}
+
+int QTreeViewPrivate::itemForKeyHome() const
+{
+ int index = 0;
+ while (isItemHiddenOrDisabled(index))
+ index++;
+ return index >= viewItems.count() ? 0 : index;
+}
+
+int QTreeViewPrivate::itemForKeyEnd() const
+{
+ int index = viewItems.count() - 1;
+ while (isItemHiddenOrDisabled(index))
+ index--;
return index == -1 ? viewItems.count() - 1 : index;
}
diff --git a/src/widgets/itemviews/qtreeview.h b/src/widgets/itemviews/qtreeview.h
index 33dbf1c1ce..e9cc1beedb 100644
--- a/src/widgets/itemviews/qtreeview.h
+++ b/src/widgets/itemviews/qtreeview.h
@@ -143,7 +143,6 @@ public:
void doItemsLayout() override;
void reset() override;
- void sortByColumn(int column, Qt::SortOrder order);
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles = QVector<int>()) override;
void selectAll() override;
@@ -158,8 +157,13 @@ public Q_SLOTS:
void expand(const QModelIndex &index);
void collapse(const QModelIndex &index);
void resizeColumnToContents(int column);
+#if QT_DEPRECATED_SINCE(5, 13)
+ QT_DEPRECATED_X ("Use QTreeeView::sortByColumn(int column, Qt::SortOrder order) instead")
void sortByColumn(int column);
+#endif
+ void sortByColumn(int column, Qt::SortOrder order);
void expandAll();
+ void expandRecursively(const QModelIndex &index, int depth = -1);
void collapseAll();
void expandToDepth(int depth);
diff --git a/src/widgets/itemviews/qtreeview_p.h b/src/widgets/itemviews/qtreeview_p.h
index 0a0e7aae87..9666a9f8c2 100644
--- a/src/widgets/itemviews/qtreeview_p.h
+++ b/src/widgets/itemviews/qtreeview_p.h
@@ -140,6 +140,8 @@ public:
int pageUp(int item) const;
int pageDown(int item) const;
+ int itemForKeyHome() const;
+ int itemForKeyEnd() const;
int itemHeight(int item) const;
int indentationForItem(int item) const;
diff --git a/src/widgets/itemviews/qtreewidget.cpp b/src/widgets/itemviews/qtreewidget.cpp
index 9fbfb50029..29cc199526 100644
--- a/src/widgets/itemviews/qtreewidget.cpp
+++ b/src/widgets/itemviews/qtreewidget.cpp
@@ -390,6 +390,27 @@ bool QTreeModel::setData(const QModelIndex &index, const QVariant &value, int ro
return false;
}
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
+bool QTreeModel::clearItemData(const QModelIndex &index)
+{
+ if (!checkIndex(index, CheckIndexOption::IndexIsValid))
+ return false;
+ QTreeWidgetItem *itm = item(index);
+ if (!itm)
+ return false;
+ const auto beginIter = itm->values.at(index.column()).cbegin();
+ const auto endIter = itm->values.at(index.column()).cend();
+ if (std::all_of(beginIter, endIter, [](const QWidgetItemData& data) -> bool { return !data.value.isValid(); })
+ && !itm->d->display.at(index.column()).isValid()) {
+ return true; //it's already cleared
+ }
+ itm->d->display[index.column()] = QVariant();
+ itm->values[index.column()].clear();
+ emit dataChanged(index, index, QVector<int>{});
+ return true;
+}
+#endif
+
QMap<int, QVariant> QTreeModel::itemData(const QModelIndex &index) const
{
QMap<int, QVariant> roles;
@@ -635,7 +656,7 @@ void QTreeModel::ensureSorted(int column, Qt::SortOrder order,
// we are going to change the persistent indexes, so we need to prepare
if (!changed) { // this will only happen once
changed = true;
- emit layoutAboutToBeChanged(); // the selection model needs to know
+ emit layoutAboutToBeChanged({parent}, QAbstractItemModel::VerticalSortHint); // the selection model needs to know
oldPersistentIndexes = persistentIndexList();
newPersistentIndexes = oldPersistentIndexes;
}
@@ -668,7 +689,7 @@ void QTreeModel::ensureSorted(int column, Qt::SortOrder order,
if (changed) {
itm->children = lst;
changePersistentIndexList(oldPersistentIndexes, newPersistentIndexes);
- emit layoutChanged();
+ emit layoutChanged({parent}, QAbstractItemModel::VerticalSortHint);
}
}
@@ -988,8 +1009,18 @@ void QTreeModel::timerEvent(QTimerEvent *ev)
Sets the selected state of the item to \a select.
\sa isSelected()
-
*/
+void QTreeWidgetItem::setSelected(bool select)
+{
+ const QTreeModel *model = treeModel();
+ if (!model || !view->selectionModel())
+ return;
+ const QModelIndex index = model->index(this, 0);
+ view->selectionModel()->select(index, (select ? QItemSelectionModel::Select
+ : QItemSelectionModel::Deselect)
+ | QItemSelectionModel::Rows);
+ d->selected = select;
+}
/*!
\fn bool QTreeWidgetItem::isSelected() const
@@ -999,6 +1030,10 @@ void QTreeModel::timerEvent(QTimerEvent *ev)
\sa setSelected()
*/
+bool QTreeWidgetItem::isSelected() const
+{
+ return d->selected;
+}
/*!
\fn void QTreeWidgetItem::setHidden(bool hide)
@@ -1012,12 +1047,18 @@ void QTreeModel::timerEvent(QTimerEvent *ev)
\sa isHidden()
*/
-void QTreeWidgetItem::setHidden(bool ahide)
+void QTreeWidgetItem::setHidden(bool hide)
{
- if (view) {
- view->setItemHidden(this, ahide);
- d->hidden = ahide;
+ const QTreeModel *model = treeModel();
+ if (!model)
+ return;
+ if (this == model->headerItem) {
+ view->header()->setHidden(hide);
+ } else {
+ const QModelIndex index = view->d_func()->index(this);
+ view->setRowHidden(index.row(), index.parent(), hide);
}
+ d->hidden = hide;
}
/*!
@@ -1031,7 +1072,15 @@ void QTreeWidgetItem::setHidden(bool ahide)
bool QTreeWidgetItem::isHidden() const
{
- return (view ? d->hidden : false);
+ const QTreeModel *model = treeModel();
+ if (!model)
+ return false;
+ if (this == model->headerItem)
+ return view->header()->isHidden();
+ if (view->d_func()->hiddenIndexes.isEmpty())
+ return false;
+ QTreeModel::SkipSorting skipSorting(model);
+ return view->d_func()->isRowHidden(view->d_func()->index(this));
}
/*!
@@ -1043,6 +1092,14 @@ bool QTreeWidgetItem::isHidden() const
\sa isExpanded()
*/
+void QTreeWidgetItem::setExpanded(bool expand)
+{
+ const QTreeModel *model = treeModel();
+ if (!model)
+ return;
+ QTreeModel::SkipSorting skipSorting(model);
+ view->setExpanded(view->d_func()->index(this), expand);
+}
/*!
\fn bool QTreeWidgetItem::isExpanded() const
@@ -1052,6 +1109,14 @@ bool QTreeWidgetItem::isHidden() const
\sa setExpanded()
*/
+bool QTreeWidgetItem::isExpanded() const
+{
+ const QTreeModel *model = treeModel();
+ if (!model)
+ return false;
+ QTreeModel::SkipSorting skipSorting(model);
+ return view->isExpanded(view->d_func()->index(this));
+}
/*!
\fn void QTreeWidgetItem::setFirstColumnSpanned(bool span)
@@ -1062,6 +1127,14 @@ bool QTreeWidgetItem::isHidden() const
\sa isFirstColumnSpanned()
*/
+void QTreeWidgetItem::setFirstColumnSpanned(bool span)
+{
+ const QTreeModel *model = treeModel();
+ if (!model || this == model->headerItem)
+ return; // We can't set the header items to spanning
+ const QModelIndex index = model->index(this, 0);
+ view->setFirstColumnSpanned(index.row(), index.parent(), span);
+}
/*!
\fn bool QTreeWidgetItem::isFirstColumnSpanned() const
@@ -1071,6 +1144,14 @@ bool QTreeWidgetItem::isHidden() const
\sa setFirstColumnSpanned()
*/
+bool QTreeWidgetItem::isFirstColumnSpanned() const
+{
+ const QTreeModel *model = treeModel();
+ if (!model || this == model->headerItem)
+ return false;
+ const QModelIndex index = model->index(this, 0);
+ return view->isFirstColumnSpanned(index.row(), index.parent());
+}
/*!
\fn QString QTreeWidgetItem::text(int column) const
@@ -1325,7 +1406,7 @@ bool QTreeWidgetItem::isHidden() const
\sa type()
*/
QTreeWidgetItem::QTreeWidgetItem(int type)
- : rtti(type), view(0), d(new QTreeWidgetItemPrivate(this)), par(0),
+ : rtti(type), view(nullptr), d(new QTreeWidgetItemPrivate(this)), par(nullptr),
itemFlags(Qt::ItemIsSelectable
|Qt::ItemIsUserCheckable
|Qt::ItemIsEnabled
@@ -1344,7 +1425,7 @@ QTreeWidgetItem::QTreeWidgetItem(int type)
\sa type()
*/
QTreeWidgetItem::QTreeWidgetItem(const QStringList &strings, int type)
- : rtti(type), view(0), d(new QTreeWidgetItemPrivate(this)), par(0),
+ : rtti(type), view(nullptr), d(new QTreeWidgetItemPrivate(this)), par(nullptr),
itemFlags(Qt::ItemIsSelectable
|Qt::ItemIsUserCheckable
|Qt::ItemIsEnabled
@@ -1364,16 +1445,16 @@ QTreeWidgetItem::QTreeWidgetItem(const QStringList &strings, int type)
\sa type()
*/
-QTreeWidgetItem::QTreeWidgetItem(QTreeWidget *view, int type)
- : rtti(type), view(0), d(new QTreeWidgetItemPrivate(this)), par(0),
+QTreeWidgetItem::QTreeWidgetItem(QTreeWidget *treeview, int type)
+ : rtti(type), view(nullptr), d(new QTreeWidgetItemPrivate(this)), par(nullptr),
itemFlags(Qt::ItemIsSelectable
|Qt::ItemIsUserCheckable
|Qt::ItemIsEnabled
|Qt::ItemIsDragEnabled
|Qt::ItemIsDropEnabled)
{
- if (view && view->model()) {
- QTreeModel *model = qobject_cast<QTreeModel*>(view->model());
+ // do not set this->view here otherwise insertChild() will fail
+ if (QTreeModel *model = treeModel(treeview)) {
model->rootItem->addChild(this);
values.reserve(model->headerItem->columnCount());
}
@@ -1389,8 +1470,8 @@ QTreeWidgetItem::QTreeWidgetItem(QTreeWidget *view, int type)
\sa type()
*/
-QTreeWidgetItem::QTreeWidgetItem(QTreeWidget *view, const QStringList &strings, int type)
- : rtti(type), view(0), d(new QTreeWidgetItemPrivate(this)), par(0),
+QTreeWidgetItem::QTreeWidgetItem(QTreeWidget *treeview, const QStringList &strings, int type)
+ : rtti(type), view(nullptr), d(new QTreeWidgetItemPrivate(this)), par(nullptr),
itemFlags(Qt::ItemIsSelectable
|Qt::ItemIsUserCheckable
|Qt::ItemIsEnabled
@@ -1399,8 +1480,8 @@ QTreeWidgetItem::QTreeWidgetItem(QTreeWidget *view, const QStringList &strings,
{
for (int i = 0; i < strings.count(); ++i)
setText(i, strings.at(i));
- if (view && view->model()) {
- QTreeModel *model = qobject_cast<QTreeModel*>(view->model());
+ // do not set this->view here otherwise insertChild() will fail
+ if (QTreeModel *model = treeModel(treeview)) {
model->rootItem->addChild(this);
values.reserve(model->headerItem->columnCount());
}
@@ -1414,21 +1495,19 @@ QTreeWidgetItem::QTreeWidgetItem(QTreeWidget *view, const QStringList &strings,
\sa type()
*/
-QTreeWidgetItem::QTreeWidgetItem(QTreeWidget *view, QTreeWidgetItem *after, int type)
- : rtti(type), view(0), d(new QTreeWidgetItemPrivate(this)), par(0),
+QTreeWidgetItem::QTreeWidgetItem(QTreeWidget *treeview, QTreeWidgetItem *after, int type)
+ : rtti(type), view(nullptr), d(new QTreeWidgetItemPrivate(this)), par(nullptr),
itemFlags(Qt::ItemIsSelectable
|Qt::ItemIsUserCheckable
|Qt::ItemIsEnabled
|Qt::ItemIsDragEnabled
|Qt::ItemIsDropEnabled)
{
- if (view) {
- QTreeModel *model = qobject_cast<QTreeModel*>(view->model());
- if (model) {
- int i = model->rootItem->children.indexOf(after) + 1;
- model->rootItem->insertChild(i, this);
- values.reserve(model->headerItem->columnCount());
- }
+ // do not set this->view here otherwise insertChild() will fail
+ if (QTreeModel *model = treeModel(treeview)) {
+ int i = model->rootItem->children.indexOf(after) + 1;
+ model->rootItem->insertChild(i, this);
+ values.reserve(model->headerItem->columnCount());
}
}
@@ -1438,7 +1517,7 @@ QTreeWidgetItem::QTreeWidgetItem(QTreeWidget *view, QTreeWidgetItem *after, int
\sa type()
*/
QTreeWidgetItem::QTreeWidgetItem(QTreeWidgetItem *parent, int type)
- : rtti(type), view(0), d(new QTreeWidgetItemPrivate(this)), par(0),
+ : rtti(type), view(nullptr), d(new QTreeWidgetItemPrivate(this)), par(nullptr),
itemFlags(Qt::ItemIsSelectable
|Qt::ItemIsUserCheckable
|Qt::ItemIsEnabled
@@ -1456,7 +1535,7 @@ QTreeWidgetItem::QTreeWidgetItem(QTreeWidgetItem *parent, int type)
\sa type()
*/
QTreeWidgetItem::QTreeWidgetItem(QTreeWidgetItem *parent, const QStringList &strings, int type)
- : rtti(type), view(0), d(new QTreeWidgetItemPrivate(this)), par(0),
+ : rtti(type), view(nullptr), d(new QTreeWidgetItemPrivate(this)), par(nullptr),
itemFlags(Qt::ItemIsSelectable
|Qt::ItemIsUserCheckable
|Qt::ItemIsEnabled
@@ -1478,7 +1557,7 @@ QTreeWidgetItem::QTreeWidgetItem(QTreeWidgetItem *parent, const QStringList &str
\sa type()
*/
QTreeWidgetItem::QTreeWidgetItem(QTreeWidgetItem *parent, QTreeWidgetItem *after, int type)
- : rtti(type), view(0), d(new QTreeWidgetItemPrivate(this)), par(0),
+ : rtti(type), view(nullptr), d(new QTreeWidgetItemPrivate(this)), par(nullptr),
itemFlags(Qt::ItemIsSelectable
|Qt::ItemIsUserCheckable
|Qt::ItemIsEnabled
@@ -1501,7 +1580,7 @@ QTreeWidgetItem::QTreeWidgetItem(QTreeWidgetItem *parent, QTreeWidgetItem *after
QTreeWidgetItem::~QTreeWidgetItem()
{
- QTreeModel *model = (view ? qobject_cast<QTreeModel*>(view->model()) : 0);
+ QTreeModel *model = treeModel();
bool wasSkipSort = false;
if (model) {
wasSkipSort = model->skipPendingSort;
@@ -1663,16 +1742,17 @@ void QTreeWidgetItem::setFlags(Qt::ItemFlags flags)
void QTreeWidgetItemPrivate::updateHiddenStatus(QTreeWidgetItem *item, bool inserting)
{
- QTreeModel *model = (item->view ? qobject_cast<QTreeModel*>(item->view->model()) : 0);
+ QTreeModel *model = item->treeModel();
if (!model)
return;
QStack<QTreeWidgetItem *> parents;
parents.push(item);
while (!parents.isEmpty()) {
QTreeWidgetItem *parent = parents.pop();
- QModelIndex index = model->index(parent, 0);
- if (parent->d->hidden)
+ if (parent->d->hidden) {
+ const QModelIndex index = model->index(parent, 0);
item->view->setRowHidden(index.row(), index.parent(), inserting);
+ }
for (int i = 0; i < parent->children.count(); ++i) {
QTreeWidgetItem *child = parent->children.at(i);
parents.push(child);
@@ -1737,7 +1817,7 @@ void QTreeWidgetItem::setData(int column, int role, const QVariant &value)
if (column < 0)
return;
- QTreeModel *model = (view ? qobject_cast<QTreeModel*>(view->model()) : 0);
+ QTreeModel *model = treeModel();
switch (role) {
case Qt::EditRole:
case Qt::DisplayRole: {
@@ -1945,7 +2025,7 @@ void QTreeWidgetItem::insertChild(int index, QTreeWidgetItem *child)
if (index < 0 || index > children.count() || child == 0 || child->view != 0 || child->par != 0)
return;
- if (QTreeModel *model = (view ? qobject_cast<QTreeModel*>(view->model()) : 0)) {
+ if (QTreeModel *model = treeModel()) {
const bool wasSkipSort = model->skipPendingSort;
model->skipPendingSort = true;
if (model->rootItem == this)
@@ -1996,7 +2076,7 @@ QTreeWidgetItem *QTreeWidgetItem::takeChild(int index)
{
// we move this outside the check of the index to allow executing
// pending sorts from inline functions, using this function (hack)
- QTreeModel *model = (view ? qobject_cast<QTreeModel*>(view->model()) : 0);
+ QTreeModel *model = treeModel();
if (model) {
// This will trigger a layoutChanged signal, thus we might want to optimize
// this function by not emitting the rowsRemoved signal etc to the view.
@@ -2054,7 +2134,7 @@ void QTreeWidgetItem::insertChildren(int index, const QList<QTreeWidgetItem*> &c
insertChild(index, children.at(n));
return;
}
- QTreeModel *model = (view ? qobject_cast<QTreeModel*>(view->model()) : 0);
+ QTreeModel *model = treeModel();
QStack<QTreeWidgetItem*> stack;
QList<QTreeWidgetItem*> itemsToInsert;
for (int n = 0; n < children.count(); ++n) {
@@ -2101,7 +2181,7 @@ QList<QTreeWidgetItem*> QTreeWidgetItem::takeChildren()
{
QList<QTreeWidgetItem*> removed;
if (children.count() > 0) {
- QTreeModel *model = (view ? qobject_cast<QTreeModel*>(view->model()) : 0);
+ QTreeModel *model = treeModel();
if (model) {
// This will trigger a layoutChanged signal, thus we might want to optimize
// this function by not emitting the rowsRemoved signal etc to the view.
@@ -2133,7 +2213,7 @@ QList<QTreeWidgetItem*> QTreeWidgetItem::takeChildren()
void QTreeWidgetItemPrivate::sortChildren(int column, Qt::SortOrder order, bool climb)
{
- QTreeModel *model = (q->view ? qobject_cast<QTreeModel*>(q->view->model()) : 0);
+ QTreeModel *model = q->treeModel();
if (!model)
return;
model->sortItems(&q->children, column, order);
@@ -2156,7 +2236,7 @@ void QTreeWidgetItemPrivate::sortChildren(int column, Qt::SortOrder order, bool
*/
void QTreeWidgetItem::sortChildren(int column, Qt::SortOrder order, bool climb)
{
- QTreeModel *model = (view ? qobject_cast<QTreeModel*>(view->model()) : 0);
+ QTreeModel *model = treeModel();
if (!model)
return;
if (model->isChanging())
@@ -2164,9 +2244,9 @@ void QTreeWidgetItem::sortChildren(int column, Qt::SortOrder order, bool climb)
QTreeModel::SkipSorting skipSorting(model);
int oldSortColumn = view->d_func()->explicitSortColumn;
view->d_func()->explicitSortColumn = column;
- emit model->layoutAboutToBeChanged();
+ emit model->layoutAboutToBeChanged({}, QAbstractItemModel::VerticalSortHint);
d->sortChildren(column, order, climb);
- emit model->layoutChanged();
+ emit model->layoutChanged({}, QAbstractItemModel::VerticalSortHint);
view->d_func()->explicitSortColumn = oldSortColumn;
}
@@ -2236,7 +2316,7 @@ void QTreeWidgetItem::emitDataChanged()
*/
void QTreeWidgetItem::itemChanged()
{
- if (QTreeModel *model = (view ? qobject_cast<QTreeModel*>(view->model()) : 0))
+ if (QTreeModel *model = treeModel())
model->itemChanged(this);
}
@@ -2245,10 +2325,21 @@ void QTreeWidgetItem::itemChanged()
*/
void QTreeWidgetItem::executePendingSort() const
{
- if (QTreeModel *model = (view ? qobject_cast<QTreeModel*>(view->model()) : 0))
+ if (QTreeModel *model = treeModel())
model->executePendingSort();
}
+/*!
+ \internal
+ returns the QTreeModel if a view is set
+*/
+QTreeModel *QTreeWidgetItem::treeModel(QTreeWidget *v) const
+{
+ if (!v)
+ v = view;
+ return (v ? qobject_cast<QTreeModel*>(v->model()) : nullptr);
+}
+
#ifndef QT_NO_DATASTREAM
/*!
@@ -2448,8 +2539,8 @@ void QTreeWidgetPrivate::_q_dataChanged(const QModelIndex &topLeft,
QStyle::SH_ItemView_ActivateItemOnSingleClick style hint) or
pressing a special key (e.g., \uicontrol Enter).
- The specified \a item is the item that was clicked, or 0 if no
- item was clicked. The \a column is the item's column that was
+ The specified \a item is the item that was clicked, or \nullptr if
+ no item was clicked. The \a column is the item's column that was
clicked, or -1 if no item was clicked.
*/
@@ -2459,8 +2550,8 @@ void QTreeWidgetPrivate::_q_dataChanged(const QModelIndex &topLeft,
This signal is emitted when the user presses a mouse button inside
the widget.
- The specified \a item is the item that was clicked, or 0 if no
- item was clicked. The \a column is the item's column that was
+ The specified \a item is the item that was clicked, or \nullptr if
+ no item was clicked. The \a column is the item's column that was
clicked, or -1 if no item was clicked.
*/
@@ -2480,8 +2571,8 @@ void QTreeWidgetPrivate::_q_dataChanged(const QModelIndex &topLeft,
This signal is emitted when the user double clicks inside the
widget.
- The specified \a item is the item that was clicked, or 0 if no
- item was clicked. The \a column is the item's column that was
+ The specified \a item is the item that was clicked, or \nullptr if
+ no item was clicked. The \a column is the item's column that was
clicked. If no item was double clicked, no signal will be emitted.
*/
@@ -2633,8 +2724,8 @@ QTreeWidgetItem *QTreeWidget::invisibleRootItem() const
}
/*!
- Returns the top level item at the given \a index, or 0 if the item does
- not exist.
+ Returns the top level item at the given \a index, or \nullptr if the
+ item does not exist.
\sa topLevelItemCount(), insertTopLevelItem()
*/
@@ -3010,7 +3101,7 @@ QWidget *QTreeWidget::itemWidget(QTreeWidgetItem *item, int column) const
This function should only be used to display static content in the place of
a tree widget item. If you want to display custom dynamic content or
- implement a custom editor widget, use QTreeView and subclass QItemDelegate
+ implement a custom editor widget, use QTreeView and subclass QStyledItemDelegate
instead.
This function cannot be called before the item hierarchy has been set up,
@@ -3027,6 +3118,7 @@ void QTreeWidget::setItemWidget(QTreeWidgetItem *item, int column, QWidget *widg
QAbstractItemView::setIndexWidget(d->index(item, column), widget);
}
+#if QT_DEPRECATED_SINCE(5, 13)
/*!
Returns \c true if the \a item is selected; otherwise returns \c false.
@@ -3038,9 +3130,7 @@ void QTreeWidget::setItemWidget(QTreeWidgetItem *item, int column, QWidget *widg
*/
bool QTreeWidget::isItemSelected(const QTreeWidgetItem *item) const
{
- if (!item)
- return false;
- return item->d->selected;
+ return ((item && item->treeWidget() == this) ? item->isSelected() : false);
}
/*!
@@ -3055,16 +3145,10 @@ bool QTreeWidget::isItemSelected(const QTreeWidgetItem *item) const
*/
void QTreeWidget::setItemSelected(const QTreeWidgetItem *item, bool select)
{
- Q_D(QTreeWidget);
-
- if (!item)
- return;
-
- selectionModel()->select(d->index(item), (select ? QItemSelectionModel::Select
- : QItemSelectionModel::Deselect)
- |QItemSelectionModel::Rows);
- item->d->selected = select;
+ if (item && item->treeWidget() == this)
+ const_cast<QTreeWidgetItem*>(item)->setSelected(select);
}
+#endif
/*!
Returns a list of all selected non-hidden items.
@@ -3081,7 +3165,7 @@ QList<QTreeWidgetItem*> QTreeWidget::selectedItems() const
seen.reserve(indexes.count());
for (const auto &index : indexes) {
QTreeWidgetItem *item = d->item(index);
- if (isItemHidden(item) || seen.contains(item))
+ if (item->isHidden() || seen.contains(item))
continue;
seen.insert(item);
items.append(item);
@@ -3105,6 +3189,7 @@ QList<QTreeWidgetItem*> QTreeWidget::findItems(const QString &text, Qt::MatchFla
return items;
}
+#if QT_DEPRECATED_SINCE(5, 13)
/*!
Returns \c true if the \a item is explicitly hidden, otherwise returns \c false.
@@ -3114,13 +3199,7 @@ QList<QTreeWidgetItem*> QTreeWidget::findItems(const QString &text, Qt::MatchFla
*/
bool QTreeWidget::isItemHidden(const QTreeWidgetItem *item) const
{
- Q_D(const QTreeWidget);
- if (item == d->treeModel()->headerItem)
- return header()->isHidden();
- if (d->hiddenIndexes.isEmpty())
- return false;
- QTreeModel::SkipSorting skipSorting(d->treeModel());
- return d->isRowHidden(d->index(item));
+ return ((item && item->treeWidget() == this) ? item->isHidden() : false);
}
/*!
@@ -3134,16 +3213,8 @@ bool QTreeWidget::isItemHidden(const QTreeWidgetItem *item) const
*/
void QTreeWidget::setItemHidden(const QTreeWidgetItem *item, bool hide)
{
- if (!item)
- return;
- Q_D(QTreeWidget);
- if (item == d->treeModel()->headerItem) {
- header()->setHidden(hide);
- } else {
- const QModelIndex index = d->index(item);
- setRowHidden(index.row(), index.parent(), hide);
- }
- item->d->hidden = hide;
+ if (item && item->treeWidget() == this)
+ const_cast<QTreeWidgetItem*>(item)->setHidden(hide);
}
/*!
@@ -3157,9 +3228,7 @@ void QTreeWidget::setItemHidden(const QTreeWidgetItem *item, bool hide)
*/
bool QTreeWidget::isItemExpanded(const QTreeWidgetItem *item) const
{
- Q_D(const QTreeWidget);
- QTreeModel::SkipSorting skipSorting(d->treeModel());
- return isExpanded(d->index(item));
+ return ((item && item->treeWidget() == this) ? item->isExpanded() : false);
}
/*!
@@ -3174,9 +3243,8 @@ bool QTreeWidget::isItemExpanded(const QTreeWidgetItem *item) const
*/
void QTreeWidget::setItemExpanded(const QTreeWidgetItem *item, bool expand)
{
- Q_D(QTreeWidget);
- QTreeModel::SkipSorting skipSorting(d->treeModel());
- setExpanded(d->index(item), expand);
+ if (item && item->treeWidget() == this)
+ const_cast<QTreeWidgetItem*>(item)->setExpanded(expand);
}
/*!
@@ -3186,14 +3254,14 @@ void QTreeWidget::setItemExpanded(const QTreeWidgetItem *item, bool expand)
otherwise returns \c false.
\sa setFirstItemColumnSpanned()
+
+ \obsolete
+
+ This function is deprecated. Use \l{QTreeWidgetItem::isFirstColumnSpanned()} instead.
*/
bool QTreeWidget::isFirstItemColumnSpanned(const QTreeWidgetItem *item) const
{
- Q_D(const QTreeWidget);
- if (item == d->treeModel()->headerItem)
- return false; // We can't set the header items to spanning
- const QModelIndex index = d->index(item);
- return isFirstColumnSpanned(index.row(), index.parent());
+ return ((item && item->treeWidget() == this) ? item->isFirstColumnSpanned() : false);
}
/*!
@@ -3203,15 +3271,17 @@ bool QTreeWidget::isFirstItemColumnSpanned(const QTreeWidgetItem *item) const
otherwise the item will show one section per column.
\sa isFirstItemColumnSpanned()
+
+ \obsolete
+
+ This function is deprecated. Use \l{QTreeWidgetItem::setFirstColumnSpanned()} instead.
*/
void QTreeWidget::setFirstItemColumnSpanned(const QTreeWidgetItem *item, bool span)
{
- Q_D(QTreeWidget);
- if (item == d->treeModel()->headerItem)
- return; // We can't set header items to spanning
- const QModelIndex index = d->index(item);
- setFirstColumnSpanned(index.row(), index.parent(), span);
+ if (item && item->treeWidget() == this)
+ const_cast<QTreeWidgetItem*>(item)->setFirstColumnSpanned(span);
}
+#endif
/*!
\since 4.3
diff --git a/src/widgets/itemviews/qtreewidget.h b/src/widgets/itemviews/qtreewidget.h
index 975f208702..bed77b336d 100644
--- a/src/widgets/itemviews/qtreewidget.h
+++ b/src/widgets/itemviews/qtreewidget.h
@@ -66,9 +66,9 @@ public:
enum ItemType { Type = 0, UserType = 1000 };
explicit QTreeWidgetItem(int type = Type);
explicit QTreeWidgetItem(const QStringList &strings, int type = Type);
- explicit QTreeWidgetItem(QTreeWidget *view, int type = Type);
- QTreeWidgetItem(QTreeWidget *view, const QStringList &strings, int type = Type);
- QTreeWidgetItem(QTreeWidget *view, QTreeWidgetItem *after, int type = Type);
+ explicit QTreeWidgetItem(QTreeWidget *treeview, int type = Type);
+ QTreeWidgetItem(QTreeWidget *treeview, const QStringList &strings, int type = Type);
+ QTreeWidgetItem(QTreeWidget *treeview, QTreeWidgetItem *after, int type = Type);
explicit QTreeWidgetItem(QTreeWidgetItem *parent, int type = Type);
QTreeWidgetItem(QTreeWidgetItem *parent, const QStringList &strings, int type = Type);
QTreeWidgetItem(QTreeWidgetItem *parent, QTreeWidgetItem *after, int type = Type);
@@ -79,17 +79,17 @@ public:
inline QTreeWidget *treeWidget() const { return view; }
- inline void setSelected(bool select);
- inline bool isSelected() const;
+ void setSelected(bool select);
+ bool isSelected() const;
void setHidden(bool hide);
bool isHidden() const;
- inline void setExpanded(bool expand);
- inline bool isExpanded() const;
+ void setExpanded(bool expand);
+ bool isExpanded() const;
- inline void setFirstColumnSpanned(bool span);
- inline bool isFirstColumnSpanned() const;
+ void setFirstColumnSpanned(bool span);
+ bool isFirstColumnSpanned() const;
inline void setDisabled(bool disabled);
inline bool isDisabled() const;
@@ -134,20 +134,28 @@ public:
inline void setTextAlignment(int column, int alignment)
{ setData(column, Qt::TextAlignmentRole, alignment); }
+#if QT_DEPRECATED_SINCE(5, 13)
+ QT_DEPRECATED_X ("Use QTreeWidgetItem::background() instead")
inline QColor backgroundColor(int column) const
- { return qvariant_cast<QColor>(data(column, Qt::BackgroundColorRole)); }
+ { return qvariant_cast<QColor>(data(column, Qt::BackgroundRole)); }
+ QT_DEPRECATED_X ("Use QTreeWidgetItem::setBackground() instead")
inline void setBackgroundColor(int column, const QColor &color)
- { setData(column, Qt::BackgroundColorRole, color); }
+ { setData(column, Qt::BackgroundRole, color); }
+#endif
inline QBrush background(int column) const
{ return qvariant_cast<QBrush>(data(column, Qt::BackgroundRole)); }
inline void setBackground(int column, const QBrush &brush)
{ setData(column, Qt::BackgroundRole, brush); }
+#if QT_DEPRECATED_SINCE(5, 13)
+ QT_DEPRECATED_X ("Use QTreeWidgetItem::foreground() instead")
inline QColor textColor(int column) const
- { return qvariant_cast<QColor>(data(column, Qt::TextColorRole)); }
+ { return qvariant_cast<QColor>(data(column, Qt::ForegroundRole)); }
+ QT_DEPRECATED_X ("Use QTreeWidgetItem::setForeground() instead")
inline void setTextColor(int column, const QColor &color)
- { setData(column, Qt::TextColorRole, color); }
+ { setData(column, Qt::ForegroundRole, color); }
+#endif
inline QBrush foreground(int column) const
{ return qvariant_cast<QBrush>(data(column, Qt::ForegroundRole)); }
@@ -207,6 +215,7 @@ private:
QVariant childrenCheckState(int column) const;
void itemChanged();
void executePendingSort() const;
+ QTreeModel *treeModel(QTreeWidget *v = nullptr) const;
int rtti;
// One item has a vector of column entries. Each column has a vector of (role, value) pairs.
@@ -306,20 +315,32 @@ public:
void setItemWidget(QTreeWidgetItem *item, int column, QWidget *widget);
inline void removeItemWidget(QTreeWidgetItem *item, int column);
+#if QT_DEPRECATED_SINCE(5, 13)
+ QT_DEPRECATED_X ("Use QTreeWidgetItem::isSelected() instead")
bool isItemSelected(const QTreeWidgetItem *item) const;
+ QT_DEPRECATED_X ("Use QTreeWidgetItem::setSelected() instead")
void setItemSelected(const QTreeWidgetItem *item, bool select);
+#endif
QList<QTreeWidgetItem*> selectedItems() const;
QList<QTreeWidgetItem*> findItems(const QString &text, Qt::MatchFlags flags,
int column = 0) const;
+#if QT_DEPRECATED_SINCE(5, 13)
+ QT_DEPRECATED_X ("Use QTreeWidgetItem::isHidden() instead")
bool isItemHidden(const QTreeWidgetItem *item) const;
+ QT_DEPRECATED_X ("Use QTreeWidgetItem::setHidden() instead")
void setItemHidden(const QTreeWidgetItem *item, bool hide);
+ QT_DEPRECATED_X ("Use QTreeWidgetItem::isExpanded() instead")
bool isItemExpanded(const QTreeWidgetItem *item) const;
+ QT_DEPRECATED_X ("Use QTreeWidgetItem::setExpanded() instead")
void setItemExpanded(const QTreeWidgetItem *item, bool expand);
+ QT_DEPRECATED_X ("Use QTreeWidgetItem::isFirstColumnSpanned() instead")
bool isFirstItemColumnSpanned(const QTreeWidgetItem *item) const;
+ QT_DEPRECATED_X ("Use QTreeWidgetItem::setFirstColumnSpanned() instead")
void setFirstItemColumnSpanned(const QTreeWidgetItem *item, bool span);
+#endif
QTreeWidgetItem *itemAbove(const QTreeWidgetItem *item) const;
QTreeWidgetItem *itemBelow(const QTreeWidgetItem *item) const;
@@ -404,24 +425,6 @@ inline QTreeWidgetItem *QTreeWidget::itemAt(int ax, int ay) const
inline void QTreeWidget::setHeaderLabel(const QString &alabel)
{ setHeaderLabels(QStringList(alabel)); }
-inline void QTreeWidgetItem::setSelected(bool aselect)
-{ if (view) view->setItemSelected(this, aselect); }
-
-inline bool QTreeWidgetItem::isSelected() const
-{ return (view ? view->isItemSelected(this) : false); }
-
-inline void QTreeWidgetItem::setExpanded(bool aexpand)
-{ if (view) view->setItemExpanded(this, aexpand); }
-
-inline bool QTreeWidgetItem::isExpanded() const
-{ return (view ? view->isItemExpanded(this) : false); }
-
-inline void QTreeWidgetItem::setFirstColumnSpanned(bool aspan)
-{ if (view) view->setFirstItemColumnSpanned(this, aspan); }
-
-inline bool QTreeWidgetItem::isFirstColumnSpanned() const
-{ return (view ? view->isFirstItemColumnSpanned(this) : false); }
-
inline void QTreeWidgetItem::setDisabled(bool disabled)
{ setFlags(disabled ? (flags() & ~Qt::ItemIsEnabled) : flags() | Qt::ItemIsEnabled); }
diff --git a/src/widgets/itemviews/qtreewidget_p.h b/src/widgets/itemviews/qtreewidget_p.h
index adc2c2c421..ee4a633468 100644
--- a/src/widgets/itemviews/qtreewidget_p.h
+++ b/src/widgets/itemviews/qtreewidget_p.h
@@ -99,7 +99,9 @@ public:
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
bool setData(const QModelIndex &index, const QVariant &value, int role) override;
-
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
+ bool clearItemData(const QModelIndex &index) override;
+#endif
QMap<int, QVariant> itemData(const QModelIndex &index) const override;
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
diff --git a/src/widgets/kernel/qactiongroup.cpp b/src/widgets/kernel/qactiongroup.cpp
index 7934ae1d90..4786437d7e 100644
--- a/src/widgets/kernel/qactiongroup.cpp
+++ b/src/widgets/kernel/qactiongroup.cpp
@@ -316,8 +316,8 @@ bool QActionGroup::isEnabled() const
}
/*!
- Returns the currently checked action in the group, or 0 if none
- are checked.
+ Returns the currently checked action in the group, or \nullptr if
+ none are checked.
*/
QAction *QActionGroup::checkedAction() const
{
diff --git a/src/widgets/kernel/qapplication.cpp b/src/widgets/kernel/qapplication.cpp
index ebab87b193..7c44bfe39d 100644
--- a/src/widgets/kernel/qapplication.cpp
+++ b/src/widgets/kernel/qapplication.cpp
@@ -784,7 +784,7 @@ QWidget *QApplication::activeModalWidget()
/*!
Cleans up any window system resources that were allocated by this
- application. Sets the global variable \c qApp to 0.
+ application. Sets the global variable \c qApp to \nullptr.
*/
QApplication::~QApplication()
@@ -893,8 +893,8 @@ void qt_cleanup()
/*!
\fn QWidget *QApplication::widgetAt(const QPoint &point)
- Returns the widget at global screen position \a point, or 0 if there is no
- Qt widget there.
+ Returns the widget at global screen position \a point, or \nullptr
+ if there is no Qt widget there.
This function can be slow.
@@ -904,9 +904,9 @@ QWidget *QApplication::widgetAt(const QPoint &p)
{
QWidget *window = QApplication::topLevelAt(p);
if (!window)
- return 0;
+ return nullptr;
- QWidget *child = 0;
+ QWidget *child = nullptr;
if (!window->testAttribute(Qt::WA_TransparentForMouseEvents))
child = window->childAt(window->mapFromGlobal(p));
@@ -942,8 +942,8 @@ QWidget *QApplication::widgetAt(const QPoint &p)
\overload
- Returns the widget at global screen position (\a x, \a y), or 0 if there is
- no Qt widget there.
+ Returns the widget at global screen position (\a x, \a y), or
+ \nullptr if there is no Qt widget there.
*/
/*!
@@ -1243,6 +1243,7 @@ QStyle* QApplication::setStyle(const QString& style)
return s;
}
+#if QT_DEPRECATED_SINCE(5, 8)
/*!
Returns the color specification.
\obsolete
@@ -1317,6 +1318,7 @@ void QApplication::setColorSpec(int spec)
{
Q_UNUSED(spec)
}
+#endif
/*!
\property QApplication::globalStrut
@@ -1428,6 +1430,7 @@ void QApplicationPrivate::setPalette_helper(const QPalette &palette, const char*
else
*QApplicationPrivate::set_pal = palette;
QCoreApplication::setAttribute(Qt::AA_SetPalette);
+ emit qGuiApp->paletteChanged(*QGuiApplicationPrivate::app_pal);
}
}
@@ -1727,8 +1730,8 @@ QWidgetList QApplication::allWidgets()
}
/*!
- Returns the application widget that has the keyboard input focus, or 0 if
- no widget in this application has the focus.
+ Returns the application widget that has the keyboard input focus,
+ or \nullptr if no widget in this application has the focus.
\sa QWidget::setFocus(), QWidget::hasFocus(), activeWindow(), focusChanged()
*/
@@ -1796,7 +1799,7 @@ void QApplicationPrivate::setFocusWidget(QWidget *focus, Qt::FocusReason reason)
/*!
Returns the application top-level window that has the keyboard input focus,
- or 0 if no application window has the focus. There might be an
+ or \nullptr if no application window has the focus. There might be an
activeWindow() even if there is no focusWidget(), for example if no widget
in that window accepts key events.
@@ -3891,6 +3894,7 @@ Qt::NavigationMode QApplication::navigationMode()
return QApplicationPrivate::navigationMode;
}
+# if QT_DEPRECATED_SINCE(5, 13)
/*!
Sets whether Qt should use focus navigation suitable for use with a
minimal keypad.
@@ -3933,6 +3937,7 @@ bool QApplication::keypadNavigationEnabled()
return QApplicationPrivate::navigationMode == Qt::NavigationModeKeypadTabOrder ||
QApplicationPrivate::navigationMode == Qt::NavigationModeKeypadDirectional;
}
+# endif
#endif
/*!
diff --git a/src/widgets/kernel/qapplication.h b/src/widgets/kernel/qapplication.h
index 7a5d7ba1a9..27e743a28d 100644
--- a/src/widgets/kernel/qapplication.h
+++ b/src/widgets/kernel/qapplication.h
@@ -180,8 +180,12 @@ public:
bool notify(QObject *, QEvent *) override;
#ifdef QT_KEYPAD_NAVIGATION
- static Q_DECL_DEPRECATED void setKeypadNavigationEnabled(bool);
- static bool keypadNavigationEnabled();
+# if QT_DEPRECATED_SINCE(5, 13)
+ static QT_DEPRECATED_X ("Use QApplication::setNavigationMode() instead")
+ void setKeypadNavigationEnabled(bool);
+ static QT_DEPRECATED_X ("Use QApplication::navigationMode() instead")
+ bool keypadNavigationEnabled();
+# endif
static void setNavigationMode(Qt::NavigationMode mode);
static Qt::NavigationMode navigationMode();
#endif
diff --git a/src/widgets/kernel/qdesktopwidget.cpp b/src/widgets/kernel/qdesktopwidget.cpp
index 5fb7882932..d17c7eb36c 100644
--- a/src/widgets/kernel/qdesktopwidget.cpp
+++ b/src/widgets/kernel/qdesktopwidget.cpp
@@ -176,26 +176,32 @@ void QDesktopWidgetPrivate::_q_updateScreens()
// Notice that we trigger screenCountChanged even if a screen was removed and another one added,
// in which case the total number of screens did not change. This is the only way for applications
// to notice that a screen was swapped out against another one.
+#if QT_DEPRECATED_SINCE(5, 11)
QT_WARNING_PUSH
QT_WARNING_DISABLE_DEPRECATED
emit q->screenCountChanged(targetLength);
QT_WARNING_POP
+#endif
}
+#if QT_DEPRECATED_SINCE(5, 11)
foreach (int changedScreen, changedScreens)
QT_WARNING_PUSH
QT_WARNING_DISABLE_DEPRECATED
emit q->resized(changedScreen);
QT_WARNING_POP
+#endif
}
void QDesktopWidgetPrivate::_q_availableGeometryChanged()
{
+#if QT_DEPRECATED_SINCE(5, 11)
Q_Q(QDesktopWidget);
if (QScreen *screen = qobject_cast<QScreen *>(q->sender()))
QT_WARNING_PUSH
QT_WARNING_DISABLE_DEPRECATED
emit q->workAreaResized(QGuiApplication::screens().indexOf(screen));
QT_WARNING_POP
+#endif
}
QDesktopWidget::QDesktopWidget()
@@ -212,10 +218,12 @@ QDesktopWidget::~QDesktopWidget()
{
}
+#if QT_DEPRECATED_SINCE(5, 11)
bool QDesktopWidget::isVirtualDesktop() const
{
return QDesktopWidgetPrivate::isVirtualDesktop();
}
+#endif
bool QDesktopWidgetPrivate::isVirtualDesktop()
{
@@ -242,24 +250,27 @@ int QDesktopWidgetPrivate::height()
return geometry().height();
}
+#if QT_DEPRECATED_SINCE(5, 11)
int QDesktopWidget::primaryScreen() const
{
return QDesktopWidgetPrivate::primaryScreen();
}
+#endif
int QDesktopWidgetPrivate::primaryScreen()
{
return 0;
}
-int QDesktopWidget::numScreens() const
+int QDesktopWidgetPrivate::numScreens()
{
- return QDesktopWidgetPrivate::numScreens();
+ return qMax(QGuiApplication::screens().size(), 1);
}
-int QDesktopWidgetPrivate::numScreens()
+#if QT_DEPRECATED_SINCE(5, 11)
+int QDesktopWidget::numScreens() const
{
- return qMax(QGuiApplication::screens().size(), 1);
+ return QDesktopWidgetPrivate::numScreens();
}
QWidget *QDesktopWidget::screen(int screen)
@@ -274,6 +285,7 @@ const QRect QDesktopWidget::availableGeometry(int screenNo) const
{
return QDesktopWidgetPrivate::availableGeometry(screenNo);
}
+#endif
const QRect QDesktopWidgetPrivate::availableGeometry(int screenNo)
{
@@ -281,10 +293,12 @@ const QRect QDesktopWidgetPrivate::availableGeometry(int screenNo)
return screen ? screen->availableGeometry() : QRect();
}
+#if QT_DEPRECATED_SINCE(5, 11)
const QRect QDesktopWidget::screenGeometry(int screenNo) const
{
return QDesktopWidgetPrivate::screenGeometry(screenNo);
}
+#endif
const QRect QDesktopWidgetPrivate::screenGeometry(int screenNo)
{
@@ -344,10 +358,12 @@ int QDesktopWidgetPrivate::screenNumber(const QWidget *w)
return allScreens.indexOf(widgetScreen);
}
+#if QT_DEPRECATED_SINCE(5, 11)
int QDesktopWidget::screenNumber(const QPoint &p) const
{
return QDesktopWidgetPrivate::screenNumber(p);
}
+#endif
int QDesktopWidgetPrivate::screenNumber(const QPoint &p)
{
diff --git a/src/widgets/kernel/qdesktopwidget.h b/src/widgets/kernel/qdesktopwidget.h
index f986f0db20..e5c587984f 100644
--- a/src/widgets/kernel/qdesktopwidget.h
+++ b/src/widgets/kernel/qdesktopwidget.h
@@ -52,9 +52,11 @@ class QDesktopWidgetPrivate;
class Q_WIDGETS_EXPORT QDesktopWidget : public QWidget
{
Q_OBJECT
+#if QT_DEPRECATED_SINCE(5, 11)
Q_PROPERTY(bool virtualDesktop READ isVirtualDesktop)
Q_PROPERTY(int screenCount READ screenCount NOTIFY screenCountChanged)
Q_PROPERTY(int primaryScreen READ primaryScreen NOTIFY primaryScreenChanged)
+#endif
public:
QDesktopWidget();
~QDesktopWidget();
diff --git a/src/widgets/kernel/qformlayout.cpp b/src/widgets/kernel/qformlayout.cpp
index 600934b8a1..bd0ea2598a 100644
--- a/src/widgets/kernel/qformlayout.cpp
+++ b/src/widgets/kernel/qformlayout.cpp
@@ -419,13 +419,15 @@ void QFormLayoutPrivate::updateSizes()
if (label) {
maxMinLblWidth = qMax(maxMinLblWidth, label->minSize.width());
maxShLblWidth = qMax(maxShLblWidth, label->sizeHint.width());
- if (field) {
+ }
+ if (field) {
+ if (field->fullRow) {
+ maxMinIfldWidth = qMax(maxMinIfldWidth, field->minSize.width());
+ maxShIfldWidth = qMax(maxShIfldWidth, field->sizeHint.width());
+ } else {
maxMinFldWidth = qMax(maxMinFldWidth, field->minSize.width() + field->sbsHSpace);
maxShFldWidth = qMax(maxShFldWidth, field->sizeHint.width() + field->sbsHSpace);
}
- } else if (field) {
- maxMinIfldWidth = qMax(maxMinIfldWidth, field->minSize.width());
- maxShIfldWidth = qMax(maxShIfldWidth, field->sizeHint.width());
}
prevLbl = label;
@@ -2207,8 +2209,11 @@ void QFormLayoutPrivate::arrangeWidgets(const QVector<QLayoutStruct>& layouts, Q
QSize sz(qMin(label->layoutWidth, label->sizeHint.width()), height);
int x = leftOffset + rect.x() + label->layoutPos;
- if (fixedAlignment(q->labelAlignment(), layoutDirection) & Qt::AlignRight)
+ const auto fAlign = fixedAlignment(q->labelAlignment(), layoutDirection);
+ if (fAlign & Qt::AlignRight)
x += label->layoutWidth - sz.width();
+ else if (fAlign & Qt::AlignHCenter)
+ x += label->layoutWidth / 2 - sz.width() / 2;
QPoint p(x, layouts.at(label->vLayoutIndex).pos);
// ### expansion & sizepolicy stuff
diff --git a/src/widgets/kernel/qgesturemanager.cpp b/src/widgets/kernel/qgesturemanager.cpp
index 891858b035..cd27c9c5be 100644
--- a/src/widgets/kernel/qgesturemanager.cpp
+++ b/src/widgets/kernel/qgesturemanager.cpp
@@ -136,7 +136,7 @@ Qt::GestureType QGestureManager::registerGestureRecognizer(QGestureRecognizer *r
++m_lastCustomGestureId;
type = Qt::GestureType(m_lastCustomGestureId);
}
- m_recognizers.insertMulti(type, recognizer);
+ m_recognizers.insert(type, recognizer);
return type;
}
@@ -517,7 +517,7 @@ bool QGestureManager::filterEvent(QWidget *receiver, QEvent *event)
for(ContextIterator it = w->d_func()->gestureContext.constBegin(),
e = w->d_func()->gestureContext.constEnd(); it != e; ++it) {
types.insert(it.key(), 0);
- contexts.insertMulti(w, it.key());
+ contexts.insert(w, it.key());
}
}
// find all gesture contexts for the widget tree
@@ -529,7 +529,7 @@ bool QGestureManager::filterEvent(QWidget *receiver, QEvent *event)
if (!(it.value() & Qt::DontStartGestureOnChildren)) {
if (!types.contains(it.key())) {
types.insert(it.key(), 0);
- contexts.insertMulti(w, it.key());
+ contexts.insert(w, it.key());
}
}
}
@@ -551,7 +551,7 @@ bool QGestureManager::filterEvent(QGraphicsObject *receiver, QEvent *event)
for(ContextIterator it = item->QGraphicsItem::d_func()->gestureContext.constBegin(),
e = item->QGraphicsItem::d_func()->gestureContext.constEnd(); it != e; ++it) {
types.insert(it.key(), 0);
- contexts.insertMulti(item, it.key());
+ contexts.insert(item, it.key());
}
}
// find all gesture contexts for the graphics object tree
@@ -564,7 +564,7 @@ bool QGestureManager::filterEvent(QGraphicsObject *receiver, QEvent *event)
if (!(it.value() & Qt::DontStartGestureOnChildren)) {
if (!types.contains(it.key())) {
types.insert(it.key(), 0);
- contexts.insertMulti(item, it.key());
+ contexts.insert(item, it.key());
}
}
}
diff --git a/src/widgets/kernel/qgridlayout.cpp b/src/widgets/kernel/qgridlayout.cpp
index f1c6c96a6d..4f2b505e32 100644
--- a/src/widgets/kernel/qgridlayout.cpp
+++ b/src/widgets/kernel/qgridlayout.cpp
@@ -1330,8 +1330,8 @@ QLayoutItem *QGridLayout::itemAt(int index) const
/*!
\since 4.4
- Returns the layout item that occupies cell (\a row, \a column), or 0 if
- the cell is empty.
+ Returns the layout item that occupies cell (\a row, \a column), or
+ \nullptr if the cell is empty.
\sa getItemPosition(), indexOf()
*/
@@ -1346,7 +1346,7 @@ QLayoutItem *QGridLayout::itemAtPosition(int row, int column) const
return box->item();
}
}
- return 0;
+ return nullptr;
}
/*!
diff --git a/src/widgets/kernel/qlayout.cpp b/src/widgets/kernel/qlayout.cpp
index eac5674161..e3f6a56875 100644
--- a/src/widgets/kernel/qlayout.cpp
+++ b/src/widgets/kernel/qlayout.cpp
@@ -109,7 +109,7 @@ static int menuBarHeightForWidth(QWidget *menubar, int w)
/*!
Constructs a new top-level QLayout, with parent \a parent.
- \a parent may not be a \c nullptr.
+ \a parent may not be a \nullptr.
The layout is set directly as the top-level layout for
\a parent. There can be only one top-level layout for a
@@ -282,6 +282,7 @@ bool QLayout::setAlignment(QLayout *l, Qt::Alignment alignment)
return false;
}
+#if QT_DEPRECATED_SINCE(5, 13)
/*!
\property QLayout::margin
\brief the width of the outside border of the layout
@@ -307,6 +308,15 @@ int QLayout::margin() const
}
/*!
+ \obsolete
+*/
+void QLayout::setMargin(int margin)
+{
+ setContentsMargins(margin, margin, margin, margin);
+}
+
+#endif
+/*!
\property QLayout::spacing
\brief the spacing between widgets inside the layout
@@ -344,14 +354,6 @@ int QLayout::spacing() const
}
}
-/*!
- \obsolete
-*/
-void QLayout::setMargin(int margin)
-{
- setContentsMargins(margin, margin, margin, margin);
-}
-
void QLayout::setSpacing(int spacing)
{
if (QBoxLayout* boxlayout = qobject_cast<QBoxLayout*>(this)) {
@@ -474,8 +476,8 @@ QRect QLayout::contentsRect() const
/*!
- Returns the parent widget of this layout, or 0 if this layout is
- not installed on any widget.
+ Returns the parent widget of this layout, or \nullptr if this
+ layout is not installed on any widget.
If the layout is a sub-layout, this function returns the parent
widget of the parent layout.
@@ -490,11 +492,11 @@ QWidget *QLayout::parentWidget() const
QLayout *parentLayout = qobject_cast<QLayout*>(parent());
if (Q_UNLIKELY(!parentLayout)) {
qWarning("QLayout::parentWidget: A layout can only have another layout as a parent.");
- return 0;
+ return nullptr;
}
return parentLayout->parentWidget();
} else {
- return 0;
+ return nullptr;
}
} else {
Q_ASSERT(parent() && parent()->isWidgetType());
@@ -950,8 +952,8 @@ void QLayout::setMenuBar(QWidget *widget)
}
/*!
- Returns the menu bar set for this layout, or 0 if no menu bar is
- set.
+ Returns the menu bar set for this layout, or \nullptr if no
+ menu bar is set.
*/
QWidget *QLayout::menuBar() const
@@ -1130,8 +1132,9 @@ bool QLayout::activate()
Searches for widget \a from and replaces it with widget \a to if found.
Returns the layout item that contains the widget \a from on success.
- Otherwise \c 0 is returned. If \a options contains \c Qt::FindChildrenRecursively
- (the default), sub-layouts are searched for doing the replacement.
+ Otherwise \nullptr is returned.
+ If \a options contains \c Qt::FindChildrenRecursively (the default),
+ sub-layouts are searched for doing the replacement.
Any other flag in \a options is ignored.
Notice that the returned item therefore might not belong to this layout,
diff --git a/src/widgets/kernel/qlayout.h b/src/widgets/kernel/qlayout.h
index 616f4e7164..35a04a35b2 100644
--- a/src/widgets/kernel/qlayout.h
+++ b/src/widgets/kernel/qlayout.h
@@ -63,7 +63,9 @@ class Q_WIDGETS_EXPORT QLayout : public QObject, public QLayoutItem
Q_OBJECT
Q_DECLARE_PRIVATE(QLayout)
+#if QT_DEPRECATED_SINCE(5, 13)
Q_PROPERTY(int margin READ margin WRITE setMargin)
+#endif
Q_PROPERTY(int spacing READ spacing WRITE setSpacing)
Q_PROPERTY(SizeConstraint sizeConstraint READ sizeConstraint WRITE setSizeConstraint)
public:
@@ -81,10 +83,12 @@ public:
QLayout();
~QLayout();
+#if QT_DEPRECATED_SINCE(5, 13)
int margin() const;
- int spacing() const;
-
void setMargin(int);
+#endif
+
+ int spacing() const;
void setSpacing(int);
void setContentsMargins(int left, int top, int right, int bottom);
diff --git a/src/widgets/kernel/qlayoutitem.cpp b/src/widgets/kernel/qlayoutitem.cpp
index 25890e888b..9e6d1c5eac 100644
--- a/src/widgets/kernel/qlayoutitem.cpp
+++ b/src/widgets/kernel/qlayoutitem.cpp
@@ -309,24 +309,24 @@ void QLayoutItem::invalidate()
/*!
If this item is a QLayout, it is returned as a QLayout; otherwise
- 0 is returned. This function provides type-safe casting.
+ \nullptr is returned. This function provides type-safe casting.
\sa spacerItem(), widget()
*/
-QLayout * QLayoutItem::layout()
+QLayout *QLayoutItem::layout()
{
- return 0;
+ return nullptr;
}
/*!
If this item is a QSpacerItem, it is returned as a QSpacerItem;
- otherwise 0 is returned. This function provides type-safe casting.
+ otherwise \nullptr is returned. This function provides type-safe casting.
\sa layout(), widget()
*/
-QSpacerItem * QLayoutItem::spacerItem()
+QSpacerItem *QLayoutItem::spacerItem()
{
- return 0;
+ return nullptr;
}
/*!
@@ -354,7 +354,7 @@ QSpacerItem * QSpacerItem::spacerItem()
/*!
If this item manages a QWidget, returns that widget. Otherwise,
- \c nullptr is returned.
+ \nullptr is returned.
\note While the functions layout() and spacerItem() perform casts, this
function returns another object: QLayout and QSpacerItem inherit QLayoutItem,
@@ -362,9 +362,9 @@ QSpacerItem * QSpacerItem::spacerItem()
\sa layout(), spacerItem()
*/
-QWidget * QLayoutItem::widget()
+QWidget *QLayoutItem::widget()
{
- return 0;
+ return nullptr;
}
/*!
diff --git a/src/widgets/kernel/qopenglwidget.cpp b/src/widgets/kernel/qopenglwidget.cpp
index 89f860150f..cf15614680 100644
--- a/src/widgets/kernel/qopenglwidget.cpp
+++ b/src/widgets/kernel/qopenglwidget.cpp
@@ -1118,8 +1118,8 @@ void QOpenGLWidget::setTextureFormat(GLenum texFormat)
/*!
\return the active internal texture format if the widget has already
initialized, the requested format if one was set but the widget has not yet
- been made visible, or 0 if setTextureFormat() was not called and the widget
- has not yet been made visible.
+ been made visible, or \nullptr if setTextureFormat() was not called and the
+ widget has not yet been made visible.
\since 5.10
*/
diff --git a/src/widgets/kernel/qstackedlayout.cpp b/src/widgets/kernel/qstackedlayout.cpp
index 7430d833db..0412dc188d 100644
--- a/src/widgets/kernel/qstackedlayout.cpp
+++ b/src/widgets/kernel/qstackedlayout.cpp
@@ -378,20 +378,20 @@ void QStackedLayout::setCurrentWidget(QWidget *widget)
/*!
- Returns the current widget, or 0 if there are no widgets in this
- layout.
+ Returns the current widget, or \nullptr if there are no widgets
+ in this layout.
\sa currentIndex(), setCurrentWidget()
*/
QWidget *QStackedLayout::currentWidget() const
{
Q_D(const QStackedLayout);
- return d->index >= 0 ? d->list.at(d->index)->widget() : 0;
+ return d->index >= 0 ? d->list.at(d->index)->widget() : nullptr;
}
/*!
- Returns the widget at the given \a index, or 0 if there is no
- widget at the given position.
+ Returns the widget at the given \a index, or \nullptr if there is
+ no widget at the given position.
\sa currentWidget(), indexOf()
*/
@@ -399,7 +399,7 @@ QWidget *QStackedLayout::widget(int index) const
{
Q_D(const QStackedLayout);
if (index < 0 || index >= d->list.size())
- return 0;
+ return nullptr;
return d->list.at(index)->widget();
}
diff --git a/src/widgets/kernel/qtooltip.cpp b/src/widgets/kernel/qtooltip.cpp
index cf0f3f153b..f81cb471fa 100644
--- a/src/widgets/kernel/qtooltip.cpp
+++ b/src/widgets/kernel/qtooltip.cpp
@@ -482,8 +482,8 @@ bool QTipLabel::tipChanged(const QPoint &pos, const QString &text, QObject *o)
The \a rect is in the coordinates of the widget you specify with
\a w. If the \a rect is not empty you must specify a widget.
- Otherwise this argument can be 0 but it is used to determine the
- appropriate screen on multi-head systems.
+ Otherwise this argument can be \nullptr but it is used to
+ determine the appropriate screen on multi-head systems.
If \a text is empty the tool tip is hidden. If the text is the
same as the currently shown tooltip, the tip will \e not move.
diff --git a/src/widgets/kernel/qwhatsthis.cpp b/src/widgets/kernel/qwhatsthis.cpp
index 1fa83d3238..4a798a7490 100644
--- a/src/widgets/kernel/qwhatsthis.cpp
+++ b/src/widgets/kernel/qwhatsthis.cpp
@@ -398,10 +398,10 @@ QWhatsThisPrivate::QWhatsThisPrivate()
#ifdef QT_NO_CURSOR
Q_UNUSED(sentEvent);
#else
- QApplication::setOverrideCursor((!sentEvent || !e.isAccepted())?
+ QGuiApplication::setOverrideCursor((!sentEvent || !e.isAccepted())?
Qt::ForbiddenCursor:Qt::WhatsThisCursor);
} else {
- QApplication::setOverrideCursor(Qt::WhatsThisCursor);
+ QGuiApplication::setOverrideCursor(Qt::WhatsThisCursor);
#endif
}
#ifndef QT_NO_ACCESSIBILITY
@@ -417,7 +417,7 @@ QWhatsThisPrivate::~QWhatsThisPrivate()
action->setChecked(false);
#endif // QT_CONFIG(action)
#ifndef QT_NO_CURSOR
- QApplication::restoreOverrideCursor();
+ QGuiApplication::restoreOverrideCursor();
#endif
#ifndef QT_NO_ACCESSIBILITY
QAccessibleEvent event(this, QAccessible::ContextHelpEnd);
diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp
index 332eee9c03..b71a0ed052 100644
--- a/src/widgets/kernel/qwidget.cpp
+++ b/src/widgets/kernel/qwidget.cpp
@@ -511,10 +511,10 @@ void QWidget::setAutoFillBackground(bool enabled)
Every widget's constructor accepts one or two standard arguments:
\list 1
- \li \c{QWidget *parent = 0} is the parent of the new widget. If it is 0
- (the default), the new widget will be a window. If not, it will be
- a child of \e parent, and be constrained by \e parent's geometry
- (unless you specify Qt::Window as window flag).
+ \li \c{QWidget *parent = \nullptr} is the parent of the new widget.
+ If it is \nullptr (the default), the new widget will be a window.
+ If not, it will be a child of \e parent, and be constrained by
+ \e parent's geometry (unless you specify Qt::Window as window flag).
\li \c{Qt::WindowFlags f = 0} (where available) sets the window flags;
the default is suitable for almost all widgets, but to get, for
example, a window without a window system frame, you must use
@@ -1003,14 +1003,14 @@ struct QWidgetExceptionCleaner
Constructs a widget which is a child of \a parent, with widget
flags set to \a f.
- If \a parent is 0, the new widget becomes a window. If
+ If \a parent is \nullptr, the new widget becomes a window. If
\a parent is another widget, this widget becomes a child window
inside \a parent. The new widget is deleted when its \a parent is
deleted.
The widget flags argument, \a f, is normally 0, but it can be set
- to customize the frame of a window (i.e. \a
- parent must be 0). To customize the frame, use a value composed
+ to customize the frame of a window (i.e. \a parent must be
+ \nullptr). To customize the frame, use a value composed
from the bitwise OR of any of the \l{Qt::WindowFlags}{window flags}.
If you add a child widget to an already visible widget you must
@@ -2413,29 +2413,34 @@ static inline void fillRegion(QPainter *painter, const QRegion &rgn, const QBrus
}
}
-void QWidgetPrivate::paintBackground(QPainter *painter, const QRegion &rgn, int flags) const
+bool QWidgetPrivate::updateBrushOrigin(QPainter *painter, const QBrush &brush) const
{
- Q_Q(const QWidget);
-
#if QT_CONFIG(scrollarea)
- bool resetBrushOrigin = false;
- QPointF oldBrushOrigin;
+ Q_Q(const QWidget);
//If we are painting the viewport of a scrollarea, we must apply an offset to the brush in case we are drawing a texture
+ if (brush.style() == Qt::NoBrush || brush.style() == Qt::SolidPattern)
+ return false;
QAbstractScrollArea *scrollArea = qobject_cast<QAbstractScrollArea *>(parent);
if (scrollArea && scrollArea->viewport() == q) {
QObjectData *scrollPrivate = static_cast<QWidget *>(scrollArea)->d_ptr.data();
QAbstractScrollAreaPrivate *priv = static_cast<QAbstractScrollAreaPrivate *>(scrollPrivate);
- oldBrushOrigin = painter->brushOrigin();
- resetBrushOrigin = true;
painter->setBrushOrigin(-priv->contentsOffset());
-
}
#endif // QT_CONFIG(scrollarea)
+ return true;
+}
+
+void QWidgetPrivate::paintBackground(QPainter *painter, const QRegion &rgn, int flags) const
+{
+ Q_Q(const QWidget);
+ bool brushOriginSet = false;
const QBrush autoFillBrush = q->palette().brush(q->backgroundRole());
if ((flags & DrawAsRoot) && !(q->autoFillBackground() && autoFillBrush.isOpaque())) {
const QBrush bg = q->palette().brush(QPalette::Window);
+ if (!brushOriginSet)
+ brushOriginSet = updateBrushOrigin(painter, bg);
if (!(flags & DontSetCompositionMode)) {
//copy alpha straight in
QPainter::CompositionMode oldMode = painter->compositionMode();
@@ -2447,8 +2452,11 @@ void QWidgetPrivate::paintBackground(QPainter *painter, const QRegion &rgn, int
}
}
- if (q->autoFillBackground())
+ if (q->autoFillBackground()) {
+ if (!brushOriginSet)
+ brushOriginSet = updateBrushOrigin(painter, autoFillBrush);
fillRegion(painter, rgn, autoFillBrush);
+ }
if (q->testAttribute(Qt::WA_StyledBackground)) {
painter->setClipRegion(rgn);
@@ -2456,11 +2464,6 @@ void QWidgetPrivate::paintBackground(QPainter *painter, const QRegion &rgn, int
opt.initFrom(q);
q->style()->drawPrimitive(QStyle::PE_Widget, &opt, painter, q);
}
-
-#if QT_CONFIG(scrollarea)
- if (resetBrushOrigin)
- painter->setBrushOrigin(oldBrushOrigin);
-#endif // QT_CONFIG(scrollarea)
}
/*
@@ -2494,12 +2497,12 @@ void QWidgetPrivate::deactivateWidgetCleanup()
The window identifier type depends on the underlying window
system, see \c qwindowdefs.h for the actual definition. If there
- is no widget with this identifier, 0 is returned.
+ is no widget with this identifier, \nullptr is returned.
*/
QWidget *QWidget::find(WId id)
{
- return QWidgetPrivate::mapper ? QWidgetPrivate::mapper->value(id, 0) : 0;
+ return QWidgetPrivate::mapper ? QWidgetPrivate::mapper->value(id, 0) : nullptr;
}
@@ -3276,7 +3279,7 @@ void QWidget::addActions(QList<QAction*> actions)
/*!
Inserts the action \a action to this widget's list of actions,
- before the action \a before. It appends the action if \a before is 0 or
+ before the action \a before. It appends the action if \a before is \nullptr or
\a before is not a valid action for this widget.
A QWidget should only have one of each action.
@@ -3310,7 +3313,7 @@ void QWidget::insertAction(QAction *before, QAction *action)
/*!
Inserts the actions \a actions to this widget's list of actions,
- before the action \a before. It appends the action if \a before is 0 or
+ before the action \a before. It appends the action if \a before is \nullptr or
\a before is not a valid action for this widget.
A QWidget can have at most one of each action.
@@ -4229,7 +4232,7 @@ void QWidget::setFixedHeight(int h)
/*!
Translates the widget coordinate \a pos to the coordinate system
- of \a parent. The \a parent must not be 0 and must be a parent
+ of \a parent. The \a parent must not be \nullptr and must be a parent
of the calling widget.
\sa mapFrom(), mapToParent(), mapToGlobal(), underMouse()
@@ -4254,7 +4257,7 @@ QPoint QWidget::mapTo(const QWidget * parent, const QPoint & pos) const
/*!
Translates the widget coordinate \a pos from the coordinate system
of \a parent to this widget's coordinate system. The \a parent
- must not be 0 and must be a parent of the calling widget.
+ must not be \nullptr and must be a parent of the calling widget.
\sa mapTo(), mapFromParent(), mapFromGlobal(), underMouse()
*/
@@ -4333,7 +4336,8 @@ QWidget *QWidget::window() const
\since 4.4
Returns the native parent for this widget, i.e. the next ancestor widget
- that has a system identifier, or 0 if it does not have any native parent.
+ that has a system identifier, or \nullptr if it does not have any native
+ parent.
\sa effectiveWinId()
*/
@@ -4954,9 +4958,9 @@ void QWidget::unsetLayoutDirection()
Some underlying window implementations will reset the cursor if it
leaves a widget even if the mouse is grabbed. If you want to have
a cursor set for all widgets, even when outside the window, consider
- QApplication::setOverrideCursor().
+ QGuiApplication::setOverrideCursor().
- \sa QApplication::setOverrideCursor()
+ \sa QGuiApplication::setOverrideCursor()
*/
#ifndef QT_NO_CURSOR
@@ -5269,7 +5273,7 @@ QPixmap QWidget::grab(const QRect &rectangle)
\brief The graphicsEffect function returns a pointer to the
widget's graphics effect.
- If the widget has no graphics effect, 0 is returned.
+ If the widget has no graphics effect, \nullptr is returned.
\since 4.6
@@ -5313,7 +5317,7 @@ void QWidget::setGraphicsEffect(QGraphicsEffect *effect)
return;
if (d->graphicsEffect) {
- d->invalidateBuffer(rect());
+ d->invalidateBackingStore(rect());
delete d->graphicsEffect;
d->graphicsEffect = 0;
}
@@ -5733,12 +5737,10 @@ void QWidgetPrivate::render(QPaintDevice *target, const QPoint &targetOffset,
QPoint offset = targetOffset;
offset -= paintRegion.boundingRect().topLeft();
QPoint redirectionOffset;
- QPaintDevice *redirected = 0;
+ QPaintDevice *redirected = nullptr;
if (target->devType() == QInternal::Widget)
redirected = static_cast<QWidget *>(target)->d_func()->redirected(&redirectionOffset);
- if (!redirected)
- redirected = QPainter::redirected(target, &redirectionOffset);
if (redirected) {
target = redirected;
@@ -5915,10 +5917,10 @@ QPixmap QWidgetEffectSourcePrivate::pixmap(Qt::CoordinateSystem system, QPoint *
Finds the nearest widget embedded in a graphics proxy widget along the chain formed by this
widget and its ancestors. The search starts at \a origin (inclusive).
- If successful, the function returns the proxy that embeds the widget, or 0 if no embedded
- widget was found.
+ If successful, the function returns the proxy that embeds the widget, or \nullptr if no
+ embedded widget was found.
*/
-QGraphicsProxyWidget * QWidgetPrivate::nearestGraphicsProxyWidget(const QWidget *origin)
+QGraphicsProxyWidget *QWidgetPrivate::nearestGraphicsProxyWidget(const QWidget *origin)
{
if (origin) {
QWExtra *extra = origin->d_func()->extra;
@@ -5926,7 +5928,7 @@ QGraphicsProxyWidget * QWidgetPrivate::nearestGraphicsProxyWidget(const QWidget
return extra->proxyWidget;
return nearestGraphicsProxyWidget(origin->parentWidget());
}
- return 0;
+ return nullptr;
}
#endif
@@ -6398,7 +6400,7 @@ void QWidget::setWindowRole(const QString &role)
/*!
- Sets the widget's focus proxy to widget \a w. If \a w is 0, the
+ Sets the widget's focus proxy to widget \a w. If \a w is \nullptr, the
function resets this widget to have no focus proxy.
Some widgets can "have focus", but create a child widget, such as
@@ -6431,15 +6433,15 @@ void QWidget::setFocusProxy(QWidget * w)
/*!
- Returns the focus proxy, or 0 if there is no focus proxy.
+ Returns the focus proxy, or \nullptr if there is no focus proxy.
\sa setFocusProxy()
*/
-QWidget * QWidget::focusProxy() const
+QWidget *QWidget::focusProxy() const
{
Q_D(const QWidget);
- return d->extra ? (QWidget *)d->extra->focus_proxy : 0;
+ return d->extra ? (QWidget *)d->extra->focus_proxy : nullptr;
}
@@ -7338,11 +7340,11 @@ void QWidgetPrivate::setGeometry_sys(int x, int y, int w, int h, bool isMove)
if (renderToTexture) {
QRegion updateRegion(q->geometry());
updateRegion += QRect(oldPos, olds);
- q->parentWidget()->d_func()->invalidateBuffer(updateRegion);
+ q->parentWidget()->d_func()->invalidateBackingStore(updateRegion);
} else if (isMove && !isResize) {
moveRect(QRect(oldPos, olds), x - oldPos.x(), y - oldPos.y());
} else {
- invalidateBuffer_resizeHelper(oldPos, olds);
+ invalidateBackingStore_resizeHelper(oldPos, olds);
}
}
}
@@ -8104,7 +8106,7 @@ void QWidgetPrivate::show_sys()
QWidgetWindow *window = windowHandle();
if (q->testAttribute(Qt::WA_DontShowOnScreen)) {
- invalidateBuffer(q->rect());
+ invalidateBackingStore(q->rect());
q->setAttribute(Qt::WA_Mapped);
// add our window the modal window list (native dialogs)
if (window && q->isWindow()
@@ -8147,7 +8149,7 @@ void QWidgetPrivate::show_sys()
#ifndef QT_NO_CURSOR
qt_qpa_set_cursor(q, false); // Needed in case cursor was set before show
#endif
- invalidateBuffer(q->rect());
+ invalidateBackingStore(q->rect());
window->setNativeWindowVisibility(true);
// Was the window moved by the Window system or QPlatformWindow::initialGeometry() ?
if (window->isTopLevel()) {
@@ -8261,12 +8263,12 @@ void QWidgetPrivate::hide_sys()
QWidget *p = q->parentWidget();
if (p &&p->isVisible()) {
if (renderToTexture)
- p->d_func()->invalidateBuffer(q->geometry());
+ p->d_func()->invalidateBackingStore(q->geometry());
else
- invalidateBuffer(q->rect());
+ invalidateBackingStore(q->rect());
}
} else {
- invalidateBuffer(q->rect());
+ invalidateBackingStore(q->rect());
}
if (window)
@@ -8820,7 +8822,7 @@ QSize QWidget::minimumSizeHint() const
/*!
\fn QWidget *QWidget::parentWidget() const
- Returns the parent of this widget, or 0 if it does not have any
+ Returns the parent of this widget, or \nullptr if it does not have any
parent widget.
*/
@@ -10230,7 +10232,7 @@ QRegion QWidget::mask() const
}
/*!
- Returns the layout manager that is installed on this widget, or 0
+ Returns the layout manager that is installed on this widget, or \nullptr
if no layout manager is installed.
The layout manager sets the geometry of the widget's children
@@ -11902,7 +11904,7 @@ void QWidget::raise()
QRegion region(rect());
d->subtractOpaqueSiblings(region);
- d->invalidateBuffer(region);
+ d->invalidateBackingStore(region);
}
if (testAttribute(Qt::WA_WState_Created))
d->raise_sys();
@@ -11922,7 +11924,7 @@ void QWidgetPrivate::raise_sys()
} else if (renderToTexture) {
if (QWidget *p = q->parentWidget()) {
setDirtyOpaqueRegion();
- p->d_func()->invalidateBuffer(effectiveRectFor(q->geometry()));
+ p->d_func()->invalidateBackingStore(effectiveRectFor(q->geometry()));
}
}
}
@@ -11972,7 +11974,7 @@ void QWidgetPrivate::lower_sys()
q->windowHandle()->lower();
} else if (QWidget *p = q->parentWidget()) {
setDirtyOpaqueRegion();
- p->d_func()->invalidateBuffer(effectiveRectFor(q->geometry()));
+ p->d_func()->invalidateBackingStore(effectiveRectFor(q->geometry()));
}
}
@@ -12016,7 +12018,7 @@ void QWidgetPrivate::stackUnder_sys(QWidget*)
Q_Q(QWidget);
if (QWidget *p = q->parentWidget()) {
setDirtyOpaqueRegion();
- p->d_func()->invalidateBuffer(effectiveRectFor(q->geometry()));
+ p->d_func()->invalidateBackingStore(effectiveRectFor(q->geometry()));
}
}
@@ -12118,14 +12120,14 @@ bool QWidgetPrivate::navigateToDirection(Direction direction)
Searches for a widget that is positioned in the \a direction, starting
from the current focusWidget.
- Returns the pointer to a found widget or 0, if there was no widget in
- that direction.
+ Returns the pointer to a found widget or \nullptr, if there was no widget
+ in that direction.
*/
QWidget *QWidgetPrivate::widgetInNavigationDirection(Direction direction)
{
const QWidget *sourceWidget = QApplication::focusWidget();
if (!sourceWidget)
- return 0;
+ return nullptr;
const QRect sourceRect = sourceWidget->rect().translated(sourceWidget->mapToGlobal(QPoint()));
const int sourceX =
(direction == DirectionNorth || direction == DirectionSouth) ?
@@ -12139,7 +12141,7 @@ QWidget *QWidgetPrivate::widgetInNavigationDirection(Direction direction)
const QPoint sourceCenter = sourceRect.center();
const QWidget *sourceWindow = sourceWidget->window();
- QWidget *targetWidget = 0;
+ QWidget *targetWidget = nullptr;
int shortestDistance = INT_MAX;
const auto targetCandidates = QApplication::allWidgets();
@@ -12458,7 +12460,7 @@ void QWidget::destroy(bool destroyWindow, bool destroySubWindows)
d->aboutToDestroy();
if (!isWindow() && parentWidget())
- parentWidget()->d_func()->invalidateBuffer(d->effectiveRectFor(geometry()));
+ parentWidget()->d_func()->invalidateBackingStore(d->effectiveRectFor(geometry()));
d->deactivateWidgetCleanup();
if ((windowType() == Qt::Popup) && qApp)
@@ -12806,7 +12808,7 @@ void QWidget::releaseKeyboard()
Returns the widget that is currently grabbing the mouse input.
If no widget in this application is currently grabbing the mouse,
- 0 is returned.
+ \nullptr is returned.
\sa grabMouse(), keyboardGrabber()
*/
@@ -12823,7 +12825,7 @@ QWidget *QWidget::mouseGrabber()
Returns the widget that is currently grabbing the keyboard input.
If no widget in this application is currently grabbing the
- keyboard, 0 is returned.
+ keyboard, \nullptr is returned.
\sa grabMouse(), mouseGrabber()
*/
diff --git a/src/widgets/kernel/qwidget.h b/src/widgets/kernel/qwidget.h
index 9d5fe89c70..4e5ef5a111 100644
--- a/src/widgets/kernel/qwidget.h
+++ b/src/widgets/kernel/qwidget.h
@@ -235,7 +235,10 @@ public:
bool isEnabled() const;
bool isEnabledTo(const QWidget *) const;
+#if QT_DEPRECATED_SINCE(5, 13)
+ QT_DEPRECATED_X ("Use isEnabled() instead")
bool isEnabledToTLW() const;
+#endif
public Q_SLOTS:
void setEnabled(bool);
@@ -769,8 +772,10 @@ inline bool QWidget::isEnabled() const
inline bool QWidget::isModal() const
{ return data->window_modality != Qt::NonModal; }
+#if QT_DEPRECATED_SINCE(5, 13)
inline bool QWidget::isEnabledToTLW() const
{ return isEnabled(); }
+#endif
inline int QWidget::minimumWidth() const
{ return minimumSize().width(); }
diff --git a/src/widgets/kernel/qwidget_p.h b/src/widgets/kernel/qwidget_p.h
index 7e4ea2cc0c..797963b931 100644
--- a/src/widgets/kernel/qwidget_p.h
+++ b/src/widgets/kernel/qwidget_p.h
@@ -150,7 +150,7 @@ public:
}
private:
- Q_DISABLE_COPY(QWidgetBackingStoreTracker)
+ Q_DISABLE_COPY_MOVE(QWidgetBackingStoreTracker)
private:
QWidgetBackingStore* m_ptr;
@@ -402,6 +402,7 @@ public:
void setUpdatesEnabled_helper(bool );
+ bool updateBrushOrigin(QPainter *, const QBrush &brush) const;
void paintBackground(QPainter *, const QRegion &, int flags = DrawAsRoot) const;
bool isAboutToShow() const;
QRegion prepareToRender(const QRegion &region, QWidget::RenderFlags renderFlags);
@@ -451,10 +452,11 @@ public:
void scrollChildren(int dx, int dy);
void moveRect(const QRect &, int dx, int dy);
void scrollRect(const QRect &, int dx, int dy);
- void invalidateBuffer_resizeHelper(const QPoint &oldPos, const QSize &oldSize);
- // ### Qt 4.6: Merge into a template function (after MSVC isn't supported anymore).
- void invalidateBuffer(const QRegion &);
- void invalidateBuffer(const QRect &);
+ void invalidateBackingStore_resizeHelper(const QPoint &oldPos, const QSize &oldSize);
+
+ template <class T>
+ void invalidateBackingStore(const T &);
+
QRegion overlappedRegion(const QRect &rect, bool breakAfterFirst = false) const;
void syncBackingStore();
void syncBackingStore(const QRegion &region);
@@ -606,6 +608,11 @@ public:
return extra ? extra->nativeChildrenForced : false;
}
+ inline QRect effectiveRectFor(const QRegion &region) const
+ {
+ return effectiveRectFor(region.boundingRect());
+ }
+
inline QRect effectiveRectFor(const QRect &rect) const
{
#if QT_CONFIG(graphicseffect)
diff --git a/src/widgets/kernel/qwidgetbackingstore.cpp b/src/widgets/kernel/qwidgetbackingstore.cpp
index a32eb2a03b..0481dffda8 100644
--- a/src/widgets/kernel/qwidgetbackingstore.cpp
+++ b/src/widgets/kernel/qwidgetbackingstore.cpp
@@ -507,6 +507,9 @@ void QWidgetBackingStore::sendUpdateRequest(QWidget *widget, UpdateTime updateTi
}
}
+static inline QRect widgetRectFor(QWidget *, const QRect &r) { return r; }
+static inline QRect widgetRectFor(QWidget *widget, const QRegion &) { return widget->rect(); }
+
/*!
Marks the region of the widget as dirty (if not already marked as dirty) and
posts an UpdateRequest event to the top-level widget (if not already posted).
@@ -517,42 +520,44 @@ void QWidgetBackingStore::sendUpdateRequest(QWidget *widget, UpdateTime updateTi
If the widget paints directly on screen, the event is sent to the widget
instead of the top-level widget, and bufferState is completely ignored.
-
- ### Qt 4.6: Merge into a template function (after MSVC isn't supported anymore).
*/
-void QWidgetBackingStore::markDirty(const QRegion &rgn, QWidget *widget,
- UpdateTime updateTime, BufferState bufferState)
+template <class T>
+void QWidgetBackingStore::markDirty(const T &r, QWidget *widget, UpdateTime updateTime, BufferState bufferState)
{
Q_ASSERT(tlw->d_func()->extra);
Q_ASSERT(tlw->d_func()->extra->topextra);
Q_ASSERT(!tlw->d_func()->extra->topextra->inTopLevelResize);
Q_ASSERT(widget->isVisible() && widget->updatesEnabled());
Q_ASSERT(widget->window() == tlw);
- Q_ASSERT(!rgn.isEmpty());
+ Q_ASSERT(!r.isEmpty());
#if QT_CONFIG(graphicseffect)
widget->d_func()->invalidateGraphicsEffectsRecursively();
-#endif // QT_CONFIG(graphicseffect)
+#endif
+
+ QRect widgetRect = widgetRectFor(widget, r);
+
+ // ---------------------------------------------------------------------------
if (widget->d_func()->paintOnScreen()) {
if (widget->d_func()->dirty.isEmpty()) {
- widget->d_func()->dirty = rgn;
+ widget->d_func()->dirty = r;
sendUpdateRequest(widget, updateTime);
return;
- } else if (qt_region_strictContains(widget->d_func()->dirty, widget->rect())) {
+ } else if (qt_region_strictContains(widget->d_func()->dirty, widgetRect)) {
if (updateTime == UpdateNow)
sendUpdateRequest(widget, updateTime);
- return; // Already dirty.
+ return; // Already dirty
}
const bool eventAlreadyPosted = !widget->d_func()->dirty.isEmpty();
- widget->d_func()->dirty += rgn;
+ widget->d_func()->dirty += r;
if (!eventAlreadyPosted || updateTime == UpdateNow)
sendUpdateRequest(widget, updateTime);
return;
}
- const QPoint offset = widget->mapTo(tlw, QPoint());
+ // ---------------------------------------------------------------------------
if (QWidgetPrivate::get(widget)->renderToTexture) {
if (!widget->d_func()->inDirtyList)
@@ -562,133 +567,67 @@ void QWidgetBackingStore::markDirty(const QRegion &rgn, QWidget *widget,
return;
}
- const QRect widgetRect = widget->d_func()->effectiveRectFor(widget->rect());
- if (qt_region_strictContains(dirty, widgetRect.translated(offset))) {
+ // ---------------------------------------------------------------------------
+
+ QRect effectiveWidgetRect = widget->d_func()->effectiveRectFor(widgetRect);
+ const QPoint offset = widget->mapTo(tlw, QPoint());
+ QRect translatedRect = effectiveWidgetRect.translated(offset);
+#if QT_CONFIG(graphicseffect)
+ // Graphics effects may exceed window size, clamp
+ translatedRect = translatedRect.intersected(QRect(QPoint(), tlw->size()));
+#endif
+ if (qt_region_strictContains(dirty, translatedRect)) {
if (updateTime == UpdateNow)
sendUpdateRequest(tlw, updateTime);
- return; // Already dirty.
+ return; // Already dirty
}
+ // ---------------------------------------------------------------------------
+
if (bufferState == BufferInvalid) {
const bool eventAlreadyPosted = !dirty.isEmpty() || updateRequestSent;
#if QT_CONFIG(graphicseffect)
if (widget->d_func()->graphicsEffect)
- dirty += widget->d_func()->effectiveRectFor(rgn.boundingRect()).translated(offset);
+ dirty += widget->d_func()->effectiveRectFor(r).translated(offset);
else
-#endif // QT_CONFIG(graphicseffect)
- dirty += rgn.translated(offset);
+#endif
+ dirty += r.translated(offset);
+
if (!eventAlreadyPosted || updateTime == UpdateNow)
sendUpdateRequest(tlw, updateTime);
return;
}
+ // ---------------------------------------------------------------------------
+
if (dirtyWidgets.isEmpty()) {
- addDirtyWidget(widget, rgn);
+ addDirtyWidget(widget, r);
sendUpdateRequest(tlw, updateTime);
return;
}
+ // ---------------------------------------------------------------------------
+
if (widget->d_func()->inDirtyList) {
- if (!qt_region_strictContains(widget->d_func()->dirty, widgetRect)) {
+ if (!qt_region_strictContains(widget->d_func()->dirty, effectiveWidgetRect)) {
#if QT_CONFIG(graphicseffect)
if (widget->d_func()->graphicsEffect)
- widget->d_func()->dirty += widget->d_func()->effectiveRectFor(rgn.boundingRect());
+ widget->d_func()->dirty += widget->d_func()->effectiveRectFor(r);
else
-#endif // QT_CONFIG(graphicseffect)
- widget->d_func()->dirty += rgn;
+#endif
+ widget->d_func()->dirty += r;
}
} else {
- addDirtyWidget(widget, rgn);
- }
-
- if (updateTime == UpdateNow)
- sendUpdateRequest(tlw, updateTime);
-}
-
-/*!
- This function is equivalent to calling markDirty(QRegion(rect), ...), but
- is more efficient as it eliminates QRegion operations/allocations and can
- use the rect more precisely for additional cut-offs.
-
- ### Qt 4.6: Merge into a template function (after MSVC isn't supported anymore).
-*/
-void QWidgetBackingStore::markDirty(const QRect &rect, QWidget *widget,
- UpdateTime updateTime, BufferState bufferState)
-{
- Q_ASSERT(tlw->d_func()->extra);
- Q_ASSERT(tlw->d_func()->extra->topextra);
- Q_ASSERT(!tlw->d_func()->extra->topextra->inTopLevelResize);
- Q_ASSERT(widget->isVisible() && widget->updatesEnabled());
- Q_ASSERT(widget->window() == tlw);
- Q_ASSERT(!rect.isEmpty());
-
-#if QT_CONFIG(graphicseffect)
- widget->d_func()->invalidateGraphicsEffectsRecursively();
-#endif // QT_CONFIG(graphicseffect)
-
- if (widget->d_func()->paintOnScreen()) {
- if (widget->d_func()->dirty.isEmpty()) {
- widget->d_func()->dirty = QRegion(rect);
- sendUpdateRequest(widget, updateTime);
- return;
- } else if (qt_region_strictContains(widget->d_func()->dirty, rect)) {
- if (updateTime == UpdateNow)
- sendUpdateRequest(widget, updateTime);
- return; // Already dirty.
- }
-
- const bool eventAlreadyPosted = !widget->d_func()->dirty.isEmpty();
- widget->d_func()->dirty += rect;
- if (!eventAlreadyPosted || updateTime == UpdateNow)
- sendUpdateRequest(widget, updateTime);
- return;
- }
-
- if (QWidgetPrivate::get(widget)->renderToTexture) {
- if (!widget->d_func()->inDirtyList)
- addDirtyRenderToTextureWidget(widget);
- if (!updateRequestSent || updateTime == UpdateNow)
- sendUpdateRequest(tlw, updateTime);
- return;
+ addDirtyWidget(widget, r);
}
-
- const QRect widgetRect = widget->d_func()->effectiveRectFor(rect);
- QRect translatedRect = widgetRect;
- if (widget != tlw)
- translatedRect.translate(widget->mapTo(tlw, QPoint()));
- // Graphics effects may exceed window size, clamp.
- translatedRect = translatedRect.intersected(QRect(QPoint(), tlw->size()));
- if (qt_region_strictContains(dirty, translatedRect)) {
- if (updateTime == UpdateNow)
- sendUpdateRequest(tlw, updateTime);
- return; // Already dirty
- }
-
- if (bufferState == BufferInvalid) {
- const bool eventAlreadyPosted = !dirty.isEmpty();
- dirty += translatedRect;
- if (!eventAlreadyPosted || updateTime == UpdateNow)
- sendUpdateRequest(tlw, updateTime);
- return;
- }
-
- if (dirtyWidgets.isEmpty()) {
- addDirtyWidget(widget, rect);
- sendUpdateRequest(tlw, updateTime);
- return;
- }
-
- if (widget->d_func()->inDirtyList) {
- if (!qt_region_strictContains(widget->d_func()->dirty, widgetRect))
- widget->d_func()->dirty += widgetRect;
- } else {
- addDirtyWidget(widget, rect);
- }
+ // ---------------------------------------------------------------------------
if (updateTime == UpdateNow)
sendUpdateRequest(tlw, updateTime);
}
+template void QWidgetBackingStore::markDirty<QRect>(const QRect &, QWidget *, UpdateTime, BufferState);
+template void QWidgetBackingStore::markDirty<QRegion>(const QRegion &, QWidget *, UpdateTime, BufferState);
/*!
Marks the \a region of the \a widget as dirty on screen. The \a region will be copied from
@@ -859,11 +798,11 @@ void QWidgetPrivate::moveRect(const QRect &rect, int dx, int dy)
if (!extra || !extra->hasMask) {
parentR -= newRect;
} else {
- // invalidateBuffer() excludes anything outside the mask
+ // invalidateBackingStore() excludes anything outside the mask
parentR += newRect & clipR;
}
- pd->invalidateBuffer(parentR);
- invalidateBuffer((newRect & clipR).translated(-data.crect.topLeft()));
+ pd->invalidateBackingStore(parentR);
+ invalidateBackingStore((newRect & clipR).translated(-data.crect.topLeft()));
} else {
QWidgetBackingStore *wbs = x->backingStoreTracker.data();
@@ -894,7 +833,7 @@ void QWidgetPrivate::moveRect(const QRect &rect, int dx, int dy)
if (childUpdatesEnabled) {
if (!overlappedExpose.isEmpty()) {
overlappedExpose.translate(-data.crect.topLeft());
- invalidateBuffer(overlappedExpose);
+ invalidateBackingStore(overlappedExpose);
}
if (!childExpose.isEmpty()) {
childExpose.translate(-data.crect.topLeft());
@@ -944,9 +883,9 @@ void QWidgetPrivate::scrollRect(const QRect &rect, int dx, int dy)
if (!overlappedRegion(scrollRect.translated(data.crect.topLeft()), true).isEmpty()) {
QRegion region(scrollRect);
subtractOpaqueSiblings(region);
- invalidateBuffer(region);
+ invalidateBackingStore(region);
}else {
- invalidateBuffer(scrollRect);
+ invalidateBackingStore(scrollRect);
}
} else {
const QPoint toplevelOffset = q->mapTo(tlw, QPoint());
@@ -987,7 +926,7 @@ void QWidgetPrivate::scrollRect(const QRect &rect, int dx, int dy)
return;
if (!overlappedExpose.isEmpty())
- invalidateBuffer(overlappedExpose);
+ invalidateBackingStore(overlappedExpose);
if (!childExpose.isEmpty()) {
wbs->markDirty(childExpose, q);
isScrolled = true;
@@ -1471,26 +1410,11 @@ void QWidgetBackingStore::flush(QWidget *widget)
dirtyOnScreenWidgets->clear();
}
-static inline bool discardInvalidateBufferRequest(QWidget *widget, QTLWExtra *tlwExtra)
-{
- Q_ASSERT(widget);
- if (QApplication::closingDown())
- return true;
-
- if (!tlwExtra || tlwExtra->inTopLevelResize || !tlwExtra->backingStore)
- return true;
-
- if (!widget->isVisible() || !widget->updatesEnabled())
- return true;
-
- return false;
-}
-
/*!
- Invalidates the buffer when the widget is resized.
+ Invalidates the backing store when the widget is resized.
Static areas are never invalidated unless absolutely needed.
*/
-void QWidgetPrivate::invalidateBuffer_resizeHelper(const QPoint &oldPos, const QSize &oldSize)
+void QWidgetPrivate::invalidateBackingStore_resizeHelper(const QPoint &oldPos, const QSize &oldSize)
{
Q_Q(QWidget);
Q_ASSERT(!q->isWindow());
@@ -1515,10 +1439,10 @@ void QWidgetPrivate::invalidateBuffer_resizeHelper(const QPoint &oldPos, const Q
if (hasStaticChildren) {
QRegion dirty(newWidgetRect);
dirty -= staticChildren;
- invalidateBuffer(dirty);
+ invalidateBackingStore(dirty);
} else {
// Entire widget needs repaint.
- invalidateBuffer(newWidgetRect);
+ invalidateBackingStore(newWidgetRect);
}
if (!parentAreaExposed)
@@ -1530,14 +1454,14 @@ void QWidgetPrivate::invalidateBuffer_resizeHelper(const QPoint &oldPos, const Q
parentExpose &= QRect(oldPos, oldSize);
if (hasStaticChildren)
parentExpose -= data.crect; // Offset is unchanged, safe to do this.
- q->parentWidget()->d_func()->invalidateBuffer(parentExpose);
+ q->parentWidget()->d_func()->invalidateBackingStore(parentExpose);
} else {
if (hasStaticChildren && !graphicsEffect) {
QRegion parentExpose(QRect(oldPos, oldSize));
parentExpose -= data.crect; // Offset is unchanged, safe to do this.
- q->parentWidget()->d_func()->invalidateBuffer(parentExpose);
+ q->parentWidget()->d_func()->invalidateBackingStore(parentExpose);
} else {
- q->parentWidget()->d_func()->invalidateBuffer(effectiveRectFor(QRect(oldPos, oldSize)));
+ q->parentWidget()->d_func()->invalidateBackingStore(effectiveRectFor(QRect(oldPos, oldSize)));
}
}
return;
@@ -1558,7 +1482,7 @@ void QWidgetPrivate::invalidateBuffer_resizeHelper(const QPoint &oldPos, const Q
if (!sizeDecreased || !oldWidgetRect.contains(newWidgetRect)) {
QRegion newVisible(newWidgetRect);
newVisible -= oldWidgetRect;
- invalidateBuffer(newVisible);
+ invalidateBackingStore(newVisible);
}
if (!parentAreaExposed)
@@ -1570,74 +1494,56 @@ void QWidgetPrivate::invalidateBuffer_resizeHelper(const QPoint &oldPos, const Q
QRegion parentExpose(oldRect);
parentExpose &= extra->mask.translated(oldPos);
parentExpose -= (extra->mask.translated(data.crect.topLeft()) & data.crect);
- q->parentWidget()->d_func()->invalidateBuffer(parentExpose);
+ q->parentWidget()->d_func()->invalidateBackingStore(parentExpose);
} else {
QRegion parentExpose(oldRect);
parentExpose -= data.crect;
- q->parentWidget()->d_func()->invalidateBuffer(parentExpose);
+ q->parentWidget()->d_func()->invalidateBackingStore(parentExpose);
}
}
/*!
- Invalidates the \a rgn (in widget's coordinates) of the backing store, i.e.
- all widgets intersecting with the region will be repainted when the backing store
- is synced.
-
- ### Qt 4.6: Merge into a template function (after MSVC isn't supported anymore).
+ Invalidates the \a r (in widget's coordinates) of the backing store, i.e.
+ all widgets intersecting with the region will be repainted when the backing
+ store is synced.
*/
-void QWidgetPrivate::invalidateBuffer(const QRegion &rgn)
+template <class T>
+void QWidgetPrivate::invalidateBackingStore(const T &r)
{
- Q_Q(QWidget);
-
- QTLWExtra *tlwExtra = q->window()->d_func()->maybeTopData();
- if (discardInvalidateBufferRequest(q, tlwExtra) || rgn.isEmpty())
+ if (r.isEmpty())
return;
- QRegion wrgn(rgn);
- wrgn &= clipRect();
- if (!graphicsEffect && extra && extra->hasMask)
- wrgn &= extra->mask;
- if (wrgn.isEmpty())
+ if (QApplication::closingDown())
return;
- tlwExtra->backingStoreTracker->markDirty(wrgn, q,
- QWidgetBackingStore::UpdateLater, QWidgetBackingStore::BufferInvalid);
-}
-
-/*!
- This function is equivalent to calling invalidateBuffer(QRegion(rect), ...), but
- is more efficient as it eliminates QRegion operations/allocations and can
- use the rect more precisely for additional cut-offs.
-
- ### Qt 4.6: Merge into a template function (after MSVC isn't supported anymore).
-*/
-void QWidgetPrivate::invalidateBuffer(const QRect &rect)
-{
Q_Q(QWidget);
-
- QTLWExtra *tlwExtra = q->window()->d_func()->maybeTopData();
- if (discardInvalidateBufferRequest(q, tlwExtra) || rect.isEmpty())
+ if (!q->isVisible() || !q->updatesEnabled())
return;
- QRect wRect(rect);
- wRect &= clipRect();
- if (wRect.isEmpty())
+ QTLWExtra *tlwExtra = q->window()->d_func()->maybeTopData();
+ if (!tlwExtra || tlwExtra->inTopLevelResize || !tlwExtra->backingStore)
return;
- if (graphicsEffect || !extra || !extra->hasMask) {
- tlwExtra->backingStoreTracker->markDirty(wRect, q,
- QWidgetBackingStore::UpdateLater, QWidgetBackingStore::BufferInvalid);
+ T clipped(r);
+ clipped &= clipRect();
+ if (clipped.isEmpty())
return;
- }
- QRegion wRgn(extra->mask);
- wRgn &= wRect;
- if (wRgn.isEmpty())
- return;
+ if (!graphicsEffect && extra && extra->hasMask) {
+ QRegion masked(extra->mask);
+ masked &= clipped;
+ if (masked.isEmpty())
+ return;
- tlwExtra->backingStoreTracker->markDirty(wRgn, q,
+ tlwExtra->backingStoreTracker->markDirty(masked, q,
QWidgetBackingStore::UpdateLater, QWidgetBackingStore::BufferInvalid);
+ } else {
+ tlwExtra->backingStoreTracker->markDirty(clipped, q,
+ QWidgetBackingStore::UpdateLater, QWidgetBackingStore::BufferInvalid);
+ }
}
+// Needed by tst_QWidget
+template Q_AUTOTEST_EXPORT void QWidgetPrivate::invalidateBackingStore<QRect>(const QRect &r);
void QWidgetPrivate::repaint_sys(const QRegion &rgn)
{
diff --git a/src/widgets/kernel/qwidgetbackingstore_p.h b/src/widgets/kernel/qwidgetbackingstore_p.h
index 53ccda850a..4d15ab138e 100644
--- a/src/widgets/kernel/qwidgetbackingstore_p.h
+++ b/src/widgets/kernel/qwidgetbackingstore_p.h
@@ -118,10 +118,8 @@ public:
return !(dirtyWidgets.isEmpty() && dirty.isEmpty() && dirtyRenderToTextureWidgets.isEmpty());
}
- // ### Qt 4.6: Merge into a template function (after MSVC isn't supported anymore).
- void markDirty(const QRegion &rgn, QWidget *widget, UpdateTime updateTime = UpdateLater,
- BufferState bufferState = BufferValid);
- void markDirty(const QRect &rect, QWidget *widget, UpdateTime updateTime = UpdateLater,
+ template <class T>
+ void markDirty(const T &r, QWidget *widget, UpdateTime updateTime = UpdateLater,
BufferState bufferState = BufferValid);
private:
@@ -305,7 +303,7 @@ private:
friend class QWidget;
friend class QBackingStore;
- Q_DISABLE_COPY(QWidgetBackingStore)
+ Q_DISABLE_COPY_MOVE(QWidgetBackingStore)
};
QT_END_NAMESPACE
diff --git a/src/widgets/statemachine/qbasickeyeventtransition_p.h b/src/widgets/statemachine/qbasickeyeventtransition_p.h
index 5007b79739..7e1b978bba 100644
--- a/src/widgets/statemachine/qbasickeyeventtransition_p.h
+++ b/src/widgets/statemachine/qbasickeyeventtransition_p.h
@@ -84,7 +84,7 @@ protected:
void onTransition(QEvent *) override;
private:
- Q_DISABLE_COPY(QBasicKeyEventTransition)
+ Q_DISABLE_COPY_MOVE(QBasicKeyEventTransition)
Q_DECLARE_PRIVATE(QBasicKeyEventTransition)
};
diff --git a/src/widgets/statemachine/qbasicmouseeventtransition_p.h b/src/widgets/statemachine/qbasicmouseeventtransition_p.h
index 93d2a5ec61..132e223535 100644
--- a/src/widgets/statemachine/qbasicmouseeventtransition_p.h
+++ b/src/widgets/statemachine/qbasicmouseeventtransition_p.h
@@ -87,7 +87,7 @@ protected:
void onTransition(QEvent *) override;
private:
- Q_DISABLE_COPY(QBasicMouseEventTransition)
+ Q_DISABLE_COPY_MOVE(QBasicMouseEventTransition)
Q_DECLARE_PRIVATE(QBasicMouseEventTransition)
};
diff --git a/src/widgets/styles/qcommonstyle.cpp b/src/widgets/styles/qcommonstyle.cpp
index c739ddc6e2..a3461d8848 100644
--- a/src/widgets/styles/qcommonstyle.cpp
+++ b/src/widgets/styles/qcommonstyle.cpp
@@ -100,6 +100,9 @@
#if QT_CONFIG(wizard)
#include <qwizard.h>
#endif
+#if QT_CONFIG(filedialog)
+#include <qsidebar_p.h>
+#endif
#include <qfileinfo.h>
#include <qdir.h>
#if QT_CONFIG(settings)
@@ -191,12 +194,12 @@ void QCommonStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, Q
opt->state & (State_Sunken | State_On), 1,
&opt->palette.brush(QPalette::Button));
break;
- case PE_IndicatorViewItemCheck:
+ case PE_IndicatorItemViewItemCheck:
proxy()->drawPrimitive(PE_IndicatorCheckBox, opt, p, widget);
break;
case PE_IndicatorCheckBox:
if (opt->state & State_NoChange) {
- p->setPen(opt->palette.foreground().color());
+ p->setPen(opt->palette.windowText().color());
p->fillRect(opt->rect, opt->palette.brush(QPalette::Button));
p->drawRect(opt->rect);
p->drawLine(opt->rect.topLeft(), opt->rect.bottomRight());
@@ -212,7 +215,7 @@ void QCommonStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, Q
p->drawArc(opt->rect, 0, 5760);
if (opt->state & (State_Sunken | State_On)) {
ir.adjust(2, 2, -2, -2);
- p->setBrush(opt->palette.foreground());
+ p->setBrush(opt->palette.windowText());
bool oldQt4CompatiblePainting = p->testRenderHint(QPainter::Qt4CompatiblePainting);
p->setRenderHint(QPainter::Qt4CompatiblePainting);
p->drawEllipse(ir);
@@ -231,7 +234,7 @@ void QCommonStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, Q
else
p->setPen(Qt::white);
} else {
- p->setPen(opt->palette.foreground().color());
+ p->setPen(opt->palette.windowText().color());
}
QRect focusRect = opt->rect.adjusted(1, 1, -1, -1);
p->drawRect(focusRect.adjusted(0, 0, -1, -1)); //draw pen inclusive
@@ -278,7 +281,7 @@ void QCommonStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, Q
qDrawShadePanel(p, frame->rect, frame->palette, frame->state & State_Sunken,
frame->lineWidth);
} else {
- qDrawPlainRect(p, frame->rect, frame->palette.foreground().color(), frame->lineWidth);
+ qDrawPlainRect(p, frame->rect, frame->palette.windowText().color(), frame->lineWidth);
}
}
break;
@@ -615,7 +618,7 @@ void QCommonStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, Q
}
p->setPen(QPen(tab->palette.dark(), qreal(.8)));
- p->setBrush(tab->palette.background());
+ p->setBrush(tab->palette.window());
p->setRenderHint(QPainter::Antialiasing);
p->drawPath(path);
}
@@ -748,7 +751,7 @@ void QCommonStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, Q
QString pixmapName = QStyleHelper::uniqueName(QLatin1String("$qt_ia-")
% QLatin1String(metaObject()->className()), opt, QSize(size, size))
% HexString<uint>(pe);
- if (!QPixmapCache::find(pixmapName, pixmap)) {
+ if (!QPixmapCache::find(pixmapName, &pixmap)) {
qreal pixelRatio = p->device()->devicePixelRatioF();
int border = qRound(pixelRatio*(size/5));
int sqsize = qRound(pixelRatio*(2*(size/2)));
@@ -1249,8 +1252,9 @@ void QCommonStylePrivate::tabLayout(const QStyleOptionTab *opt, const QWidget *w
// High-dpi icons do not need adjustment; make sure tabIconSize is not larger than iconSize
tabIconSize = QSize(qMin(tabIconSize.width(), iconSize.width()), qMin(tabIconSize.height(), iconSize.height()));
- *iconRect = QRect(tr.left(), tr.center().y() - tabIconSize.height() / 2,
- tabIconSize.width(), tabIconSize.height());
+ const int offsetX = (iconSize.width() - tabIconSize.width()) / 2;
+ *iconRect = QRect(tr.left() + offsetX, tr.center().y() - tabIconSize.height() / 2,
+ tabIconSize.width(), tabIconSize.height());
if (!verticalTabs)
*iconRect = proxyStyle->visualRect(opt->direction, opt->rect, *iconRect);
tr.setLeft(tr.left() + tabIconSize.width() + 4);
@@ -1565,7 +1569,7 @@ void QCommonStyle::drawControl(ControlElement element, const QStyleOption *opt,
QPalette pal2 = pb->palette;
// Correct the highlight color if it is the same as the background
- if (pal2.highlight() == pal2.background())
+ if (pal2.highlight() == pal2.window())
pal2.setColor(QPalette::Highlight, pb->palette.color(QPalette::Active,
QPalette::Highlight));
bool reverse = ((!vertical && (pb->direction == Qt::RightToLeft)) || vertical);
@@ -1853,14 +1857,14 @@ void QCommonStyle::drawControl(ControlElement element, const QStyleOption *opt,
}
}
- p->setPen(QPen(tab->palette.foreground(), 0));
+ p->setPen(QPen(tab->palette.windowText(), 0));
if (selected) {
p->setBrush(tab->palette.base());
} else {
if (widget && widget->parentWidget())
- p->setBrush(widget->parentWidget()->palette().background());
+ p->setBrush(widget->parentWidget()->palette().window());
else
- p->setBrush(tab->palette.background());
+ p->setBrush(tab->palette.window());
}
int y;
@@ -2157,7 +2161,7 @@ void QCommonStyle::drawControl(ControlElement element, const QStyleOption *opt,
const int indent = p->fontMetrics().descent();
proxy()->drawItemText(p, r.adjusted(indent + 1, 1, -indent - 1, -1),
- Qt::AlignLeft | Qt::AlignVCenter | Qt::TextShowMnemonic, dwOpt->palette,
+ Qt::AlignLeft | Qt::AlignVCenter, dwOpt->palette,
dwOpt->state & State_Enabled, dwOpt->title,
QPalette::WindowText);
@@ -2184,7 +2188,7 @@ void QCommonStyle::drawControl(ControlElement element, const QStyleOption *opt,
}
break;
case CE_FocusFrame:
- p->fillRect(opt->rect, opt->palette.foreground());
+ p->fillRect(opt->rect, opt->palette.windowText());
break;
case CE_HeaderSection:
qDrawShadePanel(p, opt->rect, opt->palette,
@@ -2192,7 +2196,7 @@ void QCommonStyle::drawControl(ControlElement element, const QStyleOption *opt,
&opt->palette.brush(QPalette::Button));
break;
case CE_HeaderEmptyArea:
- p->fillRect(opt->rect, opt->palette.background());
+ p->fillRect(opt->rect, opt->palette.window());
break;
#if QT_CONFIG(combobox)
case CE_ComboBoxLabel:
@@ -2296,7 +2300,7 @@ void QCommonStyle::drawControl(ControlElement element, const QStyleOption *opt,
option.state |= QStyle::State_On;
break;
}
- proxy()->drawPrimitive(QStyle::PE_IndicatorViewItemCheck, &option, p, widget);
+ proxy()->drawPrimitive(QStyle::PE_IndicatorItemViewItemCheck, &option, p, widget);
}
// draw the icon
@@ -3137,7 +3141,7 @@ QRect QCommonStyle::subElementRect(SubElement sr, const QStyleOption *opt,
}
d->cachedOption = new QStyleOptionViewItem(*vopt);
}
- if (sr == SE_ViewItemCheckIndicator)
+ if (sr == SE_ItemViewItemCheckIndicator)
r = d->checkRect;
else if (sr == SE_ItemViewItemDecoration)
r = d->decorationRect;
@@ -3153,13 +3157,17 @@ QRect QCommonStyle::subElementRect(SubElement sr, const QStyleOption *opt,
///we need to access the widget here because the style option doesn't
//have all the information we need (ie. the layout's margin)
const QToolBar *tb = qobject_cast<const QToolBar*>(widget);
- const int margin = tb && tb->layout() ? tb->layout()->margin() : 2;
+ const QMargins margins = tb && tb->layout() ? tb->layout()->contentsMargins() : QMargins(2, 2, 2, 2);
const int handleExtent = proxy()->pixelMetric(QStyle::PM_ToolBarHandleExtent, opt, tb);
if (tbopt->state & QStyle::State_Horizontal) {
- r = QRect(margin, margin, handleExtent, tbopt->rect.height() - 2*margin);
+ r = QRect(margins.left(), margins.top(),
+ handleExtent,
+ tbopt->rect.height() - (margins.top() + margins.bottom()));
r = QStyle::visualRect(tbopt->direction, tbopt->rect, r);
} else {
- r = QRect(margin, margin, tbopt->rect.width() - 2*margin, handleExtent);
+ r = QRect(margins.left(), margins.top(),
+ tbopt->rect.width() - (margins.left() + margins.right()),
+ handleExtent);
}
}
}
@@ -3256,7 +3264,7 @@ void QCommonStyle::drawComplexControl(ComplexControl cc, const QStyleOptionCompl
// Since there is no subrect for tickmarks do a translation here.
p->save();
p->translate(slider->rect.x(), slider->rect.y());
- p->setPen(slider->palette.foreground().color());
+ p->setPen(slider->palette.windowText().color());
int v = slider->minimum;
while (v <= slider->maximum + 1) {
if (v == slider->maximum + 1 && interval == 1)
@@ -3702,7 +3710,7 @@ void QCommonStyle::drawComplexControl(ComplexControl cc, const QStyleOptionCompl
QPalette pal = opt->palette;
// draw notches
if (dial->subControls & QStyle::SC_DialTickmarks) {
- p->setPen(pal.foreground().color());
+ p->setPen(pal.windowText().color());
p->drawLines(QStyleHelper::calcLines(dial));
}
@@ -4359,8 +4367,10 @@ QRect QCommonStyle::subControlRect(ComplexControl cc, const QStyleOptionComplex
int topMargin = 0;
int topHeight = 0;
int verticalAlignment = proxy()->styleHint(SH_GroupBox_TextLabelVerticalAlignment, groupBox, widget);
- if (groupBox->text.size() || (groupBox->subControls & QStyle::SC_GroupBoxCheckBox)) {
- topHeight = groupBox->fontMetrics.height();
+ bool hasCheckBox = groupBox->subControls & QStyle::SC_GroupBoxCheckBox;
+ if (groupBox->text.size() || hasCheckBox) {
+ int checkBoxHeight = hasCheckBox ? proxy()->pixelMetric(PM_IndicatorHeight, groupBox, widget) : 0;
+ topHeight = qMax(groupBox->fontMetrics.height(), checkBoxHeight);
if (verticalAlignment & Qt::AlignVCenter)
topMargin = topHeight / 2;
else if (verticalAlignment & Qt::AlignTop)
@@ -4385,20 +4395,24 @@ QRect QCommonStyle::subControlRect(ComplexControl cc, const QStyleOptionComplex
case SC_GroupBoxCheckBox:
case SC_GroupBoxLabel: {
QFontMetrics fontMetrics = groupBox->fontMetrics;
- int h = fontMetrics.height();
+ int th = fontMetrics.height();
int tw = fontMetrics.size(Qt::TextShowMnemonic, groupBox->text + QLatin1Char(' ')).width();
int marg = (groupBox->features & QStyleOptionFrame::Flat) ? 0 : 8;
ret = groupBox->rect.adjusted(marg, 0, -marg, 0);
- ret.setHeight(h);
int indicatorWidth = proxy()->pixelMetric(PM_IndicatorWidth, opt, widget);
+ int indicatorHeight = proxy()->pixelMetric(PM_IndicatorHeight, opt, widget);
int indicatorSpace = proxy()->pixelMetric(PM_CheckBoxLabelSpacing, opt, widget) - 1;
bool hasCheckBox = groupBox->subControls & QStyle::SC_GroupBoxCheckBox;
- int checkBoxSize = hasCheckBox ? (indicatorWidth + indicatorSpace) : 0;
+ int checkBoxWidth = hasCheckBox ? (indicatorWidth + indicatorSpace) : 0;
+ int checkBoxHeight = hasCheckBox ? indicatorHeight : 0;
+
+ int h = qMax(th, checkBoxHeight);
+ ret.setHeight(h);
// Adjusted rect for label + indicatorWidth + indicatorSpace
QRect totalRect = alignedRect(groupBox->direction, groupBox->textAlignment,
- QSize(tw + checkBoxSize, h), ret);
+ QSize(tw + checkBoxWidth, h), ret);
// Adjust totalRect if checkbox is set
if (hasCheckBox) {
@@ -4406,15 +4420,14 @@ QRect QCommonStyle::subControlRect(ComplexControl cc, const QStyleOptionComplex
int left = 0;
// Adjust for check box
if (sc == SC_GroupBoxCheckBox) {
- int indicatorHeight = proxy()->pixelMetric(PM_IndicatorHeight, opt, widget);
left = ltr ? totalRect.left() : (totalRect.right() - indicatorWidth);
- int top = totalRect.top() + qMax(0, fontMetrics.height() - indicatorHeight) / 2;
+ int top = totalRect.top() + (h - checkBoxHeight) / 2;
totalRect.setRect(left, top, indicatorWidth, indicatorHeight);
// Adjust for label
} else {
- left = ltr ? (totalRect.left() + checkBoxSize - 2) : totalRect.left();
- totalRect.setRect(left, totalRect.top(),
- totalRect.width() - checkBoxSize, totalRect.height());
+ left = ltr ? (totalRect.left() + checkBoxWidth - 2) : totalRect.left();
+ int top = totalRect.top() + (h - th) / 2;
+ totalRect.setRect(left, top, totalRect.width() - checkBoxWidth, th);
}
}
ret = totalRect;
@@ -4790,9 +4803,16 @@ int QCommonStyle::pixelMetric(PixelMetric m, const QStyleOption *opt, const QWid
break;
case PM_TabBarIconSize:
- case PM_ListViewIconSize:
ret = proxy()->pixelMetric(PM_SmallIconSize, opt, widget);
break;
+ case PM_ListViewIconSize:
+#if QT_CONFIG(filedialog)
+ if (qobject_cast<const QSidebar *>(widget))
+ ret = int(QStyleHelper::dpiScaled(24.));
+ else
+#endif
+ ret = proxy()->pixelMetric(PM_SmallIconSize, opt, widget);
+ break;
case PM_ButtonIconSize:
case PM_SmallIconSize:
@@ -4972,8 +4992,8 @@ QSize QCommonStyle::sizeFromContents(ContentsType ct, const QStyleOption *opt,
break;
#if QT_CONFIG(groupbox)
case CT_GroupBox:
- if (const QGroupBox *grb = static_cast<const QGroupBox *>(widget))
- sz += QSize(!grb->isFlat() ? 16 : 0, 0);
+ if (const QStyleOptionGroupBox *styleOpt = qstyleoption_cast<const QStyleOptionGroupBox *>(opt))
+ sz += QSize(styleOpt->features.testFlag(QStyleOptionFrame::Flat) ? 0 : 16, 0);
break;
#endif // QT_CONFIG(groupbox)
case CT_MdiControls:
diff --git a/src/widgets/styles/qdrawutil.cpp b/src/widgets/styles/qdrawutil.cpp
index 299dbb9f82..d30b43a679 100644
--- a/src/widgets/styles/qdrawutil.cpp
+++ b/src/widgets/styles/qdrawutil.cpp
@@ -51,7 +51,7 @@ QT_BEGIN_NAMESPACE
namespace {
class PainterStateGuard {
- Q_DISABLE_COPY(PainterStateGuard)
+ Q_DISABLE_COPY_MOVE(PainterStateGuard)
public:
explicit PainterStateGuard(QPainter *p) : m_painter(p) {}
~PainterStateGuard()
diff --git a/src/widgets/styles/qfusionstyle.cpp b/src/widgets/styles/qfusionstyle.cpp
index c565932889..f3961b2a99 100644
--- a/src/widgets/styles/qfusionstyle.cpp
+++ b/src/widgets/styles/qfusionstyle.cpp
@@ -261,7 +261,7 @@ static void qt_fusion_draw_arrow(Qt::ArrowType type, QPainter *painter, const QS
QString cacheKey = QStyleHelper::uniqueName(QLatin1String("fusion-arrow"), option, rect.size())
% HexString<uint>(type)
% HexString<uint>(color.rgba());
- if (!QPixmapCache::find(cacheKey, cachePixmap)) {
+ if (!QPixmapCache::find(cacheKey, &cachePixmap)) {
cachePixmap = styleCachePixmap(rect.size());
cachePixmap.fill(Qt::transparent);
QPainter cachePainter(&cachePixmap);
@@ -539,7 +539,7 @@ void QFusionStyle::drawPrimitive(PrimitiveElement elem,
{
if (option->rect.width() <= 1 || option->rect.height() <= 1)
break;
- QColor arrowColor = option->palette.foreground().color();
+ QColor arrowColor = option->palette.windowText().color();
arrowColor.setAlpha(160);
Qt::ArrowType arrow = Qt::UpArrow;
switch (elem) {
@@ -558,7 +558,7 @@ void QFusionStyle::drawPrimitive(PrimitiveElement elem,
qt_fusion_draw_arrow(arrow, painter, option, option->rect, arrowColor);
}
break;
- case PE_IndicatorViewItemCheck:
+ case PE_IndicatorItemViewItemCheck:
{
QStyleOptionButton button;
button.QStyleOption::operator=(*option);
@@ -569,7 +569,7 @@ void QFusionStyle::drawPrimitive(PrimitiveElement elem,
case PE_IndicatorHeaderArrow:
if (const QStyleOptionHeader *header = qstyleoption_cast<const QStyleOptionHeader *>(option)) {
QRect r = header->rect;
- QColor arrowColor = header->palette.foreground().color();
+ QColor arrowColor = header->palette.windowText().color();
arrowColor.setAlpha(180);
QPoint offset = QPoint(0, -2);
@@ -598,24 +598,24 @@ void QFusionStyle::drawPrimitive(PrimitiveElement elem,
const int margin = 6;
if (option->state & State_Horizontal) {
const int offset = rect.width()/2;
- painter->setPen(QPen(option->palette.background().color().darker(110)));
+ painter->setPen(QPen(option->palette.window().color().darker(110)));
painter->drawLine(rect.bottomLeft().x() + offset,
rect.bottomLeft().y() - margin,
rect.topLeft().x() + offset,
rect.topLeft().y() + margin);
- painter->setPen(QPen(option->palette.background().color().lighter(110)));
+ painter->setPen(QPen(option->palette.window().color().lighter(110)));
painter->drawLine(rect.bottomLeft().x() + offset + 1,
rect.bottomLeft().y() - margin,
rect.topLeft().x() + offset + 1,
rect.topLeft().y() + margin);
} else { //Draw vertical separator
const int offset = rect.height()/2;
- painter->setPen(QPen(option->palette.background().color().darker(110)));
+ painter->setPen(QPen(option->palette.window().color().darker(110)));
painter->drawLine(rect.topLeft().x() + margin ,
rect.topLeft().y() + offset,
rect.topRight().x() - margin,
rect.topRight().y() + offset);
- painter->setPen(QPen(option->palette.background().color().lighter(110)));
+ painter->setPen(QPen(option->palette.window().color().lighter(110)));
painter->drawLine(rect.topLeft().x() + margin ,
rect.topLeft().y() + offset + 1,
rect.topRight().x() - margin,
@@ -642,8 +642,8 @@ void QFusionStyle::drawPrimitive(PrimitiveElement elem,
{
painter->setPen(QPen(outline));
painter->drawRect(option->rect.adjusted(0, 0, -1, -1));
- QColor frameLight = option->palette.background().color().lighter(160);
- QColor frameShadow = option->palette.background().color().darker(110);
+ QColor frameLight = option->palette.window().color().lighter(160);
+ QColor frameShadow = option->palette.window().color().darker(110);
//paint beveleffect
QRect frame = option->rect.adjusted(1, 1, -1, -1);
@@ -661,14 +661,14 @@ void QFusionStyle::drawPrimitive(PrimitiveElement elem,
painter->save();
{
- QColor softshadow = option->palette.background().color().darker(120);
+ QColor softshadow = option->palette.window().color().darker(120);
QRect rect= option->rect;
painter->setPen(softshadow);
painter->drawRect(option->rect.adjusted(0, 0, -1, -1));
painter->setPen(QPen(option->palette.light(), 1));
painter->drawLine(QPoint(rect.left() + 1, rect.top() + 1), QPoint(rect.left() + 1, rect.bottom() - 1));
- painter->setPen(QPen(option->palette.background().color().darker(120)));
+ painter->setPen(QPen(option->palette.window().color().darker(120)));
painter->drawLine(QPoint(rect.left() + 1, rect.bottom() - 1), QPoint(rect.right() - 2, rect.bottom() - 1));
painter->drawLine(QPoint(rect.right() - 1, rect.top() + 1), QPoint(rect.right() - 1, rect.bottom() - 1));
@@ -704,7 +704,7 @@ void QFusionStyle::drawPrimitive(PrimitiveElement elem,
painter->setPen(QPen(option->palette.light(), 1));
painter->drawLine(QPoint(rect.left() + 1, rect.top() + 1),
QPoint(rect.left() + 1, rect.bottom() - 1));
- painter->setPen(QPen(option->palette.background().color().darker(120)));
+ painter->setPen(QPen(option->palette.window().color().darker(120)));
painter->drawLine(QPoint(rect.left() + 1, rect.bottom() - 1),
QPoint(rect.right() - 2, rect.bottom() - 1));
painter->drawLine(QPoint(rect.right() - 1, rect.top() + 1),
@@ -748,7 +748,7 @@ void QFusionStyle::drawPrimitive(PrimitiveElement elem,
painter->translate(0.5, 0.5);
rect = rect.adjusted(0, 0, -1, -1);
- QColor pressedColor = mergedColors(option->palette.base().color(), option->palette.foreground().color(), 85);
+ QColor pressedColor = mergedColors(option->palette.base().color(), option->palette.windowText().color(), 85);
painter->setBrush(Qt::NoBrush);
// Gradient fill
@@ -802,14 +802,14 @@ void QFusionStyle::drawPrimitive(PrimitiveElement elem,
case PE_IndicatorRadioButton:
painter->save();
{
- QColor pressedColor = mergedColors(option->palette.base().color(), option->palette.foreground().color(), 85);
+ QColor pressedColor = mergedColors(option->palette.base().color(), option->palette.windowText().color(), 85);
painter->setBrush((state & State_Sunken) ? pressedColor : option->palette.base().color());
painter->setRenderHint(QPainter::Antialiasing, true);
QPainterPath circle;
const QPointF circleCenter = rect.center() + QPoint(1, 1);
const qreal outlineRadius = (rect.width() + (rect.width() + 1) % 2) / 2.0 - 1;
circle.addEllipse(circleCenter, outlineRadius, outlineRadius);
- painter->setPen(QPen(option->palette.background().color().darker(150)));
+ painter->setPen(QPen(option->palette.window().color().darker(150)));
if (option->state & State_HasFocus && option->state & State_KeyboardFocusChange)
painter->setPen(QPen(highlightedOutline));
painter->drawPath(circle);
@@ -991,7 +991,7 @@ void QFusionStyle::drawPrimitive(PrimitiveElement elem,
case PE_PanelMenu: {
painter->save();
const QBrush menuBackground = option->palette.base().color().lighter(108);
- QColor borderColor = option->palette.background().color().darker(160);
+ QColor borderColor = option->palette.window().color().darker(160);
qDrawPlainRect(painter, option->rect, borderColor, 1, &menuBackground);
painter->restore();
}
@@ -1256,7 +1256,7 @@ void QFusionStyle::drawControl(ControlElement element, const QStyleOption *optio
Qt::ElideRight, titleRect.width());
proxy()->drawItemText(painter,
titleRect,
- Qt::AlignLeft | Qt::AlignVCenter | Qt::TextShowMnemonic, dwOpt->palette,
+ Qt::AlignLeft | Qt::AlignVCenter, dwOpt->palette,
dwOpt->state & State_Enabled, titleText,
QPalette::WindowText);
}
@@ -1272,7 +1272,7 @@ void QFusionStyle::drawControl(ControlElement element, const QStyleOption *optio
pixmapName += QString::number(- int(header->orientation));
QPixmap cache;
- if (!QPixmapCache::find(pixmapName, cache)) {
+ if (!QPixmapCache::find(pixmapName, &cache)) {
cache = styleCachePixmap(rect.size());
cache.fill(Qt::transparent);
QRect pixmapRect(0, 0, rect.width(), rect.height());
@@ -1283,8 +1283,8 @@ void QFusionStyle::drawControl(ControlElement element, const QStyleOption *optio
gradientStopColor = buttonColor.darker(102);
QLinearGradient gradient(pixmapRect.topLeft(), pixmapRect.bottomLeft());
- if (option->palette.background().gradient()) {
- gradient.setStops(option->palette.background().gradient()->stops());
+ if (option->palette.window().gradient()) {
+ gradient.setStops(option->palette.window().gradient()->stops());
} else {
QColor midColor1 = mergedColors(gradientStartColor, gradientStopColor, 60);
QColor midColor2 = mergedColors(gradientStartColor, gradientStopColor, 40);
@@ -1519,7 +1519,7 @@ void QFusionStyle::drawControl(ControlElement element, const QStyleOption *optio
proxy()->drawItemText(painter, item.rect, alignment, mbi->palette, mbi->state & State_Enabled, mbi->text, textRole);
} else {
- QColor shadow = mergedColors(option->palette.background().color().darker(120),
+ QColor shadow = mergedColors(option->palette.window().color().darker(120),
outline.lighter(140), 60);
painter->setPen(QPen(shadow));
painter->drawLine(option->rect.bottomLeft(), option->rect.bottomRight());
@@ -1649,7 +1649,7 @@ void QFusionStyle::drawControl(ControlElement element, const QStyleOption *optio
if (!ignoreCheckMark && checkable && checked) {
QStyleOption opt = *option;
if (act) {
- QColor activeColor = mergedColors(option->palette.background().color(),
+ QColor activeColor = mergedColors(option->palette.window().color(),
option->palette.highlight().color());
opt.palette.setBrush(QPalette::Button, activeColor);
}
@@ -1731,7 +1731,7 @@ void QFusionStyle::drawControl(ControlElement element, const QStyleOption *optio
newMI.rect = vSubMenuRect;
newMI.state = !enabled ? State_None : State_Enabled;
if (selected)
- newMI.palette.setColor(QPalette::Foreground,
+ newMI.palette.setColor(QPalette::WindowText,
newMI.palette.highlightedText().color());
proxy()->drawPrimitive(arrow, &newMI, painter, widget);
}
@@ -1812,7 +1812,7 @@ void QFusionStyle::drawControl(ControlElement element, const QStyleOption *optio
painter->save();
{
painter->fillRect(rect, option->palette.window());
- QColor shadow = mergedColors(option->palette.background().color().darker(120),
+ QColor shadow = mergedColors(option->palette.window().color().darker(120),
outline.lighter(140), 60);
painter->setPen(QPen(shadow));
painter->drawLine(option->rect.bottomLeft(), option->rect.bottomRight());
@@ -1975,7 +1975,7 @@ void QFusionStyle::drawComplexControl(ComplexControl control, const QStyleOption
// ### backgroundrole/foregroundrole should be part of the style option
alphaCornerColor = mergedColors(option->palette.color(widget->backgroundRole()), outline);
} else {
- alphaCornerColor = mergedColors(option->palette.background().color(), outline);
+ alphaCornerColor = mergedColors(option->palette.window().color(), outline);
}
switch (control) {
@@ -2030,7 +2030,7 @@ void QFusionStyle::drawComplexControl(ComplexControl control, const QStyleOption
if (const QStyleOptionSpinBox *spinBox = qstyleoption_cast<const QStyleOptionSpinBox *>(option)) {
QPixmap cache;
QString pixmapName = QStyleHelper::uniqueName(QLatin1String("spinbox"), spinBox, spinBox->rect.size());
- if (!QPixmapCache::find(pixmapName, cache)) {
+ if (!QPixmapCache::find(pixmapName, &cache)) {
cache = styleCachePixmap(spinBox->rect.size());
cache.fill(Qt::transparent);
@@ -2039,7 +2039,7 @@ void QFusionStyle::drawComplexControl(ComplexControl control, const QStyleOption
QRect rect = pixmapRect;
QRect r = rect.adjusted(0, 1, 0, -1);
QPainter cachePainter(&cache);
- QColor arrowColor = spinBox->palette.foreground().color();
+ QColor arrowColor = spinBox->palette.windowText().color();
arrowColor.setAlpha(160);
bool isEnabled = (spinBox->state & State_Enabled);
@@ -2174,13 +2174,13 @@ void QFusionStyle::drawComplexControl(ComplexControl control, const QStyleOption
QColor highlight = option->palette.highlight().color();
QColor titleBarFrameBorder(active ? highlight.darker(180): outline.darker(110));
- QColor titleBarHighlight(active ? highlight.lighter(120): palette.background().color().lighter(120));
+ QColor titleBarHighlight(active ? highlight.lighter(120): palette.window().color().lighter(120));
QColor textColor(active ? 0xffffff : 0xff000000);
QColor textAlphaColor(active ? 0xffffff : 0xff000000 );
{
// Fill title bar gradient
- QColor titlebarColor = QColor(active ? highlight: palette.background().color());
+ QColor titlebarColor = QColor(active ? highlight: palette.window().color());
QLinearGradient gradient(option->rect.center().x(), option->rect.top(),
option->rect.center().x(), option->rect.bottom());
@@ -2531,7 +2531,7 @@ void QFusionStyle::drawComplexControl(ComplexControl control, const QStyleOption
QColor alphaOutline = outline;
alphaOutline.setAlpha(180);
- QColor arrowColor = option->palette.foreground().color();
+ QColor arrowColor = option->palette.windowText().color();
arrowColor.setAlpha(160);
const QColor bgColor = QStyleHelper::backgroundColor(option->palette, widget);
@@ -2745,7 +2745,7 @@ void QFusionStyle::drawComplexControl(ComplexControl control, const QStyleOption
if (!comboBox->frame)
pixmapName += QLatin1String("-frameless");
- if (!QPixmapCache::find(pixmapName, cache)) {
+ if (!QPixmapCache::find(pixmapName, &cache)) {
cache = styleCachePixmap(comboBox->rect.size());
cache.fill(Qt::transparent);
QPainter cachePainter(&cache);
@@ -2852,7 +2852,7 @@ void QFusionStyle::drawComplexControl(ComplexControl control, const QStyleOption
QRect pixmapRect(0, 0, groove.width(), groove.height());
// draw background groove
- if (!QPixmapCache::find(groovePixmapName, cache)) {
+ if (!QPixmapCache::find(groovePixmapName, &cache)) {
cache = styleCachePixmap(pixmapRect.size());
cache.fill(Qt::transparent);
QPainter groovePainter(&cache);
@@ -2880,7 +2880,7 @@ void QFusionStyle::drawComplexControl(ComplexControl control, const QStyleOption
// draw blue groove highlight
QRect clipRect;
groovePixmapName += QLatin1String("_blue");
- if (!QPixmapCache::find(groovePixmapName, cache)) {
+ if (!QPixmapCache::find(groovePixmapName, &cache)) {
cache = styleCachePixmap(pixmapRect.size());
cache.fill(Qt::transparent);
QPainter groovePainter(&cache);
@@ -2987,7 +2987,7 @@ void QFusionStyle::drawComplexControl(ComplexControl control, const QStyleOption
// draw handle
if ((option->subControls & SC_SliderHandle) ) {
QString handlePixmapName = QStyleHelper::uniqueName(QLatin1String("slider_handle"), option, handle.size());
- if (!QPixmapCache::find(handlePixmapName, cache)) {
+ if (!QPixmapCache::find(handlePixmapName, &cache)) {
cache = styleCachePixmap(handle.size());
cache.fill(Qt::transparent);
QRect pixmapRect(0, 0, handle.width(), handle.height());
@@ -3225,7 +3225,7 @@ QSize QFusionStyle::sizeFromContents(ContentsType type, const QStyleOption *opti
QFont fontBold = menuItem->font;
fontBold.setBold(true);
QFontMetrics fmBold(fontBold);
- w += fmBold.width(menuItem->text) - fm.horizontalAdvance(menuItem->text);
+ w += fmBold.horizontalAdvance(menuItem->text) - fm.horizontalAdvance(menuItem->text);
}
const int checkcol = qMax<int>(maxpmw, QStyleHelper::dpiScaled(QFusionStylePrivate::menuCheckMarkWidth)); // Windows always shows a check column
w += checkcol;
@@ -3673,7 +3673,7 @@ int QFusionStyle::styleHint(StyleHint hint, const QStyleOption *option, const QW
case SH_FontDialog_SelectAssociatedText:
case SH_MenuBar_AltKeyNavigation:
case SH_ComboBox_ListMouseTracking:
- case SH_ScrollBar_StopMouseOverSlider:
+ case SH_Slider_StopMouseOverSlider:
case SH_ScrollBar_MiddleClickAbsolutePosition:
case SH_EtchDisabledText:
case SH_TitleBar_AutoRaise:
@@ -3705,7 +3705,7 @@ int QFusionStyle::styleHint(StyleHint hint, const QStyleOption *option, const QW
return 0;
case SH_Table_GridLineColor:
- return option ? option->palette.background().color().darker(120).rgb() : 0;
+ return option ? option->palette.window().color().darker(120).rgb() : 0;
case SH_MessageBox_TextInteractionFlags:
return Qt::TextSelectableByMouse | Qt::LinksAccessibleByMouse;
diff --git a/src/widgets/styles/qfusionstyle_p_p.h b/src/widgets/styles/qfusionstyle_p_p.h
index 169fd9a407..a92041fcfe 100644
--- a/src/widgets/styles/qfusionstyle_p_p.h
+++ b/src/widgets/styles/qfusionstyle_p_p.h
@@ -113,7 +113,7 @@ public:
QColor outline(const QPalette &pal) const {
if (pal.window().style() == Qt::TexturePattern)
return QColor(0, 0, 0, 160);
- return pal.background().color().darker(140);
+ return pal.window().color().darker(140);
}
QColor highlightedOutline(const QPalette &pal) const {
diff --git a/src/widgets/styles/qstyle.h b/src/widgets/styles/qstyle.h
index 9192dae864..5ee37bd8e9 100644
--- a/src/widgets/styles/qstyle.h
+++ b/src/widgets/styles/qstyle.h
@@ -141,8 +141,10 @@ public:
PE_FrameGroupBox,
PE_FrameLineEdit,
PE_FrameMenu,
- PE_FrameStatusBar, // ### Qt 6: remove
- PE_FrameStatusBarItem = PE_FrameStatusBar,
+ PE_FrameStatusBarItem,
+#if QT_DEPRECATED_SINCE(5, 13) // ### Qt 6: remove
+ PE_FrameStatusBar Q_DECL_ENUMERATOR_DEPRECATED = PE_FrameStatusBarItem,
+#endif
PE_FrameTabWidget,
PE_FrameWindow,
PE_FrameButtonBevel,
@@ -162,8 +164,10 @@ public:
PE_IndicatorArrowUp,
PE_IndicatorBranch,
PE_IndicatorButtonDropDown,
- PE_IndicatorViewItemCheck, // ### Qt 6: remove
- PE_IndicatorItemViewItemCheck = PE_IndicatorViewItemCheck,
+ PE_IndicatorItemViewItemCheck,
+#if QT_DEPRECATED_SINCE(5, 13) // ### Qt 6: remove
+ PE_IndicatorViewItemCheck Q_DECL_ENUMERATOR_DEPRECATED = PE_IndicatorItemViewItemCheck,
+#endif
PE_IndicatorCheckBox,
PE_IndicatorDockWidgetResizeHandle,
PE_IndicatorHeaderArrow,
@@ -308,9 +312,10 @@ public:
SE_TabWidgetLeftCorner,
SE_TabWidgetRightCorner,
- SE_ViewItemCheckIndicator, // ### Qt 6: remove
- SE_ItemViewItemCheckIndicator = SE_ViewItemCheckIndicator,
-
+ SE_ItemViewItemCheckIndicator,
+#if QT_DEPRECATED_SINCE(5, 13) // ### Qt 6: remove
+ SE_ViewItemCheckIndicator Q_DECL_ENUMERATOR_DEPRECATED = SE_ItemViewItemCheckIndicator,
+#endif
SE_TabBarTearIndicator,
SE_TabBarTearIndicatorLeft = SE_TabBarTearIndicator,
@@ -506,9 +511,11 @@ public:
PM_DialogButtonsButtonHeight,
PM_MdiSubWindowFrameWidth,
- PM_MDIFrameWidth = PM_MdiSubWindowFrameWidth, // ### Qt 6: remove
PM_MdiSubWindowMinimizedWidth,
- PM_MDIMinimizedWidth = PM_MdiSubWindowMinimizedWidth, // ### Qt 6: remove
+#if QT_DEPRECATED_SINCE(5, 13) // ### Qt 6: remove
+ PM_MDIFrameWidth Q_DECL_ENUMERATOR_DEPRECATED = PM_MdiSubWindowFrameWidth,
+ PM_MDIMinimizedWidth Q_DECL_ENUMERATOR_DEPRECATED = PM_MdiSubWindowMinimizedWidth,
+#endif
PM_HeaderMargin,
PM_HeaderMarkSize,
@@ -649,7 +656,9 @@ public:
SH_ComboBox_Popup,
SH_TitleBar_NoBorder,
SH_Slider_StopMouseOverSlider,
- SH_ScrollBar_StopMouseOverSlider = SH_Slider_StopMouseOverSlider, // ### Qt 6: remove
+#if QT_DEPRECATED_SINCE(5, 13) // ### Qt 6: remove
+ SH_ScrollBar_StopMouseOverSlider Q_DECL_ENUMERATOR_DEPRECATED = SH_Slider_StopMouseOverSlider,
+#endif
SH_BlinkCursorWhenTextSelected,
SH_RichText_FullWidthSelection,
SH_Menu_Scrollable,
diff --git a/src/widgets/styles/qstyle_p.h b/src/widgets/styles/qstyle_p.h
index 94e4540d0b..cdea29f944 100644
--- a/src/widgets/styles/qstyle_p.h
+++ b/src/widgets/styles/qstyle_p.h
@@ -96,7 +96,7 @@ inline QPixmap styleCachePixmap(const QSize &size)
int txType = painter->deviceTransform().type() | painter->worldTransform().type(); \
bool doPixmapCache = (!option->rect.isEmpty()) \
&& ((txType <= QTransform::TxTranslate) || (painter->deviceTransform().type() == QTransform::TxScale)); \
- if (doPixmapCache && QPixmapCache::find(unique, internalPixmapCache)) { \
+ if (doPixmapCache && QPixmapCache::find(unique, &internalPixmapCache)) { \
painter->drawPixmap(option->rect.topLeft(), internalPixmapCache); \
} else { \
if (doPixmapCache) { \
diff --git a/src/widgets/styles/qstyleoption.cpp b/src/widgets/styles/qstyleoption.cpp
index 97631a5841..88031a9f1e 100644
--- a/src/widgets/styles/qstyleoption.cpp
+++ b/src/widgets/styles/qstyleoption.cpp
@@ -3270,7 +3270,7 @@ QStyleOptionViewItem::QStyleOptionViewItem(int version)
\fn template <typename T> T qstyleoption_cast<T>(const QStyleOption *option)
\relates QStyleOption
- Returns a T or 0 depending on the \l{QStyleOption::type}{type} and
+ Returns a T or \nullptr depending on the \l{QStyleOption::type}{type} and
\l{QStyleOption::version}{version} of the given \a option.
Example:
@@ -3285,7 +3285,7 @@ QStyleOptionViewItem::QStyleOptionViewItem(int version)
\overload
\relates QStyleOption
- Returns a T or 0 depending on the type of the given \a option.
+ Returns a T or \nullptr depending on the type of the given \a option.
*/
#if QT_CONFIG(tabwidget)
@@ -4006,7 +4006,7 @@ QStyleHintReturnVariant::~QStyleHintReturnVariant()
\fn template <typename T> T qstyleoption_cast<T>(const QStyleHintReturn *hint)
\relates QStyleHintReturn
- Returns a T or 0 depending on the \l{QStyleHintReturn::type}{type}
+ Returns a T or \nullptr depending on the \l{QStyleHintReturn::type}{type}
and \l{QStyleHintReturn::version}{version} of \a hint.
Example:
@@ -4021,7 +4021,7 @@ QStyleHintReturnVariant::~QStyleHintReturnVariant()
\overload
\relates QStyleHintReturn
- Returns a T or 0 depending on the type of \a hint.
+ Returns a T or \nullptr depending on the type of \a hint.
*/
#if !defined(QT_NO_DEBUG_STREAM)
diff --git a/src/widgets/styles/qstylesheetstyle.cpp b/src/widgets/styles/qstylesheetstyle.cpp
index 79fa20851f..c104ac2498 100644
--- a/src/widgets/styles/qstylesheetstyle.cpp
+++ b/src/widgets/styles/qstylesheetstyle.cpp
@@ -44,6 +44,7 @@
#include "private/qcssutil_p.h"
#include <qdebug.h>
+#include <qdir.h>
#include <qapplication.h>
#if QT_CONFIG(menu)
#include <qmenu.h>
@@ -957,8 +958,10 @@ QRenderRule::QRenderRule(const QVector<Declaration> &declarations, const QObject
origin = Origin_Padding;
Origin clip = Origin_Border;
if (v.extractBackground(&brush, &uri, &repeat, &alignment, &origin, &attachment, &clip)) {
- bg = new QStyleSheetBackgroundData(brush, QStyleSheetStyle::loadPixmap(uri, object),
- repeat, alignment, origin, attachment, clip);
+ QPixmap pixmap = QStyleSheetStyle::loadPixmap(uri, object);
+ if (!uri.isEmpty() && pixmap.isNull())
+ qWarning("Could not create pixmap from %s", qPrintable(QDir::toNativeSeparators(uri)));
+ bg = new QStyleSheetBackgroundData(brush, pixmap, repeat, alignment, origin, attachment, clip);
}
QBrush sfg, fg;
@@ -3243,8 +3246,8 @@ void QStyleSheetStyle::drawComplexControl(ComplexControl cc, const QStyleOptionC
#if QT_CONFIG(scrollbar)
case CC_ScrollBar:
if (const QStyleOptionSlider *sb = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
- QStyleOptionSlider sbOpt(*sb);
if (!rule.hasDrawable()) {
+ QStyleOptionSlider sbOpt(*sb);
sbOpt.rect = rule.borderRect(opt->rect);
rule.drawBackgroundImage(p, opt->rect);
baseStyle()->drawComplexControl(cc, &sbOpt, p, w);
@@ -4222,7 +4225,7 @@ void QStyleSheetStyle::drawControl(ControlElement ce, const QStyleOption *opt, Q
QString titleText = p->fontMetrics().elidedText(dwOpt->title, Qt::ElideRight, r.width());
drawItemText(p, r,
- alignment | Qt::TextShowMnemonic, dwOpt->palette,
+ alignment, dwOpt->palette,
dwOpt->state & State_Enabled, titleText,
QPalette::WindowText);
@@ -4296,7 +4299,7 @@ void QStyleSheetStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *op
switch (pe) {
- case PE_FrameStatusBar: {
+ case PE_FrameStatusBarItem: {
QRenderRule subRule = renderRule(w ? w->parentWidget() : nullptr, opt, PseudoElement_Item);
if (subRule.hasDrawable()) {
subRule.drawRule(p, opt->rect);
@@ -4317,7 +4320,7 @@ void QStyleSheetStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *op
pseudoElement = PseudoElement_ExclusiveIndicator;
break;
- case PE_IndicatorViewItemCheck:
+ case PE_IndicatorItemViewItemCheck:
pseudoElement = PseudoElement_ViewItemIndicator;
break;
@@ -5080,10 +5083,11 @@ QSize QStyleSheetStyle::sizeFromContents(ContentsType ct, const QStyleOption *op
QRenderRule subRule = renderRule(w, opt, pe);
if ((pe == PseudoElement_MenuSeparator) && subRule.hasContentsSize()) {
return QSize(sz.width(), subRule.size().height());
- } else if ((pe == PseudoElement_Item) && (subRule.hasBox() || subRule.hasBorder())) {
- int width = csz.width();
+ }
+ if ((pe == PseudoElement_Item) && (subRule.hasBox() || subRule.hasBorder() || subRule.hasFont)) {
+ QSize sz(csz);
if (mi->text.contains(QLatin1Char('\t')))
- width += 12; //as in QCommonStyle
+ sz.rwidth() += 12; //as in QCommonStyle
bool checkable = mi->checkType != QStyleOptionMenuItem::NotCheckable;
int checkableWidth = 0;
if (checkable) {
@@ -5093,15 +5097,20 @@ QSize QStyleSheetStyle::sizeFromContents(ContentsType ct, const QStyleOption *op
}
if (!mi->icon.isNull()) {
QPixmap pixmap = mi->icon.pixmap(pixelMetric(PM_SmallIconSize));
- width += pixmap.width();
+ sz.rwidth() += pixmap.width();
+ }
+ if (subRule.hasFont) {
+ QFontMetrics fm(subRule.font);
+ const QRect r = fm.boundingRect(QRect(), Qt::TextSingleLine | Qt::TextShowMnemonic, mi->text);
+ sz = sz.expandedTo(r.size());
}
// padding overrules it all
if (!subRule.hasBox() || subRule.box()->paddings[LeftEdge] == 0) {
- width += checkableWidth;
+ sz.rwidth() += checkableWidth;
if (!mi->icon.isNull() || !checkable)
- width += mi->maxIconWidth;
+ sz.rwidth() += mi->maxIconWidth;
}
- return subRule.boxSize(subRule.adjustSize(QSize(width, csz.height())));
+ return subRule.boxSize(subRule.adjustSize(sz));
}
}
break;
@@ -5772,11 +5781,10 @@ QRect QStyleSheetStyle::subElementRect(SubElement se, const QStyleOption *opt, c
case SE_PushButtonContents:
case SE_PushButtonFocusRect:
if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) {
- QStyleOptionButton btnOpt(*btn);
if (rule.hasBox() || !rule.hasNativeBorder())
return visualRect(opt->direction, opt->rect, rule.contentsRect(opt->rect));
- return rule.baseStyleCanDraw() ? baseStyle()->subElementRect(se, &btnOpt, w)
- : QWindowsStyle::subElementRect(se, &btnOpt, w);
+ return rule.baseStyleCanDraw() ? baseStyle()->subElementRect(se, btn, w)
+ : QWindowsStyle::subElementRect(se, btn, w);
}
break;
@@ -5831,7 +5839,7 @@ QRect QStyleSheetStyle::subElementRect(SubElement se, const QStyleOption *opt, c
return ParentStyle::subElementRect(se, opt, w);
#if QT_CONFIG(itemviews)
- case SE_ViewItemCheckIndicator:
+ case SE_ItemViewItemCheckIndicator:
if (!qstyleoption_cast<const QStyleOptionViewItem *>(opt)) {
return subElementRect(SE_CheckBoxIndicator, opt, w);
}
diff --git a/src/widgets/styles/qstylesheetstyle_p.h b/src/widgets/styles/qstylesheetstyle_p.h
index d4edb83525..9c4b87fc32 100644
--- a/src/widgets/styles/qstylesheetstyle_p.h
+++ b/src/widgets/styles/qstylesheetstyle_p.h
@@ -173,7 +173,7 @@ public:
static int numinstances;
private:
- Q_DISABLE_COPY(QStyleSheetStyle)
+ Q_DISABLE_COPY_MOVE(QStyleSheetStyle)
Q_DECLARE_PRIVATE(QStyleSheetStyle)
};
diff --git a/src/widgets/styles/qwindowsstyle.cpp b/src/widgets/styles/qwindowsstyle.cpp
index 12ca5201c1..4e450813cb 100644
--- a/src/widgets/styles/qwindowsstyle.cpp
+++ b/src/widgets/styles/qwindowsstyle.cpp
@@ -248,7 +248,7 @@ void QWindowsStyle::polish(QApplication *app)
d->activeGradientCaptionColor = app->palette().highlight() .color();
d->inactiveCaptionColor = app->palette().dark().color();
d->inactiveGradientCaptionColor = app->palette().dark().color();
- d->inactiveCaptionText = app->palette().background().color();
+ d->inactiveCaptionText = app->palette().window().color();
#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) //fetch native title bar colors
if(app->desktopSettingsAware()){
@@ -554,7 +554,7 @@ int QWindowsStyle::styleHint(StyleHint hint, const QStyleOption *opt, const QWid
case SH_MenuBar_MouseTracking:
case SH_Menu_MouseTracking:
case SH_ComboBox_ListMouseTracking:
- case SH_ScrollBar_StopMouseOverSlider:
+ case SH_Slider_StopMouseOverSlider:
case SH_MainWindow_SpaceBelowMenuBar:
ret = 1;
@@ -817,7 +817,7 @@ void QWindowsStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt,
else if (opt->state & State_Enabled)
fill = opt->palette.base();
else
- fill = opt->palette.background();
+ fill = opt->palette.window();
p->save();
doRestore = true;
qDrawWinPanel(p, opt->rect, opt->palette, true, &fill);
@@ -827,13 +827,13 @@ void QWindowsStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt,
p->setPen(opt->palette.text().color());
}
Q_FALLTHROUGH();
- case PE_IndicatorViewItemCheck:
+ case PE_IndicatorItemViewItemCheck:
if (!doRestore) {
p->save();
doRestore = true;
}
#if QT_CONFIG(itemviews)
- if (pe == PE_IndicatorViewItemCheck) {
+ if (pe == PE_IndicatorItemViewItemCheck) {
const QStyleOptionViewItem *itemViewOpt = qstyleoption_cast<const QStyleOptionViewItem *>(opt);
p->setPen(itemViewOpt
&& itemViewOpt->showDecorationSelected
@@ -951,14 +951,14 @@ void QWindowsStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt,
if (frame->lineWidth == 2 || pe == PE_Frame) {
QPalette popupPal = frame->palette;
if (pe == PE_FrameMenu) {
- popupPal.setColor(QPalette::Light, frame->palette.background().color());
+ popupPal.setColor(QPalette::Light, frame->palette.window().color());
popupPal.setColor(QPalette::Midlight, frame->palette.light().color());
}
if (pe == PE_Frame && (frame->state & State_Raised))
qDrawWinButton(p, frame->rect, popupPal, frame->state & State_Sunken);
else if (pe == PE_Frame && (frame->state & State_Sunken))
{
- popupPal.setColor(QPalette::Midlight, frame->palette.background().color());
+ popupPal.setColor(QPalette::Midlight, frame->palette.window().color());
qDrawWinPanel(p, frame->rect, popupPal, frame->state & State_Sunken);
}
else
@@ -968,7 +968,7 @@ void QWindowsStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt,
}
} else {
QPalette popupPal = opt->palette;
- popupPal.setColor(QPalette::Light, opt->palette.background().color());
+ popupPal.setColor(QPalette::Light, opt->palette.window().color());
popupPal.setColor(QPalette::Midlight, opt->palette.light().color());
qDrawWinPanel(p, opt->rect, popupPal, opt->state & State_Sunken);
}
@@ -996,7 +996,7 @@ void QWindowsStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt,
break; }
case PE_FrameWindow: {
QPalette popupPal = opt->palette;
- popupPal.setColor(QPalette::Light, opt->palette.background().color());
+ popupPal.setColor(QPalette::Light, opt->palette.window().color());
popupPal.setColor(QPalette::Midlight, opt->palette.light().color());
qDrawWinPanel(p, opt->rect, popupPal, opt->state & State_Sunken);
break; }
@@ -1315,12 +1315,12 @@ void QWindowsStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPai
x2 -= onlyOne || lastTab ? borderThinkness : 0;
}
- p->fillRect(QRect(x1 + 1, y1 + 1, (x2 - x1) - 1, (y2 - y1) - 2), tab->palette.background());
+ p->fillRect(QRect(x1 + 1, y1 + 1, (x2 - x1) - 1, (y2 - y1) - 2), tab->palette.window());
// Delete border
if (selected) {
- p->fillRect(QRect(x1,y2-1,x2-x1,1), tab->palette.background());
- p->fillRect(QRect(x1,y2,x2-x1,1), tab->palette.background());
+ p->fillRect(QRect(x1,y2-1,x2-x1,1), tab->palette.window());
+ p->fillRect(QRect(x1,y2,x2-x1,1), tab->palette.window());
}
// Left
if (firstTab || selected || onlyOne || !previousSelected) {
@@ -1351,12 +1351,12 @@ void QWindowsStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPai
x2 -= lastTab ? borderThinkness : 0;
}
- p->fillRect(QRect(x1 + 1, y1 + 2, (x2 - x1) - 1, (y2 - y1) - 1), tab->palette.background());
+ p->fillRect(QRect(x1 + 1, y1 + 2, (x2 - x1) - 1, (y2 - y1) - 1), tab->palette.window());
// Delete border
if (selected) {
- p->fillRect(QRect(x1, y1 + 1, (x2 - 1)-x1, 1), tab->palette.background());
- p->fillRect(QRect(x1, y1, (x2 - 1)-x1, 1), tab->palette.background());
+ p->fillRect(QRect(x1, y1 + 1, (x2 - 1)-x1, 1), tab->palette.window());
+ p->fillRect(QRect(x1, y1, (x2 - 1)-x1, 1), tab->palette.window());
}
// Left
if (firstTab || selected || onlyOne || !previousSelected) {
@@ -1389,12 +1389,12 @@ void QWindowsStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPai
y2 -= lastTab ? borderThinkness : 0;
}
- p->fillRect(QRect(x1 + 1, y1 + 1, (x2 - x1) - 2, (y2 - y1) - 1), tab->palette.background());
+ p->fillRect(QRect(x1 + 1, y1 + 1, (x2 - x1) - 2, (y2 - y1) - 1), tab->palette.window());
// Delete border
if (selected) {
- p->fillRect(QRect(x2 - 1, y1, 1, y2-y1), tab->palette.background());
- p->fillRect(QRect(x2, y1, 1, y2-y1), tab->palette.background());
+ p->fillRect(QRect(x2 - 1, y1, 1, y2-y1), tab->palette.window());
+ p->fillRect(QRect(x2, y1, 1, y2-y1), tab->palette.window());
}
// Top
if (firstTab || selected || onlyOne || !previousSelected) {
@@ -1427,12 +1427,12 @@ void QWindowsStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPai
y2 -= lastTab ? borderThinkness : 0;
}
- p->fillRect(QRect(x1 + 2, y1 + 1, (x2 - x1) - 1, (y2 - y1) - 1), tab->palette.background());
+ p->fillRect(QRect(x1 + 2, y1 + 1, (x2 - x1) - 1, (y2 - y1) - 1), tab->palette.window());
// Delete border
if (selected) {
- p->fillRect(QRect(x1 + 1, y1, 1, (y2 - 1)-y1),tab->palette.background());
- p->fillRect(QRect(x1, y1, 1, (y2-1)-y1), tab->palette.background());
+ p->fillRect(QRect(x1 + 1, y1, 1, (y2 - 1)-y1),tab->palette.window());
+ p->fillRect(QRect(x1, y1, 1, (y2-1)-y1), tab->palette.window());
}
// Top
if (firstTab || selected || onlyOne || !previousSelected) {
@@ -1526,7 +1526,7 @@ void QWindowsStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPai
br = QBrush(paletteBrush.textureImage());
} else
br = QBrush(opt->palette.light().color(), Qt::Dense4Pattern);
- p->setBackground(opt->palette.background().color());
+ p->setBackground(opt->palette.window().color());
p->setBrush(br);
}
p->drawRect(opt->rect);
@@ -1693,7 +1693,7 @@ void QWindowsStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPai
}
QPalette pal2 = pb->palette;
// Correct the highlight color if it is the same as the background
- if (pal2.highlight() == pal2.background())
+ if (pal2.highlight() == pal2.window())
pal2.setColor(QPalette::Highlight, pb->palette.color(QPalette::Active,
QPalette::Highlight));
bool reverse = ((!vertical && (pb->direction == Qt::RightToLeft)) || vertical);
@@ -1825,7 +1825,7 @@ void QWindowsStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPai
titleRect.height(), titleRect.width());
}
proxy()->drawItemText(p, titleRect,
- Qt::AlignLeft | Qt::AlignVCenter | Qt::TextShowMnemonic, palette,
+ Qt::AlignLeft | Qt::AlignVCenter, palette,
dwOpt->state & State_Enabled, dwOpt->title,
floating ? (active ? QPalette::BrightText : QPalette::Window) : QPalette::WindowText);
p->setFont(oldFont);
@@ -1843,7 +1843,7 @@ void QWindowsStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPai
p->setBackground(cb->palette.highlight());
} else {
p->setPen(cb->palette.text().color());
- p->setBackground(cb->palette.background());
+ p->setBackground(cb->palette.window());
}
}
QCommonStyle::drawControl(ce, opt, p, widget);
@@ -2185,7 +2185,7 @@ void QWindowsStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComp
} else {
p->setPen(cmb->palette.text().color());
- p->setBackground(cmb->palette.background());
+ p->setBackground(cmb->palette.window());
}
if (cmb->state & State_HasFocus && !cmb->editable) {
diff --git a/src/widgets/styles/qwindowsstyle_p.h b/src/widgets/styles/qwindowsstyle_p.h
index 7993b9f1c6..47816ff651 100644
--- a/src/widgets/styles/qwindowsstyle_p.h
+++ b/src/widgets/styles/qwindowsstyle_p.h
@@ -102,7 +102,7 @@ protected:
QWindowsStyle(QWindowsStylePrivate &dd);
private:
- Q_DISABLE_COPY(QWindowsStyle)
+ Q_DISABLE_COPY_MOVE(QWindowsStyle)
Q_DECLARE_PRIVATE(QWindowsStyle)
};
diff --git a/src/widgets/util/qcompleter_p.h b/src/widgets/util/qcompleter_p.h
index 765363744b..21dddf446e 100644
--- a/src/widgets/util/qcompleter_p.h
+++ b/src/widgets/util/qcompleter_p.h
@@ -194,6 +194,7 @@ private:
const QIndexMapper& iv, QMatchData* m);
};
+// ### Qt6: QStyledItemDelegate
class QCompleterItemDelegate : public QItemDelegate
{
public:
diff --git a/src/widgets/util/qflickgesture.cpp b/src/widgets/util/qflickgesture.cpp
index b59fe0d504..a8b2a00a80 100644
--- a/src/widgets/util/qflickgesture.cpp
+++ b/src/widgets/util/qflickgesture.cpp
@@ -130,8 +130,6 @@ private:
, mouseEventSource(Qt::MouseEventNotSynthesized)
{ }
- static PressDelayHandler *inst;
-
public:
enum {
UngrabMouseBefore = 1,
diff --git a/src/widgets/util/qflickgesture_p.h b/src/widgets/util/qflickgesture_p.h
index 74a0f2a0f3..d5ace887ae 100644
--- a/src/widgets/util/qflickgesture_p.h
+++ b/src/widgets/util/qflickgesture_p.h
@@ -77,8 +77,6 @@ public:
friend class QFlickGestureRecognizer;
};
-class PressDelayHandler;
-
class QFlickGesturePrivate : public QGesturePrivate
{
Q_DECLARE_PUBLIC(QFlickGesture)
@@ -89,7 +87,6 @@ public:
QScroller *receiverScroller;
Qt::MouseButton button; // NoButton == Touch
bool macIgnoreWheel;
- static PressDelayHandler *pressDelayHandler;
};
class QFlickGestureRecognizer : public QGestureRecognizer
diff --git a/src/widgets/util/qsystemtrayicon.cpp b/src/widgets/util/qsystemtrayicon.cpp
index d15f5e5955..a38a50d3df 100644
--- a/src/widgets/util/qsystemtrayicon.cpp
+++ b/src/widgets/util/qsystemtrayicon.cpp
@@ -574,7 +574,7 @@ QBalloonTip::QBalloonTip(const QIcon &icon, const QString &title,
layout->addWidget(msgLabel, 1, 0, 1, 3);
#endif
layout->setSizeConstraint(QLayout::SetFixedSize);
- layout->setMargin(3);
+ layout->setContentsMargins(3, 3, 3, 3);
setLayout(layout);
QPalette pal = palette();
diff --git a/src/widgets/util/qundostack.cpp b/src/widgets/util/qundostack.cpp
index e928b9fe37..8788c42252 100644
--- a/src/widgets/util/qundostack.cpp
+++ b/src/widgets/util/qundostack.cpp
@@ -102,9 +102,9 @@ QT_BEGIN_NAMESPACE
/*!
Constructs a QUndoCommand object with the given \a parent and \a text.
- If \a parent is not 0, this command is appended to parent's child list.
- The parent command then owns this command and will delete it in its
- destructor.
+ If \a parent is not \nullptr, this command is appended to parent's
+ child list. The parent command then owns this command and will delete
+ it in its destructor.
\sa ~QUndoCommand()
*/
@@ -118,9 +118,9 @@ QUndoCommand::QUndoCommand(const QString &text, QUndoCommand *parent)
/*!
Constructs a QUndoCommand object with parent \a parent.
- If \a parent is not 0, this command is appended to parent's child list.
- The parent command then owns this command and will delete it in its
- destructor.
+ If \a parent is not \nullptr, this command is appended to parent's
+ child list. The parent command then owns this command and will delete
+ it in its destructor.
\sa ~QUndoCommand()
*/
diff --git a/src/widgets/widgets/qabstractscrollarea.cpp b/src/widgets/widgets/qabstractscrollarea.cpp
index 598d173144..5ea8330db2 100644
--- a/src/widgets/widgets/qabstractscrollarea.cpp
+++ b/src/widgets/widgets/qabstractscrollarea.cpp
@@ -185,7 +185,7 @@ QAbstractScrollAreaScrollBarContainer::QAbstractScrollAreaScrollBarContainer(Qt:
orientation(orientation)
{
setLayout(layout);
- layout->setMargin(0);
+ layout->setContentsMargins(QMargins());
layout->setSpacing(0);
layout->addWidget(scrollBar);
layout->setSizeConstraint(QLayout::SetMaximumSize);
@@ -820,7 +820,7 @@ QWidget *QAbstractScrollArea::cornerWidget() const
All widgets set here will be deleted by the scroll area when it is
destroyed unless you separately reparent the widget after setting
- some other corner widget (or 0).
+ some other corner widget (or \nullptr).
Any \e newly set widget should have no current parent.
@@ -1604,8 +1604,10 @@ QSize QAbstractScrollArea::sizeHint() const
if (!d->sizeHint.isValid() || d->sizeAdjustPolicy == QAbstractScrollArea::AdjustToContents) {
const int f = 2 * d->frameWidth;
const QSize frame( f, f );
- const QSize scrollbars(d->vbarpolicy == Qt::ScrollBarAlwaysOn ? d->vbar->sizeHint().width() : 0,
- d->hbarpolicy == Qt::ScrollBarAlwaysOn ? d->hbar->sizeHint().height() : 0);
+ const bool vbarHidden = d->vbar->isHidden() || d->vbarpolicy == Qt::ScrollBarAlwaysOff;
+ const bool hbarHidden = d->hbar->isHidden() || d->hbarpolicy == Qt::ScrollBarAlwaysOff;
+ const QSize scrollbars(vbarHidden ? 0 : d->vbar->sizeHint().width(),
+ hbarHidden ? 0 : d->hbar->sizeHint().height());
d->sizeHint = frame + scrollbars + viewportSizeHint();
}
return d->sizeHint;
diff --git a/src/widgets/widgets/qabstractspinbox.cpp b/src/widgets/widgets/qabstractspinbox.cpp
index 00ac5034e9..6edefaa311 100644
--- a/src/widgets/widgets/qabstractspinbox.cpp
+++ b/src/widgets/widgets/qabstractspinbox.cpp
@@ -688,7 +688,7 @@ QLineEdit *QAbstractSpinBox::lineEdit() const
\fn void QAbstractSpinBox::setLineEdit(QLineEdit *lineEdit)
Sets the line edit of the spinbox to be \a lineEdit instead of the
- current line edit widget. \a lineEdit can not be 0.
+ current line edit widget. \a lineEdit cannot be \nullptr.
QAbstractSpinBox takes ownership of the new lineEdit
diff --git a/src/widgets/widgets/qbuttongroup.cpp b/src/widgets/widgets/qbuttongroup.cpp
index fa1ccd347f..669faa92c7 100644
--- a/src/widgets/widgets/qbuttongroup.cpp
+++ b/src/widgets/widgets/qbuttongroup.cpp
@@ -291,8 +291,8 @@ QList<QAbstractButton*> QButtonGroup::buttons() const
}
/*!
- Returns the button group's checked button, or 0 if no buttons are
- checked.
+ Returns the button group's checked button, or \nullptr if no
+ buttons are checked.
\sa buttonClicked()
*/
@@ -305,8 +305,8 @@ QAbstractButton *QButtonGroup::checkedButton() const
/*!
\since 4.1
- Returns the button with the specified \a id, or 0 if no such button
- exists.
+ Returns the button with the specified \a id, or \nullptr if no
+ such button exists.
*/
QAbstractButton *QButtonGroup::button(int id) const
{
diff --git a/src/widgets/widgets/qcalendarwidget.cpp b/src/widgets/widgets/qcalendarwidget.cpp
index 2ff383d9c7..47c5267c73 100644
--- a/src/widgets/widgets/qcalendarwidget.cpp
+++ b/src/widgets/widgets/qcalendarwidget.cpp
@@ -1178,9 +1178,9 @@ QVariant QCalendarModel::data(const QModelIndex &index, int role) const
}
QTextCharFormat fmt = formatForCell(row, column);
- if (role == Qt::BackgroundColorRole)
+ if (role == Qt::BackgroundRole)
return fmt.background().color();
- if (role == Qt::TextColorRole)
+ if (role == Qt::ForegroundRole)
return fmt.foreground().color();
if (role == Qt::FontRole)
return fmt.font();
@@ -1555,6 +1555,7 @@ void QCalendarView::mouseReleaseEvent(QMouseEvent *event)
}
}
+// ### Qt6: QStyledItemDelegate
class QCalendarDelegate : public QItemDelegate
{
Q_OBJECT
@@ -1777,7 +1778,7 @@ void QCalendarWidgetPrivate::createNavigationBar(QWidget *widget)
spaceHolder = new QSpacerItem(0,0);
QHBoxLayout *headerLayout = new QHBoxLayout;
- headerLayout->setMargin(0);
+ headerLayout->setContentsMargins(QMargins());
headerLayout->setSpacing(0);
headerLayout->addWidget(prevMonth);
headerLayout->insertStretch(headerLayout->count());
@@ -2100,7 +2101,7 @@ QCalendarWidget::QCalendarWidget(QWidget *parent)
setBackgroundRole(QPalette::Window);
QVBoxLayout *layoutV = new QVBoxLayout(this);
- layoutV->setMargin(0);
+ layoutV->setContentsMargins(QMargins());
d->m_model = new QCalendarModel(this);
QTextCharFormat fmt;
fmt.setForeground(QBrush(Qt::red));
@@ -2147,7 +2148,7 @@ QCalendarWidget::QCalendarWidget(QWidget *parent)
connect(d->yearEdit, SIGNAL(editingFinished()),
this, SLOT(_q_yearEditingFinished()));
- layoutV->setMargin(0);
+ layoutV->setContentsMargins(QMargins());
layoutV->setSpacing(0);
layoutV->addWidget(d->navBarBackground);
layoutV->addWidget(d->m_view);
diff --git a/src/widgets/widgets/qcombobox.cpp b/src/widgets/widgets/qcombobox.cpp
index e20a0892b4..e38e1d7750 100644
--- a/src/widgets/widgets/qcombobox.cpp
+++ b/src/widgets/widgets/qcombobox.cpp
@@ -166,7 +166,7 @@ QStyleOptionMenuItem QComboMenuDelegate::getStyleOption(const QStyleOptionViewIt
break;
}
if (index.data(Qt::BackgroundRole).canConvert<QBrush>()) {
- menuOption.palette.setBrush(QPalette::All, QPalette::Background,
+ menuOption.palette.setBrush(QPalette::All, QPalette::Window,
qvariant_cast<QBrush>(index.data(Qt::BackgroundRole)));
}
menuOption.text = index.model()->data(index, Qt::DisplayRole).toString()
@@ -472,7 +472,7 @@ QComboBoxPrivateContainer::QComboBoxPrivateContainer(QAbstractItemView *itemView
// we need a vertical layout
QBoxLayout *layout = new QBoxLayout(QBoxLayout::TopToBottom, this);
layout->setSpacing(0);
- layout->setMargin(0);
+ layout->setContentsMargins(QMargins());
// set item view
setItemView(itemView);
@@ -895,14 +895,21 @@ QStyleOptionComboBox QComboBoxPrivateContainer::comboStyleOption() const
currentIndex was reset.
*/
+#if QT_DEPRECATED_SINCE(5, 13)
/*!
\fn void QComboBox::currentIndexChanged(const QString &text)
\since 4.1
+ \obsolete
+
+ Use currentTextChanged(const QString &) or currentIndexChanged(int)
+ instead.
+
This signal is sent whenever the currentIndex in the combobox
changes either through user interaction or programmatically. The
item's \a text is passed.
*/
+#endif
/*!
\fn void QComboBox::currentTextChanged(const QString &text)
@@ -1375,7 +1382,12 @@ void QComboBoxPrivate::_q_emitCurrentIndexChanged(const QModelIndex &index)
Q_Q(QComboBox);
const QString text = itemText(index);
emit q->currentIndexChanged(index.row());
+#if QT_DEPRECATED_SINCE(5, 13)
+ QT_WARNING_PUSH
+ QT_WARNING_DISABLE_DEPRECATED
emit q->currentIndexChanged(text);
+ QT_WARNING_POP
+#endif
// signal lineEdit.textChanged already connected to signal currentTextChanged, so don't emit double here
if (!lineEdit)
emit q->currentTextChanged(text);
@@ -1483,6 +1495,7 @@ int QComboBox::maxCount() const
}
#if QT_CONFIG(completer)
+#if QT_DEPRECATED_SINCE(5, 13)
/*!
\property QComboBox::autoCompletion
@@ -1576,6 +1589,7 @@ void QComboBox::setAutoCompletionCaseSensitivity(Qt::CaseSensitivity sensitivity
if (d->lineEdit && d->lineEdit->completer())
d->lineEdit->completer()->setCaseSensitivity(sensitivity);
}
+#endif // QT_DEPRECATED_SINCE(5, 13)
#endif // QT_CONFIG(completer)
@@ -1888,8 +1902,8 @@ void QComboBox::setLineEdit(QLineEdit *edit)
}
/*!
- Returns the line edit used to edit items in the combobox, or 0 if there
- is no line edit.
+ Returns the line edit used to edit items in the combobox, or
+ \nullptr if there is no line edit.
Only editable combo boxes have a line edit.
*/
@@ -1941,12 +1955,15 @@ const QValidator *QComboBox::validator() const
performs case insensitive inline completion is automatically created.
\note The completer is removed when the \l editable property becomes \c false.
+ Setting a completer on a QComboBox that is not editable will be ignored.
*/
void QComboBox::setCompleter(QCompleter *c)
{
Q_D(QComboBox);
- if (!d->lineEdit)
+ if (!d->lineEdit) {
+ qWarning("Setting a QCompleter on non-editable QComboBox is not allowed.");
return;
+ }
d->lineEdit->setCompleter(c);
if (c) {
connect(c, SIGNAL(activated(QModelIndex)), this, SLOT(_q_completerActivated(QModelIndex)));
@@ -2017,7 +2034,7 @@ QAbstractItemModel *QComboBox::model() const
}
/*!
- Sets the model to be \a model. \a model must not be 0.
+ Sets the model to be \a model. \a model must not be \nullptr.
If you want to clear the contents of a model, call clear().
\sa clear()
diff --git a/src/widgets/widgets/qcombobox.h b/src/widgets/widgets/qcombobox.h
index 671c883584..64fbebb3c5 100644
--- a/src/widgets/widgets/qcombobox.h
+++ b/src/widgets/widgets/qcombobox.h
@@ -73,8 +73,10 @@ class Q_WIDGETS_EXPORT QComboBox : public QWidget
Q_PROPERTY(QSize iconSize READ iconSize WRITE setIconSize)
#if QT_CONFIG(completer)
+#if QT_DEPRECATED_SINCE(5, 13)
Q_PROPERTY(bool autoCompletion READ autoCompletion WRITE setAutoCompletion DESIGNABLE false)
Q_PROPERTY(Qt::CaseSensitivity autoCompletionCaseSensitivity READ autoCompletionCaseSensitivity WRITE setAutoCompletionCaseSensitivity DESIGNABLE false)
+#endif
#endif // QT_CONFIG(completer)
Q_PROPERTY(bool duplicatesEnabled READ duplicatesEnabled WRITE setDuplicatesEnabled)
@@ -93,12 +95,14 @@ public:
int maxCount() const;
#if QT_CONFIG(completer)
+#if QT_DEPRECATED_SINCE(5, 13)
bool autoCompletion() const;
void setAutoCompletion(bool enable);
Qt::CaseSensitivity autoCompletionCaseSensitivity() const;
void setAutoCompletionCaseSensitivity(Qt::CaseSensitivity sensitivity);
#endif
+#endif
bool duplicatesEnabled() const;
void setDuplicatesEnabled(bool enable);
@@ -220,7 +224,10 @@ Q_SIGNALS:
void highlighted(int index);
void highlighted(const QString &);
void currentIndexChanged(int index);
+#if QT_DEPRECATED_SINCE(5, 13)
+ QT_DEPRECATED_X("Use currentTextChanged() instead")
void currentIndexChanged(const QString &);
+#endif
void currentTextChanged(const QString &);
protected:
diff --git a/src/widgets/widgets/qcombobox_p.h b/src/widgets/widgets/qcombobox_p.h
index 3f75a357e4..71404964da 100644
--- a/src/widgets/widgets/qcombobox_p.h
+++ b/src/widgets/widgets/qcombobox_p.h
@@ -277,7 +277,7 @@ protected:
const QStyleOptionViewItem &option,
const QModelIndex &index) const override {
QStyleOptionMenuItem opt = getStyleOption(option, index);
- painter->fillRect(option.rect, opt.palette.background());
+ painter->fillRect(option.rect, opt.palette.window());
mCombo->style()->drawControl(QStyle::CE_MenuItem, &opt, painter, mCombo);
}
QSize sizeHint(const QStyleOptionViewItem &option,
@@ -293,6 +293,7 @@ private:
QComboBox *mCombo;
};
+// ### Qt6: QStyledItemDelegate ?
// Note that this class is intentionally not using QStyledItemDelegate
// Vista does not use the new theme for combo boxes and there might
// be other side effects from using the new class
diff --git a/src/widgets/widgets/qcommandlinkbutton.h b/src/widgets/widgets/qcommandlinkbutton.h
index 2d01d63df8..3d2dd5784d 100644
--- a/src/widgets/widgets/qcommandlinkbutton.h
+++ b/src/widgets/widgets/qcommandlinkbutton.h
@@ -66,10 +66,16 @@ public:
QString description() const;
void setDescription(const QString &description);
+ // QTBUG-68722
+#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
protected:
+#else
+public:
+#endif
QSize sizeHint() const override;
int heightForWidth(int) const override;
QSize minimumSizeHint() const override;
+protected:
bool event(QEvent *e) override;
void paintEvent(QPaintEvent *) override;
diff --git a/src/widgets/widgets/qdatetimeedit.cpp b/src/widgets/widgets/qdatetimeedit.cpp
index 41d9faa5c2..b874e4e3a9 100644
--- a/src/widgets/widgets/qdatetimeedit.cpp
+++ b/src/widgets/widgets/qdatetimeedit.cpp
@@ -2599,7 +2599,7 @@ void QCalendarPopup::setCalendarWidget(QCalendarWidget *cw)
QVBoxLayout *widgetLayout = qobject_cast<QVBoxLayout*>(layout());
if (!widgetLayout) {
widgetLayout = new QVBoxLayout(this);
- widgetLayout->setMargin(0);
+ widgetLayout->setContentsMargins(QMargins());
widgetLayout->setSpacing(0);
}
delete calendar.data();
diff --git a/src/widgets/widgets/qdialogbuttonbox.cpp b/src/widgets/widgets/qdialogbuttonbox.cpp
index d93e71e32f..26b86f80be 100644
--- a/src/widgets/widgets/qdialogbuttonbox.cpp
+++ b/src/widgets/widgets/qdialogbuttonbox.cpp
@@ -820,7 +820,7 @@ QDialogButtonBox::StandardButtons QDialogButtonBox::standardButtons() const
/*!
Returns the QPushButton corresponding to the standard button \a which,
- or 0 if the standard button doesn't exist in this button box.
+ or \nullptr if the standard button doesn't exist in this button box.
\sa standardButton(), standardButtons(), buttons()
*/
diff --git a/src/widgets/widgets/qdockwidget.cpp b/src/widgets/widgets/qdockwidget.cpp
index 6c871aae2c..ba8bd90da6 100644
--- a/src/widgets/widgets/qdockwidget.cpp
+++ b/src/widgets/widgets/qdockwidget.cpp
@@ -55,6 +55,7 @@
#include <private/qwidgetresizehandler_p.h>
#include <private/qstylesheetstyle_p.h>
+#include <qpa/qplatformtheme.h>
#include "qdockwidget_p.h"
#include "qmainwindowlayout_p.h"
@@ -922,7 +923,8 @@ bool QDockWidgetPrivate::mousePressEvent(QMouseEvent *event)
initDrag(event->pos(), false);
if (state)
- state->ctrlDrag = hasFeature(this, QDockWidget::DockWidgetFloatable) && event->modifiers() & Qt::ControlModifier;
+ state->ctrlDrag = (hasFeature(this, QDockWidget::DockWidgetFloatable) && event->modifiers() & Qt::ControlModifier) ||
+ (!hasFeature(this, QDockWidget::DockWidgetMovable) && q->isFloating());
return true;
}
@@ -1044,7 +1046,8 @@ void QDockWidgetPrivate::nonClientAreaMouseEvent(QMouseEvent *event)
initDrag(event->pos(), true);
if (state == 0)
break;
- state->ctrlDrag = event->modifiers() & Qt::ControlModifier;
+ state->ctrlDrag = (event->modifiers() & Qt::ControlModifier) ||
+ (!hasFeature(this, QDockWidget::DockWidgetMovable) && q->isFloating());
startDrag();
break;
case QEvent::NonClientAreaMouseMove:
@@ -1729,8 +1732,8 @@ void QDockWidget::setTitleBarWidget(QWidget *widget)
/*!
\since 4.3
- Returns the custom title bar widget set on the QDockWidget, or 0 if no
- custom title bar has been set.
+ Returns the custom title bar widget set on the QDockWidget, or
+ \nullptr if no custom title bar has been set.
\sa setTitleBarWidget()
*/
diff --git a/src/widgets/widgets/qdockwidget_p.h b/src/widgets/widgets/qdockwidget_p.h
index 766e4ed161..14d73e815f 100644
--- a/src/widgets/widgets/qdockwidget_p.h
+++ b/src/widgets/widgets/qdockwidget_p.h
@@ -108,6 +108,7 @@ public:
// QMainWindow *findMainWindow(QWidget *widget) const;
QRect undockedGeometry;
QString fixedWindowTitle;
+ QString dockedWindowTitle;
bool mousePressEvent(QMouseEvent *event);
bool mouseDoubleClickEvent(QMouseEvent *event);
diff --git a/src/widgets/widgets/qfontcombobox.cpp b/src/widgets/widgets/qfontcombobox.cpp
index 957a464b71..4a99b0f962 100644
--- a/src/widgets/widgets/qfontcombobox.cpp
+++ b/src/widgets/widgets/qfontcombobox.cpp
@@ -236,9 +236,10 @@ void QFontFamilyDelegate::paint(QPainter *painter,
if (QFontDatabase().isSmoothlyScalable(text)) {
icon = &truetype;
}
- QSize actualSize = icon->actualSize(r.size());
-
- icon->paint(painter, r, Qt::AlignLeft|Qt::AlignVCenter);
+ const QSize actualSize = icon->actualSize(r.size());
+ const QRect iconRect = QStyle::alignedRect(option.direction, option.displayAlignment,
+ actualSize, r);
+ icon->paint(painter, iconRect, Qt::AlignLeft|Qt::AlignVCenter);
if (option.direction == Qt::RightToLeft)
r.setRight(r.right() - actualSize.width() - 4);
else
@@ -247,6 +248,7 @@ void QFontFamilyDelegate::paint(QPainter *painter,
QFont old = painter->font();
painter->setFont(font);
+ const Qt::Alignment textAlign = QStyle::visualAlignment(option.direction, option.displayAlignment);
// If the ascent of the font is larger than the height of the rect,
// we will clip the text, so it's better to align the tight bounding rect in this case
// This is specifically for fonts where the ascent is very large compared to
@@ -254,9 +256,11 @@ void QFontFamilyDelegate::paint(QPainter *painter,
QFontMetricsF fontMetrics(font);
if (fontMetrics.ascent() > r.height()) {
QRectF tbr = fontMetrics.tightBoundingRect(text);
- painter->drawText(r.x(), r.y() + (r.height() + tbr.height()) / 2.0, text);
+ QRect textRect(r);
+ textRect.setHeight(textRect.height() + (r.height() - tbr.height()));
+ painter->drawText(textRect, Qt::AlignBottom|Qt::TextSingleLine|textAlign, text);
} else {
- painter->drawText(r, Qt::AlignVCenter|Qt::AlignLeading|Qt::TextSingleLine, text);
+ painter->drawText(r, Qt::AlignVCenter|Qt::TextSingleLine|textAlign, text);
}
if (writingSystem != QFontDatabase::Any)
@@ -270,7 +274,7 @@ void QFontFamilyDelegate::paint(QPainter *painter,
r.setRight(r.right() - w);
else
r.setLeft(r.left() + w);
- painter->drawText(r, Qt::AlignVCenter|Qt::AlignLeading|Qt::TextSingleLine, sample);
+ painter->drawText(r, Qt::AlignVCenter|Qt::TextSingleLine|textAlign, sample);
}
painter->setFont(old);
diff --git a/src/widgets/widgets/qlabel.cpp b/src/widgets/widgets/qlabel.cpp
index 60f88df9af..a840bf4ee6 100644
--- a/src/widgets/widgets/qlabel.cpp
+++ b/src/widgets/widgets/qlabel.cpp
@@ -1098,7 +1098,7 @@ void QLabel::paintEvent(QPaintEvent *)
QImage scaledImage =
d->cachedimage->scaled(scaledSize,
Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
- d->scaledpixmap = new QPixmap(QPixmap::fromImage(scaledImage));
+ d->scaledpixmap = new QPixmap(QPixmap::fromImage(std::move(scaledImage)));
d->scaledpixmap->setDevicePixelRatio(devicePixelRatioF());
}
pix = *d->scaledpixmap;
diff --git a/src/widgets/widgets/qlineedit.cpp b/src/widgets/widgets/qlineedit.cpp
index 4301a3a2e7..ad3d372bd3 100644
--- a/src/widgets/widgets/qlineedit.cpp
+++ b/src/widgets/widgets/qlineedit.cpp
@@ -586,7 +586,7 @@ void QLineEdit::setEchoMode(EchoMode mode)
#ifndef QT_NO_VALIDATOR
/*!
- Returns a pointer to the current input validator, or 0 if no
+ Returns a pointer to the current input validator, or \nullptr if no
validator has been set.
\sa setValidator()
diff --git a/src/widgets/widgets/qlineedit_p.cpp b/src/widgets/widgets/qlineedit_p.cpp
index 6dcb2dd693..2a5a0c34dc 100644
--- a/src/widgets/widgets/qlineedit_p.cpp
+++ b/src/widgets/widgets/qlineedit_p.cpp
@@ -324,7 +324,7 @@ void QLineEditPrivate::drag()
data->setText(control->selectedText());
QDrag *drag = new QDrag(q);
drag->setMimeData(data);
- Qt::DropAction action = drag->start();
+ Qt::DropAction action = drag->exec(Qt::CopyAction);
if (action == Qt::MoveAction && !control->isReadOnly() && drag->target() != q)
control->removeSelection();
}
diff --git a/src/widgets/widgets/qmainwindow.cpp b/src/widgets/widgets/qmainwindow.cpp
index 411b482c11..fae3aebba4 100644
--- a/src/widgets/widgets/qmainwindow.cpp
+++ b/src/widgets/widgets/qmainwindow.cpp
@@ -851,7 +851,11 @@ void QMainWindow::removeToolBar(QToolBar *toolbar)
\sa addToolBar(), addToolBarBreak(), Qt::ToolBarArea
*/
-Qt::ToolBarArea QMainWindow::toolBarArea(QToolBar *toolbar) const
+Qt::ToolBarArea QMainWindow::toolBarArea(
+#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
+ const
+#endif
+ QToolBar *toolbar) const
{ return d_func()->layout->toolBarArea(toolbar); }
/*!
diff --git a/src/widgets/widgets/qmainwindow.h b/src/widgets/widgets/qmainwindow.h
index 8f2a192446..85e3f87d77 100644
--- a/src/widgets/widgets/qmainwindow.h
+++ b/src/widgets/widgets/qmainwindow.h
@@ -158,7 +158,11 @@ public:
bool unifiedTitleAndToolBarOnMac() const;
- Qt::ToolBarArea toolBarArea(QToolBar *toolbar) const;
+ Qt::ToolBarArea toolBarArea(
+#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
+ const
+#endif
+ QToolBar *toolbar) const;
bool toolBarBreak(QToolBar *toolbar) const;
#endif
#if QT_CONFIG(dockwidget)
diff --git a/src/widgets/widgets/qmainwindowlayout.cpp b/src/widgets/widgets/qmainwindowlayout.cpp
index 053bfbf024..ed054c7e9a 100644
--- a/src/widgets/widgets/qmainwindowlayout.cpp
+++ b/src/widgets/widgets/qmainwindowlayout.cpp
@@ -1388,7 +1388,7 @@ void QMainWindowLayout::insertToolBar(QToolBar *before, QToolBar *toolbar)
invalidate();
}
-Qt::ToolBarArea QMainWindowLayout::toolBarArea(QToolBar *toolbar) const
+Qt::ToolBarArea QMainWindowLayout::toolBarArea(const QToolBar *toolbar) const
{
QInternal::DockPosition pos = layoutState.toolBarAreaLayout.findToolBar(toolbar);
switch (pos) {
diff --git a/src/widgets/widgets/qmainwindowlayout_p.h b/src/widgets/widgets/qmainwindowlayout_p.h
index 72cbec2350..a375d856bb 100644
--- a/src/widgets/widgets/qmainwindowlayout_p.h
+++ b/src/widgets/widgets/qmainwindowlayout_p.h
@@ -475,7 +475,7 @@ public:
void addToolBar(Qt::ToolBarArea area, QToolBar *toolbar, bool needAddChildWidget = true);
void insertToolBar(QToolBar *before, QToolBar *toolbar);
- Qt::ToolBarArea toolBarArea(QToolBar *toolbar) const;
+ Qt::ToolBarArea toolBarArea(const QToolBar *toolbar) const;
bool toolBarBreak(QToolBar *toolBar) const;
void getStyleOptionInfo(QStyleOptionToolBar *option, QToolBar *toolBar) const;
void removeToolBar(QToolBar *toolbar);
diff --git a/src/widgets/widgets/qmdiarea.cpp b/src/widgets/widgets/qmdiarea.cpp
index f32cd26478..feea7cd050 100644
--- a/src/widgets/widgets/qmdiarea.cpp
+++ b/src/widgets/widgets/qmdiarea.cpp
@@ -954,14 +954,6 @@ void QMdiAreaPrivate::rearrange(Rearranger *rearranger)
}
}
- if (active && rearranger->type() == Rearranger::RegularTiler && !tileCalledFromResizeEvent) {
- // Move active window in front if necessary. That's the case if we
- // have any windows with staysOnTopHint set.
- int indexToActive = widgets.indexOf((QWidget *)active);
- if (indexToActive > 0)
- widgets.move(indexToActive, 0);
- }
-
QRect domain = viewport->rect();
if (rearranger->type() == Rearranger::RegularTiler && !widgets.isEmpty())
domain = resizeToMinimumTileSize(minSubWindowSize, widgets.count());
@@ -1296,7 +1288,11 @@ QRect QMdiAreaPrivate::resizeToMinimumTileSize(const QSize &minSubWindowSize, in
minAreaHeight += 2 * frame;
}
const QSize diff = QSize(minAreaWidth, minAreaHeight).expandedTo(q->size()) - q->size();
- topLevel->resize(topLevel->size() + diff);
+ // Only resize topLevel widget if scroll bars are disabled.
+ if (hbarpolicy == Qt::ScrollBarAlwaysOff)
+ topLevel->resize(topLevel->size().width() + diff.width(), topLevel->size().height());
+ if (vbarpolicy == Qt::ScrollBarAlwaysOff)
+ topLevel->resize(topLevel->size().width(), topLevel->size().height() + diff.height());
}
QRect domain = viewport->rect();
@@ -1778,7 +1774,7 @@ QSize QMdiArea::minimumSizeHint() const
}
/*!
- Returns a pointer to the current subwindow, or 0 if there is
+ Returns a pointer to the current subwindow, or \nullptr if there is
no current subwindow.
This function will return the same as activeSubWindow() if
@@ -1790,13 +1786,13 @@ QMdiSubWindow *QMdiArea::currentSubWindow() const
{
Q_D(const QMdiArea);
if (d->childWindows.isEmpty())
- return 0;
+ return nullptr;
if (d->active)
return d->active;
if (d->isActivated && !window()->isMinimized())
- return 0;
+ return nullptr;
Q_ASSERT(d->indicesToActivatedChildren.count() > 0);
int index = d->indicesToActivatedChildren.at(0);
@@ -1808,7 +1804,7 @@ QMdiSubWindow *QMdiArea::currentSubWindow() const
/*!
Returns a pointer to the current active subwindow. If no
- window is currently active, 0 is returned.
+ window is currently active, \nullptr is returned.
Subwindows are treated as top-level windows with respect to
window state, i.e., if a widget outside the MDI area is the active
@@ -1825,7 +1821,7 @@ QMdiSubWindow *QMdiArea::activeSubWindow() const
}
/*!
- Activates the subwindow \a window. If \a window is 0, any
+ Activates the subwindow \a window. If \a window is \nullptr, any
current active window is deactivated.
\sa activeSubWindow()
@@ -1834,7 +1830,7 @@ void QMdiArea::setActiveSubWindow(QMdiSubWindow *window)
{
Q_D(QMdiArea);
if (!window) {
- d->activateWindow(0);
+ d->activateWindow(nullptr);
return;
}
@@ -2640,7 +2636,11 @@ bool QMdiArea::eventFilter(QObject *object, QEvent *event)
#endif // QT_CONFIG(tabbar)
Q_FALLTHROUGH();
case QEvent::Hide:
- d->isSubWindowsTiled = false;
+ // Do not reset the isSubWindowsTiled flag if the event is a spontaneous system window event.
+ // This ensures that tiling will be performed during the resizeEvent after an application
+ // window minimize (hide) and then restore (show).
+ if (!event->spontaneous())
+ d->isSubWindowsTiled = false;
break;
#if QT_CONFIG(rubberband)
case QEvent::Close:
diff --git a/src/widgets/widgets/qmdisubwindow.cpp b/src/widgets/widgets/qmdisubwindow.cpp
index 794674c427..e25bc6de7a 100644
--- a/src/widgets/widgets/qmdisubwindow.cpp
+++ b/src/widgets/widgets/qmdisubwindow.cpp
@@ -2268,7 +2268,7 @@ QMdiSubWindow::QMdiSubWindow(QWidget *parent, Qt::WindowFlags flags)
setMouseTracking(true);
setLayout(new QVBoxLayout);
setFocusPolicy(Qt::StrongFocus);
- layout()->setMargin(0);
+ layout()->setContentsMargins(QMargins());
d->updateGeometryConstraints();
setAttribute(Qt::WA_Resized, false);
d->titleBarPalette = d->desktopPalette();
@@ -2576,7 +2576,8 @@ void QMdiSubWindow::showSystemMenu()
/*!
\since 4.4
- Returns the area containing this sub-window, or 0 if there is none.
+ Returns the area containing this sub-window, or \nullptr if there
+ is none.
\sa QMdiArea::addSubWindow()
*/
@@ -2590,7 +2591,7 @@ QMdiArea *QMdiSubWindow::mdiArea() const
}
parent = parent->parentWidget();
}
- return 0;
+ return nullptr;
}
/*!
@@ -3341,8 +3342,11 @@ void QMdiSubWindow::mouseMoveEvent(QMouseEvent *mouseEvent)
}
if ((mouseEvent->buttons() & Qt::LeftButton) || d->isInInteractiveMode) {
- if ((d->isResizeOperation() && d->resizeEnabled) || (d->isMoveOperation() && d->moveEnabled))
- d->setNewGeometry(mapToParent(mouseEvent->pos()));
+ if ((d->isResizeOperation() && d->resizeEnabled) || (d->isMoveOperation() && d->moveEnabled)) {
+ // As setNewGeometry moves the window, it invalidates the pos() value of any mouse move events that are
+ // currently queued in the event loop. Map to parent using globalPos() instead.
+ d->setNewGeometry(parentWidget()->mapFromGlobal(mouseEvent->globalPos()));
+ }
return;
}
diff --git a/src/widgets/widgets/qmenu.cpp b/src/widgets/widgets/qmenu.cpp
index 48253b52b0..7dc67c8efe 100644
--- a/src/widgets/widgets/qmenu.cpp
+++ b/src/widgets/widgets/qmenu.cpp
@@ -1783,21 +1783,6 @@ QAction *QMenu::addAction(const QString &text, const QObject *receiver, const ch
return action;
}
-/*!\fn template<typename PointerToMemberFunction> 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 template<typename Functor> QAction *QMenu::addAction(const QString &text, Functor functor, const QKeySequence &shortcut = 0)
\since 5.6
@@ -1822,25 +1807,11 @@ QAction *QMenu::addAction(const QString &text, const QObject *receiver, const ch
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.
+ \a functor. The functor can be a pointer to a member function of
+ the \a context object. The newly created action is added to the
+ menu's list of actions and a pointer to it is returned.
- If \a context is destroyed, the functor will not be called.
-
- QMenu takes ownership of the returned QAction.
-*/
-
-/*!\fn template<typename PointerToMemberFunction> 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.
+ If the \a context object is destroyed, the functor will not be called.
QMenu takes ownership of the returned QAction.
*/
@@ -1869,8 +1840,9 @@ QAction *QMenu::addAction(const QString &text, const QObject *receiver, const ch
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.
+ \a functor. The \a functor can be a pointer to a member function
+ of the \a context object. The newly created action is added to the
+ menu's list of actions and a pointer to it is returned.
If \a context is destroyed, the functor will not be called.
@@ -2224,7 +2196,7 @@ void QMenu::setActiveAction(QAction *act)
/*!
- Returns the currently highlighted action, or 0 if no
+ Returns the currently highlighted action, or \nullptr if no
action is currently highlighted.
*/
QAction *QMenu::activeAction() const
@@ -2592,8 +2564,8 @@ void QMenu::popup(const QPoint &p, QAction *atAction)
This is equivalent to \c{exec(pos())}.
This returns the triggered QAction in either the popup menu or one
- of its submenus, or 0 if no item was triggered (normally because
- the user pressed Esc).
+ of its submenus, or \nullptr if no item was triggered (normally
+ because the user pressed Esc).
In most situations you'll want to specify the position yourself,
for example, the current mouse position:
@@ -2619,8 +2591,8 @@ QAction *QMenu::exec()
coordinates into global coordinates, use QWidget::mapToGlobal().
This returns the triggered QAction in either the popup menu or one
- of its submenus, or 0 if no item was triggered (normally because
- the user pressed Esc).
+ of its submenus, or \nullptr if no item was triggered (normally
+ because the user pressed Esc).
Note that all signals are emitted as usual. If you connect a
QAction to a slot and call the menu's exec(), you get the result
@@ -2656,11 +2628,11 @@ QAction *QMenu::exec(const QPoint &p, QAction *action)
QPointer<QObject> guard = this;
(void) eventLoop.exec();
if (guard.isNull())
- return 0;
+ return nullptr;
action = d->syncAction;
- d->syncAction = 0;
- d->eventLoop = 0;
+ d->syncAction = nullptr;
+ d->eventLoop = nullptr;
return action;
}
@@ -2678,7 +2650,7 @@ QAction *QMenu::exec(const QPoint &p, QAction *action)
QGraphicsView).
The function returns the triggered QAction in either the popup
- menu or one of its submenus, or 0 if no item was triggered
+ menu or one of its submenus, or \nullptr if no item was triggered
(normally because the user pressed Esc).
This is equivalent to:
diff --git a/src/widgets/widgets/qmenu.h b/src/widgets/widgets/qmenu.h
index 628f818b5e..84ab9e027a 100644
--- a/src/widgets/widgets/qmenu.h
+++ b/src/widgets/widgets/qmenu.h
@@ -82,14 +82,10 @@ public:
QAction *addAction(const QIcon &icon, const QString &text, const QObject *receiver, const char* member, const QKeySequence &shortcut = 0);
#ifdef Q_CLANG_QDOC
- template<typename PointerToMemberFunction>
- QAction *addAction(const QString &text, const QObject *receiver, PointerToMemberFunction method, const QKeySequence &shortcut = 0);
template<typename Functor>
QAction *addAction(const QString &text, Functor functor, const QKeySequence &shortcut = 0);
template<typename Functor>
QAction *addAction(const QString &text, const QObject *context, Functor functor, const QKeySequence &shortcut = 0);
- template<typename PointerToMemberFunction>
- QAction *addAction(const QIcon &icon, const QString &text, const QObject *receiver, PointerToMemberFunction method, const QKeySequence &shortcut = 0);
template<typename Functor>
QAction *addAction(const QIcon &icon, const QString &text, Functor functor, const QKeySequence &shortcut = 0);
template<typename Functor>
diff --git a/src/widgets/widgets/qmenu_p.h b/src/widgets/widgets/qmenu_p.h
index f740919dc7..12521e7a36 100644
--- a/src/widgets/widgets/qmenu_p.h
+++ b/src/widgets/widgets/qmenu_p.h
@@ -95,6 +95,12 @@ static inline int &rperp(Qt::Orientation o, QPoint &pos)
static inline int &rperp(Qt::Orientation o, QSize &size)
{ return o == Qt::Vertical ? size.rwidth() : size.rheight(); }
+static inline int pick(Qt::Orientation o, const QMargins &m)
+{ return o == Qt::Horizontal ? (m.left() + m.right()) : (m.top() + m.bottom()); }
+
+static inline int perp(Qt::Orientation o, const QMargins &m)
+{ return o == Qt::Vertical ? (m.left() + m.right()) : (m.top() + m.bottom()); }
+
class QTornOffMenu;
class QEventLoop;
@@ -115,7 +121,7 @@ private:
class QMenuSloppyState
{
- Q_DISABLE_COPY(QMenuSloppyState)
+ Q_DISABLE_COPY_MOVE(QMenuSloppyState)
public:
QMenuSloppyState()
: m_enabled(false)
diff --git a/src/widgets/widgets/qplaintextedit.cpp b/src/widgets/widgets/qplaintextedit.cpp
index 57f2dec8f7..dc8765ad88 100644
--- a/src/widgets/widgets/qplaintextedit.cpp
+++ b/src/widgets/widgets/qplaintextedit.cpp
@@ -1615,7 +1615,7 @@ void QPlainTextEdit::timerEvent(QTimerEvent *e)
const QPoint globalPos = QCursor::pos();
pos = d->viewport->mapFromGlobal(globalPos);
QMouseEvent ev(QEvent::MouseMove, pos, d->viewport->mapTo(d->viewport->topLevelWidget(), pos), globalPos,
- Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
+ Qt::LeftButton, Qt::LeftButton, QGuiApplication::keyboardModifiers());
mouseMoveEvent(&ev);
}
int deltaY = qMax(pos.y() - visible.top(), visible.bottom() - pos.y()) - visible.height();
@@ -2039,7 +2039,7 @@ void QPlainTextEdit::paintEvent(QPaintEvent *e)
if (backgroundVisible() && !block.isValid() && offset.y() <= er.bottom()
&& (centerOnScroll() || verticalScrollBar()->maximum() == verticalScrollBar()->minimum())) {
- painter.fillRect(QRect(QPoint((int)er.left(), (int)offset.y()), er.bottomRight()), palette().background());
+ painter.fillRect(QRect(QPoint((int)er.left(), (int)offset.y()), er.bottomRight()), palette().window());
}
}
@@ -2892,6 +2892,7 @@ void QPlainTextEdit::setCenterOnScroll(bool enabled)
if (enabled == d->centerOnScroll)
return;
d->centerOnScroll = enabled;
+ d->_q_adjustScrollbars();
}
@@ -2929,6 +2930,27 @@ bool QPlainTextEdit::find(const QRegExp &exp, QTextDocument::FindFlags options)
#endif
/*!
+ \fn bool QPlainTextEdit::find(const QRegularExpression &exp, QTextDocument::FindFlags options)
+
+ \since 5.13
+ \overload
+
+ Finds the next occurrence, matching the regular expression, \a exp, using the given
+ \a options. The QTextDocument::FindCaseSensitively option is ignored for this overload,
+ use QRegularExpression::CaseInsensitiveOption instead.
+
+ Returns \c true if a match was found and changes the cursor to select the match;
+ otherwise returns \c false.
+*/
+#if QT_CONFIG(regularexpression)
+bool QPlainTextEdit::find(const QRegularExpression &exp, QTextDocument::FindFlags options)
+{
+ Q_D(QPlainTextEdit);
+ return d->control->find(exp, options);
+}
+#endif
+
+/*!
\fn void QPlainTextEdit::copyAvailable(bool yes)
This signal is emitted when text is selected or de-selected in the
diff --git a/src/widgets/widgets/qplaintextedit.h b/src/widgets/widgets/qplaintextedit.h
index e5ac4c82b8..a5945d649a 100644
--- a/src/widgets/widgets/qplaintextedit.h
+++ b/src/widgets/widgets/qplaintextedit.h
@@ -60,6 +60,7 @@ class QMenu;
class QPlainTextEditPrivate;
class QMimeData;
class QPagedPaintDevice;
+class QRegularExpression;
class Q_WIDGETS_EXPORT QPlainTextEdit : public QAbstractScrollArea
{
@@ -149,6 +150,9 @@ public:
#ifndef QT_NO_REGEXP
bool find(const QRegExp &exp, QTextDocument::FindFlags options = QTextDocument::FindFlags());
#endif
+#if QT_CONFIG(regularexpression)
+ bool find(const QRegularExpression &exp, QTextDocument::FindFlags options = QTextDocument::FindFlags());
+#endif
inline QString toPlainText() const
{ return document()->toPlainText(); }
diff --git a/src/widgets/widgets/qpushbutton.cpp b/src/widgets/widgets/qpushbutton.cpp
index 8f7271c2dc..b578aa0b18 100644
--- a/src/widgets/widgets/qpushbutton.cpp
+++ b/src/widgets/widgets/qpushbutton.cpp
@@ -545,8 +545,8 @@ void QPushButton::setMenu(QMenu* menu)
}
/*!
- Returns the button's associated popup menu or 0 if no popup menu
- has been set.
+ Returns the button's associated popup menu or \nullptr if no popup
+ menu has been set.
\sa setMenu()
*/
diff --git a/src/widgets/widgets/qscrollarea.cpp b/src/widgets/widgets/qscrollarea.cpp
index 0bfc56f7fa..9994344d79 100644
--- a/src/widgets/widgets/qscrollarea.cpp
+++ b/src/widgets/widgets/qscrollarea.cpp
@@ -217,7 +217,7 @@ void QScrollAreaPrivate::updateScrollBars()
}
/*!
- Returns the scroll area's widget, or 0 if there is none.
+ Returns the scroll area's widget, or \nullptr if there is none.
\sa setWidget()
*/
diff --git a/src/widgets/widgets/qsplitter.cpp b/src/widgets/widgets/qsplitter.cpp
index 3b516f36b6..de838a8f93 100644
--- a/src/widgets/widgets/qsplitter.cpp
+++ b/src/widgets/widgets/qsplitter.cpp
@@ -1231,7 +1231,7 @@ QSplitterHandle *QSplitter::createHandle()
/*!
Returns the handle to the left of (or above) the item in the
- splitter's layout at the given \a index, or \c nullptr if there is no such item.
+ splitter's layout at the given \a index, or \nullptr if there is no such item.
The handle at index 0 is always hidden.
For right-to-left languages such as Arabic and Hebrew, the layout
@@ -1250,7 +1250,7 @@ QSplitterHandle *QSplitter::handle(int index) const
/*!
Returns the widget at the given \a index in the splitter's layout,
- or \c nullptr if there is no such widget.
+ or \nullptr if there is no such widget.
\sa count(), handle(), indexOf(), insertWidget()
*/
@@ -1783,6 +1783,7 @@ void QSplitter::setStretchFactor(int index, int stretch)
}
+#if QT_DEPRECATED_SINCE(5, 13)
/*!
\relates QSplitter
\obsolete
@@ -1813,6 +1814,7 @@ QTextStream& operator>>(QTextStream& ts, QSplitter& splitter)
splitter.restoreState(std::move(line).toLatin1());
return ts;
}
+#endif
QT_END_NAMESPACE
diff --git a/src/widgets/widgets/qsplitter.h b/src/widgets/widgets/qsplitter.h
index 16fac48d1c..ec980d9ee3 100644
--- a/src/widgets/widgets/qsplitter.h
+++ b/src/widgets/widgets/qsplitter.h
@@ -129,8 +129,12 @@ private:
friend class QSplitterHandle;
};
+#if QT_DEPRECATED_SINCE(5, 13)
+QT_DEPRECATED_X("Use QSplitter::saveState() instead")
Q_WIDGETS_EXPORT QTextStream& operator<<(QTextStream&, const QSplitter&);
+QT_DEPRECATED_X("Use QSplitter::restoreState() instead")
Q_WIDGETS_EXPORT QTextStream& operator>>(QTextStream&, QSplitter&);
+#endif
class QSplitterHandlePrivate;
class Q_WIDGETS_EXPORT QSplitterHandle : public QWidget
diff --git a/src/widgets/widgets/qstackedwidget.cpp b/src/widgets/widgets/qstackedwidget.cpp
index 2217dab870..f863964c58 100644
--- a/src/widgets/widgets/qstackedwidget.cpp
+++ b/src/widgets/widgets/qstackedwidget.cpp
@@ -220,7 +220,7 @@ int QStackedWidget::currentIndex() const
}
/*!
- Returns the current widget, or 0 if there are no child widgets.
+ Returns the current widget, or \nullptr if there are no child widgets.
\sa currentIndex(), setCurrentWidget()
*/
@@ -260,8 +260,8 @@ int QStackedWidget::indexOf(QWidget *widget) const
}
/*!
- Returns the widget at the given \a index, or 0 if there is no such
- widget.
+ Returns the widget at the given \a index, or \nullptr if there is
+ no such widget.
\sa currentWidget(), indexOf()
*/
diff --git a/src/widgets/widgets/qstatusbar.cpp b/src/widgets/widgets/qstatusbar.cpp
index ef98bb6950..e9044e6cad 100644
--- a/src/widgets/widgets/qstatusbar.cpp
+++ b/src/widgets/widgets/qstatusbar.cpp
@@ -482,14 +482,14 @@ void QStatusBar::reformat()
#if QT_CONFIG(sizegrip)
if (d->resizer) {
d->box = new QHBoxLayout(this);
- d->box->setMargin(0);
+ d->box->setContentsMargins(QMargins());
vbox = new QVBoxLayout;
d->box->addLayout(vbox);
} else
#endif
{
vbox = d->box = new QVBoxLayout(this);
- d->box->setMargin(0);
+ d->box->setContentsMargins(QMargins());
}
vbox->addSpacing(3);
QBoxLayout* l = new QHBoxLayout;
@@ -689,7 +689,7 @@ void QStatusBar::paintEvent(QPaintEvent *event)
}
}
if (haveMessage) {
- p.setPen(palette().foreground().color());
+ p.setPen(palette().windowText().color());
p.drawText(d->messageRect(), Qt::AlignLeading | Qt::AlignVCenter | Qt::TextSingleLine, d->tempItem);
}
}
diff --git a/src/widgets/widgets/qtabbar.cpp b/src/widgets/widgets/qtabbar.cpp
index 68453e1842..b13f4da9d2 100644
--- a/src/widgets/widgets/qtabbar.cpp
+++ b/src/widgets/widgets/qtabbar.cpp
@@ -2093,7 +2093,6 @@ void QTabBarPrivate::setupMovableTab()
grabImage.setDevicePixelRatio(q->devicePixelRatioF());
grabImage.fill(Qt::transparent);
QStylePainter p(&grabImage, q);
- p.initFrom(q);
QStyleOptionTab tab;
q->initStyleOption(&tab, pressedIndex);
@@ -2567,7 +2566,7 @@ void QTabBar::setChangeCurrentOnDrag(bool change)
The tab bar will take ownership of the widget and so all widgets set here
will be deleted by the tab bar when it is destroyed unless you separately
- reparent the widget after setting some other widget (or 0).
+ reparent the widget after setting some other widget (or \nullptr).
\sa tabsClosable()
*/
@@ -2597,14 +2596,14 @@ void QTabBar::setTabButton(int index, ButtonPosition position, QWidget *widget)
}
/*!
- Returns the widget set a tab \a index and \a position or 0 if
- one is not set.
+ Returns the widget set a tab \a index and \a position or \nullptr
+ if one is not set.
*/
QWidget *QTabBar::tabButton(int index, ButtonPosition position) const
{
Q_D(const QTabBar);
if (index < 0 || index >= d->tabList.count())
- return 0;
+ return nullptr;
if (position == LeftSide)
return d->tabList.at(index).leftWidget;
else
diff --git a/src/widgets/widgets/qtabwidget.cpp b/src/widgets/widgets/qtabwidget.cpp
index 8a848554e3..547b8a82f9 100644
--- a/src/widgets/widgets/qtabwidget.cpp
+++ b/src/widgets/widgets/qtabwidget.cpp
@@ -579,7 +579,7 @@ void QTabWidget::setTabEnabled(int index, bool enable)
All widgets set here will be deleted by the tab widget when it is
destroyed unless you separately reparent the widget after setting
- some other corner widget (or 0).
+ some other corner widget (or \nullptr).
Note: Corner widgets are designed for \l North and \l South tab positions;
other orientations are known to not work properly.
@@ -605,7 +605,7 @@ void QTabWidget::setCornerWidget(QWidget * widget, Qt::Corner corner)
}
/*!
- Returns the widget shown in the \a corner of the tab widget or 0.
+ Returns the widget shown in the \a corner of the tab widget or \nullptr.
*/
QWidget * QTabWidget::cornerWidget(Qt::Corner corner) const
{
@@ -1146,8 +1146,8 @@ void QTabWidget::keyPressEvent(QKeyEvent *e)
}
/*!
- Returns the tab page at index position \a index or 0 if the \a
- index is out of range.
+ Returns the tab page at index position \a index or \nullptr if the
+ \a index is out of range.
*/
QWidget *QTabWidget::widget(int index) const
{
diff --git a/src/widgets/widgets/qtextbrowser.cpp b/src/widgets/widgets/qtextbrowser.cpp
index 09541bb53b..bb9a4fed91 100644
--- a/src/widgets/widgets/qtextbrowser.cpp
+++ b/src/widgets/widgets/qtextbrowser.cpp
@@ -276,7 +276,7 @@ void QTextBrowserPrivate::setSource(const QUrl &url)
Q_Q(QTextBrowser);
#ifndef QT_NO_CURSOR
if (q->isVisible())
- QApplication::setOverrideCursor(Qt::WaitCursor);
+ QGuiApplication::setOverrideCursor(Qt::WaitCursor);
#endif
textOrSourceChanged = true;
@@ -310,7 +310,7 @@ void QTextBrowserPrivate::setSource(const QUrl &url)
const QStringRef firstTag = txt.leftRef(txt.indexOf(QLatin1Char('>')) + 1);
if (firstTag.startsWith(QLatin1String("<qt")) && firstTag.contains(QLatin1String("type")) && firstTag.contains(QLatin1String("detail"))) {
#ifndef QT_NO_CURSOR
- QApplication::restoreOverrideCursor();
+ QGuiApplication::restoreOverrideCursor();
#endif
#if QT_CONFIG(whatsthis)
QWhatsThis::showText(QCursor::pos(), txt, q);
@@ -355,7 +355,7 @@ void QTextBrowserPrivate::setSource(const QUrl &url)
#ifndef QT_NO_CURSOR
if (q->isVisible())
- QApplication::restoreOverrideCursor();
+ QGuiApplication::restoreOverrideCursor();
#endif
emit q->sourceChanged(url);
}
diff --git a/src/widgets/widgets/qtextedit.cpp b/src/widgets/widgets/qtextedit.cpp
index e3a45680ef..920133d493 100644
--- a/src/widgets/widgets/qtextedit.cpp
+++ b/src/widgets/widgets/qtextedit.cpp
@@ -105,6 +105,14 @@ public:
else
ed->insertFromMimeData(source);
}
+ QVariant loadResource(int type, const QUrl &name) override {
+ auto *ed = qobject_cast<QTextEdit *>(parent());
+ if (!ed)
+ return QWidgetTextControl::loadResource(type, name);
+
+ QUrl resolvedName = ed->d_func()->resolveUrl(name);
+ return ed->loadResource(type, resolvedName);
+ }
};
QTextEditPrivate::QTextEditPrivate()
@@ -2534,6 +2542,27 @@ bool QTextEdit::find(const QRegExp &exp, QTextDocument::FindFlags options)
#endif
/*!
+ \fn bool QTextEdit::find(const QRegularExpression &exp, QTextDocument::FindFlags options)
+
+ \since 5.13
+ \overload
+
+ Finds the next occurrence, matching the regular expression, \a exp, using the given
+ \a options. The QTextDocument::FindCaseSensitively option is ignored for this overload,
+ use QRegularExpression::CaseInsensitiveOption instead.
+
+ Returns \c true if a match was found and changes the cursor to select the match;
+ otherwise returns \c false.
+*/
+#if QT_CONFIG(regularexpression)
+bool QTextEdit::find(const QRegularExpression &exp, QTextDocument::FindFlags options)
+{
+ Q_D(QTextEdit);
+ return d->control->find(exp, options);
+}
+#endif
+
+/*!
\fn void QTextEdit::copyAvailable(bool yes)
This signal is emitted when text is selected or de-selected in the
diff --git a/src/widgets/widgets/qtextedit.h b/src/widgets/widgets/qtextedit.h
index 51d6c2ccba..3aa23aaace 100644
--- a/src/widgets/widgets/qtextedit.h
+++ b/src/widgets/widgets/qtextedit.h
@@ -57,6 +57,7 @@ class QMenu;
class QTextEditPrivate;
class QMimeData;
class QPagedPaintDevice;
+class QRegularExpression;
class Q_WIDGETS_EXPORT QTextEdit : public QAbstractScrollArea
{
@@ -165,6 +166,9 @@ public:
#ifndef QT_NO_REGEXP
bool find(const QRegExp &exp, QTextDocument::FindFlags options = QTextDocument::FindFlags());
#endif
+#if QT_CONFIG(regularexpression)
+ bool find(const QRegularExpression &exp, QTextDocument::FindFlags options = QTextDocument::FindFlags());
+#endif
QString toPlainText() const;
#ifndef QT_NO_TEXTHTMLPARSER
diff --git a/src/widgets/widgets/qtoolbar.cpp b/src/widgets/widgets/qtoolbar.cpp
index 4af71c126e..bcf5a40ae3 100644
--- a/src/widgets/widgets/qtoolbar.cpp
+++ b/src/widgets/widgets/qtoolbar.cpp
@@ -799,18 +799,6 @@ QAction *QToolBar::addAction(const QIcon &icon, const QString &text,
return action;
}
-/*!\fn template<typename PointerToMemberFunction> 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 template<typename Functor> QAction *QToolBar::addAction(const QString &text, Functor functor)
\since 5.6
@@ -829,24 +817,13 @@ QAction *QToolBar::addAction(const QIcon &icon, const QString &text,
\overload
- Creates a new action with the given \a text. This action is added to
- the end of the toolbar. The action's
+ 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 template<typename PointerToMemberFunction> QAction *QToolBar::addAction(const QIcon &icon, const QString &text, const QObject *receiver, PointerToMemberFunction method)
-
- \since 5.6
+ \a functor. The \a functor can be a pointer to a member function
+ in the \a context object.
- \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.
+ If the \a context object is destroyed, the \a functor will not be called.
*/
/*!\fn template<typename Functor> QAction *QToolBar::addAction(const QIcon &icon, const QString &text, Functor functor)
@@ -870,9 +847,10 @@ QAction *QToolBar::addAction(const QIcon &icon, const QString &text,
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.
+ \a functor. The \a functor can be a pointer to a member function
+ of the \a context object.
- If \a context is destroyed, the functor will not be called.
+ If the \a context object is destroyed, the \a functor will not be called.
*/
/*!
@@ -1067,7 +1045,7 @@ void QToolBar::paintEvent(QPaintEvent *)
if (d->layout->expanded || d->layout->animating || isWindow()) {
//if the toolbar is expended, we need to fill the background with the window color
//because some styles may expects that.
- p.fillRect(opt.rect, palette().background());
+ p.fillRect(opt.rect, palette().window());
style->drawControl(QStyle::CE_ToolBar, &opt, &p, this);
style->drawPrimitive(QStyle::PE_FrameMenu, &opt, &p, this);
} else {
diff --git a/src/widgets/widgets/qtoolbar.h b/src/widgets/widgets/qtoolbar.h
index 4ae83190d1..0c434e8d1d 100644
--- a/src/widgets/widgets/qtoolbar.h
+++ b/src/widgets/widgets/qtoolbar.h
@@ -99,15 +99,11 @@ 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
- template<typename PointerToMemberFunction>
- QAction *addAction(const QString &text, const QObject *receiver, PointerToMemberFunction method);
+#ifdef Q_CLANG_QDOC
template<typename Functor>
QAction *addAction(const QString &text, Functor functor);
template<typename Functor>
QAction *addAction(const QString &text, const QObject *context, Functor functor);
- template<typename PointerToMemberFunction>
- QAction *addAction(const QIcon &icon, const QString &text, const QObject *receiver, PointerToMemberFunction method);
template<typename Functor>
QAction *addAction(const QIcon &icon, const QString &text, Functor functor);
template<typename Functor>
@@ -149,7 +145,7 @@ public:
connect(result, &QAction::triggered, slot);
return result;
}
-#endif // !Q_QDOC
+#endif // !Q_CLANG_QDOC
QAction *addSeparator();
QAction *insertSeparator(QAction *before);
diff --git a/src/widgets/widgets/qtoolbararealayout.cpp b/src/widgets/widgets/qtoolbararealayout.cpp
index edf497111b..adc329131c 100644
--- a/src/widgets/widgets/qtoolbararealayout.cpp
+++ b/src/widgets/widgets/qtoolbararealayout.cpp
@@ -789,7 +789,7 @@ void QToolBarAreaLayout::deleteAllLayoutItems()
}
}
-QInternal::DockPosition QToolBarAreaLayout::findToolBar(QToolBar *toolBar) const
+QInternal::DockPosition QToolBarAreaLayout::findToolBar(const QToolBar *toolBar) const
{
for (int i = 0; i < QInternal::DockCount; ++i) {
const QToolBarAreaLayoutInfo &dock = docks[i];
@@ -1078,7 +1078,11 @@ bool QToolBarAreaLayout::insertGap(const QList<int> &path, QLayoutItem *item)
void QToolBarAreaLayout::remove(const QList<int> &path)
{
Q_ASSERT(path.count() == 3);
- docks[path.at(0)].lines[path.at(1)].toolBarItems.removeAt(path.at(2));
+ QToolBarAreaLayoutInfo &dock = docks[path.at(0)];
+ QToolBarAreaLayoutLine &line = dock.lines[path.at(1)];
+ line.toolBarItems.removeAt(path.at(2));
+ if (line.toolBarItems.isEmpty())
+ dock.lines.removeAt(path.at(1));
}
void QToolBarAreaLayout::remove(QLayoutItem *item)
diff --git a/src/widgets/widgets/qtoolbararealayout_p.h b/src/widgets/widgets/qtoolbararealayout_p.h
index dffbab1f21..17747ef29b 100644
--- a/src/widgets/widgets/qtoolbararealayout_p.h
+++ b/src/widgets/widgets/qtoolbararealayout_p.h
@@ -196,7 +196,7 @@ public:
void insertItem(QInternal::DockPosition pos, QLayoutItem *item);
void insertItem(QToolBar *before, QLayoutItem *item);
- QInternal::DockPosition findToolBar(QToolBar *toolBar) const;
+ QInternal::DockPosition findToolBar(const QToolBar *toolBar) const;
bool toolBarBreak(QToolBar *toolBar) const;
void getStyleOptionInfo(QStyleOptionToolBar *option, QToolBar *toolBar) const;
diff --git a/src/widgets/widgets/qtoolbarlayout.cpp b/src/widgets/widgets/qtoolbarlayout.cpp
index f2d329d59d..d50e19a5ed 100644
--- a/src/widgets/widgets/qtoolbarlayout.cpp
+++ b/src/widgets/widgets/qtoolbarlayout.cpp
@@ -119,8 +119,9 @@ void QToolBarLayout::updateMarginAndSpacing()
QStyle *style = tb->style();
QStyleOptionToolBar opt;
tb->initStyleOption(&opt);
- setMargin(style->pixelMetric(QStyle::PM_ToolBarItemMargin, &opt, tb)
- + style->pixelMetric(QStyle::PM_ToolBarFrameWidth, &opt, tb));
+ const int margin = style->pixelMetric(QStyle::PM_ToolBarItemMargin, &opt, tb)
+ + style->pixelMetric(QStyle::PM_ToolBarFrameWidth, &opt, tb);
+ setContentsMargins(margin, margin, margin, margin);
setSpacing(style->pixelMetric(QStyle::PM_ToolBarItemSpacing, &opt, tb));
}
@@ -268,7 +269,7 @@ void QToolBarLayout::updateGeomArray() const
tb->initStyleOption(&opt);
const int handleExtent = movable()
? style->pixelMetric(QStyle::PM_ToolBarHandleExtent, &opt, tb) : 0;
- const int margin = this->margin();
+ const QMargins margins = contentsMargins();
const int spacing = this->spacing();
const int extensionExtent = style->pixelMetric(QStyle::PM_ToolBarExtensionExtent, &opt, tb);
Qt::Orientation o = tb->orientation();
@@ -330,12 +331,12 @@ void QToolBarLayout::updateGeomArray() const
that->empty = count == 0;
rpick(o, that->minSize) += handleExtent;
- that->minSize += QSize(2*margin, 2*margin);
+ that->minSize += QSize(pick(Qt::Horizontal, margins), pick(Qt::Vertical, margins));
if (items.count() > 1)
rpick(o, that->minSize) += spacing + extensionExtent;
rpick(o, that->hint) += handleExtent;
- that->hint += QSize(2*margin, 2*margin);
+ that->hint += QSize(pick(Qt::Horizontal, margins), pick(Qt::Vertical, margins));
that->dirty = false;
}
@@ -384,7 +385,7 @@ void QToolBarLayout::setGeometry(const QRect &rect)
QStyle *style = tb->style();
QStyleOptionToolBar opt;
tb->initStyleOption(&opt);
- const int margin = this->margin();
+ const QMargins margins = contentsMargins();
const int extensionExtent = style->pixelMetric(QStyle::PM_ToolBarExtensionExtent, &opt, tb);
Qt::Orientation o = tb->orientation();
@@ -403,14 +404,18 @@ void QToolBarLayout::setGeometry(const QRect &rect)
QSize hint = sizeHint();
QPoint pos;
- rpick(o, pos) = pick(o, rect.bottomRight()) - margin - extensionExtent + 2;
+ rpick(o, pos) = pick(o, rect.bottomRight()) -
+ pick(o, QSize(margins.bottom(), margins.right())) - extensionExtent + 2;
if (area == Qt::LeftToolBarArea || area == Qt::TopToolBarArea)
- rperp(o, pos) = perp(o, rect.topLeft()) + margin;
+ rperp(o, pos) = perp(o, rect.topLeft()) +
+ perp(o, QSize(margins.top(), margins.left()));
else
- rperp(o, pos) = perp(o, rect.bottomRight()) - margin - (perp(o, hint) - 2*margin) + 1;
+ rperp(o, pos) = perp(o, rect.bottomRight()) -
+ perp(o, QSize(margins.bottom(), margins.right())) -
+ (perp(o, hint) - perp(o, margins)) + 1;
QSize size;
rpick(o, size) = extensionExtent;
- rperp(o, size) = perp(o, hint) - 2*margin;
+ rperp(o, size) = perp(o, hint) - perp(o, margins);
QRect r(pos, size);
if (o == Qt::Horizontal)
@@ -443,13 +448,13 @@ bool QToolBarLayout::layoutActions(const QSize &size)
tb->initStyleOption(&opt);
const int handleExtent = movable()
? style->pixelMetric(QStyle::PM_ToolBarHandleExtent, &opt, tb) : 0;
- const int margin = this->margin();
+ const QMargins margins = contentsMargins();
const int spacing = this->spacing();
const int extensionExtent = style->pixelMetric(QStyle::PM_ToolBarExtensionExtent, &opt, tb);
Qt::Orientation o = tb->orientation();
bool extensionMenuContainsOnlyWidgetActions = true;
- int space = pick(o, rect.size()) - 2*margin - handleExtent;
+ int space = pick(o, rect.size()) - pick(o, margins) - handleExtent;
if (space <= 0)
return false; // nothing to do.
@@ -458,7 +463,7 @@ bool QToolBarLayout::layoutActions(const QSize &size)
bool ranOutOfSpace = false;
int rows = 0;
- int rowPos = perp(o, rect.topLeft()) + margin;
+ int rowPos = perp(o, rect.topLeft()) + perp(o, QSize(margins.top(), margins.left()));
int i = 0;
while (i < items.count()) {
QVector<QLayoutStruct> a = geomArray;
@@ -521,14 +526,14 @@ bool QToolBarLayout::layoutActions(const QSize &size)
}
QPoint pos;
- rpick(o, pos) = margin + handleExtent + a[j].pos;
+ rpick(o, pos) = pick(o, QSize(margins.top(), margins.left())) + handleExtent + a[j].pos;
rperp(o, pos) = rowPos;
QSize size;
rpick(o, size) = a[j].size;
if (expanded)
rperp(o, size) = rowHeight;
else
- rperp(o, size) = perp(o, rect.size()) - 2*margin;
+ rperp(o, size) = perp(o, rect.size()) - perp(o, QSize(margins.top(), margins.left()));
QRect r(pos, size);
if (o == Qt::Horizontal)
@@ -589,7 +594,7 @@ QSize QToolBarLayout::expandedSize(const QSize &size) const
tb->initStyleOption(&opt);
const int handleExtent = movable()
? style->pixelMetric(QStyle::PM_ToolBarHandleExtent, &opt, tb) : 0;
- const int margin = this->margin();
+ const QMargins margins = contentsMargins();
const int spacing = this->spacing();
const int extensionExtent = style->pixelMetric(QStyle::PM_ToolBarExtensionExtent, &opt, tb);
@@ -609,9 +614,9 @@ QSize QToolBarLayout::expandedSize(const QSize &size) const
if (rows == 1)
++rows; // we want to expand to at least two rows
int space = total_w/rows + spacing + extensionExtent;
- space = qMax(space, min_w - 2*margin - handleExtent);
+ space = qMax(space, min_w - pick(o, margins) - handleExtent);
if (win != 0)
- space = qMin(space, pick(o, win->size()) - 2*margin - handleExtent);
+ space = qMin(space, pick(o, win->size()) - pick(o, margins) - handleExtent);
int w = 0;
int h = 0;
@@ -644,11 +649,11 @@ QSize QToolBarLayout::expandedSize(const QSize &size) const
h += rowHeight + spacing;
}
- w += 2*margin + handleExtent + spacing + extensionExtent;
+ w += pick(Qt::Horizontal, margins) + handleExtent + spacing + extensionExtent;
w = qMax(w, min_w);
if (win != 0)
w = qMin(w, pick(o, win->size()));
- h += 2*margin - spacing; //there is no spacing before the first row
+ h += pick(Qt::Vertical, margins) - spacing; //there is no spacing before the first row
QSize result;
rpick(o, result) = w;
diff --git a/src/widgets/widgets/qtoolbox.cpp b/src/widgets/widgets/qtoolbox.cpp
index 46ade0277c..1c83485bff 100644
--- a/src/widgets/widgets/qtoolbox.cpp
+++ b/src/widgets/widgets/qtoolbox.cpp
@@ -294,7 +294,7 @@ QToolBox::QToolBox(QWidget *parent, Qt::WindowFlags f)
{
Q_D(QToolBox);
d->layout = new QVBoxLayout(this);
- d->layout->setMargin(0);
+ d->layout->setContentsMargins(QMargins());
setBackgroundRole(QPalette::Button);
}
@@ -437,7 +437,7 @@ void QToolBoxPrivate::relayout()
Q_Q(QToolBox);
delete layout;
layout = new QVBoxLayout(q);
- layout->setMargin(0);
+ layout->setContentsMargins(QMargins());
for (QToolBoxPrivate::PageList::ConstIterator i = pageList.constBegin(); i != pageList.constEnd(); ++i) {
layout->addWidget((*i).button);
layout->addWidget((*i).sv);
@@ -504,7 +504,8 @@ int QToolBox::currentIndex() const
}
/*!
- Returns a pointer to the current widget, or 0 if there is no such item.
+ Returns a pointer to the current widget, or \nullptr if there is
+ no such item.
\sa currentIndex(), setCurrentWidget()
*/
@@ -512,7 +513,7 @@ int QToolBox::currentIndex() const
QWidget * QToolBox::currentWidget() const
{
Q_D(const QToolBox);
- return d->currentPage ? d->currentPage->widget : 0;
+ return d->currentPage ? d->currentPage->widget : nullptr;
}
/*!
@@ -530,15 +531,15 @@ void QToolBox::setCurrentWidget(QWidget *widget)
}
/*!
- Returns the widget at position \a index, or 0 if there is no such
- item.
+ Returns the widget at position \a index, or \nullptr if there is
+ no such item.
*/
QWidget *QToolBox::widget(int index) const
{
Q_D(const QToolBox);
if (index < 0 || index >= (int) d->pageList.size())
- return 0;
+ return nullptr;
return d->pageList.at(index).widget;
}
diff --git a/src/widgets/widgets/qtoolbutton.cpp b/src/widgets/widgets/qtoolbutton.cpp
index 6a24712319..b00b219386 100644
--- a/src/widgets/widgets/qtoolbutton.cpp
+++ b/src/widgets/widgets/qtoolbutton.cpp
@@ -669,7 +669,8 @@ void QToolButton::setMenu(QMenu* menu)
}
/*!
- Returns the associated menu, or 0 if no menu has been defined.
+ Returns the associated menu, or \nullptr if no menu has been
+ defined.
\sa setMenu()
*/
@@ -678,7 +679,7 @@ QMenu* QToolButton::menu() const
Q_D(const QToolButton);
if (d->menuAction)
return d->menuAction->menu();
- return 0;
+ return nullptr;
}
/*!
diff --git a/src/widgets/widgets/qwidgetresizehandler_p.h b/src/widgets/widgets/qwidgetresizehandler_p.h
index b87bbd6229..89bc759cc2 100644
--- a/src/widgets/widgets/qwidgetresizehandler_p.h
+++ b/src/widgets/widgets/qwidgetresizehandler_p.h
@@ -100,7 +100,7 @@ protected:
void keyPressEvent(QKeyEvent *e);
private:
- Q_DISABLE_COPY(QWidgetResizeHandler)
+ Q_DISABLE_COPY_MOVE(QWidgetResizeHandler)
enum MousePosition {
Nowhere,
diff --git a/src/widgets/widgets/qwidgettextcontrol.cpp b/src/widgets/widgets/qwidgettextcontrol.cpp
index e179ea3b40..711c4bfd2a 100644
--- a/src/widgets/widgets/qwidgettextcontrol.cpp
+++ b/src/widgets/widgets/qwidgettextcontrol.cpp
@@ -57,9 +57,6 @@
#include <qtimer.h>
#include "private/qtextdocumentlayout_p.h"
#include "private/qabstracttextdocumentlayout_p.h"
-#if QT_CONFIG(textedit)
-#include "private/qtextedit_p.h"
-#endif
#include "qtextdocument.h"
#include "private/qtextdocument_p.h"
#include "qtextlist.h"
@@ -218,6 +215,14 @@ bool QWidgetTextControlPrivate::cursorMoveKeyEvent(QKeyEvent *e)
else if (e == QKeySequence::SelectPreviousLine) {
op = QTextCursor::Up;
mode = QTextCursor::KeepAnchor;
+ {
+ QTextBlock block = cursor.block();
+ QTextLine line = currentTextLine(cursor);
+ if (!block.previous().isValid()
+ && line.isValid()
+ && line.lineNumber() == 0)
+ op = QTextCursor::Start;
+ }
}
else if (e == QKeySequence::SelectNextLine) {
op = QTextCursor::Down;
@@ -1357,15 +1362,8 @@ process:
QVariant QWidgetTextControl::loadResource(int type, const QUrl &name)
{
-#if !QT_CONFIG(textedit)
Q_UNUSED(type);
Q_UNUSED(name);
-#else
- if (QTextEdit *textEdit = qobject_cast<QTextEdit *>(parent())) {
- QUrl resolvedName = textEdit->d_func()->resolveUrl(name);
- return textEdit->loadResource(type, resolvedName);
- }
-#endif
return QVariant();
}
@@ -3094,6 +3092,19 @@ bool QWidgetTextControl::find(const QRegExp &exp, QTextDocument::FindFlags optio
}
#endif
+#if QT_CONFIG(regularexpression)
+bool QWidgetTextControl::find(const QRegularExpression &exp, QTextDocument::FindFlags options)
+{
+ Q_D(QWidgetTextControl);
+ QTextCursor search = d->doc->find(exp, d->cursor, options);
+ if (search.isNull())
+ return false;
+
+ setTextCursor(search);
+ return true;
+}
+#endif
+
QString QWidgetTextControl::toPlainText() const
{
return document()->toPlainText();
diff --git a/src/widgets/widgets/qwidgettextcontrol_p.h b/src/widgets/widgets/qwidgettextcontrol_p.h
index 4b2acbd934..202ba36454 100644
--- a/src/widgets/widgets/qwidgettextcontrol_p.h
+++ b/src/widgets/widgets/qwidgettextcontrol_p.h
@@ -80,6 +80,7 @@ class QMenu;
class QWidgetTextControlPrivate;
class QAbstractScrollArea;
class QEvent;
+class QRegularExpression;
class QTimerEvent;
class Q_WIDGETS_EXPORT QWidgetTextControl : public QInputControl
@@ -119,6 +120,9 @@ public:
#ifndef QT_NO_REGEXP
bool find(const QRegExp &exp, QTextDocument::FindFlags options = 0);
#endif
+#if QT_CONFIG(regularexpression)
+ bool find(const QRegularExpression &exp, QTextDocument::FindFlags options = 0);
+#endif
QString toPlainText() const;
#ifndef QT_NO_TEXTHTMLPARSER
@@ -263,7 +267,7 @@ protected:
virtual bool event(QEvent *e) override;
private:
- Q_DISABLE_COPY(QWidgetTextControl)
+ Q_DISABLE_COPY_MOVE(QWidgetTextControl)
Q_PRIVATE_SLOT(d_func(), void _q_updateCurrentCharFormatAndSelection())
Q_PRIVATE_SLOT(d_func(), void _q_emitCursorPosChanged(const QTextCursor &))
Q_PRIVATE_SLOT(d_func(), void _q_deleteSelected())