Skip to content

Commit

Permalink
Add repeat distance UI
Browse files Browse the repository at this point in the history
  • Loading branch information
manisandro committed May 7, 2014
1 parent c3d7f0d commit a3b9d6c
Show file tree
Hide file tree
Showing 4 changed files with 163 additions and 1 deletion.
15 changes: 15 additions & 0 deletions src/app/qgslabelinggui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ QgsLabelingGui::QgsLabelingGui( QgsVectorLayer* layer, QgsMapCanvas* mapCanvas,
mShadowRadiusUnitWidget->setUnits( QStringList() << tr( "mm" ) << tr( "map units" ), 1 );
mPointOffsetUnitWidget->setUnits( QStringList() << tr( "mm" ) << tr( "map units" ), 1 );
mLineDistanceUnitWidget->setUnits( QStringList() << tr( "mm" ) << tr( "map units" ), 1 );
mRepeatDistanceUnitWidget->setUnits( QStringList() << tr( "mm" ) << tr( "map units" ), 1 );

mCharDlg = new QgsCharacterSelectorDialog( this );

Expand Down Expand Up @@ -308,6 +309,11 @@ void QgsLabelingGui::init()
chkLineOrientationDependent->setChecked( true );
}

// Label repeat distance
mRepeatDistanceSpinBox->setValue( lyr.repeatDistance );
mRepeatDistanceUnitWidget->setUnit( lyr.repeatDistanceUnit - 1 );
mRepeatDistanceUnitWidget->setMapUnitScale( lyr.repeatDistanceMapUnitScale );

mPrioritySlider->setValue( lyr.priority );
chkNoObstacle->setChecked( lyr.obstacle );
chkLabelPerFeaturePart->setChecked( lyr.labelPerPart );
Expand Down Expand Up @@ -591,6 +597,9 @@ QgsPalLayerSettings QgsLabelingGui::layerSettings()
qFatal( "Invalid settings" );
}

lyr.repeatDistance = mRepeatDistanceSpinBox->value();
lyr.repeatDistanceUnit = static_cast<QgsPalLayerSettings::SizeUnit>(1 + mRepeatDistanceUnitWidget->getUnit());
lyr.repeatDistanceMapUnitScale = mRepeatDistanceUnitWidget->getMapUnitScale();

lyr.textColor = btnTextColor->color();
lyr.textFont = mRefFont;
Expand Down Expand Up @@ -779,6 +788,8 @@ QgsPalLayerSettings QgsLabelingGui::layerSettings()
// TODO: is this necessary? maybe just use the data defined-only rotation?
//setDataDefinedProperty( mPointAngleDDBtn, QgsPalLayerSettings::OffsetRotation, lyr );
setDataDefinedProperty( mMaxCharAngleDDBtn, QgsPalLayerSettings::CurvedCharAngleInOut, lyr );
setDataDefinedProperty( mRepeatDistanceDDBtn, QgsPalLayerSettings::RepeatDistance, lyr );
setDataDefinedProperty( mRepeatDistanceUnitDDBtn, QgsPalLayerSettings::RepeatDistanceUnit, lyr );

// data defined-only
setDataDefinedProperty( mCoordXDDBtn, QgsPalLayerSettings::PositionX, lyr );
Expand Down Expand Up @@ -1004,6 +1015,10 @@ void QgsLabelingGui::populateDataDefinedButtons( QgsPalLayerSettings& s )
// QgsDataDefinedButton::AnyType, QgsDataDefinedButton::double180RotDesc() );
mMaxCharAngleDDBtn->init( mLayer, s.dataDefinedProperty( QgsPalLayerSettings::CurvedCharAngleInOut ),
QgsDataDefinedButton::AnyType, tr( "double coord [<b>in,out</b> as 20.0-60.0,20.0-95.0]" ) );
mRepeatDistanceDDBtn->init( mLayer, s.dataDefinedProperty( QgsPalLayerSettings::RepeatDistance ),
QgsDataDefinedButton::AnyType, QgsDataDefinedButton::doublePosDesc() );
mRepeatDistanceUnitDDBtn->init( mLayer, s.dataDefinedProperty( QgsPalLayerSettings::DistanceUnits ),
QgsDataDefinedButton::String, QgsDataDefinedButton::unitsMmMuDesc() );

