Skip to content

Commit 8435d7c

Browse files
committed
Merge pull request #54 from NathanW2/expression-ui
Remove multiline label option and make it default and expression builder UI tweaks.
2 parents 650605f + 9e809f3 commit 8435d7c

File tree

5 files changed

+438
-370
lines changed

5 files changed

+438
-370
lines changed

src/app/qgslabelinggui.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ QgsLabelingGui::QgsLabelingGui( QgsPalLabeling* lbl, QgsVectorLayer* layer, QgsM
138138
chkNoObstacle->setChecked( !lyr.obstacle );
139139
chkLabelPerFeaturePart->setChecked( lyr.labelPerPart );
140140
chkMergeLines->setChecked( lyr.mergeLines );
141-
chkMultiLine->setChecked( lyr.multiLineLabels );
142141
mMinSizeSpinBox->setValue( lyr.minFeatureSize );
143142
chkAddDirectionSymbol->setChecked( lyr.addDirectionSymbol );
144143

@@ -282,7 +281,6 @@ QgsPalLayerSettings QgsLabelingGui::layerSettings()
282281
lyr.obstacle = !chkNoObstacle->isChecked();
283282
lyr.labelPerPart = chkLabelPerFeaturePart->isChecked();
284283
lyr.mergeLines = chkMergeLines->isChecked();
285-
lyr.multiLineLabels = chkMultiLine->isChecked();
286284
if ( chkScaleBasedVisibility->isChecked() )
287285
{
288286
lyr.scaleMin = spinScaleMin->value();

src/core/qgspallabeling.cpp

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@ QgsPalLayerSettings::QgsPalLayerSettings()
152152
plusSign = false;
153153
labelPerPart = false;
154154
mergeLines = false;
155-
multiLineLabels = true;
156155
minFeatureSize = 0.0;
157156
vectorScaleFactor = 1.0;
158157
rasterCompressFactor = 1.0;
@@ -183,7 +182,6 @@ QgsPalLayerSettings::QgsPalLayerSettings( const QgsPalLayerSettings& s )
183182
plusSign = s.plusSign;
184183
labelPerPart = s.labelPerPart;
185184
mergeLines = s.mergeLines;
186-
multiLineLabels = s.multiLineLabels;
187185
minFeatureSize = s.minFeatureSize;
188186
vectorScaleFactor = s.vectorScaleFactor;
189187
rasterCompressFactor = s.rasterCompressFactor;
@@ -328,7 +326,6 @@ void QgsPalLayerSettings::readFromLayer( QgsVectorLayer* layer )
328326
plusSign = layer->customProperty( "labeling/plussign" ).toInt();
329327
labelPerPart = layer->customProperty( "labeling/labelPerPart" ).toBool();
330328
mergeLines = layer->customProperty( "labeling/mergeLines" ).toBool();
331-
multiLineLabels = layer->customProperty( "labeling/multiLineLabels" ).toBool();
332329
addDirectionSymbol = layer->customProperty( "labeling/addDirectionSymbol" ).toBool();
333330
minFeatureSize = layer->customProperty( "labeling/minFeatureSize" ).toDouble();
334331
fontSizeInMapUnits = layer->customProperty( "labeling/fontSizeInMapUnits" ).toBool();
@@ -367,7 +364,6 @@ void QgsPalLayerSettings::writeToLayer( QgsVectorLayer* layer )
367364
layer->setCustomProperty( "labeling/plussign", plusSign );
368365
layer->setCustomProperty( "labeling/labelPerPart", labelPerPart );
369366
layer->setCustomProperty( "labeling/mergeLines", mergeLines );
370-
layer->setCustomProperty( "labeling/multiLineLabels", multiLineLabels );
371367
layer->setCustomProperty( "labeling/addDirectionSymbol", addDirectionSymbol );
372368
layer->setCustomProperty( "labeling/minFeatureSize", minFeatureSize );
373369
layer->setCustomProperty( "labeling/fontSizeInMapUnits", fontSizeInMapUnits );
@@ -430,33 +426,25 @@ void QgsPalLayerSettings::calculateLabelSize( const QFontMetricsF* fm, QString t
430426
return;
431427
}
432428

433-
if ( addDirectionSymbol && !multiLineLabels && placement == QgsPalLayerSettings::Line ) //consider the space needed for the direction symbol
429+
//consider the space needed for the direction symbol
430+
if ( addDirectionSymbol && placement == QgsPalLayerSettings::Line )
434431
{
435432
text.append( ">" );
436433
}
437434

438435
double w, h;
439-
if ( !multiLineLabels )
436+
QStringList multiLineSplit = text.split( "\n" );
437+
h = fm->height() * multiLineSplit.size() / rasterCompressFactor;
438+
w = 0;
439+
for ( int i = 0; i < multiLineSplit.size(); ++i )
440440
{
441-
QRectF labelRect = fm->boundingRect( text );
442-
w = labelRect.width() / rasterCompressFactor;
443-
h = labelRect.height() / rasterCompressFactor;
444-
}
445-
else
446-
{
447-
QStringList multiLineSplit = text.split( "\n" );
448-
h = fm->height() * multiLineSplit.size() / rasterCompressFactor;
449-
w = 0;
450-
for ( int i = 0; i < multiLineSplit.size(); ++i )
441+
double width = fm->width( multiLineSplit.at( i ) );
442+
if ( width > w )
451443
{
452-
double width = fm->width( multiLineSplit.at( i ) );
453-
if ( width > w )
454-
{
455-
w = width;
456-
}
444+
w = width;
457445
}
458-
w /= rasterCompressFactor;
459446
}
447+
w /= rasterCompressFactor;
460448
QgsPoint ptSize = xform->toMapCoordinatesF( w, h );
461449

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

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

13541342
QStringList multiLineList;
1355-
if ( lyr.multiLineLabels )
1356-
{
1357-
multiLineList = txt.split( "\n" );
1358-
}
1359-
else
1360-
{
1361-
multiLineList << txt;
1362-
}
1343+
multiLineList = txt.split( "\n" );
13631344

13641345
for ( int i = 0; i < multiLineList.size(); ++i )
13651346
{

src/gui/qgsexpressionbuilderwidget.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ QgsExpressionBuilderWidget::QgsExpressionBuilderWidget( QWidget *parent )
2525
{
2626
setupUi( this );
2727

28-
mValueListWidget->hide();
29-
mValueListLabel->hide();
28+
mValueGroupBox->hide();
29+
// The open and save button are for future.
30+
btnOpen->hide();
31+
btnSave->hide();
3032

3133
mModel = new QStandardItemModel( );
3234
mProxyModel = new QgsExpressionItemSearchProxy();
@@ -112,8 +114,7 @@ void QgsExpressionBuilderWidget::on_expressionTree_clicked( const QModelIndex &i
112114
else
113115
{
114116
// Show the help for the current item.
115-
mValueListWidget->hide();
116-
mValueListLabel->hide();
117+
mValueGroupBox->hide();
117118
mValueListWidget->clear();
118119
txtHelpText->setText( item->getHelpText() );
119120
txtHelpText->setToolTip( txtHelpText->text() );
@@ -327,8 +328,7 @@ void QgsExpressionBuilderWidget::loadSampleValues()
327328
if ( !mLayer )
328329
return;
329330

330-
mValueListWidget->show();
331-
mValueListLabel->show();
331+
mValueGroupBox->show();
332332
int fieldIndex = mLayer->fieldNameIndex( item->text() );
333333
fillFieldValues( fieldIndex, 10 );
334334
}
@@ -342,8 +342,7 @@ void QgsExpressionBuilderWidget::loadAllValues()
342342
if ( !mLayer )
343343
return;
344344

345-
mValueListWidget->show();
346-
mValueListLabel->show();
345+
mValueGroupBox->show();
347346
int fieldIndex = mLayer->fieldNameIndex( item->text() );
348347
fillFieldValues( fieldIndex, -1 );
349348
}

0 commit comments

Comments
 (0)