1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-12-11 09:26:31 -05:00
sdrangel/plugins/channelrx/demodm17/m17statustextdialog.cpp

89 lines
3.1 KiB
C++
Raw Normal View History

2022-06-04 18:54:59 -04:00
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2022s F4EXB //
// written by Edouard Griffiths //
// //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation as version 3 of the License, or //
// (at your option) any later version. //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License V3 for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#include "m17statustextdialog.h"
#include "ui_m17statustextdialog.h"
#include <QDateTime>
#include <QScrollBar>
#include <QFileDialog>
#include <QMessageBox>
#include <QTextStream>
M17StatusTextDialog::M17StatusTextDialog(QWidget* parent) :
QDialog(parent),
ui(new Ui::M17StatusTextDialog)
{
ui->setupUi(this);
}
M17StatusTextDialog::~M17StatusTextDialog()
{
delete ui;
}
void M17StatusTextDialog::addLine(const QString& line)
{
2022-06-08 22:49:41 -04:00
if (line.size() > 0)
2022-06-04 18:54:59 -04:00
{
QDateTime dt = QDateTime::currentDateTime();
QString dateStr = dt.toString("HH:mm:ss");
QTextCursor cursor = ui->logEdit->textCursor();
cursor.movePosition(QTextCursor::End, QTextCursor::MoveAnchor);
cursor.insertText(tr("%1 %2\n").arg(dateStr).arg(line));
2022-06-08 22:49:41 -04:00
2022-06-04 18:54:59 -04:00
if (ui->pinToLastLine->isChecked()) {
ui->logEdit->verticalScrollBar()->setValue(ui->logEdit->verticalScrollBar()->maximum());
}
}
}
void M17StatusTextDialog::on_clear_clicked()
{
ui->logEdit->clear();
}
void M17StatusTextDialog::on_saveLog_clicked()
{
QString fileName = QFileDialog::getSaveFileName(this,
tr("Open log file"), ".", tr("Log files (*.log)"), 0, QFileDialog::DontUseNativeDialog);
if (fileName != "")
{
QFileInfo fileInfo(fileName);
if (fileInfo.suffix() != "log") {
fileName += ".log";
}
QFile exportFile(fileName);
if (exportFile.open(QIODevice::WriteOnly | QIODevice::Text))
{
QTextStream outstream(&exportFile);
outstream << ui->logEdit->toPlainText();
exportFile.close();
}
else
{
QMessageBox::information(this, tr("Message"), tr("Cannot open file for writing"));
}
}
}