2020#include " qgsgpsdetector.h"
2121#include " info.h"
2222#include " qgscoordinatetransform.h"
23- #include < qgspoint.h>
24- #include < qgsrubberband.h>
23+ #include " qgspoint.h"
24+ #include " qgsrubberband.h"
2525#include " qgsmaprenderer.h"
2626#include " qgsvectordataprovider.h"
2727#include " qgsvectorlayer.h"
3030#include " qgslogger.h"
3131#include " qgsfeatureaction.h"
3232#include " qgsgeometry.h"
33- #include < qgisapp.h>
33+ #include " qgisapp.h"
3434
3535// for avoid intersections static method
3636#include " qgsmaptooladdfeature.h"
5959#include < QPixmap>
6060#include < QPen>
6161
62- QgsGPSInformationWidget::QgsGPSInformationWidget ( QgsMapCanvas * thepCanvas, QWidget * parent, Qt::WindowFlags f ):
63- QWidget( parent, f ),
64- mNmea( 0 ),
65- mpCanvas( thepCanvas )
62+ QgsGPSInformationWidget::QgsGPSInformationWidget ( QgsMapCanvas * thepCanvas, QWidget * parent, Qt::WindowFlags f )
63+ : QWidget( parent, f )
64+ , mNmea( 0 )
65+ , mpCanvas( thepCanvas )
6666{
6767 setupUi ( this );
6868
@@ -323,20 +323,6 @@ void QgsGPSInformationWidget::on_mBtnTrackColor_clicked( )
323323 }
324324}
325325
326- #if 0 //no longer used
327- void QgsGPSInformationWidget::setTrackColor( )
328- {
329- QSettings mySettings;
330- QColor myColor( mySettings.value( "/qgis/gps/line_color_red", 255 ).toInt(),
331- mySettings.value( "/qgis/gps/line_color_green", 0 ).toInt(),
332- mySettings.value( "/qgis/gps/line_color_blue", 0 ).toInt() );
333- if ( mpRubberBand )
334- {
335- mpRubberBand->setColor( myColor );
336- }
337- }
338- #endif
339-
340326void QgsGPSInformationWidget::on_mBtnPosition_clicked ( )
341327{
342328 mStackedWidget ->setCurrentIndex ( 0 );
@@ -444,8 +430,8 @@ void QgsGPSInformationWidget::timedout()
444430void QgsGPSInformationWidget::connected ( QgsGPSConnection *conn )
445431{
446432 mNmea = conn;
447- QObject:: connect ( mNmea , SIGNAL ( stateChanged ( const QgsGPSInformation& ) ),
448- this , SLOT ( displayGPSInformation ( const QgsGPSInformation& ) ) );
433+ connect ( mNmea , SIGNAL ( stateChanged ( const QgsGPSInformation& ) ),
434+ this , SLOT ( displayGPSInformation ( const QgsGPSInformation& ) ) );
449435 mGPSPlainTextEdit ->appendPlainText ( tr ( " Connected!" ) );
450436 mConnectButton ->setText ( tr ( " Dis&connect" ) );
451437 // insert connection into registry such that it can also be used by other dialogs or plugins
@@ -466,7 +452,7 @@ void QgsGPSInformationWidget::connected( QgsGPSConnection *conn )
466452 // crude way to separate chunks - use when manually editing file - NMEA parsers should discard
467453 mLogFileTextStream << " ====" << " \r\n " ;
468454
469- QObject:: connect ( mNmea , SIGNAL ( nmeaSentenceReceived ( const QString& ) ), this , SLOT ( logNmeaSentence ( const QString& ) ) ); // added to handle raw data
455+ connect ( mNmea , SIGNAL ( nmeaSentenceReceived ( const QString& ) ), this , SLOT ( logNmeaSentence ( const QString& ) ) ); // added to handle raw data
470456 }
471457 else // error opening file
472458 {
@@ -483,7 +469,7 @@ void QgsGPSInformationWidget::disconnectGps()
483469{
484470 if ( mLogFile && mLogFile ->isOpen () )
485471 {
486- QObject:: disconnect ( mNmea , SIGNAL ( nmeaSentenceReceived ( const QString& ) ), this , SLOT ( logNmeaSentence ( const QString& ) ) );
472+ disconnect ( mNmea , SIGNAL ( nmeaSentenceReceived ( const QString& ) ), this , SLOT ( logNmeaSentence ( const QString& ) ) );
487473 mLogFile ->close ();
488474 delete mLogFile ;
489475 mLogFile = 0 ;
@@ -585,34 +571,6 @@ void QgsGPSInformationWidget::displayGPSInformation( const QgsGPSInformation& in
585571#endif
586572 } // signal
587573
588- #if 0
589- if ( mStackedWidget->currentIndex() == 4 ) //debug
590- {
591- #if 0 // temporarily removed as the info isn't being set in GSA/GSV processing
592- // mGPSPlainTextEdit->appendPlainText( "Satellite" );
593- if ( currentInfo.inUse )
594- {
595- mGPSPlainTextEdit->appendPlainText( "Satellite In use" );
596- }
597- else
598- {
599- mGPSPlainTextEdit->appendPlainText( "Satellite Not in use" );
600- }
601- #endif
602- #if 0
603- mGPSPlainTextEdit->appendPlainText( "id: " + QString::number( currentInfo.id ) );
604- mGPSPlainTextEdit->appendPlainText( "elevation: " + QString::number( currentInfo.elevation ) );
605- mGPSPlainTextEdit->appendPlainText( "azimuth: " + QString::number( currentInfo.azimuth ) );
606- mGPSPlainTextEdit->appendPlainText( "signal: " + QString::number( currentInfo.signal ) );
607- #else // as a single line per satellite - easier to read
608- mGPSPlainTextEdit->appendPlainText( "sat: " + QString::number( currentInfo.id )
609- + ", elev: " + QString::number( currentInfo.elevation )
610- + ", azimuth: " + QString::number( currentInfo.azimuth )
611- + ", signal: " + QString::number( currentInfo.signal ) );
612- #endif
613- } //debug
614- #endif
615-
616574 if ( mStackedWidget ->currentIndex () == 2 && info.satInfoComplete ) // satellites
617575 {
618576 QColor bg ( Qt::white ); // moved several items outside of the following if block to minimize loop time
@@ -671,6 +629,11 @@ void QgsGPSInformationWidget::displayGPSInformation( const QgsGPSInformation& in
671629 mpSatellitesWidget->replot ();
672630 } // satellites
673631
632+ if ( validFlag )
633+ {
634+ validFlag = info.longitude >= -180.0 && info.longitude <= 180.0 && info.latitude >= -90.0 && info.latitude <= 90.0 ;
635+ }
636+
674637 QgsPoint myNewCenter;
675638 if ( validFlag )
676639 {
@@ -708,32 +671,6 @@ void QgsGPSInformationWidget::displayGPSInformation( const QgsGPSInformation& in
708671 mTxtStatus ->setText ( info.status == ' A' ? tr ( " Valid" ) : info.status == ' V' ? tr ( " Invalid" ) : " " );
709672 } // position
710673
711- #if 0
712- if ( mStackedWidget->currentIndex() == 4 ) //debug
713- {
714- QString s;
715- for ( int i = 0; i < info.satPrn.size(); i++ )
716- {
717- if ( info.satPrn.at( i ) > 0 ) //don't show 0 (no satellite)
718- {
719- s.append( QString::number( info.satPrn.at( i ) ).append( " " ) );
720- }
721- }
722- mGPSPlainTextEdit->appendPlainText( "UTC date/time: " + info.utcDateTime.toString() );
723- mGPSPlainTextEdit->appendPlainText( "longitude: " + QString::number( info.longitude, 'f', 8 ) );
724- mGPSPlainTextEdit->appendPlainText( "latitude: " + QString::number( info.latitude, 'f', 8 ) );
725- mGPSPlainTextEdit->appendPlainText( "elevation: " + QString::number( info.elevation ) );
726- mGPSPlainTextEdit->appendPlainText( "speed (knots): " + QString::number( info.speed ) );
727- mGPSPlainTextEdit->appendPlainText( "direction: " + QString::number( info.direction ) );
728- mGPSPlainTextEdit->appendPlainText( "pdop: " + QString::number( info.pdop ) );
729- mGPSPlainTextEdit->appendPlainText( "hdop: " + QString::number( info.hdop ) );
730- mGPSPlainTextEdit->appendPlainText( "vdop: " + QString::number( info.vdop ) );
731- mGPSPlainTextEdit->appendPlainText( "satellites in use: " + s );
732- mGPSPlainTextEdit->appendPlainText( "fix mode: " + QString( info.fixMode ) );
733- mGPSPlainTextEdit->appendPlainText( "fix type: " + QString::number( info.fixType ) );
734- } //debug
735- #endif
736-
737674 // Avoid refreshing / panning if we havent moved
738675 if ( mLastGpsPosition != myNewCenter )
739676 {
@@ -792,28 +729,15 @@ void QgsGPSInformationWidget::displayGPSInformation( const QgsGPSInformation& in
792729 } // show marker
793730}
794731
795- #if 0 // not needed - signals/slots set up in UI file; may be needed in the future if GPS valid is used to control whether button is available (should use enable/disable instead of show/hide)
796- void QgsGPSInformationWidget::on_mCbxAutoAddVertices_toggled( bool theFlag )
797- {
798- if ( theFlag )
799- {
800- mBtnAddVertex->hide();
801- }
802- else
803- {
804- mBtnAddVertex->show();
805- }
806- }
807- #endif
808-
809732void QgsGPSInformationWidget::on_mBtnAddVertex_clicked ( )
810733{
811734 addVertex ();
812735}
813736
814- void QgsGPSInformationWidget::addVertex ( )
737+ void QgsGPSInformationWidget::addVertex ()
815738{
816739 QgsDebugMsg ( " Adding Vertex" );
740+
817741 if ( !mpRubberBand )
818742 {
819743 createRubberBand ( );
@@ -822,6 +746,7 @@ void QgsGPSInformationWidget::addVertex( )
822746 // we store the capture list in wgs84 and then transform to layer crs when
823747 // calling close feature
824748 mCaptureList .push_back ( mLastGpsPosition );
749+
825750 // we store the rubber band points in map canvas CRS so transform to map crs
826751 // potential problem with transform errors and wrong coordinates if map CRS is changed after points are stored - SLM
827752 // should catch map CRS change and transform the points
@@ -835,6 +760,7 @@ void QgsGPSInformationWidget::addVertex( )
835760 {
836761 myPoint = mLastGpsPosition ;
837762 }
763+
838764 mpRubberBand->addPoint ( myPoint );
839765}
840766
@@ -853,58 +779,6 @@ void QgsGPSInformationWidget::on_mBtnCloseFeature_clicked( )
853779
854780 // -------------- preconditions ------------------------
855781 // most of these preconditions are already handled due to the button being enabled/disabled based on layer geom type and editing capabilities, but not on valid GPS data
856- #if 0
857- if ( !vlayer )
858- {
859- QMessageBox::information( 0, tr( "Not a vector layer" ),
860- tr( "The current layer is not a vector layer" ) );
861- return;
862- }
863- QGis::WkbType layerWKBType = vlayer->wkbType();
864-
865- //no support for adding features to 2.5D types yet
866- if ( layerWKBType == QGis::WKBPoint25D ||
867- layerWKBType == QGis::WKBLineString25D ||
868- layerWKBType == QGis::WKBPolygon25D ||
869- layerWKBType == QGis::WKBMultiPoint25D ||
870- layerWKBType == QGis::WKBMultiLineString25D ||
871- layerWKBType == QGis::WKBMultiPolygon25D )
872- {
873- QMessageBox::critical( 0, tr( "2.5D shape type not supported" ), tr(
874- "Adding features to 2.5D shapetypes is not supported yet. Please "
875- "select a different editable, non 2.5D layer and try again." ) );
876- return;
877- }
878-
879- // Multipart features not supported
880- if ( layerWKBType == QGis::WKBMultiPoint ||
881- layerWKBType == QGis::WKBMultiLineString ||
882- layerWKBType == QGis::WKBMultiPolygon )
883- {
884- QMessageBox::critical( 0, tr( "Multipart shape type not supported" ), tr(
885- "Adding features to multipart shapetypes is not supported yet. Please "
886- "select a different editable, non 2.5D layer and try again." ) );
887- return;
888-
889- }
890-
891- QgsVectorDataProvider* provider = vlayer->dataProvider();
892-
893- if ( !( provider->capabilities() & QgsVectorDataProvider::AddFeatures ) )
894- {
895- QMessageBox::information( 0, tr( "Layer cannot be added to" ),
896- tr( "The data provider for this layer does not support the addition of features." ) );
897- return;
898- }
899-
900- if ( !vlayer->isEditable() )
901- {
902- QMessageBox::information( 0, tr( "Layer not editable" ),
903- tr( "Cannot edit the vector layer. Use 'Toggle Editing' to make it editable." )
904- );
905- return;
906- }
907- #endif
908782
909783 // lines: bail out if there are not at least two vertices
910784 if ( layerWKBType == QGis::WKBLineString && mCaptureList .size () < 2 )
@@ -1114,7 +988,8 @@ void QgsGPSInformationWidget::on_mBtnCloseFeature_clicked( )
1114988
1115989void QgsGPSInformationWidget::connectGpsSlot ( )
1116990{
1117- QObject::connect ( mNmea , SIGNAL ( stateChanged ( const QgsGPSInformation& ) ), this , SLOT ( displayGPSInformation ( const QgsGPSInformation& ) ) );
991+ connect ( mNmea , SIGNAL ( stateChanged ( const QgsGPSInformation& ) ),
992+ this , SLOT ( displayGPSInformation ( const QgsGPSInformation& ) ) );
1118993}
1119994
1120995void QgsGPSInformationWidget::on_mBtnRefreshDevices_clicked ( )
@@ -1155,27 +1030,6 @@ void QgsGPSInformationWidget::createRubberBand( )
11551030 mpRubberBand->show ();
11561031}
11571032
1158- #if 0 // this function isn't used
1159- QPointF QgsGPSInformationWidget::gpsToPixelPosition( const QgsPoint& point )
1160- {
1161- //transform to map crs
1162- QgsPoint myCenter;
1163- if ( mpCanvas && mpCanvas->mapRenderer() )
1164- {
1165- QgsCoordinateTransform t( mWgs84CRS, mpCanvas->mapRenderer()->destinationCrs() );
1166- myCenter = t.transform( point );
1167- }
1168- else
1169- {
1170- myCenter = point;
1171- }
1172-
1173- double x = myCenter.x(), y = myCenter.y();
1174- mpCanvas->getCoordinateTransform()->transformInPlace( x, y );
1175- return QPointF( x, y ) ;
1176- }
1177- #endif
1178-
11791033void QgsGPSInformationWidget::on_mBtnLogFile_clicked ()
11801034{
11811035// =========================
0 commit comments