mirror of
https://github.com/qgis/QGIS.git
synced 2025-12-07 00:03:52 -05:00
Cleanup handling of default label format for project, and avoid a QgsProject::instance() use in core
This commit is contained in:
parent
a2b8c387f6
commit
aa658465f8
@ -759,6 +759,13 @@ Returns the default patch geometry for the given symbol ``type`` and ``size`` as
|
||||
Returns the default text format to use for new text based objects in the specified ``context``.
|
||||
|
||||
.. versionadded:: 3.20
|
||||
%End
|
||||
|
||||
static QgsTextFormat defaultTextFormatForProject( QgsProject *project, QgsStyle::TextFormatContext context = QgsStyle::TextFormatContext::Labeling );
|
||||
%Docstring
|
||||
Returns the default text format to use for new text based objects for the specified ``project``, in the specified ``context``.
|
||||
|
||||
.. versionadded:: 3.26
|
||||
%End
|
||||
|
||||
bool saveSymbol3D( const QString &name, QgsAbstract3DSymbol *symbol /Transfer/, bool favorite, const QStringList &tags );
|
||||
|
||||
@ -50,6 +50,7 @@ QgsPalLayerSettings QgsAbstractVectorLayerLabeling::defaultSettingsForLayer( con
|
||||
{
|
||||
QgsPalLayerSettings settings;
|
||||
settings.fieldName = layer->displayField();
|
||||
settings.setFormat( QgsStyle::defaultTextFormatForProject( layer->project() ) );
|
||||
|
||||
switch ( layer->geometryType() )
|
||||
{
|
||||
|
||||
@ -1211,13 +1211,21 @@ QList<QList<QPolygonF> > QgsStyle::defaultPatchAsQPolygonF( Qgis::SymbolType typ
|
||||
|
||||
QgsTextFormat QgsStyle::defaultTextFormat( QgsStyle::TextFormatContext ) const
|
||||
{
|
||||
QgsTextFormat defaultTextFormat = QgsProject::instance()->styleSettings()->defaultTextFormat();
|
||||
if ( defaultTextFormat.isValid() )
|
||||
return textFormat( QStringLiteral( "Default" ) );
|
||||
}
|
||||
|
||||
QgsTextFormat QgsStyle::defaultTextFormatForProject( QgsProject *project, TextFormatContext context )
|
||||
{
|
||||
if ( project )
|
||||
{
|
||||
return defaultTextFormat;
|
||||
QgsTextFormat defaultTextFormat = project->styleSettings()->defaultTextFormat();
|
||||
if ( defaultTextFormat.isValid() )
|
||||
{
|
||||
return defaultTextFormat;
|
||||
}
|
||||
}
|
||||
|
||||
return textFormat( QStringLiteral( "Default" ) );
|
||||
return QgsStyle::defaultStyle()->defaultTextFormat( context );
|
||||
}
|
||||
|
||||
bool QgsStyle::saveSymbol3D( const QString &name, QgsAbstract3DSymbol *symbol, bool favorite, const QStringList &tags )
|
||||
|
||||
@ -777,6 +777,13 @@ class CORE_EXPORT QgsStyle : public QObject
|
||||
*/
|
||||
QgsTextFormat defaultTextFormat( QgsStyle::TextFormatContext context = QgsStyle::TextFormatContext::Labeling ) const;
|
||||
|
||||
/**
|
||||
* Returns the default text format to use for new text based objects for the specified \a project, in the specified \a context.
|
||||
*
|
||||
* \since QGIS 3.26
|
||||
*/
|
||||
static QgsTextFormat defaultTextFormatForProject( QgsProject *project, QgsStyle::TextFormatContext context = QgsStyle::TextFormatContext::Labeling );
|
||||
|
||||
/**
|
||||
* Adds a 3d \a symbol to the database.
|
||||
*
|
||||
|
||||
@ -99,7 +99,7 @@ void QgsCreatePointTextItemMapTool::cadCanvasPressEvent( QgsMapMouseEvent *event
|
||||
|
||||
std::unique_ptr< QgsAnnotationPointTextItem > createdItem = std::make_unique< QgsAnnotationPointTextItem >( tr( "Text" ), layerPoint );
|
||||
createdItem->setAlignment( Qt::AlignLeft );
|
||||
createdItem->setFormat( QgsStyle::defaultStyle()->defaultTextFormat( QgsStyle::TextFormatContext::Labeling ) );
|
||||
createdItem->setFormat( QgsStyle::defaultTextFormatForProject( QgsProject::instance(), QgsStyle::TextFormatContext::Labeling ) );
|
||||
// newly created point text items default to using symbology reference scale at the current map scale
|
||||
createdItem->setUseSymbologyReferenceScale( true );
|
||||
createdItem->setSymbologyReferenceScale( canvas()->scale() );
|
||||
|
||||
@ -344,7 +344,7 @@ void QgsLabelingGui::setLayer( QgsMapLayer *mapLayer )
|
||||
mGeometryGeneratorGroupBox->setCollapsed( true );
|
||||
mGeometryGeneratorType->setCurrentIndex( mGeometryGeneratorType->findData( mSettings.geometryGeneratorType ) );
|
||||
|
||||
updateWidgetForFormat( mSettings.format().isValid() ? mSettings.format() : QgsStyle::defaultStyle()->defaultTextFormat( QgsStyle::TextFormatContext::Labeling ) );
|
||||
updateWidgetForFormat( mSettings.format().isValid() ? mSettings.format() : QgsStyle::defaultTextFormatForProject( QgsProject::instance(), QgsStyle::TextFormatContext::Labeling ) );
|
||||
|
||||
mFieldExpressionWidget->setRow( -1 );
|
||||
mFieldExpressionWidget->setField( mSettings.fieldName );
|
||||
|
||||
@ -53,7 +53,7 @@ QgsTextFormatWidget::QgsTextFormatWidget( const QgsTextFormat &format, QgsMapCan
|
||||
initWidget();
|
||||
setWidgetMode( Text );
|
||||
populateDataDefinedButtons();
|
||||
updateWidgetForFormat( format.isValid() ? format : QgsStyle::defaultStyle()->defaultTextFormat() );
|
||||
updateWidgetForFormat( format.isValid() ? format : QgsStyle::defaultTextFormatForProject( QgsProject::instance() ) );
|
||||
}
|
||||
|
||||
QgsTextFormatWidget::QgsTextFormatWidget( QgsMapCanvas *mapCanvas, QWidget *parent, Mode mode, QgsVectorLayer *layer )
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user