Skip to content

Commit

Permalink
also show descriptions for GPS ports
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@12747 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Jan 12, 2010
1 parent 2e90951 commit ebc75f3
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 50 deletions.
39 changes: 21 additions & 18 deletions src/app/gps/qgsgpsinformationwidget.cpp
Expand Up @@ -191,9 +191,11 @@ QgsGPSInformationWidget::QgsGPSInformationWidget( QgsMapCanvas * thepCanvas, QWi

QgsGPSInformationWidget::~QgsGPSInformationWidget()
{
if ( mpMapMarker ) delete mpMapMarker;
if ( mpMapMarker )
delete mpMapMarker;

QSettings mySettings;
mySettings.setValue( "/gps/lastPort", mCboDevices->currentText() );
mySettings.setValue( "/gps/lastPort", mCboDevices->itemData( mCboDevices->currentIndex() ).toString() );
mySettings.setValue( "/gps/trackWidth", mSpinTrackWidth->value() );
mySettings.setValue( "/gps/markerSize", mSliderMarkerSize->value() );
mySettings.setValue( "/gps/autoAddVertices", mCbxAutoAddVertices->isChecked() );
Expand All @@ -220,6 +222,7 @@ QgsGPSInformationWidget::~QgsGPSInformationWidget()
{
mySettings.setValue( "/gps/panMode", "none" );
}

if ( mpRubberBand )
{
delete mpRubberBand;
Expand Down Expand Up @@ -305,14 +308,14 @@ void QgsGPSInformationWidget::connectGps()
{
if ( mRadUserPath->isChecked() )
{
if ( !mCboDevices->currentText().isEmpty() )
if ( !mCboDevices->itemData( mCboDevices->currentIndex() ).toString().isEmpty() )
{
mNmea = new QgsNMEAConnection( mCboDevices->currentText(), 500 );
mNmea = new QgsNMEAConnection( mCboDevices->itemData( mCboDevices->currentIndex() ).toString(), 500 );
QObject::connect( mNmea, SIGNAL( stateChanged( const QgsGPSInformation& ) ),
this, SLOT( displayGPSInformation( const QgsGPSInformation& ) ) );
mThread = new QgsGPSTrackerThread( mNmea );
mThread->start();
mGPSTextEdit->append( tr( "Connecting on %1" ).arg( mCboDevices->currentText() ) );
mGPSTextEdit->append( tr( "Connecting on %1" ).arg( mCboDevices->itemData( mCboDevices->currentIndex() ).toString() ) );
}
else
{
Expand Down Expand Up @@ -418,7 +421,8 @@ void QgsGPSInformationWidget::displayGPSInformation( const QgsGPSInformation& in
}
mpCurve->setData( myXData, mySignalData );
mpPlot->replot();
if ( mpMapMarker ) delete mpMapMarker;
if ( mpMapMarker )
delete mpMapMarker;
QgsPoint myNewCenter = QgsPoint( info.longitude, info.latitude );
if ( mGroupShowMarker->isChecked() )
{
Expand Down Expand Up @@ -854,31 +858,30 @@ void QgsGPSInformationWidget::on_mBtnRefreshDevices_clicked( )
/* Copied from gps plugin */
void QgsGPSInformationWidget::populateDevices()
{
QList< QPair<QString, QString> > ports = QgsGPSConnection::availablePorts();

mCboDevices->clear();
mCboDevices->addItems( QgsGPSConnection::availablePorts() );
for ( int i = 0; i < ports.size(); i++ )
{
mCboDevices->addItem( ports[i].second, ports[i].first );
}

// remember the last ports used
QSettings settings;
QString lastPort = settings.value( "/gps/lastPort", "" ).toString();
for ( int i = 0; i < mCboDevices->count(); ++i )
{
if ( mCboDevices->itemText( i ) == lastPort )
{
mCboDevices->setCurrentIndex( i );
break;
}
}

int idx = mCboDevices->findData( lastPort );
mCboDevices->setCurrentIndex( idx < 0 ? 0 : idx );
}

void QgsGPSInformationWidget::createRubberBand( )
{
if ( mpRubberBand == 0 )
if ( mpRubberBand )
{
delete mpRubberBand;
}
QSettings settings;
bool isPolygon = false;
mpRubberBand = new QgsRubberBand( mpCanvas, isPolygon );
mpRubberBand = new QgsRubberBand( mpCanvas, false );
setTrackColour();
mpRubberBand->setWidth( settings.value( "/gps/trackWidth", 2 ).toInt() );
mpRubberBand->show();
Expand Down
18 changes: 10 additions & 8 deletions src/core/gps/qgsgpsconnection.cpp
Expand Up @@ -152,9 +152,11 @@ QgsGPSConnection* QgsGPSConnection::detectGPSConnection()
QList<BaudRateType>::const_iterator baudIt = baudRatesToTry.constBegin();
for ( ; baudIt != baudRatesToTry.constEnd(); ++baudIt )
{
foreach( QString portname, availablePorts() )
QList< QPair<QString, QString> > ports = availablePorts();

for ( int i = 0; i < ports.size(); i++ )
{
port = new QextSerialPort( portname );
port = new QextSerialPort( ports[i].first );
port->setBaudRate( *baudIt );
port->setFlowControl( FLOW_OFF );
port->setParity( PAR_NONE );
Expand Down Expand Up @@ -192,9 +194,9 @@ QgsGPSConnection* QgsGPSConnection::detectGPSConnection()
return 0;
}

QStringList QgsGPSConnection::availablePorts()
QList< QPair<QString, QString> > QgsGPSConnection::availablePorts()
{
QStringList devs;
QList< QPair<QString, QString> > devs;

#ifdef linux
// look for linux serial devices
Expand All @@ -204,7 +206,7 @@ QStringList QgsGPSConnection::availablePorts()
{
if ( QFileInfo( linuxDev.arg( i ) ).exists() )
{
devs << linuxDev.arg( i );
devs << QPair<QString, QString>( linuxDev.arg( i ), linuxDev.arg( i ) );
}
}
}
Expand All @@ -218,7 +220,7 @@ QStringList QgsGPSConnection::availablePorts()
{
if ( QFileInfo( freebsdDev.arg( i ) ).exists() )
{
devs << freebsdDev.arg( i );
devs << QPair<QString, QString>( freebsdDev.arg( i ), freebsdDev.arg( i ) );
}
}
}
Expand All @@ -231,7 +233,7 @@ QStringList QgsGPSConnection::availablePorts()
{
if ( QFileInfo( solarisDev.arg( i ) ).exists() )
{
devs << solarisDev.arg( i );
devs << QPair<QString, QString>( solarisDev.arg( i ), solarisDev.arg( i ) );
}
}
#endif
Expand All @@ -240,7 +242,7 @@ QStringList QgsGPSConnection::availablePorts()
QList<QextPortInfo> ports = QextSerialEnumerator::getPorts();
foreach( QextPortInfo port, ports )
{
devs << port.portName;
devs << QPair<QString, QString>( port.portName, port.friendName );
}
#endif

Expand Down
37 changes: 16 additions & 21 deletions src/plugins/gps_importer/qgsgpsplugingui.cpp
Expand Up @@ -113,7 +113,8 @@ void QgsGPSPluginGui::on_buttonBox_accepted()
fileName += ".gpx";
}

emit downloadFromGPS( cmbDLDevice->currentText(), cmbDLPort->currentText(),
emit downloadFromGPS( cmbDLDevice->currentText(),
cmbDLPort->itemData( cmbDLPort->currentIndex() ).toString(),
featureType == 0, featureType == 1, featureType == 2,
fileName, leDLBasename->text() );
break;
Expand All @@ -122,7 +123,8 @@ void QgsGPSPluginGui::on_buttonBox_accepted()
case 3:
{
emit uploadToGPS( mGPXLayers[cmbULLayer->currentIndex()],
cmbULDevice->currentText(), cmbULPort->currentText() );
cmbULDevice->currentText(),
cmbULPort->itemData( cmbULPort->currentIndex() ).toString() );
break;
}
// or convert between waypoints/tracks=
Expand Down Expand Up @@ -304,32 +306,25 @@ void QgsGPSPluginGui::on_pbnRefresh_clicked()

void QgsGPSPluginGui::populatePortComboBoxes()
{
QStringList devs = QgsGPSConnection::availablePorts() << "usb:";
QList< QPair<QString, QString> > devs = QgsGPSConnection::availablePorts() << QPair<QString, QString>( "usb:", "usb:" );

cmbDLPort->clear();
cmbDLPort->addItems( devs );
cmbULPort->clear();
cmbULPort->addItems( devs );
for ( int i = 0; i < devs.size(); i++ )
{
cmbDLPort->addItem( devs[i].second, devs[i].first );
cmbULPort->addItem( devs[i].second, devs[i].first );
}

// remember the last ports used
QSettings settings;
QString lastDLPort = settings.value( "/Plugin-GPS/lastdlport", "" ).toString();
QString lastULPort = settings.value( "/Plugin-GPS/lastulport", "" ).toString();
for ( int i = 0; i < cmbDLPort->count(); ++i )
{
if ( cmbDLPort->itemText( i ) == lastDLPort )
{
cmbDLPort->setCurrentIndex( i );
break;
}
}
for ( int i = 0; i < cmbULPort->count(); ++i )
{
if ( cmbULPort->itemText( i ) == lastULPort )
{
cmbULPort->setCurrentIndex( i );
break;
}
}

int idx = cmbDLPort->findData( lastDLPort );
cmbDLPort->setCurrentIndex( idx < 0 ? 0 : idx );
idx = cmbULPort->findData( lastULPort );
cmbULPort->setCurrentIndex( idx < 0 ? 0 : idx );
}


Expand Down
3 changes: 0 additions & 3 deletions src/ui/qgsgpsinformationwidgetbase.ui
Expand Up @@ -318,9 +318,6 @@
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="mPathLabel">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Path to serial device</string>
</property>
Expand Down

0 comments on commit ebc75f3

Please sign in to comment.