1bb02e0acSNicolas Bonnefon /*
2bb02e0acSNicolas Bonnefon * Copyright (C) 2011, 2012 Nicolas Bonnefon and other contributors
3bb02e0acSNicolas Bonnefon *
4bb02e0acSNicolas Bonnefon * This file is part of glogg.
5bb02e0acSNicolas Bonnefon *
6bb02e0acSNicolas Bonnefon * glogg is free software: you can redistribute it and/or modify
7bb02e0acSNicolas Bonnefon * it under the terms of the GNU General Public License as published by
8bb02e0acSNicolas Bonnefon * the Free Software Foundation, either version 3 of the License, or
9bb02e0acSNicolas Bonnefon * (at your option) any later version.
10bb02e0acSNicolas Bonnefon *
11bb02e0acSNicolas Bonnefon * glogg is distributed in the hope that it will be useful,
12bb02e0acSNicolas Bonnefon * but WITHOUT ANY WARRANTY; without even the implied warranty of
13bb02e0acSNicolas Bonnefon * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14bb02e0acSNicolas Bonnefon * GNU General Public License for more details.
15bb02e0acSNicolas Bonnefon *
16bb02e0acSNicolas Bonnefon * You should have received a copy of the GNU General Public License
17bb02e0acSNicolas Bonnefon * along with glogg. If not, see <http://www.gnu.org/licenses/>.
18bb02e0acSNicolas Bonnefon */
19bb02e0acSNicolas Bonnefon
20bb02e0acSNicolas Bonnefon // This file implements the Overview class.
21bb02e0acSNicolas Bonnefon // It provides support for drawing the match overview sidebar but
22bb02e0acSNicolas Bonnefon // the actual drawing is done in AbstractLogView which uses this class.
23bb02e0acSNicolas Bonnefon
24bb02e0acSNicolas Bonnefon #include "log.h"
25bb02e0acSNicolas Bonnefon
26bb02e0acSNicolas Bonnefon #include "data/logfiltereddata.h"
27bb02e0acSNicolas Bonnefon
28bb02e0acSNicolas Bonnefon #include "overview.h"
29bb02e0acSNicolas Bonnefon
Overview()30bb02e0acSNicolas Bonnefon Overview::Overview() : matchLines_(), markLines_()
31bb02e0acSNicolas Bonnefon {
32bb02e0acSNicolas Bonnefon logFilteredData_ = NULL;
33bb02e0acSNicolas Bonnefon linesInFile_ = 0;
34bb02e0acSNicolas Bonnefon topLine_ = 0;
35bb02e0acSNicolas Bonnefon nbLines_ = 0;
36bb02e0acSNicolas Bonnefon height_ = 0;
37bb02e0acSNicolas Bonnefon dirty_ = true;
38bb02e0acSNicolas Bonnefon visible_ = false;
39bb02e0acSNicolas Bonnefon }
40bb02e0acSNicolas Bonnefon
~Overview()41bb02e0acSNicolas Bonnefon Overview::~Overview()
42bb02e0acSNicolas Bonnefon {
43bb02e0acSNicolas Bonnefon }
44bb02e0acSNicolas Bonnefon
setFilteredData(const LogFilteredData * logFilteredData)45bb02e0acSNicolas Bonnefon void Overview::setFilteredData( const LogFilteredData* logFilteredData )
46bb02e0acSNicolas Bonnefon {
47bb02e0acSNicolas Bonnefon logFilteredData_ = logFilteredData;
48bb02e0acSNicolas Bonnefon }
49bb02e0acSNicolas Bonnefon
updateData(int totalNbLine)50bb02e0acSNicolas Bonnefon void Overview::updateData( int totalNbLine )
51bb02e0acSNicolas Bonnefon {
52bb02e0acSNicolas Bonnefon LOG(logDEBUG) << "OverviewWidget::updateData " << totalNbLine;
53bb02e0acSNicolas Bonnefon
54bb02e0acSNicolas Bonnefon linesInFile_ = totalNbLine;
55bb02e0acSNicolas Bonnefon dirty_ = true;
56bb02e0acSNicolas Bonnefon }
57bb02e0acSNicolas Bonnefon
updateView(int height)58bb02e0acSNicolas Bonnefon void Overview::updateView( int height )
59bb02e0acSNicolas Bonnefon {
60bb02e0acSNicolas Bonnefon // We don't touch the cache if the height hasn't changed
61bb02e0acSNicolas Bonnefon if ( ( height != height_ ) || ( dirty_ == true ) ) {
62bb02e0acSNicolas Bonnefon height_ = height;
63bb02e0acSNicolas Bonnefon
64bb02e0acSNicolas Bonnefon recalculatesLines();
65bb02e0acSNicolas Bonnefon }
66bb02e0acSNicolas Bonnefon }
67bb02e0acSNicolas Bonnefon
getMatchLines() const68bb02e0acSNicolas Bonnefon const QVector<Overview::WeightedLine>* Overview::getMatchLines() const
69bb02e0acSNicolas Bonnefon {
70bb02e0acSNicolas Bonnefon return &matchLines_;
71bb02e0acSNicolas Bonnefon }
72bb02e0acSNicolas Bonnefon
getMarkLines() const73bb02e0acSNicolas Bonnefon const QVector<Overview::WeightedLine>* Overview::getMarkLines() const
74bb02e0acSNicolas Bonnefon {
75bb02e0acSNicolas Bonnefon return &markLines_;
76bb02e0acSNicolas Bonnefon }
77bb02e0acSNicolas Bonnefon
getViewLines() const78bb02e0acSNicolas Bonnefon std::pair<int,int> Overview::getViewLines() const
79bb02e0acSNicolas Bonnefon {
80bb02e0acSNicolas Bonnefon int top = 0;
81bb02e0acSNicolas Bonnefon int bottom = height_ - 1;
82bb02e0acSNicolas Bonnefon
83bb02e0acSNicolas Bonnefon if ( linesInFile_ > 0 ) {
84bb02e0acSNicolas Bonnefon top = (int)((qint64)topLine_ * height_ / linesInFile_);
85bb02e0acSNicolas Bonnefon bottom = (int)((qint64)top + nbLines_ * height_ / linesInFile_);
86bb02e0acSNicolas Bonnefon }
87bb02e0acSNicolas Bonnefon
88bb02e0acSNicolas Bonnefon return std::pair<int,int>(top, bottom);
89bb02e0acSNicolas Bonnefon }
90bb02e0acSNicolas Bonnefon
fileLineFromY(int position) const91bb02e0acSNicolas Bonnefon int Overview::fileLineFromY( int position ) const
92bb02e0acSNicolas Bonnefon {
93bb02e0acSNicolas Bonnefon int line = (int)((qint64)position * linesInFile_ / height_);
94bb02e0acSNicolas Bonnefon
95bb02e0acSNicolas Bonnefon return line;
96bb02e0acSNicolas Bonnefon }
97bb02e0acSNicolas Bonnefon
yFromFileLine(int file_line) const98bb02e0acSNicolas Bonnefon int Overview::yFromFileLine( int file_line ) const
99bb02e0acSNicolas Bonnefon {
100bb02e0acSNicolas Bonnefon int position = 0;
101bb02e0acSNicolas Bonnefon
102bb02e0acSNicolas Bonnefon if ( linesInFile_ > 0 )
103bb02e0acSNicolas Bonnefon position = (int)((qint64)file_line * height_ / linesInFile_);
104bb02e0acSNicolas Bonnefon
105bb02e0acSNicolas Bonnefon return position;
106bb02e0acSNicolas Bonnefon }
107bb02e0acSNicolas Bonnefon
108bb02e0acSNicolas Bonnefon // Update the internal cache
recalculatesLines()109bb02e0acSNicolas Bonnefon void Overview::recalculatesLines()
110bb02e0acSNicolas Bonnefon {
111bb02e0acSNicolas Bonnefon LOG(logDEBUG) << "OverviewWidget::recalculatesLines";
112bb02e0acSNicolas Bonnefon
113bb02e0acSNicolas Bonnefon if ( logFilteredData_ != NULL ) {
114bb02e0acSNicolas Bonnefon matchLines_.clear();
115bb02e0acSNicolas Bonnefon markLines_.clear();
116bb02e0acSNicolas Bonnefon
117f62e2c23SNicolas Bonnefon if ( linesInFile_ > 0 ) {
118bb02e0acSNicolas Bonnefon for ( int i = 0; i < logFilteredData_->getNbLine(); i++ ) {
119bb02e0acSNicolas Bonnefon LogFilteredData::FilteredLineType line_type =
120bb02e0acSNicolas Bonnefon logFilteredData_->filteredLineTypeByIndex( i );
121bb02e0acSNicolas Bonnefon int line = (int) logFilteredData_->getMatchingLineNumber( i );
122bb02e0acSNicolas Bonnefon int position = (int)( (qint64)line * height_ / linesInFile_ );
123bb02e0acSNicolas Bonnefon if ( line_type == LogFilteredData::Match ) {
124bb02e0acSNicolas Bonnefon if ( ( ! matchLines_.isEmpty() ) && matchLines_.last().position() == position ) {
125bb02e0acSNicolas Bonnefon // If the line is already there, we increase its weight
126bb02e0acSNicolas Bonnefon matchLines_.last().load();
127bb02e0acSNicolas Bonnefon }
128bb02e0acSNicolas Bonnefon else {
129bb02e0acSNicolas Bonnefon // If not we just add it
130bb02e0acSNicolas Bonnefon matchLines_.append( WeightedLine( position ) );
131bb02e0acSNicolas Bonnefon }
132bb02e0acSNicolas Bonnefon }
133bb02e0acSNicolas Bonnefon else {
134bb02e0acSNicolas Bonnefon if ( ( ! markLines_.isEmpty() ) && markLines_.last().position() == position ) {
135bb02e0acSNicolas Bonnefon // If the line is already there, we increase its weight
136bb02e0acSNicolas Bonnefon markLines_.last().load();
137bb02e0acSNicolas Bonnefon }
138bb02e0acSNicolas Bonnefon else {
139bb02e0acSNicolas Bonnefon // If not we just add it
140bb02e0acSNicolas Bonnefon markLines_.append( WeightedLine( position ) );
141bb02e0acSNicolas Bonnefon }
142bb02e0acSNicolas Bonnefon }
143bb02e0acSNicolas Bonnefon }
144bb02e0acSNicolas Bonnefon }
145f62e2c23SNicolas Bonnefon }
146bb02e0acSNicolas Bonnefon else
147*045703daSNicolas Bonnefon LOG(logDEBUG) << "Overview::recalculatesLines: logFilteredData_ == NULL";
148bb02e0acSNicolas Bonnefon
149bb02e0acSNicolas Bonnefon dirty_ = false;
150bb02e0acSNicolas Bonnefon }
151