summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVyacheslav Matyushin <[email protected]>2015-08-20 16:56:55 +0300
committerVyacheslav Matyushin <[email protected]>2015-08-20 16:56:55 +0300
commitb0d8f144a62d70fa097a7ec58fd49edc94e65c41 (patch)
tree4d75b75706003a278947333c8b4b719192630183
parentb5e1cc96d494a845c4a25b6bfe40609df72e9382 (diff)
Implemented filtering by priority.
-rw-r--r--src/lib/globals.h18
-rw-r--r--src/lib/logViewFilterWidget.cpp75
-rw-r--r--src/lib/logViewFilterWidget.h12
3 files changed, 81 insertions, 24 deletions
diff --git a/src/lib/globals.h b/src/lib/globals.h
index 1fd2132..b712a99 100644
--- a/src/lib/globals.h
+++ b/src/lib/globals.h
@@ -49,15 +49,17 @@ public:
~Globals();
enum LogLevelIds {
- NONE_LOG_LEVEL_ID = 0,
- DEBUG_LOG_LEVEL_ID,
- INFORMATION_LOG_LEVEL_ID,
- NOTICE_LOG_LEVEL_ID,
- WARNING_LOG_LEVEL_ID,
- ERROR_LOG_LEVEL_ID,
- CRITICAL_LOG_LEVEL_ID,
+ EMERGENCY_LOG_LEVEL_ID = 0,
ALERT_LOG_LEVEL_ID,
- EMERGENCY_LOG_LEVEL_ID
+ CRITICAL_LOG_LEVEL_ID,
+ ERROR_LOG_LEVEL_ID,
+ WARNING_LOG_LEVEL_ID,
+ NOTICE_LOG_LEVEL_ID,
+ INFORMATION_LOG_LEVEL_ID,
+ DEBUG_LOG_LEVEL_ID,
+ NONE_LOG_LEVEL_ID,
+
+ LOG_LEVEL_NUM
};
Q_ENUM(LogLevelIds)
diff --git a/src/lib/logViewFilterWidget.cpp b/src/lib/logViewFilterWidget.cpp
index a5c71b0..b11d76b 100644
--- a/src/lib/logViewFilterWidget.cpp
+++ b/src/lib/logViewFilterWidget.cpp
@@ -20,6 +20,10 @@
***************************************************************************/
#include "logViewFilterWidget.h"
+#include "logViewWidget.h"
+#include "logViewColumn.h"
+#include "logging.h"
+#include "logLevel.h"
#include <QLabel>
#include <QPushButton>
@@ -35,12 +39,6 @@
#include <kiconloader.h>
#include <KLocalizedString>
-#include "logViewWidget.h"
-
-#include "logViewColumn.h"
-#include "logging.h"
-#include "logLevel.h"
-
class ComboBoxDelegate : public QStyledItemDelegate
{
public:
@@ -66,18 +64,33 @@ public:
*/
KComboBox *filterList;
- QComboBox *priorities;
+ QComboBox *prioritiesComboBox;
QStandardItemModel *prioritiesModel;
};
+class LogViewWidgetSearchLinePrivate
+{
+public:
+ bool priorities[Globals::LOG_LEVEL_NUM];
+
+ LogViewWidgetSearchLinePrivate()
+ {
+ // Show all priorities.
+ for (int i = 0; i < Globals::LOG_LEVEL_NUM; i++)
+ priorities[i] = true;
+ }
+};
+
LogViewWidgetSearchLine::LogViewWidgetSearchLine()
: KTreeWidgetSearchLine()
+ , d(new LogViewWidgetSearchLinePrivate())
{
}
LogViewWidgetSearchLine::~LogViewWidgetSearchLine()
{
+ delete d;
}
void LogViewWidgetSearchLine::updateSearch(const QString &pattern)
@@ -87,12 +100,30 @@ void LogViewWidgetSearchLine::updateSearch(const QString &pattern)
emit treeWidgetUpdated();
}
+void LogViewWidgetSearchLine::setPriorityEnabled(int priority, bool enabled)
+{
+ if ((priority < 0) || (priority > Globals::LOG_LEVEL_NUM))
+ return;
+ d->priorities[priority] = enabled;
+ updateSearch(QString());
+}
+
+bool LogViewWidgetSearchLine::itemMatches(const QTreeWidgetItem *item, const QString &pattern) const
+{
+ // Hide item if its priority is not enabled.
+ int priority = item->data(0, Qt::UserRole).toInt();
+ if ((priority >= 0) && (priority < Globals::LOG_LEVEL_NUM)) {
+ if (!d->priorities[priority])
+ return false;
+ }
+ return KTreeWidgetSearchLine::itemMatches(item, pattern);
+}
+
LogViewFilterWidget::LogViewFilterWidget()
: d(new LogViewFilterWidgetPrivate())
{
QHBoxLayout *filterBarLayout = new QHBoxLayout();
filterBarLayout->setMargin(0);
- // filterBarLayout->setSpacing(-1);
setLayout(filterBarLayout);
d->filterLine = new LogViewWidgetSearchLine();
@@ -116,21 +147,24 @@ LogViewFilterWidget::LogViewFilterWidget()
filterBarLayout->addWidget(d->filterList);
- d->priorities = new QComboBox(this);
- ComboBoxDelegate *delegate = new ComboBoxDelegate(d->priorities);
- d->priorities->setItemDelegate(delegate);
- filterBarLayout->addWidget(d->priorities);
+ d->prioritiesComboBox = new QComboBox(this);
+ ComboBoxDelegate *delegate = new ComboBoxDelegate(d->prioritiesComboBox);
+ d->prioritiesComboBox->setItemDelegate(delegate);
+ filterBarLayout->addWidget(d->prioritiesComboBox);
QMetaEnum &metaEnum = Globals::instance().logLevelsMetaEnum();
- d->prioritiesModel = new QStandardItemModel(d->priorities);
- d->priorities->setModel(d->prioritiesModel);
+ d->prioritiesModel = new QStandardItemModel(d->prioritiesComboBox);
+ d->prioritiesComboBox->setModel(d->prioritiesModel);
QStandardItem *item = new QStandardItem(i18n("Select priorities"));
item->setSelectable(false);
d->prioritiesModel->appendRow(item);
+ connect(d->prioritiesModel, SIGNAL(itemChanged(QStandardItem *)),
+ SLOT(prioritiesChanged(QStandardItem *)));
- for (int i = metaEnum.keyCount() - 1; i >= 0; i--) {
+ // Don't add last enum value into combobox.
+ for (int i = 0; i < metaEnum.keyCount() - 1; i++) {
int id = metaEnum.value(i);
LogLevel *logLevel = Globals::instance().logLevelByPriority(id);
@@ -205,6 +239,17 @@ void LogViewFilterWidget::changeColumnFilter(int column)
d->filterLine->setSearchColumns(filterColumns);
}
+void LogViewFilterWidget::prioritiesChanged(QStandardItem *item)
+{
+ int priority = item->data(Qt::UserRole).toInt();
+ bool priorityEnabled = (item->checkState() == Qt::Checked);
+ d->filterLine->setPriorityEnabled(priority, priorityEnabled);
+ if (priorityEnabled)
+ logDebug() << "Show entries with priority" << priority;
+ else
+ logDebug() << "Hide entries with priority" << priority;
+}
+
KComboBox *LogViewFilterWidget::filterList()
{
return d->filterList;
diff --git a/src/lib/logViewFilterWidget.h b/src/lib/logViewFilterWidget.h
index d9a3ad3..048cb28 100644
--- a/src/lib/logViewFilterWidget.h
+++ b/src/lib/logViewFilterWidget.h
@@ -23,6 +23,7 @@
#define LOG_VIEW_FILTER_WIDGET_H
#include <QWidget>
+#include <QStandardItem>
#include <ktreewidgetsearchline.h>
@@ -32,6 +33,7 @@ class LogViewWidget;
class LogViewWidgetSearchLine;
class KComboBox;
+class LogViewWidgetSearchLinePrivate;
class LogViewFilterWidgetPrivate;
class LogViewFilterWidget : public QWidget
@@ -51,6 +53,7 @@ public slots:
private slots:
void changeColumnFilter(int column);
+ void prioritiesChanged(QStandardItem *item);
signals:
void treeWidgetUpdated();
@@ -70,15 +73,22 @@ public:
~LogViewWidgetSearchLine();
-public:
// Silence compiler warning
using KTreeWidgetSearchLine::updateSearch;
// Reimplemented just to send a signal _AFTER_ the tree updating
void updateSearch(const QString &pattern = QString());
+ void setPriorityEnabled(int priority, bool enabled);
+
+protected:
+ virtual bool itemMatches(const QTreeWidgetItem *item, const QString &pattern) const;
+
signals:
void treeWidgetUpdated();
+
+private:
+ LogViewWidgetSearchLinePrivate *const d;
};
#endif // LOG_VIEW_FILTER_WIDGET_H