// data defined-only
QString ddPlaceInfo = tr( "In edit mode, layer's relevant labeling map tool is:<br>"
Expand Down
52 changes: 51 additions & 1 deletion src/core/qgspallabeling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,8 @@ QgsPalLayerSettings::QgsPalLayerSettings()
maxCurvedCharAngleIn = 20.0;
maxCurvedCharAngleOut = -20.0;
priority = 5;
repeatDistance = 0;
repeatDistanceUnit = MM;

// rendering
scaleVisibility = false;
Expand Down Expand Up @@ -513,6 +515,9 @@ QgsPalLayerSettings::QgsPalLayerSettings( const QgsPalLayerSettings& s )
maxCurvedCharAngleIn = s.maxCurvedCharAngleIn;
maxCurvedCharAngleOut = s.maxCurvedCharAngleOut;
priority = s.priority;
repeatDistance = s.repeatDistance;
repeatDistanceUnit = s.repeatDistanceUnit;
repeatDistanceMapUnitScale = s.repeatDistanceMapUnitScale;

// rendering
scaleVisibility = s.scaleVisibility;
Expand Down Expand Up @@ -1007,6 +1012,10 @@ void QgsPalLayerSettings::readFromLayer( QgsVectorLayer* layer )
maxCurvedCharAngleIn = layer->customProperty( "labeling/maxCurvedCharAngleIn", QVariant( 20.0 ) ).toDouble();
maxCurvedCharAngleOut = layer->customProperty( "labeling/maxCurvedCharAngleOut", QVariant( -20.0 ) ).toDouble();
priority = layer->customProperty( "labeling/priority" ).toInt();
repeatDistance = layer->customProperty( "labeling/repeatDistance", 0.0 ).toDouble();
repeatDistanceUnit = (SizeUnit) layer->customProperty( "labeling/repeatDistanceUnit", QVariant( MM )).toUInt();
repeatDistanceMapUnitScale.minScale = layer->customProperty( "labeling/repeatDistanceMapUnitMinScale", 0.0).toDouble();
repeatDistanceMapUnitScale.maxScale = layer->customProperty( "labeling/repeatDistanceMapUnitMaxScale", 0.0).toDouble();

// rendering
int scalemn = layer->customProperty( "labeling/scaleMin", QVariant( 0 ) ).toInt();
Expand Down Expand Up @@ -1173,6 +1182,10 @@ void QgsPalLayerSettings::writeToLayer( QgsVectorLayer* layer )
layer->setCustomProperty( "labeling/maxCurvedCharAngleIn", maxCurvedCharAngleIn );
layer->setCustomProperty( "labeling/maxCurvedCharAngleOut", maxCurvedCharAngleOut );
layer->setCustomProperty( "labeling/priority", priority );
layer->setCustomProperty( "labeling/repeatDistance", repeatDistance );
layer->setCustomProperty( "labeling/repeatDistanceUnit", repeatDistanceUnit );
layer->setCustomProperty( "labeling/repeatDistanceMapUnitMinScale", repeatDistanceMapUnitScale.minScale );
layer->setCustomProperty( "labeling/repeatDistanceMapUnitMaxScale", repeatDistanceMapUnitScale.maxScale );

// rendering
layer->setCustomProperty( "labeling/scaleVisibility", scaleVisibility );
Expand Down Expand Up @@ -2213,12 +2226,48 @@ void QgsPalLayerSettings::registerFeature( QgsFeature& f, const QgsRenderContext
#endif
lbl->setDefinedFont( labelFont );

// data defined repeat distance?
double repeatDist = repeatDistance;
if ( dataDefinedEvaluate( QgsPalLayerSettings::RepeatDistance, exprVal ) )
{
bool ok;
double distD = exprVal.toDouble( &ok );
if ( ok )
{
repeatDist = distD;
}
}

// data defined label-repeat distance units?
bool repeatdistinmapunit = repeatDistanceUnit == MapUnits;
if ( dataDefinedEvaluate( QgsPalLayerSettings::RepeatDistanceUnit, exprVal ) )
{
QString units = exprVal.toString().trimmed();
QgsDebugMsgLevel( QString( "exprVal RepeatDistanceUnits:%1" ).arg( units ), 4 );
if ( !units.isEmpty() )
{
repeatdistinmapunit = ( _decodeUnits( units ) == QgsPalLayerSettings::MapUnits );
}
}

if ( repeatDist != 0 )
{
if ( !repeatdistinmapunit ) //convert distance from mm/map units to pixels
{
repeatDist *= repeatDistanceMapUnitScale.computeMapUnitsPerPixel(context) * context.scaleFactor();
}
else //mm
{
repeatDist *= vectorScaleFactor;
}
}

// feature to the layer
try
{
if ( !palLayer->registerFeature( lbl->strId(), lbl, labelX, labelY, labelText.toUtf8().constData(),
xPos, yPos, dataDefinedPosition, angle, dataDefinedRotation,
quadOffsetX, quadOffsetY, offsetX, offsetY, alwaysShow ) )
quadOffsetX, quadOffsetY, offsetX, offsetY, alwaysShow, repeatDist ) )
return;
}
catch ( std::exception &e )
Expand Down Expand Up @@ -2273,6 +2322,7 @@ void QgsPalLayerSettings::registerFeature( QgsFeature& f, const QgsRenderContext
feat->setDistLabel( qAbs( ptOne.x() - ptZero.x() )* distance );
}


