GUI for CSV import

This patch implements GUI for importing CSV log files. One is able to
configure what columns contain time, depth and temperature fields.
Pre-configured log applications currently included are ADP log viewer
and XP5. (Both of these use actually tab as separator, so the field
separator currently hard-coded.)

[Dirk Hohndel: minor fixes]

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Miika Turkia 2013-10-16 22:05:19 +03:00 committed by Dirk Hohndel
parent 80bced4f56
commit 4c49670cdb
11 changed files with 494 additions and 32 deletions

102
qt-ui/csvimportdialog.cpp Normal file
View file

@ -0,0 +1,102 @@
#include <QtDebug>
#include <QFileDialog>
#include "csvimportdialog.h"
#include "mainwindow.h"
#include "ui_csvimportdialog.h"
const CSVImportDialog::CSVAppConfig CSVImportDialog::CSVApps[CSVAPPS] = {
{"", },
{"APD Log Viewer", 0, 1, 15, "Tab"},
{"XP5", 0, 1, 9, "Tab"},
{NULL,}
};
CSVImportDialog::CSVImportDialog(QWidget *parent) :
QDialog(parent),
selector(true),
ui(new Ui::CSVImportDialog)
{
ui->setupUi(this);
for (int i = 0; !CSVApps[i].name.isNull(); ++i)
ui->knownImports->addItem(CSVApps[i].name);
ui->CSVSeparator->addItem("Tab");
ui->knownImports->setCurrentIndex(1);
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
}
CSVImportDialog::~CSVImportDialog()
{
delete ui;
}
void CSVImportDialog::on_buttonBox_accepted()
{
char *error = NULL;
parse_csv_file(ui->CSVFile->text().toUtf8().data(), ui->CSVTime->value(), ui->CSVDepth->value(), ui->CSVTemperature->value(), &error);
if (error != NULL) {
mainWindow()->showError(error);
free(error);
error = NULL;
}
process_dives(TRUE, FALSE);
mainWindow()->refreshDisplay();
}
void CSVImportDialog::on_CSVFileSelector_clicked()
{
QString filename = QFileDialog::getOpenFileName(this, tr("Open CSV Log File"), ".", tr("CSV Files (*.csv)"));
ui->CSVFile->setText(filename);
if (filename.isEmpty())
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
else
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
}
void CSVImportDialog::on_knownImports_currentIndexChanged(int index)
{
if (index == 0)
return;
ui->CSVTime->blockSignals(true);
ui->CSVDepth->blockSignals(true);
ui->CSVTemperature->blockSignals(true);
ui->CSVTime->setValue(CSVApps[index].time);
ui->CSVDepth->setValue(CSVApps[index].depth);
ui->CSVTemperature->setValue(CSVApps[index].temperature);
ui->CSVTime->blockSignals(false);
ui->CSVDepth->blockSignals(false);
ui->CSVTemperature->blockSignals(false);
}
void CSVImportDialog::on_CSVTime_valueChanged(int arg1)
{
unknownImports();
}
void CSVImportDialog::on_CSVDepth_valueChanged(int arg1)
{
unknownImports();
}
void CSVImportDialog::on_CSVTemperature_valueChanged(int arg1)
{
unknownImports();
}
void CSVImportDialog::unknownImports()
{
ui->knownImports->setCurrentIndex(0);
}
void CSVImportDialog::on_CSVFile_textEdited()
{
if (ui->CSVFile->text().isEmpty())
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
else
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
}

48
qt-ui/csvimportdialog.h Normal file
View file

@ -0,0 +1,48 @@
#ifndef CSVIMPORTDIALOG_H
#define CSVIMPORTDIALOG_H
#include <QDialog>
#include <QModelIndex>
#include "../dive.h"
#include "../divelist.h"
namespace Ui {
class CSVImportDialog;
}
class CSVImportDialog : public QDialog
{
Q_OBJECT
public:
explicit CSVImportDialog(QWidget *parent = 0);
~CSVImportDialog();
private slots:
void on_buttonBox_accepted();
void on_CSVFileSelector_clicked();
void on_knownImports_currentIndexChanged(int index);
void on_CSVTime_valueChanged(int arg1);
void on_CSVDepth_valueChanged(int arg1);
void on_CSVTemperature_valueChanged(int arg1);
void on_CSVFile_textEdited();
private:
void unknownImports();
bool selector;
Ui::CSVImportDialog *ui;
struct CSVAppConfig {
QString name;
int time;
int depth;
int temperature;
QString separator;
};
#define CSVAPPS 4
static const CSVAppConfig CSVApps[CSVAPPS];
};
#endif // CSVIMPORTDIALOG_H

253
qt-ui/csvimportdialog.ui Normal file
View file

