Skip to content

Commit 2f3f6fc

Browse files
author
larsl
committedOct 21, 2004
** Some changes in the GPS plugin:
* Changed the tooltip of the action from "GPS Importer" to "GPS Tools" * Removed some old unused code * Made the upload/download tools much more flexible by letting users specifying "devices" with upload and download commands * Remember the last used device and port for uploads and downloads * Remember the last directory that a GPX file was loaded from git-svn-id: http://svn.osgeo.org/qgis/trunk@2159 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 5aebc20 commit 2f3f6fc

File tree

9 files changed

+472
-570
lines changed

9 files changed

+472
-570
lines changed
 

‎ChangeLog

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@ ChangeLog,v 1.200 2004/10/21 17:27:35 mcoletti Exp
33
------------------------------------------------------------------------------
44

55

6+
2004-10-22 [larsl] 0.5.0devel11
7+
** Some changes in the GPS plugin:
8+
* Changed the tooltip of the action from "GPS Importer" to "GPS Tools"
9+
* Removed some old unused code
10+
* Made the upload/download tools much more flexible by letting users
11+
specifying "devices" with upload and download commands
12+
* Remember the last used device and port for uploads and downloads
13+
* Remember the last directory that a GPX file was loaded from
14+
615
Version 0.6 'Simon' .... development version
716

817
2004-10-20 [mcoletti] 0.5.0devel10

‎configure.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ dnl ---------------------------------------------------------------------------
2626
MAJOR_VERSION=0
2727
MINOR_VERSION=5
2828
MICRO_VERSION=0
29-
EXTRA_VERSION=10
29+
EXTRA_VERSION=11
3030
if test $EXTRA_VERSION -eq 0; then
3131
VERSION=${MAJOR_VERSION}.${MINOR_VERSION}.${MICRO_VERSION}
3232
else

‎plugins/gps_importer/Makefile.am

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,22 +40,30 @@ gpsimporterplugin_la_SOURCES = plugin.cpp \
4040
shpopen.c \
4141
dbfopen.c \
4242
shapefile.h \
43+
qgsbabelformat.h \
44+
qgsbabelformat.cpp \
4345
plugingui.cpp \
46+
qgsgpsdevicedialog.cpp \
4447
$(plugin_UI)\
4548
$(plugin_MOC)
4649

47-
4850
plugin_MOC = plugin.moc.cpp \
4951
plugingui.moc.cpp \
50-
pluginguibase.moc.cpp
52+
pluginguibase.moc.cpp \
53+
qgsgpsdevicedialogbase.moc.cpp \
54+
qgsgpsdevicedialog.moc.cpp
5155

5256
plugin_UI = pluginguibase.h \
53-
pluginguibase.cpp
57+
pluginguibase.cpp \
58+
qgsgpsdevicedialogbase.h \
59+
qgsgpsdevicedialogbase.cpp
5460

55-
plugin_UIC = pluginguibase.ui
61+
plugin_UIC = pluginguibase.ui \
62+
qgsgpsdevicedialogbase.ui
5663

5764
# UI dependencies
5865
pluginguibase.cpp: pluginguibase.h pluginguibase.ui
66+
qgsgpsdevicedialogbase.cpp: qgsgpsdevicedialogbase.h qgsgpsdevicedialogbase.ui
5967

6068
BUILT_SOURCES = $(plugin_MOC) $(plugin_UI)
6169

@@ -96,6 +104,9 @@ standalone_UI = pluginguibase.h \
96104
EXTRA_DIST = $(plugin_UIC) icon.xpm \
97105
pluginguibase.h \
98106
pluginguibase.ui.h \
107+
qgsgpsdevicedialogbase.h \
108+
qgsgpsdevicedialogbase.ui.h \
99109
plugingui.h \
100110
plugin.h \
111+
qgsgpsdevicedialog.h \
101112
utils.h

‎plugins/gps_importer/plugin.cpp

Lines changed: 143 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ email : tim@linfiniti.com
4141
#include <qcursor.h>
4242
#include <qprocess.h>
4343
#include <qprogressdialog.h>
44+
#include <qsettings.h>
45+
#include <qstringlist.h>
4446

4547
//non qt includes
4648
#include <cassert>
@@ -76,11 +78,17 @@ Plugin::Plugin(QgisApp * theQGisApp, QgisIface * theQgisInterFace):
7678
qGisInterface(theQgisInterFace),
7779
QgisPlugin(name_,description_,version_,type_)
7880
{
81+
setupBabel();
7982
}
8083

8184
Plugin::~Plugin()
8285
{
83-
86+
// delete all our babel formats
87+
BabelMap::iterator iter;
88+
for (iter = mImporters.begin(); iter != mImporters.end(); ++iter)
89+
delete iter->second;
90+
for (iter = mDevices.begin(); iter != mDevices.end(); ++iter)
91+
delete iter->second;
8492
}
8593

8694
/* Following functions return name, description, version, and type for the plugin */
@@ -113,20 +121,15 @@ void Plugin::initGui()
113121
{
114122
// add a menu with 2 items
115123
QPopupMenu *pluginMenu = new QPopupMenu(qgisMainWindowPointer);
116-
117124
pluginMenu->insertItem(QIconSet(icon),"&Gps Tools", this, SLOT(run()));
118-
119125
menuBarPointer = ((QMainWindow *) qgisMainWindowPointer)->menuBar();
120-
121126
menuIdInt = qGisInterface->addMenu("&Gps", pluginMenu);
122-
// Create the action for tool
123-
myQActionPointer = new QAction("Import Gps Data", QIconSet(icon), "&Wmi",0, this, "run");
124-
// Connect the action to the run
125-
connect(myQActionPointer, SIGNAL(activated()), this, SLOT(run()));
126127

127-
// Add the icon to the toolbar
128+
// add an action to the toolbar
129+
myQActionPointer = new QAction("Gps Tools", QIconSet(icon), "&Wmi",0,
130+
this, "run");
131+
connect(myQActionPointer, SIGNAL(activated()), this, SLOT(run()));
128132
qGisInterface->addToolBarIcon(myQActionPointer);
129-
130133
}
131134

