We now have back a real BufferModel. It's basically a ProxyModel to
authorMarcus Eggenberger <egs@quassel-irc.org>
Tue, 8 Jan 2008 19:29:30 +0000 (19:29 +0000)
committerMarcus Eggenberger <egs@quassel-irc.org>
Tue, 8 Jan 2008 19:29:30 +0000 (19:29 +0000)
the recently introduced NetworkModel.
Activity displays in the BufferViews are now a bit crippled (new
Activity levels will be shown even when the buffer is selected).

Now We can Use The Nickviews with the NetworkModel and get Rid of the
QtGui Dependency in the Client.

14 files changed:
dev-notes/ROADMAP
src/client/buffermodel.cpp [new file with mode: 0644]
src/client/buffermodel.h [new file with mode: 0644]
src/client/client.cpp
src/client/client.h
src/client/client.pri
src/client/mappedselectionmodel.cpp
src/client/mappedselectionmodel.h
src/client/networkmodel.cpp
src/client/networkmodel.h
src/client/selectionmodelsynchronizer.cpp
src/client/selectionmodelsynchronizer.h
src/core/abstractsqlstorage.cpp
src/qtui/mainwin.cpp

index f7e4097..10a2471 100644 (file)
@@ -6,22 +6,22 @@ Already Done:
       make signalproxy threadsafe
       utf-8 / encodings
       externalize SQL-queries, provide migration path...
+      Buffermodel
 
 Showstoppers:
 =============
 WiP:  settings dialog -> Sput
       serverlist, identities... -> Sput
       mode changes in serverhandler -> EgS
-      BUFFERMODEL -> EgS
       make wizard more intuitive (account data, two-step auth) -> Sput
 
 Open: network settings in DB -> ?
-      switch to network-IDs -> ?
+      switch to network-IDs (depends on network settings into db) -> ?
       remove buffergroups (DB) -> ?
       insert buffertype field rein (DB) -> ?
       core-user admin, rights management (ACL) -> Sput?
 
-BUG:  multi-user join -> ?
+BUG:  multi-user join (should be done while switching to network-IDs) -> ?
 
 Important:
 ==========
@@ -29,3 +29,5 @@ WiP:  shortcuts -> Sput
 
 Open: save activity-state in core (client reconnect) -- save per-buffer timestamp locally in client  -> ?
       backlog administration -> ?
