{
if (Q_UNLIKELY(!model)) {
qWarning("QComboBox::setModel: cannot set a 0 model");
return;
}
if (model == d->model)
return;
#ifndef QT_NO_COMPLETER
if (d->lineEdit && d->lineEdit->completer()
&& d->lineEdit->completer() == d->completer)
d->lineEdit->completer()->setModel(model);
#endif
if (d->model) {
disconnect
(d
->model,
SIGNAL(rowsAboutToBeInserted
(QModelIndex,
int,
int)),
this, SLOT(_q_updateIndexBeforeChange()));
disconnect
(d
->model,
SIGNAL(rowsInserted
(QModelIndex,
int,
int)),
disconnect
(d
->model,
SIGNAL(rowsAboutToBeRemoved
(QModelIndex,
int,
int)),
this, SLOT(_q_updateIndexBeforeChange()));
disconnect
(d
->model,
SIGNAL(rowsRemoved
(QModelIndex,
int,
int)),
disconnect(d->model, SIGNAL(destroyed()),
this, SLOT(_q_modelDestroyed()));
disconnect(d->model, SIGNAL(modelAboutToBeReset()),
this, SLOT(_q_updateIndexBeforeChange()));
disconnect(d->model, SIGNAL(modelReset()),
this, SLOT(_q_modelReset()));
if (d->model->QObject::parent() == this)
delete d->model;
}
d->model = model;
connect(model,
SIGNAL(rowsAboutToBeInserted
(QModelIndex,
int,
int)),
this, SLOT(_q_updateIndexBeforeChange()));
connect(model,
SIGNAL(rowsInserted
(QModelIndex,
int,
int)),
connect(model,
SIGNAL(rowsAboutToBeRemoved
(QModelIndex,
int,
int)),
this, SLOT(_q_updateIndexBeforeChange()));
connect(model,
SIGNAL(rowsRemoved
(QModelIndex,
int,
int)),
connect(model, SIGNAL(destroyed()),
this, SLOT(_q_modelDestroyed()));
connect(model, SIGNAL(modelAboutToBeReset()),
this, SLOT(_q_updateIndexBeforeChange()));
connect(model, SIGNAL(modelReset()),
this, SLOT(_q_modelReset()));
if (d->container) {
d->container->itemView()->setModel(model);
connect(d->container->itemView()->selectionModel(),
this,
SLOT(_q_emitHighlighted
(QModelIndex)), Qt
::UniqueConnection);
}
bool currentReset = false;
const int rowCount = count();
for (int pos=0; pos < rowCount; pos++) {
if (d->model->index(pos, d->modelColumn, d->root).flags() & Qt::ItemIsEnabled) {
setCurrentIndex(pos);
currentReset = true;
break;
}
}
if (!currentReset)
setCurrentIndex(-1);
d->modelChanged();
}