We now have a current svn snapshot of libqxt in our contrib dir, and
[quassel.git] / src / client / buffertreemodel.cpp
index 633731b..a881b5f 100644 (file)
@@ -22,6 +22,9 @@
 
 #include "buffertreemodel.h"
 
+#include "mappedselectionmodel.h"
+#include <QAbstractItemView>
+
 #include "bufferinfo.h"
 #include "client.h"
 #include "signalproxy.h"
@@ -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)));
 }
 
 QList<QVariant >BufferTreeModel::defaultHeader() {
@@ -128,6 +140,22 @@ QList<QVariant >BufferTreeModel::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();
@@ -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 &current, 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);
 }