X-Git-Url: https://git.quassel-irc.org/?a=blobdiff_plain;f=src%2Fclient%2Fbuffermodel.cpp;h=9c8df06f3286120336a339ae4f82deed74d8b10a;hb=3122a1934e356b613e5901c42285c223ab2b7e86;hp=a03ae5bd4b69b0fc16d23ced779ea75bc5323630;hpb=4be2513b86decea7720f930164b4e893b63e53e0;p=quassel.git diff --git a/src/client/buffermodel.cpp b/src/client/buffermodel.cpp index a03ae5bd..9c8df06f 100644 --- a/src/client/buffermodel.cpp +++ b/src/client/buffermodel.cpp @@ -20,10 +20,10 @@ #include "buffermodel.h" -#include "networkmodel.h" -#include "mappedselectionmodel.h" -#include "buffer.h" +#include "client.h" #include "global.h" +#include "mappedselectionmodel.h" +#include "networkmodel.h" #include @@ -61,15 +61,31 @@ void BufferModel::synchronizeView(QAbstractItemView *view) { view->setSelectionModel(mappedSelectionModel); } -QModelIndex BufferModel::currentIndex() { - return standardSelectionModel()->currentIndex(); -} - void BufferModel::setCurrentIndex(const QModelIndex &newCurrent) { _selectionModelSynchronizer.selectionModel()->setCurrentIndex(newCurrent, QItemSelectionModel::Current); _selectionModelSynchronizer.selectionModel()->select(newCurrent, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows); } +void BufferModel::switchToBuffer(const BufferId &bufferId) { + QModelIndex source_index = Client::networkModel()->bufferIndex(bufferId); + setCurrentIndex(mapFromSource(source_index)); +} + +void BufferModel::switchToBufferIndex(const QModelIndex &bufferIdx) { + // we accept indexes that directly belong to us or our parent - nothing else + if(bufferIdx.model() == this) { + setCurrentIndex(bufferIdx); + return; + } + + if(bufferIdx.model() == sourceModel()) { + setCurrentIndex(mapFromSource(bufferIdx)); + return; + } + + qWarning() << "BufferModel::switchToBufferIndex(const QModelIndex &):" << bufferIdx << "does not belong to BufferModel or NetworkModel"; +} + void BufferModel::debug_currentChanged(QModelIndex current, QModelIndex previous) { Q_UNUSED(previous); qDebug() << "Switched current Buffer: " << current << current.data().toString() << "Buffer:" << current.data(NetworkModel::BufferIdRole).value();