summaryrefslogtreecommitdiffstats
path: root/library/components/locationui.h
blob: 1c0440c763555c04a85f6cccc4c7f87cb5f2c60e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/**************************************************************************
**
** This file is part of Remote Control Widget
**
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/

#ifndef LOCATIONUI_H
#define LOCATIONUI_H

#include "remotecontrolwidget_global.h"
#include "toolbox.h"

#include <QtCore/QDateTime>
#include <QtCore/QHash>

class LocationScriptInterface;
class QLineEdit;
class QDateTimeEdit;
class QRadioButton;
class QComboBox;
class QCheckBox;

class REMOTECONTROLWIDGETSHARED_EXPORT LocationUi : public ToolBoxPage
{
    Q_OBJECT
public:
    struct LocationData
    {
        double latitude;
        double longitude;
        double altitude;
        QDateTime timestamp;
        bool useCurrentTime;
    };

    struct SatelliteData {
        struct SatelliteInfo
        {
            SatelliteInfo() : elevation(0), azimuth(0), signalStrength(0), inUse(false){}
            int prn;
            qreal elevation;
            qreal azimuth;
            int signalStrength;
            bool inUse;
        };

        QList<SatelliteInfo> satellites;
    };

public:
    explicit LocationUi(QWidget *parent = 0);
    virtual ~LocationUi();

    LocationScriptInterface *scriptInterface() const;

    LocationData locationData() const;
    SatelliteData satelliteData() const;

public slots:
    void setLocation(const LocationUi::LocationData &location);
    void setDisplayedLocation(const LocationUi::LocationData &location);

    void setSatelliteData(const LocationUi::SatelliteData &data);
    void setDisplayedSatelliteData(const LocationUi::SatelliteData &data);

signals:
    void locationChanged(const LocationUi::LocationData &location) const;
    void satelliteDataChanged(const LocationUi::SatelliteData &data) const;

private slots:
    void updateLocationTime();
    void updateTimeEditDisabled();
    void emitLocationChange() const;

    void emitSatelliteDataChange() const;
    void showSatelliteInfo();
    void editSatelliteInfo();
    void updateSatelliteList(int satelliteToShow = 0);

    void addDisplayedSatellite(int prn);
    bool removeDisplayedSatellite(int prn);
    bool renumberDisplayedSatellite(int oldPrn, int newPrn);

    void changeSatellitePrnClicked();
    void addSatelliteClicked();
    void removeSatelliteClicked();

private:
    QLineEdit *mLatitudeEdit;
    QLineEdit *mLongitudeEdit;
    QLineEdit *mAltitudeEdit;
    QRadioButton *mCurrentRadio;
    QRadioButton *mOverrideRadio;
    QDateTimeEdit *mTimeEdit;

    QComboBox *satellitePrns;
    QLineEdit *satelliteElevation;
    QLineEdit *satelliteAzimuth;
    QLineEdit *satelliteSignalStrength;
    QCheckBox *satelliteInUse;

    friend class LocationScriptInterface;
    LocationScriptInterface *mScriptInterface;

    SatelliteData mSatelliteData;
};

class LocationScriptInterface : public QObject
{
    Q_OBJECT
public:
    LocationScriptInterface(LocationUi *ui);
    virtual ~LocationScriptInterface();

    Q_PROPERTY(double latitude READ latitude WRITE setLatitude)
    Q_PROPERTY(double longitude READ longitude WRITE setLongitude)
    Q_PROPERTY(double altitude READ altitude WRITE setAltitude)
    Q_PROPERTY(bool useCurrentTimestamp READ useCurrentTimestamp WRITE setUseCurrentTimestamp)
    Q_PROPERTY(QDateTime timestamp READ timestamp WRITE setTimestamp)

    Q_INVOKABLE QList<int> satellites() const;
    Q_INVOKABLE qreal elevation(int satellite) const;
    Q_INVOKABLE qreal azimuth(int satellite) const;
    Q_INVOKABLE int signalStrength(int satellite) const;
    Q_INVOKABLE bool inUse(int satellite) const;

    double latitude() const;
    void setLatitude(double);

    double longitude() const;
    void setLongitude(double);

    double altitude() const;
    void setAltitude(double);

    bool useCurrentTimestamp() const;
    void setUseCurrentTimestamp(bool);

    QDateTime timestamp() const;
    void setTimestamp(const QDateTime &dt);

public slots:
    bool addSatellite(int prn);
    bool addSatellite(int prn, qreal elevation, qreal azimuth, int signalStrength, bool inUse);
    bool removeSatellite(int prn);
    bool setPrn(int oldPrn, int newPrn);
    bool setElevation(int prn, qreal elevation);
    bool setAzimuth(int prn, qreal azimuth);
    bool setSignalStrength(int prn, int signalStrength);
    bool setInUse(int prn, bool inUse);

private:
    LocationUi *ui;
};

#endif // LOCATIONUI_H