1
0
mirror of git://projects.qi-hardware.com/nanomap.git synced 2024-11-24 17:19:21 +02:00

use monav plugin to do address look ups

This commit is contained in:
Niels 2010-11-04 21:01:35 +01:00
parent 889c3fbc87
commit a8c63604ae
8 changed files with 201 additions and 211 deletions

View File

@ -20,7 +20,7 @@ SOURCES += main.cpp \
mapwidget.cpp \ mapwidget.cpp \
markerlist.cpp \ markerlist.cpp \
downloadwidget.cpp \ downloadwidget.cpp \
routingwidget.cpp \ searchwidget.cpp \
gpsclient.cpp gpsclient.cpp
HEADERS += mainwidget.h \ HEADERS += mainwidget.h \
@ -36,5 +36,5 @@ HEADERS += mainwidget.h \
mapwidget.h \ mapwidget.h \
markerlist.h \ markerlist.h \
downloadwidget.h \ downloadwidget.h \
routingwidget.h \ searchwidget.h \
gpsclient.h gpsclient.h

View File

@ -22,7 +22,7 @@
#include "downloadwidget.h" #include "downloadwidget.h"
#include "mapwidget.h" #include "mapwidget.h"
#include "markerlist.h" #include "markerlist.h"
#include "routingwidget.h" #include "searchwidget.h"
#include "batterylayer.h" #include "batterylayer.h"
#include "gpslayer.h" #include "gpslayer.h"
@ -42,7 +42,7 @@ MainWidget::MainWidget(QWidget *parent)
m_map(new MapWidget(this)), m_map(new MapWidget(this)),
m_markerList(new MarkerList(this)), m_markerList(new MarkerList(this)),
m_dlWidget(new DownloadWidget(this)), m_dlWidget(new DownloadWidget(this)),
m_routingWidget(new RoutingWidget(this)) m_search(new SearchWidget(this))
{ {
QHBoxLayout *layout = new QHBoxLayout(this); QHBoxLayout *layout = new QHBoxLayout(this);
layout->setContentsMargins(0, 0, 0, 0); layout->setContentsMargins(0, 0, 0, 0);
@ -73,7 +73,7 @@ MainWidget::MainWidget(QWidget *parent)
connect(m_map, SIGNAL(close()), this, SIGNAL(close())); connect(m_map, SIGNAL(close()), this, SIGNAL(close()));
connect(m_map, SIGNAL(showMarkerList()), this, SLOT(showList())); connect(m_map, SIGNAL(showMarkerList()), this, SLOT(showList()));
connect(m_map, SIGNAL(downloadArea(int, QRectF)), this, SLOT(downloadArea(int, QRectF))); connect(m_map, SIGNAL(downloadArea(int, QRectF)), this, SLOT(downloadArea(int, QRectF)));
connect(m_map, SIGNAL(route(QPointF, QPointF)), this, SLOT(findRoute(QPointF, QPointF))); connect(m_map, SIGNAL(search()), this, SLOT(search()));
m_stack->insertWidget(0, m_map); m_stack->insertWidget(0, m_map);
connect(m_markerList, SIGNAL(back()), this, SLOT(showMap())); connect(m_markerList, SIGNAL(back()), this, SLOT(showMap()));
@ -83,8 +83,9 @@ MainWidget::MainWidget(QWidget *parent)
connect(m_dlWidget, SIGNAL(back()), this, SLOT(showMap())); connect(m_dlWidget, SIGNAL(back()), this, SLOT(showMap()));
m_stack->insertWidget(2, m_dlWidget); m_stack->insertWidget(2, m_dlWidget);
connect(m_routingWidget, SIGNAL(back()), this, SLOT(showMap())); connect(m_search, SIGNAL(back()), this, SLOT(showMap()));
m_stack->insertWidget(3, m_routingWidget); connect(m_search, SIGNAL(centerOn(qreal, qreal)), this, SLOT(showMap(qreal, qreal)));
m_stack->insertWidget(3, m_search);
resize(320, 240); resize(320, 240);
} }
@ -121,6 +122,12 @@ void MainWidget::showMap()
m_stack->setCurrentIndex(0); m_stack->setCurrentIndex(0);
} }
void MainWidget::showMap(qreal lon, qreal lat)
{
m_map->centerOnGeoPos(lon, lat);
showMap();
}
void MainWidget::downloadArea(int level, const QRectF &rect) void MainWidget::downloadArea(int level, const QRectF &rect)
{ {
m_dlWidget->setStartLevel(level); m_dlWidget->setStartLevel(level);
@ -128,11 +135,8 @@ void MainWidget::downloadArea(int level, const QRectF &rect)
m_stack->setCurrentIndex(2); m_stack->setCurrentIndex(2);
} }
void MainWidget::findRoute(const QPointF &from, const QPointF &to) void MainWidget::search()
{ {
m_routingWidget->setFrom(from);
m_routingWidget->setTo(to);
m_stack->setCurrentIndex(3); m_stack->setCurrentIndex(3);
} }

