SDRAngel  4.11.5
Developer docs for <a href="https://github.com/f4exb/sdrangel">SDRangel<\a>, an Open Source Qt5 / OpenGL 3.0+ SDR and signal analyzer frontend to various hardware.
dsdstatustextdialog.cpp
Go to the documentation of this file.
1 // Copyright (C) 2018 F4EXB //
3 // written by Edouard Griffiths //
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 as 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 V3 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/>. //
18 
19 #include "dsdstatustextdialog.h"
20 #include "ui_dsdstatustextdialog.h"
21 
22 #include <QDateTime>
23 #include <QScrollBar>
24 #include <QFileDialog>
25 #include <QMessageBox>
26 #include <QTextStream>
27 
29  QDialog(parent),
30  ui(new Ui::DSDStatusTextDialog)
31 {
32  ui->setupUi(this);
33 }
34 
36 {
37  delete ui;
38 }
39 
40 void DSDStatusTextDialog::addLine(const QString& line)
41 {
42  if ((line.size() > 0) && (line != m_lastLine))
43  {
44  QDateTime dt = QDateTime::currentDateTime();
45  QString dateStr = dt.toString("HH:mm:ss");
46  QTextCursor cursor = ui->logEdit->textCursor();
47  cursor.movePosition(QTextCursor::End, QTextCursor::MoveAnchor);
48  cursor.insertText(tr("%1 %2\n").arg(dateStr).arg(line));
49  if (ui->pinToLastLine->isChecked()) {
50  ui->logEdit->verticalScrollBar()->setValue(ui->logEdit->verticalScrollBar()->maximum());
51  }
52  m_lastLine = line;
53  }
54 }
55 
57 {
58  ui->logEdit->clear();
59 }
60 
62 {
63  QString fileName = QFileDialog::getSaveFileName(this,
64  tr("Open log file"), ".", tr("Log files (*.log)"), 0, QFileDialog::DontUseNativeDialog);
65 
66  if (fileName != "")
67  {
68  QFileInfo fileInfo(fileName);
69 
70  if (fileInfo.suffix() != "log") {
71  fileName += ".log";
72  }
73 
74  QFile exportFile(fileName);
75 
76  if (exportFile.open(QIODevice::WriteOnly | QIODevice::Text))
77  {
78  QTextStream outstream(&exportFile);
79  outstream << ui->logEdit->toPlainText();
80  exportFile.close();
81  }
82  else
83  {
84  QMessageBox::information(this, tr("Message"), tr("Cannot open file for writing"));
85  }
86  }
87 
88 }
Ui::DSDStatusTextDialog * ui
Fixed< IntType, IntBits > arg(const std::complex< Fixed< IntType, IntBits > > &val)
Definition: fixed.h:2401
DSDStatusTextDialog(QWidget *parent=0)
void addLine(const QString &line)