Skip to content

Commit

Permalink
Text diagrams: new label placement method (x-height)
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Aug 9, 2012
1 parent 05dee08 commit d5531b6
Show file tree
Hide file tree
Showing 6 changed files with 822 additions and 722 deletions.
41 changes: 41 additions & 0 deletions src/app/qgsvectorlayerproperties.cpp
Expand Up @@ -845,6 +845,16 @@ void QgsVectorLayerProperties::apply()
{
ds.sizeType = QgsDiagramSettings::MM;
}

if ( !tr( "Height" ).compare( mLabelPlacementComboBox->currentText() ) )
{
ds.labelPlacementMethod = QgsDiagramSettings::Height;
}
else if ( !tr( "x-height" ).compare( mLabelPlacementComboBox->currentText() ) )
{
ds.labelPlacementMethod = QgsDiagramSettings::XHeight;
}

ds.backgroundColor = mBackgroundColorButton->color();
ds.penColor = mDiagramPenColorButton->color();
ds.penWidth = mPenWidthSpinBox->value();
Expand Down Expand Up @@ -1306,6 +1316,19 @@ void QgsVectorLayerProperties::handleDiagramItemDoubleClick( QTreeWidgetItem * i
}
}

void QgsVectorLayerProperties::handleDiagramTypeChanged( const QString& itemtext )
{
if ( tr( "Text diagram" ) == itemtext )
{
mLabelPlacementComboBox->show();
mLabelPlacementLabel->show();
}
else {
mLabelPlacementComboBox->hide();
mLabelPlacementLabel->hide();
}
}

void QgsVectorLayerProperties::useNewSymbology()
{
int res = QMessageBox::question( this, tr( "Symbology" ),
Expand Down Expand Up @@ -1565,6 +1588,9 @@ void QgsVectorLayerProperties::initDiagramTab()
mDiagramTypeComboBox->addItem( tr( "Pie chart" ) );
mDiagramTypeComboBox->addItem( tr( "Text diagram" ) );

mLabelPlacementComboBox->addItem( tr( "Height" ) );
mLabelPlacementComboBox->addItem( tr( "x-height" ) );

//insert all attributes into the combo boxes
const QgsFieldMap& layerFields = layer->pendingFields();
QgsFieldMap::const_iterator fieldIt = layerFields.constBegin();
Expand Down Expand Up @@ -1594,6 +1620,7 @@ void QgsVectorLayerProperties::initDiagramTab()
mDisplayDiagramsCheckBox->setChecked( false );
mFixedSizeCheckBox->setChecked( true );
mDiagramUnitComboBox->setCurrentIndex( mDiagramUnitComboBox->findText( tr( "MM" ) ) );
mLabelPlacementComboBox->setCurrentIndex( mLabelPlacementComboBox->findText( tr( "XHeight" ) ) );
mDiagramSizeSpinBox->setValue( 30 );
mScaleDependentDiagramVisibilityCheckBox->setChecked( false );

Expand Down Expand Up @@ -1645,6 +1672,15 @@ void QgsVectorLayerProperties::initDiagramTab()
mDiagramUnitComboBox->setCurrentIndex( 1 );
}

if ( settingList.at( 0 ).labelPlacementMethod == QgsDiagramSettings::Height )
{
mLabelPlacementComboBox->setCurrentIndex( 0 );
}
else
{
mLabelPlacementComboBox->setCurrentIndex( 1 );
}



QList< QColor > categoryColors = settingList.at( 0 ).categoryColors;
Expand Down Expand Up @@ -1696,5 +1732,10 @@ void QgsVectorLayerProperties::initDiagramTab()
}
}
}

// Hide/Show diagram specific widgets
handleDiagramTypeChanged( mDiagramTypeComboBox->currentText() );

QObject::connect( mDiagramAttributesTreeWidget, SIGNAL( itemDoubleClicked( QTreeWidgetItem*, int ) ), this, SLOT( handleDiagramItemDoubleClick( QTreeWidgetItem*, int ) ) );
QObject::connect( mDiagramTypeComboBox, SIGNAL( currentIndexChanged( const QString& ) ), this, SLOT( handleDiagramTypeChanged( const QString& ) ) );
}
1 change: 1 addition & 0 deletions src/app/qgsvectorlayerproperties.h
Expand Up @@ -144,6 +144,7 @@ class QgsVectorLayerProperties : public QDialog, private Ui::QgsVectorLayerPrope

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

signals:

Expand Down
20 changes: 18 additions & 2 deletions src/core/qgsdiagram.cpp
Expand Up @@ -197,12 +197,28 @@ void QgsTextDiagram::renderDiagram( const QgsAttributeMap& att, QgsRenderContext
for ( int i = 0; i < textPositions.size(); ++i )
{
QString val = att[ s.categoryIndices.at( i )].toString();
//find out dimensions
//find out dimesions
double textWidth = fontMetrics.width( val );
double textHeight = fontMetrics.height();

mPen.setColor( s.categoryColors.at( i ) );
p->setPen( mPen );
QPointF position = textPositions.at( i );
p->drawText( QPointF( position.x() - textWidth / 2.0, position.y() + fontMetrics.xHeight() ), val );

// Calculate vertical placement
double xOffset = 0;

switch( s.labelPlacementMethod )
{
case QgsDiagramSettings::Height:
xOffset = textHeight / 2.0;
break;

case QgsDiagramSettings::XHeight:
xOffset = fontMetrics.xHeight();
break;
}
p->drawText( QPointF( position.x() - textWidth / 2.0, position.y() + xOffset ), val );
}
}

Expand Down

0 comments on commit d5531b6

Please sign in to comment.