qtexteditlog.h 2.05 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
#ifndef QTEXTEDITLOG_H__
#define QTEXTEDITLOG_H__

#include "tgt/logmanager.h"

#include <QObject>
#include <QTextEdit>
#include <QTextDocument>

using namespace tgt;

namespace campvis {

    /**
     * QTextEditLog implements logging to a QTextEdit instance.
     */
    class QTextEditLog : private QObject, public Log {

        Q_OBJECT

    public:
        /**
         * Creates a new QTextEditLog.
         *
         * QTextEditLog doesn't take ownership of the QTextEdit instance it's passed.
         *
         * \param   output           a QTextEdit instance to which messages will be logged
28
         * \param   parent           the log's parent object
29 30 31 32 33
         * \param   dateStamping     should logged messages be date-stamped
         * \param   timeStamping     should logged messages be time-stamped
         * \param   showCat          should the category be printed along with the messages
         * \param   showLevel        should the LogLevel be printed along with the messages
         */
34
        explicit QTextEditLog(QTextEdit* logDisplay, QObject* parent = 0, bool dateStamping = true,
35
                     bool timeStamping = true, bool showCat = true, bool showLevel = true);
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
        virtual ~QTextEditLog() {}
        bool isOpen() { return true; }

	signals:
        /** Internal signal used to pass messages to _logDisplay in a thread-safe way.
         *
         * This class' \c log method is called from several non-GUI
         * threads. If it were to directly access its underlying
         * QTextEdit widget, which is neither thread-safe nor reentrant,
         * the application would break badly. However, if we connect
         * a signal to _logDisplay's append slot to display log
         * messages, Qt takes care of queueing slot accesses in the GUI
         * thread for us.
         */
        void s_messageReady(const QString& message);

    protected:
        QTextEdit* _logDisplay;
        void logFiltered(const std::string &cat, LogLevel level, const std::string &msg, const std::string &extendedInfo="");
    };
}

#endif // QTEXTEDITLOG_H__