[layout] rotated grid ticks/annotations (rebased)

This commit is contained in:
olivierdalang 2020-07-27 18:15:12 +02:00 committed by Matthias Kuhn
parent e19f27d289
commit 90cc33b3a8
9 changed files with 1329 additions and 922 deletions

View File

@ -172,7 +172,10 @@ An individual grid which is drawn above the map content in a
Horizontal,
Vertical,
VerticalDescending,
BoundaryDirection
BoundaryDirection,
AboveTick,
OnTick,
UnderTick,
};
enum AnnotationFormat
@ -193,7 +196,7 @@ An individual grid which is drawn above the map content in a
Left,
Right,
Bottom,
Top
Top,
};
enum FrameStyle
@ -208,6 +211,12 @@ An individual grid which is drawn above the map content in a
ZebraNautical,
};
enum TickLengthMode
{
OrthogonalTicks,
NormalizedTicks,
};
enum FrameSideFlag
{
FrameLeft,
@ -586,6 +595,7 @@ Returns the text format used when rendering grid annotations.
void setAnnotationFont( const QFont &font ) /Deprecated/;
%Docstring
Sets the ``font`` used for drawing grid annotations.
Shortcut for :py:func:`~QgsLayoutItemMapGrid.annotationTextFormat`.setFont().
.. seealso:: :py:func:`annotationFont`
@ -596,6 +606,7 @@ Sets the ``font`` used for drawing grid annotations.
QFont annotationFont() const /Deprecated/;
%Docstring
Returns the font used for drawing grid annotations.
Shortcut for :py:func:`~QgsLayoutItemMapGrid.annotationTextFormat`.font().
.. seealso:: :py:func:`setAnnotationFont`
@ -606,6 +617,7 @@ Returns the font used for drawing grid annotations.
void setAnnotationFontColor( const QColor &color ) /Deprecated/;
%Docstring
Sets the font ``color`` used for drawing grid annotations.
Shortcut for :py:func:`~QgsLayoutItemMapGrid.annotationTextFormat`.setColor() and :py:func:`~QgsLayoutItemMapGrid.annotationTextFormat`.setOpacity().
.. seealso:: :py:func:`annotationFontColor`
@ -616,6 +628,7 @@ Sets the font ``color`` used for drawing grid annotations.
QColor annotationFontColor() const /Deprecated/;
%Docstring
Returns the font color used for drawing grid annotations.
Shortcut for :py:func:`~QgsLayoutItemMapGrid.annotationTextFormat`.color() and :py:func:`~QgsLayoutItemMapGrid.annotationTextFormat`.opacity().
.. seealso:: :py:func:`setAnnotationFontColor`
@ -844,6 +857,90 @@ The size of the line outlines drawn in the frame can be retrieved via the
framePenSize method.
.. seealso:: :py:func:`setFrameWidth`
%End
void setRotatedTicksEnabled( const bool state );
%Docstring
Enable/disable ticks rotation for rotated or reprojected grids.
.. seealso:: :py:func:`rotatedTicksEnabled`
%End
double rotatedTicksEnabled() const;
%Docstring
Gets whether ticks rotation for rotated or reprojected grids is enabled.
.. seealso:: :py:func:`setRotatedTicksEnabled`
%End
void setRotatedTicksLengthMode( const TickLengthMode mode );
%Docstring
Sets the tick length calculation mode.
.. seealso:: :py:func:`rotatedTicksLengthMode`
%End
TickLengthMode rotatedTicksLengthMode() const;
%Docstring
Returns the grid frame style.
.. seealso:: :py:func:`setRotatedTicksLengthMode`
%End
void setRotatedTicksMinimumAngle( const double angle );
%Docstring
Sets the ``minimum`` angle (in degrees) below which ticks are not drawn.
.. seealso:: :py:func:`rotatedTicksMinimumAngle`
%End
double rotatedTicksMinimumAngle() const;
%Docstring
Gets the ``minimum`` angle (in degrees) below which ticks are not drawn.
.. seealso:: :py:func:`setRotatedTicksMinimumAngle`
%End
void setRotatedAnnotationsEnabled( const bool state );
%Docstring
Enable/disable annotations rotation for rotated or reprojected grids.
.. seealso:: :py:func:`rotatedAnnotationsEnabled`
%End
double rotatedAnnotationsEnabled() const;
%Docstring
Gets whether annotations rotation for rotated or reprojected grids is enabled.
.. seealso:: :py:func:`setRotatedAnnotationsEnabled`
%End
void setRotatedAnnotationsLengthMode( const TickLengthMode mode );
%Docstring
Sets the annotation length calculation mode.
.. seealso:: :py:func:`rotatedAnnotationsLengthMode`
%End
TickLengthMode rotatedAnnotationsLengthMode() const;
%Docstring
Returns the grid frame style.
.. seealso:: :py:func:`setRotatedAnnotationsLengthMode`
%End
void setRotatedAnnotationsMinimumAngle( const double angle );
%Docstring
Sets the ``minimum`` angle (in degrees) below which annotated are not drawn.
.. seealso:: :py:func:`rotatedAnnotationsMinimumAngle`
%End
double rotatedAnnotationsMinimumAngle() const;
%Docstring
Gets the ``minimum`` angle (in degrees) below which annotated are not drawn.
.. seealso:: :py:func:`setRotatedAnnotationsMinimumAngle`
%End
void setFrameMargin( const double margin );
@ -961,7 +1058,6 @@ Retrieves the second fill color for the grid frame.
virtual void refresh();
public:
};
QFlags<QgsLayoutItemMapGrid::FrameSideFlag> operator|(QgsLayoutItemMapGrid::FrameSideFlag f1, QFlags<QgsLayoutItemMapGrid::FrameSideFlag> f2);

File diff suppressed because it is too large Load Diff

View File