@ -0,0 +1,253 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CSVImportDialog</class>
<widget class="QDialog" name="CSVImportDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="geometry">
<rect>
<x>30</x>
<y>240</y>
<width>341</width>
<height>32</height>
</rect>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
<widget class="QGroupBox" name="groupBox">
<property name="geometry">
<rect>
<x>40</x>
<y>10</y>
<width>331</width>
<height>71</height>
</rect>
</property>
<property name="title">
<string>Import File (CSV)</string>
</property>
<widget class="QLineEdit" name="CSVFile">
<property name="geometry">
<rect>
<x>0</x>
<y>30</y>
<width>291</width>
<height>29</height>
</rect>
</property>
</widget>
<widget class="QToolButton" name="CSVFileSelector">
<property name="geometry">
<rect>
<x>300</x>
<y>30</y>
<width>25</width>
<height>27</height>
</rect>
</property>
<property name="text">
<string>...</string>
</property>
</widget>
</widget>
<widget class="QGroupBox" name="groupBox_2">
<property name="geometry">
<rect>
<x>200</x>
<y>80</y>
<width>121</width>
<height>61</height>
</rect>
</property>
<property name="title">
<string>Field Separator</string>
</property>
<widget class="QComboBox" name="CSVSeparator">
<property name="geometry">
<rect>
<x>0</x>
<y>30</y>
<width>111</width>
<height>29</height>
</rect>
</property>
</widget>
</widget>
<widget class="QGroupBox" name="groupBox_3">
<property name="geometry">
<rect>
<x>40</x>
<y>80</y>
<width>151</width>
<height>151</height>
</rect>
</property>
<property name="title">
<string>Field Configuration</string>
</property>
<widget class="QSpinBox" name="CSVTime">
<property name="geometry">
<rect>
<x>60</x>
<y>30</y>
<width>56</width>
<height>29</height>
</rect>
</property>
<property name="minimum">
<number>0</number>
</property>
<property name="value">
<number>0</number>
</property>
</widget>
<widget class="QSpinBox" name="CSVDepth">
<property name="geometry">
<rect>
<x>60</x>
<y>70</y>
<width>56</width>
<height>29</height>
</rect>
</property>
<property name="minimum">
<number>0</number>
</property>
<property name="value">
<number>1</number>
</property>
</widget>
<widget class="QSpinBox" name="CSVTemperature">
<property name="geometry">
<rect>
<x>60</x>
<y>110</y>
<width>56</width>
<height>29</height>
</rect>
</property>
<property name="minimum">
<number>0</number>
</property>
<property name="value">
<number>15</number>
</property>
</widget>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>0</x>
<y>30</y>
<width>41</width>
<height>19</height>
</rect>
</property>
<property name="text">
<string>Time</string>
</property>
</widget>
<widget class="QLabel" name="label_2">
<property name="geometry">
<rect>
<x>0</x>
<y>70</y>
<width>51</width>
<height>19</height>
</rect>
</property>
<property name="text">
<string>Depth</string>
</property>
</widget>
<widget class="QLabel" name="label_3">
<property name="geometry">
<rect>
<x>0</x>
<y>110</y>
<width>41</width>
<height>19</height>
</rect>
</property>
<property name="text">
<string>Temp</string>
</property>
</widget>
</widget>
<widget class="QGroupBox" name="groupBox_4">
<property name="geometry">
<rect>
<x>200</x>
<y>159</y>
<width>181</width>
<height>61</height>
</rect>
</property>
<property name="title">
<string>Pre-configured imports</string>
</property>
<widget class="QComboBox" name="knownImports">
<property name="geometry">
<rect>
<x>0</x>
<y>30</y>
<width>161</width>
<height>29</height>
</rect>
</property>
<property name="currentIndex">
<number>-1</number>
</property>
</widget>
</widget>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>CSVImportDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>CSVImportDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View file

@ -34,6 +34,7 @@
#include "diveplanner.h"
#include "about.h"
#include "printdialog.h"
#include "csvimportdialog.h"
static MainWindow* instance = 0;
@ -801,3 +802,17 @@ void MainWindow::loadFiles(const QStringList fileNames)
WSInfoModel *wsim = WSInfoModel::instance();
wsim->updateInfo();
}
void MainWindow::on_actionImportCSV_triggered()
{
CSVImportDialog *csvImport = new(CSVImportDialog);
csvImport->show();
process_dives(TRUE, FALSE);
ui.InfoWidget->reload();
ui.globe->reload();
ui.ListWidget->reload(DiveTripModel::TREE);
ui.ListWidget->setFocus();
WSInfoModel *wsim = WSInfoModel::instance();
wsim->updateInfo();
}

View file

@ -99,6 +99,8 @@ private slots:
void current_dive_changed(int divenr);
void initialUiSetup();
void on_actionImportCSV_triggered();
protected:
void closeEvent(QCloseEvent *);

View file

@ -183,6 +183,7 @@
<addaction name="actionClose"/>
<addaction name="separator"/>
<addaction name="actionImport"/>
<addaction name="actionImportCSV"/>
<addaction name="actionExportUDDF"/>
<addaction name="separator"/>
<addaction name="actionPrint"/>
@ -441,6 +442,13 @@
<string>Dive Planner</string>
</property>
</action>
<action name="actionImportCSV">
<property name="text">
<string>Import CSV</string>
</property>
<property name="toolTip">
</property>
</action>
</widget>
<customwidgets>
<customwidget>

View file

@ -47,7 +47,7 @@ void SubsurfaceWebServices::buttonClicked(QAbstractButton* button)
case QDialogButtonBox::ApplyRole:{
clear_table(&gps_location_table);
QByteArray url = tr("Webservice").toLocal8Bit();
parse_xml_buffer(url.data(), downloadedData.data(), downloadedData.length(), &gps_location_table, NULL);
parse_xml_buffer(url.data(), downloadedData.data(), downloadedData.length(), &gps_location_table, NULL, NULL);
/* now merge the data in the gps_location table into the dive_table */
if (merge_locations_into_dives()) {