diff --git a/assets/qml/Windows/Toolbar.qml b/assets/qml/Windows/Toolbar.qml index ab28502e..2aa53ff2 100644 --- a/assets/qml/Windows/Toolbar.qml +++ b/assets/qml/Windows/Toolbar.qml @@ -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 diff --git a/assets/qml/main.qml b/assets/qml/main.qml index c3b16825..6394e203 100644 --- a/assets/qml/main.qml +++ b/assets/qml/main.qml @@ -53,7 +53,7 @@ ApplicationWindow { // Window geometry // visible: false - minimumWidth: 960 + minimumWidth: 1120 minimumHeight: 640 title: CppAppName + " v" + CppAppVersion diff --git a/src/Export.cpp b/src/Export.cpp index add63f43..ebb91b96 100644 --- a/src/Export.cpp +++ b/src/Export.cpp @@ -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()) diff --git a/src/Export.h b/src/Export.h index a97be084..c28ee443 100644 --- a/src/Export.h +++ b/src/Export.h @@ -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> m_jsonList; };