Warning, file /utilities/konsole/src/filterHotSpots/Filter.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 SPDX-FileCopyrightText: 2007-2008 Robert Knight <robertknight@gmail.com> 0003 SPDX-FileCopyrightText: 2020 Tomaz Canabrava <tcanabrava@gmail.com> 0004 0005 SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #include "Filter.h" 0009 0010 #include "HotSpot.h" 0011 0012 using namespace Konsole; 0013 0014 Filter::Filter() 0015 : _linePositions(nullptr) 0016 , _buffer(nullptr) 0017 { 0018 } 0019 0020 Filter::~Filter() 0021 { 0022 reset(); 0023 } 0024 0025 void Filter::reset() 0026 { 0027 _hotspots.clear(); 0028 _hotspotList.clear(); 0029 } 0030 0031 void Filter::setBuffer(const QString *buffer, const QList<int> *linePositions) 0032 { 0033 _buffer = buffer; 0034 _linePositions = linePositions; 0035 } 0036 0037 std::pair<int, int> Filter::getLineColumn(int prevline, int position) 0038 { 0039 Q_ASSERT(_linePositions); 0040 Q_ASSERT(_buffer); 0041 0042 for (int i = prevline; i < _linePositions->count(); i++) { 0043 const int nextLine = i == _linePositions->count() - 1 ? _buffer->length() + 1 : _linePositions->value(i + 1); 0044 0045 if (_linePositions->value(i) <= position && position < nextLine) { 0046 return {i, Character::stringWidth(buffer()->mid(_linePositions->value(i), position - _linePositions->value(i)))}; 0047 } 0048 } 0049 return {-1, -1}; 0050 } 0051 0052 const QString *Filter::buffer() 0053 { 0054 return _buffer; 0055 } 0056 0057 void Filter::addHotSpot(QSharedPointer<HotSpot> spot) 0058 { 0059 _hotspotList << spot; 0060 0061 for (int line = spot->startLine(); line <= spot->endLine(); line++) { 0062 _hotspots.insert(line, spot); 0063 } 0064 } 0065 0066 QList<QSharedPointer<HotSpot>> Filter::hotSpots() const 0067 { 0068 return _hotspotList; 0069 } 0070 0071 QSharedPointer<HotSpot> Filter::hotSpotAt(int line, int column) const 0072 { 0073 const auto hotspots = _hotspots.values(line); 0074 0075 for (auto &spot : hotspots) { 0076 if (spot->startLine() == line && spot->startColumn() > column) { 0077 continue; 0078 } 0079 if (spot->endLine() == line && spot->endColumn() < column) { 0080 continue; 0081 } 0082 0083 return spot; 0084 } 0085 0086 return nullptr; 0087 }