132135
//method defined in interface
@@ -141,25 +144,33 @@ void Plugin::run()
141144
// find all GPX layers
142145
std::vector<QgsVectorLayer*> gpxLayers;
143146
std::map<QString, QgsMapLayer*>::const_iterator iter;
147+
std::cerr<<"LAYERS: "<<qGisInterface->getLayerRegistry()->
148+
mapLayers().size()<<std::endl;
144149
for (iter = qGisInterface->getLayerRegistry()->mapLayers().begin();
145150
iter != qGisInterface->getLayerRegistry()->mapLayers().end(); ++iter) {
151+
std::cerr<<iter->second->name()<<std::endl;
146152
if (iter->second->type() == QgsMapLayer::VECTOR) {
147-
QgsVectorLayer* vectorLayer =dynamic_cast<QgsVectorLayer*>(iter->second);
148-
if (vectorLayer->providerType() == "gpx")
149-
gpxLayers.push_back(vectorLayer);
153+
QgsVectorLayer* vLayer = dynamic_cast<QgsVectorLayer*>(iter->second);
154+
if (vLayer->providerType() == "gpx")
155+
gpxLayers.push_back(vLayer);
150156
}
151157
}
158+
std::cerr<<std::endl;
152159

153-
PluginGui *myPluginGui=new PluginGui(gpxLayers, qgisMainWindowPointer, "GPS Tools", true, 0);
160+
PluginGui *myPluginGui=new PluginGui(mImporters, mDevices, gpxLayers,
161+
qgisMainWindowPointer, "GPS Tools",
162+
true, 0);
154163
//listen for when the layer has been made so we can draw it
155-
connect(myPluginGui, SIGNAL(drawRasterLayer(QString)), this, SLOT(drawRasterLayer(QString)));
156-
connect(myPluginGui, SIGNAL(drawVectorLayer(QString,QString,QString)), this, SLOT(drawVectorLayer(QString,QString,QString)));
164+
connect(myPluginGui, SIGNAL(drawRasterLayer(QString)),
165+
this, SLOT(drawRasterLayer(QString)));
166+
connect(myPluginGui, SIGNAL(drawVectorLayer(QString,QString,QString)),
167+
this, SLOT(drawVectorLayer(QString,QString,QString)));
157168
connect(myPluginGui, SIGNAL(loadGPXFile(QString, bool, bool, bool)),
158169
this, SLOT(loadGPXFile(QString, bool, bool, bool)));
159-
connect(myPluginGui, SIGNAL(importGPSFile(QString, QString, bool, bool, bool,
160-
QString, QString)),
161-
this, SLOT(importGPSFile(QString, QString, bool, bool, bool, QString,
162-
QString)));
170+
connect(myPluginGui, SIGNAL(importGPSFile(QString, QgsBabelFormat*, bool,
171+
bool, bool, QString, QString)),
172+
this, SLOT(importGPSFile(QString, QgsBabelFormat*, bool, bool,
173+
bool, QString, QString)));
163174
connect(myPluginGui, SIGNAL(downloadFromGPS(QString, QString, bool, bool,
164175
bool, QString, QString)),
165176
this, SLOT(downloadFromGPS(QString, QString, bool, bool, bool,
@@ -171,12 +182,6 @@ void Plugin::run()
171182
myPluginGui->show();
172183
}
173184

174-
//!draw a raster layer in the qui - intended to respond to signal sent by diolog when it as finished creating
175-
//layer
176-
void Plugin::drawRasterLayer(QString theQString)
177-
{
178-
qGisInterface->addRasterLayer(theQString);
179-
}
180185
//!draw a vector layer in the qui - intended to respond to signal sent by diolog when it as finished creating a layer
181186
////needs to be given vectorLayerPath, baseName, providerKey ("ogr" or "postgres");
182187
void Plugin::drawVectorLayer(QString thePathNameQString, QString theBaseNameQString, QString theProviderQString)
@@ -205,6 +210,10 @@ void Plugin::loadGPXFile(QString filename, bool loadWaypoints, bool loadRoutes,
205210
return;
206211
}
207212

213+
// remember the directory
214+
QSettings settings;
215+
settings.writeEntry("/qgis/gps/gpxdirectory", fileInfo.dirPath());
216+
208217
// add the requested layers
209218
if (loadTracks)
210219
emit drawVectorLayer(filename + "?type=track",
@@ -220,7 +229,7 @@ void Plugin::loadGPXFile(QString filename, bool loadWaypoints, bool loadRoutes,
220229
}
221230

222231

223-
void Plugin::importGPSFile(QString inputFilename, QString inputFormat,
232+
void Plugin::importGPSFile(QString inputFilename, QgsBabelFormat* importer,
224233
bool importWaypoints, bool importRoutes,
225234
bool importTracks, QString outputFilename,
226235
QString layerName) {
@@ -235,9 +244,9 @@ void Plugin::importGPSFile(QString inputFilename, QString inputFormat,
235244
typeArg = "-t";
236245

237246
// try to start the gpsbabel process
238-
QStringList babelArgs;
239-
babelArgs<<"gpsbabel"<<typeArg<<"-i"<<inputFormat<<"-o"<<"gpx"
240-
<<inputFilename<<outputFilename;
247+
QStringList babelArgs =
248+
importer->getImportCommand(mBabelPath, typeArg,
249+
inputFilename, outputFilename);
241250
QProcess babelProcess(babelArgs);
242251
if (!babelProcess.start()) {
243252
QMessageBox::warning(NULL, "Could not start process",
@@ -281,11 +290,11 @@ void Plugin::importGPSFile(QString inputFilename, QString inputFormat,
281290
}
282291

283292

284-
void Plugin::downloadFromGPS(QString protocol, QString deviceFilename,
293+
void Plugin::downloadFromGPS(QString device, QString port,
285294
bool downloadWaypoints, bool downloadRoutes,
286295
bool downloadTracks, QString outputFilename,
287296
QString layerName) {
288-
297+
289298
// what does the user want to download?
290299
QString typeArg;
291300
if (downloadWaypoints)
@@ -296,9 +305,9 @@ void Plugin::downloadFromGPS(QString protocol, QString deviceFilename,
296305
typeArg = "-t";
297306

298307
// try to start the gpsbabel process
299-
QStringList babelArgs;
300-
babelArgs<<"gpsbabel"<<typeArg<<"-i"<<protocol<<"-o"<<"gpx"
301-
<<deviceFilename<<outputFilename;
308+
QStringList babelArgs =
309+
mDevices[device]->getImportCommand(mBabelPath, typeArg,
310+
port, outputFilename);
302311
QProcess babelProcess(babelArgs);
303312
if (!babelProcess.start()) {
304313
QMessageBox::warning(NULL, "Could not start process",
@@ -337,12 +346,17 @@ void Plugin::downloadFromGPS(QString protocol, QString deviceFilename,
337346
emit drawVectorLayer(outputFilename + "?type=track",
338347
layerName, "gpx");
339348

349+
// everything was OK, remember the device and port for next time
350+
QSettings settings;
351+
settings.writeEntry("/qgis/gps/lastdldevice", device);
352+
settings.writeEntry("/qgis/gps/lastdlport", port);
353+
340354
emit closeGui();
341355
}
342356

343357

344-
void Plugin::uploadToGPS(QgsVectorLayer* gpxLayer, QString protocol,
345-
QString deviceFilename) {
358+
void Plugin::uploadToGPS(QgsVectorLayer* gpxLayer, QString device,
359+
QString port) {
346360

347361
const QString& source(gpxLayer->getDataProvider()->getDataSourceUri());
348362

@@ -360,10 +374,9 @@ void Plugin::uploadToGPS(QgsVectorLayer* gpxLayer, QString protocol,
360374
}
361375

362376
// try to start the gpsbabel process
363-
QStringList babelArgs;
364-
babelArgs<<"gpsbabel"<<typeArg<<"-i"<<"gpx"
365-
<<"-o"<<protocol
366-
<<source.left(source.findRev('?'))<<deviceFilename;
377+
QStringList babelArgs =
378+
mDevices[device]->getExportCommand(mBabelPath, typeArg,
379+
source.left(source.findRev('?')), port);
367380
QProcess babelProcess(babelArgs);
368381
if (!babelProcess.start()) {
369382
QMessageBox::warning(NULL, "Could not start process",
@@ -391,10 +404,99 @@ void Plugin::uploadToGPS(QgsVectorLayer* gpxLayer, QString protocol,
391404
return;
392405
}
393406

407+
// everything was OK, remember this device for next time
408+
QSettings settings;
409+
settings.writeEntry("/qgis/gps/lastuldevice", device);
410+
settings.writeEntry("/qgis/gps/lastulport", port);
411+
394412
emit closeGui();
395413
}
396414

397415

416+
void Plugin::setupBabel() {
417+
418+
// where is gpsbabel?
419+
QSettings settings;
420+
mBabelPath = settings.readEntry("/qgis/gps/gpsbabelpath");
421+
if (mBabelPath.isEmpty())
422+
mBabelPath = "gpsbabel";
423+
// the importable formats
424+
mImporters["Geocaching.com .loc"] =
425+
new QgsSimpleBabelFormat("geo", true, false, false);
426+
mImporters["Magellan Mapsend"] =
427+
new QgsSimpleBabelFormat("mapsend", true, true, true);
428+
mImporters["Garmin PCX5"] =
429+
new QgsSimpleBabelFormat("pcx", true, false, true);
430+
mImporters["Garmin Mapsource"] =
431+
new QgsSimpleBabelFormat("mapsource", true, true, true);
432+
mImporters["GPSUtil"] =
433+
new QgsSimpleBabelFormat("gpsutil", true, false, false);
434+
mImporters["PocketStreets 2002/2003 Pushpin"] =
435+
new QgsSimpleBabelFormat("psp", true, false, false);
436+
mImporters["CoPilot Flight Planner"] =
437+
new QgsSimpleBabelFormat("copilot", true, false, false);
438+
mImporters["Magellan Navigator Companion"] =
439+
new QgsSimpleBabelFormat("magnav", true, false, false);
440+
mImporters["Holux"] =
441+
new QgsSimpleBabelFormat("holux", true, false, false);
442+
mImporters["Topo by National Geographic"] =
443+
new QgsSimpleBabelFormat("tpg", true, false, false);
444+
mImporters["TopoMapPro"] =
445+
new QgsSimpleBabelFormat("tmpro", true, false, false);
446+
mImporters["GeocachingDB"] =
447+
new QgsSimpleBabelFormat("gcdb", true, false, false);
448+
mImporters["Tiger"] =
449+
new QgsSimpleBabelFormat("tiger", true, false, false);
450+
mImporters["EasyGPS Binary Format"] =
451+
new QgsSimpleBabelFormat("easygps", true, false, false);
452+
mImporters["Delorme Routes"] =
453+
new QgsSimpleBabelFormat("saroute", false, false, true);
454+
mImporters["Navicache"] =
455+
new QgsSimpleBabelFormat("navicache", true, false, false);
456+
mImporters["PSITrex"] =
457+
new QgsSimpleBabelFormat("psitrex", true, true, true);
458+
mImporters["Delorme GPS Log"] =
459+
new QgsSimpleBabelFormat("gpl", false, false, true);
460+
mImporters["OziExplorer"] =
461+
new QgsSimpleBabelFormat("ozi", true, false, false);
462+
mImporters["NMEA Sentences"] =
463+
new QgsSimpleBabelFormat("nmea", true, false, true);
464+
mImporters["Delorme Street Atlas 2004 Plus"] =
465+
new QgsSimpleBabelFormat("saplus", true, false, false);
466+
mImporters["Microsoft Streets and Trips"] =
467+
new QgsSimpleBabelFormat("s_and_t", true, false, false);
468+
mImporters["NIMA/GNIS Geographic Names"] =
469+
new QgsSimpleBabelFormat("nima", true, false, false);
470+
mImporters["Maptech"] =
471+
new QgsSimpleBabelFormat("mxf", true, false, false);
472+
mImporters["Mapopolis.com Mapconverter Application"] =
473+
new QgsSimpleBabelFormat("mapconverter", true, false, false);
474+
mImporters["GPSman"] =
475+
new QgsSimpleBabelFormat("gpsman", true, false, false);
476+
mImporters["GPSDrive"] =
477+
new QgsSimpleBabelFormat("gpsdrive", true, false, false);
478+
mImporters["Fugawi"] =
479+
new QgsSimpleBabelFormat("fugawi", true, false, false);
480+
mImporters["DNA"] =
481+
new QgsSimpleBabelFormat("dna", true, false, false);
482+
483+
// and the GPS devices
484+
mDevices["Garmin serial"] =
485+
new QgsBabelCommand("%babel -i garmin -o gpx /dev/ttyS0 %out",
486+
"%babel -i gpx -o garmin %in /dev/ttyS0");
487+
QStringList deviceNames = settings.readListEntry("/qgis/gps/devicelist");
488+
QStringList::iterator iter;
489+
for (iter = deviceNames.begin(); iter != deviceNames.end(); ++iter) {
490+
QString download = settings.
491+
readEntry(QString("/qgis/gps/devices/%1/download").arg(*iter), "");
492+
QString upload = settings.
493+
readEntry(QString("/qgis/gps/devices/%1/upload").arg(*iter), "");
494+
mDevices[*iter] = new QgsBabelCommand(download, upload);
495+
}
496+
}
497+
498+
499+
398500

399501
/**
400502
* Required extern functions needed for every plugin

‎plugins/gps_importer/plugin.h

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
/* $Id$ */
2020
#ifndef PLUGIN
2121
#define PLUGIN
22+
#include "qgsbabelformat.h"
2223
#include "../qgisplugin.h"
2324
#include <qwidget.h>
2425
#include <qgisapp.h>
@@ -32,14 +33,15 @@ class QgsVectorLayer;
3233
*/
3334
class Plugin:public QObject, public QgisPlugin
3435
{
35-
Q_OBJECT public:
36+
Q_OBJECT
37+
public:
3638
/**
3739
* Constructor for a plugin. The QgisApp and QgisIface pointers are passed by
3840
* QGIS when it attempts to instantiate the plugin.
3941
* @param qgis Pointer to the QgisApp object
4042
* @param qI Pointer to the QgisIface object.
4143
*/
42-
Plugin(QgisApp * , QgisIface * );
44+
Plugin(QgisApp * , QgisIface * );
4345
/**
4446
* Virtual function to return the name of the plugin. The name will be used when presenting a list
4547
* of installable plugins to the user
@@ -64,8 +66,6 @@ class Plugin:public QObject, public QgisPlugin
6466
public slots:
6567
//! Show the dialog box
6668
void run();
67-
//!draw a raster layer in the qui
68-
void drawRasterLayer(QString);
6969
//! Add a vector layer given vectorLayerPath, baseName, providerKey ("ogr" or "postgres");
7070
void drawVectorLayer(QString,QString,QString);
7171
//! unload the plugin
@@ -76,22 +76,24 @@ class Plugin:public QObject, public QgisPlugin
7676
//! load a GPX file
7777
void loadGPXFile(QString filename, bool loadWaypoints, bool loadRoutes,
7878
bool loadTracks);
79-
void importGPSFile(QString inputFilename, QString inputFormat,
79+
void importGPSFile(QString inputFilename, QgsBabelFormat* importer,
8080
bool importWaypoints, bool importRoutes,
8181
bool importTracks, QString outputFilename,
8282
QString layerName);
83-
void downloadFromGPS(QString protocol, QString deviceFilename,
83+
void downloadFromGPS(QString device, QString port,
8484
bool downloadWaypoints, bool downloadRoutes,
8585
bool downloadTracks, QString outputFilename,
8686
QString layerName);
87-
void uploadToGPS(QgsVectorLayer* gpxLayer, QString protocol,
88-
QString deviceFilename);
87+
void uploadToGPS(QgsVectorLayer* gpxLayer, QString device,
88+
QString port);
8989

9090
signals:
9191

9292
void closeGui();
9393

94-
private:
94+
private:
95+
96+
void setupBabel();
9597

9698

9799
//! Name of the plugin
@@ -112,6 +114,10 @@ class Plugin:public QObject, public QgisPlugin
112114
QgisIface *qGisInterface;
113115
//! Pointer to the QAction object used in the menu and toolbar
114116
QAction *myQActionPointer;
117+
118+
QString mBabelPath;
119+
std::map<QString, QgsBabelFormat*> mImporters;
120+
std::map<QString, QgsBabelFormat*> mDevices;
115121
};
116122

117123
#endif

‎plugins/gps_importer/plugingui.cpp

Lines changed: 108 additions & 151 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
* (at your option) any later version. *
1111
***************************************************************************/
1212
#include "plugingui.h"
13+
#include "qgsgpsdevicedialog.h"
1314
#include "../../src/qgsmaplayer.h"
1415
#include "../../src/qgsdataprovider.h"
1516

@@ -28,6 +29,7 @@
2829
#include <qfiledialog.h>
2930
#include <qmessagebox.h>
3031
#include <qfile.h>
32+
#include <qsettings.h>
3133
#include "waypointtoshape.h"
3234

3335
//standard includes
@@ -36,22 +38,17 @@
3638
#include <iostream>
3739

3840

39-
PluginGui::PluginGui() : PluginGuiBase()
40-
{
41-
populateDeviceComboBox();
42-
populateULLayerComboBox();
43-
populateIMPBabelFormats();
44-
tabWidget->removePage(tabWidget->page(2));
45-
}
46-
PluginGui::PluginGui( std::vector<QgsVectorLayer*> gpxMapLayers,
47-
QWidget* parent , const char* name , bool modal ,
48-
WFlags fl )
49-
: PluginGuiBase( parent, name, modal, fl ), gpxLayers(gpxMapLayers)
50-
{
51-
populateDeviceComboBox();
41+
PluginGui::PluginGui(const BabelMap& importers, BabelMap& devices,
42+
std::vector<QgsVectorLayer*> gpxMapLayers,
43+
QWidget* parent, const char* name, bool modal, WFlags fl)
44+
: PluginGuiBase(parent, name, modal, fl), gpxLayers(gpxMapLayers),
45+
mImporters(importers), mDevices(devices) {
46+
populatePortComboBoxes();
5247
populateULLayerComboBox();
5348
populateIMPBabelFormats();
54-
tabWidget->removePage(tabWidget->page(2));
49+
50+
connect(pbULEditDevices, SIGNAL(clicked()), this, SLOT(openDeviceEditor()));
51+
connect(pbDLEditDevices, SIGNAL(clicked()), this, SLOT(openDeviceEditor()));
5552
}
5653
PluginGui::~PluginGui()
5754
{
@@ -97,7 +94,7 @@ void PluginGui::pbnOK_clicked()
9794
case 1: {
9895
const QString& typeString(cmbDLFeatureType->currentText());
9996
emit importGPSFile(leIMPInput->text(),
100-
babelFormats.find(impFormat)->second.formatName,
97+
mImporters.find(impFormat)->second,
10198
typeString == "Waypoints", typeString == "Routes",
10299
typeString == "Tracks", leIMPOutput->text(),
103100
leIMPLayer->text());
@@ -107,62 +104,29 @@ void PluginGui::pbnOK_clicked()
107104
// or download GPS data from a device?
108105
case 2: {
109106
int featureType = cmbDLFeatureType->currentItem();
110-
emit downloadFromGPS(cmbDLProtocol->currentText().lower(),
111-
cmbDLDevice->currentText(), featureType == 0,
112-
featureType == 1, featureType == 2,
107+
emit downloadFromGPS(cmbDLDevice->currentText(), cmbDLPort->currentText(),
108+
featureType == 0, featureType == 1, featureType == 2,
113109
leDLOutput->text(), leDLBasename->text());
114110
break;
115111
}
116112

117113
// or upload GPS data to a device?
118114
case 3:
119115
emit uploadToGPS(gpxLayers[cmbULLayer->currentItem()],
120-
cmbULProtocol->currentText().lower(),
121-
cmbULDevice->currentText());
116+
cmbULDevice->currentText(), cmbULPort->currentText());
122117
break;
123118
}
124119
}
125120

126121

127-
void PluginGui::pbnSelectInputFile_clicked()
128-
{
129-
std::cout << " Gps File Importer::pbnSelectInputFile_clicked() " << std::endl;
130-
QString myFileTypeQString;
131-
QString myFilterString="Text File (*.txt)";
132-
QString myFileNameQString = QFileDialog::getOpenFileName(
133-
"." , //initial dir
134-
myFilterString, //filters to select
135-
this , //parent dialog
136-
"OpenFileDialog" , //QFileDialog qt object name
137-
"Select GPS dump text file" , //caption
138-
&myFileTypeQString //the pointer to store selected filter
139-
);
140-
std::cout << "Selected filetype filter is : " << myFileTypeQString << std::endl;
141-
leInputFile->setText(myFileNameQString);
142-
}
143-
144-
145-
void PluginGui::pbnSelectOutputFile_clicked()
146-
{
147-
std::cout << " Gps File Importer Gui::pbnSelectOutputFile_clicked() " << std::endl;
148-
QString myOutputFileNameQString = QFileDialog::getSaveFileName(
149-
".",
150-
"ESRI Shapefile (*.shp)",
151-
this,
152-
"save file dialog"
153-
"Choose a filename to save under" );
154-
leOutputShapeFile->setText(myOutputFileNameQString);
155-
}
156-
157-
158122
void PluginGui::pbnDLOutput_clicked()
159123
{
160-
QString myFileNameQString = QFileDialog::getSaveFileName(
161-
"." , //initial dir
162-
"GPS eXchange format (*.gpx)",
163-
this , //parent dialog
164-
"Select GPX output",
165-
"Choose a filename to save under" );
124+
QString myFileNameQString =
125+
QFileDialog::getSaveFileName("." , //initial dir
126+
"GPS eXchange format (*.gpx)",
127+
this , //parent dialog
128+
"Select GPX output",
129+
"Choose a filename to save under");
166130
leDLOutput->setText(myFileNameQString);
167131
}
168132

@@ -193,18 +157,6 @@ void PluginGui::enableRelevantControls()
193157
}
194158
}
195159

196-
// import download file
197-
else if (tabWidget->currentPageIndex() == 666) {
198-
if ( (leOutputShapeFile->text()=="") || (leInputFile->text()=="") )
199-
{
200-
pbnOK->setEnabled(false);
201-
}
202-
else
203-
{
204-
pbnOK->setEnabled(true);
205-
}
206-
}
207-
208160
// import other file
209161
else if (tabWidget->currentPageIndex() == 1) {
210162

@@ -224,7 +176,7 @@ void PluginGui::enableRelevantControls()
224176
pbnOK->setEnabled(true);
225177
}
226178

227-
// upload from device
179+
// upload to device
228180
else if (tabWidget->currentPageIndex() == 3) {
229181
if (cmbULDevice->currentText() == "" || cmbULLayer->currentText() == "")
230182
pbnOK->setEnabled(false);
@@ -245,8 +197,12 @@ void PluginGui::pbnGPXSelectFile_clicked()
245197
std::cout << " Gps File Importer::pbnGPXSelectFile_clicked() " << std::endl;
246198
QString myFileTypeQString;
247199
QString myFilterString="GPS eXchange format (*.gpx)";
200+
QSettings settings;
201+
QString dir = settings.readEntry("/qgis/gps/gpxdirectory");
202+
if (dir.isEmpty())
203+
dir = ".";
248204
QString myFileNameQString = QFileDialog::getOpenFileName(
249-
"." , //initial dir
205+
dir , //initial dir
250206
myFilterString, //filters to select
251207
this , //parent dialog
252208
"OpenFileDialog" , //QFileDialog qt object name
@@ -269,21 +225,21 @@ void PluginGui::pbnIMPInput_clicked() {
269225
&myFileType //the pointer to store selected filter
270226
);
271227
impFormat = myFileType.left(myFileType.length() - 6);
272-
std::map<QString, BabelFormatInfo>::const_iterator iter;
273-
iter = babelFormats.find(impFormat);
274-
if (iter == babelFormats.end()) {
228+
std::map<QString, QgsBabelFormat*>::const_iterator iter;
229+
iter = mImporters.find(impFormat);
230+
if (iter == mImporters.end()) {
275231
std::cerr<<"Unknown file format selected: "
276232
<<myFileType.left(myFileType.length() - 6)<<std::endl;
277233
}
278234
else {
279235
std::cerr<<iter->first<<" selected"<<std::endl;
280236
leIMPInput->setText(myFileName);
281237
cmbIMPFeature->clear();
282-
if (iter->second.hasWaypoints)
238+
if (iter->second->supportsWaypoints())
283239
cmbIMPFeature->insertItem("Waypoints");
284-
if (iter->second.hasRoutes)
240+
if (iter->second->supportsRoutes())
285241
cmbIMPFeature->insertItem("Routes");
286-
if (iter->second.hasTracks)
242+
if (iter->second->supportsTracks())
287243
cmbIMPFeature->insertItem("Tracks");
288244
}
289245
}
@@ -300,14 +256,15 @@ void PluginGui::pbnIMPOutput_clicked() {
300256
}
301257

302258

303-
void PluginGui::populateDeviceComboBox() {
259+
void PluginGui::populatePortComboBoxes() {
260+
304261
#ifdef linux
305262
// look for linux serial devices
306263
QString linuxDev("/dev/ttyS%1");
307264
for (int i = 0; i < 10; ++i) {
308265
if (QFileInfo(linuxDev.arg(i)).exists()) {
309-
cmbDLDevice->insertItem(linuxDev.arg(i));
310-
cmbULDevice->insertItem(linuxDev.arg(i));
266+
cmbDLPort->insertItem(linuxDev.arg(i));
267+
cmbULPort->insertItem(linuxDev.arg(i));
311268
}
312269
else
313270
break;
@@ -317,8 +274,8 @@ void PluginGui::populateDeviceComboBox() {
317274
linuxDev = "/dev/ttyUSB%1";
318275
for (int i = 0; i < 10; ++i) {
319276
if (QFileInfo(linuxDev.arg(i)).exists()) {
320-
cmbDLDevice->insertItem(linuxDev.arg(i));
321-
cmbULDevice->insertItem(linuxDev.arg(i));
277+
cmbDLPort->insertItem(linuxDev.arg(i));
278+
cmbULPort->insertItem(linuxDev.arg(i));
322279
}
323280
else
324281
break;
@@ -331,8 +288,8 @@ void PluginGui::populateDeviceComboBox() {
331288
QString freebsdDev("/dev/cuaa%1");
332289
for (int i = 0; i < 10; ++i) {
333290
if (QFileInfo(freebsdDev.arg(i)).exists()) {
334-
cmbDLDevice->insertItem(freebsdDev.arg(i));
335-
cmbULDevice->insertItem(freebsdDev.arg(i));
291+
cmbDLPort->insertItem(freebsdDev.arg(i));
292+
cmbULPort->insertItem(freebsdDev.arg(i));
336293
}
337294
else
338295
break;
@@ -344,23 +301,39 @@ void PluginGui::populateDeviceComboBox() {
344301
QString solarisDev("/dev/cua/%1");
345302
for (int i = 'a'; i < 'k'; ++i) {
346303
if (QFileInfo(solarisDev.arg(char(i))).exists()) {
347-
cmbDLDevice->insertItem(solarisDev.arg(char(i)));
348-
cmbULDevice->insertItem(solarisDev.arg(char(i)));
304+
cmbDLPort->insertItem(solarisDev.arg(char(i)));
305+
cmbULPort->insertItem(solarisDev.arg(char(i)));
349306
}
350307
else
351308
break;
352309
}
353310
#endif
354311

355312
#ifdef WIN32
356-
cmbULDevice->insertItem("com1");
357-
cmbULDevice->insertItem("com2");
358-
cmbDLDevice->insertItem("com1");
359-
cmbDLDevice->insertItem("com2");
313+
cmbULPort->insertItem("com1");
314+
cmbULPort->insertItem("com2");
315+
cmbDLPort->insertItem("com1");
316+
cmbDLPort->insertItem("com2");
360317
#endif
361318

362319
// OSX, OpenBSD, NetBSD etc? Anyone?
363-
320+
321+
// remember the last ports used
322+
QSettings settings;
323+
QString lastDLPort = settings.readEntry("/qgis/gps/lastdlport", "");
324+
QString lastULPort = settings.readEntry("/qgis/gps/lastulport", "");
325+
for (int i = 0; i < cmbDLPort->count(); ++i) {
326+
if (cmbDLPort->text(i) == lastDLPort) {
327+
cmbDLPort->setCurrentItem(i);
328+
break;
329+
}
330+
}
331+
for (int i = 0; i < cmbULPort->count(); ++i) {
332+
if (cmbULPort->text(i) == lastULPort) {
333+
cmbULPort->setCurrentItem(i);
334+
break;
335+
}
336+
}
364337
}
365338

366339

@@ -373,65 +346,49 @@ void PluginGui::populateULLayerComboBox() {
373346

374347

375348
void PluginGui::populateIMPBabelFormats() {
376-
babelFormats["Geocaching.com .loc"] =
377-
BabelFormatInfo("geo", true, false, false);
378-
babelFormats["Magellan Mapsend"] =
379-
BabelFormatInfo("mapsend", true, true, true);
380-
babelFormats["Garmin PCX5"] =
381-
BabelFormatInfo("pcx", true, false, true);
382-
babelFormats["Garmin Mapsource"] =
383-
BabelFormatInfo("mapsource", true, true, true);
384-
babelFormats["GPSUtil"] =
385-
BabelFormatInfo("gpsutil", true, false, false);
386-
babelFormats["PocketStreets 2002/2003 Pushpin"] =
387-
BabelFormatInfo("psp", true, false, false);
388-
babelFormats["CoPilot Flight Planner"] =
389-
BabelFormatInfo("copilot", true, false, false);
390-
babelFormats["Magellan Navigator Companion"] =
391-
BabelFormatInfo("magnav", true, false, false);
392-
babelFormats["Holux"] =
393-
BabelFormatInfo("holux", true, false, false);
394-
babelFormats["Topo by National Geographic"] =
395-
BabelFormatInfo("tpg", true, false, false);
396-
babelFormats["TopoMapPro"] =
397-
BabelFormatInfo("tmpro", true, false, false);
398-
babelFormats["GeocachingDB"] =
399-
BabelFormatInfo("gcdb", true, false, false);
400-
babelFormats["Tiger"] =
401-
BabelFormatInfo("tiger", true, false, false);
402-
babelFormats["EasyGPS Binary Format"] =
403-
BabelFormatInfo("easygps", true, false, false);
404-
babelFormats["Delorme Routes"] =
405-
BabelFormatInfo("saroute", false, false, true);
406-
babelFormats["Navicache"] =
407-
BabelFormatInfo("navicache", true, false, false);
408-
babelFormats["PSITrex"] =
409-
BabelFormatInfo("psitrex", true, true, true);
410-
babelFormats["Delorme GPS Log"] =
411-
BabelFormatInfo("gpl", false, false, true);
412-
babelFormats["OziExplorer"] =
413-
BabelFormatInfo("ozi", true, false, false);
414-
babelFormats["NMEA Sentences"] =
415-
BabelFormatInfo("nmea", true, false, true);
416-
babelFormats["Delorme Street Atlas 2004 Plus"] =
417-
BabelFormatInfo("saplus", true, false, false);
418-
babelFormats["Microsoft Streets and Trips"] =
419-
BabelFormatInfo("s_and_t", true, false, false);
420-
babelFormats["NIMA/GNIS Geographic Names"] =
421-
BabelFormatInfo("nima", true, false, false);
422-
babelFormats["Maptech"] =
423-
BabelFormatInfo("mxf", true, false, false);
424-
babelFormats["Mapopolis.com Mapconverter Application"] =
425-
BabelFormatInfo("mapconverter", true, false, false);
426-
babelFormats["GPSman"] =
427-
BabelFormatInfo("gpsman", true, false, false);
428-
babelFormats["GPSDrive"] =
429-
BabelFormatInfo("gpsdrive", true, false, false);
430-
babelFormats["Fugawi"] =
431-
BabelFormatInfo("fugawi", true, false, false);
432-
babelFormats["DNA"] =
433-
BabelFormatInfo("dna", true, false, false);
434-
std::map<QString, BabelFormatInfo>::const_iterator iter;
435-
for (iter = babelFormats.begin(); iter != babelFormats.end(); ++iter)
349+
babelFilter = "";
350+
cmbULDevice->clear();
351+
cmbDLDevice->clear();
352+
QSettings settings;
353+
QString lastDLDevice = settings.readEntry("/qgis/gps/lastdldevice", "");
354+
QString lastULDevice = settings.readEntry("/qgis/gps/lastuldevice", "");
355+
BabelMap::const_iterator iter;
356+
for (iter = mImporters.begin(); iter != mImporters.end(); ++iter)
436357
babelFilter.append((const char*)iter->first).append(" (*.*);;");
358+
int u = -1, d = -1;
359+
for (iter = mDevices.begin(); iter != mDevices.end(); ++iter) {
360+
if (iter->second->supportsExport()) {
361+
cmbULDevice->insertItem(iter->first);
362+
if (iter->first == lastULDevice)
363+
u = cmbULDevice->count() - 1;
364+
}
365+
if (iter->second->supportsImport()) {
366+
cmbDLDevice->insertItem(iter->first);
367+
if (iter->first == lastDLDevice)
368+
d = cmbDLDevice->count() - 1;
369+
}
370+
}
371+
if (u != -1)
372+
cmbULDevice->setCurrentItem(u);
373+
if (d != -1)
374+
cmbDLDevice->setCurrentItem(d);
375+
}
376+
377+
378+
void populatePortComboBoxes() {
379+
380+
}
381+
382+
383+
void PluginGui::openDeviceEditor() {
384+
QgsGPSDeviceDialog* dlg = new QgsGPSDeviceDialog(mDevices);
385+
dlg->show();
386+
connect(dlg, SIGNAL(devicesChanged()), this, SLOT(slotDevicesUpdated()));
387+
}
388+
389+
390+
void PluginGui::slotDevicesUpdated() {
391+
populateIMPBabelFormats();
437392
}
393+
394+

‎plugins/gps_importer/plugingui.h

Lines changed: 50 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#include "../../src/qgsvectorlayer.h"
1616
#include "pluginguibase.h"
17+
#include "qgsbabelformat.h"
1718

1819
#include <vector>
1920

@@ -26,64 +27,59 @@
2627
class PluginGui : public PluginGuiBase
2728
{
2829
Q_OBJECT
29-
public:
30-
PluginGui();
31-
PluginGui( std::vector<QgsVectorLayer*> gpxMapLayers, QWidget* parent ,
32-
const char* name , bool modal , WFlags );
33-
~PluginGui();
30+
public:
31+
PluginGui(const BabelMap& importers, BabelMap& devices,
32+
std::vector<QgsVectorLayer*> gpxMapLayers, QWidget* parent,
33+
const char* name , bool modal , WFlags);
34+
~PluginGui();
3435

35-
private:
36+
public slots:
3637

37-
void pbnSelectInputFile_clicked();
38-
void pbnSelectOutputFile_clicked();
39-
40-
void pbnGPXSelectFile_clicked();
41-
42-
void pbnIMPInput_clicked();
43-
void pbnIMPOutput_clicked();
44-
45-
void pbnDLOutput_clicked();
46-
47-
void enableRelevantControls();
48-
void pbnCancel_clicked();
49-
void pbnOK_clicked();
50-
51-
void populateDeviceComboBox();
52-
void populateULLayerComboBox();
53-
void populateIMPBabelFormats();
54-
38+
void openDeviceEditor();
39+
void slotDevicesUpdated();
40+
41+
private:
42+
43+
void pbnSelectInputFile_clicked();
44+
void pbnSelectOutputFile_clicked();
45+
46+
void pbnGPXSelectFile_clicked();
47+
48+
void pbnIMPInput_clicked();
49+
void pbnIMPOutput_clicked();
50+
51+
void pbnDLOutput_clicked();
52+
53+
void enableRelevantControls();
54+
void pbnCancel_clicked();
55+
void pbnOK_clicked();
56+
57+
void populateDeviceComboBox();
58+
void populateULLayerComboBox();
59+
void populateIMPBabelFormats();
60+
void populatePortComboBoxes();
61+
5562
signals:
56-
void drawRasterLayer(QString);
57-
void drawVectorLayer(QString,QString,QString);
58-
void loadGPXFile(QString filename, bool showWaypoints, bool showRoutes,
59-
bool showTracks);
60-
void importGPSFile(QString inputFilename, QString inputFormat,
61-
bool importWaypoints, bool importRoutes,
62-
bool importTracks, QString outputFilename,
63-
QString layerName);
64-
void downloadFromGPS(QString protocol, QString deviceFilename,
65-
bool downloadWaypoints, bool downloadRoutes,
66-
bool downloadTracks, QString outputFilename,
67-
QString layerName);
68-
void uploadToGPS(QgsVectorLayer* gpxLayer, QString protocol,
69-
QString deviceFilename);
70-
63+
void drawRasterLayer(QString);
64+
void drawVectorLayer(QString,QString,QString);
65+
void loadGPXFile(QString filename, bool showWaypoints, bool showRoutes,
66+
bool showTracks);
67+
void importGPSFile(QString inputFilename, QgsBabelFormat* importer,
68+
bool importWaypoints, bool importRoutes,
69+
bool importTracks, QString outputFilename,
70+
QString layerName);
71+
void downloadFromGPS(QString device, QString port, bool downloadWaypoints,
72+
bool downloadRoutes, bool downloadTracks,
73+
QString outputFilename, QString layerName);
74+
void uploadToGPS(QgsVectorLayer* gpxLayer, QString device, QString port);
75+
7176
private:
72-
73-
struct BabelFormatInfo {
74-
BabelFormatInfo(QString fn = "", bool hw = false, bool hr = false,
75-
bool ht = false) :
76-
formatName(fn), hasWaypoints(hw), hasRoutes(hr), hasTracks(ht) { }
77-
QString formatName;
78-
bool hasWaypoints;
79-
bool hasRoutes;
80-
bool hasTracks;
81-
};
82-
83-
std::vector<QgsVectorLayer*> gpxLayers;
84-
std::map<QString, BabelFormatInfo> babelFormats;
85-
QString babelFilter;
86-
QString impFormat;
77+
78+
std::vector<QgsVectorLayer*> gpxLayers;
79+
const BabelMap& mImporters;
80+
BabelMap& mDevices;
81+
QString babelFilter;
82+
QString impFormat;
8783
};
8884

8985
#endif

‎plugins/gps_importer/pluginguibase.ui

Lines changed: 131 additions & 276 deletions
Large diffs are not rendered by default.

‎plugins/gps_importer/pluginguibase.ui.h

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,6 @@ void PluginGuiBase::pbnOK_clicked()
1515
}
1616

1717

18-
void PluginGuiBase::pbnSelectInputFile_clicked()
19-
{
20-
21-
}
22-
23-
24-
void PluginGuiBase::pbnSelectOutputFile_clicked()
25-
{
26-
27-
}
2818

2919

3020
void PluginGuiBase::pbnCancel_clicked()
@@ -33,30 +23,6 @@ void PluginGuiBase::pbnCancel_clicked()
3323
}
3424

3525

36-
void PluginGuiBase::leInputFile_textChanged( const QString & theQString)
37-
{
38-
if (theQString != "")
39-
{
40-
pbnOK->setEnabled(true);
41-
}
42-
else
43-
{
44-
pbnOK->setEnabled(false);
45-
}
46-
}
47-
48-
49-
void PluginGuiBase::leOutputShapeFile_textChanged( const QString & theQString )
50-
{
51-
if (theQString != "")
52-
{
53-
pbnOK->setEnabled(true);
54-
}
55-
else
56-
{
57-
pbnOK->setEnabled(false);
58-
}
59-
}
6026

6127

6228
void PluginGuiBase::leGPXFile_textChanged( const QString & theQString )

0 commit comments

Comments
 (0)
Please sign in to comment.