mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Import: add trip_table argument to DiveImportedModel::repopulate()
In the future we want to download trips into a distinct trip-table instead of the global trip-table to allow for undo of import. Therefore add a trip_table argument to DiveImportedModel::repopulate() and a trip_table member to DiveImportedModel. To correctly set these, add a DownloadThread::trips() function, which currently simply returns the global trip table. Finally, make "struct trip_table *" a Q_METATYPE, so that the corresponding arguments can be passed from QML. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
7e33369dc8
commit
f542dc4030
7 changed files with 18 additions and 7 deletions
|
@ -288,10 +288,10 @@ typedef struct dive_trip
|
||||||
bool autogen;
|
bool autogen;
|
||||||
} dive_trip_t;
|
} dive_trip_t;
|
||||||
|
|
||||||
struct trip_table {
|
typedef struct trip_table {
|
||||||
int nr, allocated;
|
int nr, allocated;
|
||||||
struct dive_trip **trips;
|
struct dive_trip **trips;
|
||||||
};
|
} trip_table_t;
|
||||||
|
|
||||||
struct picture;
|
struct picture;
|
||||||
struct dive {
|
struct dive {
|
||||||
|
@ -762,10 +762,11 @@ extern void average_max_depth(struct diveplan *dive, int *avg_depth, int *max_de
|
||||||
* be passed through QVariants and through QML.
|
* be passed through QVariants and through QML.
|
||||||
* Note: we have to use the typedef "dive_table_t" instead of "struct dive_table",
|
* Note: we have to use the typedef "dive_table_t" instead of "struct dive_table",
|
||||||
* because MOC removes the "struct", but dive_table is already the name of a global
|
* because MOC removes the "struct", but dive_table is already the name of a global
|
||||||
* variable, leading to compilation errors. */
|
* variable, leading to compilation errors. Likewise for "struct trip_table". */
|
||||||
Q_DECLARE_METATYPE(struct dive *);
|
Q_DECLARE_METATYPE(struct dive *);
|
||||||
Q_DECLARE_METATYPE(struct dive_trip *);
|
Q_DECLARE_METATYPE(struct dive_trip *);
|
||||||
Q_DECLARE_METATYPE(dive_table_t *);
|
Q_DECLARE_METATYPE(dive_table_t *);
|
||||||
|
Q_DECLARE_METATYPE(trip_table_t *);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -307,6 +307,12 @@ struct dive_table *DownloadThread::table()
|
||||||
return &downloadTable;
|
return &downloadTable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct trip_table *DownloadThread::trips()
|
||||||
|
{
|
||||||
|
// TODO: Replace by local trip-table
|
||||||
|
return &trip_table;
|
||||||
|
}
|
||||||
|
|
||||||
QString DCDeviceData::vendor() const
|
QString DCDeviceData::vendor() const
|
||||||
{
|
{
|
||||||
return data.vendor;
|
return data.vendor;
|
||||||
|
|
|
@ -61,6 +61,7 @@ private:
|
||||||
class DownloadThread : public QThread {
|
class DownloadThread : public QThread {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(dive_table_t *table READ table CONSTANT)
|
Q_PROPERTY(dive_table_t *table READ table CONSTANT)
|
||||||
|
Q_PROPERTY(trip_table_t *trips READ trips CONSTANT)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
DownloadThread();
|
DownloadThread();
|
||||||
|
@ -68,6 +69,7 @@ public:
|
||||||
|
|
||||||
DCDeviceData *data();
|
DCDeviceData *data();
|
||||||
struct dive_table *table();
|
struct dive_table *table();
|
||||||
|
struct trip_table *trips();
|
||||||
QString error;
|
QString error;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -490,7 +490,7 @@ void DownloadFromDCWidget::onDownloadThreadFinished()
|
||||||
}
|
}
|
||||||
ui.downloadCancelRetryButton->setText(tr("Retry download"));
|
ui.downloadCancelRetryButton->setText(tr("Retry download"));
|
||||||
ui.downloadCancelRetryButton->setEnabled(true);
|
ui.downloadCancelRetryButton->setEnabled(true);
|
||||||
diveImportedModel->repopulate(thread.table());
|
diveImportedModel->repopulate(thread.table(), thread.trips());
|
||||||
}
|
}
|
||||||
|
|
||||||
void DownloadFromDCWidget::on_cancel_clicked()
|
void DownloadFromDCWidget::on_cancel_clicked()
|
||||||
|
|
|
@ -28,7 +28,7 @@ Kirigami.Page {
|
||||||
id: downloadThread
|
id: downloadThread
|
||||||
|
|
||||||
onFinished : {
|
onFinished : {
|
||||||
importModel.repopulate(table)
|
importModel.repopulate(table, trips)
|
||||||
progressBar.visible = false
|
progressBar.visible = false
|
||||||
if (dcImportModel.rowCount() > 0) {
|
if (dcImportModel.rowCount() > 0) {
|
||||||
console.log(dcImportModel.rowCount() + " dive downloaded")
|
console.log(dcImportModel.rowCount() + " dive downloaded")
|
||||||
|
|
|
@ -127,11 +127,12 @@ void DiveImportedModel::clearTable()
|
||||||
endRemoveRows();
|
endRemoveRows();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiveImportedModel::repopulate(dive_table_t *table)
|
void DiveImportedModel::repopulate(dive_table_t *table, trip_table_t *trips)
|
||||||
{
|
{
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
|
|
||||||
diveTable = table;
|
diveTable = table;
|
||||||
|
tripTable = trips;
|
||||||
firstIndex = 0;
|
firstIndex = 0;
|
||||||
lastIndex = diveTable->nr - 1;
|
lastIndex = diveTable->nr - 1;
|
||||||
checkStates.resize(diveTable->nr);
|
checkStates.resize(diveTable->nr);
|
||||||
|
|
|
@ -20,7 +20,7 @@ public:
|
||||||
Qt::ItemFlags flags(const QModelIndex &index) const;
|
Qt::ItemFlags flags(const QModelIndex &index) const;
|
||||||
Q_INVOKABLE void clearTable();
|
Q_INVOKABLE void clearTable();
|
||||||
QHash<int, QByteArray> roleNames() const;
|
QHash<int, QByteArray> roleNames() const;
|
||||||
Q_INVOKABLE void repopulate(dive_table_t *table);
|
Q_INVOKABLE void repopulate(dive_table_t *table, trip_table_t *trips);
|
||||||
Q_INVOKABLE void recordDives();
|
Q_INVOKABLE void recordDives();
|
||||||
public
|
public
|
||||||
slots:
|
slots:
|
||||||
|
@ -34,6 +34,7 @@ private:
|
||||||
int lastIndex;
|
int lastIndex;
|
||||||
std::vector<char> checkStates; // char instead of bool to avoid silly pessimization of std::vector.
|
std::vector<char> checkStates; // char instead of bool to avoid silly pessimization of std::vector.
|
||||||
struct dive_table *diveTable;
|
struct dive_table *diveTable;
|
||||||
|
struct trip_table *tripTable;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Reference in a new issue