Skip to content

Commit 869a09a

Browse files
authored
Add drop-down menu with predefined filters (nickbnf#241)
* Add drop-down menu with predefined filters Feature discussed in: variar#191 * Add dialog for predefined filters drop down menu configuration Feature discussed in: variar#191
1 parent 55685fd commit 869a09a

10 files changed

+650
-1
lines changed

src/ui/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ add_library(ui STATIC
88
${CMAKE_CURRENT_SOURCE_DIR}/include/highlighterset.h
99
${CMAKE_CURRENT_SOURCE_DIR}/include/highlightersmenu.h
1010
${CMAKE_CURRENT_SOURCE_DIR}/include/highlightedmatch.h
11+
${CMAKE_CURRENT_SOURCE_DIR}/include/predefinedfilters.h
12+
${CMAKE_CURRENT_SOURCE_DIR}/include/predefinedfiltersdialog.h
1113
${CMAKE_CURRENT_SOURCE_DIR}/include/infoline.h
1214
${CMAKE_CURRENT_SOURCE_DIR}/include/pathline.h
1315
${CMAKE_CURRENT_SOURCE_DIR}/include/logmainview.h
@@ -41,6 +43,7 @@ add_library(ui STATIC
4143
${CMAKE_CURRENT_SOURCE_DIR}/include/highlighteredit.ui
4244
${CMAKE_CURRENT_SOURCE_DIR}/include/highlightersetedit.ui
4345
${CMAKE_CURRENT_SOURCE_DIR}/include/highlightersdialog.ui
46+
${CMAKE_CURRENT_SOURCE_DIR}/include/predefinedfiltersdialog.ui
4447
${CMAKE_CURRENT_SOURCE_DIR}/include/optionsdialog.ui
4548

4649
${CMAKE_CURRENT_SOURCE_DIR}/src/abstractlogview.cpp
@@ -50,6 +53,8 @@ add_library(ui STATIC
5053
${CMAKE_CURRENT_SOURCE_DIR}/src/highlighteredit.cpp
5154
${CMAKE_CURRENT_SOURCE_DIR}/src/highlightersetedit.cpp
5255
${CMAKE_CURRENT_SOURCE_DIR}/src/highlighterset.cpp
56+
${CMAKE_CURRENT_SOURCE_DIR}/src/predefinedfilters.cpp
57+
${CMAKE_CURRENT_SOURCE_DIR}/src/predefinedfiltersdialog.cpp
5358
${CMAKE_CURRENT_SOURCE_DIR}/src/infoline.cpp
5459
${CMAKE_CURRENT_SOURCE_DIR}/src/pathline.cpp
5560
${CMAKE_CURRENT_SOURCE_DIR}/src/logmainview.cpp

src/ui/include/crawlerwidget.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,12 @@
5656
#include "data/logdata.h"
5757
#include "data/logfiltereddata.h"
5858
#include "filteredview.h"
59+
#include "iconloader.h"
5960
#include "logmainview.h"
6061
#include "overview.h"
62+
#include "predefinedfilters.h"
6163
#include "signalmux.h"
6264
#include "viewinterface.h"
63-
#include "iconloader.h"
6465

6566
class InfoLine;
6667
class QuickFindPattern;
@@ -104,6 +105,15 @@ class CrawlerWidget : public QSplitter,
104105
// Returns whether follow is enabled in this crawler
105106
bool isFollowEnabled() const;
106107

108+
// Set content of search line
109+
void setSearchLineEditText( const QString& text );
110+
111+
// Get content of search line
112+
QString currentSearchLineEditText() const;
113+
114+
// Reload predefined filters after changing settings
115+
void reloadPredefinedFilters() const;
116+
107117
public slots:
108118
// Stop the asynchoronous loading of the file if one is in progress
109119
// The file is identified by the view attached to it.
@@ -303,6 +313,7 @@ class CrawlerWidget : public QSplitter,
303313
QToolButton* useRegexpButton;
304314
QToolButton* searchRefreshButton;
305315
OverviewWidget* overviewWidget_;
316+
PredefinedFiltersComboBox* predefinedFilters;
306317

307318
// Default palette to be remembered
308319
QPalette searchInfoLineDefaultPalette;

src/ui/include/mainwindow.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ class MainWindow : public QMainWindow {
113113
void openClipboard();
114114
void openUrl();
115115
void editHighlighters();
116+
void editPredefinedFilters();
116117
void options();
117118
void about();
118119
void aboutQt();
@@ -253,6 +254,7 @@ class MainWindow : public QMainWindow {
253254
QAction* showDocumentationAction;
254255
QAction* aboutAction;
255256
QAction* aboutQtAction;
257+
QAction* predefinedFiltersDialogAction;
256258
QAction* reportIssueAction;
257259
QAction* generateDumpAction;
258260
QActionGroup* encodingGroup;

src/ui/include/predefinedfilters.h

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/*
2+
* Copyright (C) 2009, 2010, 2011, 2013, 2014, 2015 Nicolas Bonnefon
3+
* and other contributors
4+
*
5+
* This file is part of glogg.
6+
*
7+
* glogg is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* glogg is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with glogg. If not, see <http://www.gnu.org/licenses/>.
19+
*/
20+
21+
/*
22+
* Copyright (C) 2016 -- 2019 Anton Filimonov and other contributors
23+
*
24+
* This file is part of klogg.
25+
*
26+
* klogg is free software: you can redistribute it and/or modify
27+
* it under the terms of the GNU General Public License as published by
28+
* the Free Software Foundation, either version 3 of the License, or
29+
* (at your option) any later version.
30+
*
31+
* klogg is distributed in the hope that it will be useful,
32+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
33+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34+
* GNU General Public License for more details.
35+
*
36+
* You should have received a copy of the GNU General Public License
37+
* along with klogg. If not, see <http://www.gnu.org/licenses/>.
38+
*/
39+
40+
#ifndef PREDEFINEDFILTERS_H_
41+
#define PREDEFINEDFILTERS_H_
42+
43+
#include <QComboBox>
44+
#include <QStandardItemModel>
45+
#include <qwidget.h>
46+
47+
#include "persistable.h"
48+
49+
// Represents collection of filters read from settings file.
50+
class PredefinedFiltersCollection final : public Persistable<PredefinedFiltersCollection> {
51+
public:
52+
using Collection = QMap<QString, QString>;
53+
using CollectionIterator = QMapIterator<QString, QString>;
54+
55+
static const char* persistableName()
56+
{
57+
return "PredefinedFiltersCollectin";
58+
}
59+
60+
Collection getSyncedFilters();
61+
Collection getFilters() const;
62+
63+
void retrieveFromStorage( QSettings& settings );
64+
void saveToStorage( QSettings& settings ) const;
65+
void saveToStorage( const Collection& filters );
66+
67+
private:
68+
static constexpr int PredefinedFiltersCollection_VERSION = 1;
69+
70+
Collection filters;
71+
};
72+
73+
class PredefinedFiltersComboBox final : public QComboBox {
74+
Q_OBJECT
75+
76+
public:
77+
PredefinedFiltersComboBox( QWidget* crawler );
78+
79+
PredefinedFiltersComboBox( const PredefinedFiltersComboBox& other ) = delete;
80+
PredefinedFiltersComboBox( PredefinedFiltersComboBox&& other ) noexcept = delete;
81+
PredefinedFiltersComboBox& operator=( const PredefinedFiltersComboBox& other ) = delete;
82+
PredefinedFiltersComboBox& operator=( PredefinedFiltersComboBox&& other ) = delete;
83+
84+
void populatePredefinedFilters();
85+
86+
private:
87+
QWidget* crawlerWidget;
88+
PredefinedFiltersCollection filtersCollection;
89+
90+
QStandardItemModel* model;
91+
92+
void setup();
93+
94+
void setTitle( const QString& title );
95+
void insertFilters( const PredefinedFiltersCollection::Collection& filters );
96+
void connectFilters( const PredefinedFiltersCollection::Collection& filters );
97+
};
98+
99+
#endif
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Copyright (C) 2009, 2010, 2011, 2013, 2014, 2015 Nicolas Bonnefon
3+
* and other contributors
4+
*
5+
* This file is part of glogg.
6+
*
7+
* glogg is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* glogg is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with glogg. If not, see <http://www.gnu.org/licenses/>.
19+
*/
20+
21+
/*
22+
* Copyright (C) 2016 -- 2019 Anton Filimonov and other contributors
23+
*
24+
* This file is part of klogg.
25+
*
26+
* klogg is free software: you can redistribute it and/or modify
27+
* it under the terms of the GNU General Public License as published by
28+
* the Free Software Foundation, either version 3 of the License, or
29+
* (at your option) any later version.
30+
*
31+
* klogg is distributed in the hope that it will be useful,
32+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
33+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34+
* GNU General Public License for more details.
35+
*
36+
* You should have received a copy of the GNU General Public License
37+
* along with klogg. If not, see <http://www.gnu.org/licenses/>.
38+
*/
39+
40+
#ifndef PREDEFINEDFILTERSDIALOG_H_
41+
#define PREDEFINEDFILTERSDIALOG_H_
42+
43+
#include "predefinedfilters.h"
44+
#include "predefinedfiltersdialog.h"
45+
#include "ui_predefinedfiltersdialog.h"
46+
47+
#include <QDialog>
48+
49+
class PredefinedFiltersDialog : public QDialog, public Ui::PredefinedFiltersDialog {
50+
Q_OBJECT
51+
52+
public:
53+
explicit PredefinedFiltersDialog( QWidget* parent = nullptr );
54+
55+
private:
56+
PredefinedFiltersCollection::Collection filters;
57+
58+
void populateFiltersTable() const;
59+
void saveSettings();
60+
61+
private slots:
62+
void addFilter() const;
63+
void removeFilter() const;
64+
65+
void resolveStandardButton( QAbstractButton* button );
66+
67+
signals:
68+
void optionsChanged();
69+
};
70+
71+
#endif
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ui version="4.0">
3+
<class>PredefinedFiltersDialog</class>
4+
<widget class="QDialog" name="PredefinedFiltersDialog">
5+
<property name="geometry">
6+
<rect>
7+
<x>0</x>
8+
<y>0</y>
9+
<width>640</width>
10+
<height>480</height>
11+
</rect>
12+
</property>
13+
<property name="windowTitle">
14+
<string>Predefined Filters</string>
15+
</property>
16+
<layout class="QVBoxLayout" name="verticalLayout_2" stretch="0,0,0,0">
17+
<property name="sizeConstraint">
18+
<enum>QLayout::SetDefaultConstraint</enum>
19+
</property>
20+
<item>
21+
<widget class="QTableWidget" name="filtersTableWidget"/>
22+
</item>
23+
<item>
24+
<layout class="QHBoxLayout" name="horizontalLayout_5">
25+
<property name="bottomMargin">
26+
<number>0</number>
27+
</property>
28+
<item>
29+
<spacer name="horizontalSpacer">
30+
<property name="orientation">
31+
<enum>Qt::Horizontal</enum>
32+
</property>
33+
<property name="sizeHint" stdset="0">
34+
<size>
35+
<width>40</width>
36+
<height>20</height>
37+
</size>
38+
</property>
39+
</spacer>
40+
</item>
41+
<item>
42+
<widget class="QToolButton" name="addFilterButton">
43+
<property name="toolTip">
44+
<string>New Filter</string>
45+
</property>
46+
<property name="text">
47+
<string/>
48+
</property>
49+
<property name="icon">
50+
<iconset resource="../../app/klogg.qrc">
51+
<normaloff>:/images/icons8-plus-16.png</normaloff>:/images/icons8-plus-16.png
52+
</iconset>
53+
</property>
54+
</widget>
55+
</item>
56+
<item>
57+
<widget class="QToolButton" name="removeFilterButton">
58+
<property name="toolTip">
59+
<string>Remove Filter</string>
60+
</property>
61+
<property name="text">
62+
<string/>
63+
</property>
64+
<property name="icon">
65+
<iconset resource="../../app/klogg.qrc">
66+
<normaloff>:/images/icons8-minus-16.png</normaloff>:/images/icons8-minus-16.png
67+
</iconset>
68+
</property>
69+
</widget>
70+
</item>
71+
</layout>
72+
</item>
73+
<item>
74+
<widget class="QDialogButtonBox" name="buttonBox">
75+
<property name="orientation">
76+
<enum>Qt::Horizontal</enum>
77+
</property>
78+
<property name="standardButtons">
79+
<set>QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
80+
</property>
81+
</widget>
82+
</item>
83+
</layout>
84+
</widget>
85+
<resources>
86+
<include location="../../app/klogg.qrc"/>
87+
<include location="../../app/klogg.qrc"/>
88+
</resources>
89+
<connections/>
90+
</ui>

0 commit comments

Comments
 (0)