X-Git-Url: https://git.quassel-irc.org/?a=blobdiff_plain;f=src%2Fclient%2Fbuffertreemodel.cpp;h=a881b5f3cf85ce8d5e33c9670af8c57f636e190f;hb=f123125ae33f48de4514a36b1518dab4a781b551;hp=26612f97c434534522d129b719915a808255f804;hpb=8a618fb4514d83a76cec8e7cd1319b935366a616;p=quassel.git diff --git a/src/client/buffertreemodel.cpp b/src/client/buffertreemodel.cpp index 26612f97..a881b5f3 100644 --- a/src/client/buffertreemodel.cpp +++ b/src/client/buffertreemodel.cpp @@ -22,6 +22,9 @@ #include "buffertreemodel.h" +#include "mappedselectionmodel.h" +#include + #include "bufferinfo.h" #include "client.h" #include "signalproxy.h" @@ -91,7 +94,7 @@ QVariant BufferTreeItem::data(int column, int role) const { Qt::ItemFlags BufferTreeItem::flags() const { Qt::ItemFlags flags = Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled; - if(buf->bufferType() == Buffer::QueryBuffer) + if(buf->bufferType() == Buffer::QueryType) flags |= Qt::ItemIsDropEnabled; return flags; @@ -117,9 +120,18 @@ Qt::ItemFlags NetworkTreeItem::flags() const { * BufferTreeModel *****************************************/ BufferTreeModel::BufferTreeModel(QObject *parent) - : TreeModel(BufferTreeModel::defaultHeader(), parent) + : TreeModel(BufferTreeModel::defaultHeader(), parent), + _selectionModelSynchronizer(new SelectionModelSynchronizer(this)), + _propertyMapper(new ModelPropertyMapper(this)) { - Client::signalProxy()->attachSignal(this, SIGNAL(fakeUserInput(BufferInfo, QString)), SIGNAL(sendInput(BufferInfo, QString))); + _propertyMapper->setModel(this); + delete _propertyMapper->selectionModel(); + MappedSelectionModel *mappedSelectionModel = new MappedSelectionModel(this); + _propertyMapper->setSelectionModel(mappedSelectionModel); + synchronizeSelectionModel(mappedSelectionModel); + + connect(_selectionModelSynchronizer, SIGNAL(setCurrentIndex(QModelIndex, QItemSelectionModel::SelectionFlags)), + this, SLOT(setCurrentIndex(QModelIndex, QItemSelectionModel::SelectionFlags))); } QListBufferTreeModel::defaultHeader() { @@ -128,6 +140,22 @@ QListBufferTreeModel::defaultHeader() { return data; } +void BufferTreeModel::synchronizeSelectionModel(MappedSelectionModel *selectionModel) { + selectionModelSynchronizer()->addSelectionModel(selectionModel); +} + +void BufferTreeModel::synchronizeView(QAbstractItemView *view) { + MappedSelectionModel *mappedSelectionModel = new MappedSelectionModel(view->model()); + selectionModelSynchronizer()->addSelectionModel(mappedSelectionModel); + Q_ASSERT(mappedSelectionModel); + delete view->selectionModel(); + view->setSelectionModel(mappedSelectionModel); +} + +void BufferTreeModel::mapProperty(int column, int role, QObject *target, const QByteArray &property) { + propertyMapper()->addMapping(column, role, target, property); +} + bool BufferTreeModel::isBufferIndex(const QModelIndex &index) const { // not so purdy... return parent(index) != QModelIndex(); @@ -209,7 +237,7 @@ bool BufferTreeModel::dropMimeData(const QMimeData *data, Qt::DropAction /*actio Buffer *sourceBuffer = static_cast(rootItem->childById(qHash(network))->child(sourcerow))->buffer(); Buffer *targetBuffer = getBufferByIndex(parent); - if(!(sourceBuffer->bufferType() & targetBuffer->bufferType() & Buffer::QueryBuffer)) // only queries can be merged + if(!(sourceBuffer->bufferType() & targetBuffer->bufferType() & Buffer::QueryType)) // only queries can be merged return false; if(sourceBuffer == targetBuffer) // we won't merge with ourself :) @@ -229,12 +257,13 @@ void BufferTreeModel::bufferUpdated(Buffer *buffer) { } // This Slot indicates that the user has selected a different buffer in the gui -void BufferTreeModel::changeCurrent(const QModelIndex ¤t, const QModelIndex &/*previous*/) { - if(isBufferIndex(current)) { - currentBuffer = getBufferByIndex(current); +void BufferTreeModel::setCurrentIndex(const QModelIndex &index, QItemSelectionModel::SelectionFlags command) { + Q_UNUSED(command) + if(isBufferIndex(index)) { + currentBuffer = getBufferByIndex(index); bufferActivity(Buffer::NoActivity, currentBuffer); emit bufferSelected(currentBuffer); - emit selectionChanged(current); + emit selectionChanged(index); } } @@ -249,6 +278,6 @@ void BufferTreeModel::bufferActivity(Buffer::ActivityLevel level, Buffer *buffer void BufferTreeModel::selectBuffer(Buffer *buffer) { QModelIndex index = getOrCreateBufferItemIndex(buffer); - //emit selectionChanged(index); - changeCurrent(index, QModelIndex()); + // SUPER UGLY! + setCurrentIndex(index, 0); }