logviewerwidget.cpp 4.71 KB
Newer Older
1
2
3
4
5
6
7
// ================================================================================================
// 
// This file is part of the CAMPVis Software Framework.
// 
// If not explicitly stated otherwise: Copyright (C) 2012, all rights reserved,
//      Christian Schulte zu Berge <christian.szb@in.tum.de>
//      Chair for Computer Aided Medical Procedures
8
9
//      Technische Universität München
//      Boltzmannstr. 3, 85748 Garching b. München, Germany
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
// 
// The licensing of this softare is not yet resolved. Until then, redistribution in source or
// binary forms outside the CAMP chair is not permitted, unless explicitly stated in legal form.
// However, the names of the original authors and the above copyright notice must retain in its
// original state in any case.
// 
// Legal disclaimer provided by the BSD license:
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 
// AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
// 
// ================================================================================================

#include "logviewerwidget.h"

namespace campvis {

    LogViewerWidget::LogViewerWidget(QWidget* parent)
        : QWidget(parent)
36
        , _filterRegExp(0)
37
38
39
    {
        setupGUI();

40
        _log = new BufferingLog(100, this);
41
        _log->addCat("", true);
42
43

        connect(_log, SIGNAL(s_messageAppended(const QString&)),
grunau's avatar
grunau committed
44
                this, SLOT(appendMessage(const QString&)));
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
    }

    LogViewerWidget::~LogViewerWidget() {
    }

    void LogViewerWidget::setupGUI() {
        setWindowTitle(tr("Log Viewer"));

        _mainLayout = new QVBoxLayout();
        setLayout(_mainLayout);

        _controls_layout = new QHBoxLayout();
        _mainLayout->addLayout(_controls_layout);

        _filter_label = new QLabel(tr("&Filter:"));
        _controls_layout->addWidget(_filter_label);

        _filter_line_edit = new QLineEdit();
        _filter_line_edit->setPlaceholderText(tr("Start typing here to filter log messages"));

        _filter_label->setBuddy(_filter_line_edit);
        _controls_layout->addWidget(_filter_line_edit);
        _controls_layout->addStretch();

        _clear_button = new QPushButton(tr("&Clear"));
        _controls_layout->addWidget(_clear_button);

        _logDisplay = new QTextEdit();
        _logDisplay->setReadOnly(true);
        _mainLayout->addWidget(_logDisplay);

76
77
78
79
80
81
82
83
        // Use the system's default monospace font at the default size in the log viewer
        QFont monoFont = QFont("Monospace");
        monoFont.setStyleHint(QFont::TypeWriter);
        monoFont.setPointSize(QFont().pointSize() + 1);

        _logDisplay->document()->setDefaultFont(monoFont);
        _logHighlighter = new LogHighlighter(_logDisplay);

grunau's avatar
grunau committed
84
85
        connect(_clear_button, SIGNAL(clicked()), this, SLOT(clearMessages()));
        connect(_filter_line_edit, SIGNAL(textEdited(const QString&)), this, SLOT(filterLogMessages(const QString&)));
86
87
88
89
90
91
92
93
94
95
    }

    void LogViewerWidget::init() {
        LogMgr.addLog(_log);
    }

    void LogViewerWidget::deinit() {
        LogMgr.removeLog(_log);
    }

grunau's avatar
grunau committed
96
97
98
    void LogViewerWidget::appendMessage(const QString& message)
    {
        _logMessages.push_back(message);
99
100
101
102
103
104
105
106
        displayMessage(message);
    }

    void LogViewerWidget::displayMessage(const QString& message)
    {
        if (_filterRegExp == 0 || _filterRegExp->indexIn(message) != -1) {
            _logDisplay->append(message);
        }
grunau's avatar
grunau committed
107
108
109
110
111
112
113
114
115
116
    }

    void LogViewerWidget::clearMessages()
    {
        _logDisplay->clear();
        _logMessages.clear();
    }

    void LogViewerWidget::filterLogMessages(const QString& text)
    {
117
118
119
120
121
122
        if (text.length() == 0) {
            _filterRegExp = 0;
        } else {
            _filterRegExp = new QRegExp(text, Qt::CaseInsensitive, QRegExp::FixedString);
        }

grunau's avatar
grunau committed
123
        _logDisplay->clear();
124
        _logHighlighter->setFilterRegExp(_filterRegExp);
grunau's avatar
grunau committed
125
126

        for (std::deque<QString>::iterator it = _logMessages.begin(); it != _logMessages.end(); it++) {
127
            displayMessage(*it);
grunau's avatar
grunau committed
128
129
130
        }
    }

131
}