1bb02e0acSNicolas Bonnefon /*
2*8e788202SNicolas Bonnefon * Copyright (C) 2009, 2010, 2012, 2017 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 FilteredView concrete class.
21bb02e0acSNicolas Bonnefon // Most of the actual drawing and event management is done in AbstractLogView
22bb02e0acSNicolas Bonnefon // Only behaviour specific to the filtered (bottom) view is implemented here.
23bb02e0acSNicolas Bonnefon
24bb02e0acSNicolas Bonnefon #include <cassert>
25bb02e0acSNicolas Bonnefon
26bb02e0acSNicolas Bonnefon #include "filteredview.h"
27bb02e0acSNicolas Bonnefon
FilteredView(LogFilteredData * newLogData,const QuickFindPattern * const quickFindPattern,QWidget * parent)28bb02e0acSNicolas Bonnefon FilteredView::FilteredView( LogFilteredData* newLogData,
29bb02e0acSNicolas Bonnefon const QuickFindPattern* const quickFindPattern, QWidget* parent )
30bb02e0acSNicolas Bonnefon : AbstractLogView( newLogData, quickFindPattern, parent )
31bb02e0acSNicolas Bonnefon {
32bb02e0acSNicolas Bonnefon // We keep a copy of the filtered data for fast lookup of the line type
33bb02e0acSNicolas Bonnefon logFilteredData_ = newLogData;
34bb02e0acSNicolas Bonnefon }
35bb02e0acSNicolas Bonnefon
setVisibility(Visibility visi)36bb02e0acSNicolas Bonnefon void FilteredView::setVisibility( Visibility visi )
37bb02e0acSNicolas Bonnefon {
38bb02e0acSNicolas Bonnefon assert( logFilteredData_ );
39bb02e0acSNicolas Bonnefon
40bb02e0acSNicolas Bonnefon LogFilteredData::Visibility data_visibility =
41bb02e0acSNicolas Bonnefon LogFilteredData::MarksAndMatches;
42bb02e0acSNicolas Bonnefon switch ( visi ) {
43bb02e0acSNicolas Bonnefon case MarksOnly:
44bb02e0acSNicolas Bonnefon data_visibility = LogFilteredData::MarksOnly;
45bb02e0acSNicolas Bonnefon break;
46bb02e0acSNicolas Bonnefon case MatchesOnly:
47bb02e0acSNicolas Bonnefon data_visibility = LogFilteredData::MatchesOnly;
48bb02e0acSNicolas Bonnefon break;
49bb02e0acSNicolas Bonnefon case MarksAndMatches:
50bb02e0acSNicolas Bonnefon data_visibility = LogFilteredData::MarksAndMatches;
51bb02e0acSNicolas Bonnefon break;
52bb02e0acSNicolas Bonnefon };
53bb02e0acSNicolas Bonnefon
54bb02e0acSNicolas Bonnefon logFilteredData_->setVisibility( data_visibility );
55bb02e0acSNicolas Bonnefon
56bb02e0acSNicolas Bonnefon updateData();
57bb02e0acSNicolas Bonnefon }
58bb02e0acSNicolas Bonnefon
59bb02e0acSNicolas Bonnefon // For the filtered view, a line is always matching!
lineType(int lineNumber) const60bb02e0acSNicolas Bonnefon AbstractLogView::LineType FilteredView::lineType( int lineNumber ) const
61bb02e0acSNicolas Bonnefon {
62bb02e0acSNicolas Bonnefon LogFilteredData::FilteredLineType type =
63bb02e0acSNicolas Bonnefon logFilteredData_->filteredLineTypeByIndex( lineNumber );
64bb02e0acSNicolas Bonnefon if ( type == LogFilteredData::Mark )
65bb02e0acSNicolas Bonnefon return Marked;
66bb02e0acSNicolas Bonnefon else
67bb02e0acSNicolas Bonnefon return Match;
68bb02e0acSNicolas Bonnefon }
69bb02e0acSNicolas Bonnefon
displayLineNumber(int lineNumber) const70bb02e0acSNicolas Bonnefon qint64 FilteredView::displayLineNumber( int lineNumber ) const
71bb02e0acSNicolas Bonnefon {
72bb02e0acSNicolas Bonnefon // Display a 1-based index
73bb02e0acSNicolas Bonnefon return logFilteredData_->getMatchingLineNumber( lineNumber ) + 1;
74bb02e0acSNicolas Bonnefon }
75bb02e0acSNicolas Bonnefon
maxDisplayLineNumber() const76bb02e0acSNicolas Bonnefon qint64 FilteredView::maxDisplayLineNumber() const
77bb02e0acSNicolas Bonnefon {
78bb02e0acSNicolas Bonnefon return logFilteredData_->getNbTotalLines();
79bb02e0acSNicolas Bonnefon }
80*8e788202SNicolas Bonnefon
keyPressEvent(QKeyEvent * keyEvent)81*8e788202SNicolas Bonnefon void FilteredView::keyPressEvent( QKeyEvent* keyEvent )
82*8e788202SNicolas Bonnefon {
83*8e788202SNicolas Bonnefon bool noModifier = keyEvent->modifiers() == Qt::NoModifier;
84*8e788202SNicolas Bonnefon
85*8e788202SNicolas Bonnefon if ( keyEvent->key() == Qt::Key_BracketLeft && noModifier ) {
86*8e788202SNicolas Bonnefon for ( qint64 i = static_cast<qint64>( getViewPosition() ) - 1; i >= 0; --i ) {
87*8e788202SNicolas Bonnefon if ( lineType( i ) == Marked ) {
88*8e788202SNicolas Bonnefon selectAndDisplayLine( static_cast<LineNumber>( i ) );
89*8e788202SNicolas Bonnefon break;
90*8e788202SNicolas Bonnefon }
91*8e788202SNicolas Bonnefon }
92*8e788202SNicolas Bonnefon keyEvent->accept();
93*8e788202SNicolas Bonnefon }
94*8e788202SNicolas Bonnefon else if ( keyEvent->key() == Qt::Key_BracketRight && noModifier ) {
95*8e788202SNicolas Bonnefon for ( qint64 i = getViewPosition() + 1;
96*8e788202SNicolas Bonnefon i < logFilteredData_->getNbLine(); ++i ) {
97*8e788202SNicolas Bonnefon if ( lineType( i ) == Marked ) {
98*8e788202SNicolas Bonnefon selectAndDisplayLine( static_cast<LineNumber>( i ) );
99*8e788202SNicolas Bonnefon break;
100*8e788202SNicolas Bonnefon }
101*8e788202SNicolas Bonnefon }
102*8e788202SNicolas Bonnefon keyEvent->accept();
103*8e788202SNicolas Bonnefon }
104*8e788202SNicolas Bonnefon else {
105*8e788202SNicolas Bonnefon keyEvent->ignore();
106*8e788202SNicolas Bonnefon AbstractLogView::keyPressEvent( keyEvent );
107*8e788202SNicolas Bonnefon }
108*8e788202SNicolas Bonnefon }
109