From 69fde0d8b0c97247644cea99f2afcc7d8c28f505 Mon Sep 17 00:00:00 2001 From: krepa098 Date: Tue, 10 Feb 2015 14:30:49 +0100 Subject: [PATCH] refactoring --- src/chatlog/chatlog.cpp | 28 +++++++++++++++++++++------- src/chatlog/content/text.cpp | 2 -- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/chatlog/chatlog.cpp b/src/chatlog/chatlog.cpp index 750262ccf..428d523ec 100644 --- a/src/chatlog/chatlog.cpp +++ b/src/chatlog/chatlog.cpp @@ -403,20 +403,34 @@ void ChatLog::insertChatlineOnTop(const QList& newLines) if(newLines.isEmpty()) return; - // move all lines down by n - int n = newLines.size(); - for(ChatLine::Ptr l : lines) - l->setRow(l->getRow() + n); + QGraphicsScene::ItemIndexMethod oldIndexMeth = scene->itemIndexMethod(); + scene->setItemIndexMethod(QGraphicsScene::NoIndex); - // add the new line + // alloc space for old and new lines + QVector combLines; + combLines.reserve(newLines.size() + lines.size()); + + // add the new lines + int i = 0; for(ChatLine::Ptr l : newLines) { l->addToScene(scene); - l->setRow(--n); l->visibilityChanged(false); - lines.prepend(l); + l->setRow(i++); + combLines.push_back(l); } + // add the old lines + for(ChatLine::Ptr l : lines) + { + l->setRow(i++); + combLines.push_back(l); + } + + lines = combLines; + + scene->setItemIndexMethod(oldIndexMeth); + // redo layout startResizeWorker(); } diff --git a/src/chatlog/content/text.cpp b/src/chatlog/content/text.cpp index 7073f2060..58002220e 100644 --- a/src/chatlog/content/text.cpp +++ b/src/chatlog/content/text.cpp @@ -47,8 +47,6 @@ void Text::setText(const QString& txt) { text = txt; dirty = true; - - regenerate(); } void Text::setWidth(qreal w)