#include <QSqlQueryModel>
#include <QSqlRecord>
#include <QDebug>
+#include <QTime>
+#include <QAbstractItemView>
EFComboBox::EFComboBox(DatabaseManager *dbMan, QWidget *parent)
: QComboBox(parent), dbManager(dbMan)
{
if (!dbManager)
throw new EmuFrontException("Database manager is not available!");
+ setSizeAdjustPolicy(QComboBox::AdjustToContents);
updateDataModel();
}
<< " [" << efo->getId() << "].";
QSqlQueryModel *qmodel
= dynamic_cast<QSqlQueryModel*>(model());
- for (int i = 0; i < qmodel->rowCount(); i++){
- QSqlRecord rec = qmodel->record(i);
- int id = rec.value(dataModelIndex_id).toInt();
- qDebug() << "Checking record with id " << rec.value(dataModelIndex_id)
- << " and name " << rec.value(dataModelIndex_name);
- if (id == efo->getId()){
- qDebug() << "Found!";
- setCurrentIndex(i);
- show();
- 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());
+ }
}