+      fix Activity and get rid of QtGui dep in client
+      
diff --git a/src/client/buffermodel.cpp b/src/client/buffermodel.cpp
new file mode 100644 (file)
index 0000000..df5d99f
--- /dev/null
@@ -0,0 +1,95 @@
+/***************************************************************************
+ *   Copyright (C) 2005-08 by the Quassel Project                          *
+ *   devel@quassel-irc.org                                                 *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) version 3.                                           *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
+ ***************************************************************************/
+
+#include "buffermodel.h"
+
+#include "networkmodel.h"
+#include "mappedselectionmodel.h"
+#include "buffer.h"
+#include <QAbstractItemView>
+
+BufferModel::BufferModel(NetworkModel *parent)
+  : QSortFilterProxyModel(parent),
+    _selectionModelSynchronizer(new SelectionModelSynchronizer(this)),
+    _propertyMapper(new ModelPropertyMapper(this))
+{
+  setSourceModel(parent);
+
+  // initialize the Property Mapper
+  _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)));
+}
+
+BufferModel::~BufferModel() {
+}
+
+bool BufferModel::filterAcceptsRow(int sourceRow, const QModelIndex &parent) const {
+  Q_UNUSED(sourceRow)
+    
+  if(parent.data(NetworkModel::ItemTypeRole) == NetworkModel::BufferItemType)
+    return false;
+  else
+    return true;
+}
+
+void BufferModel::synchronizeSelectionModel(MappedSelectionModel *selectionModel) {
+  selectionModelSynchronizer()->addSelectionModel(selectionModel);
+}
+
+void BufferModel::synchronizeView(QAbstractItemView *view) {
+  MappedSelectionModel *mappedSelectionModel = new MappedSelectionModel(view->model());
+  selectionModelSynchronizer()->addSelectionModel(mappedSelectionModel);
+  Q_ASSERT(mappedSelectionModel);
+  delete view->selectionModel();
+  view->setSelectionModel(mappedSelectionModel);
+}
+
+void BufferModel::mapProperty(int column, int role, QObject *target, const QByteArray &property) {
+  propertyMapper()->addMapping(column, role, target, property);
+}
+
+// This Slot indicates that the user has selected a different buffer in the gui
+void BufferModel::setCurrentIndex(const QModelIndex &index, QItemSelectionModel::SelectionFlags command) {
+  Q_UNUSED(command)
+  Buffer *newCurrentBuffer;
+  NetworkModel *networkModel = qobject_cast<NetworkModel *>(parent());
+  if(networkModel->isBufferIndex(mapToSource(index)) && currentBuffer != (newCurrentBuffer = networkModel->getBufferByIndex(mapToSource(index)))) {
+    currentBuffer = newCurrentBuffer;
+    networkModel->bufferActivity(Buffer::NoActivity, currentBuffer);
+    emit bufferSelected(currentBuffer);
+    emit selectionChanged(index);
+  }
+}
+
+void BufferModel::selectBuffer(Buffer *buffer) {
+  QModelIndex index = (qobject_cast<NetworkModel *>(parent()))->bufferIndex(buffer->bufferInfo());
+  if(!index.isValid()) {
+    qWarning() << "BufferModel::selectBuffer(): unknown Buffer has been selected.";
+    return;
+  }
+  // SUPER UGLY!
+  setCurrentIndex(mapFromSource(index), 0);
+}
diff --git a/src/client/buffermodel.h b/src/client/buffermodel.h
new file mode 100644 (file)
index 0000000..4fb610d
--- /dev/null
@@ -0,0 +1,67 @@
+/***************************************************************************
+ *   Copyright (C) 2005-08 by the Quassel Project                          *
+ *   devel@quassel-irc.org                                                 *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) version 3.                                           *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
+ ***************************************************************************/
+
+#ifndef BUFFERMODEL_H
+#define BUFFERMODEL_H
+
+#include <QSortFilterProxyModel>
+#include <QItemSelectionModel>
+#include <QPointer>
+
+class NetworkModel;
+//class SelectionModelSynchronizer;
+#include "selectionmodelsynchronizer.h"
+//class ModelPropertyMapper;
+#include "modelpropertymapper.h"
+class MappedSelectionModel;
+class QAbstractItemView;
+class Buffer;
+
+class BufferModel : public QSortFilterProxyModel {
+  Q_OBJECT
+
+public:
+  BufferModel(NetworkModel *parent = 0);
+  virtual ~BufferModel();
+
+  bool filterAcceptsRow(int sourceRow, const QModelIndex &parent) const;
+  
+  inline SelectionModelSynchronizer *selectionModelSynchronizer() { return _selectionModelSynchronizer; }
+  inline ModelPropertyMapper *propertyMapper() { return _propertyMapper; }
+
+  void synchronizeSelectionModel(MappedSelectionModel *selectionModel);
+  void synchronizeView(QAbstractItemView *view);
+  void mapProperty(int column, int role, QObject *target, const QByteArray &property);
+
+public slots:
+  void setCurrentIndex(const QModelIndex &index, QItemSelectionModel::SelectionFlags command);
+  void selectBuffer(Buffer *buffer);
+
+signals:
+  void bufferSelected(Buffer *);
+  void selectionChanged(const QModelIndex &);
+
+private:
+  QPointer<SelectionModelSynchronizer> _selectionModelSynchronizer;
+  QPointer<ModelPropertyMapper> _propertyMapper;
+  Buffer *currentBuffer;
+};
+
+#endif // BUFFERMODEL_H
index 1b6e0bb..55fccf2 100644 (file)
@@ -28,6 +28,7 @@
 #include "message.h"
 #include "networkinfo.h"
 #include "networkmodel.h"
+#include "buffermodel.h"
 #include "quasselui.h"
 #include "signalproxy.h"
 #include "util.h"
@@ -52,27 +53,28 @@ void Client::init(AbstractUi *ui) {
 }
 
 Client::Client(QObject *parent)
-    : QObject(parent),
+  : QObject(parent),
     socket(0),
     _signalProxy(new SignalProxy(SignalProxy::Client, this)),
     mainUi(0),
     _networkModel(0),
