From: Marcus Eggenberger Date: Sun, 30 Dec 2007 14:06:55 +0000 (+0000) Subject: Made the ModelPropertyMapper listen to dataChanged(QModelIndex, QModelIndex) signals... X-Git-Tag: 0.1.0~18 X-Git-Url: https://git.quassel-irc.org/?a=commitdiff_plain;h=c9ef00c67a47448e92398a5dce6ce5b74e77783a;p=quassel.git Made the ModelPropertyMapper listen to dataChanged(QModelIndex, QModelIndex) signals and thus making the topic bar notice topic changes --- diff --git a/src/client/modelpropertymapper.cpp b/src/client/modelpropertymapper.cpp index fe2ffcb7..890eda42 100644 --- a/src/client/modelpropertymapper.cpp +++ b/src/client/modelpropertymapper.cpp @@ -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()); diff --git a/src/client/modelpropertymapper.h b/src/client/modelpropertymapper.h index 44e902ab..27dafa5c 100644 --- a/src/client/modelpropertymapper.h +++ b/src/client/modelpropertymapper.h @@ -48,6 +48,7 @@ public: public slots: void setCurrentIndex(const QModelIndex ¤t, const QModelIndex &previous); void setCurrentRow(const QModelIndex ¤t, const QModelIndex &previous); + void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight); private slots: void targetDestroyed();