18
18
#include " qgsgpsinformationwidget.h"
19
19
#include " qgsvectorlayer.h"
20
20
#include " qgsnmeaconnection.h"
21
- #include " qgsgpstrackerthread .h"
21
+ #include " qgsgpsdetector .h"
22
22
#include " qgscoordinatetransform.h"
23
23
#include < qgspoint.h>
24
24
#include < qgsrubberband.h>
58
58
59
59
QgsGPSInformationWidget::QgsGPSInformationWidget ( QgsMapCanvas * thepCanvas, QWidget * parent, Qt::WindowFlags f ):
60
60
QWidget( parent, f ),
61
- mSerialPort( 0 ),
62
61
mNmea( 0 ),
63
- mThread( 0 ) ,
64
62
mpCanvas( thepCanvas )
65
63
{
66
64
setupUi ( this );
@@ -293,69 +291,62 @@ void QgsGPSInformationWidget::on_mConnectButton_toggled( bool theFlag )
293
291
{
294
292
if ( theFlag )
295
293
{
296
- mConnectButton ->setText ( tr ( " Connecting..." ) );
297
294
connectGps ();
298
- mConnectButton ->setText ( tr ( " Disconnect" ) );
299
295
}
300
296
else
301
297
{
302
298
disconnectGps ();
303
- mConnectButton ->setText ( tr ( " Connect" ) );
304
299
}
305
300
}
306
301
307
302
void QgsGPSInformationWidget::connectGps ()
308
303
{
304
+ QString port;
305
+
309
306
if ( mRadUserPath ->isChecked () )
310
307
{
311
- if ( !mCboDevices ->itemData ( mCboDevices ->currentIndex () ).toString ().isEmpty () )
312
- {
313
- mNmea = new QgsNMEAConnection ( mCboDevices ->itemData ( mCboDevices ->currentIndex () ).toString (), 500 );
314
- QObject::connect ( mNmea , SIGNAL ( stateChanged ( const QgsGPSInformation& ) ),
315
- this , SLOT ( displayGPSInformation ( const QgsGPSInformation& ) ) );
316
- mThread = new QgsGPSTrackerThread ( mNmea );
317
- mThread ->start ();
318
- mGPSTextEdit ->append ( tr ( " Connecting on %1" ).arg ( mCboDevices ->itemData ( mCboDevices ->currentIndex () ).toString () ) );
319
- }
320
- else
308
+ port = mCboDevices ->itemData ( mCboDevices ->currentIndex () ).toString ();
309
+
310
+ if ( port.isEmpty () )
321
311
{
322
312
QMessageBox::information ( this , tr ( " /gps" ), tr ( " No path to the GPS port "
323
313
" is specified. Please enter a path then try again." ) );
324
314
// toggle the button back off
325
315
mConnectButton ->setChecked ( false );
326
- }
327
- }
328
- else // autodetect
329
- {
330
- mNmea = QgsGPSConnection::detectGPSConnection ();
331
- if ( !mNmea )
332
- {
333
- mConnectButton ->setChecked ( false );
334
316
return ;
335
317
}
336
- mNmea ->setPollInterval ( 1000 );
337
- QObject::connect ( mNmea , SIGNAL ( stateChanged ( const QgsGPSInformation& ) ), this , SLOT ( displayGPSInformation ( const QgsGPSInformation& ) ) );
338
-
339
- mThread = new QgsGPSTrackerThread ( mNmea );
340
- mThread ->start ();
341
- mGPSTextEdit ->append ( tr ( " Connected..." ) );
342
318
}
319
+
320
+ mGPSTextEdit ->append ( tr ( " Connecting..." ) );
321
+
322
+ QgsGPSDetector *detector = new QgsGPSDetector ( port );
323
+ connect ( detector, SIGNAL ( detected ( QgsGPSConnection * ) ), this , SLOT ( connected ( QgsGPSConnection * ) ) );
324
+ connect ( detector, SIGNAL ( detectionFailed () ), this , SLOT ( timedout () ) );
325
+ }
326
+
327
+ void QgsGPSInformationWidget::timedout ()
328
+ {
329
+ mConnectButton ->setChecked ( false );
330
+ mNmea = NULL ;
331
+ mGPSTextEdit ->append ( tr ( " Timed out!" ) );
343
332
}
333
+
334
+ void QgsGPSInformationWidget::connected ( QgsGPSConnection *conn )
335
+ {
336
+ mNmea = conn;
337
+ QObject::connect ( mNmea , SIGNAL ( stateChanged ( const QgsGPSInformation& ) ),
338
+ this , SLOT ( displayGPSInformation ( const QgsGPSInformation& ) ) );
339
+ mGPSTextEdit ->append ( tr ( " Connected!" ) );
340
+ mConnectButton ->setText ( tr ( " Disconnect" ) );
341
+ }
342
+
344
343
void QgsGPSInformationWidget::disconnectGps ()
345
344
{
346
- if ( mThread )
347
- {
348
- mThread ->quit ();
349
- mThread ->wait ();
350
- delete mThread ;
351
- mThread = 0 ;
352
- mNmea = 0 ;
353
- mSerialPort = 0 ;
354
- mGPSTextEdit ->append ( tr ( " Disconnected..." ) );
355
- }
356
- // mGPSTextEdit->clear();
357
- // toggle the button back on
345
+ delete mNmea ;
346
+
347
+ mGPSTextEdit ->append ( tr ( " Disconnected..." ) );
358
348
mConnectButton ->setChecked ( false );
349
+ mConnectButton ->setText ( tr ( " Connect" ) );
359
350
}
360
351
361
352
@@ -370,6 +361,7 @@ void QgsGPSInformationWidget::displayGPSInformation( const QgsGPSInformation& in
370
361
{
371
362
delete mMarkerList .takeFirst ();
372
363
}
364
+
373
365
for ( int i = 0 ; i < info.satellitesInView .size (); ++i )
374
366
{
375
367
QgsSatelliteInfo currentInfo = info.satellitesInView .at ( i );
@@ -858,7 +850,7 @@ void QgsGPSInformationWidget::on_mBtnRefreshDevices_clicked( )
858
850
/* Copied from gps plugin */
859
851
void QgsGPSInformationWidget::populateDevices ()
860
852
{
861
- QList< QPair<QString, QString> > ports = QgsGPSConnection ::availablePorts ();
853
+ QList< QPair<QString, QString> > ports = QgsGPSDetector ::availablePorts ();
862
854
863
855
mCboDevices ->clear ();
864
856
for ( int i = 0 ; i < ports.size (); i++ )
0 commit comments