tuchulcha  0.10.1
Graphical Workflow Configuration Editor
LogViewProxyModel.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2013 Jens-Malte Gottfried
2 
3  This file is part of Tuchulcha.
4 
5  Tuchulcha is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  Tuchulcha is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with Tuchulcha. If not, see <http://www.gnu.org/licenses/>.
17  */
25 #include "LogViewProxyModel.h"
26 
27 #include <QBrush>
28 #include <QColor>
29 
31  QSortFilterProxyModel(pp) {
32 }
33 
34 LogViewProxyModel::~LogViewProxyModel() {
35 }
36 
37 QVariant LogViewProxyModel::data(const QModelIndex& idx, int rr) const {
38  QRegExp logLevel("\\((\\w+)\\).*");
39  switch(rr) {
40  case Qt::UserRole:
41  if (logLevel.exactMatch(
42  QSortFilterProxyModel::data(idx,Qt::DisplayRole).toString())) {
43  QString level = logLevel.cap(1);
44  if (level == "DD") {
45  return QString("debug");
46  }
47  else if (level == "II") {
48  return QString("info");
49  }
50  else if (level == "WW") {
51  return QString("warning");
52  }
53  else if (level == "EE") {
54  return QString("error");
55  }
56  else {
57  return QString("normal");
58  }
59  }
60  break;
61  case Qt::ForegroundRole:
62  if (logLevel.exactMatch(
63  QSortFilterProxyModel::data(idx,Qt::DisplayRole).toString())) {
64  QString level = logLevel.cap(1);
65  if (level == "DD") {
66  return QBrush(QColor("#AAA")); // light gray
67  }
68  else if (level == "II") {
69  return QBrush(QColor("#777")); // very dark gray
70  }
71  else if (level == "WW") {
72  return QBrush(QColor("#F70")); // orange
73  }
74  }
75  break;
76  case Qt::BackgroundRole:
77  if (logLevel.exactMatch(
78  QSortFilterProxyModel::data(idx,Qt::DisplayRole).toString())) {
79  QString level = logLevel.cap(1);
80  if (level == "EE") {
81  return QBrush(QColor("#F87")); // lighter red
82  }
83  }
84  break;
85  default:
86  break;
87  }
88 
89  return QSortFilterProxyModel::data(idx,rr);
90 }
91 
93  return QRegExp("^\\((?!DD)|^(?!\\()");
94 }
Declaration of class LogViewProxyModel.
static QRegExp debugFilterRegex()
regexp for filtering out debug lines
LogViewProxyModel(QObject *parent=0)
constructor
virtual QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
handle highlighting