summaryrefslogtreecommitdiffstats
path: root/src/widgets/widgets/qcombobox.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/widgets/widgets/qcombobox.cpp')
-rw-r--r--src/widgets/widgets/qcombobox.cpp39
1 files changed, 22 insertions, 17 deletions
diff --git a/src/widgets/widgets/qcombobox.cpp b/src/widgets/widgets/qcombobox.cpp
index ed3af90532..c442ace476 100644
--- a/src/widgets/widgets/qcombobox.cpp
+++ b/src/widgets/widgets/qcombobox.cpp
@@ -1360,7 +1360,7 @@ int QComboBox::maxVisibleItems() const
void QComboBox::setMaxVisibleItems(int maxItems)
{
Q_D(QComboBox);
- if (maxItems < 0) {
+ if (Q_UNLIKELY(maxItems < 0)) {
qWarning("QComboBox::setMaxVisibleItems: "
"Invalid max visible items (%d) must be >= 0", maxItems);
return;
@@ -1395,13 +1395,14 @@ int QComboBox::count() const
void QComboBox::setMaxCount(int max)
{
Q_D(QComboBox);
- if (max < 0) {
+ if (Q_UNLIKELY(max < 0)) {
qWarning("QComboBox::setMaxCount: Invalid count (%d) must be >= 0", max);
return;
}
- if (max < count())
- d->model->removeRows(max, count() - max, d->root);
+ const int rowCount = count();
+ if (rowCount > max)
+ d->model->removeRows(max, rowCount - max, d->root);
d->maxCount = max;
}
@@ -1448,7 +1449,7 @@ void QComboBox::setAutoCompletion(bool enable)
Q_D(QComboBox);
#ifdef QT_KEYPAD_NAVIGATION
- if (QApplication::keypadNavigationEnabled() && !enable && isEditable())
+ if (Q_UNLIKELY(QApplication::keypadNavigationEnabled() && !enable && isEditable()))
qWarning("QComboBox::setAutoCompletion: auto completion is mandatory when combo box editable");
#endif
@@ -1547,9 +1548,8 @@ void QComboBox::setDuplicatesEnabled(bool enable)
int QComboBox::findData(const QVariant &data, int role, Qt::MatchFlags flags) const
{
Q_D(const QComboBox);
- QModelIndexList result;
QModelIndex start = d->model->index(0, d->modelColumn, d->root);
- result = d->model->match(start, role, data, 1, flags);
+ const QModelIndexList result = d->model->match(start, role, data, 1, flags);
if (result.isEmpty())
return -1;
return result.first().row();
@@ -1758,7 +1758,7 @@ void QComboBox::setEditable(bool editable)
void QComboBox::setLineEdit(QLineEdit *edit)
{
Q_D(QComboBox);
- if (!edit) {
+ if (Q_UNLIKELY(!edit)) {
qWarning("QComboBox::setLineEdit: cannot set a 0 line edit");
return;
}
@@ -1770,7 +1770,9 @@ void QComboBox::setLineEdit(QLineEdit *edit)
delete d->lineEdit;
d->lineEdit = edit;
+#ifndef QT_NO_IM
qt_widget_private(d->lineEdit)->inheritsInputMethodHints = 1;
+#endif
if (d->lineEdit->parent() != this)
d->lineEdit->setParent(this);
connect(d->lineEdit, SIGNAL(returnPressed()), this, SLOT(_q_returnPressed()));
@@ -1915,7 +1917,7 @@ QAbstractItemDelegate *QComboBox::itemDelegate() const
*/
void QComboBox::setItemDelegate(QAbstractItemDelegate *delegate)
{
- if (!delegate) {
+ if (Q_UNLIKELY(!delegate)) {
qWarning("QComboBox::setItemDelegate: cannot set a 0 delegate");
return;
}
@@ -1947,7 +1949,7 @@ void QComboBox::setModel(QAbstractItemModel *model)
{
Q_D(QComboBox);
- if (!model) {
+ if (Q_UNLIKELY(!model)) {
qWarning("QComboBox::setModel: cannot set a 0 model");
return;
}
@@ -2393,7 +2395,7 @@ QAbstractItemView *QComboBox::view() const
void QComboBox::setView(QAbstractItemView *itemView)
{
Q_D(QComboBox);
- if (!itemView) {
+ if (Q_UNLIKELY(!itemView)) {
qWarning("QComboBox::setView: cannot set a 0 view");
return;
}
@@ -2583,7 +2585,7 @@ void QComboBox::showPopup()
#endif
while (!toCheck.isEmpty()) {
QModelIndex parent = toCheck.pop();
- for (int i = 0; i < d->model->rowCount(parent); ++i) {
+ for (int i = 0, end = d->model->rowCount(parent); i < end; ++i) {
QModelIndex idx = d->model->index(i, d->modelColumn, parent);
if (!idx.isValid())
continue;
@@ -3192,6 +3194,8 @@ void QComboBox::keyPressEvent(QKeyEvent *e)
}
}
+ const int rowCount = count();
+
if (move != NoMove) {
e->accept();
switch (move) {
@@ -3199,11 +3203,11 @@ void QComboBox::keyPressEvent(QKeyEvent *e)
newIndex = -1;
case MoveDown:
newIndex++;
- while ((newIndex < count()) && !(d->model->flags(d->model->index(newIndex,d->modelColumn,d->root)) & Qt::ItemIsEnabled))
+ while (newIndex < rowCount && !(d->model->index(newIndex, d->modelColumn, d->root).flags() & Qt::ItemIsEnabled))
newIndex++;
break;
case MoveLast:
- newIndex = count();
+ newIndex = rowCount;
case MoveUp:
newIndex--;
while ((newIndex >= 0) && !(d->model->flags(d->model->index(newIndex,d->modelColumn,d->root)) & Qt::ItemIsEnabled))
@@ -3214,7 +3218,7 @@ void QComboBox::keyPressEvent(QKeyEvent *e)
break;
}
- if (newIndex >= 0 && newIndex < count() && newIndex != currentIndex()) {
+ if (newIndex >= 0 && newIndex < rowCount && newIndex != currentIndex()) {
setCurrentIndex(newIndex);
d->emitActivated(d->currentIndex);
}
@@ -3247,6 +3251,7 @@ void QComboBox::wheelEvent(QWheelEvent *e)
#else
Q_D(QComboBox);
if (!d->viewContainer()->isVisible()) {
+ const int rowCount = count();
int newIndex = currentIndex();
if (e->delta() > 0) {
@@ -3255,11 +3260,11 @@ void QComboBox::wheelEvent(QWheelEvent *e)
newIndex--;
} else if (e->delta() < 0) {
newIndex++;
- while ((newIndex < count()) && !(d->model->flags(d->model->index(newIndex,d->modelColumn,d->root)) & Qt::ItemIsEnabled))
+ while (newIndex < rowCount && !(d->model->index(newIndex, d->modelColumn, d->root).flags() & Qt::ItemIsEnabled))
newIndex++;
}
- if (newIndex >= 0 && newIndex < count() && newIndex != currentIndex()) {
+ if (newIndex >= 0 && newIndex < rowCount && newIndex != currentIndex()) {
setCurrentIndex(newIndex);
d->emitActivated(d->currentIndex);
}