//add parameters for data defined labeling to QgsPalGeometry
QMap< DataDefinedProperties, QVariant >::const_iterator dIt = dataDefinedValues.constBegin();
for ( ; dIt != dataDefinedValues.constEnd(); ++dIt )
Expand Down
6 changes: 6 additions & 0 deletions src/core/qgspallabeling.h
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,8 @@ class CORE_EXPORT QgsPalLayerSettings
Hali = 11, //horizontal alignment for data defined label position (Left, Center, Right)
Vali = 12, //vertical alignment for data defined label position (Bottom, Base, Half, Cap, Top)
Rotation = 14, //data defined rotation
RepeatDistance = 84,
RepeatDistanceUnit = 85,

// rendering
ScaleVisibility = 23,
Expand Down Expand Up @@ -377,6 +379,10 @@ class CORE_EXPORT QgsPalLayerSettings
bool distInMapUnits; //true if distance is in map units (otherwise in mm)
QgsMapUnitScale distMapUnitScale;

double repeatDistance;
SizeUnit repeatDistanceUnit;
QgsMapUnitScale repeatDistanceMapUnitScale;

// offset labels of point/centroid features default to center
// move label to quadrant: left/down, don't move, right/up (-1, 0, 1)
QuadrantPosition quadOffset;
Expand Down
91 changes: 91 additions & 0 deletions src/ui/qgslabelingguibase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -3829,6 +3829,70 @@ font-style: italic;</string>
</property>
</widget>
</item>
<item row="1" column="0" colspan="3">
<widget class="QFrame" name="mRepeatDistanceFrame">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QGridLayout" name="gridLayout_24">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<property name="verticalSpacing">
<number>12</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Repeat</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QDoubleSpinBox" name="mRepeatDistanceSpinBox">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="decimals">
<number>4</number>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QgsDataDefinedButton" name="mRepeatDistanceDDBtn">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QgsUnitSelectionWidget" name="mRepeatDistanceUnitWidget" native="true"/>
</item>
<item row="1" column="2">
<widget class="QgsDataDefinedButton" name="mRepeatDistanceUnitDDBtn">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="pagePolygon">
Expand Down Expand Up @@ -4720,6 +4784,33 @@ font-style: italic;</string>
</layout>
</widget>
</item>
<item>
<widget class="QFrame" name="s">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QGridLayout" name="gridLayout_11">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<property name="verticalSpacing">
<number>12</number>
</property>
</layout>
</widget>
</item>
<item>
<widget class="Line" name="line">
<property name="minimumSize">
Expand Down

0 comments on commit a3b9d6c

Please sign in to comment.