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