summaryrefslogtreecommitdiffstats
path: root/src/ui/locationui.cpp
blob: 5355a7cf6eb389d87df59c8047273484e5254d91 (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
/**************************************************************************
**
** This file is part of Qt Simulator
**
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** No Commercial Usage
**
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** 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.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights.  These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**************************************************************************/

#include "locationui.h"

#include "optionsitem.h"
#include "configurationwidget.h"
#include "location.h"

#include <location/qlocationdata_simulator_p.h>

#include <QtGui/QLineEdit>
#include <QtGui/QDoubleValidator>
#include <QtGui/QPushButton>
#include <QtGui/QBoxLayout>
#include <QtGui/QDateTimeEdit>

LocationUi::LocationUi(ConfigurationWidget *w, Location *location)
    : QObject(w)
    , mLocation(location)
    , mLatitudeEdit(0)
    , mLongitudeEdit(0)
    , mAltitudeEdit(0)
    , mTimeEdit(0)
{
    QStringList tags;
    QList<OptionsItem *> optionsList;

    mLatitudeEdit = new QLineEdit("52.5056819");
    mLatitudeEdit->setValidator(new QDoubleValidator(-90, 90, 10, this));
    OptionsItem *item = new OptionsItem(tr("Latitude"), mLatitudeEdit);
    connect(mLatitudeEdit, SIGNAL(editingFinished()), SLOT(triggerLocationInfoChange()));
    item->setTags(tags);
    optionsList << item;

    mLongitudeEdit = new QLineEdit("13.3232027");
    mLatitudeEdit->setValidator(new QDoubleValidator(-180, 180, 10, this));
    item = new OptionsItem(tr("Longitude"), mLongitudeEdit);
    connect(mLongitudeEdit, SIGNAL(editingFinished()), SLOT(triggerLocationInfoChange()));
    item->setTags(tags);
    optionsList << item;

    mAltitudeEdit = new QLineEdit("13.3232027");
    mAltitudeEdit->setValidator(new QDoubleValidator(-15000, 15000, 10, this));
    item = new OptionsItem(tr("Altitude"), mAltitudeEdit);
    connect(mAltitudeEdit, SIGNAL(editingFinished()), SLOT(triggerLocationInfoChange()));
    item->setTags(tags);
    optionsList << item;

    mTimeEdit = new QDateTimeEdit();
    QPushButton *locationTimeButton = new QPushButton(tr("Now"));
    QHBoxLayout *hLayout = new QHBoxLayout();
    hLayout->setContentsMargins(0, 0, 0, 0);
    QVBoxLayout *vLayout = new QVBoxLayout();
    vLayout->addWidget(mTimeEdit);
    vLayout->addWidget(locationTimeButton);
    hLayout->addLayout(vLayout);
    QWidget *tmp = new QWidget();
    tmp->setLayout(hLayout);
    connect(mTimeEdit, SIGNAL(dateTimeChanged(const QDateTime &)), SLOT(triggerLocationInfoChange()));
    connect(locationTimeButton, SIGNAL(clicked()), this, SLOT(updateLocationTime()));
    item = new OptionsItem(tr("Timestamp"), tmp);
    item->setTags(tags);
    optionsList << item;
    connect(mLocation, SIGNAL(locationChanged(QGeoPositionInfoData)), this, SLOT(locationSetData()));

    w->addToolBoxPage(tr("Location"), optionsList);
}

void LocationUi::triggerLocationInfoChange()
{
    mLocation->setLatitude(mLatitudeEdit->text().toDouble());
    mLocation->setLongitude(mLongitudeEdit->text().toDouble());
    mLocation->setAltitude(mAltitudeEdit->text().toDouble());
    mLocation->setDateTime(mTimeEdit->dateTime());
    mLocation->publish();
}

void LocationUi::updateLocationTime()
{
    mTimeEdit->setDateTime(QDateTime::currentDateTime());
}

void LocationUi::locationSetData()
{
    mLatitudeEdit->setText(QString::number(mLocation->latitude(), 'f', 8));
    mLongitudeEdit->setText(QString::number(mLocation->longitude(), 'f', 8));
    mAltitudeEdit->setText(QString::number(mLocation->altitude(), 'f', 8));
    mTimeEdit->setDateTime(mLocation->dateTime());
}