Skip to content

Commit

Permalink
Merge pull request #54 from NathanW2/expression-ui
Browse files Browse the repository at this point in the history
Remove multiline label option and make it default and expression builder UI tweaks.
  • Loading branch information
wonder-sk committed Nov 2, 2011
2 parents 650605f + 9e809f3 commit 8435d7c
Show file tree
Hide file tree
Showing 5 changed files with 438 additions and 370 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
15 changes: 7 additions & 8 deletions src/gui/qgsexpressionbuilderwidget.cpp
Expand Up @@ -25,8 +25,10 @@ QgsExpressionBuilderWidget::QgsExpressionBuilderWidget( QWidget *parent )
{
setupUi( this );

mValueListWidget->hide();
mValueListLabel->hide();
mValueGroupBox->hide();
// The open and save button are for future.
btnOpen->hide();
btnSave->hide();

mModel = new QStandardItemModel( );
mProxyModel = new QgsExpressionItemSearchProxy();
Expand Down Expand Up @@ -112,8 +114,7 @@ void QgsExpressionBuilderWidget::on_expressionTree_clicked( const QModelIndex &i
else
{
// Show the help for the current item.
mValueListWidget->hide();
mValueListLabel->hide();
mValueGroupBox->hide();
mValueListWidget->clear();
txtHelpText->setText( item->getHelpText() );
txtHelpText->setToolTip( txtHelpText->text() );
Expand Down Expand Up @@ -327,8 +328,7 @@ void QgsExpressionBuilderWidget::loadSampleValues()
if ( !mLayer )
return;

mValueListWidget->show();
mValueListLabel->show();
mValueGroupBox->show();
int fieldIndex = mLayer->fieldNameIndex( item->text() );
fillFieldValues( fieldIndex, 10 );
}
Expand All @@ -342,8 +342,7 @@ void QgsExpressionBuilderWidget::loadAllValues()
if ( !mLayer )
return;

mValueListWidget->show();
mValueListLabel->show();
mValueGroupBox->show();
int fieldIndex = mLayer->fieldNameIndex( item->text() );
fillFieldValues( fieldIndex, -1 );
}
Expand Down

0 comments on commit 8435d7c

Please sign in to comment.