The LogView module implements a widget that shows messages output with the Common::iLogger interface.
add_subdirectory(SdiWindow)
+add_subdirectory(LogView)
add_subdirectory(Test)
--- /dev/null
+# Name of the target
+set(TARGET LogView)
+
+# Qt modules
+include(${QT_USE_FILE})
+
+# Needed for exporting/importing symbols
+add_definitions(-DLOGVIEW_LIBRARY)
+
+# Include files
+include_directories(${eVaf_INCLUDE})
+
+# Required eVaf libraries
+set(eVaf_LIBRARIES CommonLib PluginsLib)
+
+# Source files
+set(SRCS
+ factory.cpp
+ logview.cpp
+)
+
+# Header files for the meta-object compiler
+set(MOC_HDRS
+ factory.h
+ logview.h
+)
+
+# Version info resource file for Windows builds
+if(WIN32)
+ set(SRCS ${SRCS} version.rc)
+endif(WIN32)
+
+qt4_wrap_cpp(MOC_SRCS ${MOC_HDRS})
+
+add_library(${TARGET} SHARED ${SRCS} ${MOC_SRCS})
+
+target_link_libraries(${TARGET} ${QT_LIBRARIES} ${eVaf_LIBRARIES})
+
+install(TARGETS ${TARGET} DESTINATION bin)
--- /dev/null
+/**
+ * @file LogView/factory.cpp
+ * @brief LogView module's factory class
+ * @author Enar Vaikene
+ *
+ * Copyright (c) 2011 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.
+ */
+
+#include "factory.h"
+#include "logview.h"
+#include "version.h"
+
+#include <Common/iLogger>
+
+#include <QtCore>
+
+using namespace eVaf::LogView;
+
+VER_EXPORT_VERSION_INFO()
+Q_EXPORT_PLUGIN2(VER_MODULE_NAME_STR, Factory)
+
+
+//-------------------------------------------------------------------
+
+Factory::Factory()
+ : Plugins::iPluginFactory()
+ , mPlugin(0)
+{
+ setObjectName(QString("%1-Factory").arg(VER_MODULE_NAME_STR));
+
+ EVAF_INFO("%s created", qPrintable(objectName()));
+}
+
+Factory::~Factory()
+{
+ if (mPlugin)
+ delete mPlugin;
+
+ EVAF_INFO("%s destroyed", qPrintable(objectName()));
+}
+
+QObject * Factory::create(QString const & name)
+{
+ Q_UNUSED(name);
+
+ if (mPlugin == 0)
+ mPlugin = new Internal::Module;
+ return mPlugin;
+}
--- /dev/null
+/**
+ * @file LogView/factory.h
+ * @brief LogView module's factory class
+ * @author Enar Vaikene
+ *
+ * Copyright (c) 2011 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_FACTORY_H
+# define __LOGVIEW_FACTORY_H
+
+#include <Plugins/iPluginFactory>
+
+namespace eVaf {
+namespace LogView {
+namespace Internal {
+ class Module;
+} // namespace eVaf::LogView::Internal
+
+
+/**
+ * Plugin factory class for the module
+ */
+class Factory : public Plugins::iPluginFactory
+{
+ Q_OBJECT
+
+public:
+
+ Factory();
+
+ virtual ~Factory();
+
+ virtual QObject * create(QString const & name);
+
+
+private: // Members
+
+ Internal::Module * mPlugin;
+
+};
+
+} // namespace eVaf::LogView
+} // namespace eVaf
+
+#endif // factory.h
--- /dev/null
+/**
+ * @file LogView/liblogview.h
+ * @author Enar Vaikene
+ *
+ * Copyright (c) 2011 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_LIBLOGVIEW_H
+# define __LOGVIEW_LIBLOGVIEW_H
+
+#include <QtCore/qglobal.h>
+
+#if defined(LOGVIEW_LIBRARY)
+# define LOGVIEW_EXPORT Q_DECL_EXPORT
+#else
+# define LOGVIEW_EXPORT Q_DECL_IMPORT
+#endif
+
+#endif // liblogview.h
--- /dev/null
+/**
+ * @file LogView/logview.cpp
+ * @brief Implementation of the LogView module
+ * @author Enar Vaikene
+ *
+ * Copyright (c) 2011 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.
+ */
+
+#include "logview.h"
+#include "version.h"
+
+#include <Common/Globals>
+#include <Common/iLogger>
+
+#include <QtGui>
+
+
+using namespace eVaf;
+using namespace eVaf::LogView::Internal;
+
+
+//-------------------------------------------------------------------
+
+int const Model::MaxLines = 1000;
+
+char const * const Model::SeverityText[Common::iLogger::Count] = {
+ QT_TR_NOOP("[NONE] "),
+ QT_TR_NOOP("[FATAL] "),
+ QT_TR_NOOP("[ERROR] "),
+ QT_TR_NOOP("[WARNING]"),
+ QT_TR_NOOP("[INFO] "),
+ QT_TR_NOOP("[DEBUG] ")
+};
+
+Model::Model(QObject * parent)
+ : QAbstractListModel(parent)
+{
+}
+
+QVariant Model::data(QModelIndex const & index, int role) const
+{
+ if (!index.isValid() || index.row() < 0 || index.row() >= mData.size() || index.column() != 0)
+ return QVariant();
+
+ switch (role) {
+
+ // Return the message for the display role
+ case Qt::DisplayRole: {
+ return mData.at(index.row()).text;
+ break;
+ }
+
+ // Change color for different message types
+ case Qt::ForegroundRole: {
+ Common::iLogger::Severity s = mData.at(index.row()).severity;
+ switch (s) {
+ case Common::iLogger::Info:
+ return QBrush(QColor(Qt::blue));
+ break;
+ case Common::iLogger::Warning:
+ return QBrush(QColor(Qt::black));
+ break;
+ case Common::iLogger::Error:
+ case Common::iLogger::Fatal:
+ return QBrush(QColor(Qt::red));
+ break;
+ default:
+ return QVariant();
+ }
+ break;
+ }
+ } // switch (role)
+
+ return QVariant();
+}
+
+void Model::addMessage(Common::iLogger::Severity severity, QString const & text, QString const & where)
+{
+ // Add the message to the end of the queue
+ beginInsertRows(QModelIndex(), mData.size(), mData.size());
+ mData.enqueue(Message(severity, text, where));
+ endInsertRows();
+
+ // Remove oldest messages if the list is full
+ if (mData.size() > MaxLines) {
+ beginRemoveRows(QModelIndex(), 0, 0);
+ mData.dequeue();
+ endRemoveRows();
+ }
+}
+
+QString Model::details(QModelIndex const & index) const
+{
+ Message const & m = mData.at(index.row());
+ return tr("%1 %2.%3 %4 : %5\nOccurred in %6")
+ .arg(m.dt.date().toString(Qt::DefaultLocaleShortDate))
+ .arg(m.dt.time().toString(Qt::DefaultLocaleLongDate))
+ .arg(m.dt.time().msec(), 3, 10, QChar('0'))
+ .arg(tr(severityText(m.severity)))
+ .arg(m.text)
+ .arg(m.where);
+}
+
+bool Model::copyToClipboard(QModelIndex const & index)
+{
+ mErrorString.clear();
+
+ QClipboard * cb = QApplication::clipboard();
+ if (cb) {
+ cb->setText(details(index));
+ return true;
+ }
+ else {
+ mErrorString = tr("The global clipboard is not available");
+ return false;
+ }
+}
+
+bool Model::saveToFile(QString const & fileName)
+{
+ mErrorString.clear();
+
+ QFile f(fileName);
+ if (!f.open(QFile::WriteOnly)) {
+ mErrorString = tr("Failed to open the file '%1' for writing : %2").arg(fileName).arg(f.errorString());
+ return false;
+ }
+
+ QTextStream out(&f);
+
+ for (int i = 0; i < mData.size(); ++i) {
+ Message const & m = mData.at(i);
+ out << tr("%1 %2.%3 %4 : %5 (occurred in %6)\n")
+ .arg(m.dt.date().toString(Qt::DefaultLocaleShortDate))
+ .arg(m.dt.time().toString(Qt::DefaultLocaleLongDate))
+ .arg(m.dt.time().msec(), 3, 10, QChar('0'))
+ .arg(tr(severityText(m.severity)))
+ .arg(m.text)
+ .arg(m.where)
+ << endl;
+ }
+
+ return true;
+}
+
+char const * const Model::severityText(Common::iLogger::Severity s) const
+{
+ if (s >= Common::iLogger::None && s < Common::iLogger::Count)
+ return SeverityText[s];
+ else
+ return SeverityText[Common::iLogger::None];
+}
+
+
+//-------------------------------------------------------------------
+
+Widget::Widget(QWidget * parent, Qt::WindowFlags flags)
+ : QWidget(parent, flags)
+{
+ setObjectName(QString("%1-Widget").arg(VER_MODULE_NAME_STR));
+ EVAF_INFO("%s created", qPrintable(objectName()));
+}
+
+Widget::~Widget()
+{
+ EVAF_INFO("%s destroyed", qPrintable(objectName()));
+}
+
+
+//-------------------------------------------------------------------
+
+Module::Module()
+ : Plugins::iPlugin()
+ , wWidget(0)
+{
+ setObjectName(QString("%1-Module").arg(VER_MODULE_NAME_STR));
+ EVAF_INFO("%s created", qPrintable(objectName()));
+}
+
+Module::~Module()
+{
+ EVAF_INFO("%s destroyed", qPrintable(objectName()));
+}
+
+bool Module::init(QString const & args)
+{
+ Q_UNUSED(args);
+
+ wWidget = new Widget();
+
+ EVAF_INFO("%s initialized", qPrintable(objectName()));
+
+ return true;
+}
+
+void Module::done()
+{
+ if (wWidget) {
+ delete wWidget;
+ wWidget = 0;
+ }
+
+ EVAF_INFO("%s finalized", qPrintable(objectName()));
+}
--- /dev/null
+/**
+ * @file LogView/logview.h
+ * @brief Implementation of the LogView module
+ * @author Enar Vaikene
+ *
+ * Copyright (c) 2011 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 <Plugins/iPlugin>
+#include <Common/iLogger>
+
+#include <QObject>
+#include <QString>
+#include <QWidget>
+#include <QAbstractListModel>
+#include <QQueue>
+#include <QDateTime>
+
+
+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)
+ , where(w)
+ {}
+
+ QDateTime dt;
+ Common::iLogger::Severity severity;
+ QString text;
+ QString where;
+ };
+
+ Model(QObject * parent = 0);
+
+ Message const & messageAt(int idx) const { return mData.at(idx); }
+
+ virtual int rowCount(QModelIndex const & parent = 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<Message> mData;
+
+ /// Human-readable error string if the last operation failed
+ QString mErrorString;
+
+
+private: // Methods
+
+ inline char const * const severityText(Common::iLogger::Severity s) const;
+
+};
+
+/**
+ * The log view widget
+ */
+class Widget : public QWidget
+{
+ Q_OBJECT
+
+public:
+
+ Widget(QWidget * parent = 0, Qt::WindowFlags flags = 0);
+
+ virtual ~Widget();
+
+
+private: // Methods
+
+ void saveSettings();
+
+ void restoreSettings();
+
+};
+
+/**
+ * LogView module's implementation
+ */
+class Module : public Plugins::iPlugin
+{
+ Q_OBJECT
+
+public:
+
+ Module();
+
+ virtual ~Module();
+
+ virtual bool init(QString const & args);
+
+ virtual void done();
+
+ virtual bool isReady() const { return wWidget != 0; }
+
+private: // Members
+
+ Widget * wWidget;
+
+};
+
+} // namespace eVaf::LogView::Internal
+} // namespace eVaf::LogView
+} // namespace eVaf
+
+#endif // logview.h
--- /dev/null
+/**
+ * @file LogView/version.h
+ * @brief Version information for eVaf modules
+ * @author Enar Vaikene
+ *
+ * Copyright (c) 2011 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_VERSION_H
+#define __LOGVIEW_VERSION_H
+
+#include <version_rc.h>
+
+/**
+ * Module/library version number in the form major,minor,release,build
+ */
+#define VER_FILE_VERSION 0,1,1,1
+
+/**
+ * Module/library version number in the string format (shall end with \0)
+ */
+#define VER_FILE_VERSION_STR "0.1.1.1\0"
+
+/**
+ * Module/library name (shall end with \0)
+ */
+#define VER_MODULE_NAME_STR "LogView\0"
+
+/**
+ * Module type (see version_rc.h for all the types)
+ */
+#define VER_MODULE_TYPE MT_GENERIC
+
+/**
+ * Module type in the string format (see version_rc for all the types)
+ */
+#define VER_MODULE_TYPE_STR MT_GENERIC
+
+/**
+ * Original file name for windows (shall end with \0)
+ */
+#define VER_ORIGINAL_FILE_NAME_STR "LogView.dll\0"
+
+/**
+ * Description of the module/library (shall end with \0)
+ */
+#define VER_FILE_DESCRIPTION_STR "Module for viewing messages output using the iLogger interface.\0"
+
+#endif // version.h
--- /dev/null
+/**
+ * @file LogView/version.rc
+ * @brief Windows resource file with module/library version information.
+ * @author Enar Vaikene
+ *
+ * Copyright (c) 2011 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.
+ */
+
+#include "version.h"
+#include <version_rc.h>
+#include <winver.h>
+
+
+VS_VERSION_INFO VERSIONINFO
+ FILEVERSION VER_FILE_VERSION
+ PRODUCTVERSION VER_PRODUCT_VERSION
+ FILEFLAGSMASK 0x3fL
+#ifdef _DEBUG
+ FILEFLAGS VS_FF_DEBUG
+#else
+ FILEFLAGS 0x0L
+#endif
+ FILEOS VOS__WINDOWS32
+ FILETYPE VFT_DLL
+ FILESUBTYPE 0x0L
+ BEGIN
+ BLOCK "StringFileInfo"
+ BEGIN
+ BLOCK "040904B0"
+ BEGIN
+ VALUE "CompanyName", VER_COMPANY_NAME_STR
+ VALUE "FileDescription", VER_FILE_DESCRIPTION_STR
+ VALUE "FileVersion", VER_FILE_VERSION_STR
+ VALUE "LegalCopyright", VER_LEGAL_COPYRIGHT_STR
+ VALUE "OriginalFilename", VER_ORIGINAL_FILE_NAME_STR
+ VALUE "ProductName", VER_PRODUCT_NAME_STR
+ VALUE "ProductVersion", VER_PRODUCT_VERSION_STR
+ VALUE "Build Date", VER_PRODUCT_DATE_STR
+ VALUE "Module Name", VER_MODULE_NAME_STR
+ VALUE "Module Type", VER_MODULE_TYPE_STR
+ END
+ END
+ END