Skip to content
Permalink
Browse files
mLegend string member with getter and setter
  • Loading branch information
mhugent committed May 13, 2021
1 parent cd4c177 commit dce94dc65620735a1f288dc15fbb73307e8f3fb8
@@ -482,7 +482,19 @@ Sets the polygon placement ``flags``, which dictate how polygon labels can be pl

QgsWkbTypes::GeometryType layerType;

QString legendString;
void setLegendString( const QString &legendString );
%Docstring
setLegendString

:param legendString: the string to show in the legend and preview
%End

QString legendString() const;
%Docstring
legendString

:return: the string to show in the legend and in the preview icon
%End

void calculateLabelSize( const QFontMetricsF *fm, const QString &text, double &labelX, double &labelY, const QgsFeature *f = 0, QgsRenderContext *context = 0, double *rotatedLabelX /Out/ = 0, double *rotatedLabelY /Out/ = 0 );
%Docstring
@@ -366,7 +366,7 @@ QgsPalLayerSettings &QgsPalLayerSettings::operator=( const QgsPalLayerSettings &
geometryGeneratorType = s.geometryGeneratorType;
layerType = s.layerType;

legendString = s.legendString;
mLegendString = s.mLegendString;

return *this;
}
@@ -930,7 +930,7 @@ void QgsPalLayerSettings::readXml( const QDomElement &elem, const QgsReadWriteCo
Q_NOWARN_DEPRECATED_POP
substitutions.readXml( textStyleElem.firstChildElement( QStringLiteral( "substitutions" ) ) );
useSubstitutions = textStyleElem.attribute( QStringLiteral( "useSubstitutions" ) ).toInt();
legendString = textStyleElem.attribute( QStringLiteral( "legendString" ), QObject::tr( "Aa" ) );
mLegendString = textStyleElem.attribute( QStringLiteral( "legendString" ), QObject::tr( "Aa" ) );

// text formatting
QDomElement textFormatElem = elem.firstChildElement( QStringLiteral( "text-format" ) );
@@ -1170,7 +1170,7 @@ QDomElement QgsPalLayerSettings::writeXml( QDomDocument &doc, const QgsReadWrite
substitutions.writeXml( replacementElem, doc );
textStyleElem.appendChild( replacementElem );
textStyleElem.setAttribute( QStringLiteral( "useSubstitutions" ), useSubstitutions );
textStyleElem.setAttribute( QStringLiteral( "legendString" ), legendString );
textStyleElem.setAttribute( QStringLiteral( "legendString" ), mLegendString );

// text formatting
QDomElement textFormatElem = doc.createElement( QStringLiteral( "text-format" ) );
@@ -1345,7 +1345,7 @@ QPixmap QgsPalLayerSettings::labelSettingsPreviewPixmap( const QgsPalLayerSettin
if ( tempFormat.background().enabled() )
ytrans = std::max( ytrans, context.convertToPainterUnits( tempFormat.background().size().height(), tempFormat.background().sizeUnit(), tempFormat.background().sizeMapUnitScale() ) );

const QStringList text = QStringList() << ( previewText.isEmpty() ? settings.legendString : previewText );
const QStringList text = QStringList() << ( previewText.isEmpty() ? settings.legendString() : previewText );
const double textHeight = QgsTextRenderer::textHeight( context, tempFormat, text, QgsTextRenderer::Rect );
QRectF textRect = rect;
textRect.setLeft( xtrans + padding );
@@ -799,10 +799,16 @@ class CORE_EXPORT QgsPalLayerSettings
QgsWkbTypes::GeometryType layerType = QgsWkbTypes::UnknownGeometry;

/**
* \brief string to show in the legend and in the preview icon
* \since QGIS 3.20
* \brief setLegendString
* \param legendString the string to show in the legend and preview
*/
QString legendString = QObject::tr( "Aa" );
void setLegendString( const QString &legendString ) { mLegendString = legendString; }

/**
* \brief legendString
* \return the string to show in the legend and in the preview icon
*/
QString legendString() const { return mLegendString; }

/**
* Calculates the space required to render the provided \a text in map units.
@@ -1093,6 +1099,8 @@ class CORE_EXPORT QgsPalLayerSettings

bool mRenderStarted = false;

QString mLegendString = QObject::tr( "Aa" );

static void initPropertyDefinitions();
};

@@ -1451,7 +1451,7 @@ QVariant QgsVectorLabelLegendNode::data( int role ) const
if ( role == Qt::DecorationRole )
{
const int iconSize = QgsLayerTreeModel::scaleIconSize( 16 );
return QgsPalLayerSettings::labelSettingsPreviewPixmap( mLabelSettings, QSize( iconSize, iconSize ), mLabelSettings.legendString );
return QgsPalLayerSettings::labelSettingsPreviewPixmap( mLabelSettings, QSize( iconSize, iconSize ), mLabelSettings.legendString() );
}
return QVariant();
}
@@ -1475,7 +1475,7 @@ QSizeF QgsVectorLabelLegendNode::drawSymbol( const QgsLegendSettings &settings,

QSizeF QgsVectorLabelLegendNode::drawSymbol( const QgsLegendSettings &settings, const QgsRenderContext &renderContext, double xOffset, double yOffset ) const
{
QStringList textLines( mLabelSettings.legendString );
QStringList textLines( mLabelSettings.legendString() );
QgsTextFormat textFormat = mLabelSettings.format();
textFormat.setSize( textFormat.size() / renderContext.scaleFactor() ); //painter is usually scaled (e.g. mm unit)
QgsRenderContext ctx( renderContext );
@@ -1496,14 +1496,14 @@ QJsonObject QgsVectorLabelLegendNode::exportSymbolToJson( const QgsLegendSetting

const double mmToPixel = 96.0 / 25.4; //settings.dpi() is deprecated

const QStringList textLines( mLabelSettings.legendString );
const QStringList textLines( mLabelSettings.legendString() );
const QgsTextFormat textFormat = mLabelSettings.format();
QgsRenderContext ctx( context );
ctx.setScaleFactor( mmToPixel );

double textWidth, textHeight;
textWidthHeight( textWidth, textHeight, ctx, textFormat, textLines );
QPixmap previewPixmap = mLabelSettings.labelSettingsPreviewPixmap( mLabelSettings, QSize( textWidth, textHeight ), mLabelSettings.legendString );
QPixmap previewPixmap = mLabelSettings.labelSettingsPreviewPixmap( mLabelSettings, QSize( textWidth, textHeight ), mLabelSettings.legendString() );

QByteArray byteArray;
QBuffer buffer( &byteArray );
@@ -150,7 +150,7 @@ void QgsVectorLayerLegendWidget::populateLabelLegendTreeWidget()
}
}

QTreeWidgetItem *labelItem = new QTreeWidgetItem( QStringList() << description << s.legendString );
QTreeWidgetItem *labelItem = new QTreeWidgetItem( QStringList() << description << s.legendString() );
labelItem->setData( 0, Qt::UserRole, pList.at( i ) );
mLabelLegendTreeWidget->addTopLevelItem( labelItem );
}
@@ -285,7 +285,7 @@ void QgsVectorLayerLegendWidget::applyLabelLegend()
QString legendText = item->text( 1 );

QgsPalLayerSettings *s = new QgsPalLayerSettings( labeling->settings( ids.at( i ) ) );
s->legendString = legendText;
s->setLegendString( legendText );
labeling->setSettings( s, ids.at( i ) );
}
}

0 comments on commit dce94dc

Please sign in to comment.