Cppcheck
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
logview.cpp
Go to the documentation of this file.
1 /*
2  * Cppcheck - A tool for static C/C++ code analysis
3  * Copyright (C) 2007-2016 Cppcheck team.
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #include <QFile>
20 #include <QFileDialog>
21 #include <QMessageBox>
22 #include <QSettings>
23 #include <QTextStream>
24 #include <QPushButton>
25 #include "common.h"
26 #include "logview.h"
27 
28 LogView::LogView(QWidget *parent)
29  : QWidget(parent)
30 {
31  mUI.setupUi(this);
32  setWindowFlags(Qt::Tool);
33 
34  mUI.mButtonBox->button(QDialogButtonBox::Reset)->setText(tr("Clear"));
35  connect(mUI.mButtonBox->button(QDialogButtonBox::Close), SIGNAL(clicked()), this, SLOT(closeButtonClicked()));
36  connect(mUI.mButtonBox->button(QDialogButtonBox::Reset), SIGNAL(clicked()), this, SLOT(clearButtonClicked()));
37  connect(mUI.mButtonBox->button(QDialogButtonBox::Save), SIGNAL(clicked()), this, SLOT(saveButtonClicked()));
38 
39  QSettings settings;
40  resize(settings.value(SETTINGS_LOG_VIEW_WIDTH, 400).toInt(),
41  settings.value(SETTINGS_LOG_VIEW_HEIGHT, 300).toInt());
42 }
43 
45 {
46  QSettings settings;
47  settings.setValue(SETTINGS_LOG_VIEW_WIDTH, size().width());
48  settings.setValue(SETTINGS_LOG_VIEW_HEIGHT, size().height());
49 }
50 
51 void LogView::appendLine(const QString &line)
52 {
53  mUI.mLogEdit->appendPlainText(line);
54 }
55 
57 {
58  close();
59 }
60 
62 {
63  mUI.mLogEdit->clear();
64 }
65 
67 {
68  QString fileName = QFileDialog::getSaveFileName(this, tr("Save Log"),
69  "", tr("Text files (*.txt *.log);;All files (*.*)"));
70  if (!fileName.isEmpty()) {
71  QFile file(fileName);
72  if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
73  QMessageBox::warning(this, tr("Cppcheck"),
74  tr("Could not open file for writing: \"%1\"").arg(fileName));
75  return;
76  }
77 
78  QTextStream out(&file);
79  out << mUI.mLogEdit->toPlainText();
80  }
81 }
#define SETTINGS_LOG_VIEW_HEIGHT
Definition: common.h:37
void appendLine(const QString &line)
Append new log file to view.
Definition: logview.cpp:51
~LogView()
Definition: logview.cpp:44
void clearButtonClicked()
Called when clear button is clicked.
Definition: logview.cpp:61
#define SETTINGS_LOG_VIEW_WIDTH
Definition: common.h:36
void saveButtonClicked()
Called when save button is clicked.
Definition: logview.cpp:66
Ui::LogView mUI
Definition: logview.h:66
void closeButtonClicked()
Called when close button is clicked.
Definition: logview.cpp:56
LogView(QWidget *parent=0)
Definition: logview.cpp:28