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 ) );
  }
}
예제 #2
0
void TestQgsDistanceArea::emptyPolygon()
{
  QgsDistanceArea da;
  da.setSourceCrs( 3452 );
  da.setEllipsoidalMode( true );
  da.setEllipsoid( "WGS84" );

  //test that measuring an empty polygon doesn't crash
  da.measurePolygon( QList< QgsPoint >() );
}
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 );
  }
}
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;
    }
  }
}