[QGIS Commit] r14956 - in trunk/qgis/src: app ui

svn_qgis at osgeo.org svn_qgis at osgeo.org
Tue Dec 21 05:59:46 EST 2010


Author: timlinux
Date: 2010-12-21 02:59:46 -0800 (Tue, 21 Dec 2010)
New Revision: 14956

Modified:
   trunk/qgis/src/app/qgsdisplayangle.cpp
   trunk/qgis/src/app/qgsdisplayangle.h
   trunk/qgis/src/app/qgsmaptoolmeasureangle.cpp
   trunk/qgis/src/app/qgsmaptoolmeasureangle.h
   trunk/qgis/src/app/qgsmeasuredialog.cpp
   trunk/qgis/src/app/qgsmeasuredialog.h
   trunk/qgis/src/ui/qgsdisplayanglebase.ui
   trunk/qgis/src/ui/qgsmeasurebase.ui
Log:
Applied patch from ticket #3240 with some tweaks. Allows unprojected measurement of distances

Modified: trunk/qgis/src/app/qgsdisplayangle.cpp
===================================================================
--- trunk/qgis/src/app/qgsdisplayangle.cpp	2010-12-21 10:17:37 UTC (rev 14955)
+++ trunk/qgis/src/app/qgsdisplayangle.cpp	2010-12-21 10:59:46 UTC (rev 14956)
@@ -20,6 +20,17 @@
 QgsDisplayAngle::QgsDisplayAngle( QWidget * parent, Qt::WindowFlags f ): QDialog( parent, f )
 {
   setupUi( this );
+  QSettings settings;
+  int s = settings.value( "/qgis/measure/projectionEnabled", "2" ).toInt();
+  if ( s == 2 )
+    mcbProjectionEnabled->setCheckState( Qt::Checked );
+  else
+    mcbProjectionEnabled->setCheckState( Qt::Unchecked );
+
+  connect( mcbProjectionEnabled, SIGNAL( stateChanged(int) ),
+      this, SLOT( changeState() ) );
+  connect( mcbProjectionEnabled, SIGNAL( stateChanged(int) ), 
+      this, SIGNAL( changeProjectionEnabledState() ) );
 }
 
 QgsDisplayAngle::~QgsDisplayAngle()
@@ -27,6 +38,11 @@
 
 }
 
+bool QgsDisplayAngle::projectionEnabled()
+{
+  return mcbProjectionEnabled->isChecked();
+}
+
 void QgsDisplayAngle::setValueInRadians( double value )
 {
   QSettings settings;
@@ -45,3 +61,11 @@
   }
 }
 
+void QgsDisplayAngle::changeState()
+{
+  QSettings settings;
+  if ( mcbProjectionEnabled->isChecked() )
+    settings.setValue( "/qgis/measure/projectionEnabled", 2);
+  else
+    settings.setValue( "/qgis/measure/projectionEnabled", 0);
+}

Modified: trunk/qgis/src/app/qgsdisplayangle.h
===================================================================
--- trunk/qgis/src/app/qgsdisplayangle.h	2010-12-21 10:17:37 UTC (rev 14955)
+++ trunk/qgis/src/app/qgsdisplayangle.h	2010-12-21 10:59:46 UTC (rev 14956)
@@ -29,6 +29,15 @@
     /**Sets the measured angle value (in radians). The value is going to
       be converted to degrees / gon automatically if necessary*/
     void setValueInRadians( double value );
+
+    bool projectionEnabled();
+
+  signals:
+    void changeProjectionEnabledState();
+  
+  private slots:
+    void changeState();
+
 };
 
 #endif // QGSDISPLAYANGLE_H

