From e222870b3f53c90a735d44f98c76b0f884f52287 Mon Sep 17 00:00:00 2001 From: Manuel Nickschas Date: Mon, 4 Aug 2008 13:32:58 +0200 Subject: [PATCH] Fixing selections, also prevent from crashing in some circumstances --- src/qtui/chatscene.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/qtui/chatscene.cpp b/src/qtui/chatscene.cpp index 6dbe1710..8f36e1d2 100644 --- a/src/qtui/chatscene.cpp +++ b/src/qtui/chatscene.cpp @@ -252,9 +252,15 @@ void ChatScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { //!\brief Convert current selection to human-readable string. QString ChatScene::selectionToString() const { //TODO Make selection format configurable! - if(!_isSelecting) return ""; + if(!_isSelecting) return QString(); + int start = qMin(_selectionStart, _selectionEnd); + int end = qMax(_selectionStart, _selectionEnd); + if(start < 0 || end >= _lines.count()) { + qDebug() << "Invalid selection range:" << start << end; + return QString(); + } QString result; - for(int l = _selectionStart; l <= _selectionEnd; l++) { + for(int l = start; l <= end; l++) { if(_selectionMinCol == ChatLineModel::TimestampColumn) result += _lines[l]->item(ChatLineModel::TimestampColumn)->data(MessageModel::DisplayRole).toString() + " "; if(_selectionMinCol <= ChatLineModel::SenderColumn) -- 2.20.1