Skip to content
Permalink
Browse files

Text diagrams: new label placement method (x-height)

  • Loading branch information
m-kuhn committed Aug 9, 2012
1 parent 05dee08 commit d5531b6708c9e98adbcd175f029c7e477442b874
@@ -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();
@@ -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" ),
@@ -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();
@@ -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 );

@@ -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;
@@ -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& ) ) );
}
@@ -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:

@@ -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 );
}
}

0 comments on commit d5531b6

Please sign in to comment.
You can’t perform that action at this time.