summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGabriel de Dietrich <gabriel.dietrich-de@nokia.com>2010-05-25 18:09:00 (GMT)
committerGabriel de Dietrich <gabriel.dietrich-de@nokia.com>2010-05-26 08:30:25 (GMT)
commit00edad4373d394ed9f828b1fa887003f87c5fa6f (patch)
treea6a35d37c0e1f58685b32699c77ab7dcd9f52e84
parent2e0ac76a76f02e22f101b24ba222f8251d0c2580 (diff)
downloadQt-00edad4373d394ed9f828b1fa887003f87c5fa6f.zip
Qt-00edad4373d394ed9f828b1fa887003f87c5fa6f.tar.gz
Qt-00edad4373d394ed9f828b1fa887003f87c5fa6f.tar.bz2
QComboBox::modelColumn was not respected when selecting an item
Auto-test included Reviewed-by: Olivier Task-number: QTBUG-10491
-rw-r--r--src/gui/widgets/qcombobox.cpp13
-rw-r--r--src/gui/widgets/qcombobox_p.h2
-rw-r--r--tests/auto/qcombobox/tst_qcombobox.cpp19
3 files changed, 30 insertions, 4 deletions
diff --git a/src/gui/widgets/qcombobox.cpp b/src/gui/widgets/qcombobox.cpp
index 6cf24a6..213ca95 100644
--- a/src/gui/widgets/qcombobox.cpp
+++ b/src/gui/widgets/qcombobox.cpp
@@ -2003,11 +2003,18 @@ void QComboBox::setCurrentIndex(int index)
void QComboBoxPrivate::setCurrentIndex(const QModelIndex &mi)
{
Q_Q(QComboBox);
- bool indexChanged = (mi != currentIndex);
+
+ QModelIndex normalized;
+ if (mi.column() != modelColumn)
+ normalized = model->index(mi.row(), modelColumn, mi.parent());
+ if (!normalized.isValid())
+ normalized = mi; // Fallback to passed index.
+
+ bool indexChanged = (normalized != currentIndex);
if (indexChanged)
- currentIndex = QPersistentModelIndex(mi);
+ currentIndex = QPersistentModelIndex(normalized);
if (lineEdit) {
- QString newText = q->itemText(currentIndex.row());
+ QString newText = q->itemText(normalized.row());
if (lineEdit->text() != newText)
lineEdit->setText(newText);
updateLineEditGeometry();
diff --git a/src/gui/widgets/qcombobox_p.h b/src/gui/widgets/qcombobox_p.h
index 29a628c..c0727ed 100644
--- a/src/gui/widgets/qcombobox_p.h
+++ b/src/gui/widgets/qcombobox_p.h
@@ -337,7 +337,7 @@ private:
QComboBox *mCombo;
};
-class QComboBoxPrivate : public QWidgetPrivate
+class Q_AUTOTEST_EXPORT QComboBoxPrivate : public QWidgetPrivate
{
Q_DECLARE_PUBLIC(QComboBox)
public:
diff --git a/tests/auto/qcombobox/tst_qcombobox.cpp b/tests/auto/qcombobox/tst_qcombobox.cpp
index fb6c741..f00f3ef 100644
--- a/tests/auto/qcombobox/tst_qcombobox.cpp
+++ b/tests/auto/qcombobox/tst_qcombobox.cpp
@@ -157,6 +157,7 @@ private slots:
void keyBoardNavigationWithMouse();
void task_QTBUG_1071_changingFocusEmitsActivated();
void maxVisibleItems();
+ void task_QTBUG_10491_currentIndexAndModelColumn();
protected slots:
void onEditTextChanged( const QString &newString );
@@ -2562,6 +2563,24 @@ void tst_QComboBox::maxVisibleItems()
QCOMPARE(v->viewport()->height(), itemHeight * comboBox.maxVisibleItems());
}
+void tst_QComboBox::task_QTBUG_10491_currentIndexAndModelColumn()
+{
+ QComboBox comboBox;
+
+ QStandardItemModel model(4, 4, &comboBox);
+ for (int i = 0; i < 4; i++){
+ model.setItem(i, 0, new QStandardItem(QString("Employee Nr %1").arg(i)));
+ model.setItem(i, 1, new QStandardItem(QString("Street Nr %1").arg(i)));
+ model.setItem(i, 2, new QStandardItem(QString("Town Nr %1").arg(i)));
+ model.setItem(i, 3, new QStandardItem(QString("Phone Nr %1").arg(i)));
+ }
+ comboBox.setModel(&model);
+ comboBox.setModelColumn(0);
+
+ QComboBoxPrivate *d = static_cast<QComboBoxPrivate *>(QComboBoxPrivate::get(&comboBox));
+ d->setCurrentIndex(model.index(2, 2));
+ QCOMPARE(QModelIndex(d->currentIndex), model.index(2, comboBox.modelColumn()));
+}
QTEST_MAIN(tst_QComboBox)
#include "tst_qcombobox.moc"