View File

@ -27,7 +27,7 @@
class DownloadWidget; class DownloadWidget;
class MapWidget; class MapWidget;
class MarkerList; class MarkerList;
class RoutingWidget; class SearchWidget;
class MainWidget : public QWidget class MainWidget : public QWidget
{ {
@ -45,15 +45,16 @@ private slots:
void showList(); void showList();
void markerAdded(const QString &name); void markerAdded(const QString &name);
void showMap(); void showMap();
void showMap(qreal lon, qreal lat);
void downloadArea(int level, const QRectF &rect); void downloadArea(int level, const QRectF &rect);
void findRoute(const QPointF &from, const QPointF &to); void search();
private: private:
QStackedWidget *m_stack; QStackedWidget *m_stack;
MapWidget *m_map; MapWidget *m_map;
MarkerList *m_markerList; MarkerList *m_markerList;
DownloadWidget *m_dlWidget; DownloadWidget *m_dlWidget;
RoutingWidget *m_routingWidget; SearchWidget *m_search;
}; };

View File

@ -297,10 +297,10 @@ void MapWidget::keyPressEvent(QKeyEvent *event)
} }
break; break;
} }
case Qt::Key_R: case Qt::Key_F:
{ {
if (event->modifiers() == Qt::NoModifier) { if (event->modifiers() == Qt::ControlModifier) {
// emit route(m_routeStart, m_routeEnd); emit search();
} }
break; break;
} }

View File

@ -49,7 +49,7 @@ signals:
void close(); void close();
void showMarkerList(); void showMarkerList();
void downloadArea(int level, const QRectF &rect); void downloadArea(int level, const QRectF &rect);
void route(const QPointF &from, const QPointF &to); void search();
protected: protected:
virtual void resizeEvent(QResizeEvent *event); virtual void resizeEvent(QResizeEvent *event);

View File

@ -1,170 +0,0 @@
/*
* Copyright 2010 Niels Kummerfeldt <niels.kummerfeldt@tu-harburg.de>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA
*/
#include "routingwidget.h"
#include "projection.h"
#include <QtCore/QCoreApplication>
#include <QtCore/QDir>
#include <QtCore/QFile>
#include <QtCore/QSettings>
#include <QtCore/QTextStream>
#include <QtGui/QLayout>
#include <QtGui/QPushButton>
RoutingWidget::RoutingWidget(QWidget *parent)
: QWidget(parent),
m_name(new QLineEdit("route.gpx", this)),
m_transport(new QComboBox(this)),
m_quickest(new QRadioButton("Quickest", this)),
m_shortest(new QRadioButton("Shortest", this)),
m_routino(),
m_dir(),
m_prefix(),
m_profiles(),
m_swap(),
m_from(),
m_to(),
m_fromLabel(new QLabel(this)),
m_toLabel(new QLabel(this))
{
QGridLayout *layout = new QGridLayout(this);
layout->setContentsMargins(5, 5, 5, 5);
layout->setRowStretch(6, 1);
QLabel *label = new QLabel("From:");
layout->addWidget(label, 0, 0);
layout->addWidget(m_fromLabel, 0, 1, 1, 2);
label = new QLabel("To:");
layout->addWidget(label, 1, 0);
layout->addWidget(m_toLabel, 1, 1, 1, 2);
label = new QLabel("Name:");
layout->addWidget(label, 2, 0);
layout->addWidget(m_name, 2, 1, 1, 2);
label = new QLabel("Transport:");
layout->addWidget(label, 3, 0);
m_transport->addItems(QStringList() << "motorcar" << "motorbike" << "bicycle" << "foot");
layout->addWidget(m_transport, 3, 1, 1, 2);
label = new QLabel("Route:");
layout->addWidget(label, 4, 0);
m_shortest->setChecked(true);
layout->addWidget(m_shortest, 4, 1, 1, 2);
layout->addWidget(m_quickest, 5, 1, 1, 2);
QPushButton *back = new QPushButton("&Show map", this);
back->setShortcut(QKeySequence(Qt::ALT + Qt::Key_S));
layout->addWidget(back, 7, 1);
connect(back, SIGNAL(clicked()), this, SIGNAL(back()));
QPushButton *find = new QPushButton("&Find route", this);
find->setShortcut(QKeySequence(Qt::ALT + Qt::Key_F));
layout->addWidget(find, 7, 2);
connect(find, SIGNAL(clicked()), this, SLOT(findRoute()));
QFile run("/tmp/findroute.sh");
if (run.open(QFile::WriteOnly)) {
QTextStream out(&run);
out << "#!/bin/sh\n";
run.close();
}
run.setPermissions(QFile::ReadOwner | QFile::WriteOwner | QFile::ExeOwner);
loadConfig();
resize(320, 240);
}
RoutingWidget::~RoutingWidget()
{
}
void RoutingWidget::setFrom(const QPointF &from)
{
m_from = from;
m_fromLabel->setText(Projection::geo2string(from));
}
void RoutingWidget::setTo(const QPointF &to)
{
m_to = to;
m_toLabel->setText(Projection::geo2string(to));
}
void RoutingWidget::findRoute()
{
QFile run("/tmp/findroute.sh");
if (run.open(QFile::WriteOnly)) {
QString file;
QString name = m_name->text();
QString command;
QTextStream out(&run);
out << "#!/bin/sh\n";
if (!m_swap.isEmpty()) {
out << "swapon "+m_swap+"\n";
}
command = m_routino;
command.append(QString(" --dir=%1").arg(m_dir));
command.append(QString(" --prefix=%1").arg(m_prefix));
command.append(QString(" --profiles=%1").arg(m_profiles));
command.append(QString(" --lon1=%1 --lat1=%2 --lon2=%3 --lat2=%4")
.arg(m_from.x()).arg(m_from.y()).arg(m_to.x()).arg(m_to.y()));
command.append(" --output-gpx-track");
if (m_shortest->isChecked()) {
command.append(" --shortest");
file = "shortest-track.gpx";
} else {
command.append(" --quickest");
file = "quickest-track.gpx";
}
out << command+"\n";
if (!m_swap.isEmpty()) {
out << "swapon "+m_swap+"\n";
}
out << QString("mv %1 %2\n").arg(file).arg(name);;
out << QString("exec ./NanoMap.sh %1\n").arg(name);
qApp->quit();
}
}
void RoutingWidget::loadConfig()
{
QSettings set(QDir::homePath()+"/Maps/nanomap.conf", QSettings::NativeFormat);
set.beginGroup("routino");
m_routino = set.value("router", "router").toString();
m_dir = set.value("dir", ".").toString();
m_prefix = set.value("prefix", "world").toString();
m_profiles = set.value("profiles", "/usr/share/routino/routino-profiles.xml").toString();
m_swap = set.value("swap", "").toString();
set.endGroup();
}