@ -24,6 +24,7 @@
#include "qgssymbol.h"
#include "qgstextformat.h"
#include <QPainter>
#include <QVector2D>
class QgsCoordinateTransform;
class QgsLayoutItemMapGrid;
@ -193,7 +194,10 @@ class CORE_EXPORT QgsLayoutItemMapGrid : public QgsLayoutItemMapItem
Horizontal = 0, //!< Draw annotations horizontally
Vertical, //!< Draw annotations vertically, ascending
VerticalDescending, //!< Draw annotations vertically, descending
BoundaryDirection //!< Annotations follow the boundary direction
BoundaryDirection, //!< Annotations follow the boundary direction
AboveTick, //!< Draw annotations parallel to tick (above the line)
OnTick, //!< Draw annotations parallel to tick (on the line)
UnderTick, //!< Draw annotations parallel to tick (under the line)
};
/**
@ -220,7 +224,7 @@ class CORE_EXPORT QgsLayoutItemMapGrid : public QgsLayoutItemMapItem
Left, //!< Left border
Right, //!< Right border
Bottom, //!< Bottom border
Top //!< Top border
Top, //!< Top border
};
/**
@ -238,6 +242,15 @@ class CORE_EXPORT QgsLayoutItemMapGrid : public QgsLayoutItemMapItem
ZebraNautical, //!< Black/white pattern, with nautical style diagonals on corners
};
/**
* Tick length mode (useful for rotated grids)
*/
enum TickLengthMode
{
OrthogonalTicks = 0, //!< Align ticks orthogonaly
NormalizedTicks, //!< Constant tick lengths
};
/**
* Flags for controlling which side of the map a frame is drawn on
*/
@ -580,6 +593,7 @@ class CORE_EXPORT QgsLayoutItemMapGrid : public QgsLayoutItemMapItem
/**
* Sets the \a font used for drawing grid annotations.
* Shortcut for annotationTextFormat().setFont().
* \see annotationFont()
* \deprecated use setAnnotationTextFormat() instead
*/
@ -587,6 +601,7 @@ class CORE_EXPORT QgsLayoutItemMapGrid : public QgsLayoutItemMapItem
/**
* Returns the font used for drawing grid annotations.
* Shortcut for annotationTextFormat().font().
* \see setAnnotationFont()
* \deprecated use annotationTextFormat() instead
*/
@ -594,6 +609,7 @@ class CORE_EXPORT QgsLayoutItemMapGrid : public QgsLayoutItemMapItem
/**
* Sets the font \a color used for drawing grid annotations.
* Shortcut for annotationTextFormat().setColor() and annotationTextFormat().setOpacity().
* \see annotationFontColor()
* \deprecated use setAnnotationTextFormat() instead
*/
@ -601,6 +617,7 @@ class CORE_EXPORT QgsLayoutItemMapGrid : public QgsLayoutItemMapItem
/**
* Returns the font color used for drawing grid annotations.
* Shortcut for annotationTextFormat().color() and annotationTextFormat().opacity().
* \see setAnnotationFontColor()
* \deprecated use annotationTextFormat() instead
*/
@ -793,6 +810,78 @@ class CORE_EXPORT QgsLayoutItemMapGrid : public QgsLayoutItemMapItem
*/
double frameWidth() const { return mGridFrameWidth; }
/**
* Enable/disable ticks rotation for rotated or reprojected grids.
* \see rotatedTicksEnabled()
*/
void setRotatedTicksEnabled( const bool state ) { mRotatedTicksEnabled = state; }
/**
* Gets whether ticks rotation for rotated or reprojected grids is enabled.
* \see setRotatedTicksEnabled()
*/
double rotatedTicksEnabled() const { return mRotatedTicksEnabled; }
/**
* Sets the tick length calculation mode.
* \see rotatedTicksLengthMode()
*/
void setRotatedTicksLengthMode( const TickLengthMode mode ) { mRotatedTicksLengthMode = mode; }
/**
* Returns the grid frame style.
* \see setRotatedTicksLengthMode()
*/
TickLengthMode rotatedTicksLengthMode() const { return mRotatedTicksLengthMode; }
/**
* Sets the \a minimum angle (in degrees) below which ticks are not drawn.
* \see rotatedTicksMinimumAngle()
*/
void setRotatedTicksMinimumAngle( const double angle ) { mRotatedTicksMinimumAngle = angle; }
/**
* Gets the \a minimum angle (in degrees) below which ticks are not drawn.
* \see setRotatedTicksMinimumAngle()
*/
double rotatedTicksMinimumAngle() const { return mRotatedTicksMinimumAngle; }
/**
* Enable/disable annotations rotation for rotated or reprojected grids.
* \see rotatedAnnotationsEnabled()
*/
void setRotatedAnnotationsEnabled( const bool state ) { mRotatedAnnotationsEnabled = state; }
/**
* Gets whether annotations rotation for rotated or reprojected grids is enabled.
* \see setRotatedAnnotationsEnabled()
*/
double rotatedAnnotationsEnabled() const { return mRotatedAnnotationsEnabled; }
/**
* Sets the annotation length calculation mode.
* \see rotatedAnnotationsLengthMode()
*/
void setRotatedAnnotationsLengthMode( const TickLengthMode mode ) { mRotatedAnnotationsLengthMode = mode; }
/**
* Returns the grid frame style.
* \see setRotatedAnnotationsLengthMode()
*/
TickLengthMode rotatedAnnotationsLengthMode() const { return mRotatedAnnotationsLengthMode; }
/**
* Sets the \a minimum angle (in degrees) below which annotated are not drawn.
* \see rotatedAnnotationsMinimumAngle()
*/
void setRotatedAnnotationsMinimumAngle( const double angle ) { mRotatedAnnotationsMinimumAngle = angle; }
/**
* Gets the \a minimum angle (in degrees) below which annotated are not drawn.
* \see setRotatedAnnotationsMinimumAngle()
*/
double rotatedAnnotationsMinimumAngle() const { return mRotatedAnnotationsMinimumAngle; }
/**
* Sets the grid frame margin (in layout units).
* This property controls distance between the map frame and the grid frame.
@ -888,8 +977,63 @@ class CORE_EXPORT QgsLayoutItemMapGrid : public QgsLayoutItemMapItem
double right = 0.0;
double bottom = 0.0;
double left = 0.0;
/**
* Updates the specified border of the extension
*/
void UpdateBorder( BorderSide border, double value )
{
switch ( border )
{
case QgsLayoutItemMapGrid::Left:
left = std::max( left, value );
break;
case QgsLayoutItemMapGrid::Right:
right = std::max( right, value );
break;
case QgsLayoutItemMapGrid::Top:
top = std::max( top, value );
break;
case QgsLayoutItemMapGrid::Bottom:
bottom = std::max( bottom, value );
break;
}
}
/**
* Updates all borders of the extension
*/
void UpdateAll( double value )
{
left = std::max( left, value );
right = std::max( right, value );
top = std::max( top, value );
bottom = std::max( bottom, value );
}
};
struct GridLineAnnotation
{
BorderSide border; // border on which the annotation is
QVector2D position; // position on the frame
QVector2D vector; // vector towards map center
double angle; // the (acute) angle formed between the vector and the border
};
/**
* Helper that represents a grid line, for drawing the line itself an the
* anotations on the frame.
*/
struct GridLine
{
QPolygonF line; // the actual line, can be straight with two points or curved if transformed
double coordinate; // the coordinate value
QgsLayoutItemMapGrid::AnnotationCoordinate coordinateType; // whether it's a latitude or longitude line
GridLineAnnotation startAnnotation; // the annotation on the start point
GridLineAnnotation endAnnotation; // the annotation on the end point
};
mutable QList< GridLine > mGridLines;
//! True if a re-transformation of grid lines is required
mutable bool mTransformDirty = true;
@ -947,6 +1091,7 @@ class CORE_EXPORT QgsLayoutItemMapGrid : public QgsLayoutItemMapItem
mutable std::unique_ptr< QgsExpression > mGridAnnotationExpression;
FrameStyle mGridFrameStyle = QgsLayoutItemMapGrid::NoFrame;
FrameSideFlags mGridFrameSides;
double mGridFrameWidth = 2.0;
double mGridFramePenThickness = 0.3;
@ -955,6 +1100,12 @@ class CORE_EXPORT QgsLayoutItemMapGrid : public QgsLayoutItemMapItem
QColor mGridFrameFillColor2 = Qt::black;
double mCrossLength = 3.0;
double mGridFrameMargin = 0.0;
bool mRotatedTicksEnabled = false;
TickLengthMode mRotatedTicksLengthMode = QgsLayoutItemMapGrid::OrthogonalTicks;
double mRotatedTicksMinimumAngle = 0.0;
bool mRotatedAnnotationsEnabled = false;
TickLengthMode mRotatedAnnotationsLengthMode = QgsLayoutItemMapGrid::OrthogonalTicks;
double mRotatedAnnotationsMinimumAngle = 0.0;
double mMinimumIntervalWidth = 50;
double mMaximumIntervalWidth = 100;
@ -994,74 +1145,57 @@ class CORE_EXPORT QgsLayoutItemMapGrid : public QgsLayoutItemMapItem
double mEvaluatedCrossLength = 0;
double mEvaluatedGridFrameLineThickness = 0;
class QgsMapAnnotation
{
public:
double coordinate;
QPointF itemPosition;
QgsLayoutItemMapGrid::AnnotationCoordinate coordinateType;
};
/**
* Updates the grid lines annotation positions
*/
void updateGridLinesAnnotationsPositions() const;
/**
* Draws the map grid. If extension is specified, then no grid will be drawn and instead the maximum extension
* for the grid outside of the map frame will be calculated.
*/
void drawGridFrame( QPainter *p, const QList< QPair< double, QLineF > > &hLines, const QList< QPair< double, QLineF > > &vLines, GridExtension *extension = nullptr ) const;
void drawGridFrame( QPainter *p, GridExtension *extension = nullptr ) const;
/**
* Draw coordinates for mGridAnnotationType Coordinate
* \param context destination render context
* \param hLines horizontal coordinate lines in item coordinates
* \param vLines vertical coordinate lines in item coordinates
* \param expressionContext expression context for evaluating custom annotation formats
* \param extension optional. If specified, nothing will be drawn and instead the maximum extension for the grid
* annotations will be stored in this variable.
*/
void drawCoordinateAnnotations( QgsRenderContext &context, const QList< QPair< double, QLineF > > &hLines, const QList< QPair< double, QLineF > > &vLines, QgsExpressionContext &expressionContext, GridExtension *extension = nullptr ) const;
void drawCoordinateAnnotations( QgsRenderContext &context, QgsExpressionContext &expressionContext, GridExtension *extension = nullptr ) const;
/**
* Draw an annotation. If optional extension argument is specified, nothing will be drawn and instead
* the extension of the annotation outside of the map frame will be stored in this variable.
*/
void drawCoordinateAnnotation( QgsRenderContext &context, QPointF pos, const QString &annotationString, AnnotationCoordinate coordinateType, GridExtension *extension = nullptr ) const;
/**
* Draws a single annotation
* \param context destination render context
* \param pos item coordinates where to draw
* \param rotation text rotation
* \param annotationText the text to draw
*/
void drawAnnotation( QgsRenderContext &context, QPointF pos, int rotation, const QString &annotationText ) const;
void drawCoordinateAnnotation( QgsRenderContext &context, GridLineAnnotation annot, const QString &annotationString, AnnotationCoordinate coordinateType, GridExtension *extension = nullptr ) const;
QString gridAnnotationString( double value, AnnotationCoordinate coord, QgsExpressionContext &expressionContext ) const;
/**
* Returns the grid lines with associated coordinate value
* Computes the grid lines with associated coordinate value
\returns 0 in case of success*/
int xGridLines( QList< QPair< double, QLineF > > &lines ) const;
int xGridLines() const;
/**
* Returns the grid lines for the y-coordinates. Not vertical in case of rotation
* Computes the grid lines for the y-coordinates. Not vertical in case of rotation
\returns 0 in case of success*/
int yGridLines( QList< QPair< double, QLineF > > &lines ) const;
int yGridLines() const;
int xGridLinesCrsTransform( const QgsRectangle &bbox, const QgsCoordinateTransform &t, QList< QPair< double, QPolygonF > > &lines ) const;
int xGridLinesCrsTransform( const QgsRectangle &bbox, const QgsCoordinateTransform &t ) const;
int yGridLinesCrsTransform( const QgsRectangle &bbox, const QgsCoordinateTransform &t, QList< QPair< double, QPolygonF > > &lines ) const;
int yGridLinesCrsTransform( const QgsRectangle &bbox, const QgsCoordinateTransform &t ) const;
void drawGridLine( const QLineF &line, QgsRenderContext &context ) const;
void drawGridLine( const QPolygonF &line, QgsRenderContext &context ) const;
void sortGridLinesOnBorders( const QList< QPair< double, QLineF > > &hLines, const QList< QPair< double, QLineF > > &vLines, QMap< double, double > &leftFrameEntries,
QMap< double, double > &rightFrameEntries, QMap< double, double > &topFrameEntries, QMap< double, double > &bottomFrameEntries ) const;
/**
* Draw the grid frame's border. If optional extension argument is specified, nothing will be drawn and instead
* the maximum extension of the frame border outside of the map frame will be stored in this variable.
*/
void drawGridFrameBorder( QPainter *p, const QMap< double, double > &borderPos, BorderSide border, double *extension = nullptr ) const;
void drawGridFrameBorder( QPainter *p, BorderSide border, double *extension = nullptr ) const;
/**
* Returns the item border of a point (in item coordinates)
@ -1078,10 +1212,9 @@ class CORE_EXPORT QgsLayoutItemMapGrid : public QgsLayoutItemMapItem
QPolygonF scalePolygon( const QPolygonF &polygon, double scale ) const;
//! Draws grid if CRS is different to map CRS
void drawGridCrsTransform( QgsRenderContext &context, double dotsPerMM, QList< QPair< double, QLineF > > &horizontalLines,
QList< QPair< double, QLineF > > &verticalLines, bool calculateLinesOnly = false ) const;
void drawGridCrsTransform( QgsRenderContext &context, double dotsPerMM, bool calculateLinesOnly = false ) const;
void drawGridNoTransform( QgsRenderContext &context, double dotsPerMM, QList<QPair<double, QLineF> > &horizontalLines, QList<QPair<double, QLineF> > &verticalLines, bool calculateLinesOnly = false ) const;
void drawGridNoTransform( QgsRenderContext &context, double dotsPerMM, bool calculateLinesOnly = false ) const;
void createDefaultGridLineSymbol();
@ -1089,16 +1222,19 @@ class CORE_EXPORT QgsLayoutItemMapGrid : public QgsLayoutItemMapItem
void drawGridMarker( QPointF point, QgsRenderContext &context ) const;
void drawGridFrameZebraBorder( QPainter *p, const QMap<double, double> &borderPos, BorderSide border, double *extension = nullptr ) const;
void drawGridFrameZebra( QPainter *p, GridExtension *extension = nullptr ) const;
void drawGridFrameTicks( QPainter *p, const QMap<double, double> &borderPos, BorderSide border, double *extension = nullptr ) const;
void drawGridFrameZebraBorder( QPainter *p, BorderSide border, double *extension = nullptr ) const;
void drawGridFrameLineBorder( QPainter *p, BorderSide border, double *extension = nullptr ) const;
void drawGridFrameTicks( QPainter *p, GridExtension *extension = nullptr ) const;
void drawGridFrameLine( QPainter *p, GridExtension *extension = nullptr ) const;
void calculateCrsTransformLines() const;
bool shouldShowDivisionForSide( AnnotationCoordinate coordinate, BorderSide side ) const;
bool shouldShowDivisionForDisplayMode( AnnotationCoordinate coordinate, DisplayMode mode ) const;
bool shouldShowAnnotationForSide( AnnotationCoordinate coordinate, BorderSide side ) const;
bool shouldShowForDisplayMode( AnnotationCoordinate coordinate, DisplayMode mode ) const;
void refreshDataDefinedProperties();
//! Returns diagonal of map in CRS units

View File

@ -28,6 +28,8 @@
#include "qgsexpressionbuilderdialog.h"
#include "qgsvectorlayer.h"
#include "qgsprojectviewsettings.h"
#include "qgstextformatwidget.h"
#include "qgsguiutils.h"
QgsLayoutMapGridWidget::QgsLayoutMapGridWidget( QgsLayoutItemMapGrid *mapGrid, QgsLayoutItemMap *map )
: QgsLayoutItemBaseWidget( nullptr, mapGrid )
@ -45,6 +47,11 @@ QgsLayoutMapGridWidget::QgsLayoutMapGridWidget( QgsLayoutItemMapGrid *mapGrid, Q
mFrameStyleComboBox->addItem( tr( "Line Border" ), QgsLayoutItemMapGrid::LineBorder );
mFrameStyleComboBox->addItem( tr( "Line Border (Nautical)" ), QgsLayoutItemMapGrid::LineBorderNautical );
mRotatedTicksLengthModeComboBox->addItem( tr( "Orthogonal" ), QgsLayoutItemMapGrid::OrthogonalTicks );
mRotatedTicksLengthModeComboBox->addItem( tr( "Fixed length" ), QgsLayoutItemMapGrid::NormalizedTicks );
mRotatedAnnotationsLengthModeComboBox->addItem( tr( "Orthogonal" ), QgsLayoutItemMapGrid::OrthogonalTicks );
mRotatedAnnotationsLengthModeComboBox->addItem( tr( "Fixed length" ), QgsLayoutItemMapGrid::NormalizedTicks );
mGridFrameMarginSpinBox->setShowClearButton( true );
mGridFrameMarginSpinBox->setClearValue( 0 );
@ -56,6 +63,12 @@ QgsLayoutMapGridWidget::QgsLayoutMapGridWidget( QgsLayoutItemMapGrid *mapGrid, Q
connect( mFrameWidthSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutMapGridWidget::mFrameWidthSpinBox_valueChanged );
connect( mGridFrameMarginSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutMapGridWidget::mGridFrameMarginSpinBox_valueChanged );
connect( mFrameStyleComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsLayoutMapGridWidget::mFrameStyleComboBox_currentIndexChanged );
connect( mRotatedTicksCheckBox, &QCheckBox::toggled, this, &QgsLayoutMapGridWidget::mRotatedTicksCheckBox_toggled );
connect( mRotatedTicksLengthModeComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsLayoutMapGridWidget::mRotatedTicksLengthModeComboBox_currentIndexChanged );
connect( mRotatedTicksThresholdSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutMapGridWidget::mRotatedTicksThresholdSpinBox_valueChanged );
connect( mRotatedAnnotationsCheckBox, &QCheckBox::toggled, this, &QgsLayoutMapGridWidget::mRotatedAnnotationsCheckBox_toggled );
connect( mRotatedAnnotationsLengthModeComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsLayoutMapGridWidget::mRotatedAnnotationsLengthModeComboBox_currentIndexChanged );
connect( mRotatedAnnotationsThresholdSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutMapGridWidget::mRotatedAnnotationsThresholdSpinBox_valueChanged );
connect( mGridFramePenSizeSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutMapGridWidget::mGridFramePenSizeSpinBox_valueChanged );
connect( mGridFramePenColorButton, &QgsColorButton::colorChanged, this, &QgsLayoutMapGridWidget::mGridFramePenColorButton_colorChanged );
connect( mGridFrameFill1ColorButton, &QgsColorButton::colorChanged, this, &QgsLayoutMapGridWidget::mGridFrameFill1ColorButton_colorChanged );
@ -94,7 +107,6 @@ QgsLayoutMapGridWidget::QgsLayoutMapGridWidget( QgsLayoutItemMapGrid *mapGrid, Q
connect( mEnabledCheckBox, &QCheckBox::toggled, this, &QgsLayoutMapGridWidget::gridEnabledToggled );
setPanelTitle( tr( "Map Grid Properties" ) );
mAnnotationFontButton->setMode( QgsFontButton::ModeQFont );
blockAllSignals( true );
@ -160,7 +172,7 @@ QgsLayoutMapGridWidget::QgsLayoutMapGridWidget( QgsLayoutItemMapGrid *mapGrid, Q
mGridMarkerStyleButton->setSymbolType( QgsSymbol::Marker );
//set initial state of frame style controls
toggleFrameControls( false, false, false );
toggleFrameControls( false, false, false, false );
registerDataDefinedButton( mEnabledDDBtn, QgsLayoutObject::MapGridEnabled );
registerDataDefinedButton( mIntervalXDDBtn, QgsLayoutObject::MapGridIntervalX );
@ -180,8 +192,6 @@ QgsLayoutMapGridWidget::QgsLayoutMapGridWidget( QgsLayoutItemMapGrid *mapGrid, Q
connect( mGridLineStyleButton, &QgsSymbolButton::changed, this, &QgsLayoutMapGridWidget::lineSymbolChanged );
connect( mGridMarkerStyleButton, &QgsSymbolButton::changed, this, &QgsLayoutMapGridWidget::markerSymbolChanged );
connect( mAnnotationFontButton, &QgsFontButton::changed, this, &QgsLayoutMapGridWidget::annotationTextFormatChanged );
mGridLineStyleButton->registerExpressionContextGenerator( mMapGrid );
mGridLineStyleButton->setLayer( coverageLayer() );
mGridMarkerStyleButton->registerExpressionContextGenerator( mMapGrid );
@ -307,7 +317,7 @@ void QgsLayoutMapGridWidget::handleChangedAnnotationDisplay( QgsLayoutItemMapGri
mMap->endCommand();
}
void QgsLayoutMapGridWidget::toggleFrameControls( bool frameEnabled, bool frameFillEnabled, bool frameSizeEnabled )
void QgsLayoutMapGridWidget::toggleFrameControls( bool frameEnabled, bool frameFillEnabled, bool frameSizeEnabled, bool rotationEnabled )
{
//set status of frame controls
mFrameWidthSpinBox->setEnabled( frameSizeEnabled );
@ -332,6 +342,12 @@ void QgsLayoutMapGridWidget::toggleFrameControls( bool frameEnabled, bool frameF
mRightDivisionsLabel->setEnabled( frameEnabled );
mTopDivisionsLabel->setEnabled( frameEnabled );
mBottomDivisionsLabel->setEnabled( frameEnabled );
mRotatedTicksCheckBox->setEnabled( rotationEnabled );
mRotatedTicksLengthModeComboBox->setEnabled( rotationEnabled );
mRotatedTicksThresholdSpinBox->setEnabled( rotationEnabled );
mRotatedAnnotationsCheckBox->setEnabled( rotationEnabled );
mRotatedAnnotationsLengthModeComboBox->setEnabled( rotationEnabled );
mRotatedAnnotationsThresholdSpinBox->setEnabled( rotationEnabled );
}
void QgsLayoutMapGridWidget::insertAnnotationPositionEntries( QComboBox *c )
@ -345,6 +361,11 @@ void QgsLayoutMapGridWidget::insertAnnotationDirectionEntries( QComboBox *c )
c->addItem( tr( "Horizontal" ), QgsLayoutItemMapGrid::Horizontal );
c->addItem( tr( "Vertical Ascending" ), QgsLayoutItemMapGrid::Vertical );
c->addItem( tr( "Vertical Descending" ), QgsLayoutItemMapGrid::VerticalDescending );
c->addItem( tr( "Boundary Direction" ), QgsLayoutItemMapGrid::BoundaryDirection );
// c->addItem( tr( "Parallel to Tick" ), QgsLayoutItemMapGrid::ParallelToTick );
c->addItem( tr( "Above Tick" ), QgsLayoutItemMapGrid::AboveTick );
c->addItem( tr( "On Tick" ), QgsLayoutItemMapGrid::OnTick );
c->addItem( tr( "Under Tick" ), QgsLayoutItemMapGrid::UnderTick );
}
void QgsLayoutMapGridWidget::initFrameDisplayBox( QComboBox *c, QgsLayoutItemMapGrid::DisplayMode display )
@ -525,19 +546,19 @@ void QgsLayoutMapGridWidget::setGridItems()
{
case QgsLayoutItemMapGrid::Zebra:
case QgsLayoutItemMapGrid::ZebraNautical:
toggleFrameControls( true, true, true );
toggleFrameControls( true, true, true, false );
break;
case QgsLayoutItemMapGrid::InteriorTicks:
case QgsLayoutItemMapGrid::ExteriorTicks:
case QgsLayoutItemMapGrid::InteriorExteriorTicks:
toggleFrameControls( true, false, true );
toggleFrameControls( true, false, true, true );
break;
case QgsLayoutItemMapGrid::LineBorder:
case QgsLayoutItemMapGrid::LineBorderNautical:
toggleFrameControls( true, false, false );
toggleFrameControls( true, false, false, false );
break;
case QgsLayoutItemMapGrid::NoFrame:
toggleFrameControls( false, false, false );
toggleFrameControls( false, false, false, false );
break;
}
@ -546,6 +567,14 @@ void QgsLayoutMapGridWidget::setGridItems()
mCheckGridTopSide->setChecked( mMapGrid->testFrameSideFlag( QgsLayoutItemMapGrid::FrameTop ) );
mCheckGridBottomSide->setChecked( mMapGrid->testFrameSideFlag( QgsLayoutItemMapGrid::FrameBottom ) );
mRotatedTicksCheckBox->setChecked( mMapGrid->rotatedTicksEnabled() );
mRotatedTicksLengthModeComboBox->setCurrentIndex( mRotatedTicksLengthModeComboBox->findData( mMapGrid->rotatedTicksLengthMode() ) );
mRotatedTicksThresholdSpinBox->setValue( mMapGrid->rotatedTicksMinimumAngle() );
mRotatedAnnotationsCheckBox->setChecked( mMapGrid->rotatedAnnotationsEnabled() );
mRotatedAnnotationsLengthModeComboBox->setCurrentIndex( mRotatedAnnotationsLengthModeComboBox->findData( mMapGrid->rotatedAnnotationsLengthMode() ) );
mRotatedAnnotationsThresholdSpinBox->setValue( mMapGrid->rotatedAnnotationsMinimumAngle() );
initFrameDisplayBox( mFrameDivisionsLeftComboBox, mMapGrid->frameDivisions( QgsLayoutItemMapGrid::Left ) );
initFrameDisplayBox( mFrameDivisionsRightComboBox, mMapGrid->frameDivisions( QgsLayoutItemMapGrid::Right ) );
initFrameDisplayBox( mFrameDivisionsTopComboBox, mMapGrid->frameDivisions( QgsLayoutItemMapGrid::Top ) );
@ -846,19 +875,19 @@ void QgsLayoutMapGridWidget::mFrameStyleComboBox_currentIndexChanged( int )
{
case QgsLayoutItemMapGrid::Zebra:
case QgsLayoutItemMapGrid::ZebraNautical:
toggleFrameControls( true, true, true );
toggleFrameControls( true, true, true, false );
break;
case QgsLayoutItemMapGrid::InteriorTicks:
case QgsLayoutItemMapGrid::ExteriorTicks:
case QgsLayoutItemMapGrid::InteriorExteriorTicks:
toggleFrameControls( true, false, true );
toggleFrameControls( true, false, true, true );
break;
case QgsLayoutItemMapGrid::LineBorder:
case QgsLayoutItemMapGrid::LineBorderNautical:
toggleFrameControls( true, false, false );
toggleFrameControls( true, false, false, false );
break;
case QgsLayoutItemMapGrid::NoFrame:
toggleFrameControls( false, false, false );
toggleFrameControls( false, false, false, false );
break;
}
mMap->updateBoundingRect();
@ -866,6 +895,86 @@ void QgsLayoutMapGridWidget::mFrameStyleComboBox_currentIndexChanged( int )
mMap->endCommand();
}
void QgsLayoutMapGridWidget::mRotatedTicksCheckBox_toggled( bool state )
{
if ( !mMapGrid || !mMap )
{
return;
}
mMap->beginCommand( tr( "Change Tick Rotation Enabled" ) );
mMapGrid->setRotatedTicksEnabled( state );
mMap->update();
mMap->endCommand();
}
void QgsLayoutMapGridWidget::mRotatedTicksLengthModeComboBox_currentIndexChanged( int )
{
if ( !mMapGrid || !mMap )
{
return;
}
QgsLayoutItemMapGrid::TickLengthMode mode = static_cast< QgsLayoutItemMapGrid::TickLengthMode >( mRotatedTicksLengthModeComboBox->currentData().toInt() );
mMap->beginCommand( tr( "Change Tick Length Mode" ) );
mMapGrid->setRotatedTicksLengthMode( mode );
mMap->update();
mMap->endCommand();
}
void QgsLayoutMapGridWidget::mRotatedTicksThresholdSpinBox_valueChanged( double val )
{
if ( !mMapGrid || !mMap )
{
return;
}
mMap->beginCommand( tr( "Change Rotated Ticks Threshold" ) );
mMapGrid->setRotatedTicksMinimumAngle( val );
mMap->update();
mMap->endCommand();
}
void QgsLayoutMapGridWidget::mRotatedAnnotationsCheckBox_toggled( bool state )
{
if ( !mMapGrid || !mMap )
{
return;
}
mMap->beginCommand( tr( "Change Annotation Rotation Enabled" ) );
mMapGrid->setRotatedAnnotationsEnabled( state );
mMap->update();
mMap->endCommand();
}
void QgsLayoutMapGridWidget::mRotatedAnnotationsLengthModeComboBox_currentIndexChanged( int )
{
if ( !mMapGrid || !mMap )
{
return;
}
QgsLayoutItemMapGrid::TickLengthMode mode = static_cast< QgsLayoutItemMapGrid::TickLengthMode >( mRotatedAnnotationsLengthModeComboBox->currentData().toInt() );
mMap->beginCommand( tr( "Change Annotation Length Mode" ) );
mMapGrid->setRotatedAnnotationsLengthMode( mode );
mMap->update();
mMap->endCommand();
}
void QgsLayoutMapGridWidget::mRotatedAnnotationsThresholdSpinBox_valueChanged( double val )
{
if ( !mMapGrid || !mMap )
{
return;
}
mMap->beginCommand( tr( "Change Rotated Annotations Threshold" ) );
mMapGrid->setRotatedAnnotationsMinimumAngle( val );
mMap->update();
mMap->endCommand();
}
void QgsLayoutMapGridWidget::intervalUnitChanged( int )
{
if ( !mMapGrid || !mMap )
@ -1140,7 +1249,6 @@ void QgsLayoutMapGridWidget::mDistanceToMapFrameSpinBox_valueChanged( double d )
mMap->endCommand();
}
void QgsLayoutMapGridWidget::lineSymbolChanged()
{
if ( !mMapGrid || !mMap )

View File

@ -50,6 +50,12 @@ class GUI_EXPORT QgsLayoutMapGridWidget: public QgsLayoutItemBaseWidget, private
void mOffsetYSpinBox_valueChanged( double value );
void mCrossWidthSpinBox_valueChanged( double val );
void mFrameWidthSpinBox_valueChanged( double val );
void mRotatedTicksCheckBox_toggled( bool checked );
void mRotatedTicksLengthModeComboBox_currentIndexChanged( int );
void mRotatedTicksThresholdSpinBox_valueChanged( double val );
void mRotatedAnnotationsCheckBox_toggled( bool checked );
void mRotatedAnnotationsLengthModeComboBox_currentIndexChanged( int );
void mRotatedAnnotationsThresholdSpinBox_valueChanged( double val );
void mGridFrameMarginSpinBox_valueChanged( double val );
void mFrameStyleComboBox_currentIndexChanged( int );
void mGridFramePenSizeSpinBox_valueChanged( double d );
@ -97,6 +103,7 @@ class GUI_EXPORT QgsLayoutMapGridWidget: public QgsLayoutItemBaseWidget, private
protected:
//! Sets the current composer map values to the GUI elements
virtual void updateGuiElements();
@ -138,7 +145,7 @@ class GUI_EXPORT QgsLayoutMapGridWidget: public QgsLayoutItemBaseWidget, private
void initAnnotationDirectionBox( QComboBox *c, QgsLayoutItemMapGrid::AnnotationDirection dir );
//! Enables/disables grid frame related controls
void toggleFrameControls( bool frameEnabled, bool frameFillEnabled, bool frameSizeEnabled );
void toggleFrameControls( bool frameEnabled, bool frameFillEnabled, bool frameSizeEnabled, bool ticksRotationEnabled );
//! Is there some predefined scales, globally or as project's options ?
bool hasPredefinedScales() const;

View File

@ -439,59 +439,17 @@
<string notr="true">composermapgrid</string>
</property>
<layout class="QGridLayout" name="gridLayout_3" columnstretch="0,0,0,0,0">
<item row="12" column="0" colspan="5">
<layout class="QGridLayout" name="gridLayout_4">
<item row="0" column="0">
<widget class="QCheckBox" name="mCheckGridLeftSide">
<property name="text">
<string>Left side</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QCheckBox" name="mCheckGridRightSide">
<property name="text">
<string>Right side</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="mCheckGridTopSide">
<property name="text">
<string>Top side</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QCheckBox" name="mCheckGridBottomSide">
<property name="text">
<string>Bottom side</string>
</property>
</widget>
</item>
</layout>
<item row="9" column="1" colspan="4">
<widget class="QComboBox" name="mFrameDivisionsLeftComboBox"/>
</item>
<item row="4" column="1" colspan="3">
<widget class="QgsDoubleSpinBox" name="mGridFrameMarginSpinBox">
<property name="suffix">
<string> mm</string>
</property>
<property name="showClearButton" stdset="0">
<bool>false</bool>
</property>
</widget>
</item>
<item row="1" column="1" colspan="4">
<widget class="QComboBox" name="mFrameStyleComboBox"/>
</item>
<item row="8" column="0">
<widget class="QLabel" name="mLeftDivisionsLabel">
<item row="10" column="0">
<widget class="QLabel" name="mRightDivisionsLabel">
<property name="text">
<string>Left divisions</string>
<string>Right divisions</string>
</property>
</widget>
</item>
<item row="2" column="0">
<item row="3" column="0">
<widget class="QLabel" name="mFrameWidthLabel">
<property name="text">
<string>Frame size</string>
@ -501,25 +459,29 @@
</property>
</widget>
</item>
<item row="9" column="0">
<widget class="QLabel" name="mRightDivisionsLabel">
<item row="5" column="0">
<widget class="QLabel" name="mFrameMarginLabel">
<property name="text">
<string>Right divisions</string>
<string>Frame margin</string>
</property>
</widget>
</item>
<item row="2" column="1" colspan="3">
<widget class="QgsDoubleSpinBox" name="mFrameWidthSpinBox">
<item row="7" column="1">
<widget class="QgsDoubleSpinBox" name="mGridFramePenSizeSpinBox">
<property name="suffix">
<string> mm</string>
</property>
<property name="showClearButton" stdset="0">
<property name="showClearButton">
<bool>false</bool>
</property>
</widget>
</item>
<item row="8" column="1" colspan="4">
<widget class="QComboBox" name="mFrameDivisionsLeftComboBox"/>
<item row="9" column="0">
<widget class="QLabel" name="mLeftDivisionsLabel">
<property name="text">
<string>Left divisions</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="mFrameStyleLabel_2">
@ -531,37 +493,85 @@
</property>
</widget>
</item>
<item row="10" column="1" colspan="4">
<widget class="QComboBox" name="mFrameDivisionsTopComboBox"/>
</item>
<item row="9" column="1" colspan="4">
<widget class="QComboBox" name="mFrameDivisionsRightComboBox"/>
</item>
<item row="10" column="0">
<widget class="QLabel" name="mTopDivisionsLabel">
<property name="text">
<string>Top divisions</string>
</property>
</widget>
</item>
<item row="6" column="0">
<item row="7" column="0">
<widget class="QLabel" name="mFramePenLabel">
<property name="text">
<string>Frame line thickness</string>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QgsDoubleSpinBox" name="mGridFramePenSizeSpinBox">
<item row="12" column="1" colspan="4">
<widget class="QComboBox" name="mFrameDivisionsBottomComboBox"/>
</item>
<item row="5" column="1" colspan="3">
<widget class="QgsDoubleSpinBox" name="mGridFrameMarginSpinBox">
<property name="suffix">
<string> mm</string>
</property>
<property name="showClearButton" stdset="0">
<property name="showClearButton">
<bool>false</bool>
</property>
</widget>
</item>
<item row="4" column="4">
<item row="3" column="4">
<widget class="QgsPropertyOverrideButton" name="mFrameSizeDDBtn">
<property name="text">
<string>…</string>
</property>
</widget>
</item>
<item row="10" column="1" colspan="4">
<widget class="QComboBox" name="mFrameDivisionsRightComboBox"/>
</item>
<item row="16" column="0">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Skip low angled ticks</string>
</property>
</widget>
</item>
<item row="7" column="2">
<widget class="QgsPropertyOverrideButton" name="mFrameLineThicknessDDBtn">
<property name="text">
<string>…</string>
</property>
</widget>
</item>
<item row="1" column="1" colspan="4">
<widget class="QComboBox" name="mFrameStyleComboBox"/>
</item>
<item row="3" column="1" colspan="3">
<widget class="QgsDoubleSpinBox" name="mFrameWidthSpinBox">
<property name="suffix">
<string> mm</string>
</property>
<property name="showClearButton">
<bool>false</bool>
</property>
</widget>
</item>
<item row="11" column="0">
<widget class="QLabel" name="mTopDivisionsLabel">
<property name="text">
<string>Top divisions</string>
</property>
</widget>
</item>
<item row="8" column="0">
<widget class="QLabel" name="mFrameFillLabel">
<property name="text">
<string>Frame fill colors</string>
</property>
</widget>
</item>
<item row="12" column="0">
<widget class="QLabel" name="mBottomDivisionsLabel">
<property name="text">
<string>Bottom divisions</string>
</property>
</widget>
</item>
<item row="5" column="4">
<widget class="QgsPropertyOverrideButton" name="mFrameMarginDDBtn">
<property name="text">
<string>…</string>
@ -569,44 +579,60 @@
</widget>
</item>
<item row="11" column="1" colspan="4">
<widget class="QComboBox" name="mFrameDivisionsBottomComboBox"/>
<widget class="QComboBox" name="mFrameDivisionsTopComboBox"/>
</item>
<item row="11" column="0">
<widget class="QLabel" name="mBottomDivisionsLabel">
<property name="text">
<string>Bottom divisions</string>
<item row="16" column="1" colspan="4">
<widget class="QDoubleSpinBox" name="mRotatedTicksThresholdSpinBox">
<property name="toolTip">
<string>Grid lines intersecting the border below this threshold will be ignored. This only makes sense for rotated grids.</string>
</property>
<property name="suffix">
<string> °</string>
</property>
<property name="decimals">
<number>0</number>
</property>
<property name="maximum">
<double>90.000000000000000</double>
</property>
<property name="value">
<double>0.000000000000000</double>
</property>
</widget>
</item>
<item row="7" column="0">
<widget class="QLabel" name="mFrameFillLabel">
<property name="text">
<string>Frame fill colors</string>
</property>
</widget>
<item row="13" column="0" colspan="5">
<layout class="QGridLayout" name="gridLayout_4">
<item row="0" column="1">
<widget class="QCheckBox" name="mCheckGridRightSide">
<property name="text">
<string>Right side</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QCheckBox" name="mCheckGridBottomSide">
<property name="text">
<string>Bottom side</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QCheckBox" name="mCheckGridLeftSide">
<property name="text">
<string>Left side</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="mCheckGridTopSide">
<property name="text">
<string>Top side</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="2" column="4">
<widget class="QgsPropertyOverrideButton" name="mFrameSizeDDBtn">
<property name="text">
<string>…</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="mFrameMarginLabel">
<property name="text">
<string>Frame margin</string>
</property>
</widget>
</item>
<item row="6" column="2">
<widget class="QgsPropertyOverrideButton" name="mFrameLineThicknessDDBtn">
<property name="text">
<string>…</string>
</property>
</widget>
</item>
<item row="7" column="3" colspan="2">
<item row="8" column="3" colspan="2">
<widget class="QgsColorButton" name="mGridFrameFill2ColorButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
@ -625,7 +651,7 @@
</property>
</widget>
</item>
<item row="7" column="1" colspan="2">
<item row="8" column="1" colspan="2">
<widget class="QgsColorButton" name="mGridFrameFill1ColorButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
@ -644,7 +670,7 @@
</property>
</widget>
</item>
<item row="6" column="3" colspan="2">
<item row="7" column="3" colspan="2">
<widget class="QgsColorButton" name="mGridFramePenColorButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
@ -663,6 +689,34 @@
</property>
</widget>
</item>
<item row="15" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Rotated ticks alignment</string>
</property>
</widget>
</item>
<item row="15" column="1" colspan="4">
<widget class="QComboBox" name="mRotatedTicksLengthModeComboBox">
<property name="toolTip">
<string>Determines how the ticks are aligned when rotated.</string>
</property>
</widget>
</item>
<item row="14" column="0">
<widget class="QLabel" name="label_8">
<property name="text">
<string>Rotate ticks</string>
</property>
</widget>
</item>
<item row="14" column="1" colspan="4">
<widget class="QCheckBox" name="mRotatedTicksCheckBox">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</widget>
</item>
@ -687,15 +741,58 @@
<bool>false</bool>
</property>
<layout class="QGridLayout" name="gridLayout" columnstretch="0,0,0">
<item row="17" column="0">
<widget class="QLabel" name="label_11">
<property name="text">
<string>Rotate annotations</string>
</property>
</widget>
</item>
<item row="19" column="1" colspan="2">
<widget class="QDoubleSpinBox" name="mRotatedAnnotationsThresholdSpinBox">
<property name="suffix">
<string> °</string>
</property>
<property name="decimals">
<number>0</number>
</property>
<property name="maximum">
<double>90.000000000000000</double>
</property>
</widget>
</item>
<item row="18" column="0">
<widget class="QLabel" name="label_10">
<property name="text">
<string>Rotated annotations alignement</string>
</property>
</widget>
</item>
<item row="11" column="1" colspan="2">
<widget class="QComboBox" name="mAnnotationPositionBottomComboBox"/>
</item>
<item row="14" column="2">
<widget class="QgsPropertyOverrideButton" name="mLabelDistDDBtn">
<property name="text">
<string>…</string>
</property>
</widget>
</item>
<item row="14" column="0">
<widget class="QLabel" name="mCoordinatePrecisionLabel">
<property name="text">
<string>Coordinate precision</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="10" column="1" colspan="2">
<widget class="QComboBox" name="mAnnotationDisplayBottomComboBox"/>
</item>
<item row="14" column="1">
<widget class="QgsDoubleSpinBox" name="mDistanceToMapFrameSpinBox">
<property name="suffix">
<string> mm</string>
</property>
</widget>
<item row="3" column="1" colspan="2">
<widget class="QComboBox" name="mAnnotationDirectionComboBoxLeft"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="mAnnotationPositionLabelLeft">
@ -707,16 +804,16 @@
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="mAnnotationPositionLabelRight">
<item row="0" column="0">
<widget class="QLabel" name="mAnnotationFormatLabel">
<property name="text">
<string>Right</string>
</property>
<property name="wordWrap">
<bool>true</bool>
<string>Format</string>
</property>
</widget>
</item>
<item row="1" column="1" colspan="2">
<widget class="QComboBox" name="mAnnotationDisplayLeftComboBox"/>
</item>
<item row="0" column="1" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_13">
<item>
@ -735,46 +832,17 @@
</item>
</layout>
</item>
<item row="13" column="1" colspan="2">
<widget class="QgsFontButton" name="mAnnotationFontButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<item row="18" column="1" colspan="2">
<widget class="QComboBox" name="mRotatedAnnotationsLengthModeComboBox"/>
</item>
<item row="19" column="0">
<widget class="QLabel" name="label_9">
<property name="text">
<string>Font</string>
<string>Skip low angled annotations</string>
</property>
</widget>
</item>
<item row="4" column="1" colspan="2">
<widget class="QComboBox" name="mAnnotationDisplayRightComboBox"/>
</item>
<item row="10" column="0">
<widget class="QLabel" name="mAnnotationPositionLabelBottom">
<property name="text">
<string>Bottom</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="7" column="1" colspan="2">
<widget class="QComboBox" name="mAnnotationDisplayTopComboBox"/>
</item>
<item row="13" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Font</string>
</property>
</widget>
</item>
<item row="2" column="1" colspan="2">
<widget class="QComboBox" name="mAnnotationPositionLeftComboBox"/>
</item>
<item row="15" column="0">
<item row="16" column="0">
<widget class="QLabel" name="mCoordinatePrecisionLabel">
<property name="text">
<string>Coordinate precision</string>
@ -784,35 +852,6 @@
</property>
</widget>
</item>
<item row="14" column="2">
<widget class="QgsPropertyOverrideButton" name="mLabelDistDDBtn">
<property name="text">
<string>…</string>
</property>
</widget>
</item>
<item row="9" column="1" colspan="2">
<widget class="QComboBox" name="mAnnotationDirectionComboBoxTop"/>
</item>
<item row="8" column="1" colspan="2">
<widget class="QComboBox" name="mAnnotationPositionTopComboBox"/>
</item>
<item row="3" column="1" colspan="2">
<widget class="QComboBox" name="mAnnotationDirectionComboBoxLeft"/>
</item>
<item row="6" column="1" colspan="2">
<widget class="QComboBox" name="mAnnotationDirectionComboBoxRight"/>
</item>
<item row="1" column="1" colspan="2">
<widget class="QComboBox" name="mAnnotationDisplayLeftComboBox"/>
</item>
<item row="0" column="0">
<widget class="QLabel" name="mAnnotationFormatLabel">
<property name="text">
<string>Format</string>
</property>
</widget>
</item>
<item row="7" column="0">
<widget class="QLabel" name="mAnnotationPositionLabelTop">
<property name="text">
@ -823,31 +862,83 @@
</property>
</widget>
</item>
<item row="11" column="1" colspan="2">
<widget class="QComboBox" name="mAnnotationPositionBottomComboBox"/>
<item row="2" column="1" colspan="2">
<widget class="QComboBox" name="mAnnotationPositionLeftComboBox"/>
</item>
<item row="5" column="1" colspan="2">
<widget class="QComboBox" name="mAnnotationPositionRightComboBox"/>
<item row="4" column="1" colspan="2">
<widget class="QComboBox" name="mAnnotationDisplayRightComboBox"/>
</item>
<item row="14" column="0">
<widget class="QLabel" name="mDistanceToFrameLabel">
<item row="8" column="1" colspan="2">
<widget class="QComboBox" name="mAnnotationPositionTopComboBox"/>
</item>
<item row="2" column="1" colspan="2">
<widget class="QComboBox" name="mAnnotationPositionLeftComboBox"/>
</item>
<item row="10" column="0">
<widget class="QLabel" name="mAnnotationPositionLabelBottom">
<property name="text">
<string>Distance to map frame</string>
<string>Bottom</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="15" column="1" colspan="2">
<item row="17" column="1" colspan="2">
<widget class="QCheckBox" name="mRotatedAnnotationsCheckBox">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="6" column="1" colspan="2">
<widget class="QComboBox" name="mAnnotationDirectionComboBoxRight"/>
</item>
<item row="12" column="1" colspan="2">
<widget class="QComboBox" name="mAnnotationDirectionComboBoxBottom"/>
</item>
<item row="14" column="1">
<widget class="QgsDoubleSpinBox" name="mDistanceToMapFrameSpinBox">
<property name="suffix">
<string> mm</string>
</property>
</widget>
</item>
<item row="7" column="1" colspan="2">
<widget class="QComboBox" name="mAnnotationDisplayTopComboBox"/>
</item>
<item row="16" column="1" colspan="2">
<widget class="QgsSpinBox" name="mCoordinatePrecisionSpinBox">
<property name="showClearButton" stdset="0">
<property name="showClearButton">
<bool>false</bool>
</property>
</widget>
</item>
<item row="12" column="1" colspan="2">
<widget class="QComboBox" name="mAnnotationDirectionComboBoxBottom"/>
<item row="5" column="1" colspan="2">
<widget class="QComboBox" name="mAnnotationPositionRightComboBox"/>
</item>
<item row="9" column="1" colspan="2">
<widget class="QComboBox" name="mAnnotationDirectionComboBoxTop"/>
</item>
<item row="13" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Font</string>
</property>
</widget>
</item>
<item row="13" column="1" colspan="2">
<widget class="QgsFontButton" name="mAnnotationFontButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Font</string>
</property>
</widget>
</item>
</layout>
</widget>
@ -860,18 +951,6 @@
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
<customwidget>
<class>QgsCollapsibleGroupBoxBasic</class>
<extends>QGroupBox</extends>
<header location="global">qgscollapsiblegroupbox.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsScrollArea</class>
<extends>QScrollArea</extends>
<header>qgsscrollarea.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsColorButton</class>
<extends>QToolButton</extends>
@ -888,26 +967,38 @@
<extends>QToolButton</extends>
<header>qgsfontbutton.h</header>
</customwidget>
<customwidget>
<class>QgsSpinBox</class>
<extends>QSpinBox</extends>
<header>qgsspinbox.h</header>
</customwidget>
<customwidget>
<class>QgsPropertyOverrideButton</class>
<extends>QToolButton</extends>
<header>qgspropertyoverridebutton.h</header>
</customwidget>
<customwidget>
<class>QgsBlendModeComboBox</class>
<extends>QComboBox</extends>
<header>qgsblendmodecombobox.h</header>
<class>QgsSpinBox</class>
<extends>QSpinBox</extends>
<header>qgsspinbox.h</header>
</customwidget>
<customwidget>
<class>QgsSymbolButton</class>
<extends>QToolButton</extends>
<header>qgssymbolbutton.h</header>
</customwidget>
<customwidget>
<class>QgsScrollArea</class>
<extends>QScrollArea</extends>
<header>qgsscrollarea.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsCollapsibleGroupBoxBasic</class>
<extends>QGroupBox</extends>
<header>qgscollapsiblegroupbox.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsBlendModeComboBox</class>
<extends>QComboBox</extends>
<header>qgsblendmodecombobox.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>scrollArea</tabstop>

View File

@ -305,6 +305,119 @@ class TestQgsLayoutMapGrid(unittest.TestCase):
self.report += checker.report()
assert myTestResult, myMessage
def testAnnotationsVariations(self):
layout = QgsLayout(QgsProject.instance())
layout.initializeDefaults()
map_configs = [
(10, 30, QgsLayoutItemMapGrid.OutsideMapFrame, QgsLayoutItemMapGrid.InteriorTicks, 0),
(10, 120, QgsLayoutItemMapGrid.OutsideMapFrame, QgsLayoutItemMapGrid.InteriorTicks, 3),
(90, 30, QgsLayoutItemMapGrid.OutsideMapFrame, QgsLayoutItemMapGrid.ExteriorTicks, 0),
(90, 120, QgsLayoutItemMapGrid.OutsideMapFrame, QgsLayoutItemMapGrid.ExteriorTicks, 3),
(170, 30, QgsLayoutItemMapGrid.InsideMapFrame, QgsLayoutItemMapGrid.InteriorTicks, 0),
(170, 120, QgsLayoutItemMapGrid.InsideMapFrame, QgsLayoutItemMapGrid.InteriorTicks, 3),
(250, 30, QgsLayoutItemMapGrid.InsideMapFrame, QgsLayoutItemMapGrid.ExteriorTicks, 0),
(250, 120, QgsLayoutItemMapGrid.InsideMapFrame, QgsLayoutItemMapGrid.ExteriorTicks, 3),
]
for x, y, pos, style, dist in map_configs:
map = QgsLayoutItemMap(layout)
layout.addLayoutItem(map)
map.attemptSetSceneRect(QRectF(x, y, 50, 50))
map.setBackgroundColor(QColor(200, 200, 200))
map.setExtent(QgsRectangle(5, 5, 15, 15))
map.setFrameEnabled(True)
map.grid().setFrameStyle(style)
map.grid().setFrameWidth(7)
map.grid().setFramePenSize(1)
map.grid().setFramePenColor(QColor(255, 0, 0))
map.grid().setEnabled(True)
map.grid().setIntervalX(10)
map.grid().setIntervalY(10)
map.grid().setAnnotationEnabled(True)
map.grid().setGridLineColor(QColor(0, 255, 0))
map.grid().setGridLineWidth(0.5)
map.grid().setAnnotationFont(getTestFont('Bold', 20))
map.grid().setAnnotationFontColor(QColor(0, 0, 255, 150))
map.grid().setAnnotationPrecision(0)
map.grid().setAnnotationFrameDistance(dist)
map.grid().setAnnotationPosition(pos, QgsLayoutItemMapGrid.Top)
map.grid().setAnnotationPosition(pos, QgsLayoutItemMapGrid.Right)
map.grid().setAnnotationPosition(pos, QgsLayoutItemMapGrid.Bottom)
map.grid().setAnnotationPosition(pos, QgsLayoutItemMapGrid.Left)
map.grid().setAnnotationDirection(QgsLayoutItemMapGrid.Vertical, QgsLayoutItemMapGrid.Top)
map.grid().setAnnotationDirection(QgsLayoutItemMapGrid.Horizontal, QgsLayoutItemMapGrid.Right)
map.grid().setAnnotationDirection(QgsLayoutItemMapGrid.BoundaryDirection, QgsLayoutItemMapGrid.Bottom)
map.grid().setAnnotationDirection(QgsLayoutItemMapGrid.VerticalDescending, QgsLayoutItemMapGrid.Left)
map.updateBoundingRect()
checker = QgsLayoutChecker('composermap_annotations_variations', layout)
checker.setControlPathPrefix("composer_mapgrid")
myTestResult, myMessage = checker.testLayout()
self.assertTrue(myTestResult, myMessage)
def testAnnotationsVariationsRotated(self):
layout = QgsLayout(QgsProject.instance())
layout.initializeDefaults()
map_configs = [
(10, 30, QgsLayoutItemMapGrid.OutsideMapFrame, QgsLayoutItemMapGrid.InteriorTicks, 0),
(10, 120, QgsLayoutItemMapGrid.OutsideMapFrame, QgsLayoutItemMapGrid.InteriorTicks, 3),
(90, 30, QgsLayoutItemMapGrid.OutsideMapFrame, QgsLayoutItemMapGrid.ExteriorTicks, 0),
(90, 120, QgsLayoutItemMapGrid.OutsideMapFrame, QgsLayoutItemMapGrid.ExteriorTicks, 3),
(170, 30, QgsLayoutItemMapGrid.InsideMapFrame, QgsLayoutItemMapGrid.InteriorTicks, 0),
(170, 120, QgsLayoutItemMapGrid.InsideMapFrame, QgsLayoutItemMapGrid.InteriorTicks, 3),
(250, 30, QgsLayoutItemMapGrid.InsideMapFrame, QgsLayoutItemMapGrid.ExteriorTicks, 0),
(250, 120, QgsLayoutItemMapGrid.InsideMapFrame, QgsLayoutItemMapGrid.ExteriorTicks, 3),
]
for x, y, pos, style, dist in map_configs:
map = QgsLayoutItemMap(layout)
layout.addLayoutItem(map)
map.attemptSetSceneRect(QRectF(x, y, 50, 50))
map.setBackgroundColor(QColor(200, 200, 200))
map.setExtent(QgsRectangle(5, 5, 15, 15))
map.setMapRotation(30)
map.setFrameEnabled(True)
map.grid().setFrameStyle(style)
map.grid().setFrameWidth(7)
map.grid().setFramePenSize(1)
map.grid().setFramePenColor(QColor(255, 0, 0))
map.grid().setEnabled(True)
map.grid().setIntervalX(10)
map.grid().setIntervalY(10)
map.grid().setAnnotationEnabled(True)
map.grid().setGridLineColor(QColor(0, 255, 0))
map.grid().setGridLineWidth(0.5)
map.grid().setAnnotationFont(getTestFont('Bold', 20))
map.grid().setAnnotationFontColor(QColor(0, 0, 255, 150))
map.grid().setAnnotationPrecision(0)
map.grid().setAnnotationFrameDistance(dist)
map.grid().setRotatedTicksEnabled(True)
map.grid().setRotatedAnnotationsEnabled(True)
map.grid().setAnnotationPosition(pos, QgsLayoutItemMapGrid.Top)
map.grid().setAnnotationPosition(pos, QgsLayoutItemMapGrid.Right)
map.grid().setAnnotationPosition(pos, QgsLayoutItemMapGrid.Bottom)
map.grid().setAnnotationPosition(pos, QgsLayoutItemMapGrid.Left)
map.grid().setAnnotationDirection(QgsLayoutItemMapGrid.AboveTick, QgsLayoutItemMapGrid.Top)
map.grid().setAnnotationDirection(QgsLayoutItemMapGrid.OnTick, QgsLayoutItemMapGrid.Right)
map.grid().setAnnotationDirection(QgsLayoutItemMapGrid.UnderTick, QgsLayoutItemMapGrid.Bottom)
map.grid().setAnnotationDirection(QgsLayoutItemMapGrid.BoundaryDirection, QgsLayoutItemMapGrid.Left)
map.updateBoundingRect()
checker = QgsLayoutChecker('composermap_annotations_variations_rotated', layout)
checker.setControlPathPrefix("composer_mapgrid")
myTestResult, myMessage = checker.testLayout()
self.assertTrue(myTestResult, myMessage)
def testExpressionContext(self):
layout = QgsLayout(QgsProject.instance())
layout.initializeDefaults()