Skip to content

Commit ebc75f3

Browse files
author
jef
committed
also show descriptions for GPS ports
git-svn-id: http://svn.osgeo.org/qgis/trunk@12747 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 2e90951 commit ebc75f3

File tree

4 files changed

+47
-50
lines changed

4 files changed

+47
-50
lines changed

src/app/gps/qgsgpsinformationwidget.cpp

+21-18
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,11 @@ QgsGPSInformationWidget::QgsGPSInformationWidget( QgsMapCanvas * thepCanvas, QWi
191191

192192
QgsGPSInformationWidget::~QgsGPSInformationWidget()
193193
{
194-
if ( mpMapMarker ) delete mpMapMarker;
194+
if ( mpMapMarker )
195+
delete mpMapMarker;
196+
195197
QSettings mySettings;
196-
mySettings.setValue( "/gps/lastPort", mCboDevices->currentText() );
198+
mySettings.setValue( "/gps/lastPort", mCboDevices->itemData( mCboDevices->currentIndex() ).toString() );
197199
mySettings.setValue( "/gps/trackWidth", mSpinTrackWidth->value() );
198200
mySettings.setValue( "/gps/markerSize", mSliderMarkerSize->value() );
199201
mySettings.setValue( "/gps/autoAddVertices", mCbxAutoAddVertices->isChecked() );
@@ -220,6 +222,7 @@ QgsGPSInformationWidget::~QgsGPSInformationWidget()
220222
{
221223
mySettings.setValue( "/gps/panMode", "none" );
222224
}
225+
223226
if ( mpRubberBand )
224227
{
225228
delete mpRubberBand;
@@ -305,14 +308,14 @@ void QgsGPSInformationWidget::connectGps()
305308
{
306309
if ( mRadUserPath->isChecked() )
307310
{
308-
if ( !mCboDevices->currentText().isEmpty() )
311+
if ( !mCboDevices->itemData( mCboDevices->currentIndex() ).toString().isEmpty() )
309312
{
310-
mNmea = new QgsNMEAConnection( mCboDevices->currentText(), 500 );
313+
mNmea = new QgsNMEAConnection( mCboDevices->itemData( mCboDevices->currentIndex() ).toString(), 500 );
311314
QObject::connect( mNmea, SIGNAL( stateChanged( const QgsGPSInformation& ) ),
312315
this, SLOT( displayGPSInformation( const QgsGPSInformation& ) ) );
313316
mThread = new QgsGPSTrackerThread( mNmea );
314317
mThread->start();
315-
mGPSTextEdit->append( tr( "Connecting on %1" ).arg( mCboDevices->currentText() ) );
318+
mGPSTextEdit->append( tr( "Connecting on %1" ).arg( mCboDevices->itemData( mCboDevices->currentIndex() ).toString() ) );
316319
}
317320
else
318321
{
@@ -418,7 +421,8 @@ void QgsGPSInformationWidget::displayGPSInformation( const QgsGPSInformation& in
418421
}
419422
mpCurve->setData( myXData, mySignalData );
420423
mpPlot->replot();
421-
if ( mpMapMarker ) delete mpMapMarker;
424+
if ( mpMapMarker )
425+
delete mpMapMarker;
422426
QgsPoint myNewCenter = QgsPoint( info.longitude, info.latitude );
423427
if ( mGroupShowMarker->isChecked() )
424428
{
@@ -854,31 +858,30 @@ void QgsGPSInformationWidget::on_mBtnRefreshDevices_clicked( )
854858
/* Copied from gps plugin */
855859
void QgsGPSInformationWidget::populateDevices()
856860
{
861+
QList< QPair<QString, QString> > ports = QgsGPSConnection::availablePorts();
862+
857863
mCboDevices->clear();
858-
mCboDevices->addItems( QgsGPSConnection::availablePorts() );
864+
for ( int i = 0; i < ports.size(); i++ )
865+
{
866+
mCboDevices->addItem( ports[i].second, ports[i].first );
867+
}
859868

860869
// remember the last ports used
861870
QSettings settings;
862871
QString lastPort = settings.value( "/gps/lastPort", "" ).toString();
863-
for ( int i = 0; i < mCboDevices->count(); ++i )
864-
{
865-
if ( mCboDevices->itemText( i ) == lastPort )
866-
{
867-
mCboDevices->setCurrentIndex( i );
868-
break;
869-
}
870-
}
872+
873+
int idx = mCboDevices->findData( lastPort );
874+
mCboDevices->setCurrentIndex( idx < 0 ? 0 : idx );
871875
}
872876

873877
void QgsGPSInformationWidget::createRubberBand( )
874878
{
875-
if ( mpRubberBand == 0 )
879+
if ( mpRubberBand )
876880
{
877881
delete mpRubberBand;
878882
}
879883
QSettings settings;
880-
bool isPolygon = false;
881-
mpRubberBand = new QgsRubberBand( mpCanvas, isPolygon );
884+
mpRubberBand = new QgsRubberBand( mpCanvas, false );
882885
setTrackColour();
883886
mpRubberBand->setWidth( settings.value( "/gps/trackWidth", 2 ).toInt() );
884887
mpRubberBand->show();

src/core/gps/qgsgpsconnection.cpp

+10-8
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,11 @@ QgsGPSConnection* QgsGPSConnection::detectGPSConnection()
152152
QList<BaudRateType>::const_iterator baudIt = baudRatesToTry.constBegin();
153153
for ( ; baudIt != baudRatesToTry.constEnd(); ++baudIt )
154154
{
155-
foreach( QString portname, availablePorts() )
155+
QList< QPair<QString, QString> > ports = availablePorts();
156+
157+
for ( int i = 0; i < ports.size(); i++ )
156158
{
157-
port = new QextSerialPort( portname );
159+
port = new QextSerialPort( ports[i].first );
158160
port->setBaudRate( *baudIt );
159161
port->setFlowControl( FLOW_OFF );
160162
port->setParity( PAR_NONE );
@@ -192,9 +194,9 @@ QgsGPSConnection* QgsGPSConnection::detectGPSConnection()
192194
return 0;
193195
}
194196

195-
QStringList QgsGPSConnection::availablePorts()
197+
QList< QPair<QString, QString> > QgsGPSConnection::availablePorts()
196198
{
197-
QStringList devs;
199+
QList< QPair<QString, QString> > devs;
198200

199201
#ifdef linux
200202
// look for linux serial devices
@@ -204,7 +206,7 @@ QStringList QgsGPSConnection::availablePorts()
204206
{
205207
if ( QFileInfo( linuxDev.arg( i ) ).exists() )
206208
{
207-
devs << linuxDev.arg( i );
209+
devs << QPair<QString, QString>( linuxDev.arg( i ), linuxDev.arg( i ) );
208210
}
209211
}
210212
}
@@ -218,7 +220,7 @@ QStringList QgsGPSConnection::availablePorts()
218220
{
219221
if ( QFileInfo( freebsdDev.arg( i ) ).exists() )
220222
{
221-
devs << freebsdDev.arg( i );
223+
devs << QPair<QString, QString>( freebsdDev.arg( i ), freebsdDev.arg( i ) );
222224
}
223225
}
224226
}
@@ -231,7 +233,7 @@ QStringList QgsGPSConnection::availablePorts()
231233
{
232234
if ( QFileInfo( solarisDev.arg( i ) ).exists() )
233235
{
234-
devs << solarisDev.arg( i );
236+
devs << QPair<QString, QString>( solarisDev.arg( i ), solarisDev.arg( i ) );
235237
}
236238
}
237239
#endif
@@ -240,7 +242,7 @@ QStringList QgsGPSConnection::availablePorts()
240242
QList<QextPortInfo> ports = QextSerialEnumerator::getPorts();
241243
foreach( QextPortInfo port, ports )
242244
{
243-
devs << port.portName;
245+
devs << QPair<QString, QString>( port.portName, port.friendName );
244246
}
245247
#endif
246248

src/plugins/gps_importer/qgsgpsplugingui.cpp

+16-21
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ void QgsGPSPluginGui::on_buttonBox_accepted()
113113
fileName += ".gpx";
114114
}
115115

116-
emit downloadFromGPS( cmbDLDevice->currentText(), cmbDLPort->currentText(),
116+
emit downloadFromGPS( cmbDLDevice->currentText(),
117+
cmbDLPort->itemData( cmbDLPort->currentIndex() ).toString(),
117118
featureType == 0, featureType == 1, featureType == 2,
118119
fileName, leDLBasename->text() );
119120
break;
@@ -122,7 +123,8 @@ void QgsGPSPluginGui::on_buttonBox_accepted()
122123
case 3:
123124
{
124125
emit uploadToGPS( mGPXLayers[cmbULLayer->currentIndex()],
125-
cmbULDevice->currentText(), cmbULPort->currentText() );
126+
cmbULDevice->currentText(),
127+
cmbULPort->itemData( cmbULPort->currentIndex() ).toString() );
126128
break;
127129
}
128130
// or convert between waypoints/tracks=
@@ -304,32 +306,25 @@ void QgsGPSPluginGui::on_pbnRefresh_clicked()
304306

305307
void QgsGPSPluginGui::populatePortComboBoxes()
306308
{
307-
QStringList devs = QgsGPSConnection::availablePorts() << "usb:";
309+
QList< QPair<QString, QString> > devs = QgsGPSConnection::availablePorts() << QPair<QString, QString>( "usb:", "usb:" );
310+
308311
cmbDLPort->clear();
309-
cmbDLPort->addItems( devs );
310312
cmbULPort->clear();
311-
cmbULPort->addItems( devs );
313+
for ( int i = 0; i < devs.size(); i++ )
314+
{
315+
cmbDLPort->addItem( devs[i].second, devs[i].first );
316+
cmbULPort->addItem( devs[i].second, devs[i].first );
317+
}
312318

313319
// remember the last ports used
314320
QSettings settings;
315321
QString lastDLPort = settings.value( "/Plugin-GPS/lastdlport", "" ).toString();
316322
QString lastULPort = settings.value( "/Plugin-GPS/lastulport", "" ).toString();
317-
for ( int i = 0; i < cmbDLPort->count(); ++i )
318-
{
319-
if ( cmbDLPort->itemText( i ) == lastDLPort )
320-
{
321-
cmbDLPort->setCurrentIndex( i );
322-
break;
323-
}
324-
}
325-
for ( int i = 0; i < cmbULPort->count(); ++i )
326-
{
327-
if ( cmbULPort->itemText( i ) == lastULPort )
328-
{
329-
cmbULPort->setCurrentIndex( i );
330-
break;
331-
}
332-
}
323+
324+
int idx = cmbDLPort->findData( lastDLPort );
325+
cmbDLPort->setCurrentIndex( idx < 0 ? 0 : idx );
326+
idx = cmbULPort->findData( lastULPort );
327+
cmbULPort->setCurrentIndex( idx < 0 ? 0 : idx );
333328
}
334329

335330

src/ui/qgsgpsinformationwidgetbase.ui

-3
Original file line numberDiff line numberDiff line change
@@ -318,9 +318,6 @@
318318
<layout class="QHBoxLayout" name="horizontalLayout">
319319
<item>
320320
<widget class="QLabel" name="mPathLabel">
321-
<property name="enabled">
322-
<bool>false</bool>
323-
</property>
324321
<property name="text">
325322
<string>Path to serial device</string>
326323
</property>

0 commit comments

Comments
 (0)