void QgsLayoutItemScaleBar::setUnits( QgsUnitTypes::DistanceUnit u )
{
  mSettings.setUnits( u );
  refreshSegmentMillimeters();
  refreshItemSize();
  emit changed();
}
void QgsLayoutItemScaleBar::setStyle( const QString &styleName )
{
  //switch depending on style name
  if ( styleName == QLatin1String( "Single Box" ) )
  {
    mStyle = qgis::make_unique< QgsSingleBoxScaleBarRenderer >();
  }
  else if ( styleName == QLatin1String( "Double Box" ) )
  {
    mStyle = qgis::make_unique< QgsDoubleBoxScaleBarRenderer >();
  }
  else if ( styleName == QLatin1String( "Line Ticks Middle" )  || styleName == QLatin1String( "Line Ticks Down" ) || styleName == QLatin1String( "Line Ticks Up" ) )
  {
    std::unique_ptr< QgsTicksScaleBarRenderer > tickStyle = qgis::make_unique< QgsTicksScaleBarRenderer >();
    if ( styleName == QLatin1String( "Line Ticks Middle" ) )
    {
      tickStyle->setTickPosition( QgsTicksScaleBarRenderer::TicksMiddle );
    }
    else if ( styleName == QLatin1String( "Line Ticks Down" ) )
    {
      tickStyle->setTickPosition( QgsTicksScaleBarRenderer::TicksDown );
    }
    else if ( styleName == QLatin1String( "Line Ticks Up" ) )
    {
      tickStyle->setTickPosition( QgsTicksScaleBarRenderer::TicksUp );
    }
    mStyle = std::move( tickStyle );
  }
  else if ( styleName == QLatin1String( "Numeric" ) )
  {
    mStyle = qgis::make_unique< QgsNumericScaleBarRenderer >();
  }
  refreshItemSize();
  emit changed();
}
void QgsLayoutItemScaleBar::applyDefaultSettings()
{
  //style
  mStyle = qgis::make_unique< QgsSingleBoxScaleBarRenderer >();

  //default to no background
  setBackgroundEnabled( false );

  //get default composer font from settings
  QgsSettings settings;
  QString defaultFontString = settings.value( QStringLiteral( "LayoutDesigner/defaultFont" ), QVariant(), QgsSettings::Gui ).toString();
  QgsTextFormat format;
  QFont f;
  if ( !defaultFontString.isEmpty() )
  {
    f.setFamily( defaultFontString );
  }
  format.setFont( f );
  format.setSize( 12.0 );
  format.setSizeUnit( QgsUnitTypes::RenderPoints );

  mSettings.setTextFormat( format );

  mSettings.setUnits( QgsUnitTypes::DistanceUnknownUnit );
  refreshItemSize();

  emit changed();
}
void QgsLayoutItemScaleBar::setFont( const QFont &font )
{
  Q_NOWARN_DEPRECATED_PUSH
  mSettings.setFont( font );
  Q_NOWARN_DEPRECATED_POP
  refreshItemSize();
  emit changed();
}
void QgsLayoutItemScaleBar::update()
{
  //Don't adjust box size for numeric scale bars:
  if ( mStyle && mStyle->name() != QLatin1String( "Numeric" ) )
  {
    refreshItemSize();
  }
  QgsLayoutItem::update();
}
void QgsLayoutItemScaleBar::setBoxContentSpace( double space )
{
  if ( !mStyle )
  {
    mSettings.setBoxContentSpace( space );
    return;
  }
  mSettings.setBoxContentSpace( space );
  refreshItemSize();
}
void QgsLayoutItemScaleBar::refreshDataDefinedProperty( const QgsLayoutObject::DataDefinedProperty property )
{
  QgsExpressionContext context = createExpressionContext();

  bool forceUpdate = false;
  //updates data defined properties and redraws item to match
  if ( property == QgsLayoutObject::ScalebarFillColor || property == QgsLayoutObject::AllProperties )
  {
    QBrush b = mSettings.brush();
    b.setColor( mDataDefinedProperties.valueAsColor( QgsLayoutObject::ScalebarFillColor, context, mSettings.fillColor() ) );
    mSettings.setBrush( b );
    forceUpdate = true;
  }
  if ( property == QgsLayoutObject::ScalebarFillColor2 || property == QgsLayoutObject::AllProperties )
  {
    QBrush b = mSettings.brush2();
    b.setColor( mDataDefinedProperties.valueAsColor( QgsLayoutObject::ScalebarFillColor2, context, mSettings.fillColor2() ) );
    mSettings.setBrush2( b );
    forceUpdate = true;
  }
  if ( property == QgsLayoutObject::ScalebarLineColor || property == QgsLayoutObject::AllProperties )
  {
    QPen p = mSettings.pen();
    p.setColor( mDataDefinedProperties.valueAsColor( QgsLayoutObject::ScalebarLineColor, context, mSettings.lineColor() ) );
    mSettings.setPen( p );
    forceUpdate = true;
  }
  if ( property == QgsLayoutObject::ScalebarLineWidth || property == QgsLayoutObject::AllProperties )
  {
    QPen p = mSettings.pen();
    p.setWidthF( mDataDefinedProperties.valueAsDouble( QgsLayoutObject::ScalebarLineWidth, context, mSettings.lineWidth() ) );
    mSettings.setPen( p );
    forceUpdate = true;
  }
  if ( forceUpdate )
  {
    refreshItemSize();
    update();
  }

  QgsLayoutItem::refreshDataDefinedProperty( property );
}
Example #8
0
QgsLayoutFrame::QgsLayoutFrame( QgsLayout *layout, QgsLayoutMultiFrame *multiFrame )
  : QgsLayoutItem( layout )
  , mMultiFrame( multiFrame )
  , mMultiFrameUuid( multiFrame ? multiFrame->uuid() : QString() )
{

  //default to no background
  setBackgroundEnabled( false );

  if ( multiFrame )
  {
    //repaint frame when multiframe content changes
    connect( multiFrame, &QgsLayoutMultiFrame::contentsChanged, this, [ = ]
    {
      update();
    } );

    //force recalculation of rect, so that multiframe specified sizes can be applied
    refreshItemSize();
  }
}
void QgsLayoutItemScaleBar::setAlignment( QgsScaleBarSettings::Alignment a )
{
  mSettings.setAlignment( a );
  refreshItemSize();
  emit changed();
}
void QgsLayoutItemScaleBar::setTextFormat( const QgsTextFormat &format )
{
  mSettings.setTextFormat( format );
  refreshItemSize();
  emit changed();
}