2017-04-27 20:26:05 +02:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2015-05-17 16:13:41 -03:00
|
|
|
#ifndef LOCATIONINFORMATION_H
|
|
|
|
#define LOCATIONINFORMATION_H
|
|
|
|
|
2018-10-08 13:51:57 +02:00
|
|
|
#include "core/units.h"
|
2019-02-01 20:40:57 +01:00
|
|
|
#include "ui_locationinformation.h"
|
2019-04-25 09:35:46 +02:00
|
|
|
#include "modeldelegates.h"
|
2018-10-08 19:01:45 +02:00
|
|
|
#include "qt-models/divelocationmodel.h"
|
2015-05-17 16:13:41 -03:00
|
|
|
#include <stdint.h>
|
2015-05-17 16:33:23 -03:00
|
|
|
#include <QAbstractListModel>
|
2015-09-21 14:01:58 -03:00
|
|
|
#include <QSortFilterProxyModel>
|
2015-05-17 16:33:23 -03:00
|
|
|
|
2020-08-17 22:09:26 +02:00
|
|
|
struct dive_site;
|
2020-05-01 13:51:29 +02:00
|
|
|
|
2015-05-17 16:13:41 -03:00
|
|
|
class LocationInformationWidget : public QGroupBox {
|
2019-03-12 07:24:54 +01:00
|
|
|
Q_OBJECT
|
2015-05-17 16:13:41 -03:00
|
|
|
public:
|
|
|
|
LocationInformationWidget(QWidget *parent = 0);
|
2018-09-29 22:13:44 +02:00
|
|
|
bool eventFilter(QObject*, QEvent*) override;
|
2018-10-13 08:57:46 +02:00
|
|
|
void initFields(dive_site *ds);
|
2020-01-19 12:06:50 -08:00
|
|
|
Ui::LocationInformation ui;
|
2015-08-31 21:11:28 -03:00
|
|
|
|
2015-05-17 17:14:23 -03:00
|
|
|
protected:
|
2017-11-27 00:26:46 +02:00
|
|
|
void enableLocationButtons(bool enable);
|
2015-05-26 17:36:06 -03:00
|
|
|
|
2015-05-17 16:13:41 -03:00
|
|
|
public slots:
|
|
|
|
void acceptChanges();
|
2019-03-14 08:26:50 +01:00
|
|
|
void on_diveSiteCountry_editingFinished();
|
2019-03-14 22:07:48 +01:00
|
|
|
void on_diveSiteCoordinates_editingFinished();
|
2020-02-04 10:03:41 +01:00
|
|
|
void on_diveSiteCoordinates_textEdited(const QString &s);
|
2019-03-13 22:49:34 +01:00
|
|
|
void on_diveSiteDescription_editingFinished();
|
|
|
|
void on_diveSiteName_editingFinished();
|
2019-03-14 00:00:54 +01:00
|
|
|
void on_diveSiteNotes_editingFinished();
|
2019-03-25 22:18:32 +01:00
|
|
|
void on_diveSiteDistance_textChanged(const QString &s);
|
2015-08-25 18:45:29 -03:00
|
|
|
void reverseGeocode();
|
2015-08-31 21:35:17 -03:00
|
|
|
void mergeSelectedDiveSites();
|
2020-01-19 12:06:50 -08:00
|
|
|
void on_GPSbutton_clicked();
|
2015-06-03 23:50:36 -03:00
|
|
|
private slots:
|
2015-07-25 13:03:14 -03:00
|
|
|
void updateLabels();
|
2019-03-12 23:51:39 +01:00
|
|
|
void diveSiteChanged(struct dive_site *ds, int field);
|
2019-09-06 22:01:59 +02:00
|
|
|
void diveSiteDeleted(struct dive_site *ds, int);
|
2019-03-25 22:18:32 +01:00
|
|
|
void unitsChanged();
|
2015-05-17 16:13:41 -03:00
|
|
|
private:
|
2019-03-16 10:44:39 +01:00
|
|
|
void keyPressEvent(QKeyEvent *e) override;
|
2017-10-06 12:06:13 -07:00
|
|
|
void clearLabels();
|
2020-02-04 10:03:41 +01:00
|
|
|
void coordinatesSetWarning(bool warn);
|
2018-10-08 19:01:45 +02:00
|
|
|
GPSLocationInformationModel filter_model;
|
2018-10-13 13:14:48 +02:00
|
|
|
dive_site *diveSite;
|
2019-03-25 22:18:32 +01:00
|
|
|
int64_t closeDistance; // Distance of "close" dive sites in mm
|
2015-05-17 16:13:41 -03:00
|
|
|
};
|
|
|
|
|
2015-09-21 14:01:58 -03:00
|
|
|
class DiveLocationFilterProxyModel : public QSortFilterProxyModel {
|
|
|
|
Q_OBJECT
|
2019-04-15 20:15:40 +02:00
|
|
|
QString filter;
|
2015-09-21 14:01:58 -03:00
|
|
|
public:
|
|
|
|
DiveLocationFilterProxyModel(QObject *parent = 0);
|
2018-09-29 22:13:44 +02:00
|
|
|
bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const override;
|
|
|
|
bool lessThan(const QModelIndex& source_left, const QModelIndex& source_right) const override;
|
2019-04-15 20:15:40 +02:00
|
|
|
void setFilter(const QString &filter);
|
2019-04-25 00:26:48 +02:00
|
|
|
void setCurrentLocation(location_t loc);
|
|
|
|
private:
|
|
|
|
location_t currentLocation; // Sort by distance to that location
|
2015-09-21 14:01:58 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
class DiveLocationModel : public QAbstractTableModel {
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
DiveLocationModel(QObject *o = 0);
|
|
|
|
void resetModel();
|
|
|
|
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
|
|
|
|
int rowCount(const QModelIndex& parent = QModelIndex()) const;
|
|
|
|
int columnCount(const QModelIndex& parent = QModelIndex()) const;
|
|
|
|
bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole);
|
|
|
|
private:
|
|
|
|
QString new_ds_value[2];
|
|
|
|
};
|
|
|
|
|
|
|
|
class DiveLocationListView : public QListView {
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
DiveLocationListView(QWidget *parent = 0);
|
2015-09-25 13:21:23 -03:00
|
|
|
protected:
|
2018-09-29 22:13:44 +02:00
|
|
|
void currentChanged(const QModelIndex& current, const QModelIndex& previous) override;
|
2015-09-25 13:21:23 -03:00
|
|
|
signals:
|
|
|
|
void currentIndexChanged(const QModelIndex& current);
|
2015-09-21 14:01:58 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
class DiveLocationLineEdit : public QLineEdit {
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
DiveLocationLineEdit(QWidget *parent =0 );
|
|
|
|
void refreshDiveSiteCache();
|
|
|
|
void setTemporaryDiveSiteName(const QString& s);
|
2015-09-21 16:51:39 -03:00
|
|
|
bool eventFilter(QObject*, QEvent*);
|
2015-09-21 17:18:52 -03:00
|
|
|
void itemActivated(const QModelIndex& index);
|
2018-10-25 08:02:06 +02:00
|
|
|
struct dive_site *currDiveSite() const;
|
2015-09-23 16:03:28 -03:00
|
|
|
void fixPopupPosition();
|
2019-04-25 00:26:48 +02:00
|
|
|
void setCurrentDiveSite(struct dive *d);
|
2019-04-25 13:16:30 +02:00
|
|
|
void showAllSites();
|
2015-09-25 13:11:44 -03:00
|
|
|
|
2015-09-23 14:46:29 -03:00
|
|
|
signals:
|
2018-10-24 21:14:57 +02:00
|
|
|
void diveSiteSelected();
|
2015-09-25 13:11:44 -03:00
|
|
|
void entered(const QModelIndex& index);
|
2015-09-25 13:21:23 -03:00
|
|
|
void currentChanged(const QModelIndex& index);
|
2015-09-23 14:46:29 -03:00
|
|
|
|
2015-09-21 16:08:58 -03:00
|
|
|
protected:
|
|
|
|
void keyPressEvent(QKeyEvent *ev);
|
2015-09-22 15:23:38 -03:00
|
|
|
void focusOutEvent(QFocusEvent *ev);
|
2015-09-21 16:08:58 -03:00
|
|
|
void showPopup();
|
2015-09-23 14:57:55 -03:00
|
|
|
|
2015-09-21 14:01:58 -03:00
|
|
|
private:
|
2015-09-25 14:51:10 -03:00
|
|
|
using QLineEdit::setText;
|
2015-09-21 14:01:58 -03:00
|
|
|
DiveLocationFilterProxyModel *proxy;
|
|
|
|
DiveLocationModel *model;
|
|
|
|
DiveLocationListView *view;
|
2019-04-25 09:35:46 +02:00
|
|
|
LocationFilterDelegate delegate;
|
2018-10-25 08:02:06 +02:00
|
|
|
struct dive_site *currDs;
|
2015-09-21 14:01:58 -03:00
|
|
|
};
|
|
|
|
|
2015-05-17 16:13:41 -03:00
|
|
|
#endif
|