diff --git a/ChangeLog b/ChangeLog index 12261ad5966..a2e5faedad7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,6 +3,15 @@ ChangeLog,v 1.200 2004/10/21 17:27:35 mcoletti Exp ------------------------------------------------------------------------------ +2004-10-22 [larsl] 0.5.0devel11 +** 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 + Version 0.6 'Simon' .... development version 2004-10-20 [mcoletti] 0.5.0devel10 diff --git a/configure.in b/configure.in index 6f72be949b0..824a173258f 100644 --- a/configure.in +++ b/configure.in @@ -26,7 +26,7 @@ dnl --------------------------------------------------------------------------- MAJOR_VERSION=0 MINOR_VERSION=5 MICRO_VERSION=0 -EXTRA_VERSION=10 +EXTRA_VERSION=11 if test $EXTRA_VERSION -eq 0; then VERSION=${MAJOR_VERSION}.${MINOR_VERSION}.${MICRO_VERSION} else diff --git a/plugins/gps_importer/Makefile.am b/plugins/gps_importer/Makefile.am index f8e2319185c..14ab5b28671 100644 --- a/plugins/gps_importer/Makefile.am +++ b/plugins/gps_importer/Makefile.am @@ -40,22 +40,30 @@ gpsimporterplugin_la_SOURCES = plugin.cpp \ shpopen.c \ dbfopen.c \ shapefile.h \ + qgsbabelformat.h \ + qgsbabelformat.cpp \ plugingui.cpp \ + qgsgpsdevicedialog.cpp \ $(plugin_UI)\ $(plugin_MOC) - plugin_MOC = plugin.moc.cpp \ plugingui.moc.cpp \ - pluginguibase.moc.cpp + pluginguibase.moc.cpp \ + qgsgpsdevicedialogbase.moc.cpp \ + qgsgpsdevicedialog.moc.cpp plugin_UI = pluginguibase.h \ - pluginguibase.cpp + pluginguibase.cpp \ + qgsgpsdevicedialogbase.h \ + qgsgpsdevicedialogbase.cpp -plugin_UIC = pluginguibase.ui +plugin_UIC = pluginguibase.ui \ + qgsgpsdevicedialogbase.ui # UI dependencies pluginguibase.cpp: pluginguibase.h pluginguibase.ui +qgsgpsdevicedialogbase.cpp: qgsgpsdevicedialogbase.h qgsgpsdevicedialogbase.ui BUILT_SOURCES = $(plugin_MOC) $(plugin_UI) @@ -96,6 +104,9 @@ standalone_UI = pluginguibase.h \ EXTRA_DIST = $(plugin_UIC) icon.xpm \ pluginguibase.h \ pluginguibase.ui.h \ + qgsgpsdevicedialogbase.h \ + qgsgpsdevicedialogbase.ui.h \ plugingui.h \ plugin.h \ + qgsgpsdevicedialog.h \ utils.h diff --git a/plugins/gps_importer/plugin.cpp b/plugins/gps_importer/plugin.cpp index 54261e28f36..e0f92131231 100644 --- a/plugins/gps_importer/plugin.cpp +++ b/plugins/gps_importer/plugin.cpp @@ -41,6 +41,8 @@ email : tim@linfiniti.com #include #include #include +#include +#include //non qt includes #include @@ -76,11 +78,17 @@ Plugin::Plugin(QgisApp * theQGisApp, QgisIface * theQgisInterFace): qGisInterface(theQgisInterFace), QgisPlugin(name_,description_,version_,type_) { + setupBabel(); } Plugin::~Plugin() { - + // delete all our babel formats + BabelMap::iterator iter; + for (iter = mImporters.begin(); iter != mImporters.end(); ++iter) + delete iter->second; + for (iter = mDevices.begin(); iter != mDevices.end(); ++iter) + delete iter->second; } /* Following functions return name, description, version, and type for the plugin */ @@ -113,20 +121,15 @@ void Plugin::initGui() { // add a menu with 2 items QPopupMenu *pluginMenu = new QPopupMenu(qgisMainWindowPointer); - pluginMenu->insertItem(QIconSet(icon),"&Gps Tools", this, SLOT(run())); - menuBarPointer = ((QMainWindow *) qgisMainWindowPointer)->menuBar(); - menuIdInt = qGisInterface->addMenu("&Gps", pluginMenu); - // Create the action for tool - myQActionPointer = new QAction("Import Gps Data", QIconSet(icon), "&Wmi",0, this, "run"); - // Connect the action to the run + + // add an action to the toolbar + myQActionPointer = new QAction("Gps Tools", QIconSet(icon), "&Wmi",0, + this, "run"); connect(myQActionPointer, SIGNAL(activated()), this, SLOT(run())); - - // Add the icon to the toolbar qGisInterface->addToolBarIcon(myQActionPointer); - } //method defined in interface @@ -141,25 +144,33 @@ void Plugin::run() // find all GPX layers std::vector gpxLayers; std::map::const_iterator iter; + std::cerr<<"LAYERS: "<getLayerRegistry()-> + mapLayers().size()<getLayerRegistry()->mapLayers().begin(); iter != qGisInterface->getLayerRegistry()->mapLayers().end(); ++iter) { + std::cerr<second->name()<second->type() == QgsMapLayer::VECTOR) { - QgsVectorLayer* vectorLayer =dynamic_cast(iter->second); - if (vectorLayer->providerType() == "gpx") - gpxLayers.push_back(vectorLayer); + QgsVectorLayer* vLayer = dynamic_cast(iter->second); + if (vLayer->providerType() == "gpx") + gpxLayers.push_back(vLayer); } } + std::cerr<show(); } -//!draw a raster layer in the qui - intended to respond to signal sent by diolog when it as finished creating -//layer -void Plugin::drawRasterLayer(QString theQString) -{ - qGisInterface->addRasterLayer(theQString); -} //!draw a vector layer in the qui - intended to respond to signal sent by diolog when it as finished creating a layer ////needs to be given vectorLayerPath, baseName, providerKey ("ogr" or "postgres"); void Plugin::drawVectorLayer(QString thePathNameQString, QString theBaseNameQString, QString theProviderQString) @@ -205,6 +210,10 @@ void Plugin::loadGPXFile(QString filename, bool loadWaypoints, bool loadRoutes, return; } + // remember the directory + QSettings settings; + settings.writeEntry("/qgis/gps/gpxdirectory", fileInfo.dirPath()); + // add the requested layers if (loadTracks) emit drawVectorLayer(filename + "?type=track", @@ -220,7 +229,7 @@ void Plugin::loadGPXFile(QString filename, bool loadWaypoints, bool loadRoutes, } -void Plugin::importGPSFile(QString inputFilename, QString inputFormat, +void Plugin::importGPSFile(QString inputFilename, QgsBabelFormat* importer, bool importWaypoints, bool importRoutes, bool importTracks, QString outputFilename, QString layerName) { @@ -235,9 +244,9 @@ void Plugin::importGPSFile(QString inputFilename, QString inputFormat, typeArg = "-t"; // try to start the gpsbabel process - QStringList babelArgs; - babelArgs<<"gpsbabel"<getImportCommand(mBabelPath, typeArg, + inputFilename, outputFilename); QProcess babelProcess(babelArgs); if (!babelProcess.start()) { QMessageBox::warning(NULL, "Could not start process", @@ -281,11 +290,11 @@ void Plugin::importGPSFile(QString inputFilename, QString inputFormat, } -void Plugin::downloadFromGPS(QString protocol, QString deviceFilename, +void Plugin::downloadFromGPS(QString device, QString port, bool downloadWaypoints, bool downloadRoutes, bool downloadTracks, QString outputFilename, QString layerName) { - + // what does the user want to download? QString typeArg; if (downloadWaypoints) @@ -296,9 +305,9 @@ void Plugin::downloadFromGPS(QString protocol, QString deviceFilename, typeArg = "-t"; // try to start the gpsbabel process - QStringList babelArgs; - babelArgs<<"gpsbabel"<getImportCommand(mBabelPath, typeArg, + port, outputFilename); QProcess babelProcess(babelArgs); if (!babelProcess.start()) { QMessageBox::warning(NULL, "Could not start process", @@ -337,12 +346,17 @@ void Plugin::downloadFromGPS(QString protocol, QString deviceFilename, emit drawVectorLayer(outputFilename + "?type=track", layerName, "gpx"); + // everything was OK, remember the device and port for next time + QSettings settings; + settings.writeEntry("/qgis/gps/lastdldevice", device); + settings.writeEntry("/qgis/gps/lastdlport", port); + emit closeGui(); } -void Plugin::uploadToGPS(QgsVectorLayer* gpxLayer, QString protocol, - QString deviceFilename) { +void Plugin::uploadToGPS(QgsVectorLayer* gpxLayer, QString device, + QString port) { const QString& source(gpxLayer->getDataProvider()->getDataSourceUri()); @@ -360,10 +374,9 @@ void Plugin::uploadToGPS(QgsVectorLayer* gpxLayer, QString protocol, } // try to start the gpsbabel process - QStringList babelArgs; - babelArgs<<"gpsbabel"<getExportCommand(mBabelPath, typeArg, + source.left(source.findRev('?')), port); QProcess babelProcess(babelArgs); if (!babelProcess.start()) { QMessageBox::warning(NULL, "Could not start process", @@ -391,10 +404,99 @@ void Plugin::uploadToGPS(QgsVectorLayer* gpxLayer, QString protocol, return; } + // everything was OK, remember this device for next time + QSettings settings; + settings.writeEntry("/qgis/gps/lastuldevice", device); + settings.writeEntry("/qgis/gps/lastulport", port); + emit closeGui(); } +void Plugin::setupBabel() { + + // where is gpsbabel? + QSettings settings; + mBabelPath = settings.readEntry("/qgis/gps/gpsbabelpath"); + if (mBabelPath.isEmpty()) + mBabelPath = "gpsbabel"; + // the importable formats + mImporters["Geocaching.com .loc"] = + new QgsSimpleBabelFormat("geo", true, false, false); + mImporters["Magellan Mapsend"] = + new QgsSimpleBabelFormat("mapsend", true, true, true); + mImporters["Garmin PCX5"] = + new QgsSimpleBabelFormat("pcx", true, false, true); + mImporters["Garmin Mapsource"] = + new QgsSimpleBabelFormat("mapsource", true, true, true); + mImporters["GPSUtil"] = + new QgsSimpleBabelFormat("gpsutil", true, false, false); + mImporters["PocketStreets 2002/2003 Pushpin"] = + new QgsSimpleBabelFormat("psp", true, false, false); + mImporters["CoPilot Flight Planner"] = + new QgsSimpleBabelFormat("copilot", true, false, false); + mImporters["Magellan Navigator Companion"] = + new QgsSimpleBabelFormat("magnav", true, false, false); + mImporters["Holux"] = + new QgsSimpleBabelFormat("holux", true, false, false); + mImporters["Topo by National Geographic"] = + new QgsSimpleBabelFormat("tpg", true, false, false); + mImporters["TopoMapPro"] = + new QgsSimpleBabelFormat("tmpro", true, false, false); + mImporters["GeocachingDB"] = + new QgsSimpleBabelFormat("gcdb", true, false, false); + mImporters["Tiger"] = + new QgsSimpleBabelFormat("tiger", true, false, false); + mImporters["EasyGPS Binary Format"] = + new QgsSimpleBabelFormat("easygps", true, false, false); + mImporters["Delorme Routes"] = + new QgsSimpleBabelFormat("saroute", false, false, true); + mImporters["Navicache"] = + new QgsSimpleBabelFormat("navicache", true, false, false); + mImporters["PSITrex"] = + new QgsSimpleBabelFormat("psitrex", true, true, true); + mImporters["Delorme GPS Log"] = + new QgsSimpleBabelFormat("gpl", false, false, true); + mImporters["OziExplorer"] = + new QgsSimpleBabelFormat("ozi", true, false, false); + mImporters["NMEA Sentences"] = + new QgsSimpleBabelFormat("nmea", true, false, true); + mImporters["Delorme Street Atlas 2004 Plus"] = + new QgsSimpleBabelFormat("saplus", true, false, false); + mImporters["Microsoft Streets and Trips"] = + new QgsSimpleBabelFormat("s_and_t", true, false, false); + mImporters["NIMA/GNIS Geographic Names"] = + new QgsSimpleBabelFormat("nima", true, false, false); + mImporters["Maptech"] = + new QgsSimpleBabelFormat("mxf", true, false, false); + mImporters["Mapopolis.com Mapconverter Application"] = + new QgsSimpleBabelFormat("mapconverter", true, false, false); + mImporters["GPSman"] = + new QgsSimpleBabelFormat("gpsman", true, false, false); + mImporters["GPSDrive"] = + new QgsSimpleBabelFormat("gpsdrive", true, false, false); + mImporters["Fugawi"] = + new QgsSimpleBabelFormat("fugawi", true, false, false); + mImporters["DNA"] = + new QgsSimpleBabelFormat("dna", true, false, false); + + // and the GPS devices + mDevices["Garmin serial"] = + new QgsBabelCommand("%babel -i garmin -o gpx /dev/ttyS0 %out", + "%babel -i gpx -o garmin %in /dev/ttyS0"); + QStringList deviceNames = settings.readListEntry("/qgis/gps/devicelist"); + QStringList::iterator iter; + for (iter = deviceNames.begin(); iter != deviceNames.end(); ++iter) { + QString download = settings. + readEntry(QString("/qgis/gps/devices/%1/download").arg(*iter), ""); + QString upload = settings. + readEntry(QString("/qgis/gps/devices/%1/upload").arg(*iter), ""); + mDevices[*iter] = new QgsBabelCommand(download, upload); + } +} + + + /** * Required extern functions needed for every plugin diff --git a/plugins/gps_importer/plugin.h b/plugins/gps_importer/plugin.h index 7c7e76b6d01..8edce4e2b82 100644 --- a/plugins/gps_importer/plugin.h +++ b/plugins/gps_importer/plugin.h @@ -19,6 +19,7 @@ /* $Id$ */ #ifndef PLUGIN #define PLUGIN +#include "qgsbabelformat.h" #include "../qgisplugin.h" #include #include @@ -32,14 +33,15 @@ class QgsVectorLayer; */ class Plugin:public QObject, public QgisPlugin { - Q_OBJECT public: + Q_OBJECT +public: /** * Constructor for a plugin. The QgisApp and QgisIface pointers are passed by * QGIS when it attempts to instantiate the plugin. * @param qgis Pointer to the QgisApp object * @param qI Pointer to the QgisIface object. */ - Plugin(QgisApp * , QgisIface * ); + Plugin(QgisApp * , QgisIface * ); /** * Virtual function to return the name of the plugin. The name will be used when presenting a list * of installable plugins to the user @@ -64,8 +66,6 @@ class Plugin:public QObject, public QgisPlugin public slots: //! Show the dialog box void run(); - //!draw a raster layer in the qui - void drawRasterLayer(QString); //! Add a vector layer given vectorLayerPath, baseName, providerKey ("ogr" or "postgres"); void drawVectorLayer(QString,QString,QString); //! unload the plugin @@ -76,22 +76,24 @@ class Plugin:public QObject, public QgisPlugin //! load a GPX file void loadGPXFile(QString filename, bool loadWaypoints, bool loadRoutes, bool loadTracks); - void importGPSFile(QString inputFilename, QString inputFormat, + void importGPSFile(QString inputFilename, QgsBabelFormat* importer, bool importWaypoints, bool importRoutes, bool importTracks, QString outputFilename, QString layerName); - void downloadFromGPS(QString protocol, QString deviceFilename, + void downloadFromGPS(QString device, QString port, bool downloadWaypoints, bool downloadRoutes, bool downloadTracks, QString outputFilename, QString layerName); - void uploadToGPS(QgsVectorLayer* gpxLayer, QString protocol, - QString deviceFilename); + void uploadToGPS(QgsVectorLayer* gpxLayer, QString device, + QString port); signals: void closeGui(); - private: + private: + + void setupBabel(); //! Name of the plugin @@ -112,6 +114,10 @@ class Plugin:public QObject, public QgisPlugin QgisIface *qGisInterface; //! Pointer to the QAction object used in the menu and toolbar QAction *myQActionPointer; + + QString mBabelPath; + std::map mImporters; + std::map mDevices; }; #endif diff --git a/plugins/gps_importer/plugingui.cpp b/plugins/gps_importer/plugingui.cpp index 648d41e8839..7f7bd173266 100644 --- a/plugins/gps_importer/plugingui.cpp +++ b/plugins/gps_importer/plugingui.cpp @@ -10,6 +10,7 @@ * (at your option) any later version. * ***************************************************************************/ #include "plugingui.h" +#include "qgsgpsdevicedialog.h" #include "../../src/qgsmaplayer.h" #include "../../src/qgsdataprovider.h" @@ -28,6 +29,7 @@ #include #include #include +#include #include "waypointtoshape.h" //standard includes @@ -36,22 +38,17 @@ #include -PluginGui::PluginGui() : PluginGuiBase() -{ - populateDeviceComboBox(); +PluginGui::PluginGui(const BabelMap& importers, BabelMap& devices, + std::vector gpxMapLayers, + QWidget* parent, const char* name, bool modal, WFlags fl) + : PluginGuiBase(parent, name, modal, fl), gpxLayers(gpxMapLayers), + mImporters(importers), mDevices(devices) { + populatePortComboBoxes(); populateULLayerComboBox(); populateIMPBabelFormats(); - tabWidget->removePage(tabWidget->page(2)); -} -PluginGui::PluginGui( std::vector gpxMapLayers, - QWidget* parent , const char* name , bool modal , - WFlags fl ) - : PluginGuiBase( parent, name, modal, fl ), gpxLayers(gpxMapLayers) -{ - populateDeviceComboBox(); - populateULLayerComboBox(); - populateIMPBabelFormats(); - tabWidget->removePage(tabWidget->page(2)); + + connect(pbULEditDevices, SIGNAL(clicked()), this, SLOT(openDeviceEditor())); + connect(pbDLEditDevices, SIGNAL(clicked()), this, SLOT(openDeviceEditor())); } PluginGui::~PluginGui() { @@ -97,7 +94,7 @@ void PluginGui::pbnOK_clicked() case 1: { const QString& typeString(cmbDLFeatureType->currentText()); emit importGPSFile(leIMPInput->text(), - babelFormats.find(impFormat)->second.formatName, + mImporters.find(impFormat)->second, typeString == "Waypoints", typeString == "Routes", typeString == "Tracks", leIMPOutput->text(), leIMPLayer->text()); @@ -107,9 +104,8 @@ void PluginGui::pbnOK_clicked() // or download GPS data from a device? case 2: { int featureType = cmbDLFeatureType->currentItem(); - emit downloadFromGPS(cmbDLProtocol->currentText().lower(), - cmbDLDevice->currentText(), featureType == 0, - featureType == 1, featureType == 2, + emit downloadFromGPS(cmbDLDevice->currentText(), cmbDLPort->currentText(), + featureType == 0, featureType == 1, featureType == 2, leDLOutput->text(), leDLBasename->text()); break; } @@ -117,52 +113,20 @@ void PluginGui::pbnOK_clicked() // or upload GPS data to a device? case 3: emit uploadToGPS(gpxLayers[cmbULLayer->currentItem()], - cmbULProtocol->currentText().lower(), - cmbULDevice->currentText()); + cmbULDevice->currentText(), cmbULPort->currentText()); break; } } -void PluginGui::pbnSelectInputFile_clicked() -{ - std::cout << " Gps File Importer::pbnSelectInputFile_clicked() " << std::endl; - QString myFileTypeQString; - QString myFilterString="Text File (*.txt)"; - QString myFileNameQString = QFileDialog::getOpenFileName( - "." , //initial dir - myFilterString, //filters to select - this , //parent dialog - "OpenFileDialog" , //QFileDialog qt object name - "Select GPS dump text file" , //caption - &myFileTypeQString //the pointer to store selected filter - ); - std::cout << "Selected filetype filter is : " << myFileTypeQString << std::endl; - leInputFile->setText(myFileNameQString); -} - - -void PluginGui::pbnSelectOutputFile_clicked() -{ - std::cout << " Gps File Importer Gui::pbnSelectOutputFile_clicked() " << std::endl; - QString myOutputFileNameQString = QFileDialog::getSaveFileName( - ".", - "ESRI Shapefile (*.shp)", - this, - "save file dialog" - "Choose a filename to save under" ); - leOutputShapeFile->setText(myOutputFileNameQString); -} - - void PluginGui::pbnDLOutput_clicked() { - QString myFileNameQString = QFileDialog::getSaveFileName( - "." , //initial dir - "GPS eXchange format (*.gpx)", - this , //parent dialog - "Select GPX output", - "Choose a filename to save under" ); + QString myFileNameQString = + QFileDialog::getSaveFileName("." , //initial dir + "GPS eXchange format (*.gpx)", + this , //parent dialog + "Select GPX output", + "Choose a filename to save under"); leDLOutput->setText(myFileNameQString); } @@ -193,18 +157,6 @@ void PluginGui::enableRelevantControls() } } - // import download file - else if (tabWidget->currentPageIndex() == 666) { - if ( (leOutputShapeFile->text()=="") || (leInputFile->text()=="") ) - { - pbnOK->setEnabled(false); - } - else - { - pbnOK->setEnabled(true); - } - } - // import other file else if (tabWidget->currentPageIndex() == 1) { @@ -224,7 +176,7 @@ void PluginGui::enableRelevantControls() pbnOK->setEnabled(true); } - // upload from device + // upload to device else if (tabWidget->currentPageIndex() == 3) { if (cmbULDevice->currentText() == "" || cmbULLayer->currentText() == "") pbnOK->setEnabled(false); @@ -245,8 +197,12 @@ void PluginGui::pbnGPXSelectFile_clicked() std::cout << " Gps File Importer::pbnGPXSelectFile_clicked() " << std::endl; QString myFileTypeQString; QString myFilterString="GPS eXchange format (*.gpx)"; + QSettings settings; + QString dir = settings.readEntry("/qgis/gps/gpxdirectory"); + if (dir.isEmpty()) + dir = "."; QString myFileNameQString = QFileDialog::getOpenFileName( - "." , //initial dir + dir , //initial dir myFilterString, //filters to select this , //parent dialog "OpenFileDialog" , //QFileDialog qt object name @@ -269,9 +225,9 @@ void PluginGui::pbnIMPInput_clicked() { &myFileType //the pointer to store selected filter ); impFormat = myFileType.left(myFileType.length() - 6); - std::map::const_iterator iter; - iter = babelFormats.find(impFormat); - if (iter == babelFormats.end()) { + std::map::const_iterator iter; + iter = mImporters.find(impFormat); + if (iter == mImporters.end()) { std::cerr<<"Unknown file format selected: " <first<<" selected"<setText(myFileName); cmbIMPFeature->clear(); - if (iter->second.hasWaypoints) + if (iter->second->supportsWaypoints()) cmbIMPFeature->insertItem("Waypoints"); - if (iter->second.hasRoutes) + if (iter->second->supportsRoutes()) cmbIMPFeature->insertItem("Routes"); - if (iter->second.hasTracks) + if (iter->second->supportsTracks()) cmbIMPFeature->insertItem("Tracks"); } } @@ -300,14 +256,15 @@ void PluginGui::pbnIMPOutput_clicked() { } -void PluginGui::populateDeviceComboBox() { +void PluginGui::populatePortComboBoxes() { + #ifdef linux // look for linux serial devices QString linuxDev("/dev/ttyS%1"); for (int i = 0; i < 10; ++i) { if (QFileInfo(linuxDev.arg(i)).exists()) { - cmbDLDevice->insertItem(linuxDev.arg(i)); - cmbULDevice->insertItem(linuxDev.arg(i)); + cmbDLPort->insertItem(linuxDev.arg(i)); + cmbULPort->insertItem(linuxDev.arg(i)); } else break; @@ -317,8 +274,8 @@ void PluginGui::populateDeviceComboBox() { linuxDev = "/dev/ttyUSB%1"; for (int i = 0; i < 10; ++i) { if (QFileInfo(linuxDev.arg(i)).exists()) { - cmbDLDevice->insertItem(linuxDev.arg(i)); - cmbULDevice->insertItem(linuxDev.arg(i)); + cmbDLPort->insertItem(linuxDev.arg(i)); + cmbULPort->insertItem(linuxDev.arg(i)); } else break; @@ -331,8 +288,8 @@ void PluginGui::populateDeviceComboBox() { QString freebsdDev("/dev/cuaa%1"); for (int i = 0; i < 10; ++i) { if (QFileInfo(freebsdDev.arg(i)).exists()) { - cmbDLDevice->insertItem(freebsdDev.arg(i)); - cmbULDevice->insertItem(freebsdDev.arg(i)); + cmbDLPort->insertItem(freebsdDev.arg(i)); + cmbULPort->insertItem(freebsdDev.arg(i)); } else break; @@ -344,8 +301,8 @@ void PluginGui::populateDeviceComboBox() { QString solarisDev("/dev/cua/%1"); for (int i = 'a'; i < 'k'; ++i) { if (QFileInfo(solarisDev.arg(char(i))).exists()) { - cmbDLDevice->insertItem(solarisDev.arg(char(i))); - cmbULDevice->insertItem(solarisDev.arg(char(i))); + cmbDLPort->insertItem(solarisDev.arg(char(i))); + cmbULPort->insertItem(solarisDev.arg(char(i))); } else break; @@ -353,14 +310,30 @@ void PluginGui::populateDeviceComboBox() { #endif #ifdef WIN32 - cmbULDevice->insertItem("com1"); - cmbULDevice->insertItem("com2"); - cmbDLDevice->insertItem("com1"); - cmbDLDevice->insertItem("com2"); + cmbULPort->insertItem("com1"); + cmbULPort->insertItem("com2"); + cmbDLPort->insertItem("com1"); + cmbDLPort->insertItem("com2"); #endif // OSX, OpenBSD, NetBSD etc? Anyone? - + + // remember the last ports used + QSettings settings; + QString lastDLPort = settings.readEntry("/qgis/gps/lastdlport", ""); + QString lastULPort = settings.readEntry("/qgis/gps/lastulport", ""); + for (int i = 0; i < cmbDLPort->count(); ++i) { + if (cmbDLPort->text(i) == lastDLPort) { + cmbDLPort->setCurrentItem(i); + break; + } + } + for (int i = 0; i < cmbULPort->count(); ++i) { + if (cmbULPort->text(i) == lastULPort) { + cmbULPort->setCurrentItem(i); + break; + } + } } @@ -373,65 +346,49 @@ void PluginGui::populateULLayerComboBox() { void PluginGui::populateIMPBabelFormats() { - babelFormats["Geocaching.com .loc"] = - BabelFormatInfo("geo", true, false, false); - babelFormats["Magellan Mapsend"] = - BabelFormatInfo("mapsend", true, true, true); - babelFormats["Garmin PCX5"] = - BabelFormatInfo("pcx", true, false, true); - babelFormats["Garmin Mapsource"] = - BabelFormatInfo("mapsource", true, true, true); - babelFormats["GPSUtil"] = - BabelFormatInfo("gpsutil", true, false, false); - babelFormats["PocketStreets 2002/2003 Pushpin"] = - BabelFormatInfo("psp", true, false, false); - babelFormats["CoPilot Flight Planner"] = - BabelFormatInfo("copilot", true, false, false); - babelFormats["Magellan Navigator Companion"] = - BabelFormatInfo("magnav", true, false, false); - babelFormats["Holux"] = - BabelFormatInfo("holux", true, false, false); - babelFormats["Topo by National Geographic"] = - BabelFormatInfo("tpg", true, false, false); - babelFormats["TopoMapPro"] = - BabelFormatInfo("tmpro", true, false, false); - babelFormats["GeocachingDB"] = - BabelFormatInfo("gcdb", true, false, false); - babelFormats["Tiger"] = - BabelFormatInfo("tiger", true, false, false); - babelFormats["EasyGPS Binary Format"] = - BabelFormatInfo("easygps", true, false, false); - babelFormats["Delorme Routes"] = - BabelFormatInfo("saroute", false, false, true); - babelFormats["Navicache"] = - BabelFormatInfo("navicache", true, false, false); - babelFormats["PSITrex"] = - BabelFormatInfo("psitrex", true, true, true); - babelFormats["Delorme GPS Log"] = - BabelFormatInfo("gpl", false, false, true); - babelFormats["OziExplorer"] = - BabelFormatInfo("ozi", true, false, false); - babelFormats["NMEA Sentences"] = - BabelFormatInfo("nmea", true, false, true); - babelFormats["Delorme Street Atlas 2004 Plus"] = - BabelFormatInfo("saplus", true, false, false); - babelFormats["Microsoft Streets and Trips"] = - BabelFormatInfo("s_and_t", true, false, false); - babelFormats["NIMA/GNIS Geographic Names"] = - BabelFormatInfo("nima", true, false, false); - babelFormats["Maptech"] = - BabelFormatInfo("mxf", true, false, false); - babelFormats["Mapopolis.com Mapconverter Application"] = - BabelFormatInfo("mapconverter", true, false, false); - babelFormats["GPSman"] = - BabelFormatInfo("gpsman", true, false, false); - babelFormats["GPSDrive"] = - BabelFormatInfo("gpsdrive", true, false, false); - babelFormats["Fugawi"] = - BabelFormatInfo("fugawi", true, false, false); - babelFormats["DNA"] = - BabelFormatInfo("dna", true, false, false); - std::map::const_iterator iter; - for (iter = babelFormats.begin(); iter != babelFormats.end(); ++iter) + babelFilter = ""; + cmbULDevice->clear(); + cmbDLDevice->clear(); + QSettings settings; + QString lastDLDevice = settings.readEntry("/qgis/gps/lastdldevice", ""); + QString lastULDevice = settings.readEntry("/qgis/gps/lastuldevice", ""); + BabelMap::const_iterator iter; + for (iter = mImporters.begin(); iter != mImporters.end(); ++iter) babelFilter.append((const char*)iter->first).append(" (*.*);;"); + int u = -1, d = -1; + for (iter = mDevices.begin(); iter != mDevices.end(); ++iter) { + if (iter->second->supportsExport()) { + cmbULDevice->insertItem(iter->first); + if (iter->first == lastULDevice) + u = cmbULDevice->count() - 1; + } + if (iter->second->supportsImport()) { + cmbDLDevice->insertItem(iter->first); + if (iter->first == lastDLDevice) + d = cmbDLDevice->count() - 1; + } + } + if (u != -1) + cmbULDevice->setCurrentItem(u); + if (d != -1) + cmbDLDevice->setCurrentItem(d); } + + +void populatePortComboBoxes() { + +} + + +void PluginGui::openDeviceEditor() { + QgsGPSDeviceDialog* dlg = new QgsGPSDeviceDialog(mDevices); + dlg->show(); + connect(dlg, SIGNAL(devicesChanged()), this, SLOT(slotDevicesUpdated())); +} + + +void PluginGui::slotDevicesUpdated() { + populateIMPBabelFormats(); +} + + diff --git a/plugins/gps_importer/plugingui.h b/plugins/gps_importer/plugingui.h index a52c3ba2df6..d2327002bd7 100644 --- a/plugins/gps_importer/plugingui.h +++ b/plugins/gps_importer/plugingui.h @@ -14,6 +14,7 @@ #include "../../src/qgsvectorlayer.h" #include "pluginguibase.h" +#include "qgsbabelformat.h" #include @@ -26,64 +27,59 @@ class PluginGui : public PluginGuiBase { Q_OBJECT - public: - PluginGui(); - PluginGui( std::vector gpxMapLayers, QWidget* parent , - const char* name , bool modal , WFlags ); - ~PluginGui(); +public: + PluginGui(const BabelMap& importers, BabelMap& devices, + std::vector gpxMapLayers, QWidget* parent, + const char* name , bool modal , WFlags); + ~PluginGui(); - private: - - void pbnSelectInputFile_clicked(); - void pbnSelectOutputFile_clicked(); - - void pbnGPXSelectFile_clicked(); - - void pbnIMPInput_clicked(); - void pbnIMPOutput_clicked(); - - void pbnDLOutput_clicked(); - - void enableRelevantControls(); - void pbnCancel_clicked(); - void pbnOK_clicked(); - - void populateDeviceComboBox(); - void populateULLayerComboBox(); - void populateIMPBabelFormats(); - -signals: - void drawRasterLayer(QString); - void drawVectorLayer(QString,QString,QString); - void loadGPXFile(QString filename, bool showWaypoints, bool showRoutes, - bool showTracks); - void importGPSFile(QString inputFilename, QString inputFormat, - bool importWaypoints, bool importRoutes, - bool importTracks, QString outputFilename, - QString layerName); - void downloadFromGPS(QString protocol, QString deviceFilename, - bool downloadWaypoints, bool downloadRoutes, - bool downloadTracks, QString outputFilename, - QString layerName); - void uploadToGPS(QgsVectorLayer* gpxLayer, QString protocol, - QString deviceFilename); +public slots: + void openDeviceEditor(); + void slotDevicesUpdated(); + private: - - struct BabelFormatInfo { - BabelFormatInfo(QString fn = "", bool hw = false, bool hr = false, - bool ht = false) : - formatName(fn), hasWaypoints(hw), hasRoutes(hr), hasTracks(ht) { } - QString formatName; - bool hasWaypoints; - bool hasRoutes; - bool hasTracks; - }; - - std::vector gpxLayers; - std::map babelFormats; - QString babelFilter; - QString impFormat; + + void pbnSelectInputFile_clicked(); + void pbnSelectOutputFile_clicked(); + + void pbnGPXSelectFile_clicked(); + + void pbnIMPInput_clicked(); + void pbnIMPOutput_clicked(); + + void pbnDLOutput_clicked(); + + void enableRelevantControls(); + void pbnCancel_clicked(); + void pbnOK_clicked(); + + void populateDeviceComboBox(); + void populateULLayerComboBox(); + void populateIMPBabelFormats(); + void populatePortComboBoxes(); + +signals: + void drawRasterLayer(QString); + void drawVectorLayer(QString,QString,QString); + void loadGPXFile(QString filename, bool showWaypoints, bool showRoutes, + bool showTracks); + void importGPSFile(QString inputFilename, QgsBabelFormat* importer, + bool importWaypoints, bool importRoutes, + bool importTracks, QString outputFilename, + QString layerName); + void downloadFromGPS(QString device, QString port, bool downloadWaypoints, + bool downloadRoutes, bool downloadTracks, + QString outputFilename, QString layerName); + void uploadToGPS(QgsVectorLayer* gpxLayer, QString device, QString port); + +private: + + std::vector gpxLayers; + const BabelMap& mImporters; + BabelMap& mDevices; + QString babelFilter; + QString impFormat; }; #endif diff --git a/plugins/gps_importer/pluginguibase.ui b/plugins/gps_importer/pluginguibase.ui index ad0d0afa5c2..e58c04f50f0 100644 --- a/plugins/gps_importer/pluginguibase.ui +++ b/plugins/gps_importer/pluginguibase.ui @@ -1,4 +1,4 @@ - + PluginGuiBase @@ -8,8 +8,8 @@ 0 0 - 763 - 405 + 606 + 370 @@ -287,125 +287,6 @@ tracks, so some feature types may be disabled for some file formats.</p> - - - tab - - - GPS Download File Importer - - - - unnamed - - - - teInstructions - - - <html><head><meta name="qrichtext" content="1" /></head><body style="font-size:12pt;font-family:Arial"> -<p style="margin-top:16px"><span style="font-size:17pt;font-weight:600">Description</span></p> -<p>Select the GPS download file that you would like to convert to a shapefile and this plugin will do the job for you! </p> -<p>Use the minumum time gap to let the importer know what time interval should be used before starting a new feature. </p> -<p>Use the minimum distance gap to define what distance between two readings should be considered the start of a new feature.</p> -</body></html> - - - - WidgetWidth - - - true - - - - - leInputFile - - - - - lblOutputFile - - - Output (Shape) File: - - - - - leOutputShapeFile - - - - - lblMinTimeGap - - - Minimum time gap (s): - - - - - lblMinDistanceGap - - - Minimum distance gap (dd): - - - - - spinMinTimeGap - - - 999999999 - - - 10 - - - 60 - - - - - pbnSelectInputFile - - - ... - - - - - pbnSelectOutputFile - - - ... - - - - - spinMinDistanceGap - - - 999999999 - - - 10 - - - 60 - - - - - lblInputFile - - - Input File: - - - - tab @@ -425,9 +306,9 @@ tracks, so some feature types may be disabled for some file formats.</p> <html><head><meta name="qrichtext" content="1" /></head><body style="font-size:12pt;font-family:Arial"> <p style="margin-top:16px"><span style="font-size:17pt;font-weight:600">Description</span></p> <p>This tool will help you download data from a GPS device. Choose your -protocol, the device your GPS is connected to, the feature type you want -to download, a name for your new layer, and the GPX file where -you want to store the data.</p> +GPS device, the port it is connected to, the feature type you want to download, a name for your new layer, +and the GPX file where you want to store the data. If your device isn't listed, or if +you want to change some settings, you can also edit the devices.</p> <p>This tool uses the program GPSBabel (<a href="http://gpsbabel.sf.net">http://gpsbabel.sf.net</a>) to transfer the data. If you don't have GPSBabel installed where QGIS can find it, this tool will not work.</p> @@ -441,22 +322,6 @@ don't have GPSBabel installed where QGIS can find it, this tool will not work.&l true - - - textLabel1 - - - Protocol: - - - - - textLabel3 - - - Device file: - - pbDLOutput @@ -465,6 +330,66 @@ don't have GPSBabel installed where QGIS can find it, this tool will not work.&l ... + + + pbDLEditDevices + + + Edit devices + + + + + cmbDLDevice + + + + + textLabel1 + + + GPS device: + + + + + spacer6 + + + Horizontal + + + Expanding + + + + 80 + 20 + + + + + + spacer5_2 + + + Horizontal + + + Expanding + + + + 80 + 20 + + + + + + leDLOutput + + textLabel2 @@ -473,12 +398,36 @@ don't have GPSBabel installed where QGIS can find it, this tool will not work.&l Output file: - + - leDLOutput + textLabel1_2 + + + Layer name: - + + + leDLBasename + + + + + textLabel1_3 + + + Feature type: + + + + + textLabel2_5 + + + Port: + + + Waypoints @@ -498,51 +447,9 @@ don't have GPSBabel installed where QGIS can find it, this tool will not work.&l cmbDLFeatureType - + - leDLBasename - - - - - textLabel1_2 - - - Layer name: - - - - - textLabel1_3 - - - Feature type: - - - - - - Garmin - - - - - Magellan - - - - cmbDLProtocol - - - true - - - - - cmbDLDevice - - - true + cmbDLPort @@ -558,23 +465,7 @@ don't have GPSBabel installed where QGIS can find it, this tool will not work.&l unnamed - - - textLabel3_2 - - - Device file: - - - - - textLabel1_4 - - - Protocol: - - - + teDLInstructions_2 @@ -582,10 +473,12 @@ don't have GPSBabel installed where QGIS can find it, this tool will not work.&l <html><head><meta name="qrichtext" content="1" /></head><body style="font-size:12pt;font-family:Arial"> <p style="margin-top:16px"><span style="font-size:17pt;font-weight:600">Description</span></p> <p>This tool will help you upload data from a GPX layer to a GPS device. -Choose the layer you want to upload, your protocol, and the device your -GPS is connected to.</p> -<p>This tool uses the program <a href="http://gpsbabel.sf.net">GPSBabel</a> to transfer the data. If you don't -have GPSBabel installed where QGIS can find it, this tool will not work.</p> +Choose the layer you want to upload, the device you want to upload it to, and the port +your device is connected to. +If your device isn't listed, or if you want to change some settings, you can also +edit the devices.</p> +<p>This tool uses the program GPSBabel (<a href="http://gpsbabel.sf.net">http://gpsbabel.sf.net</a>) +to transfer the data. If you don't have GPSBabel installed where QGIS can find it, this tool will not work.</p> </body></html> @@ -604,52 +497,60 @@ have GPSBabel installed where QGIS can find it, this tool will not work.</p&g Data layer: - - - - Garmin - - - - - Magellan - - + - cmbULProtocol + textLabel2_4 - - true + + GPS device: - + - cmbULDevice + pbULEditDevices - - true + + Edit devices - + - spacer2 + cmbULLayer + + + + + spacer11 - Vertical + Horizontal Expanding - 20 - 90 + 40 + 20 - + - cmbULLayer + cmbULDevice + + + + + textLabel3 + + + Port: + + + + + cmbULPort @@ -724,78 +625,18 @@ have GPSBabel installed where QGIS can find it, this tool will not work.</p&g PluginGuiBase pbnOK_clicked() - - pbnSelectInputFile - clicked() - PluginGuiBase - pbnSelectInputFile_clicked() - - - pbnSelectOutputFile - clicked() - PluginGuiBase - pbnSelectOutputFile_clicked() - pbnCancel clicked() PluginGuiBase pbnCancel_clicked() - - leInputFile - textChanged(const QString&) - PluginGuiBase - leInputFile_textChanged(const QString&) - - - leOutputShapeFile - textChanged(const QString&) - PluginGuiBase - leOutputShapeFile_textChanged(const QString&) - - - leGPXFile - textChanged(const QString&) - PluginGuiBase - leGPXFile_textChanged(const QString&) - - - pbnGPXSelectFile - clicked() - PluginGuiBase - pbnGPXSelectFile_clicked() - - - leGPXFile - textChanged(const QString&) - PluginGuiBase - enableRelevantControls() - - - leInputFile - textChanged(const QString&) - PluginGuiBase - enableRelevantControls() - - - leOutputShapeFile - textChanged(const QString&) - PluginGuiBase - enableRelevantControls() - tabWidget currentChanged(QWidget*) PluginGuiBase enableRelevantControls() - - cmbDLDevice - textChanged(const QString&) - PluginGuiBase - enableRelevantControls() - leDLBasename textChanged(const QString&) @@ -815,23 +656,11 @@ have GPSBabel installed where QGIS can find it, this tool will not work.</p&g pbnDLOutput_clicked() - leIMPInput + leIMPLayer textChanged(const QString&) PluginGuiBase enableRelevantControls() - - leIMPOutput - textChanged(const QString&) - PluginGuiBase - enableRelevantControls() - - - pbIMPInput - clicked() - PluginGuiBase - pbnIMPInput_clicked() - pbIMPOutput clicked() @@ -839,7 +668,13 @@ have GPSBabel installed where QGIS can find it, this tool will not work.</p&g pbnIMPOutput_clicked() - leIMPInput + pbIMPInput + clicked() + PluginGuiBase + pbnIMPInput_clicked() + + + leIMPOutput textChanged(const QString&) PluginGuiBase enableRelevantControls() @@ -851,7 +686,31 @@ have GPSBabel installed where QGIS can find it, this tool will not work.</p&g enableRelevantControls() - leIMPLayer + leIMPInput + textChanged(const QString&) + PluginGuiBase + enableRelevantControls() + + + leIMPInput + textChanged(const QString&) + PluginGuiBase + enableRelevantControls() + + + pbnGPXSelectFile + clicked() + PluginGuiBase + pbnGPXSelectFile_clicked() + + + leGPXFile + textChanged(const QString&) + PluginGuiBase + leGPXFile_textChanged(const QString&) + + + leGPXFile textChanged(const QString&) PluginGuiBase enableRelevantControls() @@ -859,11 +718,7 @@ have GPSBabel installed where QGIS can find it, this tool will not work.</p&g pbnOK_clicked() - pbnSelectInputFile_clicked() - pbnSelectOutputFile_clicked() pbnCancel_clicked() - leInputFile_textChanged( const QString & theQString ) - leOutputShapeFile_textChanged( const QString & theQString ) leGPXFile_textChanged( const QString & theQString ) pbnGPXSelectFile_clicked() cbGPXWaypoints_toggled( bool ) diff --git a/plugins/gps_importer/pluginguibase.ui.h b/plugins/gps_importer/pluginguibase.ui.h index 72451e7fef0..f58572480da 100644 --- a/plugins/gps_importer/pluginguibase.ui.h +++ b/plugins/gps_importer/pluginguibase.ui.h @@ -15,16 +15,6 @@ void PluginGuiBase::pbnOK_clicked() } -void PluginGuiBase::pbnSelectInputFile_clicked() -{ - -} - - -void PluginGuiBase::pbnSelectOutputFile_clicked() -{ - -} void PluginGuiBase::pbnCancel_clicked() @@ -33,30 +23,6 @@ void PluginGuiBase::pbnCancel_clicked() } -void PluginGuiBase::leInputFile_textChanged( const QString & theQString) -{ - if (theQString != "") - { - pbnOK->setEnabled(true); - } - else - { - pbnOK->setEnabled(false); - } -} - - -void PluginGuiBase::leOutputShapeFile_textChanged( const QString & theQString ) -{ - if (theQString != "") - { - pbnOK->setEnabled(true); - } - else - { - pbnOK->setEnabled(false); - } -} void PluginGuiBase::leGPXFile_textChanged( const QString & theQString )