]> vaikene.ee Git - evaf/blob - src/plugins/LogView/logview.h
Warning fixes and copyright update.
[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-2019 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 #include <Gui/Panel>
26
27 #include <QObject>
28 #include <QString>
29 #include <QWidget>
30 #include <QAbstractListModel>
31 #include <QQueue>
32 #include <QDateTime>
33
34 class QListView;
35 class QLabel;
36 class QTabWidget;
37 class QStatusBar;
38 class QEvent;
39
40 namespace eVaf {
41
42 /**
43 * Module for showing messages output with the eVaf::Common::iLogger interface.
44 *
45 * The LogView module implements a widget that shows all the messages output with the
46 * eVaf::Common::iLogger interface.
47 */
48 namespace LogView {
49
50 /**
51 * Internal implementation of the LogView module.
52 */
53 namespace Internal {
54
55 /**
56 * Data model for the log view widget
57 */
58 class Model : public QAbstractListModel
59 {
60 Q_OBJECT
61
62 public:
63
64 /// One logger message
65 struct Message
66 {
67 Message(Common::iLogger::Severity s, QString const & t, QString const & w)
68 : dt(QDateTime::currentDateTime())
69 , severity(s)
70 , text(t)
71 , simplified(t.simplified())
72 , where(w)
73 {}
74
75 QDateTime dt;
76 Common::iLogger::Severity severity;
77 QString text;
78 QString simplified;
79 QString where;
80 };
81
82 Model(QObject * parent = nullptr);
83
84 Message const & messageAt(int idx) const { return mData.at(idx); }
85
86 virtual int rowCount(QModelIndex const & = QModelIndex()) const { return mData.size(); }
87
88 virtual QVariant data(QModelIndex const & index, int role = Qt::DisplayRole) const;
89
90 void addMessage(Common::iLogger::Severity severity, QString const & text, QString const & where);
91
92 QString details(QModelIndex const & index) const;
93
94 bool saveToFile(QString const & fileName);
95
96 bool copyToClipboard(QModelIndex const & index);
97
98 QString errorString() const { return mErrorString; }
99
100
101 signals:
102
103 void messageAdded(QModelIndex const & index);
104
105
106 private: // Members
107
108 /// Maximum number of lines in the queue
109 static int const MaxLines;
110
111 /// Human-readable texts for message severity levels
112 static char const * const SeverityText[Common::iLogger::Count];
113
114 /// Currently shown messages
115 QQueue<Message> mData;
116
117 /// Human-readable error string if the last operation failed
118 QString mErrorString;
119
120
121 private: // Methods
122
123 inline char const * severityText(Common::iLogger::Severity s) const;
124
125 };
126
127 /**
128 * The log view widget
129 *
130 * The Widget class implements a widget that shows messages from one logger source.
131 */
132 class Widget : public QWidget
133 {
134 Q_OBJECT
135
136 public:
137
138 Widget(QString const & source, QWidget * parent = nullptr);
139
140 QString const & source() const { return mSource; }
141
142 inline void addMessage(Common::iLogger::Severity severity, QString const & text, QString const & where)
143 {
144 mModel->addMessage(severity, text, where);
145 }
146
147
148 private slots:
149
150 void messageAdded(QModelIndex const & index);
151
152 void currentChanged(QModelIndex const &, QModelIndex const &);
153
154 void copyToClipboard();
155
156 void saveToFile();
157
158
159 private:
160
161 QString mSource;
162
163 Model * mModel;
164
165 bool mAutoScroll;
166
167 QListView * wList;
168 QLabel * wDetails;
169
170 };
171
172 /**
173 * The log view window
174 */
175 class Window : public Gui::Panel
176 {
177 Q_OBJECT
178
179 public:
180
181 Window(QString const & args, QWidget * parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags());
182
183 virtual ~Window();
184
185 virtual bool event(QEvent * e);
186
187
188 public slots:
189
190 void loggerEvent(Common::iLogger::Severity severity, QString const & text, QString const & source, QString const & where);
191
192
193 private: // Methods
194
195 void saveSettings();
196
197 void restoreSettings();
198
199 QString getPanelName(QString const & args) const;
200
201
202 private: // Members
203
204 QString mDefSource;
205 QTabWidget * wTabs;
206 QHash<QString, Widget *> mLogViews;
207 QStatusBar * wStatusBar;
208
209 };
210
211 /**
212 * LogView module's implementation
213 */
214 class Module : public Plugins::iPlugin
215 {
216 Q_OBJECT
217 Q_INTERFACES(eVaf::Plugins::iPlugin)
218
219 public:
220
221 Module();
222
223 virtual ~Module();
224
225 virtual bool init(QString const & args);
226
227 virtual void done();
228
229 virtual bool isReady() const { return wWindow != nullptr; }
230
231 private: // Members
232
233 Window * wWindow;
234
235 };
236
237 } // namespace eVaf::LogView::Internal
238 } // namespace eVaf::LogView
239 } // namespace eVaf
240
241 #endif // logview.h