コード例 #1
0
void QgsLayoutItemScaleBar::applyDefaultSize( QgsUnitTypes::DistanceUnit units )
{
  mSettings.setUnits( units );
  if ( mMap )
  {
    double upperMagnitudeMultiplier = 1.0;
    double widthInSelectedUnits = mapWidth();
    double initialUnitsPerSegment = widthInSelectedUnits / 10.0; //default scalebar width equals half the map width
    mSettings.setUnitsPerSegment( initialUnitsPerSegment );

    setUnitLabel( QgsUnitTypes::toAbbreviatedString( units ) );
    upperMagnitudeMultiplier = 1;

    double segmentWidth = initialUnitsPerSegment / upperMagnitudeMultiplier;
    int segmentMagnitude = std::floor( std::log10( segmentWidth ) );
    double unitsPerSegment = upperMagnitudeMultiplier * ( std::pow( 10.0, segmentMagnitude ) );
    double multiplier = std::floor( ( widthInSelectedUnits / ( unitsPerSegment * 10.0 ) ) / 2.5 ) * 2.5;

    if ( multiplier > 0 )
    {
      unitsPerSegment = unitsPerSegment * multiplier;
    }
    mSettings.setUnitsPerSegment( unitsPerSegment );
    mSettings.setMapUnitsPerScaleBarUnit( upperMagnitudeMultiplier );

    mSettings.setNumberOfSegments( 4 );
    mSettings.setNumberOfSegmentsLeft( 2 );
  }

  refreshSegmentMillimeters();
  resizeToMinimumWidth();
  emit changed();
}
コード例 #2
0
void QgsComposerScaleBar::applyDefaultSize()
{
  if ( mComposerMap )
  {
    setUnits( Meters );
    double widthMeter = mapWidth();
    int nUnitsPerSegment =  widthMeter / 10.0; //default scalebar width equals half the map width
    setNumUnitsPerSegment( nUnitsPerSegment );

    if ( nUnitsPerSegment > 1000 )
    {
      setNumUnitsPerSegment(( int )( numUnitsPerSegment() / 1000.0 + 0.5 ) * 1000 );
      setUnitLabeling( tr( "km" ) );
      setNumMapUnitsPerScaleBarUnit( 1000 );
    }
    else
    {
      setUnitLabeling( tr( "m" ) );
    }

    setNumSegments( 4 );
    setNumSegmentsLeft( 2 );
  }

  refreshSegmentMillimeters();
  adjustBoxSize();
  emit itemChanged();
}
コード例 #3
0
void QgsLayoutItemScaleBar::setUnits( QgsUnitTypes::DistanceUnit u )
{
  mSettings.setUnits( u );
  refreshSegmentMillimeters();
  refreshItemSize();
  emit changed();
}
コード例 #4
0
bool QgsComposerScaleBar::readXML( const QDomElement& itemElem, const QDomDocument& doc )
{
  if ( itemElem.isNull() )
  {
    return false;
  }

  mHeight = itemElem.attribute( "height", "5.0" ).toDouble();
  mLabelBarSpace = itemElem.attribute( "labelBarSpace", "3.0" ).toDouble();
  mBoxContentSpace = itemElem.attribute( "boxContentSpace", "1.0" ).toDouble();
  mNumSegments = itemElem.attribute( "numSegments", "2" ).toInt();
  mNumSegmentsLeft = itemElem.attribute( "numSegmentsLeft", "0" ).toInt();
  mNumUnitsPerSegment = itemElem.attribute( "numUnitsPerSegment", "1.0" ).toDouble();
  mSegmentMillimeters = itemElem.attribute( "segmentMillimeters", "0.0" ).toDouble();
  mNumMapUnitsPerScaleBarUnit = itemElem.attribute( "numMapUnitsPerScaleBarUnit", "1.0" ).toDouble();
  mPen.setWidthF( itemElem.attribute( "outlineWidth", "1.0" ).toDouble() );
  mUnitLabeling = itemElem.attribute( "unitLabel" );
  QString fontString = itemElem.attribute( "font", "" );
  if ( !fontString.isEmpty() )
  {
    mFont.fromString( fontString );
  }

  //style
  delete mStyle;
  mStyle = 0;
  QString styleString = itemElem.attribute( "style", "" );
  setStyle( tr( styleString.toLocal8Bit().data() ) );

  //map
  int mapId = itemElem.attribute( "mapId", "-1" ).toInt();
  if ( mapId >= 0 )
  {
    const QgsComposerMap* composerMap = mComposition->getComposerMapById( mapId );
    mComposerMap = composerMap;
    if ( mComposerMap )
    {
      connect( mComposerMap, SIGNAL( extentChanged() ), this, SLOT( updateSegmentSize() ) );
      connect( mComposerMap, SIGNAL( destroyed( QObject* ) ), this, SLOT( invalidateCurrentMap() ) );
    }
  }

  mUnits = ( ScaleBarUnits )itemElem.attribute( "units" ).toInt();

  refreshSegmentMillimeters();

  //alignment
  mAlignment = ( Alignment )( itemElem.attribute( "alignment", "0" ).toInt() );

  //restore general composer item properties
  QDomNodeList composerItemList = itemElem.elementsByTagName( "ComposerItem" );
  if ( composerItemList.size() > 0 )
  {
    QDomElement composerItemElem = composerItemList.at( 0 ).toElement();
    _readXML( composerItemElem, doc );
  }

  return true;
}
コード例 #5
0
void QgsLayoutItemScaleBar::setMaximumBarWidth( double maxWidth )
{
  if ( !mStyle )
  {
    mSettings.setMaximumBarWidth( maxWidth );
    return;
  }
  mSettings.setMaximumBarWidth( maxWidth );
  refreshSegmentMillimeters();
  resizeToMinimumWidth();
}
コード例 #6
0
void QgsLayoutItemScaleBar::setSegmentSizeMode( QgsScaleBarSettings::SegmentSizeMode mode )
{
  if ( !mStyle )
  {
    mSettings.setSegmentSizeMode( mode );
    return;
  }
  mSettings.setSegmentSizeMode( mode );
  refreshSegmentMillimeters();
  resizeToMinimumWidth();
}
コード例 #7
0
void QgsLayoutItemScaleBar::setUnitsPerSegment( double units )
{
  if ( !mStyle )
  {
    mSettings.setUnitsPerSegment( units );
    return;
  }
  mSettings.setUnitsPerSegment( units );
  refreshSegmentMillimeters();
  resizeToMinimumWidth();
}
コード例 #8
0
void QgsComposerScaleBar::updateSegmentSize()
{
  if ( !mStyle )
  {
    return;
  }
  double width = mStyle->calculateBoxSize().width();
  refreshSegmentMillimeters();
  double widthAfter = mStyle->calculateBoxSize().width();
  correctXPositionAlignment( width, widthAfter );
  update();
  emit itemChanged();
}
コード例 #9
0
void QgsComposerScaleBar::setNumUnitsPerSegment( double units )
{
  if ( !mStyle )
  {
    mNumUnitsPerSegment = units;
    return;
  }
  double width = mStyle->calculateBoxSize().width();
  mNumUnitsPerSegment = units;
  refreshSegmentMillimeters();
  double widthAfter = mStyle->calculateBoxSize().width();
  correctXPositionAlignment( width, widthAfter );
  emit itemChanged();
}
コード例 #10
0
void QgsComposerScaleBar::setMaxBarWidth( double maxWidth )
{
  if ( !mStyle )
  {
    mMaxBarWidth = maxWidth;
    return;
  }
  double width = mStyle->calculateBoxSize().width();
  mMaxBarWidth = maxWidth;
  refreshSegmentMillimeters();
  double widthAfter = mStyle->calculateBoxSize().width();
  correctXPositionAlignment( width, widthAfter );
  emit itemChanged();
}
コード例 #11
0
ファイル: qgscomposerscalebar.cpp プロジェクト: mola/qgis
void QgsComposerScaleBar::setComposerMap( const QgsComposerMap* map )
{
    disconnect( mComposerMap, SIGNAL( extentChanged() ), this, SLOT( updateSegmentSize() ) );
    disconnect( mComposerMap, SIGNAL( destroyed( QObject* ) ), this, SLOT( invalidateCurrentMap() ) );
    mComposerMap = map;

    if ( !map )
    {
        return;
    }

    connect( mComposerMap, SIGNAL( extentChanged() ), this, SLOT( updateSegmentSize() ) );
    connect( mComposerMap, SIGNAL( destroyed( QObject* ) ), this, SLOT( invalidateCurrentMap() ) );

    refreshSegmentMillimeters();
}
コード例 #12
0
void QgsLayoutItemScaleBar::setLinkedMap( QgsLayoutItemMap *map )
{
  disconnectCurrentMap();

  mMap = map;

  if ( !map )
  {
    return;
  }

  connect( mMap, &QgsLayoutItemMap::extentChanged, this, &QgsLayoutItemScaleBar::updateScale );
  connect( mMap, &QObject::destroyed, this, &QgsLayoutItemScaleBar::disconnectCurrentMap );

  refreshSegmentMillimeters();
  emit changed();
}
コード例 #13
0
void QgsComposerScaleBar::applyDefaultSize()
{
    if ( mComposerMap )
    {
        //calculate mNumUnitsPerSegment
        QgsRectangle composerMapRect = mComposerMap->extent();

        double proposedScaleBarLength = composerMapRect.width() / 4;
        int powerOf10 = int ( pow( 10.0, int ( log( proposedScaleBarLength ) / log( 10.0 ) ) ) ); // from scalebar plugin
        int nPow10 = proposedScaleBarLength / powerOf10;
        mNumSegments = 2;
        mNumUnitsPerSegment = ( nPow10 / 2 ) * powerOf10;
    }

    refreshSegmentMillimeters();
    adjustBoxSize();
    emit itemChanged();
}
コード例 #14
0
ファイル: qgscomposerscalebar.cpp プロジェクト: mola/qgis
void QgsComposerScaleBar::applyDefaultSettings()
{
    mNumSegments = 2;
    mNumSegmentsLeft = 0;

    mNumMapUnitsPerScaleBarUnit = 1.0;

    //style
    delete mStyle;
    mStyle = new QgsSingleBoxScaleBarStyle( this );

    mHeight = 5;

    mPen = QPen( QColor( 0, 0, 0 ) );
    mPen.setWidthF( 1.0 );

    mBrush.setColor( QColor( 0, 0, 0 ) );
    mBrush.setStyle( Qt::SolidPattern );

    mFont.setPointSizeF( 12.0 );

    mLabelBarSpace = 3.0;
    mBoxContentSpace = 1.0;

    if ( mComposerMap )
    {
        //calculate mNumUnitsPerSegment
        QRectF composerItemRect = mComposerMap->rect();
        QgsRectangle composerMapRect = mComposerMap->extent();

        double proposedScaleBarLength = composerMapRect.width() / 4;
        int powerOf10 = int ( pow( 10.0, int ( log( proposedScaleBarLength ) / log( 10.0 ) ) ) ); // from scalebar plugin
        int nPow10 = proposedScaleBarLength / powerOf10;
        mNumSegments = 2;
        mNumUnitsPerSegment = ( nPow10 / 2 ) * powerOf10;
    }

    refreshSegmentMillimeters();
    adjustBoxSize();
}
コード例 #15
0
void QgsComposerScaleBar::applyDefaultSize( QgsComposerScaleBar::ScaleBarUnits u )
{
  if ( mComposerMap )
  {
    setUnits( u );
    double upperMagnitudeMultiplier = 1.0;
    double widthInSelectedUnits = mapWidth();
    double initialUnitsPerSegment =  widthInSelectedUnits / 10.0; //default scalebar width equals half the map width
    setNumUnitsPerSegment( initialUnitsPerSegment );

    switch ( mUnits )
    {
      case MapUnits:
      {
        upperMagnitudeMultiplier = 1.0;
        setUnitLabeling( tr( "units" ) );
        break;
      }
      case Meters:
      {
        if ( initialUnitsPerSegment > 1000.0 )
        {
          upperMagnitudeMultiplier = 1000.0;
          setUnitLabeling( tr( "km" ) );
        }
        else
        {
          upperMagnitudeMultiplier = 1.0;
          setUnitLabeling( tr( "m" ) );
        }
        break;
      }
      case Feet:
      {
        if ( initialUnitsPerSegment > 5419.95 )
        {
          upperMagnitudeMultiplier = 5419.95;
          setUnitLabeling( tr( "miles" ) );
        }
        else
        {
          upperMagnitudeMultiplier = 1.0;
          setUnitLabeling( tr( "ft" ) );
        }
        break;
      }
      case NauticalMiles:
      {
        upperMagnitudeMultiplier = 1;
        setUnitLabeling( tr( "Nm" ) );
        break;
      }
    }

    double segmentWidth = initialUnitsPerSegment / upperMagnitudeMultiplier;
    int segmentMagnitude = floor( log10( segmentWidth ) );
    double unitsPerSegment = upperMagnitudeMultiplier * ( qPow( 10.0, segmentMagnitude ) );
    double multiplier = floor(( widthInSelectedUnits / ( unitsPerSegment * 10.0 ) ) / 2.5 ) * 2.5;

    if ( multiplier > 0 )
    {
      unitsPerSegment = unitsPerSegment * multiplier;
    }
    setNumUnitsPerSegment( unitsPerSegment );
    setNumMapUnitsPerScaleBarUnit( upperMagnitudeMultiplier );

    setNumSegments( 4 );
    setNumSegmentsLeft( 2 );
  }

  refreshSegmentMillimeters();
  adjustBoxSize();
  emit itemChanged();
}
コード例 #16
0
void QgsComposerScaleBar::setUnits( ScaleBarUnits u )
{
  mUnits = u;
  refreshSegmentMillimeters();
  emit itemChanged();
}
コード例 #17
0
ファイル: qgscomposerscalebar.cpp プロジェクト: mola/qgis
void QgsComposerScaleBar::setNumUnitsPerSegment( double units )
{
    mNumUnitsPerSegment = units;
    refreshSegmentMillimeters();
}
コード例 #18
0
ファイル: qgscomposerscalebar.cpp プロジェクト: mola/qgis
void QgsComposerScaleBar::updateSegmentSize()
{
    refreshSegmentMillimeters();
    update();
}
コード例 #19
0
void QgsLayoutItemScaleBar::updateScale()
{
  refreshSegmentMillimeters();
  resizeToMinimumWidth();
  update();
}