Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Remove option for multiline; Code always uses multiline; Direction sy…
…mbol now works for multiline
  • Loading branch information
NathanW2 committed Nov 2, 2011
1 parent 0a1cef9 commit 9e809f3
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 101 deletions.
2 changes: 0 additions & 2 deletions src/app/qgslabelinggui.cpp
Expand Up @@ -138,7 +138,6 @@ QgsLabelingGui::QgsLabelingGui( QgsPalLabeling* lbl, QgsVectorLayer* layer, QgsM
chkNoObstacle->setChecked( !lyr.obstacle );
chkLabelPerFeaturePart->setChecked( lyr.labelPerPart );
chkMergeLines->setChecked( lyr.mergeLines );
chkMultiLine->setChecked( lyr.multiLineLabels );
mMinSizeSpinBox->setValue( lyr.minFeatureSize );
chkAddDirectionSymbol->setChecked( lyr.addDirectionSymbol );

Expand Down Expand Up @@ -282,7 +281,6 @@ QgsPalLayerSettings QgsLabelingGui::layerSettings()
lyr.obstacle = !chkNoObstacle->isChecked();
lyr.labelPerPart = chkLabelPerFeaturePart->isChecked();
lyr.mergeLines = chkMergeLines->isChecked();
lyr.multiLineLabels = chkMultiLine->isChecked();
if ( chkScaleBasedVisibility->isChecked() )
{
lyr.scaleMin = spinScaleMin->value();
Expand Down
43 changes: 12 additions & 31 deletions src/core/qgspallabeling.cpp
Expand Up @@ -152,7 +152,6 @@ QgsPalLayerSettings::QgsPalLayerSettings()
plusSign = false;
labelPerPart = false;
mergeLines = false;
multiLineLabels = true;
minFeatureSize = 0.0;
vectorScaleFactor = 1.0;
rasterCompressFactor = 1.0;
Expand Down Expand Up @@ -183,7 +182,6 @@ QgsPalLayerSettings::QgsPalLayerSettings( const QgsPalLayerSettings& s )
plusSign = s.plusSign;
labelPerPart = s.labelPerPart;
mergeLines = s.mergeLines;
multiLineLabels = s.multiLineLabels;
minFeatureSize = s.minFeatureSize;
vectorScaleFactor = s.vectorScaleFactor;
rasterCompressFactor = s.rasterCompressFactor;
Expand Down Expand Up @@ -328,7 +326,6 @@ void QgsPalLayerSettings::readFromLayer( QgsVectorLayer* layer )
plusSign = layer->customProperty( "labeling/plussign" ).toInt();
labelPerPart = layer->customProperty( "labeling/labelPerPart" ).toBool();
mergeLines = layer->customProperty( "labeling/mergeLines" ).toBool();
multiLineLabels = layer->customProperty( "labeling/multiLineLabels" ).toBool();
addDirectionSymbol = layer->customProperty( "labeling/addDirectionSymbol" ).toBool();
minFeatureSize = layer->customProperty( "labeling/minFeatureSize" ).toDouble();
fontSizeInMapUnits = layer->customProperty( "labeling/fontSizeInMapUnits" ).toBool();
Expand Down Expand Up @@ -367,7 +364,6 @@ void QgsPalLayerSettings::writeToLayer( QgsVectorLayer* layer )
layer->setCustomProperty( "labeling/plussign", plusSign );
layer->setCustomProperty( "labeling/labelPerPart", labelPerPart );
layer->setCustomProperty( "labeling/mergeLines", mergeLines );
layer->setCustomProperty( "labeling/multiLineLabels", multiLineLabels );
layer->setCustomProperty( "labeling/addDirectionSymbol", addDirectionSymbol );
layer->setCustomProperty( "labeling/minFeatureSize", minFeatureSize );
layer->setCustomProperty( "labeling/fontSizeInMapUnits", fontSizeInMapUnits );
Expand Down Expand Up @@ -430,33 +426,25 @@ void QgsPalLayerSettings::calculateLabelSize( const QFontMetricsF* fm, QString t
return;
}

if ( addDirectionSymbol && !multiLineLabels && placement == QgsPalLayerSettings::Line ) //consider the space needed for the direction symbol
//consider the space needed for the direction symbol
if ( addDirectionSymbol && placement == QgsPalLayerSettings::Line )
{
text.append( ">" );
}

double w, h;
if ( !multiLineLabels )
QStringList multiLineSplit = text.split( "\n" );
h = fm->height() * multiLineSplit.size() / rasterCompressFactor;
w = 0;
for ( int i = 0; i < multiLineSplit.size(); ++i )
{
QRectF labelRect = fm->boundingRect( text );
w = labelRect.width() / rasterCompressFactor;
h = labelRect.height() / rasterCompressFactor;
}
else
{
QStringList multiLineSplit = text.split( "\n" );
h = fm->height() * multiLineSplit.size() / rasterCompressFactor;
w = 0;
for ( int i = 0; i < multiLineSplit.size(); ++i )
double width = fm->width( multiLineSplit.at( i ) );
if ( width > w )
{
double width = fm->width( multiLineSplit.at( i ) );
if ( width > w )
{
w = width;
}
w = width;
}
w /= rasterCompressFactor;
}
w /= rasterCompressFactor;
QgsPoint ptSize = xform->toMapCoordinatesF( w, h );

labelX = qAbs( ptSize.x() - ptZero.x() );
Expand Down Expand Up @@ -1337,7 +1325,7 @@ void QgsPalLabeling::drawLabel( pal::LabelPosition* label, QPainter* painter, co

//add the direction symbol if needed
if ( !txt.isEmpty() && lyr.placement == QgsPalLayerSettings::Line &&
lyr.addDirectionSymbol && !lyr.multiLineLabels )
lyr.addDirectionSymbol )
{
if ( label->getReversed() )
{
Expand All @@ -1352,14 +1340,7 @@ void QgsPalLabeling::drawLabel( pal::LabelPosition* label, QPainter* painter, co
//QgsDebugMsg( "drawLabel " + QString::number( drawBuffer ) + " " + txt );

QStringList multiLineList;
if ( lyr.multiLineLabels )
{
multiLineList = txt.split( "\n" );
}
else
{
multiLineList << txt;
}
multiLineList = txt.split( "\n" );

for ( int i = 0; i < multiLineList.size(); ++i )
{
Expand Down
129 changes: 61 additions & 68 deletions src/ui/qgslabelingguibase.ui
Expand Up @@ -63,10 +63,64 @@
</item>
</layout>
</item>
<item row="3" column="0">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
<item row="0" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QCheckBox" name="chkEnableLabeling">
<property name="text">
<string>Label this layer with</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="cboFieldName">
<property name="enabled">
<bool>false</bool>
</property>
<property name="editable">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="btnExpression">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>...</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="2" column="0">
<widget class="QTabWidget" name="mTabWidget">
<property name="enabled">
<bool>false</bool>
<bool>true</bool>
</property>
<property name="currentIndex">
<number>0</number>
Expand Down Expand Up @@ -419,8 +473,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>647</width>
<height>487</height>
<width>646</width>
<height>451</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_13">
Expand Down Expand Up @@ -487,20 +541,13 @@
</widget>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="chkMultiLine">
<property name="text">
<string>Multiline labels</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QCheckBox" name="chkAddDirectionSymbol">
<property name="text">
<string>Add direction symbol</string>
</property>
</widget>
</item>
<item row="4" column="0">
<item row="3" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label_19">
Expand All @@ -518,7 +565,7 @@
</item>
</layout>
</item>
<item row="5" column="0">
<item row="4" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_20">
<item>
<widget class="QCheckBox" name="chkNoObstacle">
Expand Down Expand Up @@ -876,8 +923,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>647</width>
<height>615</height>
<width>646</width>
<height>585</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_11">
Expand Down Expand Up @@ -1072,60 +1119,6 @@
</widget>
</widget>
</item>
<item row="3" column="0">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
<item row="0" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QCheckBox" name="chkEnableLabeling">
<property name="text">
<string>Label this layer with</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="cboFieldName">
<property name="enabled">
<bool>false</bool>
</property>
<property name="editable">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="btnExpression">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>...</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
<layoutdefault spacing="6" margin="11"/>
Expand Down

0 comments on commit 9e809f3

Please sign in to comment.