Fixed some bugs in file I/O

This commit is contained in:
Chris Esposito 2017-12-27 16:07:22 +11:00
parent 424417aab9
commit 277df7a7a1
5 changed files with 105 additions and 8 deletions

View File

@ -1249,3 +1249,46 @@ void isoDriver::serialNeedsDisabling(int channel){
qDebug("isoDriver acknowledges disconnect from channel %d", channel);
mainWindowPleaseDisableSerial(channel);
}
//Thank you https://stackoverflow.com/questions/27318631/parsing-through-a-csv-file-in-qt
void isoDriver::loadFileBuffer(QFile *fileToLoad){
//Delete the current buffer if it exists
if(internalBufferFile != NULL){
delete internalBufferFile;
}
//Load the file
if (!fileToLoad->open(QIODevice::ReadOnly)) {
qDebug() << fileToLoad->errorString();
return;
}
QByteArray currentLine;
QList<QByteArray> tempList;
//First Header line
currentLine = fileToLoad->readLine();
qDebug() << currentLine;
//Averaging line
currentLine = fileToLoad->readLine();
qDebug() << currentLine;
tempList.append(currentLine.split('\n'));
tempList.append(currentLine.split('\r'));
tempList.append(tempList.first().split(' '));
qDebug() << tempList;
int averages = tempList.back().toInt();
qDebug() << averages;
//Mode line
currentLine = fileToLoad->readLine();
qDebug() << currentLine;
//Count the number of elements
while (!fileToLoad->atEnd()) {
currentLine = fileToLoad->readLine();
//tempList = currentLine.split(',').first();
}
//Prompt user for start and end times
//Copy the data into the isoBuffer
}

View File

@ -22,7 +22,7 @@ class isoDriver : public QLabel
public:
explicit isoDriver(QWidget *parent = 0);
//Generic Vars
isoBuffer *internalBuffer375_CH1, *internalBuffer375_CH2, *internalBuffer750;
isoBuffer *internalBuffer375_CH1, *internalBuffer375_CH2, *internalBuffer750, *internalBufferFile = NULL;
#if QCP_VER == 1
QCPItemText *cursorTextPtr;
#endif
@ -43,6 +43,7 @@ public:
void setDriver(genericUsbDriver *newDriver);
void setAxes(QCustomPlot *newAxes);
double meanVoltageLast(double seconds, unsigned char channel, int TOP);
void loadFileBuffer(QFile *fileToLoad);
private:
//Those bloody bools that just Enable/Disable a single property
bool paused_CH1 = false, paused_CH2 = false, paused_multimeter = false;

View File

@ -1586,13 +1586,42 @@ void MainWindow::on_actionSingle_ep_async_triggered()
}
void MainWindow::showFileDialog(QString *fileName){
QString filters("CSV files (*.csv)");
QString defaultFilter("CSV files (*.csv)");
QFileDialog dialog;
/* Static method approach */
QString temp = QFileDialog::getSaveFileName(0, "Save file", QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation),
filters, &defaultFilter);
dialog.setDefaultSuffix("csv");
dialog.setAcceptMode(QFileDialog::AcceptSave);
dialog.setDirectory(QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation));
dialog.setFileMode(QFileDialog::AnyFile);
dialog.setNameFilter("CSV files (*.csv);;All Files (*)");
int retVal = dialog.exec();
if(!retVal){
return; //User did not select a file!
}
QStringList tempList = dialog.selectedFiles();
QString temp = tempList.first();
*(fileName) = temp;
}
void MainWindow::openFileDialog(QString *fileName){
QFileDialog dialog;
dialog.setDefaultSuffix("csv");
dialog.setAcceptMode(QFileDialog::AcceptOpen);
dialog.setDirectory(QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation));
dialog.setFileMode(QFileDialog::ExistingFile);
dialog.setNameFilter("CSV files (*.csv);;All Files (*)");
int retVal = dialog.exec();
if(!retVal){
return; //User did not select a file!
}
QStringList tempList = dialog.selectedFiles();
QString temp = tempList.first();
*(fileName) = temp;
}
@ -1795,3 +1824,18 @@ void MainWindow::on_actionAbout_triggered()
{
QMessageBox::about(this, "About EspoTek Labrador", "EspoTek Labrador, Christmas Edition 2017.\nWebsite: http://espotek.com\nContact Email: admin@espotek.com");
}
void MainWindow::on_actionOpen_DAQ_File_triggered()
{
qDebug() << "on_actionOpen_DAQ_File_triggered";
//Prompt user for file name
QString fileName;
openFileDialog(&fileName);
qDebug() << fileName;
int len = fileName.length();
if(len==0) return; //User cancelled
QFile *inputFile = new QFile(fileName);
ui->controller_iso->loadFileBuffer(inputFile);
}

View File

@ -44,6 +44,7 @@ public:
~MainWindow();
void resizeEvent(QResizeEvent *event);
void showFileDialog(QString *fileName);
void openFileDialog(QString *fileName);
private slots:
//Oscilloscope
void on_actionGain0_5_triggered();
@ -175,6 +176,8 @@ private slots:
void on_actionAbout_triggered();
void on_actionOpen_DAQ_File_triggered();
private:
//Generic Vars
Ui::MainWindow *ui;

View File

@ -1343,14 +1343,15 @@
</widget>
<widget class="QMenu" name="menuRecord">
<property name="title">
<string>Enable Data Aquisition</string>
<string>Enable DAQ</string>
</property>
<addaction name="actionRecord_CH1"/>
<addaction name="actionRecord_CH2"/>
</widget>
<addaction name="actionDAQ_Settings"/>
<addaction name="menuTake_Snapshot"/>
<addaction name="menuRecord"/>
<addaction name="actionOpen_DAQ_File"/>
<addaction name="menuTake_Snapshot"/>
</widget>
<widget class="QMenu" name="menuOscilloscope_2">
<property name="title">
@ -2241,6 +2242,11 @@
<string>About</string>
</property>
</action>
<action name="actionOpen_DAQ_File">
<property name="text">
<string>Open DAQ File</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>