• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdesdk API Reference
  • KDE Home
  • Contact Us
 

okteta

  • sources
  • kde-4.12
  • kdesdk
  • okteta
  • kasten
  • controllers
  • view
  • structures
  • script
scriptlogger.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of the Okteta Kasten Framework, made within the KDE community.
3  *
4  * Copyright 2010, 2011, 2012 Alex Richardson <alex.richardson@gmx.de>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) version 3, or any
10  * later version accepted by the membership of KDE e.V. (or its
11  * successor approved by the membership of KDE e.V.), which shall
12  * act as a proxy defined in Section 6 of version 3 of the license.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
23 #include "scriptlogger.h"
24 #include "../datatypes/datainformation.h"
25 
26 #include <KIcon>
27 #include <KLocalizedString>
28 
29 KIcon ScriptLogger::iconForLevel(ScriptLogger::LogLevel level)
30 {
31  if (level == LogInfo)
32  return KIcon(QLatin1String("dialog-information"));
33  else if (level == LogWarning)
34  return KIcon(QLatin1String("dialog-warning"));
35  else
36  return KIcon(QLatin1String("dialog-error"));
37  return KIcon();
38 }
39 
40 QVariant ScriptLogger::data(const QModelIndex& index, int role) const
41 {
42  if (!index.isValid())
43  return QVariant();
44  int row = index.row();
45  Q_ASSERT(row < mData.size());
46  Q_ASSERT(!index.parent().isValid());
47  if (role == Qt::DisplayRole)
48  {
49  const Data& data = mData.at(row);
50  switch (index.column())
51  {
52  case ColumnTime:
53  return data.time.toString(QLatin1String("hh:mm:ss.zzz"));
54  case ColumnOrigin:
55  return data.origin;
56  case ColumnMessage:
57  return data.message;
58  default:
59  return QVariant();
60  }
61  }
62  if (role == Qt::DecorationRole && index.column() == ColumnTime)
63  return iconForLevel(mData.at(row).level);
64  return QVariant();
65 }
66 
67 int ScriptLogger::rowCount(const QModelIndex& parent) const
68 {
69  if (parent.isValid())
70  return 0;
71  return mData.size();
72 }
73 
74 int ScriptLogger::columnCount(const QModelIndex& parent) const
75 {
76  Q_UNUSED(parent)
77  return COLUMN_COUNT;
78 }
79 
80 QVariant ScriptLogger::headerData(int section, Qt::Orientation orientation, int role) const
81 {
82  if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
83  {
84  switch (section)
85  {
86  case ColumnTime:
87  return i18nc("@title:column", "Time");
88  case ColumnOrigin:
89  return i18nc("@title:column", "Origin");
90  case ColumnMessage:
91  return i18nc("@title:column", "Message");
92  default:
93  return QVariant();
94  }
95  }
96  return QVariant();
97 }
98 
99 QDebug ScriptLogger::log(LogLevel level, const DataInformation* origin)
100 {
101  Q_CHECK_PTR(origin);
102  if (origin->loggedData() < level)
103  origin->setLoggedData(level);
104  return log(level, origin->fullObjectPath());
105 }
106 
107 QDebug ScriptLogger::log(LogLevel level, const QString& origin)
108 {
109  Q_ASSERT(level != LogInvalid);
110  if (mLogToStdOut)
111  return (level == LogInvalid || level == LogInfo) ? qDebug() : qWarning();
112 
113  beginInsertRows(QModelIndex(), mData.size(), mData.size());
114  mData.append(Data(level, origin));
115  endInsertRows();
116  return QDebug(&mData.last().message);
117 }
118 
119 void ScriptLogger::clear()
120 {
121  beginRemoveRows(QModelIndex(), 0, qMax(0, mData.size() - 1));
122  mData.clear();
123  endRemoveRows();
124 }
125 
126 ScriptLogger::ScriptLogger()
127  : mLogToStdOut(false)
128 {
129 }
130 
131 ScriptLogger::~ScriptLogger()
132 {
133 }
134 
135 QStringList ScriptLogger::messages(LogLevel minLevel) const
136 {
137  QStringList ret;
138  for (int i = 0; i < mData.size(); ++i)
139  {
140  const Data& d = mData.at(i);
141  if (d.level >= minLevel)
142  ret << d.message;
143  }
144  return ret;
145 }
DataInformation
Interface that must be implemented by all datatypes.
Definition: datainformation.h:67
DataInformation::fullObjectPath
QString fullObjectPath() const
Definition: datainformation.cpp:258
ScriptLogger::Data::message
QString message
Definition: scriptlogger.h:57
ScriptLogger::LogWarning
Definition: scriptlogger.h:47
ScriptLogger::COLUMN_COUNT
Definition: scriptlogger.h:43
ScriptLogger::rowCount
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
Definition: scriptlogger.cpp:67
ScriptLogger::ColumnMessage
Definition: scriptlogger.h:43
ScriptLogger::LogLevel
LogLevel
Definition: scriptlogger.h:46
ScriptLogger::iconForLevel
static KIcon iconForLevel(LogLevel level)
Definition: scriptlogger.cpp:29
ScriptLogger::columnCount
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const
Definition: scriptlogger.cpp:74
ScriptLogger::Data::level
ScriptLogger::LogLevel level
Definition: scriptlogger.h:56
ScriptLogger::ScriptLogger
ScriptLogger()
Definition: scriptlogger.cpp:126
ScriptLogger::messages
QStringList messages(LogLevel minLevel=LogInfo) const
Definition: scriptlogger.cpp:135
ScriptLogger::log
QDebug log(LogLevel level, const DataInformation *origin)
Definition: scriptlogger.cpp:99
ScriptLogger::LogInvalid
Definition: scriptlogger.h:47
ScriptLogger::~ScriptLogger
virtual ~ScriptLogger()
Definition: scriptlogger.cpp:131
scriptlogger.h
ScriptLogger::ColumnTime
Definition: scriptlogger.h:43
ScriptLogger::Data
Definition: scriptlogger.h:49
ScriptLogger::ColumnOrigin
Definition: scriptlogger.h:43
DataInformation::loggedData
ScriptLogger::LogLevel loggedData() const
whether data was logged from here (and which level it was)
Definition: datainformation.h:329
ScriptLogger::LogInfo
Definition: scriptlogger.h:47
ScriptLogger::Data::origin
QString origin
Definition: scriptlogger.h:58
ScriptLogger::clear
void clear()
Definition: scriptlogger.cpp:119
DataInformation::setLoggedData
void setLoggedData(ScriptLogger::LogLevel lvl) const
Definition: datainformation.h:334
ScriptLogger::data
virtual QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
Definition: scriptlogger.cpp:40
ScriptLogger::Data::time
QTime time
Definition: scriptlogger.h:59
ScriptLogger::headerData
virtual QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
Definition: scriptlogger.cpp:80
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:04:09 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

okteta

Skip menu "okteta"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdesdk API Reference

Skip menu "kdesdk API Reference"
  • kapptemplate
  • kcachegrind
  • kompare
  • lokalize
  • okteta
  • umbrello
  •   umbrello

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal