From 2dd69364e5219f39093dd598cadac84f18ec4812 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Mikko=20Kein=C3=A4nen?= Date: Tue, 26 Oct 2010 02:22:30 +0300 Subject: [PATCH] Using match instead of looping. --- src/widgets/efcombobox.cpp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/widgets/efcombobox.cpp b/src/widgets/efcombobox.cpp index 72791fe..c30a371 100644 --- a/src/widgets/efcombobox.cpp +++ b/src/widgets/efcombobox.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include EFComboBox::EFComboBox(DatabaseManager *dbMan, QWidget *parent) @@ -78,15 +79,13 @@ void EFComboBox::setSelected(const EmuFrontObject *efo) << " [" << efo->getId() << "]."; QSqlQueryModel *qmodel = dynamic_cast(model()); - for (int i = 0; i < qmodel->rowCount(); i++){ - QSqlRecord rec = qmodel->record(i); - int id = rec.value(dataModelIndex_id).toInt(); - if (id == efo->getId()){ - QModelIndex ind = qmodel->index(i, 0); - //view()->selectionModel()->select(ind, QItemSelectionModel::Select); - view()->setCurrentIndex(ind); - setCurrentIndex(i); - break; - } + QModelIndex idStart = qmodel->index(0, dataModelIndex_id); + int targetId = efo->getId(); + + QModelIndexList indLst = qmodel->match(idStart,Qt::DisplayRole, targetId, 1); + if (indLst.count() >= 1) { + QModelIndex ind = indLst.first(); + view()->setCurrentIndex(ind); + setCurrentIndex(ind.row()); } } -- 1.7.9.5