Skip to content
Permalink
Browse files
[FEATURE] Add label wrapping on character. Semi Fixes #3284
  • Loading branch information
NathanW2 committed Jan 6, 2012
1 parent 3f73c85 commit f57892c73d8a3b4a3abe4b8659369720e9cc1329
Showing with 47 additions and 10 deletions.
  1. +2 −0 src/app/qgslabelinggui.cpp
  2. +14 −2 src/core/qgspallabeling.cpp
  3. +1 −2 src/core/qgspallabeling.h
  4. +30 −6 src/ui/qgslabelingguibase.ui
@@ -137,6 +137,7 @@ QgsLabelingGui::QgsLabelingGui( QgsPalLabeling* lbl, QgsVectorLayer* layer, QgsM
chkMergeLines->setChecked( lyr.mergeLines );
mMinSizeSpinBox->setValue( lyr.minFeatureSize );
chkAddDirectionSymbol->setChecked( lyr.addDirectionSymbol );
wrapCharacterEdit->setText( lyr.wrapChar );

bool scaleBased = ( lyr.scaleMin != 0 && lyr.scaleMax != 0 );
chkScaleBasedVisibility->setChecked( scaleBased );
@@ -320,6 +321,7 @@ QgsPalLayerSettings QgsLabelingGui::layerSettings()
}
lyr.minFeatureSize = mMinSizeSpinBox->value();
lyr.fontSizeInMapUnits = ( mFontSizeUnitComboBox->currentIndex() == 1 );
lyr.wrapChar = wrapCharacterEdit->text();

//data defined labeling
setDataDefinedProperty( mSizeAttributeComboBox, QgsPalLayerSettings::Size, lyr );
@@ -157,6 +157,7 @@ QgsPalLayerSettings::QgsPalLayerSettings()
addDirectionSymbol = false;
fontSizeInMapUnits = false;
distInMapUnits = false;
wrapChar = "";
}

QgsPalLayerSettings::QgsPalLayerSettings( const QgsPalLayerSettings& s )
@@ -187,6 +188,7 @@ QgsPalLayerSettings::QgsPalLayerSettings( const QgsPalLayerSettings& s )
addDirectionSymbol = s.addDirectionSymbol;
fontSizeInMapUnits = s.fontSizeInMapUnits;
distInMapUnits = s.distInMapUnits;
wrapChar = s.wrapChar;

dataDefinedProperties = s.dataDefinedProperties;
fontMetrics = NULL;
@@ -329,6 +331,7 @@ void QgsPalLayerSettings::readFromLayer( QgsVectorLayer* layer )
minFeatureSize = layer->customProperty( "labeling/minFeatureSize" ).toDouble();
fontSizeInMapUnits = layer->customProperty( "labeling/fontSizeInMapUnits" ).toBool();
distInMapUnits = layer->customProperty( "labeling/distInMapUnits" ).toBool();
wrapChar = layer->customProperty( "labeling/wrapChar" ).toString();
_readDataDefinedPropertyMap( layer, dataDefinedProperties );
}

@@ -367,6 +370,7 @@ void QgsPalLayerSettings::writeToLayer( QgsVectorLayer* layer )
layer->setCustomProperty( "labeling/minFeatureSize", minFeatureSize );
layer->setCustomProperty( "labeling/fontSizeInMapUnits", fontSizeInMapUnits );
layer->setCustomProperty( "labeling/distInMapUnits", distInMapUnits );
layer->setCustomProperty( "labeling/wrapChar", wrapChar );
_writeDataDefinedPropertyMap( layer, dataDefinedProperties );
}

@@ -432,7 +436,12 @@ void QgsPalLayerSettings::calculateLabelSize( const QFontMetricsF* fm, QString t
}

double w, h;
QStringList multiLineSplit = text.split( "\n" );
QStringList multiLineSplit;
if ( !wrapChar.isEmpty() )
multiLineSplit = text.split( wrapChar );
else
multiLineSplit = text.split( "\n" );

h = fm->height() * multiLineSplit.size() / rasterCompressFactor;
w = 0;
for ( int i = 0; i < multiLineSplit.size(); ++i )
@@ -1337,7 +1346,10 @@ void QgsPalLabeling::drawLabel( pal::LabelPosition* label, QPainter* painter, co
//QgsDebugMsg( "drawLabel " + QString::number( drawBuffer ) + " " + txt );

QStringList multiLineList;
multiLineList = txt.split( "\n" );
if ( !lyr.wrapChar.isEmpty() )
multiLineList = txt.split( lyr.wrapChar );
else
multiLineList = txt.split( "\n" );

for ( int i = 0; i < multiLineList.size(); ++i )
{
@@ -126,14 +126,13 @@ class CORE_EXPORT QgsPalLayerSettings
bool plusSign;
bool labelPerPart; // whether to label every feature's part or only the biggest one
bool mergeLines;
bool multiLineLabels; //draw labels on multiple lines if they contain '\n'
double minFeatureSize; // minimum feature size to be labelled (in mm)
// Adds '<' or '>' to the label string pointing to the direction of the line / polygon ring
// Works only if Placement == Line
bool addDirectionSymbol;
bool fontSizeInMapUnits; //true if font size is in map units (otherwise in points)
bool distInMapUnits; //true if distance is in map units (otherwise in mm)

QString wrapChar;
// called from register feature hook
void calculateLabelSize( const QFontMetricsF* fm, QString text, double& labelX, double& labelY );

@@ -473,8 +473,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>658</width>
<height>443</height>
<width>646</width>
<height>484</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_13">
@@ -547,7 +547,7 @@
</property>
</widget>
</item>
<item row="3" column="0">
<item row="4" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label_19">
@@ -565,7 +565,7 @@
</item>
</layout>
</item>
<item row="4" column="0">
<item row="5" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_20">
<item>
<widget class="QCheckBox" name="chkNoObstacle">
@@ -602,6 +602,30 @@
</item>
</layout>
</item>
<item row="3" column="0">
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="topMargin">
<number>3</number>
</property>
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Wrap label on character</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="wrapCharacterEdit">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
@@ -911,8 +935,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>249</width>
<height>567</height>
<width>646</width>
<height>585</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_11">

0 comments on commit f57892c

Please sign in to comment.