]>
vaikene.ee Git - evaf/blob - LogView/logview.h
2 * @file LogView/logview.h
3 * @brief Implementation of the LogView module
6 * Copyright (c) 2011-2019 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>
30 #include <QAbstractListModel>
43 * Module for showing messages output with the eVaf::Common::iLogger interface.
45 * The LogView module implements a widget that shows all the messages output with the
46 * eVaf::Common::iLogger interface.
51 * Internal implementation of the LogView module.
56 * Data model for the log view widget
58 class Model
: public QAbstractListModel
64 /// One logger message
67 Message(Common::iLogger::Severity s
, QString
const & t
, QString
const & w
)
68 : dt(QDateTime::currentDateTime())
71 , simplified(t
.simplified())
76 Common::iLogger::Severity severity
;
82 Model(QObject
* parent
= nullptr);
84 Message
const & messageAt(int idx
) const { return mData
.at(idx
); }
86 virtual int rowCount(QModelIndex
const & = QModelIndex()) const { return mData
.size(); }
88 virtual QVariant
data(QModelIndex
const & index
, int role
= Qt::DisplayRole
) const;
90 void addMessage(Common::iLogger::Severity severity
, QString
const & text
, QString
const & where
);
92 QString
details(QModelIndex
const & index
) const;
94 bool saveToFile(QString
const & fileName
);
96 bool copyToClipboard(QModelIndex
const & index
);
98 QString
errorString() const { return mErrorString
; }
103 void messageAdded(QModelIndex
const & index
);
108 /// Maximum number of lines in the queue
109 static int const MaxLines
;
111 /// Human-readable texts for message severity levels
112 static char const * const SeverityText
[Common::iLogger::Count
];
114 /// Currently shown messages
115 QQueue
<Message
> mData
;
117 /// Human-readable error string if the last operation failed
118 QString mErrorString
;
123 inline char const * severityText(Common::iLogger::Severity s
) const;
128 * The log view widget
130 * The Widget class implements a widget that shows messages from one logger source.
132 class Widget
: public QWidget
138 Widget(QString
const & source
, QWidget
* parent
= nullptr);
140 QString
const & source() const { return mSource
; }
142 inline void addMessage(Common::iLogger::Severity severity
, QString
const & text
, QString
const & where
)
144 mModel
->addMessage(severity
, text
, where
);
150 void messageAdded(QModelIndex
const & index
);
152 void currentChanged(QModelIndex
const &, QModelIndex
const &);
154 void copyToClipboard();
173 * The log view window
175 class Window
: public Gui::Panel
181 Window(QString
const & args
, QWidget
* parent
= nullptr, Qt::WindowFlags flags
= Qt::WindowFlags());
185 virtual bool event(QEvent
* e
);
190 void loggerEvent(Common::iLogger::Severity severity
, QString
const & text
, QString
const & source
, QString
const & where
);
197 void restoreSettings();
199 QString
getPanelName(QString
const & args
) const;
206 QHash
<QString
, Widget
*> mLogViews
;
207 QStatusBar
* wStatusBar
;
212 * LogView module's implementation
214 class Module
: public Plugins::iPlugin
217 Q_INTERFACES(eVaf::Plugins::iPlugin
)
225 virtual bool init(QString
const & args
);
229 virtual bool isReady() const { return wWindow
!= nullptr; }
237 } // namespace eVaf::LogView::Internal
238 } // namespace eVaf::LogView