X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Fchatviewsearchcontroller.cpp;h=f12bfa01142c72aee6725eae8331e469b2bdcd92;hp=e21dc8a484c1108791034a5e6e3ed50821ffb70d;hb=6eefdfc697067d184a589fc8a231b16316c09106;hpb=e50ae7a06fc4e5d3a911c361d30953410deab609 diff --git a/src/qtui/chatviewsearchcontroller.cpp b/src/qtui/chatviewsearchcontroller.cpp index e21dc8a4..f12bfa01 100644 --- a/src/qtui/chatviewsearchcontroller.cpp +++ b/src/qtui/chatviewsearchcontroller.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-2015 by the Quassel Project * + * Copyright (C) 2005-2018 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -30,13 +30,7 @@ #include "messagemodel.h" ChatViewSearchController::ChatViewSearchController(QObject *parent) - : QObject(parent), - _scene(0), - _currentHighlight(0), - _caseSensitive(false), - _searchSenders(false), - _searchMsgs(true), - _searchOnlyRegularMsgs(true) + : QObject(parent) { } @@ -65,8 +59,8 @@ void ChatViewSearchController::setScene(ChatScene *scene) return; if (_scene) { - disconnect(_scene, 0, this, 0); - disconnect(Client::messageModel(), 0, this, 0); + disconnect(_scene, nullptr, this, nullptr); + disconnect(Client::messageModel(), nullptr, this, nullptr); qDeleteAll(_highlightItems); _highlightItems.clear(); } @@ -75,9 +69,9 @@ void ChatViewSearchController::setScene(ChatScene *scene) if (!scene) return; - connect(_scene, SIGNAL(destroyed()), this, SLOT(sceneDestroyed())); - connect(_scene, SIGNAL(layoutChanged()), this, SLOT(repositionHighlights())); - connect(Client::messageModel(), SIGNAL(finishedBacklogFetch(BufferId)), this, SLOT(updateHighlights())); + connect(_scene, &QObject::destroyed, this, &ChatViewSearchController::sceneDestroyed); + connect(_scene, &ChatScene::layoutChanged, this, [this]() { repositionHighlights(); }); + connect(Client::messageModel(), &MessageModel::finishedBacklogFetch, this, [this]() { updateHighlights(); }); updateHighlights(); } @@ -124,7 +118,7 @@ void ChatViewSearchController::updateHighlights(bool reuse) if (reuse) { QSet chatLines; foreach(SearchHighlightItem *highlightItem, _highlightItems) { - ChatLine *line = qgraphicsitem_cast(highlightItem->parentItem()); + auto *line = qgraphicsitem_cast(highlightItem->parentItem()); if (line) chatLines << line; } @@ -151,7 +145,7 @@ void ChatViewSearchController::updateHighlights(bool reuse) int start = 0; int end = _highlightItems.count() - 1; QPointF startPos; QPointF endPos; - while (1) { + while (true) { startPos = _highlightItems[start]->scenePos(); endPos = _highlightItems[end]->scenePos(); if (startPos == oldHighlightPos) { @@ -166,6 +160,30 @@ void ChatViewSearchController::updateHighlights(bool reuse) _currentHighlight = start; break; } + if (end == 0 && start == 0) { + // Sometimes we can run into an issue where the start and end are both set + // to zero. Rather than endlessly spin this loop, bail out. Search seems + // to work fine. + // [Test case] + // Unfortunately, this seems specific to the contents of a buffer. First, + // find a buffer that you've encountered freezing, and keep track of what + // was loaded, where it was, and the two most recent search terms. + // For example... + // 1. Load some backlog to a buffer + // 2. Search for term with any number of matches + // 3. Making sure to -type over existing words without first backspacing-, + // search for another term with only one match + // Expected: Search results found, no freezing + // Actual: Quassel hangs. startPos and endPos = same place, start = 0, + // end = 0, _currentHighlight appears to retain values from the + // previous search. + + // Reset _currentHighlight to start, otherwise it'll retain the value from + // previous search, resulting in an index-out-of-bounds error. + _currentHighlight = start; + // Escape from the loop! + break; + } int pivot = (end + start) / 2; QPointF pivotPos = _highlightItems[pivot]->scenePos(); if (startPos.y() == endPos.y()) { @@ -241,7 +259,7 @@ void ChatViewSearchController::updateHighlights(ChatLine *line) } foreach(QGraphicsItem *child, line->childItems()) { - SearchHighlightItem *highlightItem = qgraphicsitem_cast(child); + auto *highlightItem = qgraphicsitem_cast(child); if (!highlightItem) continue; @@ -286,7 +304,7 @@ void ChatViewSearchController::repositionHighlights() { QSet chatLines; foreach(SearchHighlightItem *item, _highlightItems) { - ChatLine *line = qgraphicsitem_cast(item->parentItem()); + auto *line = qgraphicsitem_cast(item->parentItem()); if (line) chatLines << line; } @@ -301,7 +319,7 @@ void ChatViewSearchController::repositionHighlights(ChatLine *line) { QList searchHighlights; foreach(QGraphicsItem *child, line->childItems()) { - SearchHighlightItem *highlightItem = qgraphicsitem_cast(child); + auto *highlightItem = qgraphicsitem_cast(child); if (highlightItem) searchHighlights << highlightItem; } @@ -333,7 +351,7 @@ void ChatViewSearchController::repositionHighlights(ChatLine *line) void ChatViewSearchController::sceneDestroyed() { // WARNING: don't call any methods on scene! - _scene = 0; + _scene = nullptr; // the items will be automatically deleted when the scene is destroyed // so we just have to clear the list; _highlightItems.clear(); @@ -404,7 +422,7 @@ SearchHighlightItem::SearchHighlightItem(QRectF wordRect, QGraphicsItem *parent) setPos(wordRect.x(), wordRect.y()); updateGeometry(wordRect.width(), wordRect.height()); - connect(&_timeLine, SIGNAL(valueChanged(qreal)), this, SLOT(updateHighlight(qreal))); + connect(&_timeLine, &QTimeLine::valueChanged, this, &SearchHighlightItem::updateHighlight); }