Add option to disable CSV export

This commit is contained in:
Alex Spataru 2020-12-30 14:53:27 -06:00
parent c3062e5930
commit 8a041403bb
4 changed files with 54 additions and 2 deletions

View File

@ -24,6 +24,8 @@ import QtQuick 2.12
import QtQuick.Layouts 1.12
import QtQuick.Controls 2.12
import Qt.labs.settings 1.0
Control {
id: root
@ -50,6 +52,13 @@ Control {
property alias widgetsChecked: widgetsBt.checked
property alias devicesChecked: devicesBt.checked
//
// Settings
//
Settings {
property alias dataExport: csvLogging.checked
}
//
// Background gradient
//
@ -152,6 +161,14 @@ Control {
Layout.fillWidth: true
}
Switch {
id: csvLogging
checked: true
text: qsTr("CSV Export")
Layout.alignment: Qt.AlignVCenter
onCheckedChanged: CppExport.exportEnabled = checked
}
Button {
flat: true
icon.width: 24

View File

@ -53,7 +53,7 @@ ApplicationWindow {
// Window geometry
//
visible: false
minimumWidth: 960
minimumWidth: 1120
minimumHeight: 640
title: CppAppName + " v" + CppAppVersion

View File

@ -87,6 +87,8 @@ Export *Export::getInstance()
*/
Export::Export()
{
m_exportEnabled = true;
auto jp = JsonParser::getInstance();
auto sp = SerialManager::getInstance();
connect(jp, SIGNAL(packetReceived()), this, SLOT(updateValues()));
@ -111,6 +113,14 @@ bool Export::isOpen() const
return m_csvFile.isOpen();
}
/**
* Returns @c true if CSV export is enabled
*/
bool Export::exportEnabled() const
{
return m_exportEnabled;
}
/**
* Open a CSV file in the Explorer/Finder window
*/
@ -127,6 +137,21 @@ void Export::openCurrentCsv()
QMessageBox::critical(Q_NULLPTR, tr("CSV file not open"), tr("Cannot find CSV export file!"), QMessageBox::Ok);
}
/**
* Enables or disables data export
*/
void Export::setExportEnabled(const bool enabled)
{
m_exportEnabled = enabled;
emit enabledChanged();
if (!exportEnabled() && isOpen())
{
m_jsonList.clear();
closeFile();
}
}
/**
* Write all remaining JSON frames & close the CSV file
*/
@ -216,7 +241,7 @@ void Export::writeValues()
values.prepend(dateTime.toString("yyyy/MMM/dd/ HH:mm:ss::zzz"));
// File not open, create it & add cell titles
if (!isOpen())
if (!isOpen() && exportEnabled())
{
// Get file name and path
QString format = dateTime.toString("yyyy/MMM/dd/");
@ -283,6 +308,10 @@ void Export::updateValues()
if (!SerialManager::getInstance()->connected())
return;
// Ignore is CSV export is disabled
if (!exportEnabled())
return;
// Get & validate JSON document
auto json = JsonParser::getInstance()->document().object();
if (json.isEmpty())

View File

@ -33,13 +33,17 @@ class Export : public QObject
{
Q_OBJECT
Q_PROPERTY(bool isOpen READ isOpen NOTIFY openChanged)
Q_PROPERTY(bool exportEnabled READ exportEnabled WRITE setExportEnabled NOTIFY enabledChanged)
signals:
void openChanged();
void enabledChanged();
public:
static Export *getInstance();
bool isOpen() const;
bool exportEnabled() const;
private:
Export();
@ -49,6 +53,7 @@ public slots:
void openCsv();
void closeFile();
void openCurrentCsv();
void setExportEnabled(const bool enabled);
private slots:
void writeValues();
@ -56,6 +61,7 @@ private slots:
private:
QFile m_csvFile;
bool m_exportEnabled;
QTextStream m_textStream;
QList<QPair<QDateTime, QJsonObject>> m_jsonList;
};