/*! Unzoom the plot \sa zoom() */ void QwtPolarPlot::unzoom() { if ( d_data->zoomFactor != 1.0 || d_data->zoomPos.isValid() ) { d_data->zoomFactor = 1.0; d_data->zoomPos = QwtPolarPoint(); autoRefresh(); } }
/*! \brief Calculate the bounding rect of the plot area The plot area depends on the zoom parameters. \param canvasRect Rectangle of the canvas \return Rectangle for displaying 100% of the plot */ QwtDoubleRect QwtPolarPlot::plotRect( const QRect &canvasRect ) const { const QwtScaleDiv *sd = scaleDiv( QwtPolar::Radius ); const QwtScaleEngine *se = scaleEngine( QwtPolar::Radius ); const int margin = plotMarginHint(); const QRect cr = canvasRect; const int radius = qwtMin( cr.width(), cr.height() ) / 2 - margin; QwtScaleMap map; map.setTransformation( se->transformation() ); map.setPaintXInterval( 0.0, radius / d_data->zoomFactor ); #if QWT_VERSION < 0x050200 map.setScaleInterval( sd->lBound(), sd->hBound() ); #else map.setScaleInterval( sd->lowerBound(), sd->upperBound() ); #endif double v = map.s1(); if ( map.s1() <= map.s2() ) v += d_data->zoomPos.radius(); else v -= d_data->zoomPos.radius(); v = map.xTransform( v ); const QwtDoublePoint off = QwtPolarPoint( d_data->zoomPos.azimuth(), v ).toPoint(); QwtDoublePoint center( cr.center().x(), cr.top() + margin + radius ); center -= QwtDoublePoint( off.x(), -off.y() ); QwtDoubleRect rect( 0, 0, 2 * map.p2(), 2 * map.p2() ); rect.moveCenter( center ); return rect; }
void QgsGPSInformationWidget::displayGPSInformation( const QgsGPSInformation &info ) { QVector<QPointF> data; // set validity flag and status from GPS data // based on GGA, GSA and RMC sentences - the logic does not require all bool validFlag = false; // true if GPS indicates position fix FixStatus fixStatus = NoData; // no fix if any of the three report bad; default values are invalid values and won't be changed if the corresponding NMEA msg is not received if ( info.status == 'V' || info.fixType == NMEA_FIX_BAD || info.quality == 0 ) // some sources say that 'V' indicates position fix, but is below acceptable quality { fixStatus = NoFix; } else if ( info.fixType == NMEA_FIX_2D ) // 2D indication (from GGA) { fixStatus = Fix2D; validFlag = true; } else if ( info.status == 'A' || info.fixType == NMEA_FIX_3D || info.quality > 0 ) // good { fixStatus = Fix3D; validFlag = true; } else // unknown status (not likely) { } // set visual status indicator -- do only on change of state if ( fixStatus != mLastFixStatus ) { setStatusIndicator( fixStatus ); } if ( mStackedWidget->currentIndex() == 1 && info.satInfoComplete ) //signal { mpPlot->setAxisScale( QwtPlot::xBottom, 0, info.satellitesInView.size() ); } //signal #ifdef WITH_QWTPOLAR if ( mStackedWidget->currentIndex() == 2 && info.satInfoComplete ) //satellites { while ( !mMarkerList.isEmpty() ) { delete mMarkerList.takeFirst(); } } //satellites #endif if ( mStackedWidget->currentIndex() == 4 ) //debug { mGPSPlainTextEdit->clear(); } //debug for ( int i = 0; i < info.satellitesInView.size(); ++i ) //satellite processing loop { QgsSatelliteInfo currentInfo = info.satellitesInView.at( i ); if ( mStackedWidget->currentIndex() == 1 && info.satInfoComplete ) //signal { data << QPointF( i, 0 ); data << QPointF( i, currentInfo.signal ); data << QPointF( i + 1, currentInfo.signal ); data << QPointF( i + 1, 0 ); } //signal if ( mStackedWidget->currentIndex() == 2 && info.satInfoComplete ) //satellites { QColor bg( Qt::white ); // moved several items outside of the following if block to minimize loop time bg.setAlpha( 200 ); QColor myColor; // Add a marker to the polar plot if ( currentInfo.id > 0 ) // don't show satellite if id=0 (no satellite indication) { #ifdef WITH_QWTPOLAR QwtPolarMarker *mypMarker = new QwtPolarMarker(); #if (QWT_POLAR_VERSION<0x010000) mypMarker->setPosition( QwtPolarPoint( currentInfo.azimuth, currentInfo.elevation ) ); #else mypMarker->setPosition( QwtPointPolar( currentInfo.azimuth, currentInfo.elevation ) ); #endif #endif if ( currentInfo.signal < 30 ) //weak signal { myColor = Qt::red; } else { myColor = Qt::black; //strong signal } #ifdef WITH_QWTPOLAR QBrush symbolBrush( Qt::black ); QSize markerSize( 9, 9 ); QBrush textBgBrush( bg ); #if (QWT_POLAR_VERSION<0x010000) mypMarker->setSymbol( QwtSymbol( QwtSymbol::Ellipse, symbolBrush, QPen( myColor ), markerSize ) ); #else mypMarker->setSymbol( new QwtSymbol( QwtSymbol::Ellipse, symbolBrush, QPen( myColor ), markerSize ) ); #endif mypMarker->setLabelAlignment( Qt::AlignHCenter | Qt::AlignTop ); QwtText text( QString::number( currentInfo.id ) ); text.setColor( myColor ); text.setBackgroundBrush( textBgBrush ); mypMarker->setLabel( text ); mypMarker->attach( mpSatellitesWidget ); mMarkerList << mypMarker; #endif } // currentInfo.id > 0 } //satellites } //satellite processing loop if ( mStackedWidget->currentIndex() == 1 && info.satInfoComplete ) //signal { mpCurve->setSamples( data ); mpPlot->replot(); } //signal #ifdef WITH_QWTPOLAR if ( mStackedWidget->currentIndex() == 2 && info.satInfoComplete ) //satellites { mpSatellitesWidget->replot(); } //satellites #endif if ( validFlag ) { validFlag = info.longitude >= -180.0 && info.longitude <= 180.0 && info.latitude >= -90.0 && info.latitude <= 90.0; } QgsPointXY myNewCenter; if ( validFlag ) { myNewCenter = QgsPointXY( info.longitude, info.latitude ); } else { myNewCenter = mLastGpsPosition; } if ( mStackedWidget->currentIndex() == 0 ) //position { mTxtLatitude->setText( QString::number( info.latitude, 'f', 8 ) ); mTxtLongitude->setText( QString::number( info.longitude, 'f', 8 ) ); mTxtAltitude->setText( tr( "%1 m" ).arg( info.elevation, 0, 'f', 1 ) ); // don't know of any GPS receivers that output better than 0.1 m precision if ( mDateTimeFormat.isEmpty() ) { mTxtDateTime->setText( info.utcDateTime.toString( Qt::TextDate ) ); // default format } else { mTxtDateTime->setText( info.utcDateTime.toString( mDateTimeFormat ) ); //user specified format string for testing the millisecond part of time } mTxtSpeed->setText( tr( "%1 km/h" ).arg( info.speed, 0, 'f', 1 ) ); mTxtDirection->setText( QString::number( info.direction, 'f', 1 ) + QStringLiteral( "°" ) ); mTxtHdop->setText( QString::number( info.hdop, 'f', 1 ) ); mTxtVdop->setText( QString::number( info.vdop, 'f', 1 ) ); mTxtPdop->setText( QString::number( info.pdop, 'f', 1 ) ); mTxtHacc->setText( QString::number( info.hacc, 'f', 1 ) + "m" ); mTxtVacc->setText( QString::number( info.vacc, 'f', 1 ) + "m" ); mTxtFixMode->setText( info.fixMode == 'A' ? tr( "Automatic" ) : info.fixMode == 'M' ? tr( "Manual" ) : QLatin1String( "" ) ); // A=automatic 2d/3d, M=manual; allowing for anything else mTxtFixType->setText( info.fixType == 3 ? tr( "3D" ) : info.fixType == 2 ? tr( "2D" ) : info.fixType == 1 ? tr( "No fix" ) : QString::number( info.fixType ) ); // 1=no fix, 2=2D, 3=3D; allowing for anything else mTxtQuality->setText( info.quality == 2 ? tr( "Differential" ) : info.quality == 1 ? tr( "Non-differential" ) : info.quality == 0 ? tr( "No position" ) : info.quality > 2 ? QString::number( info.quality ) : QLatin1String( "" ) ); // allowing for anything else mTxtSatellitesUsed->setText( QString::number( info.satellitesUsed ) ); mTxtStatus->setText( info.status == 'A' ? tr( "Valid" ) : info.status == 'V' ? tr( "Invalid" ) : QLatin1String( "" ) ); } //position // Avoid refreshing / panning if we haven't moved if ( mLastGpsPosition != myNewCenter ) { mLastGpsPosition = myNewCenter; // Pan based on user specified behavior if ( radRecenterMap->isChecked() || radRecenterWhenNeeded->isChecked() ) { QgsCoordinateReferenceSystem mypSRS = mpCanvas->mapSettings().destinationCrs(); QgsCoordinateTransform myTransform( mWgs84CRS, mypSRS ); // use existing WGS84 CRS QgsPointXY myPoint = myTransform.transform( myNewCenter ); //keep the extent the same just center the map canvas in the display so our feature is in the middle QgsRectangle myRect( myPoint, myPoint ); // empty rect can be used to set new extent that is centered on the point used to construct the rect // testing if position is outside some proportion of the map extent // this is a user setting - useful range: 5% to 100% (0.05 to 1.0) QgsRectangle myExtentLimit( mpCanvas->extent() ); myExtentLimit.scale( mSpinMapExtentMultiplier->value() * 0.01 ); // only change the extents if the point is beyond the current extents to minimize repaints if ( radRecenterMap->isChecked() || ( radRecenterWhenNeeded->isChecked() && !myExtentLimit.contains( myPoint ) ) ) { mpCanvas->setExtent( myRect ); mpCanvas->refresh(); } } //otherwise never recenter automatically if ( mCbxAutoAddVertices->isChecked() ) { addVertex(); } } // mLastGpsPosition != myNewCenter // new marker position after recentering if ( mGroupShowMarker->isChecked() ) // show marker { if ( validFlag ) // update cursor position if valid position { // initially, cursor isn't drawn until first valid fix; remains visible until GPS disconnect if ( ! mpMapMarker ) { mpMapMarker = new QgsGpsMarker( mpCanvas ); } mpMapMarker->setSize( mSliderMarkerSize->value() ); mpMapMarker->setCenter( myNewCenter ); } } else { if ( mpMapMarker ) { delete mpMapMarker; mpMapMarker = nullptr; } } // show marker }