1bb02e0acSNicolas Bonnefon /* 2bb02e0acSNicolas Bonnefon * Copyright (C) 2009, 2010 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 #ifndef FILTERSET_H 21bb02e0acSNicolas Bonnefon #define FILTERSET_H 22bb02e0acSNicolas Bonnefon 23*4fb0346eSAnton Filimonov #include <QRegularExpression> 24bb02e0acSNicolas Bonnefon #include <QColor> 25bb02e0acSNicolas Bonnefon #include <QMetaType> 26bb02e0acSNicolas Bonnefon 27bb02e0acSNicolas Bonnefon #include "persistable.h" 28bb02e0acSNicolas Bonnefon 29bb02e0acSNicolas Bonnefon // Represents a filter, i.e. a regexp and the colors matching text 30bb02e0acSNicolas Bonnefon // should be rendered in. 31bb02e0acSNicolas Bonnefon class Filter 32bb02e0acSNicolas Bonnefon { 33bb02e0acSNicolas Bonnefon public: 34bb02e0acSNicolas Bonnefon // Construct an uninitialized Filter (when reading from a config file) 35bb02e0acSNicolas Bonnefon Filter(); 36b9c9a815SAnton Filimonov Filter(const QString& pattern, bool ignoreCase, 37bb02e0acSNicolas Bonnefon const QString& foreColor, const QString& backColor ); 38bb02e0acSNicolas Bonnefon 39*4fb0346eSAnton Filimonov bool hasMatch( const QString& string ) const; 40bb02e0acSNicolas Bonnefon 41bb02e0acSNicolas Bonnefon // Accessor functions 42bb02e0acSNicolas Bonnefon QString pattern() const; 43bb02e0acSNicolas Bonnefon void setPattern( const QString& pattern ); 44b9c9a815SAnton Filimonov bool ignoreCase() const; 45b9c9a815SAnton Filimonov void setIgnoreCase( bool ignoreCase ); 46bb02e0acSNicolas Bonnefon const QString& foreColorName() const; 47bb02e0acSNicolas Bonnefon void setForeColor( const QString& foreColorName ); 48bb02e0acSNicolas Bonnefon const QString& backColorName() const; 49bb02e0acSNicolas Bonnefon void setBackColor( const QString& backColorName ); 50bb02e0acSNicolas Bonnefon 51bb02e0acSNicolas Bonnefon // Operators for serialization 52bb02e0acSNicolas Bonnefon // (must be kept to migrate filters from <=0.8.2) 53bb02e0acSNicolas Bonnefon friend QDataStream& operator<<( QDataStream& out, const Filter& object ); 54bb02e0acSNicolas Bonnefon friend QDataStream& operator>>( QDataStream& in, Filter& object ); 55bb02e0acSNicolas Bonnefon 56bb02e0acSNicolas Bonnefon // Reads/writes the current config in the QSettings object passed 57bb02e0acSNicolas Bonnefon void saveToStorage( QSettings& settings ) const; 58bb02e0acSNicolas Bonnefon void retrieveFromStorage( QSettings& settings ); 59bb02e0acSNicolas Bonnefon 60bb02e0acSNicolas Bonnefon private: 61*4fb0346eSAnton Filimonov QRegularExpression regexp_; 62bb02e0acSNicolas Bonnefon QString foreColorName_; 63bb02e0acSNicolas Bonnefon QString backColorName_; 64bb02e0acSNicolas Bonnefon bool enabled_; 65bb02e0acSNicolas Bonnefon }; 66bb02e0acSNicolas Bonnefon 67bb02e0acSNicolas Bonnefon // Represents an ordered set of filters to be applied to each line displayed. 68bb02e0acSNicolas Bonnefon class FilterSet : public Persistable 69bb02e0acSNicolas Bonnefon { 70bb02e0acSNicolas Bonnefon public: 71bb02e0acSNicolas Bonnefon // Construct an empty filter set 72bb02e0acSNicolas Bonnefon FilterSet(); 73bb02e0acSNicolas Bonnefon 74bb02e0acSNicolas Bonnefon // Returns weither the passed line match a filter of the set, 75bb02e0acSNicolas Bonnefon // if so, it returns the fore/back colors the line should use. 76bb02e0acSNicolas Bonnefon // Ownership of the colors is transfered to the caller. 77bb02e0acSNicolas Bonnefon bool matchLine( const QString& line, 78bb02e0acSNicolas Bonnefon QColor* foreColor, QColor* backColor ) const; 79bb02e0acSNicolas Bonnefon 80bb02e0acSNicolas Bonnefon // Reads/writes the current config in the QSettings object passed 81bb02e0acSNicolas Bonnefon virtual void saveToStorage( QSettings& settings ) const; 82bb02e0acSNicolas Bonnefon virtual void retrieveFromStorage( QSettings& settings ); 83bb02e0acSNicolas Bonnefon 84bb02e0acSNicolas Bonnefon // Should be private really, but I don't know how to have 85bb02e0acSNicolas Bonnefon // it recognised by QVariant then. 86bb02e0acSNicolas Bonnefon typedef QList<Filter> FilterList; 87bb02e0acSNicolas Bonnefon 88bb02e0acSNicolas Bonnefon // Operators for serialization 89bb02e0acSNicolas Bonnefon // (must be kept to migrate filters from <=0.8.2) 90bb02e0acSNicolas Bonnefon friend QDataStream& operator<<( 91bb02e0acSNicolas Bonnefon QDataStream& out, const FilterSet& object ); 92bb02e0acSNicolas Bonnefon friend QDataStream& operator>>( 93bb02e0acSNicolas Bonnefon QDataStream& in, FilterSet& object ); 94bb02e0acSNicolas Bonnefon 95bb02e0acSNicolas Bonnefon private: 96bb02e0acSNicolas Bonnefon static const int FILTERSET_VERSION; 97bb02e0acSNicolas Bonnefon 98bb02e0acSNicolas Bonnefon FilterList filterList; 99bb02e0acSNicolas Bonnefon 100bb02e0acSNicolas Bonnefon // To simplify this class interface, FilterDialog can access our 101bb02e0acSNicolas Bonnefon // internal structure directly. 102bb02e0acSNicolas Bonnefon friend class FiltersDialog; 103bb02e0acSNicolas Bonnefon }; 104bb02e0acSNicolas Bonnefon 105bb02e0acSNicolas Bonnefon Q_DECLARE_METATYPE(Filter) 106bb02e0acSNicolas Bonnefon Q_DECLARE_METATYPE(FilterSet) 107bb02e0acSNicolas Bonnefon Q_DECLARE_METATYPE(FilterSet::FilterList) 108bb02e0acSNicolas Bonnefon 109bb02e0acSNicolas Bonnefon #endif 110