156
searchwidget.cpp Normal file
View File

@ -0,0 +1,156 @@
/*
* Copyright 2010 Niels Kummerfeldt <niels.kummerfeldt@tu-harburg.de>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA
*/
#include "searchwidget.h"
#include <QtCore/QDebug>
#include <QtCore/QDir>
#include <QtCore/QPluginLoader>
#include <QtCore/QSettings>
#include <QtGui/QCompleter>
#include <QtGui/QLayout>
#include <QtGui/QPushButton>
SearchWidget::SearchWidget(QWidget *parent)
: QWidget(parent),
m_addrLookup(0),
m_cityCoordinates(),
m_loaded(false),
m_city(new QLineEdit(this)),
m_cityList(new QListWidget(this)),
m_street(new QLineEdit(this)),
m_streetList(new QListWidget(this))
{
QGridLayout *layout = new QGridLayout(this);
layout->setContentsMargins(0, 0, 0, 0);
m_city->setPlaceholderText("Enter city name");
layout->addWidget(m_city, 0, 0, 1, 2);
connect(m_city, SIGNAL(textEdited(QString)), this, SLOT(cityChanged(QString)));
connect(m_city, SIGNAL(editingFinished()), this, SLOT(cityEntered()));
layout->addWidget(m_cityList, 1, 0, 1, 2);
connect(m_cityList, SIGNAL(itemActivated(QListWidgetItem*)),
this, SLOT(citySelected(QListWidgetItem*)));
m_street->setPlaceholderText("Enter street name");
layout->addWidget(m_street, 2, 0, 1, 2);
connect(m_street, SIGNAL(textEdited(QString)), this, SLOT(streetChanged(QString)));
layout->addWidget(m_streetList, 3, 0, 1, 2);
connect(m_streetList, SIGNAL(itemActivated(QListWidgetItem*)),
this, SLOT(streetSelected(QListWidgetItem*)));
QPushButton *back = new QPushButton("&Cancel", this);
layout->addWidget(back, 4, 1);
connect(back, SIGNAL(clicked()), this, SIGNAL(back()));
QSettings set(QDir::homePath()+"/Maps/nanomap.conf", QSettings::NativeFormat);
set.beginGroup("monav");
QString dataDir = set.value("datadir").toString();
QString addrLookupLib = set.value("addresslookup",
"/usr/lib/monav/libunicodetournamenttrieclient.so").toString();
set.endGroup();
QSettings pluginSettings(dataDir+"/plugins.ini", QSettings::IniFormat);
QString addrLookupName = pluginSettings.value("addressLookup").toString();
QPluginLoader Loader(addrLookupLib);
QObject *plugin = Loader.instance();
if (plugin) {
m_addrLookup = qobject_cast<IAddressLookup*>(plugin);
if (m_addrLookup) {
m_addrLookup->SetInputDirectory(dataDir);
m_loaded = m_addrLookup->LoadData();
}
}
resize(320, 240);
}
SearchWidget::~SearchWidget()
{
}
void SearchWidget::cityChanged(const QString &city)
{
if (m_loaded) {
QStringList suggestions, inputSuggestions;
bool found = m_addrLookup->GetPlaceSuggestions(city, 20, &suggestions, &inputSuggestions);
if (found) {
QCompleter *c = new QCompleter(suggestions, this);
c->setCompletionMode(QCompleter::PopupCompletion);
c->setCaseSensitivity(Qt::CaseInsensitive);
m_city->setCompleter(c);
}
}
}
void SearchWidget::cityEntered()
{
if (m_loaded) {
QVector<int> placeIDs;
QVector<UnsignedCoordinate> placeCoordinates;
if (m_addrLookup->GetPlaceData(m_city->text(), &placeIDs, &placeCoordinates)) {
QListWidgetItem *item;
m_cityList->clear();
m_cityCoordinates.clear();
for (int i = 0; i < placeIDs.count(); ++i) {
GPSCoordinate coord = placeCoordinates.at(i).ToGPSCoordinate();
QString name = QString("%1: %2 / %3").arg(m_city->text())
.arg(coord.latitude).arg(coord.longitude);
item = new QListWidgetItem(name, m_cityList);
item->setData(Qt::UserRole, placeIDs.at(i));
m_cityList->addItem(item);
m_cityCoordinates.insert(placeIDs.at(i), coord);
}
}
}
}
void SearchWidget::citySelected(QListWidgetItem *item)
{
int id = item->data(Qt::UserRole).toInt();
GPSCoordinate c = m_cityCoordinates.value(id);
emit centerOn(c.longitude, c.latitude);
}
void SearchWidget::streetChanged(const QString &street)
{
if (m_loaded) {
m_addrLookup->SelectPlace(m_cityList->currentItem()->data(Qt::UserRole).toInt());
QStringList suggestions, inputSuggestions;
bool found = m_addrLookup->GetStreetSuggestions(street, 20, &suggestions, &inputSuggestions);
if (found) {
m_streetList->clear();
m_streetList->insertItems(0, suggestions);
}
}
}
void SearchWidget::streetSelected(QListWidgetItem *item)
{
QVector<int> segmentLength;
QVector<UnsignedCoordinate> coordinates;
if (m_addrLookup->GetStreetData(item->text(), &segmentLength, &coordinates)) {
GPSCoordinate coord = coordinates.first().ToGPSCoordinate();
emit centerOn(coord.longitude, coord.latitude);
}
}

