]> vaikene.ee Git - evaf/blob - src/plugins/LogView/logview.h
383588de454272efb192c1c019531688143004c6
[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
34 namespace eVaf {
35
36 /**
37 * Module for showing messages output with the eVaf::Common::iLogger interface.
38 *
39 * The LogView module implements a widget that shows all the messages output with the
40 * eVaf::Common::iLogger interface.
41 */
42 namespace LogView {
43
44 /**
45 * Internal implementation of the LogView module.
46 */
47 namespace Internal {
48
49 /**
50 * Data model for the log view widget
51 */
52 class Model : public QAbstractListModel
53 {
54 Q_OBJECT
55
56 public:
57
58 /// One logger message
59 struct Message
60 {
61 Message(Common::iLogger::Severity s, QString const & t, QString const & w)
62 : dt(QDateTime::currentDateTime())
63 , severity(s)
64 , text(t)
65 , where(w)
66 {}
67
68 QDateTime dt;
69 Common::iLogger::Severity severity;
70 QString text;
71 QString where;
72 };
73
74 Model(QObject * parent = 0);
75
76 Message const & messageAt(int idx) const { return mData.at(idx); }
77
78 virtual int rowCount(QModelIndex const & parent = QModelIndex()) const { return mData.size(); }
79
80 virtual QVariant data(QModelIndex const & index, int role = Qt::DisplayRole) const;
81
82 void addMessage(Common::iLogger::Severity severity, QString const & text, QString const & where);
83
84 QString details(QModelIndex const & index) const;
85
86 bool saveToFile(QString const & fileName);
87
88 bool copyToClipboard(QModelIndex const & index);
89
90 QString errorString() const { return mErrorString; }
91
92
93 signals:
94
95 void messageAdded(QModelIndex const & index);
96
97
98 private: // Members
99
100 /// Maximum number of lines in the queue
101 static int const MaxLines;
102
103 /// Human-readable texts for message severity levels
104 static char const * const SeverityText[Common::iLogger::Count];
105
106 /// Currently shown messages
107 QQueue<Message> mData;
108
109 /// Human-readable error string if the last operation failed
110 QString mErrorString;
111
112
113 private: // Methods
114
115 inline char const * const severityText(Common::iLogger::Severity s) const;
116
117 };
118
119 /**
120 * The log view widget
121 */
122 class Widget : public QWidget
123 {
124 Q_OBJECT
125
126 public:
127
128 Widget(QWidget * parent = 0, Qt::WindowFlags flags = 0);
129
130 virtual ~Widget();
131
132
133 private: // Methods
134
135 void saveSettings();
136
137 void restoreSettings();
138
139 };
140
141 /**
142 * LogView module's implementation
143 */
144 class Module : public Plugins::iPlugin
145 {
146 Q_OBJECT
147 Q_INTERFACES(eVaf::Plugins::iPlugin)
148
149 public:
150
151 Module();
152
153 virtual ~Module();
154
155 virtual bool init(QString const & args);
156
157 virtual void done();
158
159 virtual bool isReady() const { return wWidget != 0; }
160
161 private: // Members
162
163 Widget * wWidget;
164
165 };
166
167 } // namespace eVaf::LogView::Internal
168 } // namespace eVaf::LogView
169 } // namespace eVaf
170
171 #endif // logview.h