Skip to content

Commit

Permalink
rotated ticks followup : add some data defined settings (just one)
Browse files Browse the repository at this point in the history
  • Loading branch information
olivierdalang authored and nyalldawson committed Oct 7, 2020
1 parent a251699 commit a85b6c5
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 71 deletions.
26 changes: 25 additions & 1 deletion src/core/layout/qgslayoutitemmapgrid.cpp
Expand Up @@ -15,6 +15,7 @@
* *
***************************************************************************/

#include "qgsmessagelog.h"
#include "qgslayoutitemmapgrid.h"
#include "qgslayoututils.h"
#include "qgsclipper.h"
Expand Down Expand Up @@ -1892,7 +1893,7 @@ bool QgsLayoutItemMapGrid::shouldShowAnnotationForSide( QgsLayoutItemMapGrid::An
switch ( side )
{
case QgsLayoutItemMapGrid::Left:
return shouldShowForDisplayMode( coordinate, mLeftGridAnnotationDisplay );
return shouldShowForDisplayMode( coordinate, mEvaluatedLeftGridAnnotationDisplay );
case QgsLayoutItemMapGrid::Right:
return shouldShowForDisplayMode( coordinate, mRightGridAnnotationDisplay );
case QgsLayoutItemMapGrid::Top:
Expand All @@ -1910,6 +1911,19 @@ bool QgsLayoutItemMapGrid::shouldShowForDisplayMode( QgsLayoutItemMapGrid::Annot
|| ( mode == QgsLayoutItemMapGrid::LongitudeOnly && coordinate == QgsLayoutItemMapGrid::Longitude );
}

/*
QgsLayoutItemMapGrid::DisplayMode gridAnnotationDisplayModeFromDD(QString ddValue) {
if( ddValue == QStringLiteral("x_only") )
return QgsLayoutItemMapGrid::LatitudeOnly;
else if ( ddValue == QStringLiteral("y_only") )
return QgsLayoutItemMapGrid::LongitudeOnly;
else if ( ddValue == QStringLiteral("disabled") )
return QgsLayoutItemMapGrid::HideAll;
else // if ( ddValue == QStringLiteral("all") )
return QgsLayoutItemMapGrid::ShowAll;
}
*/

void QgsLayoutItemMapGrid::refreshDataDefinedProperties()
{
QgsExpressionContext context = createExpressionContext();
Expand Down Expand Up @@ -1952,6 +1966,16 @@ void QgsLayoutItemMapGrid::refreshDataDefinedProperties()
mEvaluatedAnnotationFrameDistance = mDataDefinedProperties.valueAsDouble( QgsLayoutObject::MapGridLabelDistance, context, mAnnotationFrameDistance );
mEvaluatedCrossLength = mDataDefinedProperties.valueAsDouble( QgsLayoutObject::MapGridCrossSize, context, mCrossLength );
mEvaluatedGridFrameLineThickness = mDataDefinedProperties.valueAsDouble( QgsLayoutObject::MapGridFrameLineThickness, context, mGridFramePenThickness );
QString leftGridAnnotationDisplayStr = mDataDefinedProperties.valueAsString( QgsLayoutObject::MapGridAnnotationDisplayLeft, context, QStringLiteral("all") );
QgsMessageLog::logMessage(QStringLiteral("DEBUG MAPGRID : ") + leftGridAnnotationDisplayStr, QStringLiteral("DEBUGDEBUG"));
if( leftGridAnnotationDisplayStr == QStringLiteral("x_only") )
mEvaluatedLeftGridAnnotationDisplay = LatitudeOnly;
else if ( leftGridAnnotationDisplayStr == QStringLiteral("y_only") )
mEvaluatedLeftGridAnnotationDisplay = LongitudeOnly;
else if ( leftGridAnnotationDisplayStr == QStringLiteral("disabled") )
mEvaluatedLeftGridAnnotationDisplay = HideAll;
else // if ( leftGridAnnotationDisplayStr == QStringLiteral("all") )
mEvaluatedLeftGridAnnotationDisplay = ShowAll;
}

double QgsLayoutItemMapGrid::mapWidth() const
Expand Down
1 change: 1 addition & 0 deletions src/core/layout/qgslayoutitemmapgrid.h
Expand Up @@ -1186,6 +1186,7 @@ class CORE_EXPORT QgsLayoutItemMapGrid : public QgsLayoutItemMapItem
double mEvaluatedAnnotationFrameDistance = 0;
double mEvaluatedCrossLength = 0;
double mEvaluatedGridFrameLineThickness = 0;
DisplayMode mEvaluatedLeftGridAnnotationDisplay = QgsLayoutItemMapGrid::ShowAll;

/**
* Updates the grid lines annotation positions
Expand Down
1 change: 1 addition & 0 deletions src/core/layout/qgslayoutobject.cpp
Expand Up @@ -78,6 +78,7 @@ void QgsLayoutObject::initPropertyDefinitions()
{ QgsLayoutObject::MapGridCrossSize, QgsPropertyDefinition( "dataDefinedMapGridCrossSize", QObject::tr( "Grid cross size" ), QgsPropertyDefinition::DoublePositive ) },
{ QgsLayoutObject::MapGridFrameMargin, QgsPropertyDefinition( "dataDefinedMapGridFrameMargin", QObject::tr( "Grid frame margin" ), QgsPropertyDefinition::DoublePositive ) },
{ QgsLayoutObject::MapGridLabelDistance, QgsPropertyDefinition( "dataDefinedMapGridLabelDistance", QObject::tr( "Grid label distance" ), QgsPropertyDefinition::DoublePositive ) },
{ QgsLayoutObject::MapGridAnnotationDisplayLeft, QgsPropertyDefinition( "dataDefinedMapGridAnnotationDisplayLeft", QgsPropertyDefinition::DataTypeString, QObject::tr( "Map grid annotation display left" ), QObject::tr( "string " ) + QLatin1String( "[<b>all</b>|<b>x_only</b>|<b>y_only</b>|<b>disabled</b>]" ) ) },
{ QgsLayoutObject::PictureSource, QgsPropertyDefinition( "dataDefinedSource", QObject::tr( "Picture source (URL)" ), QgsPropertyDefinition::String ) },
{ QgsLayoutObject::SourceUrl, QgsPropertyDefinition( "dataDefinedSourceUrl", QObject::tr( "Source URL" ), QgsPropertyDefinition::String ) },
{ QgsLayoutObject::PictureSvgBackgroundColor, QgsPropertyDefinition( "dataDefinedSvgBackgroundColor", QObject::tr( "SVG background color" ), QgsPropertyDefinition::ColorWithAlpha ) },
Expand Down
1 change: 1 addition & 0 deletions src/core/layout/qgslayoutobject.h
Expand Up @@ -174,6 +174,7 @@ class CORE_EXPORT QgsLayoutObject: public QObject, public QgsExpressionContextGe
MapGridLabelDistance, //!< Map grid label distance
MapGridCrossSize, //!< Map grid cross size
MapGridFrameLineThickness, //!< Map grid frame line thickness
MapGridAnnotationDisplayLeft, //!< Map annotation display left
//composer picture
PictureSource, //!< Picture source url
PictureSvgBackgroundColor, //!< SVG background color
Expand Down
2 changes: 2 additions & 0 deletions src/gui/layout/qgslayoutmapgridwidget.cpp
Expand Up @@ -189,6 +189,7 @@ QgsLayoutMapGridWidget::QgsLayoutMapGridWidget( QgsLayoutItemMapGrid *mapGrid, Q
registerDataDefinedButton( mLabelDistDDBtn, QgsLayoutObject::MapGridLabelDistance );
registerDataDefinedButton( mCrossWidthDDBtn, QgsLayoutObject::MapGridCrossSize );
registerDataDefinedButton( mFrameLineThicknessDDBtn, QgsLayoutObject::MapGridFrameLineThickness );
registerDataDefinedButton( mAnnotationDisplayLeftDDBtn, QgsLayoutObject::MapGridAnnotationDisplayLeft );

updateGuiElements();

Expand Down Expand Up @@ -223,6 +224,7 @@ void QgsLayoutMapGridWidget::populateDataDefinedButtons()
updateDataDefinedButton( mLabelDistDDBtn );
updateDataDefinedButton( mCrossWidthDDBtn );
updateDataDefinedButton( mFrameLineThicknessDDBtn );
updateDataDefinedButton( mAnnotationDisplayLeftDDBtn );
}

void QgsLayoutMapGridWidget::setGuiElementValues()
Expand Down
151 changes: 81 additions & 70 deletions src/ui/layout/qgslayoutmapgridwidgetbase.ui
Expand Up @@ -49,7 +49,7 @@
<x>0</x>
<y>0</y>
<width>492</width>
<height>1209</height>
<height>1211</height>
</rect>
</property>
<property name="sizePolicy">
Expand Down Expand Up @@ -232,7 +232,7 @@
<double>9999999.000000000000000</double>
</property>
<property name="showClearButton" stdset="0">
<bool>true</bool>
<bool>true</bool>
</property>
</widget>
</item>
Expand Down Expand Up @@ -694,6 +694,9 @@
<property name="toolTip">
<string>Grid lines intersecting the border below this threshold will be ignored.</string>
</property>
<property name="showClearButton" stdset="0">
<bool>true</bool>
</property>
<property name="suffix">
<string> °</string>
</property>
Expand All @@ -706,9 +709,6 @@
<property name="value">
<double>0.000000000000000</double>
</property>
<property name="showClearButton" stdset="0">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="0">
Expand All @@ -723,6 +723,9 @@
<property name="toolTip">
<string>Outwards facing ticks closer to the corners than this margin will be ignored.</string>
</property>
<property name="showClearButton" stdset="0">
<bool>true</bool>
</property>
<property name="suffix">
<string> mm</string>
</property>
Expand All @@ -732,9 +735,6 @@
<property name="value">
<double>0.000000000000000</double>
</property>
<property name="showClearButton" stdset="0">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
Expand Down Expand Up @@ -771,25 +771,35 @@
<bool>false</bool>
</property>
<layout class="QGridLayout" name="gridLayout" columnstretch="0,0,0">
<item row="15" column="1" colspan="2">
<widget class="QComboBox" name="mAnnotationPositionBottomComboBox"/>
</item>
<item row="10" column="1" colspan="2">
<widget class="QComboBox" name="mAnnotationDirectionComboBoxRight"/>
</item>
<item row="8" column="0">
<widget class="QLabel" name="mAnnotationPositionLabelRight">
<property name="text">
<string>Right</string>
</property>
</widget>
</item>
<item row="8" column="1" colspan="2">
<widget class="QComboBox" name="mAnnotationDisplayRightComboBox"/>
<item row="7" column="1" colspan="2">
<widget class="QComboBox" name="mAnnotationDirectionComboBoxLeft"/>
</item>
<item row="6" column="1" colspan="2">
<widget class="QComboBox" name="mAnnotationPositionLeftComboBox"/>
</item>
<item row="0" column="0">
<widget class="QLabel" name="mAnnotationFormatLabel">
<property name="text">
<string>Format</string>
</property>
</widget>
</item>
<item row="8" column="1" colspan="2">
<widget class="QComboBox" name="mAnnotationDisplayRightComboBox"/>
</item>
<item row="9" column="1" colspan="2">
<widget class="QComboBox" name="mAnnotationPositionRightComboBox"/>
</item>
<item row="10" column="1" colspan="2">
<widget class="QComboBox" name="mAnnotationDirectionComboBoxRight"/>
</item>
<item row="0" column="1" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_13">
<item>
Expand All @@ -808,6 +818,19 @@
</item>
</layout>
</item>
<item row="14" 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="15" column="1" colspan="2">
<widget class="QComboBox" name="mAnnotationPositionBottomComboBox"/>
</item>
<item row="11" column="1" colspan="2">
<widget class="QComboBox" name="mAnnotationDisplayTopComboBox"/>
</item>
Expand All @@ -834,29 +857,25 @@
<item row="13" column="1" colspan="2">
<widget class="QComboBox" name="mAnnotationDirectionComboBoxTop"/>
</item>
<item row="14" column="0">
<widget class="QLabel" name="mAnnotationPositionLabelBottom">
<property name="text">
<string>Bottom</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
<item row="16" column="1" colspan="2">
<widget class="QComboBox" name="mAnnotationDirectionComboBoxBottom"/>
</item>
<item row="7" column="1" colspan="2">
<widget class="QComboBox" name="mAnnotationDirectionComboBoxLeft"/>
<item row="14" column="1" colspan="2">
<widget class="QComboBox" name="mAnnotationDisplayBottomComboBox"/>
</item>
<item row="0" column="0">
<widget class="QLabel" name="mAnnotationFormatLabel">
<item row="17" 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>Format</string>
<string>Font</string>
</property>
</widget>
</item>
<item row="9" column="1" colspan="2">
<widget class="QComboBox" name="mAnnotationPositionRightComboBox"/>
</item>
<item row="20" column="1" colspan="2">
<widget class="QgsSpinBox" name="mCoordinatePrecisionSpinBox">
<property name="showClearButton" stdset="0">
Expand All @@ -874,25 +893,19 @@
</property>
</widget>
</item>
<item row="18" column="1">
<widget class="QgsDoubleSpinBox" name="mDistanceToMapFrameSpinBox">
<property name="suffix">
<string> mm</string>
</property>
</widget>
</item>
<item row="18" column="2">
<widget class="QgsPropertyOverrideButton" name="mLabelDistDDBtn">
<property name="text">
<string>…</string>
</property>
</widget>
</item>
<item row="16" column="1" colspan="2">
<widget class="QComboBox" name="mAnnotationDirectionComboBoxBottom"/>
</item>
<item row="14" column="1" colspan="2">
<widget class="QComboBox" name="mAnnotationDisplayBottomComboBox"/>
<item row="18" column="1">
<widget class="QgsDoubleSpinBox" name="mDistanceToMapFrameSpinBox">
<property name="suffix">
<string> mm</string>
</property>
</widget>
</item>
<item row="20" column="0">
<widget class="QLabel" name="mCoordinatePrecisionLabel">
Expand All @@ -904,19 +917,6 @@
</property>
</widget>
</item>
<item row="17" 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>
<item row="21" column="0" colspan="3">
<widget class="QGroupBox" name="mRotatedAnnotationsGroupBox">
<property name="title">
Expand All @@ -935,9 +935,9 @@
</item>
<item row="0" column="1">
<widget class="QComboBox" name="mRotatedAnnotationsLengthModeComboBox">
<property name="toolTip">
<string>Determines how the ticks length is defined when rotated.</string>
</property>
<property name="toolTip">
<string>Determines how the ticks length is defined when rotated.</string>
</property>
</widget>
</item>
<item row="1" column="0">
Expand All @@ -952,6 +952,9 @@
<property name="toolTip">
<string>Grid lines intersecting the border below this threshold will be ignored.</string>
</property>
<property name="showClearButton" stdset="0">
<bool>true</bool>
</property>
<property name="suffix">
<string> °</string>
</property>
Expand All @@ -961,9 +964,6 @@
<property name="maximum">
<double>90.000000000000000</double>
</property>
<property name="showClearButton" stdset="0">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="0">
Expand All @@ -978,6 +978,9 @@
<property name="toolTip">
<string>Outwards facing annotations closer to the corners than this margin will be ignored.</string>
</property>
<property name="showClearButton" stdset="0">
<bool>true</bool>
</property>
<property name="suffix">
<string> mm</string>
</property>
Expand All @@ -987,18 +990,26 @@
<property name="value">
<double>0.000000000000000</double>
</property>
<property name="showClearButton" stdset="0">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="2" column="1" colspan="2">
<widget class="QComboBox" name="mAnnotationDisplayLeftComboBox"/>
<item row="1" column="1" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QComboBox" name="mAnnotationDisplayLeftComboBox"/>
</item>
<item>
<widget class="QgsPropertyOverrideButton" name="mAnnotationDisplayLeftDDBtn">
<property name="text">
<string>…</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="2" column="0">
<item row="1" column="0">
<widget class="QLabel" name="mAnnotationPositionLabelLeft">
<property name="text">
<string>Left</string>
Expand Down

0 comments on commit a85b6c5

Please sign in to comment.