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()
|
||||
: 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();
|
||||
|
@ -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<QCompleter> 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<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
|
||||
|
Loading…
x
Reference in New Issue
Block a user