+    _bufferModel(0),
     connectedToCore(false)
 {
-
 }
 
 Client::~Client() {
-
 }
 
 void Client::init() {
   blockSize = 0;
 
   _networkModel = new NetworkModel(this);
+  _bufferModel = new BufferModel(_networkModel);
 
   connect(this, SIGNAL(bufferSelected(Buffer *)),
-          _networkModel, SLOT(selectBuffer(Buffer *)));
+          _bufferModel, SLOT(selectBuffer(Buffer *)));
+  
   connect(this, SIGNAL(bufferUpdated(Buffer *)),
           _networkModel, SLOT(bufferUpdated(Buffer *)));
   connect(this, SIGNAL(bufferActivity(Buffer::ActivityLevel, Buffer *)),
@@ -192,6 +194,11 @@ NetworkModel *Client::networkModel() {
   return instance()->_networkModel;
 }
 
+BufferModel *Client::bufferModel() {
+  return instance()->_bufferModel;
+}
+
+
 SignalProxy *Client::signalProxy() {
   return instance()->_signalProxy;
 }
index 9a64526..342f8d0 100644 (file)
@@ -37,6 +37,7 @@ class NetworkInfo;
 class AbstractUi;
 class AbstractUiMsg;
 class NetworkModel;
+class BufferModel;
 class SignalProxy;
 
 class QTimer;
@@ -82,6 +83,7 @@ public:
   static void removeIdentity(IdentityId id);
 
   static NetworkModel *networkModel();
+  static BufferModel *bufferModel();
   static SignalProxy *signalProxy();
 
   static AbstractUiMsg *layoutMsg(const Message &);
@@ -191,6 +193,7 @@ private:
   QPointer<SignalProxy> _signalProxy;
   QPointer<AbstractUi> mainUi;
   QPointer<NetworkModel> _networkModel;
+  QPointer<BufferModel> _bufferModel;
 
   ClientMode clientMode;
 
index 740f74e..89088da 100644 (file)
@@ -1,6 +1,6 @@
 DEPMOD = common
 QT_MOD = core network gui   # gui is needed just for QColor... FIXME!
-SRCS += buffer.cpp networkmodel.cpp client.cpp clientsettings.cpp mappedselectionmodel.cpp modelpropertymapper.cpp \
-        nickmodel.cpp selectionmodelsynchronizer.cpp treemodel.cpp
-HDRS += buffer.h networkmodel.h client.h clientsettings.h quasselui.h mappedselectionmodel.h modelpropertymapper.h \
-        nickmodel.h selectionmodelsynchronizer.h treemodel.h
+SRCS += buffer.cpp treemodel.cpp networkmodel.cpp buffermodel.cpp client.cpp clientsettings.cpp mappedselectionmodel.cpp modelpropertymapper.cpp \
+        nickmodel.cpp selectionmodelsynchronizer.cpp
+HDRS += buffer.h treemodel.h networkmodel.h buffermodel.h client.h clientsettings.h quasselui.h mappedselectionmodel.h modelpropertymapper.h \
+        nickmodel.h selectionmodelsynchronizer.h
index 2c73186..f5b7470 100644 (file)
@@ -56,21 +56,11 @@ QModelIndex MappedSelectionModel::mapFromSource(const QModelIndex &sourceIndex)
     return sourceIndex;
 }
 
