fixing dupe messages
authorMarcus Eggenberger <egs@quassel-irc.org>
Tue, 4 Nov 2008 23:41:21 +0000 (00:41 +0100)
committerMarcus Eggenberger <egs@quassel-irc.org>
Tue, 4 Nov 2008 23:41:21 +0000 (00:41 +0100)
src/client/messagemodel.cpp
src/client/messagemodel.h
src/qtui/CMakeLists.txt
src/qtui/chatscene.cpp
src/qtui/mainwin.cpp
src/qtui/mainwin.h

index 82fd71b..13e6900 100644 (file)
@@ -86,22 +86,29 @@ void MessageModel::insertMessages(const QList<Message> &msglist) {
   if(msglist.isEmpty())
     return;
 
-  int processedMsgs = insertMessagesGracefully(msglist);
-  int remainingMsgs = msglist.count() - processedMsgs;
-  if(remainingMsgs > 0) {
-    if(msglist.first().msgId() < msglist.last().msgId()) {
-      // in Order - we have just successfully processed "processedMsg" messages from the end of the list
-      _messageBuffer << msglist.mid(0, remainingMsgs);
-    } else {
-      _messageBuffer << msglist.mid(processedMsgs);
+  if(_messageBuffer.isEmpty()) {
+    int processedMsgs = insertMessagesGracefully(msglist);
+    int remainingMsgs = msglist.count() - processedMsgs;
+    if(remainingMsgs > 0) {
+      if(msglist.first().msgId() < msglist.last().msgId()) {
+       // in Order - we have just successfully processed "processedMsg" messages from the end of the list
+       _messageBuffer = msglist.mid(0, remainingMsgs);
+      } else {
+       _messageBuffer = msglist.mid(processedMsgs);
+      }
+      qSort(_messageBuffer);
+      QCoreApplication::postEvent(this, new ProcessBufferEvent());
     }
+  } else {
+    _messageBuffer << msglist;
     qSort(_messageBuffer);
-    QCoreApplication::postEvent(this, new ProcessBufferEvent());
   }
 }
 
 void MessageModel::insertMessageGroup(const QList<Message> &msglist) {
   Q_ASSERT(!msglist.isEmpty()); // the msglist can be assumed to be non empty
+//   int last = msglist.count() - 1;
+//   Q_ASSERT(0 == last || msglist.at(0).msgId() != msglist.at(last).msgId() || msglist.at(last).type() == Message::DayChange);
   int start = indexForId(msglist.first().msgId());
   int end = start + msglist.count() - 1;
   MessageModelItem *dayChangeItem = 0;
@@ -165,6 +172,8 @@ void MessageModel::insertMessageGroup(const QList<Message> &msglist) {
     pos++; // needed for the following assert
   }
   endInsertRows();
+
+//   Q_ASSERT(start == end || _messageList.at(start)->msgId() != _messageList.at(end)->msgId() || _messageList.at(end)->msgType() == Message::DayChange);
   Q_ASSERT(start == 0 || _messageList[start - 1]->msgId() < _messageList[start]->msgId());
   Q_ASSERT(end + 1 == _messageList.count() || _messageList[end]->msgId() < _messageList[end + 1]->msgId());
   Q_ASSERT(pos - 1 == end);
@@ -182,7 +191,7 @@ int MessageModel::insertMessagesGracefully(const QList<Message> &msglist) {
   // depending on the order we have to traverse from the front to the back or vice versa
 
   QList<Message> grouplist;
-  MsgId id;
+  MsgId minId;
   MsgId dupeId;
   int processedMsgs = 1; // we know the list isn't empty, so we at least process one message
   int idx;
@@ -196,18 +205,20 @@ int MessageModel::insertMessagesGracefully(const QList<Message> &msglist) {
   }
 
   idx = indexForId((*iter).msgId());
-  if(idx >= 0 && !_messageList.isEmpty())
+  if(idx < _messageList.count())
     dupeId = _messageList[idx]->msgId();
 
   // we always compare to the previous entry...
   // if there isn't, we can fastforward to the top
   if(idx - 1 >= 0)
-    id = _messageList[idx - 1]->msgId();
+    minId = _messageList[idx - 1]->msgId();
   else
     fastForward = true;
 
-  if((*iter).msgId() != dupeId)
+  if((*iter).msgId() != dupeId) {
     grouplist << *iter;
+    dupeId = (*iter).msgId();
+  }
 
   if(!inOrder)
     iter++;
@@ -216,7 +227,7 @@ int MessageModel::insertMessagesGracefully(const QList<Message> &msglist) {
     while(iter != msglist.constBegin()) {
       iter--;
 
-      if(!fastForward && (*iter).msgId() < id)
+      if(!fastForward && (*iter).msgId() < minId)
        break;
       processedMsgs++;
 
@@ -247,7 +258,7 @@ int MessageModel::insertMessagesGracefully(const QList<Message> &msglist) {
     }
   } else {
     while(iter != msglist.constEnd()) {
-      if(!fastForward && (*iter).msgId() < id)
+      if(!fastForward && (*iter).msgId() < minId)
        break;
       processedMsgs++;
 
@@ -299,7 +310,6 @@ void MessageModel::customEvent(QEvent *event) {
   QList<Message>::iterator removeStart = _messageBuffer.begin() + remainingMsgs;
   QList<Message>::iterator removeEnd = _messageBuffer.end();
   _messageBuffer.erase(removeStart, removeEnd);
-
   if(!_messageBuffer.isEmpty())
     QCoreApplication::postEvent(this, new ProcessBufferEvent());
 }
index f8ffaa5..0f25fa8 100644 (file)
@@ -55,7 +55,7 @@ public:
 
   inline QModelIndex index(int row, int column, const QModelIndex &/*parent*/ = QModelIndex()) const { return createIndex(row, column); }
   inline QModelIndex parent(const QModelIndex &) const { return QModelIndex(); }
-  inline int rowCount(const QModelIndex &/*parent*/ = QModelIndex()) const { return _messageList.count(); }
+  inline int rowCount(const QModelIndex &parent = QModelIndex()) const { return parent.isValid() ? 0 : _messageList.count(); }
   inline int columnCount(const QModelIndex &/*parent*/ = QModelIndex()) const { return 3; }
 
   virtual QVariant data(const QModelIndex &index, int role) const;
index 4a59126..b65c318 100644 (file)
@@ -26,6 +26,7 @@ set(SOURCES
     coreinfodlg.cpp
     debugconsole.cpp
     debuglogwidget.cpp
+    debugmessagemodelfilter.cpp
     inputwidget.cpp
     jumpkeyhandler.cpp
     mainwin.cpp
@@ -64,6 +65,7 @@ set(MOC_HDRS
     coreinfodlg.h
     debugconsole.h
     debuglogwidget.h
+    debugmessagemodelfilter.h
     inputwidget.h
     jumpkeyhandler.h
     mainwin.h
index 87dfae5..bc62842 100644 (file)
@@ -103,9 +103,25 @@ ChatScene::~ChatScene() {
 
 void ChatScene::rowsInserted(const QModelIndex &index, int start, int end) {
   Q_UNUSED(index);
-//   QModelIndex sidx = model()->index(start, 0);
-//   QModelIndex eidx = model()->index(end, 0);
-//   qDebug() << "rowsInserted" << start << end << "-" << sidx.data(MessageModel::MsgIdRole).value<MsgId>() << eidx.data(MessageModel::MsgIdRole).value<MsgId>();
+
+
+//   QModelIndex sidx = model()->index(start, 2);
+//   QModelIndex eidx = model()->index(end, 2);
+//   qDebug() << "rowsInserted:";
+//   if(start > 0) {
+//     QModelIndex ssidx = model()->index(start - 1, 2);
+//     qDebug() << "Start--:" << start - 1 << ssidx.data(MessageModel::MsgIdRole).value<MsgId>()
+//          << ssidx.data(Qt::DisplayRole).toString();
+//   }
+//   qDebug() << "Start:" << start << sidx.data(MessageModel::MsgIdRole).value<MsgId>()
+//        << sidx.data(Qt::DisplayRole).toString();
+//   qDebug() << "End:" << end << eidx.data(MessageModel::MsgIdRole).value<MsgId>()
+//        << eidx.data(Qt::DisplayRole).toString();
+//   if(end + 1 < model()->rowCount()) {
+//     QModelIndex eeidx = model()->index(end + 1, 2);
+//     qDebug() << "End++:" << end + 1 << eeidx.data(MessageModel::MsgIdRole).value<MsgId>()
+//          << eeidx.data(Qt::DisplayRole).toString();
+//   }
 
   qreal h = 0;
   qreal y = 0;
index e7390ea..8287ddd 100644 (file)
@@ -35,6 +35,7 @@
 #include "coreinfodlg.h"
 #include "coreconnectdlg.h"
 #include "debuglogwidget.h"
+#include "debugmessagemodelfilter.h"
 #include "iconloader.h"
 #include "inputwidget.h"
 #include "inputline.h"
@@ -198,6 +199,8 @@ void MainWin::setupActions() {
                                          qApp, SLOT(aboutQt())));
   coll->addAction("DebugNetworkModel", new Action(SmallIcon("tools-report-bug"), tr("Debug &NetworkModel"), coll,
                                        this, SLOT(on_actionDebugNetworkModel_triggered())));
+  coll->addAction("DebugMessageModel", new Action(SmallIcon("tools-report-bug"), tr("Debug &MessageModel"), coll,
+                                       this, SLOT(on_actionDebugMessageModel_triggered())));
   coll->addAction("DebugLog", new Action(SmallIcon("tools-report-bug"), tr("Debug &Log"), coll,
                                        this, SLOT(on_actionDebugLog_triggered())));
 }
@@ -234,6 +237,7 @@ void MainWin::setupMenus() {
   _helpMenu->addSeparator();
   _helpDebugMenu = _helpMenu->addMenu(SmallIcon("tools-report-bug"), tr("Debug"));
   _helpDebugMenu->addAction(coll->action("DebugNetworkModel"));
+  _helpDebugMenu->addAction(coll->action("DebugMessageModel"));
   _helpDebugMenu->addAction(coll->action("DebugLog"));
 }
 
@@ -737,6 +741,17 @@ void MainWin::on_actionDebugNetworkModel_triggered() {
   view->show();
 }
 
+void MainWin::on_actionDebugMessageModel_triggered() {
+  QTableView *view = new QTableView(0);
+  DebugMessageModelFilter *filter = new DebugMessageModelFilter(view);
+  filter->setSourceModel(Client::messageModel());
+  view->setModel(filter);
+  view->setAttribute(Qt::WA_DeleteOnClose, true);
+  view->verticalHeader()->hide();
+  view->horizontalHeader()->setStretchLastSection(true);
+  view->show();
+}
+
 void MainWin::on_actionDebugLog_triggered() {
   DebugLogWidget *logWidget = new DebugLogWidget(0);
   logWidget->show();
index a2d0bc8..2a53f75 100644 (file)
@@ -84,6 +84,7 @@ class MainWin : public QMainWindow {
     void on_actionManageViews_triggered();
     void on_actionLockDockPositions_toggled(bool lock);
     void on_actionDebugNetworkModel_triggered();
+    void on_actionDebugMessageModel_triggered();
     void on_actionDebugLog_triggered();
 
     void clientNetworkCreated(NetworkId);