Skip to content

Commit d5531b6

Browse files
committedAug 9, 2012
Text diagrams: new label placement method (x-height)
1 parent 05dee08 commit d5531b6

6 files changed

+822
-722
lines changed
 

‎src/app/qgsvectorlayerproperties.cpp

+41
Original file line numberDiff line numberDiff line change
@@ -845,6 +845,16 @@ void QgsVectorLayerProperties::apply()
845845
{
846846
ds.sizeType = QgsDiagramSettings::MM;
847847
}
848+
849+
if ( !tr( "Height" ).compare( mLabelPlacementComboBox->currentText() ) )
850+
{
851+
ds.labelPlacementMethod = QgsDiagramSettings::Height;
852+
}
853+
else if ( !tr( "x-height" ).compare( mLabelPlacementComboBox->currentText() ) )
854+
{
855+
ds.labelPlacementMethod = QgsDiagramSettings::XHeight;
856+
}
857+
848858
ds.backgroundColor = mBackgroundColorButton->color();
849859
ds.penColor = mDiagramPenColorButton->color();
850860
ds.penWidth = mPenWidthSpinBox->value();
@@ -1306,6 +1316,19 @@ void QgsVectorLayerProperties::handleDiagramItemDoubleClick( QTreeWidgetItem * i
13061316
}
13071317
}
13081318

1319+
void QgsVectorLayerProperties::handleDiagramTypeChanged( const QString& itemtext )
1320+
{
1321+
if ( tr( "Text diagram" ) == itemtext )
1322+
{
1323+
mLabelPlacementComboBox->show();
1324+
mLabelPlacementLabel->show();
1325+
}
1326+
else {
1327+
mLabelPlacementComboBox->hide();
1328+
mLabelPlacementLabel->hide();
1329+
}
1330+
}
1331+
13091332
void QgsVectorLayerProperties::useNewSymbology()
13101333
{
13111334
int res = QMessageBox::question( this, tr( "Symbology" ),
@@ -1565,6 +1588,9 @@ void QgsVectorLayerProperties::initDiagramTab()
15651588
mDiagramTypeComboBox->addItem( tr( "Pie chart" ) );
15661589
mDiagramTypeComboBox->addItem( tr( "Text diagram" ) );
15671590

1591+
mLabelPlacementComboBox->addItem( tr( "Height" ) );
1592+
mLabelPlacementComboBox->addItem( tr( "x-height" ) );
1593+
15681594
//insert all attributes into the combo boxes
15691595
const QgsFieldMap& layerFields = layer->pendingFields();
15701596
QgsFieldMap::const_iterator fieldIt = layerFields.constBegin();
@@ -1594,6 +1620,7 @@ void QgsVectorLayerProperties::initDiagramTab()
15941620
mDisplayDiagramsCheckBox->setChecked( false );
15951621
mFixedSizeCheckBox->setChecked( true );
15961622
mDiagramUnitComboBox->setCurrentIndex( mDiagramUnitComboBox->findText( tr( "MM" ) ) );
1623+
mLabelPlacementComboBox->setCurrentIndex( mLabelPlacementComboBox->findText( tr( "XHeight" ) ) );
15971624
mDiagramSizeSpinBox->setValue( 30 );
15981625
mScaleDependentDiagramVisibilityCheckBox->setChecked( false );
15991626

@@ -1645,6 +1672,15 @@ void QgsVectorLayerProperties::initDiagramTab()
16451672
mDiagramUnitComboBox->setCurrentIndex( 1 );
16461673
}
16471674

1675+
if ( settingList.at( 0 ).labelPlacementMethod == QgsDiagramSettings::Height )
1676+
{
1677+
mLabelPlacementComboBox->setCurrentIndex( 0 );
1678+
}
1679+
else
1680+
{
1681+
mLabelPlacementComboBox->setCurrentIndex( 1 );
1682+
}
1683+
16481684

16491685

16501686
QList< QColor > categoryColors = settingList.at( 0 ).categoryColors;
@@ -1696,5 +1732,10 @@ void QgsVectorLayerProperties::initDiagramTab()
16961732
}
16971733
}
16981734
}
1735+
1736+
// Hide/Show diagram specific widgets
1737+
handleDiagramTypeChanged( mDiagramTypeComboBox->currentText() );
1738+
16991739
QObject::connect( mDiagramAttributesTreeWidget, SIGNAL( itemDoubleClicked( QTreeWidgetItem*, int ) ), this, SLOT( handleDiagramItemDoubleClick( QTreeWidgetItem*, int ) ) );
1740+
QObject::connect( mDiagramTypeComboBox, SIGNAL( currentIndexChanged( const QString& ) ), this, SLOT( handleDiagramTypeChanged( const QString& ) ) );
17001741
}

‎src/app/qgsvectorlayerproperties.h

+1
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ class QgsVectorLayerProperties : public QDialog, private Ui::QgsVectorLayerPrope
144144

145145
/**Set color for diagram category*/
146146
void handleDiagramItemDoubleClick( QTreeWidgetItem * item, int column );
147+
void handleDiagramTypeChanged( const QString& itemtext );
147148

148149
signals:
149150

‎src/core/qgsdiagram.cpp

+18-2
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,28 @@ void QgsTextDiagram::renderDiagram( const QgsAttributeMap& att, QgsRenderContext
197197
for ( int i = 0; i < textPositions.size(); ++i )
198198
{
199199
QString val = att[ s.categoryIndices.at( i )].toString();
200-
//find out dimensions
200+
//find out dimesions
201201
double textWidth = fontMetrics.width( val );
202+
double textHeight = fontMetrics.height();
203+
202204
mPen.setColor( s.categoryColors.at( i ) );
203205
p->setPen( mPen );
204206
QPointF position = textPositions.at( i );
205-
p->drawText( QPointF( position.x() - textWidth / 2.0, position.y() + fontMetrics.xHeight() ), val );
207+
208+
// Calculate vertical placement
209+
double xOffset = 0;
210+
211+
switch( s.labelPlacementMethod )
212+
{
213+
case QgsDiagramSettings::Height:
214+
xOffset = textHeight / 2.0;
215+
break;
216+
217+
case QgsDiagramSettings::XHeight:
218+
xOffset = fontMetrics.xHeight();
219+
break;
220+
}
221+
p->drawText( QPointF( position.x() - textWidth / 2.0, position.y() + xOffset ), val );
206222
}
207223
}
208224

0 commit comments

Comments
 (0)
Please sign in to comment.