From f0443984b84dea782ccd06dbce59808d55b15dbe Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Tue, 24 Sep 2019 16:26:56 +0200 Subject: QComboBox cleanup: use member initialization and nullptr Cleanup QComboBox private classes: - rearrange members to avoid unneeded padding - use nullptr - remove unused functions - don't print warnings about own deprecated functions Change-Id: I350d1c63602e32cf4b45549bc35cf1538dbbe8f0 Reviewed-by: Friedemann Kleint --- src/widgets/widgets/qcombobox.cpp | 48 +++++++---------------- src/widgets/widgets/qcombobox_p.h | 82 ++++++++++++++++++--------------------- 2 files changed, 52 insertions(+), 78 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/widgets/qcombobox.cpp b/src/widgets/widgets/qcombobox.cpp index 03dcde0a58..19b442f477 100644 --- a/src/widgets/widgets/qcombobox.cpp +++ b/src/widgets/widgets/qcombobox.cpp @@ -91,30 +91,11 @@ QT_BEGIN_NAMESPACE QComboBoxPrivate::QComboBoxPrivate() : QWidgetPrivate(), - model(0), - lineEdit(0), - container(0), - insertPolicy(QComboBox::InsertAtBottom), - sizeAdjustPolicy(QComboBox::AdjustToContentsOnFirstShow), - minimumContentsLength(0), shownOnce(false), autoCompletion(true), duplicatesEnabled(false), frame(true), - maxVisibleItems(10), - maxCount(INT_MAX), - modelColumn(0), - inserting(false), - arrowState(QStyle::State_None), - hoverControl(QStyle::SC_None), - autoCompletionCaseSensitivity(Qt::CaseInsensitive), - indexBeforeChange(-1) -#ifdef Q_OS_MAC - , m_platformMenu(0) -#endif -#if QT_CONFIG(completer) - , completer(0) -#endif + inserting(false) { } @@ -447,12 +428,8 @@ void QComboBoxPrivateContainer::paintEvent(QPaintEvent *e) QFrame::paintEvent(e); } -void QComboBoxPrivateContainer::leaveEvent(QEvent *) -{ -} - QComboBoxPrivateContainer::QComboBoxPrivateContainer(QAbstractItemView *itemView, QComboBox *parent) - : QFrame(parent, Qt::Popup), combo(parent), view(0), top(0), bottom(0), maybeIgnoreMouseButtonRelease(false) + : QFrame(parent, Qt::Popup), combo(parent) { // we need the combobox and itemview Q_ASSERT(parent); @@ -557,7 +534,7 @@ void QComboBoxPrivateContainer::updateScrollers() */ void QComboBoxPrivateContainer::viewDestroyed() { - view = 0; + view = nullptr; setItemView(new QComboBoxListView()); } @@ -591,7 +568,7 @@ void QComboBoxPrivateContainer::setItemView(QAbstractItemView *itemView) if (isAncestorOf(view)) delete view; - view = 0; + view = nullptr; } // setup the item view @@ -1568,7 +1545,7 @@ void QComboBox::setAutoCompletion(bool enable) d->lineEdit->setCompleter(d->completer); d->completer->setWidget(this); } else { - d->lineEdit->setCompleter(0); + d->lineEdit->setCompleter(nullptr); } } @@ -1757,7 +1734,7 @@ QSize QComboBox::iconSize() const if (d->iconSize.isValid()) return d->iconSize; - int iconWidth = style()->pixelMetric(QStyle::PM_SmallIconSize, 0, this); + int iconWidth = style()->pixelMetric(QStyle::PM_SmallIconSize, nullptr, this); return QSize(iconWidth, iconWidth); } @@ -1827,7 +1804,7 @@ QString QComboBox::placeholderText() const bool QComboBox::isEditable() const { Q_D(const QComboBox); - return d->lineEdit != 0; + return d->lineEdit != nullptr; } /*! \internal @@ -1883,7 +1860,7 @@ void QComboBox::setEditable(bool editable) setAttribute(Qt::WA_InputMethodEnabled, false); d->lineEdit->hide(); d->lineEdit->deleteLater(); - d->lineEdit = 0; + d->lineEdit = nullptr; } d->updateDelegate(); @@ -1932,6 +1909,8 @@ void QComboBox::setLineEdit(QLineEdit *edit) d->lineEdit->setFocusProxy(this); d->lineEdit->setAttribute(Qt::WA_MacShowFocusRect, false); #if QT_DEPRECATED_SINCE(5, 13) +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED #if QT_CONFIG(completer) setAutoCompletion(d->autoCompletion); @@ -1948,6 +1927,7 @@ void QComboBox::setLineEdit(QLineEdit *edit) } #endif #endif +QT_WARNING_POP #endif setAttribute(Qt::WA_InputMethodEnabled); @@ -1996,7 +1976,7 @@ void QComboBox::setValidator(const QValidator *v) const QValidator *QComboBox::validator() const { Q_D(const QComboBox); - return d->lineEdit ? d->lineEdit->validator() : 0; + return d->lineEdit ? d->lineEdit->validator() : nullptr; } #endif // QT_NO_VALIDATOR @@ -2040,7 +2020,7 @@ void QComboBox::setCompleter(QCompleter *c) QCompleter *QComboBox::completer() const { Q_D(const QComboBox); - return d->lineEdit ? d->lineEdit->completer() : 0; + return d->lineEdit ? d->lineEdit->completer() : nullptr; } #endif // QT_CONFIG(completer) @@ -2927,7 +2907,7 @@ void QComboBox::hidePopup() QSignalBlocker containerBlocker(d->container); // Flash selected/triggered item (if any). if (style()->styleHint(QStyle::SH_Menu_FlashTriggeredItem)) { - QItemSelectionModel *selectionModel = view() ? view()->selectionModel() : 0; + QItemSelectionModel *selectionModel = view() ? view()->selectionModel() : nullptr; if (selectionModel && selectionModel->hasSelection()) { QEventLoop eventLoop; const QItemSelection selection = selectionModel->selection(); diff --git a/src/widgets/widgets/qcombobox_p.h b/src/widgets/widgets/qcombobox_p.h index 00211d70aa..c79406eafd 100644 --- a/src/widgets/widgets/qcombobox_p.h +++ b/src/widgets/widgets/qcombobox_p.h @@ -79,7 +79,6 @@ QT_REQUIRE_CONFIG(combobox); QT_BEGIN_NAMESPACE -class QAction; class QPlatformMenu; class QComboBoxListView : public QListView @@ -131,9 +130,6 @@ private: QComboBox *combo; }; - -class QStandardItemModel; - class Q_AUTOTEST_EXPORT QComboBoxPrivateScroller : public QWidget { Q_OBJECT @@ -212,7 +208,7 @@ Q_SIGNALS: private: QAbstractSlider::SliderAction sliderAction; QBasicTimer timer; - bool fast; + bool fast = false; }; class Q_WIDGETS_EXPORT QComboBoxPrivateContainer : public QFrame @@ -246,7 +242,6 @@ protected: void showEvent(QShowEvent *e) override; void hideEvent(QHideEvent *e) override; void timerEvent(QTimerEvent *timerEvent) override; - void leaveEvent(QEvent *e) override; void resizeEvent(QResizeEvent *e) override; void paintEvent(QPaintEvent *e) override; QStyleOptionComboBox comboStyleOption() const; @@ -257,18 +252,19 @@ Q_SIGNALS: private: QComboBox *combo; - QAbstractItemView *view; - QComboBoxPrivateScroller *top; - QComboBoxPrivateScroller *bottom; - bool maybeIgnoreMouseButtonRelease; + QAbstractItemView *view = nullptr; + QComboBoxPrivateScroller *top = nullptr; + QComboBoxPrivateScroller *bottom = nullptr; QElapsedTimer popupTimer; + bool maybeIgnoreMouseButtonRelease = false; friend class QComboBox; friend class QComboBoxPrivate; }; class Q_AUTOTEST_EXPORT QComboMenuDelegate : public QAbstractItemDelegate -{ Q_OBJECT +{ + Q_OBJECT public: QComboMenuDelegate(QObject *parent, QComboBox *cmb) : QAbstractItemDelegate(parent), mCombo(cmb) {} @@ -355,8 +351,8 @@ public: void _q_complete(); void _q_itemSelected(const QModelIndex &item); bool contains(const QString &text, int role); - void emitActivated(const QModelIndex&); - void _q_emitHighlighted(const QModelIndex&); + void emitActivated(const QModelIndex &index); + void _q_emitHighlighted(const QModelIndex &index); void _q_emitCurrentIndexChanged(const QModelIndex &index); void _q_modelDestroyed(); void _q_modelReset(); @@ -366,8 +362,8 @@ public: void _q_resetButton(); void _q_dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight); void _q_updateIndexBeforeChange(); - void _q_rowsInserted(const QModelIndex & parent, int start, int end); - void _q_rowsRemoved(const QModelIndex & parent, int start, int end); + void _q_rowsInserted(const QModelIndex &parent, int start, int end); + void _q_rowsRemoved(const QModelIndex &parent, int start, int end); void updateArrow(QStyle::StateFlag state); bool updateHoverControl(const QPoint &pos); QRect popupGeometry(int screen = -1) const; @@ -402,40 +398,38 @@ public: }; #endif - QAbstractItemModel *model; - QLineEdit *lineEdit; - QComboBoxPrivateContainer *container; - QComboBox::InsertPolicy insertPolicy; - QComboBox::SizeAdjustPolicy sizeAdjustPolicy; - int minimumContentsLength; - QSize iconSize; - uint shownOnce : 1; - uint autoCompletion : 1; - uint duplicatesEnabled : 1; - uint frame : 1; - uint padding : 26; - int maxVisibleItems; - int maxCount; - int modelColumn; - QString placeholderText; - bool inserting; - mutable QSize minimumSizeHint; - mutable QSize sizeHint; - QStyle::StateFlag arrowState; - QStyle::SubControl hoverControl; - QRect hoverRect; - QPersistentModelIndex currentIndex; - QPersistentModelIndex root; - Qt::CaseSensitivity autoCompletionCaseSensitivity; - int indexBeforeChange; + QAbstractItemModel *model = nullptr; + QLineEdit *lineEdit = nullptr; + QComboBoxPrivateContainer *container = nullptr; #ifdef Q_OS_MAC - QPlatformMenu *m_platformMenu; + QPlatformMenu *m_platformMenu = nullptr; #endif #if QT_CONFIG(completer) QPointer completer; #endif - static QPalette viewContainerPalette(QComboBox *cmb) - { return cmb->d_func()->viewContainer()->palette(); } + QPersistentModelIndex currentIndex; + QPersistentModelIndex root; + QString placeholderText; + QRect hoverRect; + QSize iconSize; + mutable QSize minimumSizeHint; + mutable QSize sizeHint; + QComboBox::InsertPolicy insertPolicy = QComboBox::InsertAtBottom; + QComboBox::SizeAdjustPolicy sizeAdjustPolicy = QComboBox::AdjustToContentsOnFirstShow; + QStyle::StateFlag arrowState = QStyle::State_None; + QStyle::SubControl hoverControl = QStyle::SC_None; + Qt::CaseSensitivity autoCompletionCaseSensitivity = Qt::CaseInsensitive; + int minimumContentsLength = 0; + int indexBeforeChange = -1; + int maxVisibleItems = 10; + int maxCount = std::numeric_limits::max(); + int modelColumn = 0; + int placeholderIndex = -1; + bool shownOnce : 1; + bool autoCompletion : 1; + bool duplicatesEnabled : 1; + bool frame : 1; + bool inserting : 1; }; QT_END_NAMESPACE -- cgit v1.2.3 From c54b1d273f6aee3538c1608e9fefff22e80e11fb Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Mon, 25 Nov 2019 16:19:17 +0100 Subject: qtestsupport_widgets.h: Fix syncqt warning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix include, removing: QtWidgets WARNING qtbase/src/widgets/kernel/qtestsupport_widgets.h includes qtwidgetsglobal.h when it should include QtWidgets/qtwidgetsglobal.h Change-Id: I3dc608cba48e9ae36b0683a94a4bf411e23f5136 Reviewed-by: Tor Arne Vestbø --- src/widgets/kernel/qtestsupport_widgets.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/widgets') diff --git a/src/widgets/kernel/qtestsupport_widgets.h b/src/widgets/kernel/qtestsupport_widgets.h index ca1406b0b2..2b37a9e858 100644 --- a/src/widgets/kernel/qtestsupport_widgets.h +++ b/src/widgets/kernel/qtestsupport_widgets.h @@ -40,7 +40,7 @@ #ifndef QTESTSUPPORT_WIDGETS_H #define QTESTSUPPORT_WIDGETS_H -#include "qtwidgetsglobal.h" +#include QT_BEGIN_NAMESPACE -- cgit v1.2.3 From 1825426187ba7fa5d53b1ad7c4eea1a1ad5f4b2c Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Mon, 25 Nov 2019 16:00:06 +0100 Subject: QtWidgets: Fix warnings about providing function for DESIGNABLE in property declaration Set them to be designable by default, fixing: kernel/qaction.h:66: Warning: Providing a function for DESIGNABLE in a property declaration is deprecated and will not be supported in Qt 6 anymore. kernel/qwidget.h:178: Warning: Providing a function for DESIGNABLE in a property declaration is deprecated and will not be supported in Qt 6 anymore. kernel/qwidget.h:179: Warning: Providing a function for DESIGNABLE in a property declaration is deprecated and will not be supported in Qt 6 anymore. kernel/qwidget.h:180: Warning: Providing a function for DESIGNABLE in a property declaration is deprecated and will not be supported in Qt 6 anymore. kernel/qwidget.h:181: Warning: Providing a function for DESIGNABLE in a property declaration is deprecated and will not be supported in Qt 6 anymore. kernel/qwidget.h:182: Warning: Providing a function for DESIGNABLE in a property declaration is deprecated and will not be supported in Qt 6 anymore. kernel/qwidget.h:204: Warning: Providing a function for DESIGNABLE in a property declaration is deprecated and will not be supported in Qt 6 anymore. widgets/qabstractbutton.h:67: Warning: Providing a function for DESIGNABLE in a property declaration is deprecated and will not be supported in Qt 6 anymore. widgets/qgroupbox.h:60: Warning: Providing a function for DESIGNABLE in a property declaration is deprecated and will not be supported in Qt 6 anymore. The toolbar properties were not caught by the warnings, but it appears the checks do not work; the properties are designable when parented on a non-QMainWindow parent. Change-Id: Ib7dfb878ba593f2dfa05b85db2c384bf3d860e46 Reviewed-by: Jarek Kobus Reviewed-by: Richard Moe Gustavsen --- src/widgets/kernel/qaction.h | 2 +- src/widgets/kernel/qwidget.h | 12 ++++++------ src/widgets/widgets/qabstractbutton.h | 2 +- src/widgets/widgets/qgroupbox.h | 2 +- src/widgets/widgets/qtoolbar.h | 12 +++--------- 5 files changed, 12 insertions(+), 18 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/kernel/qaction.h b/src/widgets/kernel/qaction.h index f7693f4dde..258a1ea0a0 100644 --- a/src/widgets/kernel/qaction.h +++ b/src/widgets/kernel/qaction.h @@ -63,7 +63,7 @@ class Q_WIDGETS_EXPORT QAction : public QObject Q_DECLARE_PRIVATE(QAction) Q_PROPERTY(bool checkable READ isCheckable WRITE setCheckable NOTIFY changed) - Q_PROPERTY(bool checked READ isChecked WRITE setChecked DESIGNABLE isCheckable NOTIFY toggled) + Q_PROPERTY(bool checked READ isChecked WRITE setChecked NOTIFY toggled) Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY changed) Q_PROPERTY(QIcon icon READ icon WRITE setIcon NOTIFY changed) Q_PROPERTY(QString text READ text WRITE setText NOTIFY changed) diff --git a/src/widgets/kernel/qwidget.h b/src/widgets/kernel/qwidget.h index 83a6e6d4b3..415a738eb4 100644 --- a/src/widgets/kernel/qwidget.h +++ b/src/widgets/kernel/qwidget.h @@ -175,11 +175,11 @@ class Q_WIDGETS_EXPORT QWidget : public QObject, public QPaintDevice Q_PROPERTY(QSize sizeHint READ sizeHint) Q_PROPERTY(QSize minimumSizeHint READ minimumSizeHint) Q_PROPERTY(bool acceptDrops READ acceptDrops WRITE setAcceptDrops) - Q_PROPERTY(QString windowTitle READ windowTitle WRITE setWindowTitle NOTIFY windowTitleChanged DESIGNABLE isWindow) - Q_PROPERTY(QIcon windowIcon READ windowIcon WRITE setWindowIcon NOTIFY windowIconChanged DESIGNABLE isWindow) - Q_PROPERTY(QString windowIconText READ windowIconText WRITE setWindowIconText NOTIFY windowIconTextChanged DESIGNABLE isWindow) // deprecated - Q_PROPERTY(double windowOpacity READ windowOpacity WRITE setWindowOpacity DESIGNABLE isWindow) - Q_PROPERTY(bool windowModified READ isWindowModified WRITE setWindowModified DESIGNABLE isWindow) + Q_PROPERTY(QString windowTitle READ windowTitle WRITE setWindowTitle NOTIFY windowTitleChanged) + Q_PROPERTY(QIcon windowIcon READ windowIcon WRITE setWindowIcon NOTIFY windowIconChanged) + Q_PROPERTY(QString windowIconText READ windowIconText WRITE setWindowIconText NOTIFY windowIconTextChanged) // deprecated + Q_PROPERTY(double windowOpacity READ windowOpacity WRITE setWindowOpacity) + Q_PROPERTY(bool windowModified READ isWindowModified WRITE setWindowModified) #ifndef QT_NO_TOOLTIP Q_PROPERTY(QString toolTip READ toolTip WRITE setToolTip) Q_PROPERTY(int toolTipDuration READ toolTipDuration WRITE setToolTipDuration) @@ -201,7 +201,7 @@ class Q_WIDGETS_EXPORT QWidget : public QObject, public QPaintDevice Q_PROPERTY(QString styleSheet READ styleSheet WRITE setStyleSheet) #endif Q_PROPERTY(QLocale locale READ locale WRITE setLocale RESET unsetLocale) - Q_PROPERTY(QString windowFilePath READ windowFilePath WRITE setWindowFilePath DESIGNABLE isWindow) + Q_PROPERTY(QString windowFilePath READ windowFilePath WRITE setWindowFilePath) Q_PROPERTY(Qt::InputMethodHints inputMethodHints READ inputMethodHints WRITE setInputMethodHints) public: diff --git a/src/widgets/widgets/qabstractbutton.h b/src/widgets/widgets/qabstractbutton.h index e8dee142f2..50c94654f3 100644 --- a/src/widgets/widgets/qabstractbutton.h +++ b/src/widgets/widgets/qabstractbutton.h @@ -64,7 +64,7 @@ class Q_WIDGETS_EXPORT QAbstractButton : public QWidget Q_PROPERTY(QKeySequence shortcut READ shortcut WRITE setShortcut) #endif Q_PROPERTY(bool checkable READ isCheckable WRITE setCheckable) - Q_PROPERTY(bool checked READ isChecked WRITE setChecked DESIGNABLE isCheckable NOTIFY toggled USER true) + Q_PROPERTY(bool checked READ isChecked WRITE setChecked NOTIFY toggled USER true) Q_PROPERTY(bool autoRepeat READ autoRepeat WRITE setAutoRepeat) Q_PROPERTY(bool autoExclusive READ autoExclusive WRITE setAutoExclusive) Q_PROPERTY(int autoRepeatDelay READ autoRepeatDelay WRITE setAutoRepeatDelay) diff --git a/src/widgets/widgets/qgroupbox.h b/src/widgets/widgets/qgroupbox.h index deaeba4656..bd8394b43b 100644 --- a/src/widgets/widgets/qgroupbox.h +++ b/src/widgets/widgets/qgroupbox.h @@ -57,7 +57,7 @@ class Q_WIDGETS_EXPORT QGroupBox : public QWidget Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment) Q_PROPERTY(bool flat READ isFlat WRITE setFlat) Q_PROPERTY(bool checkable READ isCheckable WRITE setCheckable) - Q_PROPERTY(bool checked READ isChecked WRITE setChecked DESIGNABLE isCheckable NOTIFY toggled USER true) + Q_PROPERTY(bool checked READ isChecked WRITE setChecked NOTIFY toggled USER true) public: explicit QGroupBox(QWidget *parent = nullptr); explicit QGroupBox(const QString &title, QWidget *parent = nullptr); diff --git a/src/widgets/widgets/qtoolbar.h b/src/widgets/widgets/qtoolbar.h index 0c434e8d1d..6aaf59cafd 100644 --- a/src/widgets/widgets/qtoolbar.h +++ b/src/widgets/widgets/qtoolbar.h @@ -59,15 +59,9 @@ class Q_WIDGETS_EXPORT QToolBar : public QWidget { Q_OBJECT - Q_PROPERTY(bool movable READ isMovable WRITE setMovable - DESIGNABLE (qobject_cast(parentWidget()) != 0) - NOTIFY movableChanged) - Q_PROPERTY(Qt::ToolBarAreas allowedAreas READ allowedAreas WRITE setAllowedAreas - DESIGNABLE (qobject_cast(parentWidget()) != 0) - NOTIFY allowedAreasChanged) - Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation - DESIGNABLE (qobject_cast(parentWidget()) == 0) - NOTIFY orientationChanged) + Q_PROPERTY(bool movable READ isMovable WRITE setMovable NOTIFY movableChanged) + Q_PROPERTY(Qt::ToolBarAreas allowedAreas READ allowedAreas WRITE setAllowedAreas NOTIFY allowedAreasChanged) + Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation NOTIFY orientationChanged) Q_PROPERTY(QSize iconSize READ iconSize WRITE setIconSize NOTIFY iconSizeChanged) Q_PROPERTY(Qt::ToolButtonStyle toolButtonStyle READ toolButtonStyle WRITE setToolButtonStyle NOTIFY toolButtonStyleChanged) -- cgit v1.2.3