Modified: trunk/qgis/src/app/qgsmaptoolmeasureangle.cpp
===================================================================
--- trunk/qgis/src/app/qgsmaptoolmeasureangle.cpp	2010-12-21 10:17:37 UTC (rev 14955)
+++ trunk/qgis/src/app/qgsmaptoolmeasureangle.cpp	2010-12-21 10:59:46 UTC (rev 14956)
@@ -49,9 +49,26 @@
     QgsDistanceArea* distArea = mCanvas->mapRenderer()->distanceArea();
     if ( distArea )
     {
-      double azimutOne = distArea->bearing( mAnglePoints.at( 1 ), mAnglePoints.at( 0 ) );
-      double azimutTwo = distArea->bearing( mAnglePoints.at( 1 ), point );
-      double resultAngle = azimutTwo - azimutOne;
+      //show angle in dialog
+      if ( !mResultDisplay )
+      {
+        mResultDisplay = new QgsDisplayAngle( mCanvas->topLevelWidget() );
+        QObject::connect( mResultDisplay, SIGNAL( rejected() ), this, SLOT( stopMeasuring() ) );
+        QObject::connect( mResultDisplay, SIGNAL( changeProjectionEnabledState() ), 
+            this, SLOT( changeProjectionEnabledState() ) );
+        mResultDisplay->move( e->pos() - QPoint( 100, 100 ) );
+      }
+      mResultDisplay->show();   
+      
+      QgsDistanceArea myDa;
+      myDa.setSourceCrs( mCanvas->mapRenderer()->destinationSrs().srsid() );
+      myDa.setEllipsoid( distArea->ellipsoid() );
+      myDa.setProjectionsEnabled( mResultDisplay->projectionEnabled() );
+
+      //angle calculation
+      double azimuthOne = myDa.bearing( mAnglePoints.at( 1 ), mAnglePoints.at( 0 ) );
+      double azimuthTwo = myDa.bearing( mAnglePoints.at( 1 ), point );
+      double resultAngle = azimuthTwo - azimuthOne;
       QgsDebugMsg( QString::number( qAbs( resultAngle ) ) );
       QgsDebugMsg( QString::number( M_PI ) );
       if ( qAbs( resultAngle ) > M_PI )
@@ -66,14 +83,6 @@
         }
       }
 
-      //show angle in dialog
-      if ( !mResultDisplay )
-      {
-        mResultDisplay = new QgsDisplayAngle( mCanvas->topLevelWidget() );
-        QObject::connect( mResultDisplay, SIGNAL( rejected() ), this, SLOT( stopMeasuring() ) );
-        mResultDisplay->move( e->pos() - QPoint( 100, 100 ) );
-      }
-      mResultDisplay->show();
       mResultDisplay->setValueInRadians( resultAngle );
     }
   }
@@ -145,5 +154,36 @@
   }
 }
 
+void QgsMapToolMeasureAngle::changeProjectionEnabledState()
+{
+  if ( mAnglePoints.size() != 3 )
+    return;
+  if ( !mResultDisplay )
+    return;
+  
+  QgsDistanceArea myDa;
+  myDa.setSourceCrs( mCanvas->mapRenderer()->destinationSrs().srsid() );
+  myDa.setEllipsoid( mCanvas->mapRenderer()->distanceArea()->ellipsoid() );
+  myDa.setProjectionsEnabled( mResultDisplay->projectionEnabled() );
 
+  //angle calculation
+  double azimuthOne = myDa.bearing( mAnglePoints.at( 1 ), mAnglePoints.at( 0 ) );
+  double azimuthTwo = myDa.bearing( mAnglePoints.at( 1 ), mAnglePoints.at( 2 ) );
+  double resultAngle = azimuthTwo - azimuthOne;
+  QgsDebugMsg( QString::number( fabs( resultAngle ) ) );
+  QgsDebugMsg( QString::number( M_PI ) );
+  if ( fabs( resultAngle ) > M_PI )
+  {
+    if ( resultAngle < 0 )
+    {
+      resultAngle = M_PI + ( resultAngle + M_PI );
+    }
+    else
+    {
+      resultAngle = -M_PI + ( resultAngle - M_PI );
+    }
+  }
+  mResultDisplay->setValueInRadians( resultAngle );
 
+}
+

Modified: trunk/qgis/src/app/qgsmaptoolmeasureangle.h
===================================================================
--- trunk/qgis/src/app/qgsmaptoolmeasureangle.h	2010-12-21 10:17:37 UTC (rev 14955)
+++ trunk/qgis/src/app/qgsmaptoolmeasureangle.h	2010-12-21 10:59:46 UTC (rev 14956)
@@ -59,6 +59,9 @@
     /**Deletes the rubber band and the dialog*/
     void stopMeasuring();
 
+    /** recalculate angle if projection state changed*/
+    void changeProjectionEnabledState();
+
 };
 
 #endif // QGSMAPTOOLMEASUREANGLE_H

Modified: trunk/qgis/src/app/qgsmeasuredialog.cpp
===================================================================
--- trunk/qgis/src/app/qgsmeasuredialog.cpp	2010-12-21 10:17:37 UTC (rev 14955)
+++ trunk/qgis/src/app/qgsmeasuredialog.cpp	2010-12-21 10:59:46 UTC (rev 14956)
@@ -52,7 +52,14 @@
   //mTable->setHeaderLabels(QStringList() << tr("Segments (in meters)") << tr("Total") << tr("Azimuth") );
 
   QSettings settings;
