]>
vaikene.ee Git - evaf/blob - src/plugins/LogView/logview.h
1bfe6a8228b62c30943efa09787ee95fd3ecfa25
2 * @file LogView/logview.h
3 * @brief Implementation of the LogView module
6 * Copyright (c) 2011 Enar Vaikene
8 * This file is part of the eVaf C++ cross-platform application development framework.
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.
16 * Alternatively, this file may be used in accordance with the Commercial License
17 * Agreement provided with the Software.
20 #ifndef __LOGVIEW_LOGVIEW_H
21 # define __LOGVIEW_LOGVIEW_H
23 #include <Plugins/iPlugin>
24 #include <Common/iLogger>
29 #include <QAbstractListModel>
42 * Module for showing messages output with the eVaf::Common::iLogger interface.
44 * The LogView module implements a widget that shows all the messages output with the
45 * eVaf::Common::iLogger interface.
50 * Internal implementation of the LogView module.
55 * Data model for the log view widget
57 class Model
: public QAbstractListModel
63 /// One logger message
66 Message(Common::iLogger::Severity s
, QString
const & t
, QString
const & w
)
67 : dt(QDateTime::currentDateTime())
70 , simplified(t
.simplified())
75 Common::iLogger::Severity severity
;
81 Model(QObject
* parent
= 0);
83 Message
const & messageAt(int idx
) const { return mData
.at(idx
); }
85 virtual int rowCount(QModelIndex
const & parent
= QModelIndex()) const { return mData
.size(); }
87 virtual QVariant
data(QModelIndex
const & index
, int role
= Qt::DisplayRole
) const;
89 void addMessage(Common::iLogger::Severity severity
, QString
const & text
, QString
const & where
);
91 QString
details(QModelIndex
const & index
) const;
93 bool saveToFile(QString
const & fileName
);
95 bool copyToClipboard(QModelIndex
const & index
);
97 QString
errorString() const { return mErrorString
; }
102 void messageAdded(QModelIndex
const & index
);
107 /// Maximum number of lines in the queue
108 static int const MaxLines
;
110 /// Human-readable texts for message severity levels
111 static char const * const SeverityText
[Common::iLogger::Count
];
113 /// Currently shown messages
114 QQueue
<Message
> mData
;
116 /// Human-readable error string if the last operation failed
117 QString mErrorString
;
122 inline char const * const severityText(Common::iLogger::Severity s
) const;
127 * The log view widget
129 * The Widget class implements a widget that shows messages from one logger source.
131 class Widget
: public QWidget
137 Widget(QString
const & source
, QWidget
* parent
= 0);
139 QString
const & source() const { return mSource
; }
141 inline void addMessage(Common::iLogger::Severity severity
, QString
const & text
, QString
const & where
)
143 mModel
->addMessage(severity
, text
, where
);
149 void messageAdded(QModelIndex
const & index
);
151 void currentChanged(QModelIndex
const &, QModelIndex
const &);
153 void copyToClipboard();
172 * The log view window
174 class Window
: public QWidget
180 Window(QWidget
* parent
= 0, Qt::WindowFlags flags
= 0);
184 virtual bool event(QEvent
* e
);
189 void loggerEvent(Common::iLogger::Severity severity
, QString
const & text
, QString
const & source
, QString
const & where
);
196 void restoreSettings();
203 QHash
<QString
, Widget
*> mLogViews
;
204 QStatusBar
* wStatusBar
;
209 * LogView module's implementation
211 class Module
: public Plugins::iPlugin
214 Q_INTERFACES(eVaf::Plugins::iPlugin
)
222 virtual bool init(QString
const & args
);
226 virtual bool isReady() const { return wWindow
!= 0; }
234 } // namespace eVaf::LogView::Internal
235 } // namespace eVaf::LogView