-QItemSelection MappedSelectionModel::mapFromSource(const QItemSelection &sourceSelection) {
-  if(isProxyModel()) {
-    QItemSelection mappedSelection;
-    foreach(QItemSelectionRange range, sourceSelection) {
-      QModelIndex topleft = mapFromSource(range.topLeft());
-      QModelIndex bottomright = mapFromSource(range.bottomRight());
-      if(topleft.isValid() && bottomright.isValid())
-       mappedSelection << QItemSelectionRange(topleft, bottomright);
-      else 
-       Q_ASSERT(!topleft.isValid() && !bottomright.isValid());
-    }
-    return mappedSelection;
-  } else {
+QItemSelection MappedSelectionModel::mapSelectionFromSource(const QItemSelection &sourceSelection) {
+  if(isProxyModel())
+    return proxyModel()->mapSelectionFromSource(sourceSelection);
+  else
     return sourceSelection;
-  }
 }
                                    
 QModelIndex MappedSelectionModel::mapToSource(const QModelIndex &proxyIndex) {
@@ -80,16 +70,11 @@ QModelIndex MappedSelectionModel::mapToSource(const QModelIndex &proxyIndex) {
     return proxyIndex;
 }
 
-QItemSelection MappedSelectionModel::mapToSource(const QItemSelection &proxySelection) {
-  if(isProxyModel()) {
-    QItemSelection mappedSelection;
-    foreach(QItemSelectionRange range, proxySelection) {
-      mappedSelection << QItemSelectionRange(mapToSource(range.topLeft()), mapToSource(range.bottomRight()));
-    }
-    return mappedSelection;
-  } else {
+QItemSelection MappedSelectionModel::mapSelectionToSource(const QItemSelection &proxySelection) {
+  if(isProxyModel())
+    return proxyModel()->mapSelectionToSource(proxySelection);
+  else
     return proxySelection;
-  }
 }
                                                                        
 void MappedSelectionModel::mappedSelect(const QModelIndex &index, QItemSelectionModel::SelectionFlags command) {
@@ -99,7 +84,7 @@ void MappedSelectionModel::mappedSelect(const QModelIndex &index, QItemSelection
 }
 
 void MappedSelectionModel::mappedSelect(const QItemSelection &selection, QItemSelectionModel::SelectionFlags command) {
-  QItemSelection mappedSelection = mapFromSource(selection);
+  QItemSelection mappedSelection = mapSelectionFromSource(selection);
   if(mappedSelection != QItemSelectionModel::selection())
     select(mappedSelection, command);  
 }
@@ -124,6 +109,6 @@ void MappedSelectionModel::_currentChanged(const QModelIndex &current, const QMo
 void MappedSelectionModel::_selectionChanged(const QItemSelection &selected, const QItemSelection &deselected) {
   Q_UNUSED(selected)
   Q_UNUSED(deselected)
-  emit mappedSelectionChanged(mapToSource(QItemSelectionModel::selection()));
+  emit mappedSelectionChanged(mapSelectionToSource(QItemSelectionModel::selection()));
 }
   
index 01ccb4b..a59ea25 100644 (file)
@@ -41,10 +41,10 @@ public:
   const QAbstractProxyModel *proxyModel() const;
   
   QModelIndex mapFromSource(const QModelIndex &sourceIndex);
-  QItemSelection mapFromSource(const QItemSelection &sourceSelection);
+  QItemSelection mapSelectionFromSource(const QItemSelection &sourceSelection);
                                    
   QModelIndex mapToSource(const QModelIndex &proxyIndex);
-  QItemSelection mapToSource(const QItemSelection &proxySelection);
+  QItemSelection mapSelectionToSource(const QItemSelection &proxySelection);
                                                                        
 public slots:
   void mappedSelect(const QModelIndex &index, QItemSelectionModel::SelectionFlags command);
index 85cc23d..4bad7a0 100644 (file)
@@ -22,7 +22,6 @@
 
 #include "networkmodel.h"
 
-#include "mappedselectionmodel.h"
 #include <QAbstractItemView>
 
 #include "bufferinfo.h"
@@ -128,8 +127,8 @@ void BufferItem::setTopic(const QString &topic) {
 }
 
 void BufferItem::join(IrcUser *ircUser) {
-//   emit newChild(new IrcUserItem(ircUser, this));
-//   emit dataChanged(2);
+  emit newChild(new IrcUserItem(ircUser, this));
+  emit dataChanged(2);
 }
 
 void BufferItem::part(IrcUser *ircUser) {
@@ -262,19 +261,8 @@ void IrcUserItem::ircUserDestroyed() {
  * NetworkModel
  *****************************************/
 NetworkModel::NetworkModel(QObject *parent)
-  : TreeModel(NetworkModel::defaultHeader(), parent),
-    _selectionModelSynchronizer(new SelectionModelSynchronizer(this)),
-    _propertyMapper(new ModelPropertyMapper(this))
+  : TreeModel(NetworkModel::defaultHeader(), parent)
 {
-  // initialize the Property Mapper
-  _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 >NetworkModel::defaultHeader() {
@@ -283,22 +271,6 @@ QList<QVariant >NetworkModel::defaultHeader() {
   return data;
 }
 
-void NetworkModel::synchronizeSelectionModel(MappedSelectionModel *selectionModel) {
-  selectionModelSynchronizer()->addSelectionModel(selectionModel);
-}
-
-void NetworkModel::synchronizeView(QAbstractItemView *view) {
-  MappedSelectionModel *mappedSelectionModel = new MappedSelectionModel(view->model());
-  selectionModelSynchronizer()->addSelectionModel(mappedSelectionModel);
-  Q_ASSERT(mappedSelectionModel);
-  delete view->selectionModel();
-  view->setSelectionModel(mappedSelectionModel);
-}
-
-void NetworkModel::mapProperty(int column, int role, QObject *target, const QByteArray &property) {
-  propertyMapper()->addMapping(column, role, target, property);
-}
-
 bool NetworkModel::isBufferIndex(const QModelIndex &index) const {
   return index.data(NetworkModel::ItemTypeRole) == NetworkModel::BufferItemType;
 }
@@ -469,38 +441,13 @@ void NetworkModel::bufferUpdated(Buffer *buffer) {
   emit dataChanged(itemindex, itemindex);
 }
 
-// This Slot indicates that the user has selected a different buffer in the gui
-void NetworkModel::setCurrentIndex(const QModelIndex &index, QItemSelectionModel::SelectionFlags command) {
-  Q_UNUSED(command)
-  Buffer *newCurrentBuffer;
-  if(isBufferIndex(index) && currentBuffer != (newCurrentBuffer = getBufferByIndex(index))) {
-    currentBuffer = newCurrentBuffer;
-    bufferActivity(Buffer::NoActivity, currentBuffer);
-    emit bufferSelected(currentBuffer);
-    emit selectionChanged(index);
-  }
-}
-
 void NetworkModel::bufferActivity(Buffer::ActivityLevel level, Buffer *buf) {
   BufferItem *bufferItem = buffer(buf->bufferInfo());
   if(!bufferItem) {
     qWarning() << "NetworkModel::bufferActivity(): received Activity Info for uknown Buffer";
     return;
   }
-  
-  if(buf != currentBuffer)
-    bufferItem->setActivity(level);
-  else
-    bufferItem->setActivity(Buffer::NoActivity);
+  bufferItem->setActivity(level);
   bufferUpdated(buf);
 }
 
-void NetworkModel::selectBuffer(Buffer *buffer) {
-  QModelIndex index = bufferIndex(buffer->bufferInfo());
-  if(!index.isValid()) {
-    qWarning() << "NetworkModel::selectBuffer(): unknown Buffer has been selected.";
-    return;
-  }
-  // SUPER UGLY!
-  setCurrentIndex(index, 0);
-}
index 0ed7487..3b6b331 100644 (file)
@@ -28,8 +28,6 @@
 
 #include <QPointer>
 
-#include <QItemSelectionModel>
-
 class BufferInfo;
 
 #include "selectionmodelsynchronizer.h"
@@ -159,13 +157,6 @@ public:
   NetworkModel(QObject *parent = 0);
   static QList<QVariant> defaultHeader();
 
-  inline SelectionModelSynchronizer *selectionModelSynchronizer() { return _selectionModelSynchronizer; }
-  inline ModelPropertyMapper *propertyMapper() { return _propertyMapper; }
-
-  void synchronizeSelectionModel(MappedSelectionModel *selectionModel);
-  void synchronizeView(QAbstractItemView *view);
-  void mapProperty(int column, int role, QObject *target, const QByteArray &property);
-
   static bool mimeContainsBufferList(const QMimeData *mimeData);
   static QList< QPair<uint, uint> > mimeDataToBufferList(const QMimeData *mimeData);
 
@@ -174,32 +165,23 @@ public:
   virtual bool dropMimeData(const QMimeData *, Qt::DropAction, int, int, const QModelIndex &);
 
   void attachNetworkInfo(NetworkInfo *networkInfo);
-                                                 
+
+  bool isBufferIndex(const QModelIndex &) const;
+  Buffer *getBufferByIndex(const QModelIndex &) const;
+  QModelIndex bufferIndex(BufferInfo bufferInfo);
+
 public slots:
   void bufferUpdated(Buffer *);
-  void setCurrentIndex(const QModelIndex &index, QItemSelectionModel::SelectionFlags command);
-  void selectBuffer(Buffer *buffer);
   void bufferActivity(Buffer::ActivityLevel, Buffer *buffer);
 
-signals:
-  void bufferSelected(Buffer *);
-  void selectionChanged(const QModelIndex &);
-
 private:
-  bool isBufferIndex(const QModelIndex &) const;
-  Buffer *getBufferByIndex(const QModelIndex &) const;
-
   QModelIndex networkIndex(uint networkId);
   NetworkItem *network(uint networkId);
   NetworkItem *newNetwork(uint networkId, const QString &networkName);
   
-  QModelIndex bufferIndex(BufferInfo bufferInfo);
   BufferItem *buffer(BufferInfo bufferInfo);
   BufferItem *newBuffer(BufferInfo bufferInfo);
 
-  QPointer<SelectionModelSynchronizer> _selectionModelSynchronizer;
-  QPointer<ModelPropertyMapper> _propertyMapper;
-  Buffer *currentBuffer;
 };
 
 #endif // NETWORKMODEL_H
index bdb2ccf..ef0b947 100644 (file)
@@ -36,6 +36,11 @@ SelectionModelSynchronizer::~SelectionModelSynchronizer() {
 }
 
 void SelectionModelSynchronizer::addSelectionModel(MappedSelectionModel *selectionmodel) {
+  if(selectionmodel->model() == model()) {
+    addRegularSelectionModel(selectionmodel);
+    return;
+  }
+  
   if(selectionmodel->baseModel() != model()) {
     qWarning() << "cannot Syncronize SelectionModel" << selectionmodel << "which has a different baseModel()";
     return;
@@ -50,6 +55,22 @@ void SelectionModelSynchronizer::addSelectionModel(MappedSelectionModel *selecti
          selectionmodel, SLOT(mappedSetCurrentIndex(QModelIndex, QItemSelectionModel::SelectionFlags)));
   connect(this, SIGNAL(select(QItemSelection, QItemSelectionModel::SelectionFlags)),
          selectionmodel, SLOT(mappedSelect(QItemSelection, QItemSelectionModel::SelectionFlags)));
+}
+
+void SelectionModelSynchronizer::addRegularSelectionModel(QItemSelectionModel *selectionmodel) {
+  if(selectionmodel->model() != model()) {
+    qWarning() << "cannot Syncronize QItemSelectionModel" << selectionmodel << "which has a different model()";    
+    return;
+  }
+  connect(selectionmodel, SIGNAL(currentChanged(QModelIndex, QModelIndex)),
+         this, SLOT(_regularCurrentChanged(QModelIndex, QModelIndex)));
+  connect(selectionmodel, SIGNAL(selectionChanged(QItemSelection, QItemSelection)),
+         this, SLOT(_regularSelectionChanged(QItemSelection, QItemSelection)));
+  
+  connect(this, SIGNAL(setCurrentIndex(QModelIndex, QItemSelectionModel::SelectionFlags)),
+         selectionmodel, SLOT(setCurrentIndex(QModelIndex, QItemSelectionModel::SelectionFlags)));
+  connect(this, SIGNAL(select(QItemSelection, QItemSelectionModel::SelectionFlags)),
+         selectionmodel, SLOT(select(QItemSelection, QItemSelectionModel::SelectionFlags)));
   
 }
 
@@ -65,3 +86,15 @@ void SelectionModelSynchronizer::_mappedCurrentChanged(const QModelIndex &curren
 void SelectionModelSynchronizer::_mappedSelectionChanged(const QItemSelection &selected) {
   emit select(selected, QItemSelectionModel::ClearAndSelect);
 }
+
+void SelectionModelSynchronizer::_regularCurrentChanged(const QModelIndex &newCurrent, const QModelIndex &oldCurrent) {
+  Q_UNUSED(oldCurrent)
+  emit setCurrentIndex(newCurrent, QItemSelectionModel::ClearAndSelect);
+}
+
+void SelectionModelSynchronizer::_regularSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected) {
+  Q_UNUSED(selected)
+  Q_UNUSED(deselected)
+  QItemSelectionModel *selectionModel = qobject_cast<QItemSelectionModel *>(sender());
+  emit select(selectionModel->selection(), QItemSelectionModel::ClearAndSelect);
+}
index a655147..5cda9cc 100644 (file)
@@ -35,6 +35,7 @@ public:
   virtual ~SelectionModelSynchronizer();
 
   void addSelectionModel(MappedSelectionModel *model);
+  void addRegularSelectionModel(QItemSelectionModel *model);
   void removeSelectionModel(MappedSelectionModel *model);
 
   inline QAbstractItemModel *model() { return _model; }
@@ -43,6 +44,9 @@ private slots:
   void _mappedCurrentChanged(const QModelIndex &current);
   void _mappedSelectionChanged(const QItemSelection &selected);
 
+  void _regularCurrentChanged(const QModelIndex &newCurrent, const QModelIndex &oldCurrent);
+  void _regularSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
+
 signals:
   void select(const QItemSelection &selection, QItemSelectionModel::SelectionFlags command);
   void setCurrentIndex(const QModelIndex &index, QItemSelectionModel::SelectionFlags command);
index b29c88c..4744270 100644 (file)
@@ -30,6 +30,12 @@ AbstractSqlStorage::AbstractSqlStorage(QObject *parent)
 }
 
 AbstractSqlStorage::~AbstractSqlStorage() {
+  QHash<QPair<QString, int>, QSqlQuery *>::iterator iter = _queryCache.begin();
+  while(iter != _queryCache.end()) {
+    delete *iter;
+    iter = _queryCache.erase(iter);
+  }
+  
   {
     QSqlDatabase db = QSqlDatabase::database("quassel_connection");
     db.commit();
@@ -126,7 +132,6 @@ QSqlQuery *AbstractSqlStorage::cachedQuery(const QString &queryName, int version
     query->prepare(queryString(queryName, version));
     _queryCache[queryId] = query;
   }
-
   return _queryCache[queryId];
 }
 
index d7c3bba..0feeb63 100644 (file)
@@ -25,6 +25,7 @@
 #include "client.h"
 #include "coreconnectdlg.h"
 #include "networkmodel.h"
+#include "buffermodel.h"
 #include "nicklistwidget.h"
 #include "serverlist.h"
 #include "settingsdlg.h"
@@ -117,7 +118,7 @@ void MainWin::init() {
   TopicWidget *topicwidget = new TopicWidget(dock);
   dock->setWidget(topicwidget);
 
-  Client::networkModel()->mapProperty(1, Qt::DisplayRole, topicwidget, "topic");
+  Client::bufferModel()->mapProperty(1, Qt::DisplayRole, topicwidget, "topic");
 
   addDockWidget(Qt::TopDockWidgetArea, dock);
 
@@ -159,7 +160,7 @@ void MainWin::setupMenus() {
 
 void MainWin::setupViews() {
   
-  NetworkModel *model = Client::networkModel();
+  BufferModel *model = Client::bufferModel();
   connect(model, SIGNAL(bufferSelected(Buffer *)), this, SLOT(showBuffer(Buffer *)));
 
   addBufferView(tr("All Buffers"), model, BufferViewFilter::AllNets, QList<uint>());
@@ -167,6 +168,18 @@ void MainWin::setupViews() {
   addBufferView(tr("All Queries"), model, BufferViewFilter::AllNets|BufferViewFilter::NoChannels|BufferViewFilter::NoServers, QList<uint>());
   addBufferView(tr("All Networks"), model, BufferViewFilter::AllNets|BufferViewFilter::NoChannels|BufferViewFilter::NoQueries, QList<uint>());
   addBufferView(tr("Full Custom"), model, BufferViewFilter::FullCustom, QList<uint>());
+
+//   QDockWidget *dock = new QDockWidget("FILTERTEST", this);
+//   dock->setAllowedAreas(Qt::RightDockWidgetArea|Qt::LeftDockWidgetArea);
+//   BufferView *view = new BufferView(dock);
+//   view->setModel(Client::bufferModel());
+//   dock->setWidget(view);
+
+//   addDockWidget(Qt::LeftDockWidgetArea, dock);
+//   ui.menuViews->addAction(dock->toggleViewAction());
+
+//   netViews.append(dock);
+
   
   ui.menuViews->addSeparator();
 }
@@ -180,7 +193,7 @@ void MainWin::addBufferView(const QString &viewname, QAbstractItemModel *model,
   //create the view and initialize it's filter
   BufferView *view = new BufferView(dock);
   view->setFilteredModel(model, mode, nets);
-  Client::networkModel()->synchronizeView(view);
+  Client::bufferModel()->synchronizeView(view);
   dock->setWidget(view);
 
   addDockWidget(Qt::LeftDockWidgetArea, dock);