+  int s = settings.value( "/qgis/measure/projectionEnabled", "2" ).toInt();
+  if ( s == 2 )
+    mcbProjectionEnabled->setCheckState( Qt::Checked );
+  else
+    mcbProjectionEnabled->setCheckState( Qt::Unchecked );
 
+  connect( mcbProjectionEnabled, SIGNAL( stateChanged(int) ), 
+      this, SLOT( changeProjectionEnabledState() ));
 
   updateUi();
 }
@@ -91,21 +98,27 @@
   QSettings settings;
   int decimalPlaces = settings.value( "/qgis/measure/decimalplaces", "3" ).toInt();
 
+  // Create QgsDistance Area for customization ProjectionEnabled setting
+  QgsDistanceArea myDa;  
+  myDa.setSourceCrs( mTool->canvas()->mapRenderer()->destinationSrs().srsid() );
+  myDa.setEllipsoid( mTool->canvas()->mapRenderer()->distanceArea()->ellipsoid() );
+  myDa.setProjectionsEnabled( mcbProjectionEnabled->isChecked() );
+
   // show current distance/area while moving the point
   // by creating a temporary copy of point array
-  // and adding moving point at the end
+  // and adding moving point at the end  
   if ( mMeasureArea && mTool->points().size() > 1 )
   {
     QList<QgsPoint> tmpPoints = mTool->points();
     tmpPoints.append( point );
-    double area = mTool->canvas()->mapRenderer()->distanceArea()->measurePolygon( tmpPoints );
+    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 = mTool->canvas()->mapRenderer()->distanceArea()->measureLine( p1, p2 );
+    double d = myDa.measureLine( p1, p2 );
     editTotal->setText( formatDistance( mTotal + d, decimalPlaces ) );
     QGis::UnitType myDisplayUnits;
     // Ignore units
@@ -120,10 +133,16 @@
   QSettings settings;
   int decimalPlaces = settings.value( "/qgis/measure/decimalplaces", "3" ).toInt();
 
+  // Create QgsDistance Area for customization ProjectionEnabled setting
+  QgsDistanceArea myDa;  
+  myDa.setSourceCrs( mTool->canvas()->mapRenderer()->destinationSrs().srsid() );
+  myDa.setEllipsoid( mTool->canvas()->mapRenderer()->distanceArea()->ellipsoid() );
+  myDa.setProjectionsEnabled( mcbProjectionEnabled->isChecked() );
+
   int numPoints = mTool->points().size();
   if ( mMeasureArea && numPoints > 2 )
   {
-    double area = mTool->canvas()->mapRenderer()->distanceArea()->measurePolygon( mTool->points() );
+    double area = myDa.measurePolygon( mTool->points() );
     editTotal->setText( formatArea( area, decimalPlaces ) );
   }
   else if ( !mMeasureArea && numPoints > 1 )
@@ -132,7 +151,7 @@
 
     QgsPoint p1 = mTool->points()[last], p2 = mTool->points()[last+1];
 
-    double d = mTool->canvas()->mapRenderer()->distanceArea()->measureLine( p1, p2 );
+    double d = myDa.measureLine( p1, p2 );
 
     mTotal += d;
     editTotal->setText( formatDistance( mTotal, decimalPlaces ) );
@@ -252,17 +271,17 @@
   QGis::UnitType myUnits = mTool->canvas()->mapUnits();
   if (( myUnits == QGis::Degrees || myUnits == QGis::Feet ) &&
       mTool->canvas()->mapRenderer()->distanceArea()->ellipsoid() != "NONE" &&
-      mTool->canvas()->mapRenderer()->distanceArea()->hasCrsTransformEnabled() )
+      mcbProjectionEnabled->isChecked() )
   {
     // Measuring on an ellipsoid returns meters, and so does using projections???
     myUnits = QGis::Meters;
     QgsDebugMsg( "We're measuring on an ellipsoid or using projections, the system is returning meters" );
   }
-
+   
   // Get the units for display
   QSettings settings;
   QString myDisplayUnitsTxt = settings.value( "/qgis/measure/displayunits", "meters" ).toString();
-
+  
   // Only convert between meters and feet
   if ( myUnits == QGis::Meters && myDisplayUnitsTxt == "feet" )
   {
@@ -289,3 +308,68 @@
 
   u = myUnits;
 }
+
+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;  
+  myDa.setSourceCrs( mTool->canvas()->mapRenderer()->destinationSrs().srsid() );
+  myDa.setEllipsoid( mTool->canvas()->mapRenderer()->distanceArea()->ellipsoid() );
+  myDa.setProjectionsEnabled( mcbProjectionEnabled->isChecked() );
+  
+  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;
+    }
+  }
+}

