mirror of
https://github.com/subsurface/subsurface.git
synced 2024-12-01 06:30:26 +00:00
087a80194a
The DiveImportedModel and DownloadThread used the same table of dives and dive sites. This made it very hard to keep the model consistent: Every modification of the download thread would make the model inconsistent and could lead to memory corruption owing to dangling pointers. Therefore, keep a copy in the model. When updating the model, use move-semantics, i.e. move the data and reset the tables of the thread to zero elements. Since the DiveImportedModel and the DownloadThread are very tightly integrated, remove the accessor-functions of the dive and dive-site tables. They fulfilled no purpose whatsoever as they gave the same access-rights as a public field. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
54 lines
1.5 KiB
C++
54 lines
1.5 KiB
C++
#ifndef DIVEIMPORTEDMODEL_H
|
|
#define DIVEIMPORTEDMODEL_H
|
|
|
|
#include <QAbstractTableModel>
|
|
#include <vector>
|
|
#include "core/divesite.h"
|
|
#include "core/downloadfromdcthread.h"
|
|
|
|
class DiveImportedModel : public QAbstractTableModel
|
|
{
|
|
Q_OBJECT
|
|
public:
|
|
enum roleTypes { DateTime = Qt::UserRole + 1, Duration, Depth, Selected};
|
|
|
|
DiveImportedModel(QObject *parent = 0);
|
|
int columnCount(const QModelIndex& index = QModelIndex()) const;
|
|
int rowCount(const QModelIndex& index = QModelIndex()) const;
|
|
QVariant data(const QModelIndex& index, int role) const;
|
|
QVariant headerData(int section, Qt::Orientation orientation, int role) const;
|
|
void setImportedDivesIndexes(int first, int last);
|
|
Qt::ItemFlags flags(const QModelIndex &index) const;
|
|
Q_INVOKABLE void clearTable();
|
|
QHash<int, QByteArray> roleNames() const;
|
|
void deleteDeselected();
|
|
std::pair<struct dive_table, struct dive_site_table> consumeTables(); // Returns dives and sites and resets model.
|
|
|
|
int numDives() const;
|
|
Q_INVOKABLE void recordDives();
|
|
Q_INVOKABLE void startDownload();
|
|
|
|
DownloadThread thread;
|
|
public
|
|
slots:
|
|
void changeSelected(QModelIndex clickedIndex);
|
|
void selectRow(int row);
|
|
void selectAll();
|
|
void selectNone();
|
|
|
|
private
|
|
slots:
|
|
void downloadThreadFinished();
|
|
|
|
signals:
|
|
void downloadFinished();
|
|
|
|
private:
|
|
int firstIndex;
|
|
int lastIndex;
|
|
std::vector<char> checkStates; // char instead of bool to avoid silly pessimization of std::vector.
|
|
struct dive_table diveTable;
|
|
struct dive_site_table sitesTable;
|
|
};
|
|
|
|
#endif
|