From eb18be36ad013c80fe982a77b3eadb9791f96298 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Wed, 4 Dec 2019 10:55:42 +0100 Subject: Mark QApplication::globalStrut as deprecated MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This property is obsolete with today's user interface reality, and was never consistently implemented in all styles and widgets. Deprecating it for Qt 5.15 as preparating for removing the code for Qt 6. [ChangeLog][QtWidgets][QApplication] The globalStrut property has been deprecated and will be removed from Qt 6 Change-Id: Iaea88e563144481a395de6cf0745a512e386407d Reviewed-by: Tor Arne Vestbø Reviewed-by: Shawn Rutledge Reviewed-by: Simon Hausmann --- src/widgets/doc/snippets/code/src_gui_kernel_qapplication.cpp | 2 +- src/widgets/kernel/qapplication.cpp | 1 + src/widgets/kernel/qapplication.h | 4 ++++ 3 files changed, 6 insertions(+), 1 deletion(-) (limited to 'src/widgets') 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 5e1f0883e7..a7bce6d378 100644 --- a/src/widgets/doc/snippets/code/src_gui_kernel_qapplication.cpp +++ b/src/widgets/doc/snippets/code/src_gui_kernel_qapplication.cpp @@ -93,7 +93,7 @@ int main(int argc, char *argv[]) //! [3] QSize MyWidget::sizeHint() const { - return QSize(80, 25).expandedTo(QApplication::globalStrut()); + return QSize(80, 25); } //! [3] diff --git a/src/widgets/kernel/qapplication.cpp b/src/widgets/kernel/qapplication.cpp index eea97b2c0b..842c0ea9e6 100644 --- a/src/widgets/kernel/qapplication.cpp +++ b/src/widgets/kernel/qapplication.cpp @@ -1224,6 +1224,7 @@ void QApplication::setColorSpec(int spec) \property QApplication::globalStrut \brief the minimum size that any GUI element that the user can interact with should have + \deprecated For example, no button should be resized to be smaller than the global strut size. The strut size should be considered when reimplementing GUI diff --git a/src/widgets/kernel/qapplication.h b/src/widgets/kernel/qapplication.h index 27e743a28d..6de72899f1 100644 --- a/src/widgets/kernel/qapplication.h +++ b/src/widgets/kernel/qapplication.h @@ -79,7 +79,9 @@ class Q_WIDGETS_EXPORT QApplication : public QGuiApplication #if QT_CONFIG(wheelevent) Q_PROPERTY(int wheelScrollLines READ wheelScrollLines WRITE setWheelScrollLines) #endif +#if QT_DEPRECATED_SINCE(5, 15) Q_PROPERTY(QSize globalStrut READ globalStrut WRITE setGlobalStrut) +#endif Q_PROPERTY(int startDragTime READ startDragTime WRITE setStartDragTime) Q_PROPERTY(int startDragDistance READ startDragDistance WRITE setStartDragDistance) #ifndef QT_NO_STYLE_STYLESHEET @@ -158,8 +160,10 @@ public: static void setWheelScrollLines(int); static int wheelScrollLines(); #endif +#if QT_DEPRECATED_SINCE(5, 15) static void setGlobalStrut(const QSize &); static QSize globalStrut(); +#endif static void setStartDragTime(int ms); static int startDragTime(); -- cgit v1.2.3 From 477dc115670d7c122d6590b9be10e076ebff8d08 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Thu, 16 Jan 2020 20:26:03 +0100 Subject: QTabBar: fix QStyleOptionTab::position During 556712f511a02ff8101e648d2e6f0090231d4f3d a small regression was introduced which set a wrong value for QStyleOptionTab::position. Fixes: QTBUG-81393 Change-Id: Ie8c66186b1b79c97bf77c7b139e08840233b7b66 Reviewed-by: Timur Pocheptsov --- src/widgets/widgets/qtabbar.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/widgets') diff --git a/src/widgets/widgets/qtabbar.cpp b/src/widgets/widgets/qtabbar.cpp index a7b115a1bc..df480629da 100644 --- a/src/widgets/widgets/qtabbar.cpp +++ b/src/widgets/widgets/qtabbar.cpp @@ -208,7 +208,7 @@ void QTabBarPrivate::initBasicStyleOption(QStyleOptionTab *option, int tabIndex) option->selectedPosition = QStyleOptionTab::NotAdjacent; const bool paintBeginning = (tabIndex == firstVisible) || (dragInProgress && tabIndex == pressedIndex + 1); - const bool paintEnd = (tabIndex == lastVisible - 1) || (dragInProgress && tabIndex == pressedIndex - 1); + const bool paintEnd = (tabIndex == lastVisible) || (dragInProgress && tabIndex == pressedIndex - 1); if (paintBeginning) { if (paintEnd) option->position = QStyleOptionTab::OnlyOneTab; -- cgit v1.2.3 From ef14e775de9932fecea5443b976b950c311ba938 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Thu, 5 Dec 2019 09:02:21 +0100 Subject: QMenu: Move exec(), popup() to private class Task-number: QTBUG-78966 Change-Id: I69257dc52706449a1e0babfc29e5f93f63d9291b Reviewed-by: Volker Hilsheimer Reviewed-by: Richard Moe Gustavsen --- src/widgets/widgets/qmenu.cpp | 180 ++++++++++++++++++++++-------------------- src/widgets/widgets/qmenu_p.h | 2 + 2 files changed, 98 insertions(+), 84 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/widgets/qmenu.cpp b/src/widgets/widgets/qmenu.cpp index 8ba5b98fa9..e3e3b07d71 100644 --- a/src/widgets/widgets/qmenu.cpp +++ b/src/widgets/widgets/qmenu.cpp @@ -2319,76 +2319,82 @@ QSize QMenu::sizeHint() const void QMenu::popup(const QPoint &p, QAction *atAction) { Q_D(QMenu); - if (d->scroll) { // reset scroll state from last popup - if (d->scroll->scrollOffset) - d->itemsDirty = 1; // sizeHint will be incorrect if there is previous scroll - d->scroll->scrollOffset = 0; - d->scroll->scrollFlags = QMenuPrivate::QMenuScroller::ScrollNone; + d->popup(p, atAction); +} + +void QMenuPrivate::popup(const QPoint &p, QAction *atAction) +{ + Q_Q(QMenu); + if (scroll) { // reset scroll state from last popup + if (scroll->scrollOffset) + itemsDirty = 1; // sizeHint will be incorrect if there is previous scroll + scroll->scrollOffset = 0; + scroll->scrollFlags = QMenuPrivate::QMenuScroller::ScrollNone; } - d->tearoffHighlighted = 0; - d->motions = 0; - d->doChildEffects = true; - d->updateLayoutDirection(); + tearoffHighlighted = 0; + motions = 0; + doChildEffects = true; + updateLayoutDirection(); // Ensure that we get correct sizeHints by placing this window on the correct screen. // However if the QMenu was constructed with a QDesktopScreenWidget as its parent, // then initialScreenIndex was set, so we should respect that for the lifetime of this menu. // Use d->popupScreen to remember, because initialScreenIndex will be reset after the first showing. // However if eventLoop exists, then exec() already did this by calling createWinId(); so leave it alone. (QTBUG-76162) - if (!d->eventLoop) { - const int screenIndex = d->topData()->initialScreenIndex; + if (!eventLoop) { + const int screenIndex = topData()->initialScreenIndex; if (screenIndex >= 0) - d->popupScreen = screenIndex; - if (auto s = QGuiApplication::screens().value(d->popupScreen)) { - if (d->setScreen(s)) - d->itemsDirty = true; - } else if (d->setScreenForPoint(p)) { - d->itemsDirty = true; + popupScreen = screenIndex; + if (auto s = QGuiApplication::screens().value(popupScreen)) { + if (setScreen(s)) + itemsDirty = true; + } else if (setScreenForPoint(p)) { + itemsDirty = true; } } - const bool contextMenu = d->isContextMenu(); - if (d->lastContextMenu != contextMenu) { - d->itemsDirty = true; - d->lastContextMenu = contextMenu; + const bool contextMenu = isContextMenu(); + if (lastContextMenu != contextMenu) { + itemsDirty = true; + lastContextMenu = contextMenu; } #if QT_CONFIG(menubar) // if this menu is part of a chain attached to a QMenuBar, set the // _NET_WM_WINDOW_TYPE_DROPDOWN_MENU X11 window type - setAttribute(Qt::WA_X11NetWmWindowTypeDropDownMenu, qobject_cast(d->topCausedWidget()) != 0); + q->setAttribute(Qt::WA_X11NetWmWindowTypeDropDownMenu, qobject_cast(topCausedWidget()) != nullptr); #endif - ensurePolished(); // Get the right font - emit aboutToShow(); - const bool actionListChanged = d->itemsDirty; + q->ensurePolished(); // Get the right font + emit q->aboutToShow(); + const bool actionListChanged = itemsDirty; QRect screen; #if QT_CONFIG(graphicsview) - bool isEmbedded = !bypassGraphicsProxyWidget(this) && QMenuPrivate::nearestGraphicsProxyWidget(this); + bool isEmbedded = !bypassGraphicsProxyWidget(q) && QMenuPrivate::nearestGraphicsProxyWidget(q); if (isEmbedded) - screen = d->popupGeometry(); + screen = popupGeometry(); else #endif - screen = d->popupGeometry(QDesktopWidgetPrivate::screenNumber(p)); - d->updateActionRects(screen); + screen = popupGeometry(QDesktopWidgetPrivate::screenNumber(p)); + updateActionRects(screen); QPoint pos; - QPushButton *causedButton = qobject_cast(d->causedPopup.widget); + QPushButton *causedButton = qobject_cast(causedPopup.widget); if (actionListChanged && causedButton) pos = QPushButtonPrivate::get(causedButton)->adjustedMenuPosition(); else pos = p; - const QSize menuSizeHint(sizeHint()); + const QSize menuSizeHint(q->sizeHint()); QSize size = menuSizeHint; - const int desktopFrame = style()->pixelMetric(QStyle::PM_MenuDesktopFrameWidth, nullptr, this); - bool adjustToDesktop = !window()->testAttribute(Qt::WA_DontShowOnScreen); + const int desktopFrame = q->style()->pixelMetric(QStyle::PM_MenuDesktopFrameWidth, nullptr, q); + bool adjustToDesktop = !q->window()->testAttribute(Qt::WA_DontShowOnScreen); // if the screens have very different geometries and the menu is too big, we have to recalculate if ((size.height() > screen.height() || size.width() > screen.width()) || // Layout is not right, we might be able to save horizontal space - (d->ncols >1 && size.height() < screen.height())) { + (ncols >1 && size.height() < screen.height())) { size.setWidth(qMin(menuSizeHint.width(), screen.width() - desktopFrame * 2)); size.setHeight(qMin(menuSizeHint.height(), screen.height() - desktopFrame * 2)); adjustToDesktop = true; @@ -2397,61 +2403,61 @@ void QMenu::popup(const QPoint &p, QAction *atAction) #ifdef QT_KEYPAD_NAVIGATION if (!atAction && QApplicationPrivate::keypadNavigationEnabled()) { // Try to have one item activated - if (d->defaultAction && d->defaultAction->isEnabled()) { - atAction = d->defaultAction; + if (defaultAction && defaultAction->isEnabled()) { + atAction = defaultAction; // TODO: This works for first level menus, not yet sub menus } else { - for (QAction *action : qAsConst(d->actions)) + for (QAction *action : qAsConst(actions)) if (action->isEnabled()) { atAction = action; break; } } - d->currentAction = atAction; + currentAction = atAction; } #endif - if (d->ncols > 1) { + if (ncols > 1) { pos.setY(screen.top() + desktopFrame); } else if (atAction) { - for (int i = 0, above_height = 0; i < d->actions.count(); i++) { - QAction *action = d->actions.at(i); + for (int i = 0, above_height = 0; i < actions.count(); i++) { + QAction *action = actions.at(i); if (action == atAction) { int newY = pos.y() - above_height; - if (d->scroll && newY < desktopFrame) { - d->scroll->scrollFlags = d->scroll->scrollFlags + if (scroll && newY < desktopFrame) { + scroll->scrollFlags = scroll->scrollFlags | QMenuPrivate::QMenuScroller::ScrollUp; - d->scroll->scrollOffset = newY; + scroll->scrollOffset = newY; newY = desktopFrame; } pos.setY(newY); - if (d->scroll && d->scroll->scrollFlags != QMenuPrivate::QMenuScroller::ScrollNone - && !style()->styleHint(QStyle::SH_Menu_FillScreenWithScroll, nullptr, this)) { - int below_height = above_height + d->scroll->scrollOffset; - for (int i2 = i; i2 < d->actionRects.count(); i2++) - below_height += d->actionRects.at(i2).height(); + if (scroll && scroll->scrollFlags != QMenuPrivate::QMenuScroller::ScrollNone + && !q->style()->styleHint(QStyle::SH_Menu_FillScreenWithScroll, nullptr, q)) { + int below_height = above_height + scroll->scrollOffset; + for (int i2 = i; i2 < actionRects.count(); i2++) + below_height += actionRects.at(i2).height(); size.setHeight(below_height); } break; } else { - above_height += d->actionRects.at(i).height(); + above_height += actionRects.at(i).height(); } } } QPoint mouse = QCursor::pos(); - d->mousePopupPos = mouse; - const bool snapToMouse = !d->causedPopup.widget && (QRect(p.x() - 3, p.y() - 3, 6, 6).contains(mouse)); + mousePopupPos = mouse; + const bool snapToMouse = !causedPopup.widget && (QRect(p.x() - 3, p.y() - 3, 6, 6).contains(mouse)); if (adjustToDesktop) { // handle popup falling "off screen" - if (isRightToLeft()) { + if (q->isRightToLeft()) { if (snapToMouse) // position flowing left from the mouse pos.setX(mouse.x() - size.width()); #if QT_CONFIG(menubar) // if the menu is in a menubar or is a submenu, it should be right-aligned - if (qobject_cast(d->causedPopup.widget) || qobject_cast(d->causedPopup.widget)) + if (qobject_cast(causedPopup.widget) || qobject_cast(causedPopup.widget)) pos.rx() -= size.width(); #endif // QT_CONFIG(menubar) @@ -2475,8 +2481,8 @@ void QMenu::popup(const QPoint &p, QAction *atAction) if (pos.y() < screen.top() + desktopFrame) pos.setY(screen.top() + desktopFrame); if (pos.y() + menuSizeHint.height() - 1 > screen.bottom() - desktopFrame) { - if (d->scroll) { - d->scroll->scrollFlags |= uint(QMenuPrivate::QMenuScroller::ScrollDown); + if (scroll) { + scroll->scrollFlags |= uint(QMenuPrivate::QMenuScroller::ScrollDown); int y = qMax(screen.y(),pos.y()); size.setHeight(screen.bottom() - (desktopFrame * 2) - y); } else { @@ -2485,13 +2491,13 @@ void QMenu::popup(const QPoint &p, QAction *atAction) } } } - const int subMenuOffset = style()->pixelMetric(QStyle::PM_SubMenuOverlap, nullptr, this); - QMenu *caused = qobject_cast(d_func()->causedPopup.widget); + const int subMenuOffset = q->style()->pixelMetric(QStyle::PM_SubMenuOverlap, nullptr, q); + QMenu *caused = qobject_cast(causedPopup.widget); if (caused && caused->geometry().width() + menuSizeHint.width() + subMenuOffset < screen.width()) { QRect parentActionRect(caused->d_func()->actionRect(caused->d_func()->currentAction)); const QPoint actionTopLeft = caused->mapToGlobal(parentActionRect.topLeft()); parentActionRect.moveTopLeft(actionTopLeft); - if (isRightToLeft()) { + if (q->isRightToLeft()) { if ((pos.x() + menuSizeHint.width() > parentActionRect.left() - subMenuOffset) && (pos.x() < parentActionRect.right())) { @@ -2513,61 +2519,61 @@ void QMenu::popup(const QPoint &p, QAction *atAction) } } } - setGeometry(QRect(pos, size)); + q->setGeometry(QRect(pos, size)); #if QT_CONFIG(effects) - int hGuess = isRightToLeft() ? QEffects::LeftScroll : QEffects::RightScroll; + int hGuess = q->isRightToLeft() ? QEffects::LeftScroll : QEffects::RightScroll; int vGuess = QEffects::DownScroll; - if (isRightToLeft()) { + if (q->isRightToLeft()) { if ((snapToMouse && (pos.x() + size.width() / 2 > mouse.x())) || - (qobject_cast(d->causedPopup.widget) && pos.x() + size.width() / 2 > d->causedPopup.widget->x())) + (qobject_cast(causedPopup.widget) && pos.x() + size.width() / 2 > causedPopup.widget->x())) hGuess = QEffects::RightScroll; } else { if ((snapToMouse && (pos.x() + size.width() / 2 < mouse.x())) || - (qobject_cast(d->causedPopup.widget) && pos.x() + size.width() / 2 < d->causedPopup.widget->x())) + (qobject_cast(causedPopup.widget) && pos.x() + size.width() / 2 < causedPopup.widget->x())) hGuess = QEffects::LeftScroll; } #if QT_CONFIG(menubar) if ((snapToMouse && (pos.y() + size.height() / 2 < mouse.y())) || - (qobject_cast(d->causedPopup.widget) && - pos.y() + size.width() / 2 < d->causedPopup.widget->mapToGlobal(d->causedPopup.widget->pos()).y())) + (qobject_cast(causedPopup.widget) && + pos.y() + size.width() / 2 < causedPopup.widget->mapToGlobal(causedPopup.widget->pos()).y())) vGuess = QEffects::UpScroll; #endif if (QApplication::isEffectEnabled(Qt::UI_AnimateMenu)) { bool doChildEffects = true; #if QT_CONFIG(menubar) - if (QMenuBar *mb = qobject_cast(d->causedPopup.widget)) { + if (QMenuBar *mb = qobject_cast(causedPopup.widget)) { doChildEffects = mb->d_func()->doChildEffects; mb->d_func()->doChildEffects = false; } else #endif - if (QMenu *m = qobject_cast(d->causedPopup.widget)) { + if (QMenu *m = qobject_cast(causedPopup.widget)) { doChildEffects = m->d_func()->doChildEffects; m->d_func()->doChildEffects = false; } if (doChildEffects) { if (QApplication::isEffectEnabled(Qt::UI_FadeMenu)) - qFadeEffect(this); - else if (d->causedPopup.widget) - qScrollEffect(this, qobject_cast(d->causedPopup.widget) ? hGuess : vGuess); + qFadeEffect(q); + else if (causedPopup.widget) + qScrollEffect(q, qobject_cast(causedPopup.widget) ? hGuess : vGuess); else - qScrollEffect(this, hGuess | vGuess); + qScrollEffect(q, hGuess | vGuess); } else { // kill any running effect qFadeEffect(nullptr); qScrollEffect(nullptr); - show(); + q->show(); } } else #endif { - show(); + q->show(); } #ifndef QT_NO_ACCESSIBILITY - QAccessibleEvent event(this, QAccessible::PopupMenuStart); + QAccessibleEvent event(q, QAccessible::PopupMenuStart); QAccessible::updateAccessibility(&event); #endif } @@ -2633,20 +2639,26 @@ QAction *QMenu::exec() QAction *QMenu::exec(const QPoint &p, QAction *action) { Q_D(QMenu); - ensurePolished(); - createWinId(); - QEventLoop eventLoop; - d->eventLoop = &eventLoop; + return d->exec(p, action); +} + +QAction *QMenuPrivate::exec(const QPoint &p, QAction *action) +{ + Q_Q(QMenu); + q->ensurePolished(); + q->createWinId(); + QEventLoop evtLoop; + eventLoop = &evtLoop; popup(p, action); - QPointer guard = this; - (void) eventLoop.exec(); + QPointer guard = q; + (void) evtLoop.exec(); if (guard.isNull()) return nullptr; - action = d->syncAction; - d->syncAction = nullptr; - d->eventLoop = nullptr; + action = syncAction; + syncAction = nullptr; + eventLoop = nullptr; return action; } diff --git a/src/widgets/widgets/qmenu_p.h b/src/widgets/widgets/qmenu_p.h index efbbc099a1..7d2d0ab487 100644 --- a/src/widgets/widgets/qmenu_p.h +++ b/src/widgets/widgets/qmenu_p.h @@ -351,6 +351,8 @@ public: QRect popupGeometry(int screen) const; bool useFullScreenForPopup() const; int getLastVisibleAction() const; + void popup(const QPoint &p, QAction *atAction); + QAction *exec(const QPoint &p, QAction *action); //selection static QMenu *mouseDown; -- cgit v1.2.3 From a78d66743171557d79b16c08be775e3ac15bb4ef Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Thu, 5 Dec 2019 09:33:50 +0100 Subject: Fix positioning of dynamically populated QToolButton::MenuButtonPopup's in screen corners The existing code positioning the menu in QToolButtonPrivate::popupTimerDone() had a clause checking whether any receivers were connnected to QMenu::aboutToShow() causing the sizeHint to be -1,-1 in that case (apparently trying to accommodate menus populated in slots). In that case, the checking for screen borders would not work, causing the similar checks in QMenu::popup() to trigger, potentially positioning the menu over the mouse. To solve this dilemma, add a parameter taking a std::function calulating the position of the menu from the sizeHint to QMenuPrivate::exec()/popup() and invoke that in QMenuPrivate::popup() after emitting QMenu::aboutToShow() when the sizeHint is known. Fixes: QTBUG-78966 Change-Id: I180bd2dc7eadcaca6cadca13745ed4a2dd89e412 Reviewed-by: Volker Hilsheimer --- src/widgets/widgets/qmenu.cpp | 10 ++++-- src/widgets/widgets/qmenu_p.h | 8 +++-- src/widgets/widgets/qtoolbutton.cpp | 67 +++++++++++++++++++++---------------- 3 files changed, 51 insertions(+), 34 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/widgets/qmenu.cpp b/src/widgets/widgets/qmenu.cpp index e3e3b07d71..701035fc32 100644 --- a/src/widgets/widgets/qmenu.cpp +++ b/src/widgets/widgets/qmenu.cpp @@ -2322,7 +2322,7 @@ void QMenu::popup(const QPoint &p, QAction *atAction) d->popup(p, atAction); } -void QMenuPrivate::popup(const QPoint &p, QAction *atAction) +void QMenuPrivate::popup(const QPoint &p, QAction *atAction, PositionFunction positionFunction) { Q_Q(QMenu); if (scroll) { // reset scroll state from last popup @@ -2388,6 +2388,10 @@ void QMenuPrivate::popup(const QPoint &p, QAction *atAction) const QSize menuSizeHint(q->sizeHint()); QSize size = menuSizeHint; + + if (positionFunction) + pos = positionFunction(menuSizeHint); + const int desktopFrame = q->style()->pixelMetric(QStyle::PM_MenuDesktopFrameWidth, nullptr, q); bool adjustToDesktop = !q->window()->testAttribute(Qt::WA_DontShowOnScreen); @@ -2642,14 +2646,14 @@ QAction *QMenu::exec(const QPoint &p, QAction *action) return d->exec(p, action); } -QAction *QMenuPrivate::exec(const QPoint &p, QAction *action) +QAction *QMenuPrivate::exec(const QPoint &p, QAction *action, PositionFunction positionFunction) { Q_Q(QMenu); q->ensurePolished(); q->createWinId(); QEventLoop evtLoop; eventLoop = &evtLoop; - popup(p, action); + popup(p, action, positionFunction); QPointer guard = q; (void) evtLoop.exec(); diff --git a/src/widgets/widgets/qmenu_p.h b/src/widgets/widgets/qmenu_p.h index 7d2d0ab487..02fe9f31a1 100644 --- a/src/widgets/widgets/qmenu_p.h +++ b/src/widgets/widgets/qmenu_p.h @@ -64,6 +64,8 @@ #include +#include + QT_REQUIRE_CONFIG(menu); QT_BEGIN_NAMESPACE @@ -302,6 +304,8 @@ class QMenuPrivate : public QWidgetPrivate { Q_DECLARE_PUBLIC(QMenu) public: + using PositionFunction = std::function; + QMenuPrivate() : itemsDirty(false), hasCheckableItems(false), @@ -351,8 +355,8 @@ public: QRect popupGeometry(int screen) const; bool useFullScreenForPopup() const; int getLastVisibleAction() const; - void popup(const QPoint &p, QAction *atAction); - QAction *exec(const QPoint &p, QAction *action); + void popup(const QPoint &p, QAction *atAction, PositionFunction positionFunction = {}); + QAction *exec(const QPoint &p, QAction *action, PositionFunction positionFunction = {}); //selection static QMenu *mouseDown; diff --git a/src/widgets/widgets/qtoolbutton.cpp b/src/widgets/widgets/qtoolbutton.cpp index 263fe5d8ce..314c6ab40c 100644 --- a/src/widgets/widgets/qtoolbutton.cpp +++ b/src/widgets/widgets/qtoolbutton.cpp @@ -723,38 +723,12 @@ void QToolButtonPrivate::_q_buttonReleased() popupTimer.stop(); } -void QToolButtonPrivate::popupTimerDone() +static QPoint positionMenu(const QToolButton *q, bool horizontal, + const QSize &sh) { - Q_Q(QToolButton); - popupTimer.stop(); - if (!menuButtonDown && !down) - return; - - menuButtonDown = true; - QPointer actualMenu; - bool mustDeleteActualMenu = false; - if(menuAction) { - actualMenu = menuAction->menu(); - } else if (defaultAction && defaultAction->menu()) { - actualMenu = defaultAction->menu(); - } else { - actualMenu = new QMenu(q); - mustDeleteActualMenu = true; - for(int i = 0; i < actions.size(); i++) - actualMenu->addAction(actions.at(i)); - } - repeat = q->autoRepeat(); - q->setAutoRepeat(false); - bool horizontal = true; -#if QT_CONFIG(toolbar) - QToolBar *tb = qobject_cast(parent); - if (tb && tb->orientation() == Qt::Vertical) - horizontal = false; -#endif QPoint p; const QRect rect = q->rect(); // Find screen via point in case of QGraphicsProxyWidget. QRect screen = QDesktopWidgetPrivate::availableGeometry(q->mapToGlobal(rect.center())); - QSize sh = ((QToolButton*)(QMenu*)actualMenu)->receivers(SIGNAL(aboutToShow()))? QSize() : actualMenu->sizeHint(); if (horizontal) { if (q->isRightToLeft()) { if (q->mapToGlobal(QPoint(0, rect.bottom())).y() + sh.height() <= screen.bottom()) { @@ -788,6 +762,37 @@ void QToolButtonPrivate::popupTimerDone() } p.rx() = qMax(screen.left(), qMin(p.x(), screen.right() - sh.width())); p.ry() += 1; + return p; +} + +void QToolButtonPrivate::popupTimerDone() +{ + Q_Q(QToolButton); + popupTimer.stop(); + if (!menuButtonDown && !down) + return; + + menuButtonDown = true; + QPointer actualMenu; + bool mustDeleteActualMenu = false; + if (menuAction) { + actualMenu = menuAction->menu(); + } else if (defaultAction && defaultAction->menu()) { + actualMenu = defaultAction->menu(); + } else { + actualMenu = new QMenu(q); + mustDeleteActualMenu = true; + for (int i = 0; i < actions.size(); i++) + actualMenu->addAction(actions.at(i)); + } + repeat = q->autoRepeat(); + q->setAutoRepeat(false); + bool horizontal = true; +#if QT_CONFIG(toolbar) + QToolBar *tb = qobject_cast(parent); + if (tb && tb->orientation() == Qt::Vertical) + horizontal = false; +#endif QPointer that = q; actualMenu->setNoReplayFor(q); if (!mustDeleteActualMenu) //only if action are not in this widget @@ -796,7 +801,11 @@ void QToolButtonPrivate::popupTimerDone() actualMenu->d_func()->causedPopup.widget = q; actualMenu->d_func()->causedPopup.action = defaultAction; actionsCopy = q->actions(); //(the list of action may be modified in slots) - actualMenu->exec(p); + + // QTBUG-78966, Delay positioning until after aboutToShow(). + auto positionFunction = [q, horizontal](const QSize &sizeHint) { + return positionMenu(q, horizontal, sizeHint); }; + actualMenu->d_func()->exec({}, nullptr, positionFunction); if (!that) return; -- cgit v1.2.3 From 73d1476fb1397948a4d806bd921fce372bd8d63b Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Mon, 2 Dec 2019 17:54:48 +0100 Subject: Replace most use of QVariant::type and occurrences of QVariant::Type I made a clazy automated check that replaced the use of QVariant::Type by the equivalent in QMetaType. This has been deprecated since Qt 5.0, but many uses were not yet removed. In addition, there was some manual changes to fix the compilation errors. Adapted the Private API of QDateTimeParser and QMimeDataPrivate and adjust QDateTimeEdit and QSpinBox. QVariant(QVariant::Invalid) in qstylesheet made no sense. But note that in QVariant::save, we actually wanted to use the non-user type. In the SQL module, many changes were actually reverted because the API still expects QVarient::Type. Change-Id: I98c368490e4ee465ed3a3b63bda8b8eaa50ea67e Reviewed-by: Lars Knoll --- src/widgets/dialogs/qsidebar.cpp | 2 +- src/widgets/graphicsview/qgraphicsitem.cpp | 8 +-- src/widgets/graphicsview/qgraphicsproxywidget.cpp | 10 ++-- src/widgets/graphicsview/qgraphicsscene.cpp | 8 +-- src/widgets/graphicsview/qgraphicsview.cpp | 8 +-- src/widgets/itemviews/qabstractitemdelegate.cpp | 18 +++--- src/widgets/itemviews/qabstractitemview.cpp | 2 +- src/widgets/itemviews/qheaderview.cpp | 2 +- src/widgets/itemviews/qitemdelegate.cpp | 22 +++---- src/widgets/itemviews/qitemeditorfactory.cpp | 34 +++++------ src/widgets/itemviews/qstyleditemdelegate.cpp | 10 ++-- src/widgets/kernel/qsizepolicy.cpp | 2 +- src/widgets/kernel/qwidgetsvariant.cpp | 12 ++-- src/widgets/styles/qstylesheetstyle.cpp | 31 +++++----- src/widgets/widgets/qabstractspinbox.cpp | 70 +++++++++++------------ src/widgets/widgets/qabstractspinbox_p.h | 2 +- src/widgets/widgets/qcombobox.cpp | 8 +-- src/widgets/widgets/qdatetimeedit.cpp | 32 +++++++---- src/widgets/widgets/qdatetimeedit.h | 3 + src/widgets/widgets/qplaintextedit.cpp | 20 +++---- src/widgets/widgets/qspinbox.cpp | 4 +- src/widgets/widgets/qtextbrowser.cpp | 4 +- src/widgets/widgets/qtextedit.cpp | 24 ++++---- 23 files changed, 173 insertions(+), 163 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/dialogs/qsidebar.cpp b/src/widgets/dialogs/qsidebar.cpp index dfb707eda0..4272b612ec 100644 --- a/src/widgets/dialogs/qsidebar.cpp +++ b/src/widgets/dialogs/qsidebar.cpp @@ -163,7 +163,7 @@ bool QUrlModel::dropMimeData(const QMimeData *data, Qt::DropAction action, */ bool QUrlModel::setData(const QModelIndex &index, const QVariant &value, int role) { - if (value.type() == QVariant::Url) { + if (value.userType() == QMetaType::QUrl) { QUrl url = value.toUrl(); QModelIndex dirIndex = fileSystemModel->index(url.toLocalFile()); //On windows the popup display the "C:\", convert to nativeSeparators diff --git a/src/widgets/graphicsview/qgraphicsitem.cpp b/src/widgets/graphicsview/qgraphicsitem.cpp index 6f1eb4b346..a2120e53fe 100644 --- a/src/widgets/graphicsview/qgraphicsitem.cpp +++ b/src/widgets/graphicsview/qgraphicsitem.cpp @@ -10511,13 +10511,13 @@ QVariant QGraphicsTextItem::inputMethodQuery(Qt::InputMethodQuery query) const v = int(inputMethodHints()); else if (dd->control) v = dd->control->inputMethodQuery(query, QVariant()); - if (v.type() == QVariant::RectF) + if (v.userType() == QMetaType::QRectF) v = v.toRectF().translated(-dd->controlOffset()); - else if (v.type() == QVariant::PointF) + else if (v.userType() == QMetaType::QPointF) v = v.toPointF() - dd->controlOffset(); - else if (v.type() == QVariant::Rect) + else if (v.userType() == QMetaType::QRect) v = v.toRect().translated(-dd->controlOffset().toPoint()); - else if (v.type() == QVariant::Point) + else if (v.userType() == QMetaType::QPoint) v = v.toPoint() - dd->controlOffset().toPoint(); return v; } diff --git a/src/widgets/graphicsview/qgraphicsproxywidget.cpp b/src/widgets/graphicsview/qgraphicsproxywidget.cpp index 4d4958c674..eb8acf1f27 100644 --- a/src/widgets/graphicsview/qgraphicsproxywidget.cpp +++ b/src/widgets/graphicsview/qgraphicsproxywidget.cpp @@ -1441,17 +1441,17 @@ QVariant QGraphicsProxyWidget::inputMethodQuery(Qt::InputMethodQuery query) cons focusWidget = d->widget; QVariant v = focusWidget->inputMethodQuery(query); QPointF focusWidgetPos = subWidgetRect(focusWidget).topLeft(); - switch (v.type()) { - case QVariant::RectF: + switch (v.userType()) { + case QMetaType::QRectF: v = v.toRectF().translated(focusWidgetPos); break; - case QVariant::PointF: + case QMetaType::QPointF: v = v.toPointF() + focusWidgetPos; break; - case QVariant::Rect: + case QMetaType::QRect: v = v.toRect().translated(focusWidgetPos.toPoint()); break; - case QVariant::Point: + case QMetaType::QPoint: v = v.toPoint() + focusWidgetPos.toPoint(); break; default: diff --git a/src/widgets/graphicsview/qgraphicsscene.cpp b/src/widgets/graphicsview/qgraphicsscene.cpp index 1c6e68def1..1cb24f74b6 100644 --- a/src/widgets/graphicsview/qgraphicsscene.cpp +++ b/src/widgets/graphicsview/qgraphicsscene.cpp @@ -3190,13 +3190,13 @@ QVariant QGraphicsScene::inputMethodQuery(Qt::InputMethodQuery query) const return QVariant(); const QTransform matrix = d->focusItem->sceneTransform(); QVariant value = d->focusItem->inputMethodQuery(query); - if (value.type() == QVariant::RectF) + if (value.userType() == QMetaType::QRectF) value = matrix.mapRect(value.toRectF()); - else if (value.type() == QVariant::PointF) + else if (value.userType() == QMetaType::QPointF) value = matrix.map(value.toPointF()); - else if (value.type() == QVariant::Rect) + else if (value.userType() == QMetaType::QRect) value = matrix.mapRect(value.toRect()); - else if (value.type() == QVariant::Point) + else if (value.userType() == QMetaType::QPoint) value = matrix.map(value.toPoint()); return value; } diff --git a/src/widgets/graphicsview/qgraphicsview.cpp b/src/widgets/graphicsview/qgraphicsview.cpp index 7589a1ebbd..e1a829f779 100644 --- a/src/widgets/graphicsview/qgraphicsview.cpp +++ b/src/widgets/graphicsview/qgraphicsview.cpp @@ -2589,13 +2589,13 @@ QVariant QGraphicsView::inputMethodQuery(Qt::InputMethodQuery query) const return QVariant(); QVariant value = d->scene->inputMethodQuery(query); - if (value.type() == QVariant::RectF) + if (value.userType() == QMetaType::QRectF) value = d->mapRectFromScene(value.toRectF()); - else if (value.type() == QVariant::PointF) + else if (value.userType() == QMetaType::QPointF) value = mapFromScene(value.toPointF()); - else if (value.type() == QVariant::Rect) + else if (value.userType() == QMetaType::QRect) value = d->mapRectFromScene(value.toRect()).toRect(); - else if (value.type() == QVariant::Point) + else if (value.userType() == QMetaType::QPoint) value = mapFromScene(value.toPoint()); return value; } diff --git a/src/widgets/itemviews/qabstractitemdelegate.cpp b/src/widgets/itemviews/qabstractitemdelegate.cpp index bb47881c03..c5b22b5667 100644 --- a/src/widgets/itemviews/qabstractitemdelegate.cpp +++ b/src/widgets/itemviews/qabstractitemdelegate.cpp @@ -585,27 +585,27 @@ QString QAbstractItemDelegatePrivate::textForRole(Qt::ItemDataRole role, const Q case QMetaType::Float: text = locale.toString(value.toFloat()); break; - case QVariant::Double: + case QMetaType::Double: text = locale.toString(value.toDouble(), 'g', precision); break; - case QVariant::Int: - case QVariant::LongLong: + case QMetaType::Int: + case QMetaType::LongLong: text = locale.toString(value.toLongLong()); break; - case QVariant::UInt: - case QVariant::ULongLong: + case QMetaType::UInt: + case QMetaType::ULongLong: text = locale.toString(value.toULongLong()); break; - case QVariant::Date: + case QMetaType::QDate: text = locale.toString(value.toDate(), formatType); break; - case QVariant::Time: + case QMetaType::QTime: text = locale.toString(value.toTime(), formatType); break; - case QVariant::DateTime: + case QMetaType::QDateTime: text = locale.toString(value.toDateTime(), formatType); break; - case QVariant::Type(QMetaType::QJsonValue): { + case QMetaType::QJsonValue: { const QJsonValue val = value.toJsonValue(); if (val.isBool()) { text = QVariant(val.toBool()).toString(); diff --git a/src/widgets/itemviews/qabstractitemview.cpp b/src/widgets/itemviews/qabstractitemview.cpp index 0e54cf235f..2524d4acfa 100644 --- a/src/widgets/itemviews/qabstractitemview.cpp +++ b/src/widgets/itemviews/qabstractitemview.cpp @@ -2339,7 +2339,7 @@ void QAbstractItemView::keyPressEvent(QKeyEvent *event) QVariant variant; if (d->model) variant = d->model->data(currentIndex(), Qt::DisplayRole); - if (variant.type() == QVariant::String) + if (variant.userType() == QMetaType::QString) QGuiApplication::clipboard()->setText(variant.toString()); event->accept(); } diff --git a/src/widgets/itemviews/qheaderview.cpp b/src/widgets/itemviews/qheaderview.cpp index 790f305463..84e2fd72a9 100644 --- a/src/widgets/itemviews/qheaderview.cpp +++ b/src/widgets/itemviews/qheaderview.cpp @@ -3660,7 +3660,7 @@ void QHeaderViewPrivate::flipSortIndicator(int section) sortOrder = (sortIndicatorOrder == Qt::DescendingOrder) ? Qt::AscendingOrder : Qt::DescendingOrder; } else { const QVariant value = model->headerData(section, orientation, Qt::InitialSortOrderRole); - if (value.canConvert(QVariant::Int)) + if (value.canConvert(QMetaType::Int)) sortOrder = static_cast(value.toInt()); else sortOrder = Qt::AscendingOrder; diff --git a/src/widgets/itemviews/qitemdelegate.cpp b/src/widgets/itemviews/qitemdelegate.cpp index daea907963..4420d39b8e 100644 --- a/src/widgets/itemviews/qitemdelegate.cpp +++ b/src/widgets/itemviews/qitemdelegate.cpp @@ -414,7 +414,7 @@ void QItemDelegate::paint(QPainter *painter, if (value.isValid()) { // ### we need the pixmap to call the virtual function pixmap = decoration(opt, value); - if (value.type() == QVariant::Icon) { + if (value.userType() == QMetaType::QIcon) { d->tmp.icon = qvariant_cast(value); d->tmp.mode = d->iconMode(option.state); d->tmp.state = d->iconState(option.state); @@ -969,12 +969,12 @@ void QItemDelegate::doLayout(const QStyleOptionViewItem &option, QPixmap QItemDelegate::decoration(const QStyleOptionViewItem &option, const QVariant &variant) const { Q_D(const QItemDelegate); - switch (variant.type()) { - case QVariant::Icon: { + switch (variant.userType()) { + case QMetaType::QIcon: { QIcon::Mode mode = d->iconMode(option.state); QIcon::State state = d->iconState(option.state); return qvariant_cast(variant).pixmap(option.decorationSize, mode, state); } - case QVariant::Color: { + case QMetaType::QColor: { static QPixmap pixmap(option.decorationSize); pixmap.fill(qvariant_cast(variant)); return pixmap; } @@ -1060,24 +1060,24 @@ QRect QItemDelegate::rect(const QStyleOptionViewItem &option, if (role == Qt::CheckStateRole) return doCheck(option, option.rect, value); if (value.isValid() && !value.isNull()) { - switch (value.type()) { - case QVariant::Invalid: + switch (value.userType()) { + case QMetaType::UnknownType: break; - case QVariant::Pixmap: { + case QMetaType::QPixmap: { const QPixmap &pixmap = qvariant_cast(value); return QRect(QPoint(0, 0), pixmap.size() / pixmap.devicePixelRatio() ); } - case QVariant::Image: { + case QMetaType::QImage: { const QImage &image = qvariant_cast(value); return QRect(QPoint(0, 0), image.size() / image.devicePixelRatio() ); } - case QVariant::Icon: { + case QMetaType::QIcon: { QIcon::Mode mode = d->iconMode(option.state); QIcon::State state = d->iconState(option.state); QIcon icon = qvariant_cast(value); QSize size = icon.actualSize(option.decorationSize, mode, state); return QRect(QPoint(0, 0), size); } - case QVariant::Color: + case QMetaType::QColor: return QRect(QPoint(0, 0), option.decorationSize); - case QVariant::String: + case QMetaType::QString: default: { const QString text = d->valueToText(value, option); value = index.data(Qt::FontRole); diff --git a/src/widgets/itemviews/qitemeditorfactory.cpp b/src/widgets/itemviews/qitemeditorfactory.cpp index f874597d59..fe9b482122 100644 --- a/src/widgets/itemviews/qitemeditorfactory.cpp +++ b/src/widgets/itemviews/qitemeditorfactory.cpp @@ -241,21 +241,21 @@ QWidget *QDefaultItemEditorFactory::createEditor(int userType, QWidget *parent) { switch (userType) { #if QT_CONFIG(combobox) - case QVariant::Bool: { + case QMetaType::Bool: { QBooleanComboBox *cb = new QBooleanComboBox(parent); cb->setFrame(false); cb->setSizePolicy(QSizePolicy::Ignored, cb->sizePolicy().verticalPolicy()); return cb; } #endif #if QT_CONFIG(spinbox) - case QVariant::UInt: { + case QMetaType::UInt: { QSpinBox *sb = new QUIntSpinBox(parent); sb->setFrame(false); sb->setMinimum(0); sb->setMaximum(INT_MAX); sb->setSizePolicy(QSizePolicy::Ignored, sb->sizePolicy().verticalPolicy()); return sb; } - case QVariant::Int: { + case QMetaType::Int: { QSpinBox *sb = new QSpinBox(parent); sb->setFrame(false); sb->setMinimum(INT_MIN); @@ -264,25 +264,25 @@ QWidget *QDefaultItemEditorFactory::createEditor(int userType, QWidget *parent) return sb; } #endif #if QT_CONFIG(datetimeedit) - case QVariant::Date: { + case QMetaType::QDate: { QDateTimeEdit *ed = new QDateEdit(parent); ed->setFrame(false); return ed; } - case QVariant::Time: { + case QMetaType::QTime: { QDateTimeEdit *ed = new QTimeEdit(parent); ed->setFrame(false); return ed; } - case QVariant::DateTime: { + case QMetaType::QDateTime: { QDateTimeEdit *ed = new QDateTimeEdit(parent); ed->setFrame(false); return ed; } #endif #if QT_CONFIG(label) - case QVariant::Pixmap: + case QMetaType::QPixmap: return new QLabel(parent); #endif #if QT_CONFIG(spinbox) - case QVariant::Double: { + case QMetaType::Double: { QDoubleSpinBox *sb = new QDoubleSpinBox(parent); sb->setFrame(false); sb->setMinimum(-DBL_MAX); @@ -291,7 +291,7 @@ QWidget *QDefaultItemEditorFactory::createEditor(int userType, QWidget *parent) return sb; } #endif #if QT_CONFIG(lineedit) - case QVariant::String: + case QMetaType::QString: default: { // the default editor is a lineedit QExpandingLineEdit *le = new QExpandingLineEdit(parent); @@ -311,24 +311,24 @@ QByteArray QDefaultItemEditorFactory::valuePropertyName(int userType) const { switch (userType) { #if QT_CONFIG(combobox) - case QVariant::Bool: + case QMetaType::Bool: return "currentIndex"; #endif #if QT_CONFIG(spinbox) - case QVariant::UInt: - case QVariant::Int: - case QVariant::Double: + case QMetaType::UInt: + case QMetaType::Int: + case QMetaType::Double: return "value"; #endif #if QT_CONFIG(datetimeedit) - case QVariant::Date: + case QMetaType::QDate: return "date"; - case QVariant::Time: + case QMetaType::QTime: return "time"; - case QVariant::DateTime: + case QMetaType::QDateTime: return "dateTime"; #endif - case QVariant::String: + case QMetaType::QString: default: // the default editor is a lineedit return "text"; diff --git a/src/widgets/itemviews/qstyleditemdelegate.cpp b/src/widgets/itemviews/qstyleditemdelegate.cpp index f42af2ea00..c685cc7f05 100644 --- a/src/widgets/itemviews/qstyleditemdelegate.cpp +++ b/src/widgets/itemviews/qstyleditemdelegate.cpp @@ -302,8 +302,8 @@ void QStyledItemDelegate::initStyleOption(QStyleOptionViewItem *option, value = index.data(Qt::DecorationRole); if (value.isValid() && !value.isNull()) { option->features |= QStyleOptionViewItem::HasDecoration; - switch (value.type()) { - case QVariant::Icon: { + switch (value.userType()) { + case QMetaType::QIcon: { option->icon = qvariant_cast(value); QIcon::Mode mode; if (!(option->state & QStyle::State_Enabled)) @@ -319,19 +319,19 @@ void QStyledItemDelegate::initStyleOption(QStyleOptionViewItem *option, qMin(option->decorationSize.height(), actualSize.height())); break; } - case QVariant::Color: { + case QMetaType::QColor: { QPixmap pixmap(option->decorationSize); pixmap.fill(qvariant_cast(value)); option->icon = QIcon(pixmap); break; } - case QVariant::Image: { + case QMetaType::QImage: { QImage image = qvariant_cast(value); option->icon = QIcon(QPixmap::fromImage(image)); option->decorationSize = image.size() / image.devicePixelRatio(); break; } - case QVariant::Pixmap: { + case QMetaType::QPixmap: { QPixmap pixmap = qvariant_cast(value); option->icon = QIcon(pixmap); option->decorationSize = pixmap.size() / pixmap.devicePixelRatio(); diff --git a/src/widgets/kernel/qsizepolicy.cpp b/src/widgets/kernel/qsizepolicy.cpp index 54bf8fe0dc..c4372a9fbc 100644 --- a/src/widgets/kernel/qsizepolicy.cpp +++ b/src/widgets/kernel/qsizepolicy.cpp @@ -439,7 +439,7 @@ void QSizePolicy::setControlType(ControlType type) noexcept */ QSizePolicy::operator QVariant() const { - return QVariant(QVariant::SizePolicy, this); + return QVariant(QMetaType::QSizePolicy, this); } #ifndef QT_NO_DATASTREAM diff --git a/src/widgets/kernel/qwidgetsvariant.cpp b/src/widgets/kernel/qwidgetsvariant.cpp index 41600d2143..edb166e8d5 100644 --- a/src/widgets/kernel/qwidgetsvariant.cpp +++ b/src/widgets/kernel/qwidgetsvariant.cpp @@ -51,12 +51,12 @@ namespace { static void construct(QVariant::Private *x, const void *copy) { switch (x->type) { - case QVariant::SizePolicy: + case QMetaType::QSizePolicy: v_construct(x, copy); break; default: qWarning("Trying to construct an instance of an invalid type, type id: %i", x->type); - x->type = QVariant::Invalid; + x->type = QMetaType::UnknownType; return; } x->is_null = !copy; @@ -65,7 +65,7 @@ static void construct(QVariant::Private *x, const void *copy) static void clear(QVariant::Private *d) { switch (d->type) { - case QVariant::SizePolicy: + case QMetaType::QSizePolicy: v_clear(d); break; default: @@ -73,7 +73,7 @@ static void clear(QVariant::Private *d) return; } - d->type = QVariant::Invalid; + d->type = QMetaType::UnknownType; d->is_null = true; d->is_shared = false; } @@ -88,7 +88,7 @@ static bool compare(const QVariant::Private *a, const QVariant::Private *b) { Q_ASSERT(a->type == b->type); switch(a->type) { - case QVariant::SizePolicy: + case QMetaType::QSizePolicy: return *v_cast(a) == *v_cast(b); default: Q_ASSERT(false); @@ -111,7 +111,7 @@ static void streamDebug(QDebug dbg, const QVariant &v) { QVariant::Private *d = const_cast(&v.data_ptr()); switch (d->type) { - case QVariant::SizePolicy: + case QMetaType::QSizePolicy: dbg.nospace() << *v_cast(d); break; default: diff --git a/src/widgets/styles/qstylesheetstyle.cpp b/src/widgets/styles/qstylesheetstyle.cpp index 2eccb24431..1e032b237a 100644 --- a/src/widgets/styles/qstylesheetstyle.cpp +++ b/src/widgets/styles/qstylesheetstyle.cpp @@ -1547,11 +1547,10 @@ public: } } } - QString valueStr; - if(value.type() == QVariant::StringList || value.type() == QVariant::List) - valueStr = value.toStringList().join(QLatin1Char(' ')); - else - valueStr = value.toString(); + QString valueStr = (value.userType() == QMetaType::QStringList + || value.userType() == QMetaType::QVariantList) + ? value.toStringList().join(QLatin1Char(' ')) + : value.toString(); cache[name] = valueStr; return valueStr; } @@ -2611,16 +2610,16 @@ void QStyleSheetStyle::setProperties(QWidget *w) QVariant v; const QVariant value = w->property(property.toLatin1()); - switch (value.type()) { - case QVariant::Icon: v = decl.iconValue(); break; - case QVariant::Image: v = QImage(decl.uriValue()); break; - case QVariant::Pixmap: v = QPixmap(decl.uriValue()); break; - case QVariant::Rect: v = decl.rectValue(); break; - case QVariant::Size: v = decl.sizeValue(); break; - case QVariant::Color: v = decl.colorValue(); break; - case QVariant::Brush: v = decl.brushValue(); break; + switch (value.userType()) { + case QMetaType::QIcon: v = decl.iconValue(); break; + case QMetaType::QImage: v = QImage(decl.uriValue()); break; + case QMetaType::QPixmap: v = QPixmap(decl.uriValue()); break; + case QMetaType::QRect: v = decl.rectValue(); break; + case QMetaType::QSize: v = decl.sizeValue(); break; + case QMetaType::QColor: v = decl.colorValue(); break; + case QMetaType::QBrush: v = decl.brushValue(); break; #ifndef QT_NO_SHORTCUT - case QVariant::KeySequence: v = QKeySequence(decl.d->values.at(0).variant.toString()); break; + case QMetaType::QKeySequence: v = QKeySequence(decl.d->values.at(0).variant.toString()); break; #endif default: v = decl.d->values.at(0).variant; break; } @@ -4648,7 +4647,7 @@ void QStyleSheetStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *op } if (baseStyle()->property("_q_styleSheetRealCloseButton").toBool()) - baseStyle()->setProperty("_q_styleSheetRealCloseButton", QVariant(QVariant::Invalid)); + baseStyle()->setProperty("_q_styleSheetRealCloseButton", QVariant()); } QPixmap QStyleSheetStyle::generatedIconPixmap(QIcon::Mode iconMode, const QPixmap& pixmap, @@ -6128,7 +6127,7 @@ void QStyleSheetStyle::saveWidgetFont(QWidget* w, const QFont& font) const void QStyleSheetStyle::clearWidgetFont(QWidget* w) const { - w->setProperty("_q_styleSheetWidgetFont", QVariant(QVariant::Invalid)); + w->setProperty("_q_styleSheetWidgetFont", QVariant()); } // Polish palette that should be used for a particular widget, with particular states diff --git a/src/widgets/widgets/qabstractspinbox.cpp b/src/widgets/widgets/qabstractspinbox.cpp index 6a0d2f5019..04176ab5e2 100644 --- a/src/widgets/widgets/qabstractspinbox.cpp +++ b/src/widgets/widgets/qabstractspinbox.cpp @@ -570,7 +570,7 @@ void QAbstractSpinBox::clear() QAbstractSpinBox::StepEnabled QAbstractSpinBox::stepEnabled() const { Q_D(const QAbstractSpinBox); - if (d->readOnly || d->type == QVariant::Invalid) + if (d->readOnly || d->type == QMetaType::UnknownType) return StepNone; if (d->wrapping) return StepEnabled(StepUpEnabled | StepDownEnabled); @@ -723,7 +723,7 @@ void QAbstractSpinBox::setLineEdit(QLineEdit *lineEdit) d->edit->setFocusProxy(this); d->edit->setAcceptDrops(false); - if (d->type != QVariant::Invalid) { + if (d->type != QMetaType::UnknownType) { connect(d->edit, SIGNAL(textChanged(QString)), this, SLOT(_q_editorTextChanged(QString))); connect(d->edit, SIGNAL(cursorPositionChanged(int,int)), @@ -1421,7 +1421,7 @@ void QAbstractSpinBox::mouseReleaseEvent(QMouseEvent *event) */ QAbstractSpinBoxPrivate::QAbstractSpinBoxPrivate() - : edit(nullptr), type(QVariant::Invalid), spinClickTimerId(-1), + : edit(nullptr), type(QMetaType::UnknownType), spinClickTimerId(-1), spinClickTimerInterval(100), spinClickThresholdTimerId(-1), spinClickThresholdTimerInterval(-1), effectiveSpinRepeatRate(1), buttonState(None), cachedText(QLatin1String("\x01")), cachedState(QValidator::Invalid), pendingEmit(false), readOnly(false), wrapping(false), @@ -1805,7 +1805,7 @@ void QAbstractSpinBoxPrivate::setValue(const QVariant &val, EmitPolicy ep, void QAbstractSpinBoxPrivate::updateEdit() { Q_Q(QAbstractSpinBox); - if (type == QVariant::Invalid) + if (type == QMetaType::UnknownType) return; const QString newText = specialValue() ? specialValueText : prefix + textFromValue(value) + suffix; if (newText == edit->displayText() || cleared) @@ -1865,8 +1865,8 @@ QVariant QAbstractSpinBoxPrivate::getZeroVariant() const { QVariant ret; switch (type) { - case QVariant::Int: ret = QVariant((int)0); break; - case QVariant::Double: ret = QVariant((double)0.0); break; + case QMetaType::Int: ret = QVariant(0); break; + case QMetaType::Double: ret = QVariant(0.0); break; default: break; } return ret; @@ -1913,7 +1913,7 @@ QVariant QAbstractSpinBoxPrivate::valueFromText(const QString &) const void QAbstractSpinBoxPrivate::interpret(EmitPolicy ep) { Q_Q(QAbstractSpinBox); - if (type == QVariant::Invalid || cleared) + if (type == QMetaType::UnknownType || cleared) return; QVariant v = getZeroVariant(); @@ -2013,11 +2013,11 @@ void QSpinBoxValidator::fixup(QString &input) const QVariant operator+(const QVariant &arg1, const QVariant &arg2) { QVariant ret; - if (Q_UNLIKELY(arg1.type() != arg2.type())) + if (Q_UNLIKELY(arg1.userType() != arg2.userType())) qWarning("QAbstractSpinBox: Internal error: Different types (%s vs %s) (%s:%d)", arg1.typeName(), arg2.typeName(), __FILE__, __LINE__); - switch (arg1.type()) { - case QVariant::Int: { + switch (arg1.userType()) { + case QMetaType::Int: { const int int1 = arg1.toInt(); const int int2 = arg2.toInt(); if (int1 > 0 && (int2 >= INT_MAX - int1)) { @@ -2031,9 +2031,9 @@ QVariant operator+(const QVariant &arg1, const QVariant &arg2) } break; } - case QVariant::Double: ret = QVariant(arg1.toDouble() + arg2.toDouble()); break; + case QMetaType::Double: ret = QVariant(arg1.toDouble() + arg2.toDouble()); break; #if QT_CONFIG(datetimeparser) - case QVariant::DateTime: { + case QMetaType::QDateTime: { QDateTime a2 = arg2.toDateTime(); QDateTime a1 = arg1.toDateTime().addDays(QDATETIMEEDIT_DATE_MIN.daysTo(a2.date())); a1.setTime(a1.time().addMSecs(a2.time().msecsSinceStartOfDay())); @@ -2055,13 +2055,13 @@ QVariant operator+(const QVariant &arg1, const QVariant &arg2) QVariant operator-(const QVariant &arg1, const QVariant &arg2) { QVariant ret; - if (Q_UNLIKELY(arg1.type() != arg2.type())) + if (Q_UNLIKELY(arg1.userType() != arg2.userType())) qWarning("QAbstractSpinBox: Internal error: Different types (%s vs %s) (%s:%d)", arg1.typeName(), arg2.typeName(), __FILE__, __LINE__); - switch (arg1.type()) { - case QVariant::Int: ret = QVariant(arg1.toInt() - arg2.toInt()); break; - case QVariant::Double: ret = QVariant(arg1.toDouble() - arg2.toDouble()); break; - case QVariant::DateTime: { + switch (arg1.userType()) { + case QMetaType::Int: ret = QVariant(arg1.toInt() - arg2.toInt()); break; + case QMetaType::Double: ret = QVariant(arg1.toDouble() - arg2.toDouble()); break; + case QMetaType::QDateTime: { QDateTime a1 = arg1.toDateTime(); QDateTime a2 = arg2.toDateTime(); int days = a2.daysTo(a1); @@ -2090,13 +2090,13 @@ QVariant operator*(const QVariant &arg1, double multiplier) { QVariant ret; - switch (arg1.type()) { - case QVariant::Int: + switch (arg1.userType()) { + case QMetaType::Int: ret = static_cast(qBound(INT_MIN, arg1.toInt() * multiplier, INT_MAX)); break; - case QVariant::Double: ret = QVariant(arg1.toDouble() * multiplier); break; + case QMetaType::Double: ret = QVariant(arg1.toDouble() * multiplier); break; #if QT_CONFIG(datetimeparser) - case QVariant::DateTime: { + case QMetaType::QDateTime: { double days = QDATETIMEEDIT_DATE_MIN.daysTo(arg1.toDateTime().date()) * multiplier; const qint64 daysInt = qint64(days); days -= daysInt; @@ -2119,17 +2119,17 @@ double operator/(const QVariant &arg1, const QVariant &arg2) double a1 = 0; double a2 = 0; - switch (arg1.type()) { - case QVariant::Int: + switch (arg1.userType()) { + case QMetaType::Int: a1 = (double)arg1.toInt(); a2 = (double)arg2.toInt(); break; - case QVariant::Double: + case QMetaType::Double: a1 = arg1.toDouble(); a2 = arg2.toDouble(); break; #if QT_CONFIG(datetimeparser) - case QVariant::DateTime: + case QMetaType::QDateTime: a1 = QDATETIMEEDIT_DATE_MIN.daysTo(arg1.toDate()); a2 = QDATETIMEEDIT_DATE_MIN.daysTo(arg2.toDate()); a1 += arg1.toDateTime().time().msecsSinceStartOfDay() / (36e5 * 24); @@ -2144,9 +2144,9 @@ double operator/(const QVariant &arg1, const QVariant &arg2) int QAbstractSpinBoxPrivate::variantCompare(const QVariant &arg1, const QVariant &arg2) { - switch (arg2.type()) { - case QVariant::Date: - Q_ASSERT_X(arg1.type() == QVariant::Date, "QAbstractSpinBoxPrivate::variantCompare", + switch (arg2.userType()) { + case QMetaType::QDate: + Q_ASSERT_X(arg1.userType() == QMetaType::QDate, "QAbstractSpinBoxPrivate::variantCompare", qPrintable(QString::fromLatin1("Internal error 1 (%1)"). arg(QString::fromLatin1(arg1.typeName())))); if (arg1.toDate() == arg2.toDate()) { @@ -2156,8 +2156,8 @@ int QAbstractSpinBoxPrivate::variantCompare(const QVariant &arg1, const QVariant } else { return 1; } - case QVariant::Time: - Q_ASSERT_X(arg1.type() == QVariant::Time, "QAbstractSpinBoxPrivate::variantCompare", + case QMetaType::QTime: + Q_ASSERT_X(arg1.userType() == QMetaType::QTime, "QAbstractSpinBoxPrivate::variantCompare", qPrintable(QString::fromLatin1("Internal error 2 (%1)"). arg(QString::fromLatin1(arg1.typeName())))); if (arg1.toTime() == arg2.toTime()) { @@ -2169,7 +2169,7 @@ int QAbstractSpinBoxPrivate::variantCompare(const QVariant &arg1, const QVariant } - case QVariant::DateTime: + case QMetaType::QDateTime: if (arg1.toDateTime() == arg2.toDateTime()) { return 0; } else if (arg1.toDateTime() < arg2.toDateTime()) { @@ -2177,7 +2177,7 @@ int QAbstractSpinBoxPrivate::variantCompare(const QVariant &arg1, const QVariant } else { return 1; } - case QVariant::Int: + case QMetaType::Int: if (arg1.toInt() == arg2.toInt()) { return 0; } else if (arg1.toInt() < arg2.toInt()) { @@ -2185,7 +2185,7 @@ int QAbstractSpinBoxPrivate::variantCompare(const QVariant &arg1, const QVariant } else { return 1; } - case QVariant::Double: + case QMetaType::Double: if (arg1.toDouble() == arg2.toDouble()) { return 0; } else if (arg1.toDouble() < arg2.toDouble()) { @@ -2193,8 +2193,8 @@ int QAbstractSpinBoxPrivate::variantCompare(const QVariant &arg1, const QVariant } else { return 1; } - case QVariant::Invalid: - if (arg2.type() == QVariant::Invalid) + case QMetaType::UnknownType: + if (arg2.userType() == QMetaType::UnknownType) return 0; Q_FALLTHROUGH(); default: diff --git a/src/widgets/widgets/qabstractspinbox_p.h b/src/widgets/widgets/qabstractspinbox_p.h index ad169fde19..63b19c7317 100644 --- a/src/widgets/widgets/qabstractspinbox_p.h +++ b/src/widgets/widgets/qabstractspinbox_p.h @@ -127,7 +127,7 @@ public: QLineEdit *edit; QString prefix, suffix, specialValueText; QVariant value, minimum, maximum, singleStep; - QVariant::Type type; + QMetaType::Type type; int spinClickTimerId, spinClickTimerInterval, spinClickThresholdTimerId, spinClickThresholdTimerInterval; int effectiveSpinRepeatRate; uint buttonState; diff --git a/src/widgets/widgets/qcombobox.cpp b/src/widgets/widgets/qcombobox.cpp index d786c7ff83..9826cabe50 100644 --- a/src/widgets/widgets/qcombobox.cpp +++ b/src/widgets/widgets/qcombobox.cpp @@ -144,11 +144,11 @@ QStyleOptionMenuItem QComboMenuDelegate::getStyleOption(const QStyleOptionViewIt menuOption.menuItemType = QStyleOptionMenuItem::Normal; QVariant variant = index.model()->data(index, Qt::DecorationRole); - switch (variant.type()) { - case QVariant::Icon: + switch (variant.userType()) { + case QMetaType::QIcon: menuOption.icon = qvariant_cast(variant); break; - case QVariant::Color: { + case QMetaType::QColor: { static QPixmap pixmap(option.decorationSize); pixmap.fill(qvariant_cast(variant)); menuOption.icon = pixmap; @@ -1888,7 +1888,7 @@ void QComboBoxPrivate::updateDelegate(bool force) QIcon QComboBoxPrivate::itemIcon(const QModelIndex &index) const { QVariant decoration = model->data(index, Qt::DecorationRole); - if (decoration.type() == QVariant::Pixmap) + if (decoration.userType() == QMetaType::QPixmap) return QIcon(qvariant_cast(decoration)); else return qvariant_cast(decoration); diff --git a/src/widgets/widgets/qdatetimeedit.cpp b/src/widgets/widgets/qdatetimeedit.cpp index 5f415aca42..63d5ae268e 100644 --- a/src/widgets/widgets/qdatetimeedit.cpp +++ b/src/widgets/widgets/qdatetimeedit.cpp @@ -195,11 +195,19 @@ QDateTimeEdit::QDateTimeEdit(const QTime &time, QWidget *parent) d->init(time.isValid() ? time : QDATETIMEEDIT_TIME_MIN); } +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) /*! \internal */ - QDateTimeEdit::QDateTimeEdit(const QVariant &var, QVariant::Type parserType, QWidget *parent) + : QDateTimeEdit(var, QMetaType::Type(parserType), parent) +{ } +/*! + \internal +*/ +#endif + +QDateTimeEdit::QDateTimeEdit(const QVariant &var, QMetaType::Type parserType, QWidget *parent) : QAbstractSpinBox(*new QDateTimeEditPrivate, parent) { Q_D(QDateTimeEdit); @@ -1564,7 +1572,7 @@ void QDateTimeEdit::mousePressEvent(QMouseEvent *event) QTimeEdit::QTimeEdit(QWidget *parent) - : QDateTimeEdit(QDATETIMEEDIT_TIME_MIN, QVariant::Time, parent) + : QDateTimeEdit(QDATETIMEEDIT_TIME_MIN, QMetaType::QTime, parent) { connect(this, &QTimeEdit::timeChanged, this, &QTimeEdit::userTimeChanged); } @@ -1575,7 +1583,7 @@ QTimeEdit::QTimeEdit(QWidget *parent) */ QTimeEdit::QTimeEdit(const QTime &time, QWidget *parent) - : QDateTimeEdit(time, QVariant::Time, parent) + : QDateTimeEdit(time, QMetaType::QTime, parent) { connect(this, &QTimeEdit::timeChanged, this, &QTimeEdit::userTimeChanged); } @@ -1634,7 +1642,7 @@ QTimeEdit::~QTimeEdit() */ QDateEdit::QDateEdit(QWidget *parent) - : QDateTimeEdit(QDATETIMEEDIT_DATE_INITIAL, QVariant::Date, parent) + : QDateTimeEdit(QDATETIMEEDIT_DATE_INITIAL, QMetaType::QDate, parent) { connect(this, &QDateEdit::dateChanged, this, &QDateEdit::userDateChanged); } @@ -1645,7 +1653,7 @@ QDateEdit::QDateEdit(QWidget *parent) */ QDateEdit::QDateEdit(const QDate &date, QWidget *parent) - : QDateTimeEdit(date, QVariant::Date, parent) + : QDateTimeEdit(date, QMetaType::QDate, parent) { connect(this, &QDateEdit::dateChanged, this, &QDateEdit::userDateChanged); } @@ -1682,13 +1690,13 @@ QDateEdit::~QDateEdit() QDateTimeEditPrivate::QDateTimeEditPrivate() - : QDateTimeParser(QVariant::DateTime, QDateTimeParser::DateTimeEdit, QCalendar()) + : QDateTimeParser(QMetaType::QDateTime, QDateTimeParser::DateTimeEdit, QCalendar()) { hasHadFocus = false; formatExplicitlySet = false; cacheGuard = false; fixday = true; - type = QVariant::DateTime; + type = QMetaType::QDateTime; sections = { }; cachedDay = -1; currentSectionIndex = FirstSectionIndex; @@ -2430,22 +2438,22 @@ void QDateTimeEdit::initStyleOption(QStyleOptionSpinBox *option) const void QDateTimeEditPrivate::init(const QVariant &var) { Q_Q(QDateTimeEdit); - switch (var.type()) { - case QVariant::Date: + switch (var.userType()) { + case QMetaType::QDate: value = var.toDate().startOfDay(); updateTimeSpec(); q->setDisplayFormat(defaultDateFormat); if (sectionNodes.isEmpty()) // ### safeguard for broken locale q->setDisplayFormat(QLatin1String("dd/MM/yyyy")); break; - case QVariant::DateTime: + case QMetaType::QDateTime: value = var; updateTimeSpec(); q->setDisplayFormat(defaultDateTimeFormat); if (sectionNodes.isEmpty()) // ### safeguard for broken locale q->setDisplayFormat(QLatin1String("dd/MM/yyyy hh:mm:ss")); break; - case QVariant::Time: + case QMetaType::QTime: value = QDateTime(QDATETIMEEDIT_DATE_INITIAL, var.toTime()); updateTimeSpec(); q->setDisplayFormat(defaultTimeFormat); @@ -2524,7 +2532,7 @@ void QDateTimeEditPrivate::updateEditFieldGeometry() QVariant QDateTimeEditPrivate::getZeroVariant() const { - Q_ASSERT(type == QVariant::DateTime); + Q_ASSERT(type == QMetaType::QDateTime); return QDateTime(QDATETIMEEDIT_DATE_INITIAL, QTime(), spec); } diff --git a/src/widgets/widgets/qdatetimeedit.h b/src/widgets/widgets/qdatetimeedit.h index 03994675ae..8905ad4a9c 100644 --- a/src/widgets/widgets/qdatetimeedit.h +++ b/src/widgets/widgets/qdatetimeedit.h @@ -195,7 +195,10 @@ protected: void paintEvent(QPaintEvent *event) override; void initStyleOption(QStyleOptionSpinBox *option) const; +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) QDateTimeEdit(const QVariant &val, QVariant::Type parserType, QWidget *parent = nullptr); +#endif + QDateTimeEdit(const QVariant &val, QMetaType::Type parserType, QWidget *parent = nullptr); private: Q_DECLARE_PRIVATE(QDateTimeEdit) Q_DISABLE_COPY(QDateTimeEdit) diff --git a/src/widgets/widgets/qplaintextedit.cpp b/src/widgets/widgets/qplaintextedit.cpp index d54c0d0b20..87e8af1382 100644 --- a/src/widgets/widgets/qplaintextedit.cpp +++ b/src/widgets/widgets/qplaintextedit.cpp @@ -2250,17 +2250,17 @@ QVariant QPlainTextEdit::inputMethodQuery(Qt::InputMethodQuery query, QVariant a } const QPointF offset = contentOffset(); - switch (argument.type()) { - case QVariant::RectF: + switch (argument.userType()) { + case QMetaType::QRectF: argument = argument.toRectF().translated(-offset); break; - case QVariant::PointF: + case QMetaType::QPointF: argument = argument.toPointF() - offset; break; - case QVariant::Rect: + case QMetaType::QRect: argument = argument.toRect().translated(-offset.toPoint()); break; - case QVariant::Point: + case QMetaType::QPoint: argument = argument.toPoint() - offset; break; default: @@ -2268,14 +2268,14 @@ QVariant QPlainTextEdit::inputMethodQuery(Qt::InputMethodQuery query, QVariant a } const QVariant v = d->control->inputMethodQuery(query, argument); - switch (v.type()) { - case QVariant::RectF: + switch (v.userType()) { + case QMetaType::QRectF: return v.toRectF().translated(offset); - case QVariant::PointF: + case QMetaType::QPointF: return v.toPointF() + offset; - case QVariant::Rect: + case QMetaType::QRect: return v.toRect().translated(offset.toPoint()); - case QVariant::Point: + case QMetaType::QPoint: return v.toPoint() + offset.toPoint(); default: break; diff --git a/src/widgets/widgets/qspinbox.cpp b/src/widgets/widgets/qspinbox.cpp index 61ea81c892..08428f673e 100644 --- a/src/widgets/widgets/qspinbox.cpp +++ b/src/widgets/widgets/qspinbox.cpp @@ -1081,7 +1081,7 @@ QSpinBoxPrivate::QSpinBoxPrivate() value = minimum; displayIntegerBase = 10; singleStep = QVariant((int)1); - type = QVariant::Int; + type = QMetaType::Int; } /*! @@ -1238,7 +1238,7 @@ QDoubleSpinBoxPrivate::QDoubleSpinBoxPrivate() value = minimum; singleStep = QVariant(1.0); decimals = 2; - type = QVariant::Double; + type = QMetaType::Double; } /*! diff --git a/src/widgets/widgets/qtextbrowser.cpp b/src/widgets/widgets/qtextbrowser.cpp index d0ccd435b3..0ba74a20e0 100644 --- a/src/widgets/widgets/qtextbrowser.cpp +++ b/src/widgets/widgets/qtextbrowser.cpp @@ -310,9 +310,9 @@ void QTextBrowserPrivate::setSource(const QUrl &url, QTextDocument::ResourceType if (url.isValid() && (newUrlWithoutFragment != currentUrlWithoutFragment || forceLoadOnSourceChange)) { QVariant data = q->loadResource(type, resolveUrl(url)); - if (data.type() == QVariant::String) { + if (data.userType() == QMetaType::QString) { txt = data.toString(); - } else if (data.type() == QVariant::ByteArray) { + } else if (data.userType() == QMetaType::QByteArray) { if (type == QTextDocument::HtmlResource) { #if QT_CONFIG(textcodec) QByteArray ba = data.toByteArray(); diff --git a/src/widgets/widgets/qtextedit.cpp b/src/widgets/widgets/qtextedit.cpp index 10de7d0b9e..913ca6ec16 100644 --- a/src/widgets/widgets/qtextedit.cpp +++ b/src/widgets/widgets/qtextedit.cpp @@ -1502,7 +1502,7 @@ void QTextEdit::resizeEvent(QResizeEvent *e) QVariant alignmentProperty = doc->documentLayout()->property("contentHasAlignment"); if (!doc->pageSize().isNull() - && alignmentProperty.type() == QVariant::Bool + && alignmentProperty.userType() == QMetaType::Bool && !alignmentProperty.toBool()) { d->_q_adjustScrollbars(); @@ -1547,7 +1547,7 @@ void QTextEditPrivate::relayoutDocument() width = lineWrapColumnOrWidth; else if (lineWrap == QTextEdit::NoWrap) { QVariant alignmentProperty = doc->documentLayout()->property("contentHasAlignment"); - if (alignmentProperty.type() == QVariant::Bool && !alignmentProperty.toBool()) { + if (alignmentProperty.userType() == QMetaType::Bool && !alignmentProperty.toBool()) { width = 0; } @@ -1835,17 +1835,17 @@ QVariant QTextEdit::inputMethodQuery(Qt::InputMethodQuery query, QVariant argume } const QPointF offset(-d->horizontalOffset(), -d->verticalOffset()); - switch (argument.type()) { - case QVariant::RectF: + switch (argument.userType()) { + case QMetaType::QRectF: argument = argument.toRectF().translated(-offset); break; - case QVariant::PointF: + case QMetaType::QPointF: argument = argument.toPointF() - offset; break; - case QVariant::Rect: + case QMetaType::QRect: argument = argument.toRect().translated(-offset.toPoint()); break; - case QVariant::Point: + case QMetaType::QPoint: argument = argument.toPoint() - offset; break; default: @@ -1853,14 +1853,14 @@ QVariant QTextEdit::inputMethodQuery(Qt::InputMethodQuery query, QVariant argume } const QVariant v = d->control->inputMethodQuery(query, argument); - switch (v.type()) { - case QVariant::RectF: + switch (v.userType()) { + case QMetaType::QRectF: return v.toRectF().translated(offset); - case QVariant::PointF: + case QMetaType::QPointF: return v.toPointF() + offset; - case QVariant::Rect: + case QMetaType::QRect: return v.toRect().translated(offset.toPoint()); - case QVariant::Point: + case QMetaType::QPoint: return v.toPoint() + offset.toPoint(); default: break; -- cgit v1.2.3 From 39396409656b12940ffe9b715f13e23ac4290eca Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Thu, 23 Jan 2020 15:48:15 +0100 Subject: Fix some qdoc-warnings src/corelib/tools/qmap.cpp:1199: (qdoc) warning: Can't link to 'QMultiMap::unite()' src/gui/kernel/qevent.cpp:949: (qdoc) warning: Unknown command '\see' src/gui/painting/qpaintengine_raster.cpp:344: (qdoc) warning: clang found diagnostics parsing \fn Type QRasterPaintEngine::type() const error: unknown type name 'Type' src/gui/doc/src/qtgui.qdoc:45: (qdoc) warning: Can't link to 'Build with CMake' examples/widgets/doc/src/gallery.qdoc:28: (qdoc) warning: Cannot find file 'widgets/gallery/gallery.pro' or 'widgets/gallery/gallery.pyproject' src/widgets/kernel/qwidget.cpp:5950: (qdoc) warning: Can't link to 'setFilePath' src/widgets/kernel/qshortcut.cpp:542: (qdoc) warning: No such parameter 'context' in QShortcut::QShortcut() Change-Id: I2395af854efebef719d4762da466f69f7c5aab9e Reviewed-by: Paul Wicking --- src/widgets/kernel/qshortcut.cpp | 2 +- src/widgets/kernel/qwidget.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/kernel/qshortcut.cpp b/src/widgets/kernel/qshortcut.cpp index d469279ea5..039699a004 100644 --- a/src/widgets/kernel/qshortcut.cpp +++ b/src/widgets/kernel/qshortcut.cpp @@ -545,7 +545,7 @@ QShortcut::QShortcut(QWidget *parent) match the \a key sequence. Depending on the ambiguity of the event, the shortcut will call the \a member function, or the \a ambiguousMember function, if the key press was in the shortcut's - \a context. + \a shortcutContext. */ QShortcut::QShortcut(const QKeySequence &key, QWidget *parent, const char *member, const char *ambiguousMember, diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index 954b00eb35..b85bb62917 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -5957,9 +5957,9 @@ void QWidget::setWindowTitle(const QString &title) \note On \macos, window icons represent the active document, and will not be displayed unless a file path has also been - set using setFilePath. + set using setWindowFilePath. - \sa windowTitle, setFilePath + \sa windowTitle, setWindowFilePath */ QIcon QWidget::windowIcon() const { -- cgit v1.2.3 From a11267c5320324cce19496313e2f7f8cdce9d8f7 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Wed, 8 Jan 2020 20:18:17 +0100 Subject: QTextBrowser: deprecate signal highlighted(QString) Deprecate QTextBrowser::highlighted(QString) to avoid the use of qOverloadOf<>. Task-number: QTBUG-80906 Change-Id: I757622c976f7540ecef9225026299ebb0b90d007 Reviewed-by: Richard Moe Gustavsen --- src/widgets/widgets/qtextbrowser.cpp | 37 ++++++++++++++++++------------------ src/widgets/widgets/qtextbrowser.h | 3 +++ 2 files changed, 22 insertions(+), 18 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/widgets/qtextbrowser.cpp b/src/widgets/widgets/qtextbrowser.cpp index 0ba74a20e0..78fde94fad 100644 --- a/src/widgets/widgets/qtextbrowser.cpp +++ b/src/widgets/widgets/qtextbrowser.cpp @@ -152,6 +152,16 @@ public: QTextCursor prevFocus; int lastKeypadScrollValue; #endif + void emitHighlighted(const QUrl &url) + { + Q_Q(QTextBrowser); + emit q->highlighted(url); +#if QT_DEPRECATED_SINCE(5, 15) +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED + emit q->highlighted(url.toString()); +#endif + } }; Q_DECLARE_TYPEINFO(QTextBrowserPrivate::HistoryEntry, Q_MOVABLE_TYPE); @@ -256,24 +266,20 @@ void QTextBrowserPrivate::_q_activateAnchor(const QString &href) void QTextBrowserPrivate::_q_highlightLink(const QString &anchor) { - Q_Q(QTextBrowser); if (anchor.isEmpty()) { #ifndef QT_NO_CURSOR if (viewport->cursor().shape() != Qt::PointingHandCursor) oldCursor = viewport->cursor(); viewport->setCursor(oldCursor); #endif - emit q->highlighted(QUrl()); - emit q->highlighted(QString()); + emitHighlighted(QUrl()); } else { #ifndef QT_NO_CURSOR viewport->setCursor(Qt::PointingHandCursor); #endif const QUrl url = resolveUrl(anchor); - emit q->highlighted(url); - // convenience to ease connecting to QStatusBar::showMessage(const QString &) - emit q->highlighted(url.toString()); + emitHighlighted(url); } } @@ -383,8 +389,7 @@ void QTextBrowserPrivate::setSource(const QUrl &url, QTextDocument::ResourceType } #ifdef QT_KEYPAD_NAVIGATION lastKeypadScrollValue = vbar->value(); - emit q->highlighted(QUrl()); - emit q->highlighted(QString()); + emitHighlighted(QUrl()); #endif #ifndef QT_NO_CURSOR @@ -559,8 +564,7 @@ void QTextBrowserPrivate::keypadMove(bool next) // Ensure that the new selection is highlighted. const QString href = control->anchorAtCursor(); QUrl url = resolveUrl(href); - emit q->highlighted(url); - emit q->highlighted(url.toString()); + emitHighlighted(url); } else { // Scroll vbar->setValue(scrollYOffset); @@ -575,8 +579,7 @@ void QTextBrowserPrivate::keypadMove(bool next) hbar->setValue(savedXOffset); vbar->setValue(scrollYOffset); - emit q->highlighted(QUrl()); - emit q->highlighted(QString()); + emitHighlighted(QUrl()); } } #endif @@ -619,8 +622,7 @@ void QTextBrowserPrivate::restoreHistoryEntry(const HistoryEntry &entry) Q_Q(QTextBrowser); const QString href = prevFocus.charFormat().anchorHref(); QUrl url = resolveUrl(href); - emit q->highlighted(url); - emit q->highlighted(url.toString()); + emitHighlighted(url); #endif } @@ -927,6 +929,7 @@ void QTextBrowser::doSetSource(const QUrl &url, QTextDocument::ResourceType type /*! \fn void QTextBrowser::highlighted(const QString &link) \overload + \obsolete Convenience signal that allows connecting to a slot that takes just a QString, like for example QStatusBar's @@ -1127,8 +1130,7 @@ bool QTextBrowser::focusNextPrevChild(bool next) if (d->prevFocus != d->control->textCursor() && d->control->textCursor().hasSelection()) { const QString href = d->control->anchorAtCursor(); QUrl url = d->resolveUrl(href); - emit highlighted(url); - emit highlighted(url.toString()); + emitHighlighted(url); } d->prevFocus = d->control->textCursor(); #endif @@ -1136,8 +1138,7 @@ bool QTextBrowser::focusNextPrevChild(bool next) } else { #ifdef QT_KEYPAD_NAVIGATION // We assume we have no highlight now. - emit highlighted(QUrl()); - emit highlighted(QString()); + emitHighlighted(QUrl()); #endif } return QTextEdit::focusNextPrevChild(next); diff --git a/src/widgets/widgets/qtextbrowser.h b/src/widgets/widgets/qtextbrowser.h index 33e5b3980c..4b3ec491ee 100644 --- a/src/widgets/widgets/qtextbrowser.h +++ b/src/widgets/widgets/qtextbrowser.h @@ -107,7 +107,10 @@ Q_SIGNALS: void historyChanged(); void sourceChanged(const QUrl &); void highlighted(const QUrl &); +#if QT_DEPRECATED_SINCE(5, 15) + QT_DEPRECATED_VERSION_X_5_15("Use QTextBrowser::highlighted(QUrl) instead") void highlighted(const QString &); +#endif void anchorClicked(const QUrl &); protected: -- cgit v1.2.3 From 5c3b5efd40b3ab14cc6406a0dca62dfb14b03d46 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Fri, 10 Jan 2020 22:11:12 +0100 Subject: QMenu: don't crash when another popup is closed when a popup is closed When closing a popup (submenu) triggers closing another popup (the menu) programatically it can happen that QApplicationPrivate::popupWidgets is destroyed. Therefore we have to check if popupWidgets is still valid after the focus change event was delivered. Fixes: QTBUG-81222 Change-Id: Ide3a6897e43f389d396a80d8b158f7c8eb04e3aa Reviewed-by: Friedemann Kleint Reviewed-by: Richard Moe Gustavsen --- src/widgets/kernel/qapplication.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/widgets') diff --git a/src/widgets/kernel/qapplication.cpp b/src/widgets/kernel/qapplication.cpp index 842c0ea9e6..68f6b72d20 100644 --- a/src/widgets/kernel/qapplication.cpp +++ b/src/widgets/kernel/qapplication.cpp @@ -3762,7 +3762,9 @@ void QApplicationPrivate::closePopup(QWidget *popup) if (QWidget *fw = aw->focusWidget()) fw->setFocus(Qt::PopupFocusReason); - if (QApplicationPrivate::popupWidgets->count() == 1) // grab mouse/keyboard + // can become nullptr due to setFocus() above + if (QApplicationPrivate::popupWidgets && + QApplicationPrivate::popupWidgets->count() == 1) // grab mouse/keyboard grabForPopup(aw); } -- cgit v1.2.3 From e9a797799ee7e81d1cd113ba56f62705ae150e5c Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Mon, 2 Dec 2019 18:03:47 +0100 Subject: CMake: Add Qt6 forward compatible CMake API and targets Create Qt:: versionless targets for libraries and tools. So Qt::Core will link to Qt5::Core. Add additional feature properties to targets, with the same name they have in Qt6: QT_ENABLED_PUBLIC_FEATURES, QT_DISABLED_PUBLIC_FEATURES, QT_ENABLED_PRIVATE_FEATURES, QT_DISABLED_PRIVATE_FEATURES, to be forward-compatible with Qt6. Prefix properties with INTERFACE_ for interface libraries. Create functions with no major version in their prefix, so qt_foo instead of qt5_foo. The non-versioned functions will call the versioned functions, depending on the value of QT_DEFAULT_MAJOR_VERSION, which can be set by an application developer before finding the Qt package. Set QT_DEFAULT_MAJOR_VERSION to 5 if the value has not been defined in the current scope. Application developers can set QT_NO_CREATE_VERSIONLESS_FUNCTIONS to TRUE before calling find_package(Qt5) to suppress creation of the non-versioned functions. Application developers can set QT_NO_CREATE_VERSIONLESS_TARGETS to TRUE before calling find_package(Qt5) to suppress creation of the non-versioned targets. Setting these can be useful when both find_package(Qt5) and find_package(Qt6) are in the same project. If none of these are set by the user, then the first find_package(Qt5) will create versionless targets with the major version being "5", which means the second find_package(Qt6) will not create versionless targets. Handle versionless plugin names in qt_import_plugins, so both Qt::QCocoaIntegrationPlugin and Qt5/6::QCocoaIntegrationPlugin are recognized by the function. Allow specifying multiple types in EXCLUDE_BY_TYPE in qt_import_plugins, to be consitent with the Qt 6 version. Make sure to set the QT_PLUGIN_CLASS_NAME property to compatible with Qt 6. Task-number: QTBUG-74137 Task-number: QTBUG-80477 Change-Id: Ib89d090ea6f7794d7debd64f03f29da963a17ca7 Reviewed-by: Joerg Bornemann --- src/widgets/Qt5WidgetsConfigExtras.cmake.in | 11 +++++++++++ src/widgets/Qt5WidgetsMacros.cmake | 12 ++++++++++++ 2 files changed, 23 insertions(+) (limited to 'src/widgets') diff --git a/src/widgets/Qt5WidgetsConfigExtras.cmake.in b/src/widgets/Qt5WidgetsConfigExtras.cmake.in index 99d87e2e46..236d1d4159 100644 --- a/src/widgets/Qt5WidgetsConfigExtras.cmake.in +++ b/src/widgets/Qt5WidgetsConfigExtras.cmake.in @@ -17,3 +17,14 @@ endif() include(\"${CMAKE_CURRENT_LIST_DIR}/Qt5Widgets_AccessibleFactory.cmake\" OPTIONAL) set(Qt5Widgets_UIC_EXECUTABLE Qt5::uic) + +# Create versionless tool targets. +foreach(__qt_tool uic) + if(NOT \"${QT_NO_CREATE_VERSIONLESS_TARGETS}\" AND NOT TARGET Qt::${__qt_tool} + AND TARGET Qt5::${__qt_tool}) + add_executable(Qt::${__qt_tool} IMPORTED) + get_target_property(__qt_imported_location Qt5::${__qt_tool} IMPORTED_LOCATION) + set_target_properties(Qt::${__qt_tool} + PROPERTIES IMPORTED_LOCATION \"${__qt_imported_location}\") + endif() +endforeach() diff --git a/src/widgets/Qt5WidgetsMacros.cmake b/src/widgets/Qt5WidgetsMacros.cmake index 21e73d4f0c..35d2a2dc54 100644 --- a/src/widgets/Qt5WidgetsMacros.cmake +++ b/src/widgets/Qt5WidgetsMacros.cmake @@ -66,3 +66,15 @@ function(qt5_wrap_ui outfiles ) endforeach() set(${outfiles} ${${outfiles}} PARENT_SCOPE) endfunction() + +# This will override the CMake upstream command, because that one is for Qt 3. +if(NOT QT_NO_CREATE_VERSIONLESS_FUNCTIONS) + function(qt_wrap_ui outfiles) + if(QT_DEFAULT_MAJOR_VERSION EQUAL 5) + qt5_wrap_ui("${outfiles}" ${ARGN}) + elseif(QT_DEFAULT_MAJOR_VERSION EQUAL 6) + qt6_wrap_ui("${outfiles}" ${ARGN}) + endif() + set("${outfiles}" "${${outfiles}}" PARENT_SCOPE) + endfunction() +endif() -- cgit v1.2.3 From 114ff44f3c42e2575c60e6b5c8459acfea2dc60d Mon Sep 17 00:00:00 2001 From: Sze Howe Koh Date: Mon, 2 Sep 2019 07:32:49 +0800 Subject: QLabel: Allow pixmap() and picture() to return by-value MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The previous versions of these functions that returned by-pointer are held over from Qt 1 times. They are inconsistent with the rest of the Qt API. [ChangeLog][QtWidgets][QLabel] QLabel::pixmap() and QLabel::picture() can now return by-value instead of by-pointer. Task-number: QTBUG-48701 Change-Id: I23ce319a7b1f757e1f4dec697551bb472e92fabf Reviewed-by: André Hartmann --- src/widgets/accessible/simplewidgets.cpp | 15 +++--- src/widgets/dialogs/qmessagebox.cpp | 6 +-- src/widgets/dialogs/qwizard.cpp | 4 +- src/widgets/widgets/qlabel.cpp | 78 ++++++++++++++++++++++++++++++-- src/widgets/widgets/qlabel.h | 20 +++++++- 5 files changed, 104 insertions(+), 19 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/accessible/simplewidgets.cpp b/src/widgets/accessible/simplewidgets.cpp index 9dbbe9c608..107fd729fe 100644 --- a/src/widgets/accessible/simplewidgets.cpp +++ b/src/widgets/accessible/simplewidgets.cpp @@ -76,6 +76,9 @@ #include #include #endif +#ifndef QT_NO_PICTURE +#include +#endif #include #include #include @@ -431,10 +434,10 @@ QAccessible::Role QAccessibleDisplay::role() const #if QT_CONFIG(label) QLabel *l = qobject_cast(object()); if (l) { - if (l->pixmap()) + if (!l->pixmap(Qt::ReturnByValue).isNull()) return QAccessible::Graphic; #ifndef QT_NO_PICTURE - if (l->picture()) + if (!l->picture(Qt::ReturnByValue).isNull()) return QAccessible::Graphic; #endif #if QT_CONFIG(movie) @@ -558,10 +561,7 @@ QSize QAccessibleDisplay::imageSize() const #endif return QSize(); #if QT_CONFIG(label) - const QPixmap *pixmap = label->pixmap(); - if (!pixmap) - return QSize(); - return pixmap->size(); + return label->pixmap(Qt::ReturnByValue).size(); #endif } @@ -574,8 +574,7 @@ QPoint QAccessibleDisplay::imagePosition() const #endif return QPoint(); #if QT_CONFIG(label) - const QPixmap *pixmap = label->pixmap(); - if (!pixmap) + if (label->pixmap(Qt::ReturnByValue).isNull()) return QPoint(); return QPoint(label->mapToGlobal(label->pos())); diff --git a/src/widgets/dialogs/qmessagebox.cpp b/src/widgets/dialogs/qmessagebox.cpp index 854fee6e33..4e7a4a65e3 100644 --- a/src/widgets/dialogs/qmessagebox.cpp +++ b/src/widgets/dialogs/qmessagebox.cpp @@ -305,7 +305,7 @@ void QMessageBoxPrivate::setupLayout() Q_Q(QMessageBox); delete q->layout(); QGridLayout *grid = new QGridLayout; - bool hasIcon = iconLabel->pixmap() && !iconLabel->pixmap()->isNull(); + bool hasIcon = !iconLabel->pixmap(Qt::ReturnByValue).isNull(); if (hasIcon) grid->addWidget(iconLabel, 0, 0, 2, 1, Qt::AlignTop); @@ -1323,9 +1323,7 @@ void QMessageBox::setIcon(Icon icon) QPixmap QMessageBox::iconPixmap() const { Q_D(const QMessageBox); - if (d->iconLabel && d->iconLabel->pixmap()) - return *d->iconLabel->pixmap(); - return QPixmap(); + return d->iconLabel->pixmap(Qt::ReturnByValue); } void QMessageBox::setIconPixmap(const QPixmap &pixmap) diff --git a/src/widgets/dialogs/qwizard.cpp b/src/widgets/dialogs/qwizard.cpp index a4789f40b1..2f145806cf 100644 --- a/src/widgets/dialogs/qwizard.cpp +++ b/src/widgets/dialogs/qwizard.cpp @@ -452,8 +452,8 @@ public: } QSize minimumSizeHint() const override { - if (pixmap() && !pixmap()->isNull()) - return pixmap()->size() / pixmap()->devicePixelRatio(); + if (!pixmap(Qt::ReturnByValue).isNull()) + return pixmap(Qt::ReturnByValue).size() / pixmap(Qt::ReturnByValue).devicePixelRatio(); return QFrame::minimumSizeHint(); } diff --git a/src/widgets/widgets/qlabel.cpp b/src/widgets/widgets/qlabel.cpp index 77d117775a..2490df58f2 100644 --- a/src/widgets/widgets/qlabel.cpp +++ b/src/widgets/widgets/qlabel.cpp @@ -188,8 +188,13 @@ QLabelPrivate::~QLabelPrivate() */ #ifndef QT_NO_PICTURE +#if QT_DEPRECATED_SINCE(5, 15) /*! - Returns the label's picture or nullptr if the label doesn't have a + \deprecated + + New code should use the other overload which returns QPicture by-value. + + This function returns the label's picture or \c nullptr if the label doesn't have a picture. */ @@ -198,6 +203,37 @@ const QPicture *QLabel::picture() const Q_D(const QLabel); return d->picture; } +#endif // QT_DEPRECATED_SINCE(5, 15) + +/*! + \since 5.15 + Returns the label's picture. + + Previously, Qt provided a version of \c picture() which returned the picture + by-pointer. That version is now deprecated. To maintain compatibility + with old code, you can explicitly differentiate between the by-pointer + function and the by-value function: + + \code + const QPicture *picPtr = label->picture(); + QPicture picVal = label->picture(Qt::ReturnByValue); + \endcode + + If you disable the deprecated version using the QT_DISABLE_DEPRECATED_BEFORE + macro, then you can omit \c Qt::ReturnByValue as shown below: + + \code + QPicture picVal = label->picture(); + \endcode +*/ + +QPicture QLabel::picture(Qt::ReturnByValue_t) const +{ + Q_D(const QLabel); + if (d->picture) + return *(d->picture); + return QPicture(); +} #endif @@ -352,9 +388,27 @@ void QLabel::clear() /*! \property QLabel::pixmap - \brief the label's pixmap + \brief the label's pixmap. - If no pixmap has been set this will return nullptr. + Previously, Qt provided a version of \c pixmap() which returned the pixmap + by-pointer. That version is now deprecated. To maintain compatibility + with old code, you can explicitly differentiate between the by-pointer + function and the by-value function: + + \code + const QPixmap *pixmapPtr = label->pixmap(); + QPixmap pixmapVal = label->pixmap(Qt::ReturnByValue); + \endcode + + If you disable the deprecated version using the QT_DISABLE_DEPRECATED_BEFORE + macro, then you can omit \c Qt::ReturnByValue as shown below: + + \code + QPixmap pixmapVal = label->pixmap(); + \endcode + + If no pixmap has been set, the deprecated getter function will return + \c nullptr. Setting the pixmap clears any previous content. The buddy shortcut, if any, is disabled. @@ -373,11 +427,29 @@ void QLabel::setPixmap(const QPixmap &pixmap) d->updateLabel(); } +#if QT_DEPRECATED_SINCE(5, 15) +/*! + \deprecated + + New code should use the other overload which returns QPixmap by-value. +*/ const QPixmap *QLabel::pixmap() const { Q_D(const QLabel); return d->pixmap; } +#endif // QT_DEPRECATED_SINCE(5, 15) + +/*! + \since 5.15 +*/ +QPixmap QLabel::pixmap(Qt::ReturnByValue_t) const +{ + Q_D(const QLabel); + if (d->pixmap) + return *(d->pixmap); + return QPixmap(); +} #ifndef QT_NO_PICTURE /*! diff --git a/src/widgets/widgets/qlabel.h b/src/widgets/widgets/qlabel.h index 2f5db5a7d3..288022a71e 100644 --- a/src/widgets/widgets/qlabel.h +++ b/src/widgets/widgets/qlabel.h @@ -72,9 +72,25 @@ public: ~QLabel(); QString text() const; - const QPixmap *pixmap() const; + +#if QT_DEPRECATED_SINCE(5,15) + QT_DEPRECATED_VERSION_X(5, 15, "Use the other overload which returns QPixmap by-value") + const QPixmap *pixmap() const; // ### Qt 7: Remove function + + QPixmap pixmap(Qt::ReturnByValue_t) const; +#else + QPixmap pixmap(Qt::ReturnByValue_t = Qt::ReturnByValue) const; // ### Qt 7: Remove arg +#endif // QT_DEPRECATED_SINCE(5,15) + #ifndef QT_NO_PICTURE - const QPicture *picture() const; +# if QT_DEPRECATED_SINCE(5,15) + QT_DEPRECATED_VERSION_X(5, 15, "Use the other overload which returns QPicture by-value") + const QPicture *picture() const; // ### Qt 7: Remove function + + QPicture picture(Qt::ReturnByValue_t) const; +# else + QPicture picture(Qt::ReturnByValue_t = Qt::ReturnByValue) const; // ### Qt 7: Remove arg +# endif // QT_DEPRECATED_SINCE(5,15) #endif #if QT_CONFIG(movie) QMovie *movie() const; -- cgit v1.2.3 From 859307d7a590873d8df5f8094e13043370fccaa7 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Wed, 25 Sep 2019 15:04:36 +0200 Subject: Windows QPA: Provide an experimental palette for dark mode Provide a simple palette for dark mode, implementing dark mode support level 2. Task-number: QTBUG-72028 Change-Id: I6f71870b251ccb7da30c01abb22c224e600f2b27 Reviewed-by: Oliver Wolff --- src/widgets/styles/qwindowsstyle.cpp | 17 +++++++++++++++++ src/widgets/styles/qwindowsstyle_p_p.h | 1 + 2 files changed, 18 insertions(+) (limited to 'src/widgets') diff --git a/src/widgets/styles/qwindowsstyle.cpp b/src/widgets/styles/qwindowsstyle.cpp index 8496a2c223..497afd17e1 100644 --- a/src/widgets/styles/qwindowsstyle.cpp +++ b/src/widgets/styles/qwindowsstyle.cpp @@ -84,6 +84,7 @@ #include #include #include +#include #include #include @@ -127,6 +128,22 @@ qreal QWindowsStylePrivate::appDevicePixelRatio() return qApp->devicePixelRatio(); } +bool QWindowsStylePrivate::isDarkMode() +{ + bool result = false; +#ifdef Q_OS_WIN + // Windows only: Return whether dark mode style support is desired and + // dark mode is in effect. + if (auto ni = QGuiApplication::platformNativeInterface()) { + const QVariant darkModeStyleP = ni->property("darkModeStyle"); + result = darkModeStyleP.type() == QVariant::Bool + && darkModeStyleP.value() + && ni->property("darkMode").value(); + } +#endif + return result; +} + // Returns \c true if the toplevel parent of \a widget has seen the Alt-key bool QWindowsStylePrivate::hasSeenAlt(const QWidget *widget) const { diff --git a/src/widgets/styles/qwindowsstyle_p_p.h b/src/widgets/styles/qwindowsstyle_p_p.h index 4f6ffcefc2..a25f5c4166 100644 --- a/src/widgets/styles/qwindowsstyle_p_p.h +++ b/src/widgets/styles/qwindowsstyle_p_p.h @@ -74,6 +74,7 @@ public: static qreal devicePixelRatio(const QWidget *widget = nullptr) { return widget ? widget->devicePixelRatioF() : QWindowsStylePrivate::appDevicePixelRatio(); } static qreal nativeMetricScaleFactor(const QWidget *widget = nullptr); + static bool isDarkMode(); bool hasSeenAlt(const QWidget *widget) const; bool altDown() const { return alt_down; } -- cgit v1.2.3 From bf330a8f034a8d6198a78f87d23eafc5ef7e6ffb Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 26 Dec 2019 19:35:55 +0100 Subject: QGestureManager: fix one (of many) inefficient loop(s) I showed QGestureManager to a colleage and I just couldn't avert my eyes... Also remove a pointless container::clear() call (the data member's dtor will do that implicitly). Change-Id: Id2b3f471d62e5ea416e875f28ecee73f8614a469 Reviewed-by: Giuseppe D'Angelo --- src/widgets/kernel/qgesturemanager.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/kernel/qgesturemanager.cpp b/src/widgets/kernel/qgesturemanager.cpp index 5604391059..541519245e 100644 --- a/src/widgets/kernel/qgesturemanager.cpp +++ b/src/widgets/kernel/qgesturemanager.cpp @@ -105,11 +105,10 @@ QGestureManager::QGestureManager(QObject *parent) QGestureManager::~QGestureManager() { qDeleteAll(m_recognizers); - foreach (QGestureRecognizer *recognizer, m_obsoleteGestures.keys()) { - qDeleteAll(m_obsoleteGestures.value(recognizer)); - delete recognizer; + for (auto it = m_obsoleteGestures.cbegin(), end = m_obsoleteGestures.cend(); it != end; ++it) { + qDeleteAll(it.value()); + delete it.key(); } - m_obsoleteGestures.clear(); } Qt::GestureType QGestureManager::registerGestureRecognizer(QGestureRecognizer *recognizer) -- cgit v1.2.3 From f21a6d409ea0504c64cd72861fc16b6f3e080086 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 18 Dec 2019 15:43:24 +0100 Subject: QStringList: use local storage in removeDuplicates() If available, use a C++17 std::pmr::unordered_set with a monotonic buffer resource and a 256-byte stack buffer to avoid the per-element allocations of QSet. Results on my machine: RESULT : tst_QStringList::removeDuplicates():"empty": - 0.00014 msecs per iteration (total: 74, iterations: 524288) + 0.000031 msecs per iteration (total: 66, iterations: 2097152) RESULT : tst_QStringList::removeDuplicates():"short-dup-0.00": - 0.00043 msecs per iteration (total: 57, iterations: 131072) + 0.00013 msecs per iteration (total: 69, iterations: 524288) RESULT : tst_QStringList::removeDuplicates():"short-dup-0.50": - 0.00049 msecs per iteration (total: 65, iterations: 131072) + 0.00032 msecs per iteration (total: 85, iterations: 262144) RESULT : tst_QStringList::removeDuplicates():"short-dup-0.66": - 0.00057 msecs per iteration (total: 75, iterations: 131072) + 0.00039 msecs per iteration (total: 52, iterations: 131072) RESULT : tst_QStringList::removeDuplicates():"short-dup-0.75": - 0.00064 msecs per iteration (total: 85, iterations: 131072) + 0.00048 msecs per iteration (total: 63, iterations: 131072) RESULT : tst_QStringList::removeDuplicates():"long-dup-0.00": - 0.083 msecs per iteration (total: 85, iterations: 1024) + 0.039 msecs per iteration (total: 80, iterations: 2048) RESULT : tst_QStringList::removeDuplicates():"long-dup-0.50": - 0.11 msecs per iteration (total: 58, iterations: 512) + 0.078 msecs per iteration (total: 80, iterations: 1024) RESULT : tst_QStringList::removeDuplicates():"long-dup-0.66": - 0.13 msecs per iteration (total: 70, iterations: 512) + 0.10 msecs per iteration (total: 53, iterations: 512) RESULT : tst_QStringList::removeDuplicates():"long-dup-0.75": - 0.16 msecs per iteration (total: 86, iterations: 512) + 0.13 msecs per iteration (total: 69, iterations: 512) When interpreting the data, take into account that each iteration contains _also_ a deep copy of the QStringList d/t the detach from 'input'. The pattern is used elsewhere in Qt, so I've put the class that implements the seen set into a private header file and used in some other places I found. Change-Id: I1f71a82008a16d5a3818f91f290ade21d837805e Reviewed-by: Giuseppe D'Angelo --- src/widgets/itemviews/qtreewidget.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/itemviews/qtreewidget.cpp b/src/widgets/itemviews/qtreewidget.cpp index ddb31523fd..0d4c391e1c 100644 --- a/src/widgets/itemviews/qtreewidget.cpp +++ b/src/widgets/itemviews/qtreewidget.cpp @@ -48,6 +48,8 @@ #include #include +#include + #include QT_BEGIN_NAMESPACE @@ -3175,13 +3177,12 @@ QList QTreeWidget::selectedItems() const const QModelIndexList indexes = selectionModel()->selectedIndexes(); QList items; items.reserve(indexes.count()); - QSet seen; + QDuplicateTracker seen; seen.reserve(indexes.count()); for (const auto &index : indexes) { QTreeWidgetItem *item = d->item(index); - if (item->isHidden() || seen.contains(item)) + if (item->isHidden() || seen.hasSeen(item)) continue; - seen.insert(item); items.append(item); } return items; -- cgit v1.2.3 From aec4e05e9e8ad9109d7db15dd0fea477e4574c20 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Sat, 25 Jan 2020 20:12:12 +0100 Subject: Doc/QtWidgets: replace some 0 with \nullptr MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace some 'is 0' or 'are 0' where 0 referes to a nullptr with 'is \nullptr' and 'are \nullptr' Change-Id: I5ff46185b570bdfc7d20d18a47fd9174771ad8e5 Reviewed-by: André Hartmann Reviewed-by: Sze Howe Koh --- src/widgets/dialogs/qwizard.cpp | 2 +- src/widgets/graphicsview/qgraphicsproxywidget.cpp | 4 ++-- src/widgets/graphicsview/qgraphicsview.cpp | 2 +- src/widgets/styles/qdrawutil.cpp | 20 ++++++++++---------- src/widgets/styles/qproxystyle.cpp | 2 +- src/widgets/styles/qstyle.cpp | 6 +++--- src/widgets/util/qundoview.cpp | 10 +++++----- src/widgets/widgets/qabstractscrollarea.cpp | 6 +++--- src/widgets/widgets/qcombobox.cpp | 2 +- src/widgets/widgets/qdialogbuttonbox.cpp | 2 +- src/widgets/widgets/qdockwidget.cpp | 4 ++-- src/widgets/widgets/qmdiarea.cpp | 4 ++-- src/widgets/widgets/qtabwidget.cpp | 2 +- 13 files changed, 33 insertions(+), 33 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/dialogs/qwizard.cpp b/src/widgets/dialogs/qwizard.cpp index 2f145806cf..87f6875c8c 100644 --- a/src/widgets/dialogs/qwizard.cpp +++ b/src/widgets/dialogs/qwizard.cpp @@ -2924,7 +2924,7 @@ void QWizard::setDefaultProperty(const char *className, const char *property, or when the watermark is not provided the side widget is displayed on the left side of the wizard. - Passing 0 shows no side widget. + Passing \nullptr shows no side widget. When the \a widget is not \nullptr the wizard reparents it. diff --git a/src/widgets/graphicsview/qgraphicsproxywidget.cpp b/src/widgets/graphicsview/qgraphicsproxywidget.cpp index eb8acf1f27..a9a57c57fa 100644 --- a/src/widgets/graphicsview/qgraphicsproxywidget.cpp +++ b/src/widgets/graphicsview/qgraphicsproxywidget.cpp @@ -570,8 +570,8 @@ QGraphicsProxyWidget::~QGraphicsProxyWidget() After this function returns, QGraphicsProxyWidget will keep its state synchronized with that of \a widget whenever possible. - If a widget is already embedded by this proxy when this function is - called, that widget will first be automatically unembedded. Passing 0 for + If a widget is already embedded by this proxy when this function is called, + that widget will first be automatically unembedded. Passing \nullptr for the \a widget argument will only unembed the widget, and the ownership of the currently embedded widget will be passed on to the caller. Every child widget that are embedded will also be embedded and their proxy diff --git a/src/widgets/graphicsview/qgraphicsview.cpp b/src/widgets/graphicsview/qgraphicsview.cpp index e1a829f779..102f3e894f 100644 --- a/src/widgets/graphicsview/qgraphicsview.cpp +++ b/src/widgets/graphicsview/qgraphicsview.cpp @@ -963,7 +963,7 @@ static inline void QRect_unite(QRect *rect, const QRect &other) /* Calling this function results in update rects being clipped to the item's bounding rect. Note that updates prior to this function call is not clipped. - The clip is removed by passing 0. + The clip is removed by passing \nullptr. */ void QGraphicsViewPrivate::setUpdateClip(QGraphicsItem *item) { diff --git a/src/widgets/styles/qdrawutil.cpp b/src/widgets/styles/qdrawutil.cpp index d30b43a679..66729e4dc7 100644 --- a/src/widgets/styles/qdrawutil.cpp +++ b/src/widgets/styles/qdrawutil.cpp @@ -214,7 +214,7 @@ void qDrawShadeLine(QPainter *p, int x1, int y1, int x2, int y2, specifies the line width for each of the lines; it is not the total line width. The \a midLineWidth specifies the width of a middle line drawn in the QPalette::mid() color. The rectangle's - interior is filled with the \a fill brush unless \a fill is 0. + interior is filled with the \a fill brush unless \a fill is \nullptr. The rectangle appears sunken if \a sunken is true, otherwise raised. @@ -331,7 +331,7 @@ void qDrawShadeRect(QPainter *p, int x, int y, int w, int h, The given \a palette specifies the shading colors (\l {QPalette::light()}{light}, \l {QPalette::dark()}{dark} and \l {QPalette::mid()}{middle} colors). The panel's interior is filled - with the \a fill brush unless \a fill is 0. + with the \a fill brush unless \a fill is \nullptr. The panel appears sunken if \a sunken is true, otherwise raised. @@ -490,7 +490,7 @@ static void qDrawWinShades(QPainter *p, Draws the Windows-style button specified by the given point (\a x, \a y}, \a width and \a height using the provided \a painter with a line width of 2 pixels. The button's interior is filled with the - \a{fill} brush unless \a fill is 0. + \a{fill} brush unless \a fill is \nullptr. The given \a palette specifies the shading colors (\l {QPalette::light()}{light}, \l {QPalette::dark()}{dark} and \l @@ -528,7 +528,7 @@ void qDrawWinButton(QPainter *p, int x, int y, int w, int h, Draws the Windows-style panel specified by the given point(\a x, \a y), \a width and \a height using the provided \a painter with a line width of 2 pixels. The button's interior is filled with the - \a fill brush unless \a fill is 0. + \a fill brush unless \a fill is \nullptr. The given \a palette specifies the shading colors. The panel appears sunken if \a sunken is true, otherwise raised. @@ -567,7 +567,7 @@ void qDrawWinPanel(QPainter *p, int x, int y, int w, int h, Draws the plain rectangle beginning at (\a x, \a y) with the given \a width and \a height, using the specified \a painter, \a lineColor and \a lineWidth. The rectangle's interior is filled with the \a - fill brush unless \a fill is 0. + fill brush unless \a fill is \nullptr. \warning This function does not look at QWidget::style() or QApplication::style(). Use the drawing functions in QStyle to make @@ -676,7 +676,7 @@ void qDrawShadeLine(QPainter *p, const QPoint &p1, const QPoint &p2, specifies the line width for each of the lines; it is not the total line width. The \a midLineWidth specifies the width of a middle line drawn in the QPalette::mid() color. The rectangle's - interior is filled with the \a fill brush unless \a fill is 0. + interior is filled with the \a fill brush unless \a fill is \nullptr. The rectangle appears sunken if \a sunken is true, otherwise raised. @@ -714,7 +714,7 @@ void qDrawShadeRect(QPainter *p, const QRect &r, The given \a palette specifies the shading colors (\l {QPalette::light()}{light}, \l {QPalette::dark()}{dark} and \l {QPalette::mid()}{middle} colors). The panel's interior is filled - with the \a fill brush unless \a fill is 0. + with the \a fill brush unless \a fill is \nullptr. The panel appears sunken if \a sunken is true, otherwise raised. @@ -746,7 +746,7 @@ void qDrawShadePanel(QPainter *p, const QRect &r, Draws the Windows-style button at the rectangle specified by \a rect using the given \a painter with a line width of 2 pixels. The button's interior - is filled with the \a{fill} brush unless \a fill is 0. + is filled with the \a{fill} brush unless \a fill is \nullptr. The given \a palette specifies the shading colors (\l {QPalette::light()}{light}, \l {QPalette::dark()}{dark} and \l @@ -774,7 +774,7 @@ void qDrawWinButton(QPainter *p, const QRect &r, Draws the Windows-style panel at the rectangle specified by \a rect using the given \a painter with a line width of 2 pixels. The button's interior - is filled with the \a fill brush unless \a fill is 0. + is filled with the \a fill brush unless \a fill is \nullptr. The given \a palette specifies the shading colors. The panel appears sunken if \a sunken is true, otherwise raised. @@ -804,7 +804,7 @@ void qDrawWinPanel(QPainter *p, const QRect &r, Draws the plain rectangle specified by \a rect using the given \a painter, \a lineColor and \a lineWidth. The rectangle's interior is filled with the - \a fill brush unless \a fill is 0. + \a fill brush unless \a fill is \nullptr. \warning This function does not look at QWidget::style() or QApplication::style(). Use the drawing functions in QStyle to make diff --git a/src/widgets/styles/qproxystyle.cpp b/src/widgets/styles/qproxystyle.cpp index cfaa5a2011..0cc235bc84 100644 --- a/src/widgets/styles/qproxystyle.cpp +++ b/src/widgets/styles/qproxystyle.cpp @@ -403,7 +403,7 @@ QIcon QProxyStyle::standardIcon(StandardPixmap standardIcon, orientation specifies whether the controls are laid out side by side or stacked vertically. The \a option parameter can be used to pass extra information about the parent widget. The \a widget parameter - is optional and can also be used if \a option is 0. + is optional and can also be used if \a option is \nullptr. The default implementation returns -1. diff --git a/src/widgets/styles/qstyle.cpp b/src/widgets/styles/qstyle.cpp index d2f5ac76f9..72e40d657d 100644 --- a/src/widgets/styles/qstyle.cpp +++ b/src/widgets/styles/qstyle.cpp @@ -2362,14 +2362,14 @@ QPalette QStyle::standardPalette() const \fn int QStyle::layoutSpacing(QSizePolicy::ControlType control1, QSizePolicy::ControlType control2, Qt::Orientation orientation, - const QStyleOption *option = 0, const QWidget *widget = 0) const + const QStyleOption *option = nullptr, const QWidget *widget = nullptr) const Returns the spacing that should be used between \a control1 and \a control2 in a layout. \a orientation specifies whether the controls are laid out side by side or stacked vertically. The \a option parameter can be used to pass extra information about the parent widget. The \a widget parameter is optional and can also - be used if \a option is 0. + be used if \a option is \nullptr. This function is called by the layout system. It is used only if PM_LayoutHorizontalSpacing or PM_LayoutVerticalSpacing returns a @@ -2386,7 +2386,7 @@ QPalette QStyle::standardPalette() const controls are laid out side by side or stacked vertically. The \a option parameter can be used to pass extra information about the parent widget. The \a widget parameter is optional and can also - be used if \a option is 0. + be used if \a option is \nullptr. \a controls1 and \a controls2 are OR-combination of zero or more \l{QSizePolicy::ControlTypes}{control types}. diff --git a/src/widgets/util/qundoview.cpp b/src/widgets/util/qundoview.cpp index 9ca83a1da2..a39276a2b8 100644 --- a/src/widgets/util/qundoview.cpp +++ b/src/widgets/util/qundoview.cpp @@ -358,8 +358,8 @@ QUndoStack *QUndoView::stack() const } /*! - Sets the stack displayed by this view to \a stack. If \a stack is 0, the view - will be empty. + Sets the stack displayed by this view to \a stack. If \a stack is \nullptr, + the view will be empty. If the view was previously looking at a QUndoGroup, the group is set to \nullptr. @@ -378,10 +378,10 @@ void QUndoView::setStack(QUndoStack *stack) #if QT_CONFIG(undogroup) /*! - Sets the group displayed by this view to \a group. If \a group is 0, the view will - be empty. + Sets the group displayed by this view to \a group. If \a group is \nullptr, + the view will be empty. - The view will update itself autmiatically whenever the active stack of the group changes. + The view will update itself automatically whenever the active stack of the group changes. \sa group(), setStack() */ diff --git a/src/widgets/widgets/qabstractscrollarea.cpp b/src/widgets/widgets/qabstractscrollarea.cpp index 320b3bf7ef..257cffda62 100644 --- a/src/widgets/widgets/qabstractscrollarea.cpp +++ b/src/widgets/widgets/qabstractscrollarea.cpp @@ -512,8 +512,8 @@ QAbstractScrollArea::~QAbstractScrollArea() Sets the viewport to be the given \a widget. The QAbstractScrollArea will take ownership of the given \a widget. - If \a widget is 0, QAbstractScrollArea will assign a new QWidget instance - for the viewport. + If \a widget is \nullptr, QAbstractScrollArea will assign a new QWidget + instance for the viewport. \sa viewport() */ @@ -720,7 +720,7 @@ QWidget *QAbstractScrollArea::cornerWidget() const You will probably also want to set at least one of the scroll bar modes to \c AlwaysOn. - Passing 0 shows no widget in the corner. + Passing \nullptr shows no widget in the corner. Any previous corner widget is hidden. diff --git a/src/widgets/widgets/qcombobox.cpp b/src/widgets/widgets/qcombobox.cpp index 9826cabe50..aa3788c404 100644 --- a/src/widgets/widgets/qcombobox.cpp +++ b/src/widgets/widgets/qcombobox.cpp @@ -2044,7 +2044,7 @@ const QValidator *QComboBox::validator() const \since 4.2 Sets the \a completer to use instead of the current completer. - If \a completer is 0, auto completion is disabled. + If \a completer is \nullptr, auto completion is disabled. By default, for an editable combo box, a QCompleter that performs case insensitive inline completion is automatically created. diff --git a/src/widgets/widgets/qdialogbuttonbox.cpp b/src/widgets/widgets/qdialogbuttonbox.cpp index 2e12320bc3..28c4f59d0d 100644 --- a/src/widgets/widgets/qdialogbuttonbox.cpp +++ b/src/widgets/widgets/qdialogbuttonbox.cpp @@ -699,7 +699,7 @@ QList QDialogButtonBox::buttons() const /*! 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 button box. + \l InvalidRole if \a button is \nullptr or has not been added to the button box. \sa buttons(), addButton() */ diff --git a/src/widgets/widgets/qdockwidget.cpp b/src/widgets/widgets/qdockwidget.cpp index 299e5da8d3..1d358c493e 100644 --- a/src/widgets/widgets/qdockwidget.cpp +++ b/src/widgets/widgets/qdockwidget.cpp @@ -1674,8 +1674,8 @@ QAction * QDockWidget::toggleViewAction() const \since 4.3 Sets an arbitrary \a widget as the dock widget's title bar. If \a widget - is 0, any custom title bar widget previously set on the dock widget is - removed, but not deleted, and the default title bar will be used + is \nullptr, any custom title bar widget previously set on the dock widget + is removed, but not deleted, and the default title bar will be used instead. If a title bar widget is set, QDockWidget will not use native window diff --git a/src/widgets/widgets/qmdiarea.cpp b/src/widgets/widgets/qmdiarea.cpp index 3272ac440b..da6eb47372 100644 --- a/src/widgets/widgets/qmdiarea.cpp +++ b/src/widgets/widgets/qmdiarea.cpp @@ -103,8 +103,8 @@ \fn void QMdiArea::subWindowActivated(QMdiSubWindow *window) QMdiArea emits this signal after \a window has been activated. When \a - window is 0, QMdiArea has just deactivated its last active window, and - there are no active windows on the workspace. + window is \nullptr, QMdiArea has just deactivated its last active window, + and there are no active windows on the workspace. \sa QMdiArea::activeSubWindow() */ diff --git a/src/widgets/widgets/qtabwidget.cpp b/src/widgets/widgets/qtabwidget.cpp index f0bfe67e3a..a19dacda52 100644 --- a/src/widgets/widgets/qtabwidget.cpp +++ b/src/widgets/widgets/qtabwidget.cpp @@ -612,7 +612,7 @@ void QTabWidget::setTabVisible(int index, bool visible) Only the horizontal element of the \a corner will be used. - Passing 0 shows no widget in the corner. + Passing \nullptr shows no widget in the corner. Any previously set corner widget is hidden. -- cgit v1.2.3 From 582311d1224cb196d8149bdfd8f178d5239c6b28 Mon Sep 17 00:00:00 2001 From: Sze Howe Koh Date: Mon, 27 Jan 2020 17:11:51 +0800 Subject: Doc: Replace some usages of 0/zero/null with \nullptr Change-Id: Ibe7de11fc6fc41477c35e7d653c6a911855deabb Reviewed-by: Paul Wicking --- src/widgets/styles/qproxystyle.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/widgets') diff --git a/src/widgets/styles/qproxystyle.cpp b/src/widgets/styles/qproxystyle.cpp index 0cc235bc84..ecad637957 100644 --- a/src/widgets/styles/qproxystyle.cpp +++ b/src/widgets/styles/qproxystyle.cpp @@ -162,7 +162,7 @@ QStyle *QProxyStyle::baseStyle() const Ownership of \a style is transferred to QProxyStyle. - If style is zero, a desktop-dependant style will be + If style is \nullptr, a desktop-dependent style will be assigned automatically. */ void QProxyStyle::setBaseStyle(QStyle *style) -- cgit v1.2.3