Modified: trunk/qgis/src/app/qgsmeasuredialog.h
===================================================================
--- trunk/qgis/src/app/qgsmeasuredialog.h	2010-12-21 10:17:37 UTC (rev 14955)
+++ trunk/qgis/src/app/qgsmeasuredialog.h	2010-12-21 10:59:46 UTC (rev 14956)
@@ -62,6 +62,9 @@
 
     //! Show the help for the dialog
     void on_buttonBox_helpRequested() { QgsContextHelp::run( metaObject()->className() ); }
+  private slots:
+    //! on change state projection enable
+    void changeProjectionEnabledState();
 
   private:
 

Modified: trunk/qgis/src/ui/qgsdisplayanglebase.ui
===================================================================
--- trunk/qgis/src/ui/qgsdisplayanglebase.ui	2010-12-21 10:17:37 UTC (rev 14955)
+++ trunk/qgis/src/ui/qgsdisplayanglebase.ui	2010-12-21 10:59:46 UTC (rev 14956)
@@ -6,22 +6,22 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>276</width>
-    <height>78</height>
+    <width>293</width>
+    <height>105</height>
    </rect>
   </property>
   <property name="windowTitle">
    <string>Angle</string>
   </property>
   <layout class="QGridLayout" name="gridLayout">
-   <item row="0" column="0" colspan="2">
+   <item row="1" column="0" colspan="2">
     <widget class="QLineEdit" name="mAngleLineEdit">
      <property name="readOnly">
       <bool>true</bool>
      </property>
     </widget>
    </item>
-   <item row="1" column="0">
+   <item row="2" column="0">
     <spacer name="horizontalSpacer">
      <property name="orientation">
       <enum>Qt::Horizontal</enum>
@@ -34,7 +34,7 @@
      </property>
     </spacer>
    </item>
-   <item row="1" column="1">
+   <item row="2" column="1">
     <widget class="QDialogButtonBox" name="buttonBox">
      <property name="orientation">
       <enum>Qt::Horizontal</enum>
@@ -44,6 +44,13 @@
      </property>
     </widget>
    </item>
+   <item row="0" column="0">
+    <widget class="QCheckBox" name="mcbProjectionEnabled">
+     <property name="text">
+      <string>Ellipsoidal (WGS84)</string>
+     </property>
+    </widget>
+   </item>
   </layout>
  </widget>
  <resources/>

Modified: trunk/qgis/src/ui/qgsmeasurebase.ui
===================================================================
--- trunk/qgis/src/ui/qgsmeasurebase.ui	2010-12-21 10:17:37 UTC (rev 14955)
+++ trunk/qgis/src/ui/qgsmeasurebase.ui	2010-12-21 10:59:46 UTC (rev 14956)
@@ -31,7 +31,7 @@
    <property name="spacing">
     <number>6</number>
    </property>
-   <item row="1" column="2">
+   <item row="2" column="2">
     <widget class="QLineEdit" name="editTotal">
      <property name="font">
       <font>
@@ -47,7 +47,7 @@
      </property>
     </widget>
    </item>
-   <item row="1" column="1">
+   <item row="2" column="1">
     <spacer>
      <property name="orientation">
       <enum>Qt::Horizontal</enum>
@@ -63,7 +63,7 @@
      </property>
     </spacer>
    </item>
-   <item row="1" column="0">
+   <item row="2" column="0">
     <widget class="QLabel" name="textLabel2">
      <property name="text">
       <string>Total</string>
@@ -73,7 +73,7 @@
      </property>
     </widget>
    </item>
-   <item row="0" column="0" colspan="3">
+   <item row="1" column="0" colspan="3">
     <widget class="QTreeWidget" name="mTable">
      <property name="editTriggers">
       <set>QAbstractItemView::NoEditTriggers</set>
@@ -91,13 +91,20 @@
      </column>
     </widget>
    </item>
-   <item row="2" column="2">
+   <item row="3" column="2">
     <widget class="QDialogButtonBox" name="buttonBox">
      <property name="standardButtons">
       <set>QDialogButtonBox::Close|QDialogButtonBox::Help</set>
      </property>
     </widget>
    </item>
+   <item row="0" column="0" colspan="3">
+    <widget class="QCheckBox" name="mcbProjectionEnabled">
+     <property name="text">
+      <string>Ellipsoidal (WGS84)</string>
+     </property>
+    </widget>
+   </item>
   </layout>
  </widget>
  <layoutdefault spacing="6" margin="11"/>



More information about the QGIS-commit mailing list