Fixed #2047 (GUI: save log to file)

This commit is contained in:
Zachary Blair 2010-12-14 23:51:21 -08:00
parent 05ebf120c3
commit 500c0a19c3
3 changed files with 37 additions and 0 deletions

View File

@ -16,7 +16,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <QFile>
#include <QFileDialog>
#include <QMessageBox>
#include <QSettings>
#include <QTextStream>
#include "common.h"
#include "logview.h"
@ -29,6 +33,7 @@ LogView::LogView(QSettings *programSettings, QWidget *parent)
connect(mUI.mCloseButton, SIGNAL(clicked()), this, SLOT(CloseButtonClicked()));
connect(mUI.mClearButton, SIGNAL(clicked()), this, SLOT(ClearButtonClicked()));
connect(mUI.mSaveButton, SIGNAL(clicked()), this, SLOT(SaveButtonClicked()));
resize(mSettings->value(SETTINGS_LOG_VIEW_WIDTH, 400).toInt(),
mSettings->value(SETTINGS_LOG_VIEW_HEIGHT, 300).toInt());
@ -54,3 +59,22 @@ void LogView::ClearButtonClicked()
{
mUI.mLogEdit->clear();
}
void LogView::SaveButtonClicked()
{
QString fileName = QFileDialog::getSaveFileName(this, tr("Save Log"),
"", tr("Text files (*.txt *.log);;All files (*.*)"));
if (!fileName.isEmpty())
{
QFile file(fileName);
if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
{
QMessageBox::warning(this, tr("Cppcheck"),
tr("Could not open file for writing: \"%1\"").arg(fileName));
return;
}
QTextStream out(&file);
out << mUI.mLogEdit->toPlainText();
}
}

View File

@ -59,6 +59,12 @@ protected slots:
*/
void ClearButtonClicked();
/**
* @brief Called when save button is clicked.
*
*/
void SaveButtonClicked();
private:
Ui::LogView mUI;

View File

@ -42,6 +42,13 @@
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="mSaveButton">
<property name="text">
<string>&amp;Save</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="mClearButton">
<property name="text">