/** * @file LogView/logview.h * @brief Implementation of the LogView module * @author Enar Vaikene * * Copyright (c) 2011-2019 Enar Vaikene * * This file is part of the eVaf C++ cross-platform application development framework. * * This file can be used under the terms of the GNU General Public License * version 3.0 as published by the Free Software Foundation and appearing in * the file LICENSE included in the packaging of this file. Please review the * the following information to ensure the GNU General Public License version * 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html. * * Alternatively, this file may be used in accordance with the Commercial License * Agreement provided with the Software. */ #ifndef __LOGVIEW_LOGVIEW_H # define __LOGVIEW_LOGVIEW_H #include #include #include #include #include #include #include #include #include class QListView; class QLabel; class QTabWidget; class QStatusBar; class QEvent; namespace eVaf { /** * Module for showing messages output with the eVaf::Common::iLogger interface. * * The LogView module implements a widget that shows all the messages output with the * eVaf::Common::iLogger interface. */ namespace LogView { /** * Internal implementation of the LogView module. */ namespace Internal { /** * Data model for the log view widget */ class Model : public QAbstractListModel { Q_OBJECT public: /// One logger message struct Message { Message(Common::iLogger::Severity s, QString const & t, QString const & w) : dt(QDateTime::currentDateTime()) , severity(s) , text(t) , simplified(t.simplified()) , where(w) {} QDateTime dt; Common::iLogger::Severity severity; QString text; QString simplified; QString where; }; Model(QObject * parent = nullptr); Message const & messageAt(int idx) const { return mData.at(idx); } virtual int rowCount(QModelIndex const & = QModelIndex()) const { return mData.size(); } virtual QVariant data(QModelIndex const & index, int role = Qt::DisplayRole) const; void addMessage(Common::iLogger::Severity severity, QString const & text, QString const & where); QString details(QModelIndex const & index) const; bool saveToFile(QString const & fileName); bool copyToClipboard(QModelIndex const & index); QString errorString() const { return mErrorString; } signals: void messageAdded(QModelIndex const & index); private: // Members /// Maximum number of lines in the queue static int const MaxLines; /// Human-readable texts for message severity levels static char const * const SeverityText[Common::iLogger::Count]; /// Currently shown messages QQueue mData; /// Human-readable error string if the last operation failed QString mErrorString; private: // Methods inline char const * severityText(Common::iLogger::Severity s) const; }; /** * The log view widget * * The Widget class implements a widget that shows messages from one logger source. */ class Widget : public QWidget { Q_OBJECT public: Widget(QString const & source, QWidget * parent = nullptr); QString const & source() const { return mSource; } inline void addMessage(Common::iLogger::Severity severity, QString const & text, QString const & where) { mModel->addMessage(severity, text, where); } private slots: void messageAdded(QModelIndex const & index); void currentChanged(QModelIndex const &, QModelIndex const &); void copyToClipboard(); void saveToFile(); private: QString mSource; Model * mModel; bool mAutoScroll; QListView * wList; QLabel * wDetails; }; /** * The log view window */ class Window : public Gui::Panel { Q_OBJECT public: Window(QString const & args, QWidget * parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags()); virtual ~Window(); virtual bool event(QEvent * e); public slots: void loggerEvent(Common::iLogger::Severity severity, QString const & text, QString const & source, QString const & where); private: // Methods void saveSettings(); void restoreSettings(); QString getPanelName(QString const & args) const; private: // Members QString mDefSource; QTabWidget * wTabs; QHash mLogViews; QStatusBar * wStatusBar; }; /** * LogView module's implementation */ class Module : public Plugins::iPlugin { Q_OBJECT Q_INTERFACES(eVaf::Plugins::iPlugin) public: Module(); virtual ~Module(); virtual bool init(QString const & args); virtual void done(); virtual bool isReady() const { return wWindow != nullptr; } private: // Members Window * wWindow; }; } // namespace eVaf::LogView::Internal } // namespace eVaf::LogView } // namespace eVaf #endif // logview.h