Skip to content

Commit

Permalink
Deprecate legend line spacing setting, this is now handled in the text
Browse files Browse the repository at this point in the history
formats
  • Loading branch information
nyalldawson committed Nov 29, 2022
1 parent b4ecf8a commit 3527257
Show file tree
Hide file tree
Showing 13 changed files with 223 additions and 203 deletions.
10 changes: 8 additions & 2 deletions python/core/auto_generated/layout/qgslayoutitemlegend.sip.in
Expand Up @@ -240,18 +240,24 @@ Set the ``margin`` for a legend ``component``.
Set the ``margin`` for a particular ``side`` of a legend ``component``.
%End

double lineSpacing() const;
double lineSpacing() const /Deprecated/;
%Docstring
Returns the spacing in-between lines in layout units.

.. seealso:: :py:func:`setLineSpacing`

.. deprecated::
use :py:func:`QgsLegendStyle.textFormat()` from :py:func:`~QgsLayoutItemLegend.style` instead.
%End

void setLineSpacing( double spacing );
void setLineSpacing( double spacing ) /Deprecated/;
%Docstring
Sets the ``spacing`` in-between multiple lines.

.. seealso:: :py:func:`lineSpacing`

.. deprecated::
use :py:func:`QgsLegendStyle.setTextFormat()` from :py:func:`~QgsLayoutItemLegend.style` instead.
%End

double boxSpace() const;
Expand Down
10 changes: 8 additions & 2 deletions python/core/auto_generated/qgslegendsettings.sip.in
Expand Up @@ -395,18 +395,24 @@ Sets the desired size (in millimeters) of WMS legend graphics shown in the legen
.. seealso:: :py:func:`wmsLegendSize`
%End

double lineSpacing() const;
double lineSpacing() const /Deprecated/;
%Docstring
Returns the line spacing to use between lines of legend text.

.. seealso:: :py:func:`setLineSpacing`

.. deprecated::
use :py:func:`QgsLegendStyle.textFormat()` from :py:func:`~QgsLegendSettings.style` instead.
%End

void setLineSpacing( double s );
void setLineSpacing( double s );
%Docstring
Sets the line spacing to use between lines of legend text.

.. seealso:: :py:func:`lineSpacing`

.. deprecated::
use :py:func:`QgsLegendStyle.setTextFormat()` from :py:func:`~QgsLegendSettings.style` instead.
%End

