| 
									
										
										
										
											2017-04-18 17:32:10 +02:00
										 |  |  | #ifndef DIVEIMPORTEDMODEL_H
 | 
					
						
							|  |  |  | #define DIVEIMPORTEDMODEL_H
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-17 16:07:39 +02:00
										 |  |  | #include "core/device.h"
 | 
					
						
							| 
									
										
										
										
											2019-03-04 23:20:29 +01:00
										 |  |  | #include "core/divesite.h"
 | 
					
						
							| 
									
										
										
										
											2019-11-16 22:24:06 +01:00
										 |  |  | #include "core/divelist.h"
 | 
					
						
							| 
									
										
										
										
											2019-09-25 20:49:13 +02:00
										 |  |  | #include "core/downloadfromdcthread.h"
 | 
					
						
							| 
									
										
										
										
											2020-10-17 16:07:39 +02:00
										 |  |  | #include <QAbstractTableModel>
 | 
					
						
							| 
									
										
										
										
											2017-04-18 17:32:10 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | class DiveImportedModel : public QAbstractTableModel | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	Q_OBJECT | 
					
						
							|  |  |  | public: | 
					
						
							| 
									
										
										
										
											2017-06-04 14:40:25 +02:00
										 |  |  | 	enum roleTypes { DateTime = Qt::UserRole + 1, Duration, Depth, Selected}; | 
					
						
							| 
									
										
										
										
											2017-05-26 17:53:25 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	DiveImportedModel(QObject *parent = 0); | 
					
						
							| 
									
										
										
										
											2017-04-18 17:32:10 +02:00
										 |  |  | 	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; | 
					
						
							| 
									
										
										
										
											2020-03-11 11:30:51 +01:00
										 |  |  | 	void setImportedDivesIndices(int first, int last); | 
					
						
							| 
									
										
										
										
											2017-04-18 17:32:10 +02:00
										 |  |  | 	Qt::ItemFlags flags(const QModelIndex &index) const; | 
					
						
							| 
									
										
										
										
											2017-06-16 01:22:44 -07:00
										 |  |  | 	Q_INVOKABLE void clearTable(); | 
					
						
							| 
									
										
										
										
											2017-05-26 17:53:25 +02:00
										 |  |  | 	QHash<int, QByteArray> roleNames() const; | 
					
						
							| 
									
										
										
										
											2019-09-22 18:50:10 +02:00
										 |  |  | 	void deleteDeselected(); | 
					
						
							| 
									
										
										
										
											2020-10-17 16:07:39 +02:00
										 |  |  | 	std::tuple<struct dive_table, struct dive_site_table, struct device_table> consumeTables(); // Returns downloaded tables and resets model.
 | 
					
						
							| 
									
										
										
										
											2019-09-22 21:48:46 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-22 21:00:15 +02:00
										 |  |  | 	int numDives() const; | 
					
						
							| 
									
										
										
										
											2019-11-16 22:24:06 +01:00
										 |  |  | 	Q_INVOKABLE void recordDives(int flags = IMPORT_PREFER_IMPORTED | IMPORT_IS_DOWNLOADED); | 
					
						
							| 
									
										
										
										
											2019-09-25 20:49:13 +02:00
										 |  |  | 	Q_INVOKABLE void startDownload(); | 
					
						
							| 
									
										
										
										
											2020-11-23 17:17:17 +01:00
										 |  |  | 	Q_INVOKABLE void waitForDownload(); | 
					
						
							| 
									
										
										
										
											2019-09-25 20:49:13 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	DownloadThread thread; | 
					
						
							| 
									
										
										
										
											2017-04-18 17:32:10 +02:00
										 |  |  | public | 
					
						
							|  |  |  | slots: | 
					
						
							|  |  |  | 	void changeSelected(QModelIndex clickedIndex); | 
					
						
							| 
									
										
										
										
											2017-05-29 20:36:00 +02:00
										 |  |  | 	void selectRow(int row); | 
					
						
							| 
									
										
										
										
											2017-04-18 17:32:10 +02:00
										 |  |  | 	void selectAll(); | 
					
						
							|  |  |  | 	void selectNone(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-25 20:49:13 +02:00
										 |  |  | private | 
					
						
							|  |  |  | slots: | 
					
						
							|  |  |  | 	void downloadThreadFinished(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | signals: | 
					
						
							|  |  |  | 	void downloadFinished(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-18 17:32:10 +02:00
										 |  |  | private: | 
					
						
							| 
									
										
										
										
											2018-12-09 19:10:55 +01:00
										 |  |  | 	std::vector<char> checkStates; // char instead of bool to avoid silly pessimization of std::vector.
 | 
					
						
							| 
									
										
										
										
											2019-09-22 21:48:46 +02:00
										 |  |  | 	struct dive_table diveTable; | 
					
						
							|  |  |  | 	struct dive_site_table sitesTable; | 
					
						
							| 
									
										
										
										
											2020-10-17 16:07:39 +02:00
										 |  |  | 	struct device_table deviceTable; | 
					
						
							| 
									
										
										
										
											2017-04-18 17:32:10 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif
 |