Clean up MessageModel on disconnect
authorManuel Nickschas <sputnick@quassel-irc.org>
Sun, 3 Aug 2008 23:43:18 +0000 (01:43 +0200)
committerManuel Nickschas <sputnick@quassel-irc.org>
Sun, 3 Aug 2008 23:43:18 +0000 (01:43 +0200)
src/client/client.cpp
src/client/messagemodel.cpp
src/client/messagemodel.h
src/qtui/chatscene.cpp
src/qtui/chatscene.h

index e39435e..eeb25d5 100644 (file)
@@ -357,6 +357,7 @@ void Client::disconnectFromCore() {
     _bufferViewManager = 0;
   }
 
+  _messageModel->clear();
   _networkModel->clear();
 
   QHash<BufferId, Buffer *>::iterator bufferIter =  _buffers.begin();
index 76104bd..4032c64 100644 (file)
 #include "message.h"
 
 MessageModel::MessageModel(QObject *parent) : QAbstractItemModel(parent) {
-  
-  
-  
+
+
+
 }
 
 MessageModel::~MessageModel() {
-  
-  
+
+
 }
 
 QVariant MessageModel::data(const QModelIndex &index, int role) const {
@@ -66,6 +66,12 @@ void MessageModel::insertMessages(const QList<Message> &msglist) {
 
 }
 
+void MessageModel::clear() {
+  reset();
+  qDeleteAll(_messageList);
+  _messageList.clear();
+}
+
 // returns index of msg with given Id or of the next message after that (i.e., the index where we'd insert this msg)
 int MessageModel::indexForId(MsgId id) {
   if(_messageList.isEmpty() || id <= _messageList[0]->data(0, MsgIdRole).value<MsgId>()) return 0;
index f6e2538..8d7c0ed 100644 (file)
@@ -66,6 +66,8 @@ class MessageModel : public QAbstractItemModel {
     void insertMessage(const Message &);
     void insertMessages(const QList<Message> &);
 
+    void clear();
+
   protected:
     virtual MessageModelItem *createMessageModelItem(const Message &) = 0;
 
index 8207248..6dbe171 100644 (file)
@@ -45,6 +45,7 @@ ChatScene::ChatScene(QAbstractItemModel *model, const QString &idString, QObject
   connect(this, SIGNAL(sceneRectChanged(const QRectF &)), this, SLOT(rectChanged(const QRectF &)));
 
   connect(model, SIGNAL(rowsInserted(const QModelIndex &, int, int)), this, SLOT(rowsInserted(const QModelIndex &, int, int)));
+  connect(model, SIGNAL(modelAboutToBeReset()), this, SLOT(modelReset()));
   for(int i = 0; i < model->rowCount(); i++) {
     ChatLine *line = new ChatLine(model->index(i, 0));
     _lines.append(line);
@@ -76,7 +77,6 @@ ChatScene::ChatScene(QAbstractItemModel *model, const QString &idString, QObject
 
 ChatScene::~ChatScene() {
 
-
 }
 
 void ChatScene::rowsInserted(const QModelIndex &index, int start, int end) {
@@ -106,6 +106,15 @@ void ChatScene::rowsInserted(const QModelIndex &index, int start, int end) {
   }
 }
 
+void ChatScene::modelReset() {
+  foreach(ChatLine *line, _lines) {
+    removeItem(line);
+    delete line;
+  }
+  _lines.clear();
+  setSceneRect(QRectF(0, 0, _width, 0));
+}
+
 void ChatScene::setWidth(qreal w) {
   _width = w;
   _height = 0;
index cd71aac..22dcb47 100644 (file)
@@ -62,6 +62,7 @@ class ChatScene : public QGraphicsScene {
 
   protected slots:
     void rowsInserted(const QModelIndex &, int, int);
+    void modelReset();
 
   private slots:
     void rectChanged(const QRectF &);