X-Git-Url: https://git.quassel-irc.org/?a=blobdiff_plain;f=src%2Fclient%2Fbuffertreemodel.cpp;h=a881b5f3cf85ce8d5e33c9670af8c57f636e190f;hb=f123125ae33f48de4514a36b1518dab4a781b551;hp=568f7e6c3b9fecaee47f8456e3794131edbf7a33;hpb=017582b02dcf25ed4027c54fbcd652004b103f91;p=quassel.git diff --git a/src/client/buffertreemodel.cpp b/src/client/buffertreemodel.cpp index 568f7e6c..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" @@ -79,10 +82,10 @@ QVariant BufferTreeItem::data(int column, int role) const { case BufferTreeModel::BufferNameRole: return buf->bufferName(); case BufferTreeModel::BufferTypeRole: - return buf->bufferType(); + return int(buf->bufferType()); case BufferTreeModel::BufferActiveRole: return buf->isActive(); - case BufferTreeModel::BufferInfoRole: + case BufferTreeModel::BufferUidRole: return buf->bufferInfo().uid(); default: return QVariant(); @@ -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,21 +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); - } -} - -// we received a double click on a buffer, so we're going to join it -void BufferTreeModel::doubleClickReceived(const QModelIndex &clicked) { - if(isBufferIndex(clicked)) { - Buffer *buffer = getBufferByIndex(clicked); - if(!buffer->isStatusBuffer()) - emit fakeUserInput(buffer->bufferInfo(), QString("/join " + buffer->bufferName())); + emit selectionChanged(index); } } @@ -258,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); }