double mmPerMapUnit() const /Deprecated/;
Expand Down
2 changes: 2 additions & 0 deletions src/core/layout/qgscompositionconverter.cpp
Expand Up @@ -1305,7 +1305,9 @@ bool QgsCompositionConverter::readLegendXml( QgsLayoutItemLegend *layoutItem, co
layoutItem->setSymbolHeight( itemElem.attribute( QStringLiteral( "symbolHeight" ), QStringLiteral( "14.0" ) ).toDouble() );
layoutItem->setWmsLegendWidth( itemElem.attribute( QStringLiteral( "wmsLegendWidth" ), QStringLiteral( "50" ) ).toDouble() );
layoutItem->setWmsLegendHeight( itemElem.attribute( QStringLiteral( "wmsLegendHeight" ), QStringLiteral( "25" ) ).toDouble() );
Q_NOWARN_DEPRECATED_PUSH
layoutItem->setLineSpacing( itemElem.attribute( QStringLiteral( "lineSpacing" ), QStringLiteral( "1.0" ) ).toDouble() );
Q_NOWARN_DEPRECATED_POP

layoutItem->setDrawRasterStroke( itemElem.attribute( QStringLiteral( "rasterBorder" ), QStringLiteral( "1" ) ) != QLatin1String( "0" ) );
layoutItem->setRasterStrokeColor( QgsSymbolLayerUtils::decodeColor( itemElem.attribute( QStringLiteral( "rasterBorderColor" ), QStringLiteral( "0,0,0" ) ) ) );
Expand Down
43 changes: 35 additions & 8 deletions src/core/layout/qgslayoutitemlegend.cpp
Expand Up @@ -19,7 +19,6 @@
#include "qgslayoutitemlegend.h"
#include "qgslayoutitemregistry.h"
#include "qgslayoutitemmap.h"
#include "qgslayout.h"
#include "qgslayoutmodel.h"
#include "qgslayertree.h"
#include "qgslayertreemodel.h"
Expand All @@ -31,8 +30,11 @@
#include "qgssymbollayerutils.h"
#include "qgslayertreeutils.h"
#include "qgslayoututils.h"
#include "qgsmapthemecollection.h"
#include "qgslayout.h"
#include "qgsstyleentityvisitor.h"
#include "qgslayertreemodellegendnode.h"
#include "qgsvectorlayer.h"

#include <QDomDocument>
#include <QDomElement>
#include <QPainter>
Expand Down Expand Up @@ -253,7 +255,7 @@ void QgsLayoutItemLegend::adjustBoxSize()

QgsLegendRenderer legendRenderer( mLegendModel.get(), mSettings );
const QSizeF size = legendRenderer.minimumSize( &context );
QgsDebugMsg( QStringLiteral( "width = %1 height = %2" ).arg( size.width() ).arg( size.height() ) );
QgsDebugMsgLevel( QStringLiteral( "width = %1 height = %2" ).arg( size.width() ).arg( size.height() ), 2 );
if ( size.isValid() )
{
const QgsLayoutSize newSize = mLayout->convertFromLayoutUnits( size, sizeWithUnits().units() );
Expand Down Expand Up @@ -381,12 +383,16 @@ void QgsLayoutItemLegend::setStyleMargin( QgsLegendStyle::Style s, QgsLegendStyl

double QgsLayoutItemLegend::lineSpacing() const
{
Q_NOWARN_DEPRECATED_PUSH
return mSettings.lineSpacing();
Q_NOWARN_DEPRECATED_POP
}

void QgsLayoutItemLegend::setLineSpacing( double spacing )
{
Q_NOWARN_DEPRECATED_PUSH
mSettings.setLineSpacing( spacing );
Q_NOWARN_DEPRECATED_POP
}

double QgsLayoutItemLegend::boxSpace() const
Expand Down Expand Up @@ -591,7 +597,6 @@ bool QgsLayoutItemLegend::writePropertiesToElement( QDomElement &legendElem, QDo
legendElem.setAttribute( QStringLiteral( "symbolAlignment" ), mSettings.symbolAlignment() );

legendElem.setAttribute( QStringLiteral( "symbolAlignment" ), mSettings.symbolAlignment() );
legendElem.setAttribute( QStringLiteral( "lineSpacing" ), QString::number( mSettings.lineSpacing() ) );

legendElem.setAttribute( QStringLiteral( "rasterBorder" ), mSettings.drawRasterStroke() );
legendElem.setAttribute( QStringLiteral( "rasterBorderColor" ), QgsSymbolLayerUtils::encodeColor( mSettings.rasterStrokeColor() ) );
Expand Down Expand Up @@ -691,7 +696,32 @@ bool QgsLayoutItemLegend::readPropertiesFromElement( const QDomElement &itemElem
mSettings.setMinimumSymbolSize( itemElem.attribute( QStringLiteral( "minSymbolSize" ), QStringLiteral( "0.0" ) ).toDouble() );

mSettings.setWmsLegendSize( QSizeF( itemElem.attribute( QStringLiteral( "wmsLegendWidth" ), QStringLiteral( "50" ) ).toDouble(), itemElem.attribute( QStringLiteral( "wmsLegendHeight" ), QStringLiteral( "25" ) ).toDouble() ) );
mSettings.setLineSpacing( itemElem.attribute( QStringLiteral( "lineSpacing" ), QStringLiteral( "1.0" ) ).toDouble() );

if ( itemElem.hasAttribute( QStringLiteral( "lineSpacing" ) ) )
{
const double spacing = itemElem.attribute( QStringLiteral( "lineSpacing" ), QStringLiteral( "1.0" ) ).toDouble();
// line spacing *was* a fixed amount (in mm) added between each line of text.
QgsTextFormat f = rstyle( QgsLegendStyle::Title ).textFormat();
// assume font sizes in points, since that was what we always had from before this method was deprecated
f.setLineHeight( f.size() * 0.352778 + spacing );
f.setLineHeightUnit( QgsUnitTypes::RenderMillimeters );
rstyle( QgsLegendStyle::Title ).setTextFormat( f );

f = rstyle( QgsLegendStyle::Group ).textFormat();
f.setLineHeight( f.size() * 0.352778 + spacing );
f.setLineHeightUnit( QgsUnitTypes::RenderMillimeters );
rstyle( QgsLegendStyle::Group ).setTextFormat( f );

f = rstyle( QgsLegendStyle::Subgroup ).textFormat();
f.setLineHeight( f.size() * 0.352778 + spacing );
f.setLineHeightUnit( QgsUnitTypes::RenderMillimeters );
rstyle( QgsLegendStyle::Subgroup ).setTextFormat( f );

f = rstyle( QgsLegendStyle::SymbolLabel ).textFormat();
f.setLineHeight( f.size() * 0.352778 + spacing );
f.setLineHeightUnit( QgsUnitTypes::RenderMillimeters );
rstyle( QgsLegendStyle::SymbolLabel ).setTextFormat( f );
}

mSettings.setDrawRasterStroke( itemElem.attribute( QStringLiteral( "rasterBorder" ), QStringLiteral( "1" ) ) != QLatin1String( "0" ) );
mSettings.setRasterStrokeColor( QgsSymbolLayerUtils::decodeColor( itemElem.attribute( QStringLiteral( "rasterBorderColor" ), QStringLiteral( "0,0,0" ) ) ) );
Expand Down Expand Up @@ -1090,9 +1120,6 @@ bool QgsLayoutItemLegend::accept( QgsStyleEntityVisitorInterface *visitor ) cons


// -------------------------------------------------------------------------
#include "qgslayertreemodellegendnode.h"
#include "qgsvectorlayer.h"
#include "qgsmaplayerlegend.h"

QgsLegendModel::QgsLegendModel( QgsLayerTree *rootNode, QObject *parent, QgsLayoutItemLegend *layout )
: QgsLayerTreeModel( rootNode, parent )
Expand Down
8 changes: 6 additions & 2 deletions src/core/layout/qgslayoutitemlegend.h
Expand Up @@ -265,14 +265,18 @@ class CORE_EXPORT QgsLayoutItemLegend : public QgsLayoutItem
/**
* Returns the spacing in-between lines in layout units.
* \see setLineSpacing()
*
* \deprecated use QgsLegendStyle::textFormat() from style() instead.
*/
double lineSpacing() const;
Q_DECL_DEPRECATED double lineSpacing() const SIP_DEPRECATED;

/**
* Sets the \a spacing in-between multiple lines.
* \see lineSpacing()
*
* \deprecated use QgsLegendStyle::setTextFormat() from style() instead.
*/
void setLineSpacing( double spacing );
Q_DECL_DEPRECATED void setLineSpacing( double spacing ) SIP_DEPRECATED;

/**
* Returns the legend box space.
Expand Down
27 changes: 27 additions & 0 deletions src/core/qgslegendsettings.cpp
Expand Up @@ -88,6 +88,33 @@ void QgsLegendSettings::setLayerFontColor( const QColor &fontColor )
rstyle( QgsLegendStyle::Subgroup ).textFormat().setColor( fontColor );
}

void QgsLegendSettings::setLineSpacing( double s ) SIP_DEPRECATED
{
// line spacing *was* a fixed amount (in mm) added between each line of text.
mLineSpacing = s;

QgsTextFormat f = rstyle( QgsLegendStyle::Title ).textFormat();
// assume font sizes in points, since that was what we always had from before this method was deprecated
f.setLineHeight( f.size() * 0.352778 + s );
f.setLineHeightUnit( QgsUnitTypes::RenderMillimeters );
rstyle( QgsLegendStyle::Title ).setTextFormat( f );

f = rstyle( QgsLegendStyle::Group ).textFormat();
f.setLineHeight( f.size() * 0.352778 + s );
f.setLineHeightUnit( QgsUnitTypes::RenderMillimeters );
rstyle( QgsLegendStyle::Group ).setTextFormat( f );

f = rstyle( QgsLegendStyle::Subgroup ).textFormat();
f.setLineHeight( f.size() * 0.352778 + s );
f.setLineHeightUnit( QgsUnitTypes::RenderMillimeters );
rstyle( QgsLegendStyle::Subgroup ).setTextFormat( f );

f = rstyle( QgsLegendStyle::SymbolLabel ).textFormat();
f.setLineHeight( f.size() * 0.352778 + s );
f.setLineHeightUnit( QgsUnitTypes::RenderMillimeters );
rstyle( QgsLegendStyle::SymbolLabel ).setTextFormat( f );
}

double QgsLegendSettings::mmPerMapUnit() const
{
return mMmPerMapUnit;
Expand Down
6 changes: 4 additions & 2 deletions src/core/qgslegendsettings.h
Expand Up @@ -371,15 +371,17 @@ class CORE_EXPORT QgsLegendSettings
* Returns the line spacing to use between lines of legend text.
*
* \see setLineSpacing()
* \deprecated use QgsLegendStyle::textFormat() from style() instead.
*/
double lineSpacing() const { return mLineSpacing; }
Q_DECL_DEPRECATED double lineSpacing() const SIP_DEPRECATED { return mLineSpacing; }

/**
* Sets the line spacing to use between lines of legend text.
*
* \see lineSpacing()
* \deprecated use QgsLegendStyle::setTextFormat() from style() instead.
*/
void setLineSpacing( double s ) { mLineSpacing = s; }
Q_DECL_DEPRECATED void setLineSpacing( double s );

/**
* \deprecated Use scale factor from render contexts instead.
Expand Down
20 changes: 1 addition & 19 deletions src/gui/layout/qgslayoutlegendwidget.cpp
Expand Up @@ -20,7 +20,6 @@
#include "qgslayoutlegendlayersdialog.h"
#include "qgslayoutitemwidget.h"
#include "qgslayoutitemmap.h"
#include "qgslayout.h"
#include "qgsguiutils.h"
#include "qgslayoutdesignerinterface.h"

Expand All @@ -32,7 +31,6 @@
#include "qgslegendrenderer.h"
#include "qgsmapcanvas.h"
#include "qgsmaplayerlegend.h"
#include "qgsproject.h"
#include "qgsrenderer.h"
#include "qgsvectorlayer.h"
#include "qgslayoutatlas.h"
Expand All @@ -41,9 +39,8 @@
#include "qgsunittypes.h"
#include "qgsexpressionbuilderdialog.h"
#include "qgsexpressioncontextutils.h"
#include "qgslegendpatchshapewidget.h"
#include "qgslayertreefilterproxymodel.h"
#include "qgscolorramplegendnodewidget.h"
#include "qgssymbol.h"

#include <QMenu>
#include <QMessageBox>
Expand Down Expand Up @@ -107,7 +104,6 @@ QgsLayoutLegendWidget::QgsLayoutLegendWidget( QgsLayoutItemLegend *legend, QgsMa
connect( mIconLabelSpaceSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutLegendWidget::mIconLabelSpaceSpinBox_valueChanged );
connect( mBoxSpaceSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutLegendWidget::mBoxSpaceSpinBox_valueChanged );
connect( mColumnSpaceSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutLegendWidget::mColumnSpaceSpinBox_valueChanged );
connect( mLineSpacingSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutLegendWidget::mLineSpacingSpinBox_valueChanged );
connect( mCheckBoxAutoUpdate, &QCheckBox::stateChanged, this, [ = ]( int state ) { mCheckBoxAutoUpdate_stateChanged( state ); } );
connect( mCheckboxResizeContents, &QCheckBox::toggled, this, &QgsLayoutLegendWidget::mCheckboxResizeContents_toggled );
connect( mRasterStrokeGroupBox, &QgsCollapsibleGroupBoxBasic::toggled, this, &QgsLayoutLegendWidget::mRasterStrokeGroupBox_toggled );
Expand Down Expand Up @@ -278,7 +274,6 @@ void QgsLayoutLegendWidget::setGuiElements()
mSymbolSideSpaceSpinBox->setValue( mLegend->style( QgsLegendStyle::Symbol ).margin( QgsLegendStyle::Left ) );
mBoxSpaceSpinBox->setValue( mLegend->boxSpace() );
mColumnSpaceSpinBox->setValue( mLegend->columnSpace() );
mLineSpacingSpinBox->setValue( mLegend->lineSpacing() );

mRasterStrokeGroupBox->setChecked( mLegend->drawRasterStroke() );
mRasterStrokeWidthSpinBox->setValue( mLegend->rasterStrokeWidth() );
Expand Down Expand Up @@ -713,18 +708,6 @@ void QgsLayoutLegendWidget::mColumnSpaceSpinBox_valueChanged( double d )
}
}

void QgsLayoutLegendWidget::mLineSpacingSpinBox_valueChanged( double d )
{
if ( mLegend )
{
mLegend->beginCommand( tr( "Change Line Space" ), QgsLayoutItem::UndoLegendLineSpacing );
mLegend->setLineSpacing( d );
mLegend->adjustBoxSize();
mLegend->update();
mLegend->endCommand();
}
}

static void _moveLegendNode( QgsLayerTreeLayer *nodeLayer, int legendNodeIndex, int offset )
{
QList<int> order = QgsMapLayerLegendUtils::legendNodeOrder( nodeLayer );
Expand Down Expand Up @@ -1326,7 +1309,6 @@ void QgsLayoutLegendWidget::blockAllSignals( bool b )
mLayerFontButton->blockSignals( b );
mItemFontButton->blockSignals( b );
mWrapCharLineEdit->blockSignals( b );
mLineSpacingSpinBox->blockSignals( b );
}

void QgsLayoutLegendWidget::selectedChanged( const QModelIndex &current, const QModelIndex &previous )
Expand Down
1 change: 0 additions & 1 deletion src/gui/layout/qgslayoutlegendwidget.h
Expand Up @@ -89,7 +89,6 @@ class GUI_EXPORT QgsLayoutLegendWidget: public QgsLayoutItemBaseWidget, public Q
void mIconLabelSpaceSpinBox_valueChanged( double d );
void mBoxSpaceSpinBox_valueChanged( double d );
void mColumnSpaceSpinBox_valueChanged( double d );
void mLineSpacingSpinBox_valueChanged( double d );
void mCheckBoxAutoUpdate_stateChanged( int state, bool userTriggered = true );
void composerMapChanged( QgsLayoutItem *item );
void mCheckboxResizeContents_toggled( bool checked );
Expand Down

0 comments on commit 3527257

Please sign in to comment.