SelectionEditorFactory + ItemModel + ItemModelFactory combination is working
in new EditTableWidget (EditTableWidget is very much WIP)
This commit is contained in:
parent
e44f73166f
commit
742fd0a4d3
19 changed files with 419 additions and 80 deletions
|
|
@ -30,16 +30,15 @@ void SelectionEditorFactory::setEditorData(QWidget *editor, const QModelIndex &i
|
|||
QComboBox *cmbbx = dynamic_cast<QComboBox*>(editor);
|
||||
if (cmbbx) {
|
||||
auto data = index.data();
|
||||
if (data.canConvert<QString>()) {
|
||||
auto selection_model = cmbbx->model();
|
||||
QModelIndexList indexes = selection_model->match(
|
||||
selection_model->index(0, m_keyColumn), Qt::DisplayRole, data, 1, Qt::MatchFlags( Qt::MatchExactly ));
|
||||
if (!indexes.empty()) {
|
||||
cmbbx->setCurrentIndex(indexes.at(0).row());
|
||||
}
|
||||
else {
|
||||
cmbbx->setCurrentIndex(-1);
|
||||
}
|
||||
|
||||
auto list_model = cmbbx->model();
|
||||
QModelIndexList indexes = list_model->match(
|
||||
list_model->index(0, m_keyColumn), Qt::DisplayRole, data, 1, Qt::MatchFlags( Qt::MatchExactly ));
|
||||
if (!indexes.empty()) {
|
||||
cmbbx->setCurrentIndex(indexes.at(0).row());
|
||||
}
|
||||
else {
|
||||
cmbbx->setCurrentIndex(-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -50,9 +49,9 @@ void SelectionEditorFactory::setModelData(QWidget *editor, QAbstractItemModel *m
|
|||
if (cmbbx) {
|
||||
auto data = index.data();
|
||||
if (data.canConvert<QString>()) {
|
||||
auto selection_model = cmbbx->model();
|
||||
QVariant d = selection_model->data(
|
||||
selection_model->index(cmbbx->currentIndex(), m_keyColumn));
|
||||
auto list_model = cmbbx->model();
|
||||
QVariant d = list_model->data(
|
||||
list_model->index(cmbbx->currentIndex(), m_keyColumn));
|
||||
model->setData(index, d);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue