File indexing completed on 2024-04-28 04:39:08
0001 /* 0002 SPDX-FileCopyrightText: 2013 Milian Wolff <mail@milianw.de> 0003 0004 SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0005 */ 0006 0007 #ifndef FILTER_H 0008 #define FILTER_H 0009 0010 #include <QRegExp> 0011 #include <QVector> 0012 #include <KSharedConfig> 0013 0014 namespace KDevelop { 0015 0016 struct SerializedFilter; 0017 0018 /** 0019 * The Filter is a the class which is used for actual matching against items. 0020 * 0021 * It "compiles" serialized filters for performance and extracts useful information. 0022 */ 0023 struct Filter 0024 { 0025 public: 0026 enum Target { 0027 Files = 1, 0028 Folders = 2 0029 }; 0030 Q_DECLARE_FLAGS(Targets, Target) 0031 0032 enum Type { 0033 /// Hides matched targets. 0034 Exclusive, 0035 /// Reverses the match to be inclusive and negates the previously applied exclusive filters. 0036 Inclusive 0037 }; 0038 0039 Filter(); 0040 Filter(const SerializedFilter& filter); 0041 0042 bool operator==(const Filter& filter) const 0043 { 0044 return filter.pattern == pattern 0045 && filter.targets == targets 0046 && filter.type == type; 0047 } 0048 0049 QRegExp pattern; 0050 Targets targets; 0051 Type type = Exclusive; 0052 }; 0053 0054 using Filters = QVector<Filter>; 0055 0056 /** 0057 * SerializedFilter is what gets stored on disk in the configuration and represents 0058 * the interface which the user can interact with. 0059 */ 0060 struct SerializedFilter 0061 { 0062 SerializedFilter(); 0063 SerializedFilter(const QString& pattern, Filter::Targets targets, Filter::Type type = Filter::Exclusive); 0064 QString pattern; 0065 Filter::Targets targets; 0066 Filter::Type type = Filter::Exclusive; 0067 }; 0068 0069 using SerializedFilters = QVector<SerializedFilter>; 0070 0071 SerializedFilters defaultFilters(); 0072 SerializedFilters readFilters(const KSharedConfigPtr& config); 0073 void writeFilters(const SerializedFilters& filters, KSharedConfigPtr config); 0074 Filters deserialize(const SerializedFilters& filters); 0075 0076 } 0077 0078 Q_DECLARE_TYPEINFO(KDevelop::Filter, Q_MOVABLE_TYPE); 0079 Q_DECLARE_TYPEINFO(KDevelop::SerializedFilter, Q_MOVABLE_TYPE); 0080 0081 #endif // FILTER_H