From 3c6a3e20cab757c94cac4ca54f0dabec4d7ac409 Mon Sep 17 00:00:00 2001 From: Alexander Hirsch Date: Thu, 14 Jun 2018 16:22:07 +0200 Subject: [PATCH 1/3] Fix lookupLineNumber() when lower-bound is empty The function returns an index, but returned the line-number instead. If there is no lower-bound we return 0, since the first element is already greater (if we have any). --- src/utils.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/utils.h b/src/utils.h index 5e1abd2d7..bb923664e 100644 --- a/src/utils.h +++ b/src/utils.h @@ -118,9 +118,6 @@ LineNumber lookupLineNumber( Iterator begin, Iterator end, LineNumber lineNum ) if ( lowerBound != end ) { lineIndex = std::distance(begin, lowerBound); } - else if (begin != end) { - lineIndex = begin->lineNumber(); - } return lineIndex; } From c824960f6011bc892ae503d27421d0e25803d499 Mon Sep 17 00:00:00 2001 From: Alexander Hirsch Date: Thu, 14 Jun 2018 16:25:03 +0200 Subject: [PATCH 2/3] Don't attempt jumping to a FilteredView-line when it's empty --- src/crawlerwidget.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/crawlerwidget.cpp b/src/crawlerwidget.cpp index 657d1cd1f..28c1d3559 100644 --- a/src/crawlerwidget.cpp +++ b/src/crawlerwidget.cpp @@ -572,8 +572,10 @@ void CrawlerWidget::changeFilteredViewVisibility( int index ) filteredView->setVisibility( visibility ); - const int lineIndex = logFilteredData_->getLineIndexNumber( currentLineNumber_ ); - filteredView->selectAndDisplayLine( lineIndex ); + if ( logFilteredData_->getNbLine() > 0 ) { + const int lineIndex = logFilteredData_->getLineIndexNumber( currentLineNumber_ ); + filteredView->selectAndDisplayLine( lineIndex ); + } } void CrawlerWidget::addToSearch( const QString& string ) From a7cb343bc36b65edfe75fd8275f194e6830bbb8f Mon Sep 17 00:00:00 2001 From: Alexander Hirsch Date: Thu, 21 Jun 2018 11:18:57 +0200 Subject: [PATCH 3/3] Prevent AbstractLogView::convertCoordToFilePos attempting to lookup empty lines. --- src/abstractlogview.cpp | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/abstractlogview.cpp b/src/abstractlogview.cpp index d56155f0d..22ad4d3c7 100644 --- a/src/abstractlogview.cpp +++ b/src/abstractlogview.cpp @@ -1167,21 +1167,25 @@ int AbstractLogView::convertCoordToLine(int yPos) const QPoint AbstractLogView::convertCoordToFilePos( const QPoint& pos ) const { int line = convertCoordToLine( pos.y() ); - if ( line >= logData->getNbLine() ) - line = logData->getNbLine() - 1; + int nbLine = logData->getNbLine(); + if ( line >= nbLine ) + line = nbLine - 1; if ( line < 0 ) line = 0; - // Determine column in screen space and convert it to file space - int column = firstCol + ( pos.x() - leftMarginPx_ ) / charWidth_; + int column = 0; - QString this_line = logData->getExpandedLineString( line ); - const int length = this_line.length(); + if ( nbLine ) { + // Determine column in screen space and convert it to file space + column = firstCol + ( pos.x() - leftMarginPx_ ) / charWidth_; + QString this_line = logData->getExpandedLineString( line ); + const int length = this_line.length(); - if ( column >= length ) - column = length - 1; - if ( column < 0 ) - column = 0; + if ( column >= length ) + column = length - 1; + if ( column < 0 ) + column = 0; + } LOG(logDEBUG4) << "AbstractLogView::convertCoordToFilePos col=" << column << " line=" << line;