26
26
#include " qgslayouteffect.h"
27
27
#include " qgslayoutundostack.h"
28
28
#include " qgslayoutpagecollection.h"
29
+ #include " qgslayoutitempage.h"
29
30
#include < QPainter>
30
31
#include < QStyleOptionGraphicsItem>
31
32
#include < QUuid>
@@ -932,6 +933,37 @@ QgsLayoutPoint QgsLayoutItem::applyDataDefinedPosition( const QgsLayoutPoint &po
932
933
return QgsLayoutPoint ( evaluatedX, evaluatedY, position.units () );
933
934
}
934
935
936
+ void QgsLayoutItem::applyDataDefinedOrientation ( double &width, double &height, const QgsExpressionContext &context )
937
+ {
938
+ bool ok = false ;
939
+ QString orientationString = mDataDefinedProperties .valueAsString ( QgsLayoutObject::PaperOrientation, context, QString (), &ok );
940
+ if ( ok && !orientationString.isEmpty () )
941
+ {
942
+ QgsLayoutItemPage::Orientation orientation = QgsLayoutUtils::decodePaperOrientation ( orientationString, ok );
943
+ if ( ok )
944
+ {
945
+ double heightD, widthD;
946
+ switch ( orientation )
947
+ {
948
+ case QgsLayoutItemPage::Portrait:
949
+ {
950
+ heightD = std::max ( height, width );
951
+ widthD = std::min ( height, width );
952
+ break ;
953
+ }
954
+ case QgsLayoutItemPage::Landscape:
955
+ {
956
+ heightD = std::min ( height, width );
957
+ widthD = std::max ( height, width );
958
+ break ;
959
+ }
960
+ }
961
+ width = widthD;
962
+ height = heightD;
963
+ }
964
+ }
965
+ }
966
+
935
967
QgsLayoutSize QgsLayoutItem::applyDataDefinedSize ( const QgsLayoutSize &size )
936
968
{
937
969
if ( !mLayout )
@@ -941,7 +973,8 @@ QgsLayoutSize QgsLayoutItem::applyDataDefinedSize( const QgsLayoutSize &size )
941
973
942
974
if ( !mDataDefinedProperties .isActive ( QgsLayoutObject::PresetPaperSize ) &&
943
975
!mDataDefinedProperties .isActive ( QgsLayoutObject::ItemWidth ) &&
944
- !mDataDefinedProperties .isActive ( QgsLayoutObject::ItemHeight ) )
976
+ !mDataDefinedProperties .isActive ( QgsLayoutObject::ItemHeight ) &&
977
+ !mDataDefinedProperties .isActive ( QgsLayoutObject::PaperOrientation ) )
945
978
return size;
946
979
947
980
@@ -962,6 +995,10 @@ QgsLayoutSize QgsLayoutItem::applyDataDefinedSize( const QgsLayoutSize &size )
962
995
// highest priority is dd width/height
963
996
evaluatedWidth = mDataDefinedProperties .valueAsDouble ( QgsLayoutObject::ItemWidth, context, evaluatedWidth );
964
997
evaluatedHeight = mDataDefinedProperties .valueAsDouble ( QgsLayoutObject::ItemHeight, context, evaluatedHeight );
998
+
999
+ // which is finally overwritten by data defined orientation
1000
+ applyDataDefinedOrientation ( evaluatedWidth, evaluatedHeight, context );
1001
+
965
1002
return QgsLayoutSize ( evaluatedWidth, evaluatedHeight, size.units () );
966
1003
}
967
1004
0 commit comments