mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-13 00:03:09 -04:00
[FEATURE][composer] Custom format for grid annotations (fix #9292)
Allows composer map grid annotations in custom formats which are evaluated using QgsExpressions. Made possible through the use of Expression Contexts(tm)!
This commit is contained in:
parent
c3a141551d
commit
e8c3afa398
@ -182,9 +182,10 @@ class QgsComposerMapGrid : QgsComposerMapItem
|
||||
DegreeMinuteSecond, /*!< degree/minutes/seconds, use NSEW suffix */
|
||||
DecimalWithSuffix, /*!< decimal degrees, use NSEW suffix */
|
||||
DegreeMinuteNoSuffix, /*!< degree/minutes, use - for S/W coordinates */
|
||||
DegreeMinutePadded, /*!< degree/minutes, with minutes using leading zeros were required */
|
||||
DegreeMinutePadded, /*!< degree/minutes, with minutes using leading zeros where required */
|
||||
DegreeMinuteSecondNoSuffix, /*!< degree/minutes/seconds, use - for S/W coordinates */
|
||||
DegreeMinuteSecondPadded /*!< degree/minutes/seconds, with minutes using leading zeros were required */
|
||||
DegreeMinuteSecondPadded, /*!< degree/minutes/seconds, with minutes using leading zeros where required */
|
||||
CustomFormat /*!< custom expression-based format */
|
||||
};
|
||||
|
||||
/** Border sides for annotations
|
||||
@ -586,6 +587,22 @@ class QgsComposerMapGrid : QgsComposerMapItem
|
||||
*/
|
||||
AnnotationFormat annotationFormat() const;
|
||||
|
||||
/** Sets the expression used for drawing grid annotations. This is only used when annotationFormat()
|
||||
* is QgsComposerMapGrid::CustomFormat.
|
||||
* @param expression expression for evaluating custom grid annotations
|
||||
* @see annotationExpression
|
||||
* @note added in QGIS 2.12
|
||||
*/
|
||||
void setAnnotationExpression( const QString& expression );
|
||||
|
||||
/** Returns the expression used for drawing grid annotations. This is only used when annotationFormat()
|
||||
* is QgsComposerMapGrid::CustomFormat.
|
||||
* @returns expression for evaluating custom grid annotations
|
||||
* @see setAnnotationExpression
|
||||
* @note added in QGIS 2.12
|
||||
*/
|
||||
QString annotationExpression() const;
|
||||
|
||||
//
|
||||
// GRID FRAME
|
||||
//
|
||||
@ -735,4 +752,6 @@ class QgsComposerMapGrid : QgsComposerMapItem
|
||||
*/
|
||||
QColor frameFillColor2() const;
|
||||
|
||||
virtual QgsExpressionContext* createExpressionContext() const;
|
||||
|
||||
};
|
||||
|
@ -74,14 +74,15 @@ QgsComposerMapWidget::QgsComposerMapWidget( QgsComposerMap* composerMap )
|
||||
insertFrameDisplayEntries( mFrameDivisionsTopComboBox );
|
||||
insertFrameDisplayEntries( mFrameDivisionsBottomComboBox );
|
||||
|
||||
mAnnotationFormatComboBox->insertItem( 0, tr( "Decimal" ) );
|
||||
mAnnotationFormatComboBox->insertItem( 1, tr( "Decimal with suffix" ) );
|
||||
mAnnotationFormatComboBox->insertItem( 2, tr( "Degree, minute" ) );
|
||||
mAnnotationFormatComboBox->insertItem( 3, tr( "Degree, minute with suffix" ) );
|
||||
mAnnotationFormatComboBox->insertItem( 4, tr( "Degree, minute aligned" ) );
|
||||
mAnnotationFormatComboBox->insertItem( 5, tr( "Degree, minute, second" ) );
|
||||
mAnnotationFormatComboBox->insertItem( 6, tr( "Degree, minute, second with suffix" ) );
|
||||
mAnnotationFormatComboBox->insertItem( 7, tr( "Degree, minute, second aligned" ) );
|
||||
mAnnotationFormatComboBox->addItem( tr( "Decimal" ), QgsComposerMapGrid::Decimal );
|
||||
mAnnotationFormatComboBox->addItem( tr( "Decimal with suffix" ), QgsComposerMapGrid::DecimalWithSuffix );
|
||||
mAnnotationFormatComboBox->addItem( tr( "Degree, minute" ), QgsComposerMapGrid::DegreeMinuteNoSuffix );
|
||||
mAnnotationFormatComboBox->addItem( tr( "Degree, minute with suffix" ), QgsComposerMapGrid::DegreeMinute );
|
||||
mAnnotationFormatComboBox->addItem( tr( "Degree, minute aligned" ), QgsComposerMapGrid::DegreeMinutePadded );
|
||||
mAnnotationFormatComboBox->addItem( tr( "Degree, minute, second" ), QgsComposerMapGrid::DegreeMinuteSecondNoSuffix );
|
||||
mAnnotationFormatComboBox->addItem( tr( "Degree, minute, second with suffix" ), QgsComposerMapGrid::DegreeMinuteSecond );
|
||||
mAnnotationFormatComboBox->addItem( tr( "Degree, minute, second aligned" ), QgsComposerMapGrid::DegreeMinuteSecondPadded );
|
||||
mAnnotationFormatComboBox->addItem( tr( "Custom" ), QgsComposerMapGrid::CustomFormat );
|
||||
|
||||
mAnnotationFontColorButton->setColorDialogTitle( tr( "Select font color" ) );
|
||||
mAnnotationFontColorButton->setAllowAlpha( true );
|
||||
@ -1494,34 +1495,8 @@ void QgsComposerMapWidget::setGridItems( const QgsComposerMapGrid* grid )
|
||||
|
||||
mAnnotationFontColorButton->setColor( grid->annotationFontColor() );
|
||||
|
||||
//mAnnotationFormatComboBox
|
||||
switch ( grid->annotationFormat() )
|
||||
{
|
||||
case QgsComposerMapGrid::Decimal:
|
||||
mAnnotationFormatComboBox->setCurrentIndex( 0 );
|
||||
break;
|
||||
case QgsComposerMapGrid::DegreeMinute:
|
||||
mAnnotationFormatComboBox->setCurrentIndex( 3 );
|
||||
break;
|
||||
case QgsComposerMapGrid::DegreeMinuteSecond:
|
||||
mAnnotationFormatComboBox->setCurrentIndex( 6 );
|
||||
break;
|
||||
case QgsComposerMapGrid::DecimalWithSuffix:
|
||||
mAnnotationFormatComboBox->setCurrentIndex( 1 );
|
||||
break;
|
||||
case QgsComposerMapGrid::DegreeMinuteNoSuffix:
|
||||
mAnnotationFormatComboBox->setCurrentIndex( 2 );
|
||||
break;
|
||||
case QgsComposerMapGrid::DegreeMinutePadded:
|
||||
mAnnotationFormatComboBox->setCurrentIndex( 4 );
|
||||
break;
|
||||
case QgsComposerMapGrid::DegreeMinuteSecondNoSuffix:
|
||||
mAnnotationFormatComboBox->setCurrentIndex( 5 );
|
||||
break;
|
||||
case QgsComposerMapGrid::DegreeMinuteSecondPadded:
|
||||
mAnnotationFormatComboBox->setCurrentIndex( 7 );
|
||||
break;
|
||||
}
|
||||
mAnnotationFormatComboBox->setCurrentIndex( mAnnotationFormatComboBox->findData( grid->annotationFormat() ) );
|
||||
mAnnotationFormatButton->setEnabled( grid->annotationFormat() == QgsComposerMapGrid::CustomFormat );
|
||||
mDistanceToMapFrameSpinBox->setValue( grid->annotationFrameDistance() );
|
||||
mCoordinatePrecisionSpinBox->setValue( grid->annotationPrecision() );
|
||||
|
||||
@ -2023,6 +1998,30 @@ void QgsComposerMapWidget::on_mDrawAnnotationGroupBox_toggled( bool state )
|
||||
mComposerMap->endCommand();
|
||||
}
|
||||
|
||||
void QgsComposerMapWidget::on_mAnnotationFormatButton_clicked()
|
||||
{
|
||||
QgsComposerMapGrid* grid = currentGrid();
|
||||
if ( !grid )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
QScopedPointer< QgsExpressionContext> expressionContext( grid->createExpressionContext() );
|
||||
|
||||
QgsExpressionBuilderDialog exprDlg( 0, grid->annotationExpression(), this, "generic", *expressionContext );
|
||||
exprDlg.setWindowTitle( tr( "Expression based annotation" ) );
|
||||
|
||||
if ( exprDlg.exec() == QDialog::Accepted )
|
||||
{
|
||||
QString expression = exprDlg.expressionText();
|
||||
mComposerMap->beginCommand( tr( "Annotation format changed" ) );
|
||||
grid->setAnnotationExpression( expression );
|
||||
mComposerMap->updateBoundingRect();
|
||||
mComposerMap->update();
|
||||
mComposerMap->endCommand();
|
||||
}
|
||||
}
|
||||
|
||||
void QgsComposerMapWidget::on_mAnnotationDisplayLeftComboBox_currentIndexChanged( const QString &text )
|
||||
{
|
||||
handleChangedAnnotationDisplay( QgsComposerMapGrid::Left, text );
|
||||
@ -2142,41 +2141,14 @@ void QgsComposerMapWidget::on_mAnnotationFormatComboBox_currentIndexChanged( int
|
||||
|
||||
mComposerMap->beginCommand( tr( "Annotation format changed" ) );
|
||||
|
||||
switch ( index )
|
||||
{
|
||||
case 0:
|
||||
grid->setAnnotationFormat( QgsComposerMapGrid::Decimal );
|
||||
break;
|
||||
case 3:
|
||||
grid->setAnnotationFormat( QgsComposerMapGrid::DegreeMinute );
|
||||
break;
|
||||
case 6:
|
||||
grid->setAnnotationFormat( QgsComposerMapGrid::DegreeMinuteSecond );
|
||||
break;
|
||||
case 1:
|
||||
grid->setAnnotationFormat( QgsComposerMapGrid::DecimalWithSuffix );
|
||||
break;
|
||||
case 2:
|
||||
grid->setAnnotationFormat( QgsComposerMapGrid::DegreeMinuteNoSuffix );
|
||||
break;
|
||||
case 4:
|
||||
grid->setAnnotationFormat( QgsComposerMapGrid::DegreeMinutePadded );
|
||||
break;
|
||||
case 5:
|
||||
grid->setAnnotationFormat( QgsComposerMapGrid::DegreeMinuteSecondNoSuffix );
|
||||
break;
|
||||
case 7:
|
||||
grid->setAnnotationFormat( QgsComposerMapGrid::DegreeMinuteSecondPadded );
|
||||
break;
|
||||
}
|
||||
grid->setAnnotationFormat(( QgsComposerMapGrid::AnnotationFormat )mAnnotationFormatComboBox->itemData( index ).toInt() );
|
||||
mAnnotationFormatButton->setEnabled( grid->annotationFormat() == QgsComposerMapGrid::CustomFormat );
|
||||
|
||||
mComposerMap->updateBoundingRect();
|
||||
mComposerMap->update();
|
||||
mComposerMap->endCommand();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void QgsComposerMapWidget::on_mCoordinatePrecisionSpinBox_valueChanged( int value )
|
||||
{
|
||||
QgsComposerMapGrid* grid = currentGrid();
|
||||
|
@ -106,6 +106,7 @@ class QgsComposerMapWidget: public QgsComposerItemBaseWidget, private Ui::QgsCom
|
||||
void on_mFrameDivisionsBottomComboBox_currentIndexChanged( int index );
|
||||
|
||||
void on_mDrawAnnotationGroupBox_toggled( bool state );
|
||||
void on_mAnnotationFormatButton_clicked();
|
||||
|
||||
//annotation display
|
||||
void on_mAnnotationDisplayLeftComboBox_currentIndexChanged( const QString& text );
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include "qgscoordinatereferencesystem.h"
|
||||
#include "qgslogger.h"
|
||||
#include "qgsfontutils.h"
|
||||
#include "qgsexpressioncontext.h"
|
||||
|
||||
#include <QPainter>
|
||||
#include <QPen>
|
||||
@ -296,6 +297,7 @@ bool QgsComposerMapGrid::writeXML( QDomElement& elem, QDomDocument& doc ) const
|
||||
|
||||
mapGridElem.setAttribute( "annotationFormat", mGridAnnotationFormat );
|
||||
mapGridElem.setAttribute( "showAnnotation", mShowGridAnnotation );
|
||||
mapGridElem.setAttribute( "annotationExpression", mGridAnnotationExpressionString );
|
||||
mapGridElem.setAttribute( "leftAnnotationDisplay", mLeftGridAnnotationDisplay );
|
||||
mapGridElem.setAttribute( "rightAnnotationDisplay", mRightGridAnnotationDisplay );
|
||||
mapGridElem.setAttribute( "topAnnotationDisplay", mTopGridAnnotationDisplay );
|
||||
@ -395,6 +397,8 @@ bool QgsComposerMapGrid::readXML( const QDomElement& itemElem, const QDomDocumen
|
||||
//annotation
|
||||
mShowGridAnnotation = ( itemElem.attribute( "showAnnotation", "0" ) != "0" );
|
||||
mGridAnnotationFormat = QgsComposerMapGrid::AnnotationFormat( itemElem.attribute( "annotationFormat", "0" ).toInt() );
|
||||
mGridAnnotationExpressionString = itemElem.attribute( "annotationExpression" );
|
||||
mGridAnnotationExpression.reset();
|
||||
mLeftGridAnnotationPosition = QgsComposerMapGrid::AnnotationPosition( itemElem.attribute( "leftAnnotationPosition", "0" ).toInt() );
|
||||
mRightGridAnnotationPosition = QgsComposerMapGrid::AnnotationPosition( itemElem.attribute( "rightAnnotationPosition", "0" ).toInt() );
|
||||
mTopGridAnnotationPosition = QgsComposerMapGrid::AnnotationPosition( itemElem.attribute( "topAnnotationPosition", "0" ).toInt() );
|
||||
@ -689,7 +693,7 @@ void QgsComposerMapGrid::draw( QPainter* p )
|
||||
|
||||
if ( mShowGridAnnotation )
|
||||
{
|
||||
drawCoordinateAnnotations( p, horizontalLines, verticalLines );
|
||||
drawCoordinateAnnotations( p, horizontalLines, verticalLines, context.expressionContext() );
|
||||
}
|
||||
}
|
||||
|
||||
@ -1037,7 +1041,7 @@ void QgsComposerMapGrid::drawGridFrameLineBorder( QPainter* p, QgsComposerMapGri
|
||||
}
|
||||
}
|
||||
|
||||
void QgsComposerMapGrid::drawCoordinateAnnotations( QPainter* p, const QList< QPair< double, QLineF > >& hLines, const QList< QPair< double, QLineF > >& vLines ) const
|
||||
void QgsComposerMapGrid::drawCoordinateAnnotations( QPainter* p, const QList< QPair< double, QLineF > >& hLines, const QList< QPair< double, QLineF > >& vLines, QgsExpressionContext &expressionContext ) const
|
||||
{
|
||||
if ( !p )
|
||||
{
|
||||
@ -1048,7 +1052,7 @@ void QgsComposerMapGrid::drawCoordinateAnnotations( QPainter* p, const QList< QP
|
||||
QList< QPair< double, QLineF > >::const_iterator it = hLines.constBegin();
|
||||
for ( ; it != hLines.constEnd(); ++it )
|
||||
{
|
||||
currentAnnotationString = gridAnnotationString( it->first, QgsComposerMapGrid::Latitude );
|
||||
currentAnnotationString = gridAnnotationString( it->first, QgsComposerMapGrid::Latitude, expressionContext );
|
||||
drawCoordinateAnnotation( p, it->second.p1(), currentAnnotationString, QgsComposerMapGrid::Latitude );
|
||||
drawCoordinateAnnotation( p, it->second.p2(), currentAnnotationString, QgsComposerMapGrid::Latitude );
|
||||
}
|
||||
@ -1056,7 +1060,7 @@ void QgsComposerMapGrid::drawCoordinateAnnotations( QPainter* p, const QList< QP
|
||||
it = vLines.constBegin();
|
||||
for ( ; it != vLines.constEnd(); ++it )
|
||||
{
|
||||
currentAnnotationString = gridAnnotationString( it->first, QgsComposerMapGrid::Longitude );
|
||||
currentAnnotationString = gridAnnotationString( it->first, QgsComposerMapGrid::Longitude, expressionContext );
|
||||
drawCoordinateAnnotation( p, it->second.p1(), currentAnnotationString, QgsComposerMapGrid::Longitude );
|
||||
drawCoordinateAnnotation( p, it->second.p2(), currentAnnotationString, QgsComposerMapGrid::Longitude );
|
||||
}
|
||||
@ -1369,7 +1373,7 @@ void QgsComposerMapGrid::drawAnnotation( QPainter* p, const QPointF& pos, int ro
|
||||
p->restore();
|
||||
}
|
||||
|
||||
QString QgsComposerMapGrid::gridAnnotationString( double value, QgsComposerMapGrid::AnnotationCoordinate coord ) const
|
||||
QString QgsComposerMapGrid::gridAnnotationString( double value, QgsComposerMapGrid::AnnotationCoordinate coord, QgsExpressionContext &expressionContext ) const
|
||||
{
|
||||
//check if we are using degrees (ie, geographic crs)
|
||||
bool geographic = false;
|
||||
@ -1432,6 +1436,17 @@ QString QgsComposerMapGrid::gridAnnotationString( double value, QgsComposerMapGr
|
||||
return QString::number( qAbs( value ), 'f', mGridAnnotationPrecision ) + hemisphere;
|
||||
}
|
||||
}
|
||||
else if ( mGridAnnotationFormat == CustomFormat )
|
||||
{
|
||||
expressionContext.lastScope()->setVariable( "grid_number", value );
|
||||
expressionContext.lastScope()->setVariable( "grid_axis", coord == QgsComposerMapGrid::Longitude ? "x" : "y" );
|
||||
if ( !mGridAnnotationExpression.data() )
|
||||
{
|
||||
mGridAnnotationExpression.reset( new QgsExpression( mGridAnnotationExpressionString ) );
|
||||
mGridAnnotationExpression->prepare( &expressionContext );
|
||||
}
|
||||
return mGridAnnotationExpression->evaluate( &expressionContext ).toString();
|
||||
}
|
||||
|
||||
QgsPoint p;
|
||||
p.setX( coord == QgsComposerMapGrid::Longitude ? value : 0 );
|
||||
@ -2008,6 +2023,9 @@ double QgsComposerMapGrid::maxExtension() const
|
||||
}
|
||||
|
||||
const QgsMapSettings& ms = mComposerMap->composition()->mapSettings();
|
||||
|
||||
QScopedPointer< QgsExpressionContext> expressionContext( createExpressionContext() );
|
||||
|
||||
QStringList coordStrings;
|
||||
if ( mCRS.isValid() && mCRS != ms.destinationCrs() )
|
||||
{
|
||||
@ -2030,12 +2048,12 @@ double QgsComposerMapGrid::maxExtension() const
|
||||
QList< QPair< double, QPolygonF > >::const_iterator it = xGridLines.constBegin();
|
||||
for ( ; it != xGridLines.constEnd(); ++it )
|
||||
{
|
||||
coordStrings.append( gridAnnotationString( it->first, QgsComposerMapGrid::Latitude ) );
|
||||
coordStrings.append( gridAnnotationString( it->first, QgsComposerMapGrid::Latitude, *expressionContext ) );
|
||||
}
|
||||
it = yGridLines.constBegin();
|
||||
for ( ; it != yGridLines.constEnd(); ++it )
|
||||
{
|
||||
coordStrings.append( gridAnnotationString( it->first, QgsComposerMapGrid::Longitude ) );
|
||||
coordStrings.append( gridAnnotationString( it->first, QgsComposerMapGrid::Longitude, *expressionContext ) );
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -2052,13 +2070,13 @@ double QgsComposerMapGrid::maxExtension() const
|
||||
QList< QPair< double, QLineF > >::const_iterator it = xLines.constBegin();
|
||||
for ( ; it != xLines.constEnd(); ++it )
|
||||
{
|
||||
coordStrings.append( gridAnnotationString( it->first, QgsComposerMapGrid::Latitude ) );
|
||||
coordStrings.append( gridAnnotationString( it->first, QgsComposerMapGrid::Latitude, *expressionContext ) );
|
||||
}
|
||||
|
||||
it = yLines.constBegin();
|
||||
for ( ; it != yLines.constEnd(); ++it )
|
||||
{
|
||||
coordStrings.append( gridAnnotationString( it->first, QgsComposerMapGrid::Longitude ) );
|
||||
coordStrings.append( gridAnnotationString( it->first, QgsComposerMapGrid::Longitude, *expressionContext ) );
|
||||
}
|
||||
}
|
||||
|
||||
@ -2183,6 +2201,16 @@ QgsComposerMapGrid::FrameSideFlags QgsComposerMapGrid::frameSideFlags() const
|
||||
return mGridFrameSides;
|
||||
}
|
||||
|
||||
QgsExpressionContext* QgsComposerMapGrid::createExpressionContext() const
|
||||
{
|
||||
QgsExpressionContext* context = QgsComposerObject::createExpressionContext();
|
||||
context->appendScope( new QgsExpressionContextScope( tr( "Grid" ) ) );
|
||||
context->lastScope()->setVariable( "grid_number", 0 );
|
||||
context->lastScope()->setVariable( "grid_axis", "x" );
|
||||
context->setHighlightedVariables( QStringList() << "grid_number" << "grid_axis" );
|
||||
return context;
|
||||
}
|
||||
|
||||
bool QgsComposerMapGrid::testFrameSideFlag( QgsComposerMapGrid::FrameSideFlag flag ) const
|
||||
{
|
||||
return mGridFrameSides.testFlag( flag );
|
||||
|
@ -213,9 +213,10 @@ class CORE_EXPORT QgsComposerMapGrid : public QgsComposerMapItem
|
||||
DegreeMinuteSecond, /*!< degree/minutes/seconds, use NSEW suffix */
|
||||
DecimalWithSuffix, /*!< decimal degrees, use NSEW suffix */
|
||||
DegreeMinuteNoSuffix, /*!< degree/minutes, use - for S/W coordinates */
|
||||
DegreeMinutePadded, /*!< degree/minutes, with minutes using leading zeros were required */
|
||||
DegreeMinutePadded, /*!< degree/minutes, with minutes using leading zeros where required */
|
||||
DegreeMinuteSecondNoSuffix, /*!< degree/minutes/seconds, use - for S/W coordinates */
|
||||
DegreeMinuteSecondPadded /*!< degree/minutes/seconds, with minutes using leading zeros were required */
|
||||
DegreeMinuteSecondPadded, /*!< degree/minutes/seconds, with minutes using leading zeros where required */
|
||||
CustomFormat /*!< custom expression-based format */
|
||||
};
|
||||
|
||||
/** Border sides for annotations
|
||||
@ -635,6 +636,22 @@ class CORE_EXPORT QgsComposerMapGrid : public QgsComposerMapItem
|
||||
*/
|
||||
AnnotationFormat annotationFormat() const { return mGridAnnotationFormat; }
|
||||
|
||||
/** Sets the expression used for drawing grid annotations. This is only used when annotationFormat()
|
||||
* is QgsComposerMapGrid::CustomFormat.
|
||||
* @param expression expression for evaluating custom grid annotations
|
||||
* @see annotationExpression
|
||||
* @note added in QGIS 2.12
|
||||
*/
|
||||
void setAnnotationExpression( const QString& expression ) { mGridAnnotationExpressionString = expression; mGridAnnotationExpression.reset(); }
|
||||
|
||||
/** Returns the expression used for drawing grid annotations. This is only used when annotationFormat()
|
||||
* is QgsComposerMapGrid::CustomFormat.
|
||||
* @returns expression for evaluating custom grid annotations
|
||||
* @see setAnnotationExpression
|
||||
* @note added in QGIS 2.12
|
||||
*/
|
||||
QString annotationExpression() const { return mGridAnnotationExpressionString; }
|
||||
|
||||
//
|
||||
// GRID FRAME
|
||||
//
|
||||
@ -784,6 +801,8 @@ class CORE_EXPORT QgsComposerMapGrid : public QgsComposerMapItem
|
||||
*/
|
||||
QColor frameFillColor2() const { return mGridFrameFillColor2; }
|
||||
|
||||
virtual QgsExpressionContext* createExpressionContext() const override;
|
||||
|
||||
private:
|
||||
|
||||
QgsComposerMapGrid(); //forbidden
|
||||
@ -840,6 +859,10 @@ class CORE_EXPORT QgsComposerMapGrid : public QgsComposerMapItem
|
||||
/** Annotation direction on bottom side ( horizontal or vertical )*/
|
||||
AnnotationDirection mBottomGridAnnotationDirection;
|
||||
AnnotationFormat mGridAnnotationFormat;
|
||||
|
||||
QString mGridAnnotationExpressionString;
|
||||
mutable QScopedPointer< QgsExpression > mGridAnnotationExpression;
|
||||
|
||||
FrameStyle mGridFrameStyle;
|
||||
FrameSideFlags mGridFrameSides;
|
||||
double mGridFrameWidth;
|
||||
@ -889,8 +912,10 @@ class CORE_EXPORT QgsComposerMapGrid : public QgsComposerMapItem
|
||||
/** Draw coordinates for mGridAnnotationType Coordinate
|
||||
@param p drawing painter
|
||||
@param hLines horizontal coordinate lines in item coordinates
|
||||
@param vLines vertical coordinate lines in item coordinates*/
|
||||
void drawCoordinateAnnotations( QPainter* p, const QList< QPair< double, QLineF > >& hLines, const QList< QPair< double, QLineF > >& vLines ) const;
|
||||
@param vLines vertical coordinate lines in item coordinates
|
||||
@param expressionContext expression context for evaluating custom annotation formats
|
||||
*/
|
||||
void drawCoordinateAnnotations( QPainter* p, const QList< QPair< double, QLineF > >& hLines, const QList< QPair< double, QLineF > >& vLines, QgsExpressionContext& expressionContext ) const;
|
||||
|
||||
void drawCoordinateAnnotation( QPainter* p, const QPointF& pos, QString annotationString, const AnnotationCoordinate coordinateType ) const;
|
||||
|
||||
@ -902,7 +927,7 @@ class CORE_EXPORT QgsComposerMapGrid : public QgsComposerMapItem
|
||||
*/
|
||||
void drawAnnotation( QPainter* p, const QPointF& pos, int rotation, const QString& annotationText ) const;
|
||||
|
||||
QString gridAnnotationString( double value, AnnotationCoordinate coord ) const;
|
||||
QString gridAnnotationString( double value, AnnotationCoordinate coord, QgsExpressionContext& expressionContext ) const;
|
||||
|
||||
/** Returns the grid lines with associated coordinate value
|
||||
@return 0 in case of success*/
|
||||
|
@ -3245,6 +3245,8 @@ void QgsExpression::initVariableHelp()
|
||||
gVariableHelpTexts.insert( "map_scale", QCoreApplication::translate( "variable_help", "Current scale of map." ) );
|
||||
|
||||
gVariableHelpTexts.insert( "row_number", QCoreApplication::translate( "variable_help", "Stores the number of the current row." ) );
|
||||
gVariableHelpTexts.insert( "grid_number", QCoreApplication::translate( "variable_help", "Current grid annotation value." ) );
|
||||
gVariableHelpTexts.insert( "grid_axis", QCoreApplication::translate( "variable_help", "Current grid annotation axis (eg, 'x' for longitude, 'y' for latitude)." ) );
|
||||
}
|
||||
|
||||
QString QgsExpression::variableHelpText( const QString &variableName, bool showValue, const QVariant &value )
|
||||
|
@ -23,16 +23,7 @@
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<property name="margin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
@ -63,8 +54,8 @@
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>446</width>
|
||||
<y>-1446</y>
|
||||
<width>444</width>
|
||||
<height>2493</height>
|
||||
</rect>
|
||||
</property>
|
||||
@ -1076,9 +1067,6 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QComboBox" name="mAnnotationFormatComboBox"/>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QComboBox" name="mAnnotationPositionLeftComboBox"/>
|
||||
</item>
|
||||
@ -1218,6 +1206,24 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_13">
|
||||
<item>
|
||||
<widget class="QComboBox" name="mAnnotationFormatComboBox"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="mAnnotationFormatButton">
|
||||
<property name="text">
|
||||
<string>...</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../../../images/images.qrc">
|
||||
<normaloff>:/images/themes/default/mIconExpression.svg</normaloff>:/images/themes/default/mIconExpression.svg</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
@ -1498,6 +1504,7 @@
|
||||
<tabstop>mCheckGridBottomSide</tabstop>
|
||||
<tabstop>mDrawAnnotationGroupBox</tabstop>
|
||||
<tabstop>mAnnotationFormatComboBox</tabstop>
|
||||
<tabstop>mAnnotationFormatButton</tabstop>
|
||||
<tabstop>mAnnotationDisplayLeftComboBox</tabstop>
|
||||
<tabstop>mAnnotationPositionLeftComboBox</tabstop>
|
||||
<tabstop>mAnnotationDirectionComboBoxLeft</tabstop>
|
||||
|
@ -640,26 +640,33 @@ void TestQgsComposerMapGrid::annotationFormats()
|
||||
gridProjected.setAnnotationFormat( QgsComposerMapGrid::DecimalWithSuffix );
|
||||
gridProjected.setAnnotationPrecision( 1 );
|
||||
|
||||
QScopedPointer< QgsExpressionContext> expressionContext( gridGeographic.createExpressionContext() );
|
||||
|
||||
//normal e/w
|
||||
QCOMPARE( gridGeographic.gridAnnotationString( 90, QgsComposerMapGrid::Longitude ), QString( "90.0" ) + QChar( 176 ) + QString( "E" ) );
|
||||
QCOMPARE( gridProjected.gridAnnotationString( 90, QgsComposerMapGrid::Longitude ), QString( "90.0E" ) );
|
||||
QCOMPARE( gridGeographic.gridAnnotationString( 90, QgsComposerMapGrid::Longitude, *expressionContext ), QString( "90.0" ) + QChar( 176 ) + QString( "E" ) );
|
||||
QCOMPARE( gridProjected.gridAnnotationString( 90, QgsComposerMapGrid::Longitude, *expressionContext ), QString( "90.0E" ) );
|
||||
|
||||
//0 degrees
|
||||
QCOMPARE( gridGeographic.gridAnnotationString( 0, QgsComposerMapGrid::Longitude ), QString( "0.0" ) + QChar( 176 ) );
|
||||
QCOMPARE( gridProjected.gridAnnotationString( 0, QgsComposerMapGrid::Longitude ), QString( "0.0E" ) );
|
||||
QCOMPARE( gridGeographic.gridAnnotationString( 0, QgsComposerMapGrid::Longitude, *expressionContext ), QString( "0.0" ) + QChar( 176 ) );
|
||||
QCOMPARE( gridProjected.gridAnnotationString( 0, QgsComposerMapGrid::Longitude, *expressionContext ), QString( "0.0E" ) );
|
||||
|
||||
//180 degrees
|
||||
QCOMPARE( gridGeographic.gridAnnotationString( 180, QgsComposerMapGrid::Longitude ), QString( "180.0" ) + QChar( 176 ) );
|
||||
QCOMPARE( gridProjected.gridAnnotationString( 180, QgsComposerMapGrid::Longitude ), QString( "180.0E" ) );
|
||||
QCOMPARE( gridGeographic.gridAnnotationString( 180, QgsComposerMapGrid::Longitude, *expressionContext ), QString( "180.0" ) + QChar( 176 ) );
|
||||
QCOMPARE( gridProjected.gridAnnotationString( 180, QgsComposerMapGrid::Longitude, *expressionContext ), QString( "180.0E" ) );
|
||||
|
||||
//normal n/s
|
||||
QCOMPARE( gridGeographic.gridAnnotationString( 45, QgsComposerMapGrid::Latitude ), QString( "45.0" ) + QChar( 176 ) + QString( "N" ) );
|
||||
QCOMPARE( gridProjected.gridAnnotationString( 45, QgsComposerMapGrid::Latitude ), QString( "45.0N" ) );
|
||||
QCOMPARE( gridGeographic.gridAnnotationString( 45, QgsComposerMapGrid::Latitude, *expressionContext ), QString( "45.0" ) + QChar( 176 ) + QString( "N" ) );
|
||||
QCOMPARE( gridProjected.gridAnnotationString( 45, QgsComposerMapGrid::Latitude, *expressionContext ), QString( "45.0N" ) );
|
||||
|
||||
//0 north/south
|
||||
QCOMPARE( gridGeographic.gridAnnotationString( 0, QgsComposerMapGrid::Latitude ), QString( "0.0" ) + QChar( 176 ) );
|
||||
QCOMPARE( gridProjected.gridAnnotationString( 0, QgsComposerMapGrid::Latitude ), QString( "0.0N" ) );
|
||||
QCOMPARE( gridGeographic.gridAnnotationString( 0, QgsComposerMapGrid::Latitude, *expressionContext ), QString( "0.0" ) + QChar( 176 ) );
|
||||
QCOMPARE( gridProjected.gridAnnotationString( 0, QgsComposerMapGrid::Latitude, *expressionContext ), QString( "0.0N" ) );
|
||||
|
||||
//Custom format annotations
|
||||
gridProjected.setAnnotationFormat( QgsComposerMapGrid::CustomFormat );
|
||||
gridProjected.setAnnotationExpression( "(@grid_number/10) || case when @grid_axis ='x' then 'a' else 'b' end" );
|
||||
QCOMPARE( gridProjected.gridAnnotationString( 45, QgsComposerMapGrid::Latitude, *expressionContext ), QString( "4.5b" ) );
|
||||
QCOMPARE( gridProjected.gridAnnotationString( 33, QgsComposerMapGrid::Longitude, *expressionContext ), QString( "3.3a" ) );
|
||||
}
|
||||
|
||||
void TestQgsComposerMapGrid::descendingAnnotations()
|
||||
|
Loading…
x
Reference in New Issue
Block a user