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 <Friedemann.Kleint@qt.io>
This commit is contained in:
parent
0e0793ca59
commit
f0443984b8
@ -91,30 +91,11 @@ QT_BEGIN_NAMESPACE
|
|||||||
|
|
||||||
QComboBoxPrivate::QComboBoxPrivate()
|
QComboBoxPrivate::QComboBoxPrivate()
|
||||||
: QWidgetPrivate(),
|
: QWidgetPrivate(),
|
||||||
model(0),
|
|
||||||
lineEdit(0),
|
|
||||||
container(0),
|
|
||||||
insertPolicy(QComboBox::InsertAtBottom),
|
|
||||||
sizeAdjustPolicy(QComboBox::AdjustToContentsOnFirstShow),
|
|
||||||
minimumContentsLength(0),
|
|
||||||
shownOnce(false),
|
shownOnce(false),
|
||||||
autoCompletion(true),
|
autoCompletion(true),
|
||||||
duplicatesEnabled(false),
|
duplicatesEnabled(false),
|
||||||
frame(true),
|
frame(true),
|
||||||
maxVisibleItems(10),
|
inserting(false)
|
||||||
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
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -447,12 +428,8 @@ void QComboBoxPrivateContainer::paintEvent(QPaintEvent *e)
|
|||||||
QFrame::paintEvent(e);
|
QFrame::paintEvent(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QComboBoxPrivateContainer::leaveEvent(QEvent *)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
QComboBoxPrivateContainer::QComboBoxPrivateContainer(QAbstractItemView *itemView, QComboBox *parent)
|
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
|
// we need the combobox and itemview
|
||||||
Q_ASSERT(parent);
|
Q_ASSERT(parent);
|
||||||
@ -557,7 +534,7 @@ void QComboBoxPrivateContainer::updateScrollers()
|
|||||||
*/
|
*/
|
||||||
void QComboBoxPrivateContainer::viewDestroyed()
|
void QComboBoxPrivateContainer::viewDestroyed()
|
||||||
{
|
{
|
||||||
view = 0;
|
view = nullptr;
|
||||||
setItemView(new QComboBoxListView());
|
setItemView(new QComboBoxListView());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -591,7 +568,7 @@ void QComboBoxPrivateContainer::setItemView(QAbstractItemView *itemView)
|
|||||||
|
|
||||||
if (isAncestorOf(view))
|
if (isAncestorOf(view))
|
||||||
delete view;
|
delete view;
|
||||||
view = 0;
|
view = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// setup the item view
|
// setup the item view
|
||||||
@ -1568,7 +1545,7 @@ void QComboBox::setAutoCompletion(bool enable)
|
|||||||
d->lineEdit->setCompleter(d->completer);
|
d->lineEdit->setCompleter(d->completer);
|
||||||
d->completer->setWidget(this);
|
d->completer->setWidget(this);
|
||||||
} else {
|
} else {
|
||||||
d->lineEdit->setCompleter(0);
|
d->lineEdit->setCompleter(nullptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1757,7 +1734,7 @@ QSize QComboBox::iconSize() const
|
|||||||
if (d->iconSize.isValid())
|
if (d->iconSize.isValid())
|
||||||
return d->iconSize;
|
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);
|
return QSize(iconWidth, iconWidth);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1827,7 +1804,7 @@ QString QComboBox::placeholderText() const
|
|||||||
bool QComboBox::isEditable() const
|
bool QComboBox::isEditable() const
|
||||||
{
|
{
|
||||||
Q_D(const QComboBox);
|
Q_D(const QComboBox);
|
||||||
return d->lineEdit != 0;
|
return d->lineEdit != nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! \internal
|
/*! \internal
|
||||||
@ -1883,7 +1860,7 @@ void QComboBox::setEditable(bool editable)
|
|||||||
setAttribute(Qt::WA_InputMethodEnabled, false);
|
setAttribute(Qt::WA_InputMethodEnabled, false);
|
||||||
d->lineEdit->hide();
|
d->lineEdit->hide();
|
||||||
d->lineEdit->deleteLater();
|
d->lineEdit->deleteLater();
|
||||||
d->lineEdit = 0;
|
d->lineEdit = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
d->updateDelegate();
|
d->updateDelegate();
|
||||||
@ -1932,6 +1909,8 @@ void QComboBox::setLineEdit(QLineEdit *edit)
|
|||||||
d->lineEdit->setFocusProxy(this);
|
d->lineEdit->setFocusProxy(this);
|
||||||
d->lineEdit->setAttribute(Qt::WA_MacShowFocusRect, false);
|
d->lineEdit->setAttribute(Qt::WA_MacShowFocusRect, false);
|
||||||
#if QT_DEPRECATED_SINCE(5, 13)
|
#if QT_DEPRECATED_SINCE(5, 13)
|
||||||
|
QT_WARNING_PUSH
|
||||||
|
QT_WARNING_DISABLE_DEPRECATED
|
||||||
#if QT_CONFIG(completer)
|
#if QT_CONFIG(completer)
|
||||||
setAutoCompletion(d->autoCompletion);
|
setAutoCompletion(d->autoCompletion);
|
||||||
|
|
||||||
@ -1948,6 +1927,7 @@ void QComboBox::setLineEdit(QLineEdit *edit)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
QT_WARNING_POP
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
setAttribute(Qt::WA_InputMethodEnabled);
|
setAttribute(Qt::WA_InputMethodEnabled);
|
||||||
@ -1996,7 +1976,7 @@ void QComboBox::setValidator(const QValidator *v)
|
|||||||
const QValidator *QComboBox::validator() const
|
const QValidator *QComboBox::validator() const
|
||||||
{
|
{
|
||||||
Q_D(const QComboBox);
|
Q_D(const QComboBox);
|
||||||
return d->lineEdit ? d->lineEdit->validator() : 0;
|
return d->lineEdit ? d->lineEdit->validator() : nullptr;
|
||||||
}
|
}
|
||||||
#endif // QT_NO_VALIDATOR
|
#endif // QT_NO_VALIDATOR
|
||||||
|
|
||||||
@ -2040,7 +2020,7 @@ void QComboBox::setCompleter(QCompleter *c)
|
|||||||
QCompleter *QComboBox::completer() const
|
QCompleter *QComboBox::completer() const
|
||||||
{
|
{
|
||||||
Q_D(const QComboBox);
|
Q_D(const QComboBox);
|
||||||
return d->lineEdit ? d->lineEdit->completer() : 0;
|
return d->lineEdit ? d->lineEdit->completer() : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // QT_CONFIG(completer)
|
#endif // QT_CONFIG(completer)
|
||||||
@ -2927,7 +2907,7 @@ void QComboBox::hidePopup()
|
|||||||
QSignalBlocker containerBlocker(d->container);
|
QSignalBlocker containerBlocker(d->container);
|
||||||
// Flash selected/triggered item (if any).
|
// Flash selected/triggered item (if any).
|
||||||
if (style()->styleHint(QStyle::SH_Menu_FlashTriggeredItem)) {
|
if (style()->styleHint(QStyle::SH_Menu_FlashTriggeredItem)) {
|
||||||
QItemSelectionModel *selectionModel = view() ? view()->selectionModel() : 0;
|
QItemSelectionModel *selectionModel = view() ? view()->selectionModel() : nullptr;
|
||||||
if (selectionModel && selectionModel->hasSelection()) {
|
if (selectionModel && selectionModel->hasSelection()) {
|
||||||
QEventLoop eventLoop;
|
QEventLoop eventLoop;
|
||||||
const QItemSelection selection = selectionModel->selection();
|
const QItemSelection selection = selectionModel->selection();
|
||||||
|
@ -79,7 +79,6 @@ QT_REQUIRE_CONFIG(combobox);
|
|||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
class QAction;
|
|
||||||
class QPlatformMenu;
|
class QPlatformMenu;
|
||||||
|
|
||||||
class QComboBoxListView : public QListView
|
class QComboBoxListView : public QListView
|
||||||
@ -131,9 +130,6 @@ private:
|
|||||||
QComboBox *combo;
|
QComboBox *combo;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class QStandardItemModel;
|
|
||||||
|
|
||||||
class Q_AUTOTEST_EXPORT QComboBoxPrivateScroller : public QWidget
|
class Q_AUTOTEST_EXPORT QComboBoxPrivateScroller : public QWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -212,7 +208,7 @@ Q_SIGNALS:
|
|||||||
private:
|
private:
|
||||||
QAbstractSlider::SliderAction sliderAction;
|
QAbstractSlider::SliderAction sliderAction;
|
||||||
QBasicTimer timer;
|
QBasicTimer timer;
|
||||||
bool fast;
|
bool fast = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Q_WIDGETS_EXPORT QComboBoxPrivateContainer : public QFrame
|
class Q_WIDGETS_EXPORT QComboBoxPrivateContainer : public QFrame
|
||||||
@ -246,7 +242,6 @@ protected:
|
|||||||
void showEvent(QShowEvent *e) override;
|
void showEvent(QShowEvent *e) override;
|
||||||
void hideEvent(QHideEvent *e) override;
|
void hideEvent(QHideEvent *e) override;
|
||||||
void timerEvent(QTimerEvent *timerEvent) override;
|
void timerEvent(QTimerEvent *timerEvent) override;
|
||||||
void leaveEvent(QEvent *e) override;
|
|
||||||
void resizeEvent(QResizeEvent *e) override;
|
void resizeEvent(QResizeEvent *e) override;
|
||||||
void paintEvent(QPaintEvent *e) override;
|
void paintEvent(QPaintEvent *e) override;
|
||||||
QStyleOptionComboBox comboStyleOption() const;
|
QStyleOptionComboBox comboStyleOption() const;
|
||||||
@ -257,18 +252,19 @@ Q_SIGNALS:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
QComboBox *combo;
|
QComboBox *combo;
|
||||||
QAbstractItemView *view;
|
QAbstractItemView *view = nullptr;
|
||||||
QComboBoxPrivateScroller *top;
|
QComboBoxPrivateScroller *top = nullptr;
|
||||||
QComboBoxPrivateScroller *bottom;
|
QComboBoxPrivateScroller *bottom = nullptr;
|
||||||
bool maybeIgnoreMouseButtonRelease;
|
|
||||||
QElapsedTimer popupTimer;
|
QElapsedTimer popupTimer;
|
||||||
|
bool maybeIgnoreMouseButtonRelease = false;
|
||||||
|
|
||||||
friend class QComboBox;
|
friend class QComboBox;
|
||||||
friend class QComboBoxPrivate;
|
friend class QComboBoxPrivate;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Q_AUTOTEST_EXPORT QComboMenuDelegate : public QAbstractItemDelegate
|
class Q_AUTOTEST_EXPORT QComboMenuDelegate : public QAbstractItemDelegate
|
||||||
{ Q_OBJECT
|
{
|
||||||
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
QComboMenuDelegate(QObject *parent, QComboBox *cmb) : QAbstractItemDelegate(parent), mCombo(cmb) {}
|
QComboMenuDelegate(QObject *parent, QComboBox *cmb) : QAbstractItemDelegate(parent), mCombo(cmb) {}
|
||||||
|
|
||||||
@ -355,8 +351,8 @@ public:
|
|||||||
void _q_complete();
|
void _q_complete();
|
||||||
void _q_itemSelected(const QModelIndex &item);
|
void _q_itemSelected(const QModelIndex &item);
|
||||||
bool contains(const QString &text, int role);
|
bool contains(const QString &text, int role);
|
||||||
void emitActivated(const QModelIndex&);
|
void emitActivated(const QModelIndex &index);
|
||||||
void _q_emitHighlighted(const QModelIndex&);
|
void _q_emitHighlighted(const QModelIndex &index);
|
||||||
void _q_emitCurrentIndexChanged(const QModelIndex &index);
|
void _q_emitCurrentIndexChanged(const QModelIndex &index);
|
||||||
void _q_modelDestroyed();
|
void _q_modelDestroyed();
|
||||||
void _q_modelReset();
|
void _q_modelReset();
|
||||||
@ -402,40 +398,38 @@ public:
|
|||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
QAbstractItemModel *model;
|
QAbstractItemModel *model = nullptr;
|
||||||
QLineEdit *lineEdit;
|
QLineEdit *lineEdit = nullptr;
|
||||||
QComboBoxPrivateContainer *container;
|
QComboBoxPrivateContainer *container = nullptr;
|
||||||
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;
|
|
||||||
#ifdef Q_OS_MAC
|
#ifdef Q_OS_MAC
|
||||||
QPlatformMenu *m_platformMenu;
|
QPlatformMenu *m_platformMenu = nullptr;
|
||||||
#endif
|
#endif
|
||||||
#if QT_CONFIG(completer)
|
#if QT_CONFIG(completer)
|
||||||
QPointer<QCompleter> completer;
|
QPointer<QCompleter> completer;
|
||||||
#endif
|
#endif
|
||||||
static QPalette viewContainerPalette(QComboBox *cmb)
|
QPersistentModelIndex currentIndex;
|
||||||
{ return cmb->d_func()->viewContainer()->palette(); }
|
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<int>::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
|
QT_END_NAMESPACE
|
||||||
|
Loading…
x
Reference in New Issue
Block a user