eVaf
logview.h
Go to the documentation of this file.
1 
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 
48 namespace LogView {
49 
53 namespace Internal {
54 
58 class Model : public QAbstractListModel
59 {
60  Q_OBJECT
61 
62 public:
63 
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;
77  QString text;
78  QString simplified;
79  QString where;
80  };
81 
82  Model(QObject * parent = 0);
83 
84  Message const & messageAt(int idx) const { return mData.at(idx); }
85 
86  virtual int rowCount(QModelIndex const & parent = 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 
109  static int const MaxLines;
110 
112  static char const * const SeverityText[Common::iLogger::Count];
113 
115  QQueue<Message> mData;
116 
118  QString mErrorString;
119 
120 
121 private: // Methods
122 
123  inline char const * const severityText(Common::iLogger::Severity s) const;
124 
125 };
126 
132 class Widget : public QWidget
133 {
134  Q_OBJECT
135 
136 public:
137 
138  Widget(QString const & source, QWidget * parent = 0);
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 
175 class Window : public Gui::Panel
176 {
177  Q_OBJECT
178 
179 public:
180 
181  Window(QString const & args, QWidget * parent = 0, Qt::WindowFlags flags = 0);
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 
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 != 0; }
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
The log view window.
Definition: logview.h:175
Common::iLogger::Severity severity
Definition: logview.h:76
void addMessage(Common::iLogger::Severity severity, QString const &text, QString const &where)
Definition: logview.h:142
eVaf GUI panel class.
Definition: panel.h:49
QString details(QModelIndex const &index) const
The log view widget.
Definition: logview.h:132
virtual QVariant data(QModelIndex const &index, int role=Qt::DisplayRole) const
QString errorString() const
Definition: logview.h:98
bool COMMON_EXPORT init()
eVaf common library initialized
LogView module&#39;s implementation.
Definition: logview.h:214
Data model for the log view widget.
Definition: logview.h:58
virtual int rowCount(QModelIndex const &parent=QModelIndex()) const
Definition: logview.h:86
Message const & messageAt(int idx) const
Definition: logview.h:84
void messageAdded(QModelIndex const &index)
Global eVaf namespace.
Definition: engine.h:37
Common interface for all the eVaf modules.
Definition: iplugin.h:38
Message(Common::iLogger::Severity s, QString const &t, QString const &w)
Definition: logview.h:67
QString const & source() const
Definition: logview.h:140
Number of severity levels.
Definition: ilogger.h:66
bool saveToFile(QString const &fileName)
void addMessage(Common::iLogger::Severity severity, QString const &text, QString const &where)
bool copyToClipboard(QModelIndex const &index)
Severity
Severity levels for messages indicating the meaning and seriousness of the message.
Definition: ilogger.h:59