コード例 #1
0
ファイル: qgsscalecombobox.cpp プロジェクト: alexbruy/QGIS
double QgsScaleComboBox::toDouble( const QString &scaleString, bool *returnOk )
{
  bool ok = false;
  QString scaleTxt( scaleString );

  double denominator = qgsPermissiveToDouble( scaleTxt, ok );
  double scale = !qgsDoubleNear( denominator, 0.0 ) ? 1.0 / denominator : 0.0;
  if ( ok )
  {
    // Create a text version and set that text and rescan
    // Idea is to get the same rounding.
    scaleTxt = toString( scale );
  }
  else
  {
    // It is now either X:Y or not valid
    QStringList txtList = scaleTxt.split( ':' );
    if ( 2 == txtList.size() )
    {
      bool okX = false;
      bool okY = false;
      int x = qgsPermissiveToInt( txtList[ 0 ], okX );
      int y = qgsPermissiveToInt( txtList[ 1 ], okY );
      if ( okX && okY && x != 0 )
      {
        // Scale is fraction of x and y
        scale = static_cast<  double >( y ) / static_cast< double >( x );
        ok = true;
      }
    }
  }

  // Set up optional return flag
  if ( returnOk )
  {
    *returnOk = ok;
  }
  return scale;
}
コード例 #2
0
ファイル: qgsscalecombobox.cpp プロジェクト: Antoviscomi/QGIS
double QgsScaleComboBox::toDouble( const QString& scaleString, bool * returnOk )
{
  bool ok = false;
  QString scaleTxt( scaleString );

  double scale = QGis::permissiveToDouble( scaleTxt, ok );
  if ( ok )
  {
    // Create a text version and set that text and rescan
    // Idea is to get the same rounding.
    scaleTxt = toString( scale );
  }
  else
  {
    // It is now either X:Y or not valid
    QStringList txtList = scaleTxt.split( ':' );
    if ( 2 == txtList.size() )
    {
      bool okX = false;
      bool okY = false;
      int x = QGis::permissiveToInt( txtList[ 0 ], okX );
      int y = QGis::permissiveToInt( txtList[ 1 ], okY );
      if ( okX && okY )
      {
        // Scale is fraction of x and y
        scale = ( double )x / ( double )y;
        ok = true;
      }
    }
  }

  // Set up optional return flag
  if ( returnOk )
  {
    *returnOk = ok;
  }
  return scale;
}