Go to the documentation of this file.00001 #include "form.h"
00002 #include "ui_form.h"
00003 #include <QDebug>
00004 #include <QWebFrame>
00005 #include <QWebElement>
00006 #include <QMessageBox>
00007
00008
00009 Form::Form(QWidget *parent) :
00010 QWidget(parent),
00011 ui(new Ui::Form)
00012 {
00013 ui->setupUi(this);
00014 connect(ui->goButton, SIGNAL(clicked()), this, SLOT(goClicked()));
00015 connect(ui->lePostalAddress, SIGNAL(returnPressed()), this, SLOT(goClicked()));
00016
00017
00018
00019
00020 QWebSettings::globalSettings()->setAttribute(QWebSettings::PluginsEnabled, true);
00021 ui->lePostalAddress->setText("");
00022 ui->webView->setUrl(QUrl("qrc:/html/google_maps.html"));
00023 }
00024
00025 Form::~Form()
00026 {
00027 delete ui;
00028 }
00029
00030
00031 void Form::showCoordinates(double east, double north, bool saveMarker)
00032 {
00033 qDebug() << "Form, showCoordinates" << east << north;
00034
00035 QString str =
00036 QString("var newLoc = new google.maps.LatLng(%1, %2); ").arg(north).arg(east) +
00037 QString("map.setCenter(newLoc);") +
00038 QString("map.setZoom(%1);").arg(ui->zoomSpinBox->value());
00039
00040 qDebug() << str;
00041
00042 ui->webView->page()->currentFrame()->documentElement().evaluateJavaScript(str);
00043
00044 if (saveMarker)
00045 setMarker(east, north, ui->lePostalAddress->text());
00046 }
00047
00048 void Form::setMarker(double east, double north, QString caption)
00049 {
00050 for (int i=0; i<m_markers.size(); i++)
00051 {
00052 if (m_markers[i]->caption == caption) return;
00053 }
00054
00055 QString str =
00056 QString("var marker = new google.maps.Marker({") +
00057 QString("position: new google.maps.LatLng(%1, %2),").arg(north).arg(east) +
00058 QString("map: map,") +
00059 QString("title: %1").arg("\""+caption+"\"") +
00060 QString("});") +
00061 QString("markers.push(marker);");
00062 qDebug() << str;
00063 ui->webView->page()->currentFrame()->documentElement().evaluateJavaScript(str);
00064
00065
00066 SMarker *_marker = new SMarker(east, north, caption);
00067 m_markers.append(_marker);
00068
00069
00070 ui->lwMarkers->addItem(caption);
00071 }
00072
00073 void Form::goClicked()
00074 {
00075 QString address = ui->lePostalAddress->text();
00076
00077 }
00078
00079
00080
00081 void Form::errorOccured(const QString& error)
00082 {
00083 QMessageBox::warning(this, tr("Geocode Error"), error);
00084 }
00085
00086
00087
00088 void Form::on_lwMarkers_currentRowChanged(int currentRow)
00089 {
00090 if (currentRow < 0) return;
00091 QString str =
00092 QString("var newLoc = new google.maps.LatLng(%1, %2); ").arg(m_markers[currentRow]->north).arg(m_markers[currentRow]->east) +
00093 QString("map.setCenter(newLoc);");
00094
00095 qDebug() << str;
00096
00097 ui->webView->page()->currentFrame()->documentElement().evaluateJavaScript(str);
00098 }
00099
00100 void Form::on_pbRemoveMarker_clicked()
00101 {
00102 if (ui->lwMarkers->currentRow() < 0) return;
00103
00104 QString str =
00105 QString("markers[%1].setMap(null); markers.splice(%1, 1);").arg(ui->lwMarkers->currentRow());
00106 qDebug() << str;
00107 ui->webView->page()->currentFrame()->documentElement().evaluateJavaScript(str);
00108
00109
00110 delete m_markers.takeAt(ui->lwMarkers->currentRow());
00111
00112 delete ui->lwMarkers->takeItem(ui->lwMarkers->currentRow());
00113
00114 }
00115
00116 void Form::on_zoomSpinBox_valueChanged(int arg1)
00117 {
00118
00119
00120
00121
00122 }