int remainingMsgs = msglist.count() - processedMsgs;
if(remainingMsgs > 0) {
if(msglist.first().msgId() < msglist.last().msgId()) {
- // in Order
+ // 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);
int start = indexForId(msglist.first().msgId());
int end = start + msglist.count() - 1;
MessageModelItem *dayChangeItem = 0;
-
+ bool relocatedMsg = false;
if(start > 0) {
// check if the preceeding msg is a daychange message and if so if
// we have to drop or relocate it at the end of this chunk
endRemoveRows();
start--;
end--;
+ relocatedMsg = true;
}
}
}
int MessageModel::insertMessagesGracefully(const QList<Message> &msglist) {
+ /* short description:
+ * 1) first we check where the message with the highest msgId from msglist would be inserted
+ * 2) check that position for dupe
+ * 3) determine the messageId of the preceeding msg
+ * 4) insert as many msgs from msglist with with msgId larger then the just determined id
+ * those messages are automatically less then the msg of the position we just determined in 1)
+ */
bool inOrder = (msglist.first().msgId() < msglist.last().msgId());
// depending on the order we have to traverse from the front to the back or vice versa
QList<Message> grouplist;
MsgId id;
MsgId dupeId;
- int dupeCount = 0;
+ int processedMsgs = 1; // we know the list isn't empty, so we at least process one message
+ int idx;
bool fastForward = false;
QList<Message>::const_iterator iter;
if(inOrder) {
iter = msglist.constBegin();
}
- int idx = indexForId((*iter).msgId());
+ idx = indexForId((*iter).msgId());
if(idx >= 0 && !_messageList.isEmpty())
dupeId = _messageList[idx]->msgId();
if((*iter).msgId() != dupeId)
grouplist << *iter;
- else
- dupeCount++;
if(!inOrder)
iter++;
if(!fastForward && (*iter).msgId() < id)
break;
+ processedMsgs++;
+ if(grouplist.isEmpty()) { // as long as we don't have a starting point, we have to update the dupeId
+ idx = indexForId((*iter).msgId());
+ if(idx >= 0 && !_messageList.isEmpty())
+ dupeId = _messageList[idx]->msgId();
+ }
if((*iter).msgId() != dupeId) {
if(!grouplist.isEmpty()) {
QDateTime nextTs = grouplist.value(0).timestamp();
Message dayChangeMsg = Message::ChangeOfDay(nextTs);
dayChangeMsg.setMsgId((*iter).msgId());
grouplist.prepend(dayChangeMsg);
- dupeCount--;
}
}
+ dupeId = (*iter).msgId();
grouplist.prepend(*iter);
- } else {
- dupeCount++;
}
}
} else {
while(iter != msglist.constEnd()) {
if(!fastForward && (*iter).msgId() < id)
break;
+ processedMsgs++;
+ if(grouplist.isEmpty()) { // as long as we don't have a starting point, we have to update the dupeId
+ idx = indexForId((*iter).msgId());
+ if(idx >= 0 && !_messageList.isEmpty())
+ dupeId = _messageList[idx]->msgId();
+ }
if((*iter).msgId() != dupeId) {
if(!grouplist.isEmpty()) {
QDateTime nextTs = grouplist.value(0).timestamp();
Message dayChangeMsg = Message::ChangeOfDay(nextTs);
dayChangeMsg.setMsgId((*iter).msgId());
grouplist.prepend(dayChangeMsg);
- dupeCount--;
}
}
+ dupeId = (*iter).msgId();
grouplist.prepend(*iter);
- } else {
- dupeCount++;
}
-
iter++;
}
}
- insertMessageGroup(grouplist);
- return grouplist.count() + dupeCount;
+ if(!grouplist.isEmpty())
+ insertMessageGroup(grouplist);
+ return processedMsgs;
}
void MessageModel::customEvent(QEvent *event) {
bool MessageModelItem::operator>(const MessageModelItem &other) const {
return _msgId > other._msgId;
}
+
+QDebug operator<<(QDebug dbg, const MessageModelItem &msgItem) {
+ dbg.nospace() << qPrintable(QString("MessageModelItem(MsgId:")) << msgItem.msgId()
+ << qPrintable(QString(",")) << msgItem.timeStamp()
+ << qPrintable(QString(", Type:")) << msgItem.msgType()
+ << qPrintable(QString(", Flags:")) << msgItem.msgFlags() << qPrintable(QString(")"))
+ << msgItem.data(1, Qt::DisplayRole).toString() << ":" << msgItem.data(2, Qt::DisplayRole).toString();
+ return dbg;
+}