-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathform.cpp
124 lines (93 loc) · 3.62 KB
/
form.cpp
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
#include "form.h"
#include "ui_form.h"
#include <QDebug>
#include <QWebFrame>
#include <QWebElement>
#include <QMessageBox>
Form::Form(QWidget *parent) :
QWidget(parent),
ui(new Ui::Form)
{
ui->setupUi(this);
connect(ui->goButton, SIGNAL(clicked()), this, SLOT(goClicked()));
connect(ui->lePostalAddress, SIGNAL(returnPressed()), this, SLOT(goClicked()));
connect(&m_geocodeDataManager, SIGNAL(coordinatesReady(double,double)), this, SLOT(showCoordinates(double,double)));
connect(&m_geocodeDataManager, SIGNAL(errorOccured(QString)), this, SLOT(errorOccured(QString)));
connect(&m_geocodeDataManager, SIGNAL(addressReady(QString)), ui->lePostalAddress, SLOT(setText(QString)));
QWebSettings::globalSettings()->setAttribute(QWebSettings::PluginsEnabled, true);
ui->lePostalAddress->setText("");
ui->webView->setUrl(QUrl("qrc:/html/google_maps.html"));
}
Form::~Form()
{
delete ui;
}
void Form::showCoordinates(double east, double north, bool saveMarker)
{
qDebug() << "Form, showCoordinates" << east << north;
QString str =
QString("var newLoc = new google.maps.LatLng(%1, %2); ").arg(north).arg(east) +
QString("map.setCenter(newLoc);") +
QString("map.setZoom(%1);").arg(ui->zoomSpinBox->value());
qDebug() << str;
ui->webView->page()->currentFrame()->documentElement().evaluateJavaScript(str);
if (saveMarker)
setMarker(east, north, ui->lePostalAddress->text());
}
void Form::setMarker(double east, double north, QString caption)
{
for (int i=0; i<m_markers.size(); i++)
{
if (m_markers[i]->caption == caption) return;
}
QString str =
QString("var marker = new google.maps.Marker({") +
QString("position: new google.maps.LatLng(%1, %2),").arg(north).arg(east) +
QString("map: map,") +
QString("title: %1").arg("\""+caption+"\"") +
QString("});") +
QString("markers.push(marker);");
qDebug() << str;
ui->webView->page()->currentFrame()->documentElement().evaluateJavaScript(str);
SMarker *_marker = new SMarker(east, north, caption);
m_markers.append(_marker);
//adding capton to ListWidget
ui->lwMarkers->addItem(caption);
}
void Form::goClicked()
{
QString address = ui->lePostalAddress->text();
m_geocodeDataManager.getCoordinates(address.replace(" ", "+"));
}
void Form::errorOccured(const QString& error)
{
QMessageBox::warning(this, tr("Geocode Error"), error);
}
void Form::on_lwMarkers_currentRowChanged(int currentRow)
{
if (currentRow < 0) return;
QString str =
QString("var newLoc = new google.maps.LatLng(%1, %2); ").arg(m_markers[currentRow]->north).arg(m_markers[currentRow]->east) +
QString("map.setCenter(newLoc);");
qDebug() << str;
ui->webView->page()->currentFrame()->documentElement().evaluateJavaScript(str);
}
void Form::on_pbRemoveMarker_clicked()
{
if (ui->lwMarkers->currentRow() < 0) return;
QString str =
QString("markers[%1].setMap(null); markers.splice(%1, 1);").arg(ui->lwMarkers->currentRow());
qDebug() << str;
ui->webView->page()->currentFrame()->documentElement().evaluateJavaScript(str);
//deleteing caption from markers list
delete m_markers.takeAt(ui->lwMarkers->currentRow());
//deleteing caption from ListWidget
delete ui->lwMarkers->takeItem(ui->lwMarkers->currentRow());
}
void Form::on_zoomSpinBox_valueChanged(int arg1)
{
// QString str =
// QString("map.setZoom(%1);").arg(arg1);
// qDebug() << str;
// ui->webView->page()->currentFrame()->documentElement().evaluateJavaScript(str);
}