mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-31 22:43:25 +00:00
Add support for importing NDL from CSV files
Signed-off-by: Anton Lundin <glance@acc.umu.se> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
848a5352c7
commit
d5991800ee
6 changed files with 53 additions and 12 deletions
2
dive.h
2
dive.h
|
@ -553,7 +553,7 @@ extern int parse_dm4_buffer(sqlite3 *handle, const char *url, const char *buf, i
|
||||||
extern int parse_shearwater_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct dive_table *table);
|
extern int parse_shearwater_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct dive_table *table);
|
||||||
|
|
||||||
extern int parse_file(const char *filename);
|
extern int parse_file(const char *filename);
|
||||||
extern int parse_csv_file(const char *filename, int time, int depth, int temp, int po2f, int cnsf, int stopdepthf, int sepidx, const char *csvtemplate, int units);
|
extern int parse_csv_file(const char *filename, int time, int depth, int temp, int po2f, int cnsf, int ndlf, int stopdepthf, int sepidx, const char *csvtemplate, int units);
|
||||||
extern int parse_manual_file(const char *filename, int separator_index, int units, int number, int date, int time, int duration, int location, int gps, int maxdepth, int meandepth, int buddy, int notes, int weight, int tags);
|
extern int parse_manual_file(const char *filename, int separator_index, int units, int number, int date, int time, int duration, int location, int gps, int maxdepth, int meandepth, int buddy, int notes, int weight, int tags);
|
||||||
|
|
||||||
extern int save_dives(const char *filename);
|
extern int save_dives(const char *filename);
|
||||||
|
|
10
file.c
10
file.c
|
@ -384,16 +384,17 @@ int parse_file(const char *filename)
|
||||||
|
|
||||||
#define MAXCOLDIGITS 3
|
#define MAXCOLDIGITS 3
|
||||||
#define MAXCOLS 100
|
#define MAXCOLS 100
|
||||||
int parse_csv_file(const char *filename, int timef, int depthf, int tempf, int po2f, int cnsf, int stopdepthf, int sepidx, const char *csvtemplate, int unitidx)
|
int parse_csv_file(const char *filename, int timef, int depthf, int tempf, int po2f, int cnsf, int ndlf, int stopdepthf, int sepidx, const char *csvtemplate, int unitidx)
|
||||||
{
|
{
|
||||||
struct memblock mem;
|
struct memblock mem;
|
||||||
int pnr = 0;
|
int pnr = 0;
|
||||||
char *params[21];
|
char *params[23];
|
||||||
char timebuf[MAXCOLDIGITS];
|
char timebuf[MAXCOLDIGITS];
|
||||||
char depthbuf[MAXCOLDIGITS];
|
char depthbuf[MAXCOLDIGITS];
|
||||||
char tempbuf[MAXCOLDIGITS];
|
char tempbuf[MAXCOLDIGITS];
|
||||||
char po2buf[MAXCOLDIGITS];
|
char po2buf[MAXCOLDIGITS];
|
||||||
char cnsbuf[MAXCOLDIGITS];
|
char cnsbuf[MAXCOLDIGITS];
|
||||||
|
char ndlbuf[MAXCOLDIGITS];
|
||||||
char stopdepthbuf[MAXCOLDIGITS];
|
char stopdepthbuf[MAXCOLDIGITS];
|
||||||
char unitbuf[MAXCOLDIGITS];
|
char unitbuf[MAXCOLDIGITS];
|
||||||
char separator_index[MAXCOLDIGITS];
|
char separator_index[MAXCOLDIGITS];
|
||||||
|
@ -402,7 +403,7 @@ int parse_csv_file(const char *filename, int timef, int depthf, int tempf, int p
|
||||||
char curdate[9];
|
char curdate[9];
|
||||||
char curtime[6];
|
char curtime[6];
|
||||||
|
|
||||||
if (timef >= MAXCOLS || depthf >= MAXCOLS || tempf >= MAXCOLS || po2f >= MAXCOLS || cnsf >= MAXCOLS || stopdepthf >= MAXCOLS)
|
if (timef >= MAXCOLS || depthf >= MAXCOLS || tempf >= MAXCOLS || po2f >= MAXCOLS || cnsf >= MAXCOLS || ndlf >= MAXCOLS || cnsf >= MAXCOLS || stopdepthf >= MAXCOLS)
|
||||||
return report_error(translate("gettextFromC", "Maximum number of supported columns on CSV import is %d"), MAXCOLS);
|
return report_error(translate("gettextFromC", "Maximum number of supported columns on CSV import is %d"), MAXCOLS);
|
||||||
|
|
||||||
snprintf(timebuf, MAXCOLDIGITS, "%d", timef);
|
snprintf(timebuf, MAXCOLDIGITS, "%d", timef);
|
||||||
|
@ -410,6 +411,7 @@ int parse_csv_file(const char *filename, int timef, int depthf, int tempf, int p
|
||||||
snprintf(tempbuf, MAXCOLDIGITS, "%d", tempf);
|
snprintf(tempbuf, MAXCOLDIGITS, "%d", tempf);
|
||||||
snprintf(po2buf, MAXCOLDIGITS, "%d", po2f);
|
snprintf(po2buf, MAXCOLDIGITS, "%d", po2f);
|
||||||
snprintf(cnsbuf, MAXCOLDIGITS, "%d", cnsf);
|
snprintf(cnsbuf, MAXCOLDIGITS, "%d", cnsf);
|
||||||
|
snprintf(ndlbuf, MAXCOLDIGITS, "%d", ndlf);
|
||||||
snprintf(stopdepthbuf, MAXCOLDIGITS, "%d", stopdepthf);
|
snprintf(stopdepthbuf, MAXCOLDIGITS, "%d", stopdepthf);
|
||||||
snprintf(separator_index, MAXCOLDIGITS, "%d", sepidx);
|
snprintf(separator_index, MAXCOLDIGITS, "%d", sepidx);
|
||||||
snprintf(unitbuf, MAXCOLDIGITS, "%d", unitidx);
|
snprintf(unitbuf, MAXCOLDIGITS, "%d", unitidx);
|
||||||
|
@ -431,6 +433,8 @@ int parse_csv_file(const char *filename, int timef, int depthf, int tempf, int p
|
||||||
params[pnr++] = po2buf;
|
params[pnr++] = po2buf;
|
||||||
params[pnr++] = "cnsField";
|
params[pnr++] = "cnsField";
|
||||||
params[pnr++] = cnsbuf;
|
params[pnr++] = cnsbuf;
|
||||||
|
params[pnr++] = "ndlField";
|
||||||
|
params[pnr++] = ndlbuf;
|
||||||
params[pnr++] = "stopdepthField";
|
params[pnr++] = "stopdepthField";
|
||||||
params[pnr++] = stopdepthbuf;
|
params[pnr++] = stopdepthbuf;
|
||||||
params[pnr++] = "date";
|
params[pnr++] = "date";
|
||||||
|
|
|
@ -6,12 +6,12 @@
|
||||||
#include "ui_divelogimportdialog.h"
|
#include "ui_divelogimportdialog.h"
|
||||||
|
|
||||||
const DiveLogImportDialog::CSVAppConfig DiveLogImportDialog::CSVApps[CSVAPPS] = {
|
const DiveLogImportDialog::CSVAppConfig DiveLogImportDialog::CSVApps[CSVAPPS] = {
|
||||||
// time, depth, temperature, po2, cns, stopdepth
|
// time, depth, temperature, po2, cns, ndl, stopdepth
|
||||||
{ "", },
|
{ "", },
|
||||||
{ "APD Log Viewer", 1, 2, 16, 7, 18, 19, "Tab" },
|
{ "APD Log Viewer", 1, 2, 16, 7, 18, -1, 19, "Tab" },
|
||||||
{ "XP5", 1, 2, 10, -1, -1, -1, "Tab" },
|
{ "XP5", 1, 2, 10, -1, -1, -1, -1, "Tab" },
|
||||||
{ "SensusCSV", 10, 11, -1, -1, -1, -1, "," },
|
{ "SensusCSV", 10, 11, -1, -1, -1, -1, -1, "," },
|
||||||
{ "Seabear CSV", 1, 2, 6, -1, -1, 5, ";" },
|
{ "Seabear CSV", 1, 2, 6, -1, -1, -1, 5, ";" },
|
||||||
{ NULL, }
|
{ NULL, }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -45,6 +45,8 @@ DiveLogImportDialog::DiveLogImportDialog(QStringList *fn, QWidget *parent) : QDi
|
||||||
connect(ui->po2CheckBox, SIGNAL(clicked(bool)), this, SLOT(unknownImports()));
|
connect(ui->po2CheckBox, SIGNAL(clicked(bool)), this, SLOT(unknownImports()));
|
||||||
connect(ui->CSVcns, SIGNAL(valueChanged(int)), this, SLOT(unknownImports()));
|
connect(ui->CSVcns, SIGNAL(valueChanged(int)), this, SLOT(unknownImports()));
|
||||||
connect(ui->cnsCheckBox, SIGNAL(clicked(bool)), this, SLOT(unknownImports()));
|
connect(ui->cnsCheckBox, SIGNAL(clicked(bool)), this, SLOT(unknownImports()));
|
||||||
|
connect(ui->CSVndl, SIGNAL(valueChanged(int)), this, SLOT(unknownImports()));
|
||||||
|
connect(ui->ndlCheckBox, SIGNAL(clicked(bool)), this, SLOT(unknownImports()));
|
||||||
connect(ui->CSVstopdepth, SIGNAL(valueChanged(int)), this, SLOT(unknownImports()));
|
connect(ui->CSVstopdepth, SIGNAL(valueChanged(int)), this, SLOT(unknownImports()));
|
||||||
connect(ui->stopdepthCheckBox, SIGNAL(clicked(bool)), this, SLOT(unknownImports()));
|
connect(ui->stopdepthCheckBox, SIGNAL(clicked(bool)), this, SLOT(unknownImports()));
|
||||||
QShortcut *close = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_W), this);
|
QShortcut *close = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_W), this);
|
||||||
|
@ -67,6 +69,7 @@ void DiveLogImportDialog::on_buttonBox_accepted()
|
||||||
ui->CSVDepth->value() - 1, VALUE_IF_CHECKED(CSVTemperature),
|
ui->CSVDepth->value() - 1, VALUE_IF_CHECKED(CSVTemperature),
|
||||||
VALUE_IF_CHECKED(CSVpo2),
|
VALUE_IF_CHECKED(CSVpo2),
|
||||||
VALUE_IF_CHECKED(CSVcns),
|
VALUE_IF_CHECKED(CSVcns),
|
||||||
|
VALUE_IF_CHECKED(CSVndl),
|
||||||
VALUE_IF_CHECKED(CSVstopdepth),
|
VALUE_IF_CHECKED(CSVstopdepth),
|
||||||
ui->CSVSeparator->currentIndex(),
|
ui->CSVSeparator->currentIndex(),
|
||||||
specialCSV.contains(ui->knownImports->currentIndex()) ? CSVApps[ui->knownImports->currentIndex()].name.toUtf8().data() : "csv",
|
specialCSV.contains(ui->knownImports->currentIndex()) ? CSVApps[ui->knownImports->currentIndex()].name.toUtf8().data() : "csv",
|
||||||
|
@ -116,6 +119,7 @@ void DiveLogImportDialog::on_knownImports_currentIndexChanged(int index)
|
||||||
SET_VALUE_AND_CHECKBOX(CSVTemperature, temperatureCheckBox, CSVApps[index].temperature);
|
SET_VALUE_AND_CHECKBOX(CSVTemperature, temperatureCheckBox, CSVApps[index].temperature);
|
||||||
SET_VALUE_AND_CHECKBOX(CSVpo2, po2CheckBox, CSVApps[index].po2);
|
SET_VALUE_AND_CHECKBOX(CSVpo2, po2CheckBox, CSVApps[index].po2);
|
||||||
SET_VALUE_AND_CHECKBOX(CSVcns, cnsCheckBox, CSVApps[index].cns);
|
SET_VALUE_AND_CHECKBOX(CSVcns, cnsCheckBox, CSVApps[index].cns);
|
||||||
|
SET_VALUE_AND_CHECKBOX(CSVndl, ndlCheckBox, CSVApps[index].ndl);
|
||||||
SET_VALUE_AND_CHECKBOX(CSVstopdepth, stopdepthCheckBox, CSVApps[index].stopdepth);
|
SET_VALUE_AND_CHECKBOX(CSVstopdepth, stopdepthCheckBox, CSVApps[index].stopdepth);
|
||||||
ui->CSVSeparator->blockSignals(true);
|
ui->CSVSeparator->blockSignals(true);
|
||||||
int separator_index = ui->CSVSeparator->findText(CSVApps[index].separator);
|
int separator_index = ui->CSVSeparator->findText(CSVApps[index].separator);
|
||||||
|
|
|
@ -36,6 +36,7 @@ private:
|
||||||
int temperature;
|
int temperature;
|
||||||
int po2;
|
int po2;
|
||||||
int cns;
|
int cns;
|
||||||
|
int ndl;
|
||||||
int stopdepth;
|
int stopdepth;
|
||||||
QString separator;
|
QString separator;
|
||||||
};
|
};
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>522</width>
|
<width>522</width>
|
||||||
<height>352</height>
|
<height>385</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
|
@ -75,7 +75,7 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="5" column="1">
|
<item row="7" column="1">
|
||||||
<widget class="QSpinBox" name="CSVstopdepth">
|
<widget class="QSpinBox" name="CSVstopdepth">
|
||||||
<property name="enabled">
|
<property name="enabled">
|
||||||
<bool>false</bool>
|
<bool>false</bool>
|
||||||
|
@ -88,7 +88,7 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="5" column="0">
|
<item row="7" column="0">
|
||||||
<widget class="QCheckBox" name="stopdepthCheckBox">
|
<widget class="QCheckBox" name="stopdepthCheckBox">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Stopdepth</string>
|
<string>Stopdepth</string>
|
||||||
|
@ -139,6 +139,26 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="5" column="0">
|
||||||
|
<widget class="QCheckBox" name="ndlCheckBox">
|
||||||
|
<property name="text">
|
||||||
|
<string>NDL</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="5" column="1">
|
||||||
|
<widget class="QSpinBox" name="CSVndl">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="minimum">
|
||||||
|
<number>1</number>
|
||||||
|
</property>
|
||||||
|
<property name="value">
|
||||||
|
<number>1</number>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item row="4" column="0">
|
<item row="4" column="0">
|
||||||
<widget class="QCheckBox" name="cnsCheckBox">
|
<widget class="QCheckBox" name="cnsCheckBox">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
|
@ -147,6 +167,8 @@
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
|
<zorder>ndlCheckBox</zorder>
|
||||||
|
<zorder>CSVndl</zorder>
|
||||||
<zorder>label</zorder>
|
<zorder>label</zorder>
|
||||||
<zorder>label_2</zorder>
|
<zorder>label_2</zorder>
|
||||||
<zorder>CSVTime</zorder>
|
<zorder>CSVTime</zorder>
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
<xsl:param name="po2Field" select="po2Field"/>
|
<xsl:param name="po2Field" select="po2Field"/>
|
||||||
<xsl:param name="cnsField" select="cnsField"/>
|
<xsl:param name="cnsField" select="cnsField"/>
|
||||||
<xsl:param name="otuField" select="otuField"/>
|
<xsl:param name="otuField" select="otuField"/>
|
||||||
|
<xsl:param name="ndlField" select="ndlField"/>
|
||||||
<xsl:param name="stopdepthField" select="stopdepthField"/>
|
<xsl:param name="stopdepthField" select="stopdepthField"/>
|
||||||
<xsl:param name="date" select="date"/>
|
<xsl:param name="date" select="date"/>
|
||||||
<xsl:param name="time" select="time"/>
|
<xsl:param name="time" select="time"/>
|
||||||
|
@ -177,6 +178,15 @@
|
||||||
</xsl:attribute>
|
</xsl:attribute>
|
||||||
</xsl:if>
|
</xsl:if>
|
||||||
|
|
||||||
|
<xsl:if test="$ndlField >= 0">
|
||||||
|
<xsl:attribute name="ndl">
|
||||||
|
<xsl:call-template name="getFieldByIndex">
|
||||||
|
<xsl:with-param name="index" select="$ndlField"/>
|
||||||
|
<xsl:with-param name="line" select="$line"/>
|
||||||
|
</xsl:call-template>
|
||||||
|
</xsl:attribute>
|
||||||
|
</xsl:if>
|
||||||
|
|
||||||
<xsl:if test="$stopdepthField >= 0">
|
<xsl:if test="$stopdepthField >= 0">
|
||||||
<xsl:variable name="stopdepth">
|
<xsl:variable name="stopdepth">
|
||||||
<xsl:call-template name="getFieldByIndex">
|
<xsl:call-template name="getFieldByIndex">
|
||||||
|
|
Loading…
Add table
Reference in a new issue