From 9ee91d2a42d48e62e31680db21b9a5df1a4ab970 Mon Sep 17 00:00:00 2001 From: EspoTek Date: Sat, 4 Nov 2017 16:52:19 +1100 Subject: [PATCH] "Snapshot" asks user where they want to save w/ dialog --- .gitignore | 1 + Desktop_Interface/isodriver.cpp | 24 ++++++++++-------------- Desktop_Interface/isodriver.h | 2 +- Desktop_Interface/mainwindow.cpp | 24 ++++++++++++++++++++++-- Desktop_Interface/mainwindow.h | 1 + 5 files changed, 35 insertions(+), 17 deletions(-) diff --git a/.gitignore b/.gitignore index 5ecfcdaa..6e4ddd62 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ *.csv /.project +*.obj diff --git a/Desktop_Interface/isodriver.cpp b/Desktop_Interface/isodriver.cpp index c1c8f939..94d73394 100644 --- a/Desktop_Interface/isodriver.cpp +++ b/Desktop_Interface/isodriver.cpp @@ -1179,26 +1179,22 @@ void isoDriver::setTimeWindow(double newWindow){ windowAtPause = window; } -void isoDriver::takeSnapshot(){ +void isoDriver::takeSnapshot(QString *fileName){ snapshotEnabled = true; - QDateTime now = QDateTime::currentDateTime(); - QString fileName_CH1 = now.toString("yyyyMMddhhmmsszzz"); - fileName_CH1.append("_CH1.csv"); + QString fname_CH1 = *(fileName); + fname_CH1.append("_CH1.csv"); - QString fileName_CH2 = now.toString("yyyyMMddhhmmsszzz"); - fileName_CH2.append("_CH2.csv"); + QString fname_CH2 = *(fileName); + fname_CH2.append("_CH2.csv"); - QDir *dir = new QDir(QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation)); - dir->mkdir("EspoTek"); - dir->cd("EspoTek"); - dir->mkdir("snapshots"); - dir->cd("snapshots"); - snapshotFile_CH1 = new QFile(dir->filePath(fileName_CH1)); - snapshotFile_CH2 = new QFile(dir->filePath(fileName_CH2)); + qDebug() << fname_CH1; + qDebug() << fname_CH2; + + snapshotFile_CH1 = new QFile(fname_CH1); + snapshotFile_CH2 = new QFile(fname_CH2); - free(dir); } double isoDriver::meanVoltageLast(double seconds, unsigned char channel, int TOP){ diff --git a/Desktop_Interface/isodriver.h b/Desktop_Interface/isodriver.h index cacddd20..06697e13 100644 --- a/Desktop_Interface/isodriver.h +++ b/Desktop_Interface/isodriver.h @@ -181,7 +181,7 @@ public slots: void setTopRange(double newTop); void setBotRange(double newBot); void setTimeWindow(double newWindow); - void takeSnapshot(); + void takeSnapshot(QString *fileName); void rSourceChanged(int newSource); }; diff --git a/Desktop_Interface/mainwindow.cpp b/Desktop_Interface/mainwindow.cpp index ed3e98cf..090baef9 100644 --- a/Desktop_Interface/mainwindow.cpp +++ b/Desktop_Interface/mainwindow.cpp @@ -152,7 +152,6 @@ MainWindow::MainWindow(QWidget *parent) : connect(ui->controller_iso, SIGNAL(multimeterREnabled(int)), this, SLOT(rSourceIndexChanged(int))); connect(ui->controller_iso, SIGNAL(multimeterRMS(double)), ui->multimeterRmsDisplay, SLOT(display(double))); connect(ui->controller_iso, SIGNAL(sendMultimeterLabel4(QString)), ui->multimeterRmsLabel, SLOT(setText(QString))); - } MainWindow::~MainWindow() @@ -1158,7 +1157,17 @@ void MainWindow::on_actionRecord_triggered(bool checked) void MainWindow::on_actionTake_Snapshot_triggered() { - ui->controller_iso->takeSnapshot(); + QString fileName; + showFileDialog(&fileName); + qDebug() << fileName; + int len = fileName.length(); + + if(len==0) return; //User cancelled + + qDebug() << len; + fileName.remove(len-4, 4); + qDebug() << fileName; + ui->controller_iso->takeSnapshot(&fileName); } void MainWindow::reinitUsb(void){ @@ -1543,3 +1552,14 @@ void MainWindow::on_actionSingle_ep_async_triggered() settings->setValue("ConnectionType", 2); if(ui->controller_iso->driver->connected) reinitUsb(); } + +void MainWindow::showFileDialog(QString *fileName){ + QString filters("CSV files (*.csv)"); + QString defaultFilter("CSV files (*.csv)"); + + /* Static method approach */ + QString temp = QFileDialog::getSaveFileName(0, "Save file", QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation), + filters, &defaultFilter); + + *(fileName) = temp; +} diff --git a/Desktop_Interface/mainwindow.h b/Desktop_Interface/mainwindow.h index 8a34f3fb..d78a90e2 100644 --- a/Desktop_Interface/mainwindow.h +++ b/Desktop_Interface/mainwindow.h @@ -43,6 +43,7 @@ public: explicit MainWindow(QWidget *parent = 0); ~MainWindow(); void resizeEvent(QResizeEvent *event); + void showFileDialog(QString *fileName); private slots: //Oscilloscope void on_actionGain0_5_triggered();