]> vaikene.ee Git - evaf/blob - src/plugins/LogView/logview.h
Implemented the LogView module that shows messages output using the Common::iLogger...
[evaf] / src / plugins / LogView / logview.h
1 /**
2 * @file LogView/logview.h
3 * @brief Implementation of the LogView module
4 * @author Enar Vaikene
5 *
6 * Copyright (c) 2011 Enar Vaikene
7 *
8 * This file is part of the eVaf C++ cross-platform application development framework.
9 *
10 * This file can be used under the terms of the GNU General Public License
11 * version 3.0 as published by the Free Software Foundation and appearing in
12 * the file LICENSE included in the packaging of this file. Please review the
13 * the following information to ensure the GNU General Public License version
14 * 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
15 *
16 * Alternatively, this file may be used in accordance with the Commercial License
17 * Agreement provided with the Software.
18 */
19
20 #ifndef __LOGVIEW_LOGVIEW_H
21 # define __LOGVIEW_LOGVIEW_H
22
23 #include <Plugins/iPlugin>
24 #include <Common/iLogger>
25
26 #include <QObject>
27 #include <QString>
28 #include <QWidget>
29 #include <QAbstractListModel>
30 #include <QQueue>
31 #include <QDateTime>
32
33 class QListView;
34 class QLabel;
35 class QTabWidget;
36 class QStatusBar;
37 class QEvent;
38
39 namespace eVaf {
40
41 /**
42 * Module for showing messages output with the eVaf::Common::iLogger interface.
43 *
44 * The LogView module implements a widget that shows all the messages output with the
45 * eVaf::Common::iLogger interface.
46 */
47 namespace LogView {
48
49 /**
50 * Internal implementation of the LogView module.
51 */
52 namespace Internal {
53
54 /**
55 * Data model for the log view widget
56 */
57 class Model : public QAbstractListModel
58 {
59 Q_OBJECT
60
61 public:
62
63 /// One logger message
64 struct Message
65 {
66 Message(Common::iLogger::Severity s, QString const & t, QString const & w)
67 : dt(QDateTime::currentDateTime())
68 , severity(s)
69 , text(t)
70 , simplified(t.simplified())
71 , where(w)
72 {}
73
74 QDateTime dt;
75 Common::iLogger::Severity severity;
76 QString text;
77 QString simplified;
78 QString where;
79 };
80
81 Model(QObject * parent = 0);
82
83 Message const & messageAt(int idx) const { return mData.at(idx); }
84
85 virtual int rowCount(QModelIndex const & parent = QModelIndex()) const { return mData.size(); }
86
87 virtual QVariant data(QModelIndex const & index, int role = Qt::DisplayRole) const;
88
89 void addMessage(Common::iLogger::Severity severity, QString const & text, QString const & where);
90
91 QString details(QModelIndex const & index) const;
92
93 bool saveToFile(QString const & fileName);
94
95 bool copyToClipboard(QModelIndex const & index);
96
97 QString errorString() const { return mErrorString; }
98
99
100 signals:
101
102 void messageAdded(QModelIndex const & index);
103
104
105 private: // Members
106
107 /// Maximum number of lines in the queue
108 static int const MaxLines;
109
110 /// Human-readable texts for message severity levels
111 static char const * const SeverityText[Common::iLogger::Count];
112
113 /// Currently shown messages
114 QQueue<Message> mData;
115
116 /// Human-readable error string if the last operation failed
117 QString mErrorString;
118
119
120 private: // Methods
121
122 inline char const * const severityText(Common::iLogger::Severity s) const;
123
124 };
125
126 /**
127 * The log view widget
128 *
129 * The Widget class implements a widget that shows messages from one logger source.
130 */
131 class Widget : public QWidget
132 {
133 Q_OBJECT
134
135 public:
136
137 Widget(QString const & source, QWidget * parent = 0);
138
139 QString const & source() const { return mSource; }
140
141 inline void addMessage(Common::iLogger::Severity severity, QString const & text, QString const & where)
142 {
143 mModel->addMessage(severity, text, where);
144 }
145
146
147 private slots:
148
149 void messageAdded(QModelIndex const & index);
150
151 void currentChanged(QModelIndex const &, QModelIndex const &);
152
153 void copyToClipboard();
154
155 void saveToFile();
156
157
158 private:
159
160 QString mSource;
161
162 Model * mModel;
163
164 bool mAutoScroll;
165
166 QListView * wList;
167 QLabel * wDetails;
168
169 };
170
171 /**
172 * The log view window
173 */
174 class Window : public QWidget
175 {
176 Q_OBJECT
177
178 public:
179
180 Window(QWidget * parent = 0, Qt::WindowFlags flags = 0);
181
182 virtual ~Window();
183
184 virtual bool event(QEvent * e);
185
186
187 public slots:
188
189 void loggerEvent(Common::iLogger::Severity severity, QString const & text, QString const & source, QString const & where);
190
191
192 private: // Methods
193
194 void saveSettings();
195
196 void restoreSettings();
197
198
199 private: // Members
200
201 QString mDefSource;
202 QTabWidget * wTabs;
203 QHash<QString, Widget *> mLogViews;
204 QStatusBar * wStatusBar;
205
206 };
207
208 /**
209 * LogView module's implementation
210 */
211 class Module : public Plugins::iPlugin
212 {
213 Q_OBJECT
214 Q_INTERFACES(eVaf::Plugins::iPlugin)
215
216 public:
217
218 Module();
219
220 virtual ~Module();
221
222 virtual bool init(QString const & args);
223
224 virtual void done();
225
226 virtual bool isReady() const { return wWindow != 0; }
227
228 private: // Members
229
230 Window * wWindow;
231
232 };
233
234 } // namespace eVaf::LogView::Internal
235 } // namespace eVaf::LogView
236 } // namespace eVaf
237
238 #endif // logview.h