mirror of
https://github.com/qgis/QGIS.git
synced 2025-12-06 00:03:16 -05:00
Apply suggestions from code review
This commit is contained in:
parent
34fd68fd58
commit
2973735a6b
@ -145,9 +145,12 @@ Sets the background color for the text preview widget.
|
|||||||
:param color: background color
|
:param color: background color
|
||||||
%End
|
%End
|
||||||
|
|
||||||
void updateDataDefinedAlignment();
|
void enableDataDefinedAlignment( bool enable ) /Deprecated/;
|
||||||
%Docstring
|
%Docstring
|
||||||
Update the enabled state of the data defined alignment buttons.
|
Update the enabled state of the data defined alignment buttons.
|
||||||
|
|
||||||
|
.. deprecated::
|
||||||
|
QGIS 3.24
|
||||||
%End
|
%End
|
||||||
|
|
||||||
virtual QgsExpressionContext createExpressionContext() const;
|
virtual QgsExpressionContext createExpressionContext() const;
|
||||||
|
|||||||
@ -36,6 +36,7 @@
|
|||||||
#include "qgsstatusbar.h"
|
#include "qgsstatusbar.h"
|
||||||
#include "qgslabelingresults.h"
|
#include "qgslabelingresults.h"
|
||||||
#include "qgsexpressionnodeimpl.h"
|
#include "qgsexpressionnodeimpl.h"
|
||||||
|
#include "qgsreferencedgeometry.h"
|
||||||
|
|
||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
|
|
||||||
@ -632,50 +633,8 @@ QVariant QgsMapToolLabel::evaluateDataDefinedProperty( QgsPalLayerSettings::Prop
|
|||||||
|
|
||||||
bool QgsMapToolLabel::currentLabelDataDefinedPosition( double &x, bool &xSuccess, double &y, bool &ySuccess, int &xCol, int &yCol ) const
|
bool QgsMapToolLabel::currentLabelDataDefinedPosition( double &x, bool &xSuccess, double &y, bool &ySuccess, int &xCol, int &yCol ) const
|
||||||
{
|
{
|
||||||
QgsVectorLayer *vlayer = mCurrentLabel.layer;
|
int pointCol = -1;
|
||||||
QgsFeatureId featureId = mCurrentLabel.pos.featureId;
|
return currentLabelDataDefinedPosition( x, xSuccess, y, ySuccess, xCol, yCol, pointCol );
|
||||||
|
|
||||||
xSuccess = false;
|
|
||||||
ySuccess = false;
|
|
||||||
|
|
||||||
if ( !vlayer )
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( mCurrentLabel.pos.isDiagram )
|
|
||||||
{
|
|
||||||
if ( !diagramMoveable( vlayer, xCol, yCol ) )
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if ( !labelMoveable( vlayer, mCurrentLabel.settings, xCol, yCol ) )
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
QgsFeature f;
|
|
||||||
if ( !vlayer->getFeatures( QgsFeatureRequest().setFilterFid( featureId ).setFlags( QgsFeatureRequest::NoGeometry ) ).nextFeature( f ) )
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( mCurrentLabel.pos.isUnplaced )
|
|
||||||
{
|
|
||||||
xSuccess = false;
|
|
||||||
ySuccess = false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
QgsAttributes attributes = f.attributes();
|
|
||||||
if ( !attributes.at( xCol ).isNull() )
|
|
||||||
x = attributes.at( xCol ).toDouble( &xSuccess );
|
|
||||||
if ( !attributes.at( yCol ).isNull() )
|
|
||||||
y = attributes.at( yCol ).toDouble( &ySuccess );
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QgsMapToolLabel::currentLabelDataDefinedPosition( double &x, bool &xSuccess, double &y, bool &ySuccess, int &xCol, int &yCol, int &pointCol ) const
|
bool QgsMapToolLabel::currentLabelDataDefinedPosition( double &x, bool &xSuccess, double &y, bool &ySuccess, int &xCol, int &yCol, int &pointCol ) const
|
||||||
@ -715,30 +674,18 @@ bool QgsMapToolLabel::currentLabelDataDefinedPosition( double &x, bool &xSuccess
|
|||||||
|
|
||||||
if ( mCurrentLabel.settings.dataDefinedProperties().isActive( QgsPalLayerSettings::PositionPoint ) )
|
if ( mCurrentLabel.settings.dataDefinedProperties().isActive( QgsPalLayerSettings::PositionPoint ) )
|
||||||
{
|
{
|
||||||
if ( !attributes.at( pointCol ).isNull() )
|
if ( pointCol >= 0
|
||||||
|
&& !attributes.at( pointCol ).isNull() )
|
||||||
{
|
{
|
||||||
QVariant pointAsVariant = attributes.at( pointCol );
|
QVariant pointAsVariant = attributes.at( pointCol );
|
||||||
if ( pointAsVariant.canConvert<QgsGeometry>() )
|
if ( pointAsVariant.canConvert<QgsGeometry>() )
|
||||||
{
|
{
|
||||||
const QgsGeometry geometry = pointAsVariant.value<QgsGeometry>();
|
const QgsGeometry geometry = pointAsVariant.value<QgsGeometry>();
|
||||||
if ( const QgsPoint *point = ( geometry.constGet() ? qgsgeometry_cast<QgsPoint *>( geometry.constGet()->simplifiedTypeRef() ) : nullptr ) )
|
if ( const QgsPoint *point = ( geometry.constGet() ? qgsgeometry_cast<QgsPoint *>( geometry.constGet()->simplifiedTypeRef() ) : nullptr ) )
|
||||||
{
|
{
|
||||||
x = point->x();
|
x = point->x();
|
||||||
y = point->y();
|
y = point->y();
|
||||||
|
|
||||||
xSuccess = true;
|
|
||||||
ySuccess = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if ( !pointAsVariant.toByteArray().isEmpty() )
|
|
||||||
{
|
|
||||||
QgsPoint point;
|
|
||||||
QgsConstWkbPtr wkbPtr( pointAsVariant.toByteArray() );
|
|
||||||
if ( point.fromWkb( wkbPtr ) )
|
|
||||||
{
|
|
||||||
x = point.x();
|
|
||||||
y = point.y();
|
|
||||||
|
|
||||||
xSuccess = true;
|
xSuccess = true;
|
||||||
ySuccess = true;
|
ySuccess = true;
|
||||||
}
|
}
|
||||||
@ -809,7 +756,7 @@ bool QgsMapToolLabel::changeCurrentLabelDataDefinedPosition( const QVariant &x,
|
|||||||
QString pointColName = dataDefinedColumnName( QgsPalLayerSettings::PositionPoint, mCurrentLabel.settings, mCurrentLabel.layer );
|
QString pointColName = dataDefinedColumnName( QgsPalLayerSettings::PositionPoint, mCurrentLabel.settings, mCurrentLabel.layer );
|
||||||
int pointCol = mCurrentLabel.layer->fields().lookupField( pointColName );
|
int pointCol = mCurrentLabel.layer->fields().lookupField( pointColName );
|
||||||
|
|
||||||
if ( !mCurrentLabel.layer->changeAttributeValue( mCurrentLabel.pos.featureId, pointCol, QgsPoint( x.toDouble(), y.toDouble() ).asWkt() ) )
|
if ( !mCurrentLabel.layer->changeAttributeValue( mCurrentLabel.pos.featureId, pointCol, QVariant::fromValue( QgsReferencedGeometry( QgsGeometry::fromPointXY( QgsPoint( x.toDouble(), y.toDouble() ) ), mCurrentLabel.layer->crs() ) ) ) )
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -905,12 +852,8 @@ bool QgsMapToolLabel::labelMoveable( QgsVectorLayer *vlayer, int &xCol, int &yCo
|
|||||||
|
|
||||||
bool QgsMapToolLabel::labelMoveable( QgsVectorLayer *vlayer, const QgsPalLayerSettings &settings, int &xCol, int &yCol ) const
|
bool QgsMapToolLabel::labelMoveable( QgsVectorLayer *vlayer, const QgsPalLayerSettings &settings, int &xCol, int &yCol ) const
|
||||||
{
|
{
|
||||||
QString xColName = dataDefinedColumnName( QgsPalLayerSettings::PositionX, settings, vlayer );
|
int pointCol = -1;
|
||||||
QString yColName = dataDefinedColumnName( QgsPalLayerSettings::PositionY, settings, vlayer );
|
return labelMoveable( vlayer, settings, xCol, yCol, pointCol );
|
||||||
//return !xColName.isEmpty() && !yColName.isEmpty();
|
|
||||||
xCol = vlayer->fields().lookupField( xColName );
|
|
||||||
yCol = vlayer->fields().lookupField( yColName );
|
|
||||||
return ( xCol != -1 && yCol != -1 );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QgsMapToolLabel::layerCanPin( QgsVectorLayer *vlayer, int &xCol, int &yCol ) const
|
bool QgsMapToolLabel::layerCanPin( QgsVectorLayer *vlayer, int &xCol, int &yCol ) const
|
||||||
@ -1071,7 +1014,7 @@ bool QgsMapToolLabel::createAuxiliaryFields( LabelDetails &details, QgsPalIndexe
|
|||||||
{
|
{
|
||||||
index = vlayer->fields().lookupField( prop.field() );
|
index = vlayer->fields().lookupField( prop.field() );
|
||||||
}
|
}
|
||||||
else if ( prop.propertyType() != QgsProperty::ExpressionBasedProperty )
|
else
|
||||||
{
|
{
|
||||||
index = QgsAuxiliaryLayer::createProperty( p, vlayer, false );
|
index = QgsAuxiliaryLayer::createProperty( p, vlayer, false );
|
||||||
changed = true;
|
changed = true;
|
||||||
|
|||||||
@ -83,12 +83,6 @@ class APP_EXPORT QgsMapToolLabel: public QgsMapToolAdvancedDigitizing
|
|||||||
*/
|
*/
|
||||||
bool labelCanShowHide( QgsVectorLayer *vlayer, int &showCol ) const;
|
bool labelCanShowHide( QgsVectorLayer *vlayer, int &showCol ) const;
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if labels in a layer can be rotated
|
|
||||||
* \param rotationCol out: attribute column for data defined label rotation
|
|
||||||
*/
|
|
||||||
bool layerIsRotatable( QgsVectorLayer *vlayer, int &rotationCol ) const;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if labels in a layer can be rotated
|
* Checks if labels in a layer can be rotated
|
||||||
* \param rotationCol out: attribute column for data defined label rotation
|
* \param rotationCol out: attribute column for data defined label rotation
|
||||||
|
|||||||
@ -187,48 +187,30 @@ void QgsMapToolMoveLabel::cadCanvasPressEvent( QgsMapMouseEvent *e )
|
|||||||
if ( !mCurrentLabel.pos.isDiagram && !labelMoveable( vlayer, mCurrentLabel.settings, xCol, yCol, pointCol ) )
|
if ( !mCurrentLabel.pos.isDiagram && !labelMoveable( vlayer, mCurrentLabel.settings, xCol, yCol, pointCol ) )
|
||||||
{
|
{
|
||||||
if ( mCurrentLabel.settings.dataDefinedProperties().isActive( QgsPalLayerSettings::PositionPoint ) )
|
if ( mCurrentLabel.settings.dataDefinedProperties().isActive( QgsPalLayerSettings::PositionPoint ) )
|
||||||
|
mCurrentLabel.settings.dataDefinedProperties().property( QgsPalLayerSettings::PositionPoint ).setActive( false );
|
||||||
|
|
||||||
|
mPalProperties.clear();
|
||||||
|
mPalProperties << QgsPalLayerSettings::PositionX;
|
||||||
|
mPalProperties << QgsPalLayerSettings::PositionY;
|
||||||
|
QgsPalIndexes indexes;
|
||||||
|
if ( createAuxiliaryFields( indexes ) )
|
||||||
|
return;
|
||||||
|
|
||||||
|
if ( !labelMoveable( vlayer, mCurrentLabel.settings, xCol, yCol ) )
|
||||||
{
|
{
|
||||||
mPalProperties.clear();
|
QString xColName = dataDefinedColumnName( QgsPalLayerSettings::PositionX, mCurrentLabel.settings, vlayer );
|
||||||
mPalProperties << QgsPalLayerSettings::PositionPoint;
|
QString yColName = dataDefinedColumnName( QgsPalLayerSettings::PositionY, mCurrentLabel.settings, vlayer );
|
||||||
QgsPalIndexes indexes;
|
if ( xCol < 0 && yCol < 0 )
|
||||||
if ( createAuxiliaryFields( indexes ) )
|
QgisApp::instance()->messageBar()->pushWarning( tr( "Move Label" ), tr( "The label X/Y columns “%1” and “%2” do not exist in the layer" ).arg( xColName, yColName ) );
|
||||||
return;
|
else if ( xCol < 0 )
|
||||||
|
QgisApp::instance()->messageBar()->pushWarning( tr( "Move Label" ), tr( "The label X column “%1” does not exist in the layer" ).arg( xColName ) );
|
||||||
if ( !labelMoveable( vlayer, mCurrentLabel.settings, xCol, yCol, pointCol ) )
|
else if ( yCol < 0 )
|
||||||
{
|
QgisApp::instance()->messageBar()->pushWarning( tr( "Move Label" ), tr( "The label Y column “%1” does not exist in the layer" ).arg( yColName ) );
|
||||||
QString pointColName = dataDefinedColumnName( QgsPalLayerSettings::PositionPoint, mCurrentLabel.settings, vlayer );
|
return;
|
||||||
if ( pointCol < 0 )
|
|
||||||
QgisApp::instance()->messageBar()->pushWarning( tr( "Move Label" ), tr( "The label Point column “%1” does not exist in the layer" ).arg( pointColName ) );
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
pointCol = indexes[ QgsPalLayerSettings::PositionPoint ];
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
mPalProperties.clear();
|
|
||||||
mPalProperties << QgsPalLayerSettings::PositionX;
|
|
||||||
mPalProperties << QgsPalLayerSettings::PositionY;
|
|
||||||
QgsPalIndexes indexes;
|
|
||||||
if ( createAuxiliaryFields( indexes ) )
|
|
||||||
return;
|
|
||||||
|
|
||||||
if ( !labelMoveable( vlayer, mCurrentLabel.settings, xCol, yCol ) )
|
xCol = indexes[ QgsPalLayerSettings::PositionX ];
|
||||||
{
|
yCol = indexes[ QgsPalLayerSettings::PositionY ];
|
||||||
QString xColName = dataDefinedColumnName( QgsPalLayerSettings::PositionX, mCurrentLabel.settings, vlayer );
|
|
||||||
QString yColName = dataDefinedColumnName( QgsPalLayerSettings::PositionY, mCurrentLabel.settings, vlayer );
|
|
||||||
if ( xCol < 0 && yCol < 0 )
|
|
||||||
QgisApp::instance()->messageBar()->pushWarning( tr( "Move Label" ), tr( "The label X/Y columns “%1” and “%2” do not exist in the layer" ).arg( xColName, yColName ) );
|
|
||||||
else if ( xCol < 0 )
|
|
||||||
QgisApp::instance()->messageBar()->pushWarning( tr( "Move Label" ), tr( "The label X column “%1” does not exist in the layer" ).arg( xColName ) );
|
|
||||||
else if ( yCol < 0 )
|
|
||||||
QgisApp::instance()->messageBar()->pushWarning( tr( "Move Label" ), tr( "The label Y column “%1” does not exist in the layer" ).arg( yColName ) );
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
xCol = indexes[ QgsPalLayerSettings::PositionX ];
|
|
||||||
yCol = indexes[ QgsPalLayerSettings::PositionY ];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if ( mCurrentLabel.pos.isDiagram && !diagramMoveable( vlayer, xCol, yCol ) )
|
else if ( mCurrentLabel.pos.isDiagram && !diagramMoveable( vlayer, xCol, yCol ) )
|
||||||
{
|
{
|
||||||
@ -244,8 +226,11 @@ void QgsMapToolMoveLabel::cadCanvasPressEvent( QgsMapMouseEvent *e )
|
|||||||
yCol = indexes[ QgsDiagramLayerSettings::PositionY ];
|
yCol = indexes[ QgsDiagramLayerSettings::PositionY ];
|
||||||
}
|
}
|
||||||
|
|
||||||
bool usesAuxFields = vlayer->fields().fieldOrigin( xCol ) == QgsFields::OriginJoin
|
bool usesAuxFields = false;
|
||||||
&& vlayer->fields().fieldOrigin( yCol ) == QgsFields::OriginJoin;
|
if ( xCol >= 0 && yCol >= 0 )
|
||||||
|
usesAuxFields = vlayer->fields().fieldOrigin( xCol ) == QgsFields::OriginJoin
|
||||||
|
&& vlayer->fields().fieldOrigin( yCol ) == QgsFields::OriginJoin;
|
||||||
|
|
||||||
if ( mCurrentLabel.settings.dataDefinedProperties().isActive( QgsPalLayerSettings::PositionPoint )
|
if ( mCurrentLabel.settings.dataDefinedProperties().isActive( QgsPalLayerSettings::PositionPoint )
|
||||||
&& !mCurrentLabel.pos.isDiagram )
|
&& !mCurrentLabel.pos.isDiagram )
|
||||||
usesAuxFields = vlayer->fields().fieldOrigin( pointCol ) == QgsFields::OriginJoin;
|
usesAuxFields = vlayer->fields().fieldOrigin( pointCol ) == QgsFields::OriginJoin;
|
||||||
|
|||||||
@ -2383,47 +2383,53 @@ std::unique_ptr<QgsLabelFeature> QgsPalLayerSettings::registerFeatureWithDetails
|
|||||||
bool ddPosition = false;
|
bool ddPosition = false;
|
||||||
|
|
||||||
if ( mDataDefinedProperties.isActive( QgsPalLayerSettings::PositionX )
|
if ( mDataDefinedProperties.isActive( QgsPalLayerSettings::PositionX )
|
||||||
&& mDataDefinedProperties.isActive( QgsPalLayerSettings::PositionY )
|
&& mDataDefinedProperties.isActive( QgsPalLayerSettings::PositionY ) )
|
||||||
&& !mDataDefinedProperties.value( QgsPalLayerSettings::PositionX, context.expressionContext() ).isNull()
|
|
||||||
&& !mDataDefinedProperties.value( QgsPalLayerSettings::PositionY, context.expressionContext() ).isNull() )
|
|
||||||
{
|
{
|
||||||
ddPosition = true;
|
const QVariant xPosProperty = mDataDefinedProperties.value( QgsPalLayerSettings::PositionX, context.expressionContext() );
|
||||||
|
const QVariant yPosProperty = mDataDefinedProperties.value( QgsPalLayerSettings::PositionY, context.expressionContext() );
|
||||||
bool ddXPos = false, ddYPos = false;
|
if ( !xPosProperty.isNull()
|
||||||
xPos = mDataDefinedProperties.value( QgsPalLayerSettings::PositionX, context.expressionContext() ).toDouble( &ddXPos );
|
&& !yPosProperty.isNull() )
|
||||||
yPos = mDataDefinedProperties.value( QgsPalLayerSettings::PositionY, context.expressionContext() ).toDouble( &ddYPos );
|
|
||||||
if ( ddXPos && ddYPos )
|
|
||||||
hasDataDefinedPosition = true;
|
|
||||||
}
|
|
||||||
else if ( mDataDefinedProperties.isActive( QgsPalLayerSettings::PositionPoint )
|
|
||||||
&& !mDataDefinedProperties.value( QgsPalLayerSettings::PositionPoint, context.expressionContext() ).isNull() )
|
|
||||||
{
|
|
||||||
ddPosition = true;
|
|
||||||
|
|
||||||
QVariant pointAsVariant = mDataDefinedProperties.value( QgsPalLayerSettings::PositionPoint, context.expressionContext() );
|
|
||||||
QgsPoint point;
|
|
||||||
if ( pointAsVariant.canConvert<QgsReferencedGeometry>() )
|
|
||||||
{
|
{
|
||||||
point = QgsPoint( pointAsVariant.value<QgsReferencedGeometry>().asPoint() );
|
ddPosition = true;
|
||||||
}
|
|
||||||
else if ( pointAsVariant.canConvert<QgsGeometry>() )
|
|
||||||
{
|
|
||||||
point = QgsPoint( pointAsVariant.value<QgsGeometry>().asPoint() );
|
|
||||||
}
|
|
||||||
else if ( !pointAsVariant.toString().isEmpty() )
|
|
||||||
{
|
|
||||||
point.fromWkt( pointAsVariant.toString() );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( !point.isEmpty() )
|
bool ddXPos = false, ddYPos = false;
|
||||||
{
|
xPos = xPosProperty.toDouble( &ddXPos );
|
||||||
hasDataDefinedPosition = true;
|
yPos = yPosProperty.toDouble( &ddYPos );
|
||||||
|
if ( ddXPos && ddYPos )
|
||||||
xPos = point.x();
|
hasDataDefinedPosition = true;
|
||||||
yPos = point.y();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if ( mDataDefinedProperties.isActive( QgsPalLayerSettings::PositionPoint ) )
|
||||||
|
{
|
||||||
|
const QVariant pointPosProperty = mDataDefinedProperties.value( QgsPalLayerSettings::PositionPoint, context.expressionContext() );
|
||||||
|
if ( !pointPosProperty.isNull() )
|
||||||
|
{
|
||||||
|
ddPosition = true;
|
||||||
|
|
||||||
|
QgsPoint point;
|
||||||
|
if ( pointPosProperty.canConvert<QgsReferencedGeometry>() )
|
||||||
|
{
|
||||||
|
QgsReferencedGeometry referencedGeometryPoint = pointPosProperty.value<QgsReferencedGeometry>();
|
||||||
|
point = QgsPoint( referencedGeometryPoint.asPoint() );
|
||||||
|
|
||||||
|
if ( !referencedGeometryPoint.isNull()
|
||||||
|
&& ct.sourceCrs() != referencedGeometryPoint.crs() )
|
||||||
|
QgsMessageLog::logMessage( QObject::tr( "Label position geometry is not in layer coordinates reference system. Layer CRS: '%1', Geometry CRS: '%2'" ).arg( ct.sourceCrs().userFriendlyIdentifier(), referencedGeometryPoint.crs().userFriendlyIdentifier() ), QObject::tr( "Labeling" ), Qgis::Warning );
|
||||||
|
}
|
||||||
|
else if ( pointPosProperty.canConvert<QgsGeometry>() )
|
||||||
|
{
|
||||||
|
point = QgsPoint( pointPosProperty.value<QgsGeometry>().asPoint() );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !point.isEmpty() )
|
||||||
|
{
|
||||||
|
hasDataDefinedPosition = true;
|
||||||
|
|
||||||
|
xPos = point.x();
|
||||||
|
yPos = point.y();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ( ddPosition )
|
if ( ddPosition )
|
||||||
{
|
{
|
||||||
@ -2525,12 +2531,6 @@ std::unique_ptr<QgsLabelFeature> QgsPalLayerSettings::registerFeatureWithDetails
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
anchorPosition = QgsPointXY( xPos, yPos );
|
anchorPosition = QgsPointXY( xPos, yPos );
|
||||||
|
|
||||||
// only rotate non-pinned OverPoint placements until other placements are supported in pal::Feature
|
|
||||||
if ( dataDefinedRotation && placement != QgsPalLayerSettings::OverPoint )
|
|
||||||
{
|
|
||||||
angle = 0.0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -482,8 +482,6 @@ void QgsLabelingGui::setLayer( QgsMapLayer *mapLayer )
|
|||||||
// do this after other widgets are configured, so they can be enabled/disabled
|
// do this after other widgets are configured, so they can be enabled/disabled
|
||||||
populateDataDefinedButtons();
|
populateDataDefinedButtons();
|
||||||
|
|
||||||
updateDataDefinedAlignment();
|
|
||||||
|
|
||||||
updateUi(); // should come after data defined button setup
|
updateUi(); // should come after data defined button setup
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -685,9 +685,12 @@ void QgsPropertyOverrideButton::showExpressionDialog()
|
|||||||
if ( d.exec() == QDialog::Accepted )
|
if ( d.exec() == QDialog::Accepted )
|
||||||
{
|
{
|
||||||
mExpressionString = d.expressionText().trimmed();
|
mExpressionString = d.expressionText().trimmed();
|
||||||
|
bool active = mProperty.isActive();
|
||||||
mProperty.setExpressionString( mExpressionString );
|
mProperty.setExpressionString( mExpressionString );
|
||||||
mProperty.setTransformer( nullptr );
|
mProperty.setTransformer( nullptr );
|
||||||
setActivePrivate( !mExpressionString.isEmpty() );
|
mProperty.setActive( !mExpressionString.isEmpty() );
|
||||||
|
if ( mProperty.isActive() != active )
|
||||||
|
emit activated( mProperty.isActive() );
|
||||||
updateSiblingWidgets( isActive() );
|
updateSiblingWidgets( isActive() );
|
||||||
updateGui();
|
updateGui();
|
||||||
emit changed();
|
emit changed();
|
||||||
|
|||||||
@ -813,6 +813,8 @@ void QgsTextFormatWidget::populateDataDefinedButtons()
|
|||||||
registerDataDefinedButton( mCoordAlignmentVDDBtn, QgsPalLayerSettings::Vali );
|
registerDataDefinedButton( mCoordAlignmentVDDBtn, QgsPalLayerSettings::Vali );
|
||||||
registerDataDefinedButton( mCoordRotationDDBtn, QgsPalLayerSettings::LabelRotation );
|
registerDataDefinedButton( mCoordRotationDDBtn, QgsPalLayerSettings::LabelRotation );
|
||||||
|
|
||||||
|
updateDataDefinedAlignment();
|
||||||
|
|
||||||
// rendering
|
// rendering
|
||||||
const QString ddScaleVisInfo = tr( "Value < 0 represents a scale closer than 1:1, e.g. -10 = 10:1<br>"
|
const QString ddScaleVisInfo = tr( "Value < 0 represents a scale closer than 1:1, e.g. -10 = 10:1<br>"
|
||||||
"Value of 0 disables the specific limit." );
|
"Value of 0 disables the specific limit." );
|
||||||
@ -1862,6 +1864,13 @@ void QgsTextFormatWidget::updateCalloutFrameStatus()
|
|||||||
mCalloutFrame->setEnabled( mCalloutDrawDDBtn->isActive() || mCalloutsDrawCheckBox->isChecked() );
|
mCalloutFrame->setEnabled( mCalloutDrawDDBtn->isActive() || mCalloutsDrawCheckBox->isChecked() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QgsTextFormatWidget::updateDataDefinedAlignment()
|
||||||
|
{
|
||||||
|
// no data defined alignment without data defined position
|
||||||
|
mCoordAlignmentFrame->setEnabled( ( mCoordXDDBtn->isActive() && mCoordYDDBtn->isActive() )
|
||||||
|
|| mCoordPointDDBtn->isActive() );
|
||||||
|
}
|
||||||
|
|
||||||
void QgsTextFormatWidget::setFormatFromStyle( const QString &name, QgsStyle::StyleEntity type )
|
void QgsTextFormatWidget::setFormatFromStyle( const QString &name, QgsStyle::StyleEntity type )
|
||||||
{
|
{
|
||||||
switch ( type )
|
switch ( type )
|
||||||
@ -2056,13 +2065,6 @@ void QgsTextFormatWidget::showBackgroundRadius( bool show )
|
|||||||
mShapeRadiusUnitsDDBtn->setVisible( show );
|
mShapeRadiusUnitsDDBtn->setVisible( show );
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsTextFormatWidget::updateDataDefinedAlignment()
|
|
||||||
{
|
|
||||||
// no data defined alignment without data defined position
|
|
||||||
mCoordAlignmentFrame->setEnabled( ( mCoordXDDBtn->isActive() && mCoordYDDBtn->isActive() )
|
|
||||||
|| mCoordPointDDBtn->isActive() );
|
|
||||||
}
|
|
||||||
|
|
||||||
QgsExpressionContext QgsTextFormatWidget::createExpressionContext() const
|
QgsExpressionContext QgsTextFormatWidget::createExpressionContext() const
|
||||||
{
|
{
|
||||||
if ( auto *lExpressionContext = mContext.expressionContext() )
|
if ( auto *lExpressionContext = mContext.expressionContext() )
|
||||||
|
|||||||
@ -155,8 +155,10 @@ class GUI_EXPORT QgsTextFormatWidget : public QWidget, public QgsExpressionConte
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the enabled state of the data defined alignment buttons.
|
* Update the enabled state of the data defined alignment buttons.
|
||||||
|
*
|
||||||
|
* \deprecated QGIS 3.24
|
||||||
*/
|
*/
|
||||||
void updateDataDefinedAlignment();
|
Q_DECL_DEPRECATED void enableDataDefinedAlignment( bool enable ) SIP_DEPRECATED { Q_UNUSED( enable ) }
|
||||||
|
|
||||||
QgsExpressionContext createExpressionContext() const override;
|
QgsExpressionContext createExpressionContext() const override;
|
||||||
|
|
||||||
@ -311,6 +313,7 @@ class GUI_EXPORT QgsTextFormatWidget : public QWidget, public QgsExpressionConte
|
|||||||
void updateBufferFrameStatus();
|
void updateBufferFrameStatus();
|
||||||
void updateShadowFrameStatus();
|
void updateShadowFrameStatus();
|
||||||
void updateCalloutFrameStatus();
|
void updateCalloutFrameStatus();
|
||||||
|
void updateDataDefinedAlignment();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -5424,12 +5424,92 @@ font-style: italic;</string>
|
|||||||
<property name="rightMargin">
|
<property name="rightMargin">
|
||||||
<number>8</number>
|
<number>8</number>
|
||||||
</property>
|
</property>
|
||||||
<item row="1" column="0">
|
<item row="3" column="1">
|
||||||
<widget class="QLabel" name="mCoordAlignmentLabel">
|
<layout class="QHBoxLayout" name="horizontalLayout_25">
|
||||||
<property name="text">
|
<item>
|
||||||
<string>Alignment</string>
|
<widget class="QgsPropertyOverrideButton" name="mCoordRotationDDBtn">
|
||||||
</property>
|
<property name="text">
|
||||||
</widget>
|
<string>…</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QComboBox" name="mCoordRotationUnitComboBox"/>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QCheckBox" name="chkPreserveRotation">
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>Uncheck to write labeling engine derived rotation on pin and NULL on unpin</string>
|
||||||
|
</property>
|
||||||
|
<property name="styleSheet">
|
||||||
|
<string notr="true">margin-left: 12px; margin-top: 3px;</string>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Preserve data rotation values</string>
|
||||||
|
</property>
|
||||||
|
<property name="checked">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="1">
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_22">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="mCoordXLabel">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>X</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QgsPropertyOverrideButton" name="mCoordXDDBtn">
|
||||||
|
<property name="text">
|
||||||
|
<string>…</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="mCoordYLabel">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Y</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QgsPropertyOverrideButton" name="mCoordYDDBtn">
|
||||||
|
<property name="text">
|
||||||
|
<string>…</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="horizontalSpacer_6">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="0">
|
<item row="0" column="0">
|
||||||
<widget class="QLabel" name="mCoordLabel">
|
<widget class="QLabel" name="mCoordLabel">
|
||||||
@ -5438,14 +5518,7 @@ font-style: italic;</string>
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="0">
|
<item row="2" column="1">
|
||||||
<widget class="QLabel" name="mCoordRotationLabel">
|
|
||||||
<property name="text">
|
|
||||||
<string>Rotation</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="1">
|
|
||||||
<widget class="QFrame" name="mCoordAlignmentFrame">
|
<widget class="QFrame" name="mCoordAlignmentFrame">
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_27">
|
<layout class="QHBoxLayout" name="horizontalLayout_27">
|
||||||
<property name="leftMargin">
|
<property name="leftMargin">
|
||||||
@ -5516,68 +5589,15 @@ font-style: italic;</string>
|
|||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="1">
|
<item row="3" column="0">
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_22">
|
<widget class="QLabel" name="mCoordRotationLabel">
|
||||||
<item>
|
<property name="text">
|
||||||
<widget class="QLabel" name="mCoordXLabel">
|
<string>Rotation</string>
|
||||||
<property name="sizePolicy">
|
</property>
|
||||||
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
|
</widget>
|
||||||
<horstretch>0</horstretch>
|
</item>
|
||||||
<verstretch>0</verstretch>
|
<item row="1" column="1">
|
||||||
</sizepolicy>
|
<layout class="QHBoxLayout" name="horizontalLayout_15">
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string>X</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="QgsPropertyOverrideButton" name="mCoordXDDBtn">
|
|
||||||
<property name="text">
|
|
||||||
<string>…</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="QLabel" name="mCoordYLabel">
|
|
||||||
<property name="sizePolicy">
|
|
||||||
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
|
|
||||||
<horstretch>0</horstretch>
|
|
||||||
<verstretch>0</verstretch>
|
|
||||||
</sizepolicy>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string>Y</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="QgsPropertyOverrideButton" name="mCoordYDDBtn">
|
|
||||||
<property name="text">
|
|
||||||
<string>…</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<spacer name="horizontalSpacer_6">
|
|
||||||
<property name="orientation">
|
|
||||||
<enum>Qt::Horizontal</enum>
|
|
||||||
</property>
|
|
||||||
<property name="sizeHint" stdset="0">
|
|
||||||
<size>
|
|
||||||
<width>40</width>
|
|
||||||
<height>20</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
</spacer>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="QLabel" name="label_44">
|
|
||||||
<property name="text">
|
|
||||||
<string>Point</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
<item>
|
||||||
<widget class="QgsPropertyOverrideButton" name="mCoordPointDDBtn">
|
<widget class="QgsPropertyOverrideButton" name="mCoordPointDDBtn">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@ -5600,35 +5620,19 @@ font-style: italic;</string>
|
|||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="1">
|
<item row="2" column="0">
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_25">
|
<widget class="QLabel" name="mCoordAlignmentLabel">
|
||||||
<item>
|
<property name="text">
|
||||||
<widget class="QgsPropertyOverrideButton" name="mCoordRotationDDBtn">
|
<string>Alignment</string>
|
||||||
<property name="text">
|
</property>
|
||||||
<string>…</string>
|
</widget>
|
||||||
</property>
|
</item>
|
||||||
</widget>
|
<item row="1" column="0">
|
||||||
</item>
|
<widget class="QLabel" name="label_44">
|
||||||
<item>
|
<property name="text">
|
||||||
<widget class="QComboBox" name="mCoordRotationUnitComboBox"/>
|
<string>Point</string>
|
||||||
</item>
|
</property>
|
||||||
<item>
|
</widget>
|
||||||
<widget class="QCheckBox" name="chkPreserveRotation">
|
|
||||||
<property name="toolTip">
|
|
||||||
<string>Uncheck to write labeling engine derived rotation on pin and NULL on unpin</string>
|
|
||||||
</property>
|
|
||||||
<property name="styleSheet">
|
|
||||||
<string notr="true">margin-left: 12px; margin-top: 3px;</string>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string>Preserve data rotation values</string>
|
|
||||||
</property>
|
|
||||||
<property name="checked">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user