}
void ModelPropertyMapper::setModel(QAbstractItemModel *model) {
- if(_model)
+ if(_model) {
setSelectionModel(new QItemSelectionModel(model));
+ disconnect(_model, SIGNAL(dataChanged(QModelIndex, QModelIndex)),
+ this, SLOT(dataChanged(QModelIndex, QModelIndex)));
+ }
_model = model;
+ connect(_model, SIGNAL(dataChanged(QModelIndex, QModelIndex)),
+ this, SLOT(dataChanged(QModelIndex, QModelIndex)));
}
QAbstractItemModel *ModelPropertyMapper::model() const {
Q_UNUSED(previous)
foreach(Mapping mapping, _mappings) {
QModelIndex index = current.sibling(current.row(), mapping.column);
- // qDebug() << mapping.target << mapping.property << index.data(mapping.role);
mapping.target->setProperty(mapping.property, index.data(mapping.role));
}
}
+void ModelPropertyMapper::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight) {
+ QItemSelectionRange changedRange(topLeft, bottomRight);
+ foreach(Mapping mapping, _mappings) {
+ QModelIndex index = _selectionModel->currentIndex().sibling(_selectionModel->currentIndex().row(), mapping.column);
+ if(changedRange.contains(index)) {
+ mapping.target->setProperty(mapping.property, index.data(mapping.role));
+ }
+ }
+}
void ModelPropertyMapper::targetDestroyed() {
QObject *obj = static_cast<QObject *>(sender());