void QgsMeasureDialog::mouseMove( QgsPoint &point ) { QSettings settings; int decimalPlaces = settings.value( "/qgis/measure/decimalplaces", "3" ).toInt(); // Create QgsDistance Area for customization ProjectionEnabled setting QgsDistanceArea myDa; configureDistanceArea( myDa ); // show current distance/area while moving the point // by creating a temporary copy of point array // and adding moving point at the end if ( mMeasureArea && mTool->points().size() > 1 ) { QList<QgsPoint> tmpPoints = mTool->points(); tmpPoints.append( point ); double area = myDa.measurePolygon( tmpPoints ); editTotal->setText( formatArea( area, decimalPlaces ) ); } else if ( !mMeasureArea && mTool->points().size() > 0 ) { QgsPoint p1( mTool->points().last() ), p2( point ); double d = myDa.measureLine( p1, p2 ); editTotal->setText( formatDistance( mTotal + d, decimalPlaces ) ); QGis::UnitType myDisplayUnits; // Ignore units convertMeasurement( d, myDisplayUnits, false ); QTreeWidgetItem *item = mTable->topLevelItem( mTable->topLevelItemCount() - 1 ); item->setText( 0, QLocale::system().toString( d, 'f', decimalPlaces ) ); } }
void QgsMeasureDialog::removeLastPoint() { int numPoints = mTool->points().size(); if ( mMeasureArea ) { if ( numPoints > 1 ) { QList<QgsPoint> tmpPoints = mTool->points(); tmpPoints.append( mLastMousePoint ); double area = mDa.measurePolygon( tmpPoints ); editTotal->setText( formatArea( area ) ); } else { editTotal->setText( formatArea( 0 ) ); } } else if ( !mMeasureArea && numPoints >= 1 ) { //remove final row delete mTable->takeTopLevelItem( mTable->topLevelItemCount() - 1 ); QgsPoint p1( mTool->points().last() ); double d = mDa.measureLine( p1, mLastMousePoint ); mTotal = mDa.measureLine( mTool->points() ); editTotal->setText( formatDistance( mTotal + d ) ); d = convertLength( d, mDistanceUnits ); QTreeWidgetItem *item = mTable->topLevelItem( mTable->topLevelItemCount() - 1 ); item->setText( 0, QLocale::system().toString( d, 'f', mDecimalPlaces ) ); } }
void QgsMeasureDialog::mouseMove( QgsPoint &point ) { // show current distance/area while moving the point // by creating a temporary copy of point array // and adding moving point at the end if ( mMeasureArea && mTool->points().size() >= 2 ) { QList<QgsPoint> tmpPoints = mTool->points(); tmpPoints.append( point ); double area = mDa.measurePolygon( tmpPoints ); editTotal->setText( formatArea( area ) ); } else if ( !mMeasureArea && mTool->points().size() >= 1 ) { QgsPoint p1( mTool->points().last() ), p2( point ); double d = mDa.measureLine( p1, p2 ); editTotal->setText( formatDistance( mTotal + d ) ); QGis::UnitType displayUnits; // Meters or feet? convertMeasurement( d, displayUnits, false ); // Set moving QTreeWidgetItem *item = mTable->topLevelItem( mTable->topLevelItemCount() - 1 ); item->setText( 0, QLocale::system().toString( d, 'f', mDecimalPlaces ) ); QgsDebugMsg( QString( "Final result is %1" ).arg( item->text( 0 ) ) ); } }
void QgsMeasureDialog::addPoint( QgsPoint &p ) { Q_UNUSED( p ); int numPoints = mTool->points().size(); if ( mMeasureArea && numPoints > 2 ) { double area = mDa.measurePolygon( mTool->points() ); editTotal->setText( formatArea( area ) ); } else if ( !mMeasureArea && numPoints >= 1 ) { if ( !mTool->done() ) { QTreeWidgetItem * item = new QTreeWidgetItem( QStringList( QLocale::system().toString( 0.0, 'f', mDecimalPlaces ) ) ); item->setTextAlignment( 0, Qt::AlignRight ); mTable->addTopLevelItem( item ); mTable->scrollToItem( item ); } if ( numPoints > 1 ) { mTotal = mDa.measureLine( mTool->points() ); editTotal->setText( formatDistance( mTotal ) ); } } QgsDebugMsg( "Exiting" ); }
void QgsMeasureDialog::mouseMove( const QgsPointXY &point ) { mLastMousePoint = point; // show current distance/area while moving the point // by creating a temporary copy of point array // and adding moving point at the end if ( mMeasureArea && mTool->points().size() >= 2 ) { QVector<QgsPointXY> tmpPoints = mTool->points(); tmpPoints.append( point ); double area = mDa.measurePolygon( tmpPoints ); editTotal->setText( formatArea( area ) ); } else if ( !mMeasureArea && !mTool->points().empty() ) { QVector< QgsPointXY > tmpPoints = mTool->points(); QgsPointXY p1( tmpPoints.at( tmpPoints.size() - 1 ) ), p2( point ); double d = mDa.measureLine( p1, p2 ); editTotal->setText( formatDistance( mTotal + d ) ); d = convertLength( d, mDistanceUnits ); // Set moving QTreeWidgetItem *item = mTable->topLevelItem( mTable->topLevelItemCount() - 1 ); if ( item ) { item->setText( 0, QLocale::system().toString( d, 'f', mDecimalPlaces ) ); } } }
void QgsMeasureDialog::updateUi() { QSettings settings; int decimalPlaces = settings.value( "/qgis/measure/decimalplaces", "3" ).toInt(); double dummy = 1.0; QGis::UnitType myDisplayUnits; // The dummy distance is ignored convertMeasurement( dummy, myDisplayUnits, false ); switch ( myDisplayUnits ) { case QGis::Meters: mTable->setHeaderLabels( QStringList( tr( "Segments (in meters)" ) ) ); break; case QGis::Feet: mTable->setHeaderLabels( QStringList( tr( "Segments (in feet)" ) ) ); break; case QGis::DegreesMinutesSeconds: case QGis::DegreesDecimalMinutes: case QGis::Degrees: mTable->setHeaderLabels( QStringList( tr( "Segments (in degrees)" ) ) ); break; case QGis::UnknownUnit: mTable->setHeaderLabels( QStringList( tr( "Segments" ) ) ); }; if ( mMeasureArea ) { mTable->hide(); editTotal->setText( formatArea( 0, decimalPlaces ) ); } else { mTable->show(); editTotal->setText( formatDistance( 0, decimalPlaces ) ); } }
void QgsMeasureDialog::addPoint( QgsPoint &point ) { QSettings settings; int decimalPlaces = settings.value( "/qgis/measure/decimalplaces", "3" ).toInt(); // Create QgsDistance Area for customization ProjectionEnabled setting QgsDistanceArea myDa; configureDistanceArea( myDa ); int numPoints = mTool->points().size(); if ( mMeasureArea && numPoints > 2 ) { double area = myDa.measurePolygon( mTool->points() ); editTotal->setText( formatArea( area, decimalPlaces ) ); } else if ( !mMeasureArea && numPoints > 1 ) { int last = numPoints - 2; QgsPoint p1 = mTool->points()[last], p2 = mTool->points()[last+1]; double d = myDa.measureLine( p1, p2 ); mTotal += d; editTotal->setText( formatDistance( mTotal, decimalPlaces ) ); QGis::UnitType myDisplayUnits; // Ignore units convertMeasurement( d, myDisplayUnits, false ); QTreeWidgetItem *item = mTable->topLevelItem( mTable->topLevelItemCount() - 1 ); item->setText( 0, QLocale::system().toString( d, 'f', decimalPlaces ) ); item = new QTreeWidgetItem( QStringList( QLocale::system().toString( 0.0, 'f', decimalPlaces ) ) ); item->setTextAlignment( 0, Qt::AlignRight ); mTable->addTopLevelItem( item ); mTable->scrollToItem( item ); } }
QMap< QString, QString > QgsMapToolIdentify::featureDerivedAttributes( QgsFeature *feature, QgsMapLayer *layer, const QgsPoint& layerPoint ) { // Calculate derived attributes and insert: // measure distance or area depending on geometry type QMap< QString, QString > derivedAttributes; // init distance/area calculator QString ellipsoid = QgsProject::instance()->ellipsoid(); QgsDistanceArea calc; calc.setEllipsoidalMode( mCanvas->hasCrsTransformEnabled() ); calc.setEllipsoid( ellipsoid ); calc.setSourceCrs( layer->crs().srsid() ); QgsWkbTypes::Type wkbType = QgsWkbTypes::NoGeometry; QgsWkbTypes::GeometryType geometryType = QgsWkbTypes::NullGeometry; QgsVertexId vId; QgsPointV2 closestPoint; if ( feature->hasGeometry() ) { geometryType = feature->geometry().type(); wkbType = feature->geometry().geometry()->wkbType(); //find closest vertex to clicked point closestPoint = QgsGeometryUtils::closestVertex( *feature->geometry().geometry(), QgsPointV2( layerPoint.x(), layerPoint.y() ), vId ); } if ( QgsWkbTypes::isMultiType( wkbType ) ) { QString str = QLocale::system().toString( static_cast<const QgsGeometryCollection*>( feature->geometry().geometry() )->numGeometries() ); derivedAttributes.insert( tr( "Parts" ), str ); str = QLocale::system().toString( vId.part + 1 ); derivedAttributes.insert( tr( "Part number" ), str ); } if ( geometryType == QgsWkbTypes::LineGeometry ) { double dist = calc.measureLength( feature->geometry() ); dist = calc.convertLengthMeasurement( dist, displayDistanceUnits() ); QString str = formatDistance( dist ); derivedAttributes.insert( tr( "Length" ), str ); const QgsCurve* curve = dynamic_cast< const QgsCurve* >( feature->geometry().geometry() ); if ( curve ) { str = QLocale::system().toString( curve->nCoordinates() ); derivedAttributes.insert( tr( "Vertices" ), str ); //add details of closest vertex to identify point closestVertexAttributes( *curve, vId, layer, derivedAttributes ); // Add the start and end points in as derived attributes QgsPoint pnt = mCanvas->mapSettings().layerToMapCoordinates( layer, QgsPoint( curve->startPoint().x(), curve->startPoint().y() ) ); str = formatXCoordinate( pnt ); derivedAttributes.insert( tr( "firstX", "attributes get sorted; translation for lastX should be lexically larger than this one" ), str ); str = formatYCoordinate( pnt ); derivedAttributes.insert( tr( "firstY" ), str ); pnt = mCanvas->mapSettings().layerToMapCoordinates( layer, QgsPoint( curve->endPoint().x(), curve->endPoint().y() ) ); str = formatXCoordinate( pnt ); derivedAttributes.insert( tr( "lastX", "attributes get sorted; translation for firstX should be lexically smaller than this one" ), str ); str = formatYCoordinate( pnt ); derivedAttributes.insert( tr( "lastY" ), str ); } } else if ( geometryType == QgsWkbTypes::PolygonGeometry ) { double area = calc.measureArea( feature->geometry() ); area = calc.convertAreaMeasurement( area, displayAreaUnits() ); QString str = formatArea( area ); derivedAttributes.insert( tr( "Area" ), str ); double perimeter = calc.measurePerimeter( feature->geometry() ); perimeter = calc.convertLengthMeasurement( perimeter, displayDistanceUnits() ); str = formatDistance( perimeter ); derivedAttributes.insert( tr( "Perimeter" ), str ); str = QLocale::system().toString( feature->geometry().geometry()->nCoordinates() ); derivedAttributes.insert( tr( "Vertices" ), str ); //add details of closest vertex to identify point closestVertexAttributes( *feature->geometry().geometry(), vId, layer, derivedAttributes ); } else if ( geometryType == QgsWkbTypes::PointGeometry && QgsWkbTypes::flatType( wkbType ) == QgsWkbTypes::Point ) { // Include the x and y coordinates of the point as a derived attribute QgsPoint pnt = mCanvas->mapSettings().layerToMapCoordinates( layer, feature->geometry().asPoint() ); QString str = formatXCoordinate( pnt ); derivedAttributes.insert( "X", str ); str = formatYCoordinate( pnt ); derivedAttributes.insert( "Y", str ); if ( QgsWkbTypes::hasZ( wkbType ) ) { str = QLocale::system().toString( static_cast<const QgsPointV2*>( feature->geometry().geometry() )->z(), 'g', 10 ); derivedAttributes.insert( "Z", str ); } if ( QgsWkbTypes::hasM( wkbType ) ) { str = QLocale::system().toString( static_cast<const QgsPointV2*>( feature->geometry().geometry() )->m(), 'g', 10 ); derivedAttributes.insert( "M", str ); } } return derivedAttributes; }
void QgsMeasureDialog::updateUi() { // Set tooltip to indicate how we calculate measurments QString toolTip = tr( "The calculations are based on:" ); if ( ! mTool->canvas()->hasCrsTransformEnabled() ) { toolTip += "<br> * " + tr( "Project CRS transformation is turned off." ) + " "; toolTip += tr( "Canvas units setting is taken from project properties setting (%1)." ).arg( QGis::tr( mCanvasUnits ) ); toolTip += "<br> * " + tr( "Ellipsoidal calculation is not possible, as project CRS is undefined." ); setWindowTitle( tr( "Measure (OTF off)" ) ); } else { if ( mDa.ellipsoidalEnabled() ) { toolTip += "<br> * " + tr( "Project CRS transformation is turned on and ellipsoidal calculation is selected." ) + " "; toolTip += "<br> * " + tr( "The coordinates are transformed to the chosen ellipsoid (%1), and the result is in meters" ).arg( mDa.ellipsoid() ); } else { toolTip += "<br> * " + tr( "Project CRS transformation is turned on but ellipsoidal calculation is not selected." ); toolTip += "<br> * " + tr( "The canvas units setting is taken from the project CRS (%1)." ).arg( QGis::tr( mCanvasUnits ) ); } setWindowTitle( tr( "Measure (OTF on)" ) ); } if (( mCanvasUnits == QGis::Meters && mDisplayUnits == QGis::Feet ) || ( mCanvasUnits == QGis::Feet && mDisplayUnits == QGis::Meters ) ) { toolTip += "<br> * " + tr( "Finally, the value is converted from %1 to %2." ).arg( QGis::tr( mCanvasUnits ) ).arg( QGis::tr( mDisplayUnits ) ); } editTotal->setToolTip( toolTip ); mTable->setToolTip( toolTip ); QGis::UnitType newDisplayUnits; double dummy = 1.0; convertMeasurement( dummy, newDisplayUnits, true ); mTable->setHeaderLabels( QStringList( tr( "Segments [%1]" ).arg( QGis::tr( newDisplayUnits ) ) ) ); if ( mMeasureArea ) { double area = 0.0; if ( mTool->points().size() > 1 ) { area = mDa.measurePolygon( mTool->points() ); } mTable->hide(); // Hide the table, only show summary. editTotal->setText( formatArea( area ) ); } else { QList<QgsPoint>::const_iterator it; bool b = true; // first point QgsPoint p1, p2; for ( it = mTool->points().constBegin(); it != mTool->points().constEnd(); ++it ) { p2 = *it; if ( !b ) { double d = mDa.measureLine( p1, p2 ); QGis::UnitType dummyUnits; convertMeasurement( d, dummyUnits, false ); QTreeWidgetItem *item = new QTreeWidgetItem( QStringList( QLocale::system().toString( d , 'f', mDecimalPlaces ) ) ); item->setTextAlignment( 0, Qt::AlignRight ); mTable->addTopLevelItem( item ); mTable->scrollToItem( item ); } p1 = p2; b = false; } mTotal = mDa.measureLine( mTool->points() ); mTable->show(); // Show the table with items editTotal->setText( formatDistance( mTotal ) ); } }
void QgsMeasureDialog::updateUi() { // Set tooltip to indicate how we calculate measurments QString toolTip = tr( "The calculations are based on:" ); bool forceCartesian = false; bool convertToDisplayUnits = true; if ( mMeasureArea ) { if ( mTool->canvas()->mapSettings().destinationCrs().mapUnits() == QgsUnitTypes::DistanceDegrees && ( mAreaUnits == QgsUnitTypes::AreaSquareDegrees || mAreaUnits == QgsUnitTypes::AreaUnknownUnit ) ) { //both source and destination units are degrees toolTip += "<br> * " + tr( "Both project CRS (%1) and measured area are in degrees, so area is calculated using cartesian calculations in square degrees." ).arg( mTool->canvas()->mapSettings().destinationCrs().description() ); forceCartesian = true; convertToDisplayUnits = false; //not required since we will be measuring in degrees } else { QgsUnitTypes::AreaUnit resultUnit = QgsUnitTypes::AreaUnknownUnit; if ( ! mTool->canvas()->hasCrsTransformEnabled() ) { resultUnit = QgsUnitTypes::distanceToAreaUnit( mTool->canvas()->mapSettings().destinationCrs().mapUnits() ); toolTip += "<br> * " + tr( "Project CRS transformation is turned off." ) + ' '; toolTip += tr( "Area is calculated in %1, based on project CRS (%2)." ).arg( QgsUnitTypes::toString( resultUnit ), mTool->canvas()->mapSettings().destinationCrs().description() ); toolTip += "<br> * " + tr( "Ellipsoidal calculation is not possible with CRS transformation disabled." ); setWindowTitle( tr( "Measure (OTF off)" ) ); } else { if ( mDa.willUseEllipsoid() ) { resultUnit = QgsUnitTypes::AreaSquareMeters; toolTip += "<br> * " + tr( "Project CRS transformation is turned on and ellipsoidal calculation is selected." ) + ' '; toolTip += "<br> * " + tr( "The coordinates are transformed to the chosen ellipsoid (%1), and the area is calculated in %2." ).arg( mDa.ellipsoid(), QgsUnitTypes::toString( resultUnit ) ); } else { resultUnit = QgsUnitTypes::distanceToAreaUnit( mTool->canvas()->mapSettings().destinationCrs().mapUnits() ); toolTip += "<br> * " + tr( "Project CRS transformation is turned on but ellipsoidal calculation is not selected." ) + ' '; toolTip += tr( "Area is calculated in %1, based on project CRS (%2)." ).arg( QgsUnitTypes::toString( resultUnit ), mTool->canvas()->mapSettings().destinationCrs().description() ); } setWindowTitle( tr( "Measure (OTF on)" ) ); } if ( QgsUnitTypes::unitType( resultUnit ) == QgsUnitTypes::Geographic && QgsUnitTypes::unitType( mAreaUnits ) == QgsUnitTypes::Standard ) { toolTip += "<br> * Area is roughly converted to square meters by using scale at equator (1 degree = 111319.49 meters)."; resultUnit = QgsUnitTypes::AreaSquareMeters; } else if ( QgsUnitTypes::unitType( resultUnit ) == QgsUnitTypes::Standard && QgsUnitTypes::unitType( mAreaUnits ) == QgsUnitTypes::Geographic ) { toolTip += "<br> * Area is roughly converted to square degrees by using scale at equator (1 degree = 111319.49 meters)."; resultUnit = QgsUnitTypes::AreaSquareDegrees; } if ( resultUnit != mAreaUnits ) { if ( QgsUnitTypes::unitType( resultUnit ) == QgsUnitTypes::Standard && QgsUnitTypes::unitType( mAreaUnits ) == QgsUnitTypes::Standard ) { // only shown if both conditions are true: // - the display unit is a standard distance measurement (eg square feet) // - either the canvas units is also a standard distance OR we are using an ellipsoid (in which case the // value will be in square meters) toolTip += "<br> * " + tr( "The value is converted from %1 to %2." ).arg( QgsUnitTypes::toString( resultUnit ), QgsUnitTypes::toString( mAreaUnits ) ); } else { //should not be possible! } } } } else { if ( mTool->canvas()->mapSettings().destinationCrs().mapUnits() == QgsUnitTypes::DistanceDegrees && mDistanceUnits == QgsUnitTypes::DistanceDegrees ) { //both source and destination units are degrees toolTip += "<br> * " + tr( "Both project CRS (%1) and measured length are in degrees, so distance is calculated using cartesian calculations in degrees." ).arg( mTool->canvas()->mapSettings().destinationCrs().description() ); forceCartesian = true; convertToDisplayUnits = false; //not required since we will be measuring in degrees } else { QgsUnitTypes::DistanceUnit resultUnit = QgsUnitTypes::DistanceUnknownUnit; if ( ! mTool->canvas()->hasCrsTransformEnabled() ) { resultUnit = mTool->canvas()->mapSettings().destinationCrs().mapUnits(); toolTip += "<br> * " + tr( "Project CRS transformation is turned off." ) + ' '; toolTip += tr( "Distance is calculated in %1, based on project CRS (%2)." ).arg( QgsUnitTypes::toString( resultUnit ), mTool->canvas()->mapSettings().destinationCrs().description() ); toolTip += "<br> * " + tr( "Ellipsoidal calculation is not possible with CRS transformation disabled." ); setWindowTitle( tr( "Measure (OTF off)" ) ); } else { if ( mDa.willUseEllipsoid() ) { resultUnit = QgsUnitTypes::DistanceMeters; toolTip += "<br> * " + tr( "Project CRS transformation is turned on and ellipsoidal calculation is selected." ) + ' '; toolTip += "<br> * " + tr( "The coordinates are transformed to the chosen ellipsoid (%1), and the distance is calculated in %2." ).arg( mDa.ellipsoid(), QgsUnitTypes::toString( resultUnit ) ); } else { resultUnit = mTool->canvas()->mapSettings().destinationCrs().mapUnits(); toolTip += "<br> * " + tr( "Project CRS transformation is turned on but ellipsoidal calculation is not selected." ) + ' '; toolTip += tr( "Distance is calculated in %1, based on project CRS (%2)." ).arg( QgsUnitTypes::toString( resultUnit ), mTool->canvas()->mapSettings().destinationCrs().description() ); } setWindowTitle( tr( "Measure (OTF on)" ) ); } if ( QgsUnitTypes::unitType( resultUnit ) == QgsUnitTypes::Geographic && QgsUnitTypes::unitType( mDistanceUnits ) == QgsUnitTypes::Standard ) { toolTip += "<br> * Distance is roughly converted to meters by using scale at equator (1 degree = 111319.49 meters)."; resultUnit = QgsUnitTypes::DistanceMeters; } else if ( QgsUnitTypes::unitType( resultUnit ) == QgsUnitTypes::Standard && QgsUnitTypes::unitType( mDistanceUnits ) == QgsUnitTypes::Geographic ) { toolTip += "<br> * Distance is roughly converted to degrees by using scale at equator (1 degree = 111319.49 meters)."; resultUnit = QgsUnitTypes::DistanceDegrees; } if ( resultUnit != mDistanceUnits ) { if ( QgsUnitTypes::unitType( resultUnit ) == QgsUnitTypes::Standard && QgsUnitTypes::unitType( mDistanceUnits ) == QgsUnitTypes::Standard ) { // only shown if both conditions are true: // - the display unit is a standard distance measurement (eg feet) // - either the canvas units is also a standard distance OR we are using an ellipsoid (in which case the // value will be in meters) toolTip += "<br> * " + tr( "The value is converted from %1 to %2." ).arg( QgsUnitTypes::toString( resultUnit ), QgsUnitTypes::toString( mDistanceUnits ) ); } else { //should not be possible! } } } } editTotal->setToolTip( toolTip ); mTable->setToolTip( toolTip ); mNotesLabel->setText( toolTip ); if ( mMeasureArea ) { mUnitsCombo->setCurrentIndex( mUnitsCombo->findData( mAreaUnits ) ); } else { mUnitsCombo->setCurrentIndex( mUnitsCombo->findData( mDistanceUnits ) ); mTable->setHeaderLabels( QStringList( tr( "Segments [%1]" ).arg( QgsUnitTypes::toString( mDistanceUnits ) ) ) ); } if ( mMeasureArea ) { double area = 0.0; if ( mTool->points().size() > 1 ) { area = mDa.measurePolygon( mTool->points() ); } mTable->hide(); // Hide the table, only show summary. editTotal->setText( formatArea( area ) ); } else { QList<QgsPoint>::const_iterator it; bool b = true; // first point QgsPoint p1, p2; mTotal = 0; for ( it = mTool->points().constBegin(); it != mTool->points().constEnd(); ++it ) { p2 = *it; if ( !b ) { double d = -1; if ( forceCartesian ) { //cartesian calculation forced d = sqrt( p2.sqrDist( p1 ) ); mTotal += d; } else { d = mDa.measureLine( p1, p2 ); d = convertLength( d, mDistanceUnits ); } QTreeWidgetItem *item = new QTreeWidgetItem( QStringList( QLocale::system().toString( d, 'f', mDecimalPlaces ) ) ); item->setTextAlignment( 0, Qt::AlignRight ); mTable->addTopLevelItem( item ); mTable->scrollToItem( item ); } p1 = p2; b = false; } if ( !forceCartesian ) mTotal = mDa.measureLine( mTool->points() ); mTable->show(); // Show the table with items editTotal->setText( formatDistance( mTotal, convertToDisplayUnits ) ); } }
void QgsMeasureDialog::changeProjectionEnabledState() { // store value QSettings settings; if ( mcbProjectionEnabled->isChecked() ) settings.setValue( "/qgis/measure/projectionEnabled", 2 ); else settings.setValue( "/qgis/measure/projectionEnabled", 0 ); // clear interface mTable->clear(); QTreeWidgetItem* item = new QTreeWidgetItem( QStringList( QString::number( 0, 'f', 1 ) ) ); item->setTextAlignment( 0, Qt::AlignRight ); mTable->addTopLevelItem( item ); mTotal = 0; updateUi(); int decimalPlaces = settings.value( "/qgis/measure/decimalplaces", "3" ).toInt(); // create DistanceArea QgsDistanceArea myDa; configureDistanceArea( myDa ); if ( mMeasureArea ) { double area = 0.0; if ( mTool->points().size() > 1 ) { area = myDa.measurePolygon( mTool->points() ); } editTotal->setText( formatArea( area, decimalPlaces ) ); } else { QList<QgsPoint>::const_iterator it; bool b = true; // first point QgsPoint p1, p2; for ( it = mTool->points().constBegin(); it != mTool->points().constEnd(); ++it ) { p2 = *it; if ( !b ) { double d = myDa.measureLine( p1, p2 ); mTotal += d; editTotal->setText( formatDistance( mTotal, decimalPlaces ) ); QGis::UnitType myDisplayUnits; convertMeasurement( d, myDisplayUnits, false ); QTreeWidgetItem *item = mTable->topLevelItem( mTable->topLevelItemCount() - 1 ); item->setText( 0, QLocale::system().toString( d, 'f', decimalPlaces ) ); item = new QTreeWidgetItem( QStringList( QLocale::system().toString( 0.0, 'f', decimalPlaces ) ) ); item->setTextAlignment( 0, Qt::AlignRight ); mTable->addTopLevelItem( item ); mTable->scrollToItem( item ); } p1 = p2; b = false; } } }