Merging r774:778 from trunk into branches/0.3. Forwardporting hopefully the last...
[quassel.git] / src / client / buffermodel.cpp
index 52d6d54..b67a447 100644 (file)
 
 BufferModel::BufferModel(NetworkModel *parent)
   : QSortFilterProxyModel(parent),
-    _selectionModelSynchronizer(this),
-    _standardSelectionModel(this)
+    _selectionModelSynchronizer(this)
 {
   setSourceModel(parent);
-  _selectionModelSynchronizer.addRegularSelectionModel(standardSelectionModel());
-}
-
-BufferModel::~BufferModel() {
+  if(QCoreApplication::instance()->arguments().contains("--debugbufferswitches")) {
+    connect(_selectionModelSynchronizer.selectionModel(), SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)),
+           this, SLOT(debug_currentChanged(const QModelIndex &, const QModelIndex &)));
+  }
 }
 
 bool BufferModel::filterAcceptsRow(int sourceRow, const QModelIndex &parent) const {
@@ -65,6 +64,11 @@ QModelIndex BufferModel::currentIndex() {
 }
 
 void BufferModel::setCurrentIndex(const QModelIndex &newCurrent) {
-  _standardSelectionModel.setCurrentIndex(newCurrent, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
-  _standardSelectionModel.select(newCurrent, QItemSelectionModel::ClearAndSelect);
+  _selectionModelSynchronizer.selectionModel()->setCurrentIndex(newCurrent, QItemSelectionModel::Current);
+  _selectionModelSynchronizer.selectionModel()->select(newCurrent, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
+}
+
+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<BufferId>();
 }