]> vaikene.ee Git - evaf/blobdiff - src/plugins/LogView/logview.h
Started working on the LogView module.
[evaf] / src / plugins / LogView / logview.h
diff --git a/src/plugins/LogView/logview.h b/src/plugins/LogView/logview.h
new file mode 100644 (file)
index 0000000..1800018
--- /dev/null
@@ -0,0 +1,170 @@
+/**
+ * @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