| 
									
										
										
										
											2017-07-17 17:58:34 +03:00
										 |  |  | // SPDX-License-Identifier: GPL-2.0
 | 
					
						
							|  |  |  | #ifndef MAPLOCATIONMODEL_H
 | 
					
						
							|  |  |  | #define MAPLOCATIONMODEL_H
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-03 19:33:06 +01:00
										 |  |  | #include "core/subsurface-qt/divelistnotifier.h"
 | 
					
						
							| 
									
										
										
										
											2017-07-17 17:58:34 +03:00
										 |  |  | #include <QObject>
 | 
					
						
							| 
									
										
										
										
											2017-07-17 23:04:00 +03:00
										 |  |  | #include <QVector>
 | 
					
						
							| 
									
										
										
										
											2017-07-17 17:58:34 +03:00
										 |  |  | #include <QHash>
 | 
					
						
							|  |  |  | #include <QByteArray>
 | 
					
						
							|  |  |  | #include <QAbstractListModel>
 | 
					
						
							| 
									
										
										
										
											2017-07-17 22:36:55 +03:00
										 |  |  | #include <QGeoCoordinate>
 | 
					
						
							| 
									
										
										
										
											2017-07-17 17:58:34 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-01 00:24:18 +02:00
										 |  |  | class MapLocation | 
					
						
							| 
									
										
										
										
											2017-07-17 17:58:34 +03:00
										 |  |  | { | 
					
						
							|  |  |  | public: | 
					
						
							| 
									
										
										
										
											2019-08-30 15:25:59 +02:00
										 |  |  | 	explicit MapLocation(struct dive_site *ds, QGeoCoordinate coord, QString name, bool selected); | 
					
						
							| 
									
										
										
										
											2017-07-17 17:58:34 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	QVariant getRole(int role) const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	enum Roles { | 
					
						
							| 
									
										
										
										
											2018-10-26 17:03:54 +02:00
										 |  |  | 		RoleDivesite = Qt::UserRole + 1, | 
					
						
							| 
									
										
										
										
											2017-07-25 23:15:28 +03:00
										 |  |  | 		RoleCoordinate, | 
					
						
							| 
									
										
										
										
											2019-08-30 15:25:59 +02:00
										 |  |  | 		RoleName, | 
					
						
							| 
									
										
										
										
											2019-08-30 18:09:37 +02:00
										 |  |  | 		RolePixmap, | 
					
						
							| 
									
										
										
										
											2019-08-31 23:24:21 +02:00
										 |  |  | 		RoleZ, | 
					
						
							|  |  |  | 		RoleIsSelected | 
					
						
							| 
									
										
										
										
											2017-07-17 17:58:34 +03:00
										 |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-01 00:18:15 +02:00
										 |  |  | 	struct dive_site *divesite; | 
					
						
							|  |  |  | 	QGeoCoordinate coordinate; | 
					
						
							|  |  |  | 	QString name; | 
					
						
							| 
									
										
										
										
											2019-09-01 00:26:51 +02:00
										 |  |  | 	bool selected; | 
					
						
							| 
									
										
										
										
											2017-07-17 17:58:34 +03:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class MapLocationModel : public QAbstractListModel | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	Q_OBJECT | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  | 	MapLocationModel(QObject *parent = NULL); | 
					
						
							|  |  |  | 	~MapLocationModel(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-29 22:13:44 +02:00
										 |  |  | 	QVariant data(const QModelIndex &index, int role) const override; | 
					
						
							|  |  |  | 	int rowCount(const QModelIndex &parent) const override; | 
					
						
							| 
									
										
										
										
											2017-07-17 22:12:04 +03:00
										 |  |  | 	void add(MapLocation *); | 
					
						
							| 
									
										
										
										
											2019-05-08 22:15:01 +02:00
										 |  |  | 	// If map is not null, it will be used to place new dive sites without GPS location at the center of the map
 | 
					
						
							|  |  |  | 	void reload(QObject *map); | 
					
						
							| 
									
										
										
										
											2019-08-30 16:51:59 +02:00
										 |  |  | 	void selectionChanged(); | 
					
						
							| 
									
										
										
										
											2019-08-30 17:38:54 +02:00
										 |  |  | 	void setSelected(const QVector<dive_site *> &divesites); | 
					
						
							| 
									
										
										
										
											2018-10-26 17:03:54 +02:00
										 |  |  | 	MapLocation *getMapLocation(const struct dive_site *ds); | 
					
						
							| 
									
										
										
										
											2019-05-03 23:16:40 +02:00
										 |  |  | 	const QVector<dive_site *> &selectedDs() const; | 
					
						
							| 
									
										
										
										
											2019-08-31 23:34:17 +02:00
										 |  |  | 	void setSelected(struct dive_site *ds); | 
					
						
							| 
									
										
										
										
											2017-07-17 17:58:34 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | protected: | 
					
						
							| 
									
										
										
										
											2018-09-29 22:13:44 +02:00
										 |  |  | 	QHash<int, QByteArray> roleNames() const override; | 
					
						
							| 
									
										
										
										
											2017-07-17 17:58:34 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-09 21:33:01 +02:00
										 |  |  | private slots: | 
					
						
							|  |  |  | 	void diveSiteChanged(struct dive_site *ds, int field); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-24 21:17:11 +03:00
										 |  |  | private: | 
					
						
							| 
									
										
										
										
											2017-07-17 23:04:00 +03:00
										 |  |  | 	QVector<MapLocation *> m_mapLocations; | 
					
						
							| 
									
										
										
										
											2019-05-02 00:09:59 +02:00
										 |  |  | 	QVector<dive_site *> m_selectedDs; | 
					
						
							| 
									
										
										
										
											2017-07-17 17:58:34 +03:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif
 |