X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fclient%2Fmodelpropertymapper.cpp;h=890eda42295d94b374fac6c7afda1fe49ff482ea;hp=a59a7a52fe3a811f21dfddbbcc7d59b3ebce330b;hb=c9ef00c67a47448e92398a5dce6ce5b74e77783a;hpb=42ce41212deabaf284cc496760cb901b9e3b4dc4 diff --git a/src/client/modelpropertymapper.cpp b/src/client/modelpropertymapper.cpp index a59a7a52..890eda42 100644 --- a/src/client/modelpropertymapper.cpp +++ b/src/client/modelpropertymapper.cpp @@ -1,11 +1,11 @@ /*************************************************************************** - * Copyright (C) 2005-07 by The Quassel Team * + * Copyright (C) 2005-07 by the Quassel IRC Team * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * + * (at your option) version 3. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * @@ -34,9 +34,14 @@ ModelPropertyMapper::~ModelPropertyMapper() { } 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 { @@ -95,11 +100,19 @@ void ModelPropertyMapper::setCurrentRow(const QModelIndex ¤t, const QModel 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(sender());