From fd90abd3f3baa4fc98fa7e3df0e22e9bd3d77d95 Mon Sep 17 00:00:00 2001 From: Manuel Nickschas Date: Wed, 13 Aug 2008 12:23:30 +0200 Subject: [PATCH] Correctly handle selections while new ChatLines are being inserted This should fix most selection-based crashes. Had one caused by something else, but couldn't reproduce yet. Backtraces welcome :) --- src/qtui/chatscene.cpp | 12 +++++++++--- src/qtui/chatscene.h | 3 +-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/qtui/chatscene.cpp b/src/qtui/chatscene.cpp index 7ba7d392..e04784c9 100644 --- a/src/qtui/chatscene.cpp +++ b/src/qtui/chatscene.cpp @@ -44,7 +44,6 @@ ChatScene::ChatScene(QAbstractItemModel *model, const QString &idString, QObject _model(model), _singleBufferScene(false), _selectingItem(0), - _lastItem(0), _selectionStart(-1), _isSelecting(false), _fetchingBacklog(false) @@ -113,6 +112,15 @@ void ChatScene::rowsInserted(const QModelIndex &index, int start, int end) { _lines[i]->setRow(i); } + // update selection + if(_selectionStart >= 0) { + int offset = end - start + 1; + if(_selectionStart >= start) _selectionStart += offset; + if(_selectionEnd >= start) _selectionEnd += offset; + if(_firstSelectionRow >= start) _firstSelectionRow += offset; + if(_lastSelectionRow >= start) _lastSelectionRow += offset; + } + if(h > 0) { _height += h; for(int i = end+1; i < _lines.count(); i++) { @@ -205,10 +213,8 @@ void ChatScene::updateSelection(const QPointF &pos) { _lines[l]->setSelected(true, minColumn); } } - int newstart = qMin(curRow, _firstSelectionRow); int newend = qMax(curRow, _firstSelectionRow); - if(newstart < _selectionStart) { for(int l = newstart; l < _selectionStart; l++) _lines[l]->setSelected(true, minColumn); diff --git a/src/qtui/chatscene.h b/src/qtui/chatscene.h index 17c009c8..1dae1e22 100644 --- a/src/qtui/chatscene.h +++ b/src/qtui/chatscene.h @@ -92,8 +92,7 @@ class ChatScene : public QGraphicsScene { ColumnHandleItem *firstColHandle, *secondColHandle; qreal firstColHandlePos, secondColHandlePos; - ChatItem *_selectingItem, *_lastItem; - QSet _selectedItems; + ChatItem *_selectingItem; int _selectionStartCol, _selectionMinCol; int _selectionStart; int _selectionEnd; -- 2.20.1