View File

@ -17,42 +17,41 @@
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*/ */
#ifndef ROUTINGWIDGET_H #ifndef SEARCHWIDGET_H
#define ROUTINGWIDGET_H #define SEARCHWIDGET_H
#include <QtGui/QComboBox>
#include <QtGui/QLabel>
#include <QtGui/QLineEdit> #include <QtGui/QLineEdit>
#include <QtGui/QRadioButton> #include <QtGui/QListWidget>
#include <QtGui/QWidget>
class RoutingWidget : public QWidget #include "interfaces/iaddresslookup.h"
class SearchWidget : public QWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
RoutingWidget(QWidget *parent = 0); SearchWidget(QWidget *parent = 0);
~RoutingWidget(); ~SearchWidget();
void setFrom(const QPointF &from);
void setTo(const QPointF &to);
signals: signals:
void back(); void back();
void centerOn(qreal lon, qreal lat);
private slots: private slots:
void findRoute(); void cityChanged(const QString &city);
void cityEntered();
void citySelected(QListWidgetItem *item);
void streetChanged(const QString &street);
void streetSelected(QListWidgetItem *item);
private: private:
void loadConfig(); IAddressLookup *m_addrLookup;
QHash<int, GPSCoordinate> m_cityCoordinates;
QLineEdit *m_name; bool m_loaded;
QComboBox *m_transport; QLineEdit *m_city;
QRadioButton *m_quickest; QListWidget *m_cityList;
QRadioButton *m_shortest; QLineEdit *m_street;
QString m_routino, m_dir, m_prefix, m_profiles, m_swap; QListWidget *m_streetList;
QPointF m_from, m_to;
QLabel *m_fromLabel, *m_toLabel;
}; };
#endif // ROUTINGWIDGET_H #endif // SEARCHWIDGET_H