Skip to content

Commit

Permalink
Fix text diagram
Browse files Browse the repository at this point in the history
Assign userData properly to text diagram combobox item.
Use id's instead of translated text for selected item identification in combobox.
  • Loading branch information
m-kuhn committed Aug 29, 2012
1 parent 55b5dcb commit c8a3321
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
25 changes: 14 additions & 11 deletions src/app/qgsdiagramproperties.cpp
Expand Up @@ -93,7 +93,7 @@ QgsDiagramProperties::QgsDiagramProperties( QgsVectorLayer* layer, QWidget* pare
QPixmap pix = QgsApplication::getThemePixmap( "pie-chart" );
mDiagramTypeComboBox->addItem( pix, tr( "Pie chart" ), DIAGRAM_NAME_PIE );
pix = QgsApplication::getThemePixmap( "text" );
mDiagramTypeComboBox->addItem( pix, tr( "Text diagram", DIAGRAM_NAME_TEXT ) );
mDiagramTypeComboBox->addItem( pix, tr( "Text diagram" ), DIAGRAM_NAME_TEXT );
pix = QgsApplication::getThemePixmap( "histogram" );
mDiagramTypeComboBox->addItem( pix, tr( "Histogram" ), DIAGRAM_NAME_HISTOGRAM );

Expand Down Expand Up @@ -286,7 +286,7 @@ QgsDiagramProperties::QgsDiagramProperties( QgsVectorLayer* layer, QWidget* pare
{
QMessageBox::warning( this, tr( "Unknown diagram type." ),
tr( "The diagram type '%1' is unknown. A default type is selected for you." ).arg( diagramName ), QMessageBox::Ok );
mDiagramTypeComboBox->setCurrentIndex( mDiagramTypeComboBox->findText( tr( "Pie chart" ) ) );
mDiagramTypeComboBox->setCurrentIndex( mDiagramTypeComboBox->findData( DIAGRAM_NAME_PIE ) );
}
}
} // if ( !dr )
Expand All @@ -295,9 +295,10 @@ QgsDiagramProperties::QgsDiagramProperties( QgsVectorLayer* layer, QWidget* pare
on_mDisplayDiagramsGroupBox_toggled( mDisplayDiagramsGroupBox->isChecked() );
}

void QgsDiagramProperties::on_mDiagramTypeComboBox_currentIndexChanged( const QString& itemtext )
void QgsDiagramProperties::on_mDiagramTypeComboBox_currentIndexChanged( int index )
{
if ( tr( "Text diagram" ) == itemtext )
QString diagramType = mDiagramTypeComboBox->itemData( index ).toString();
if ( diagramType == DIAGRAM_NAME_TEXT )
{
mLabelPlacementComboBox->show();
mLabelPlacementLabel->show();
Expand All @@ -307,7 +308,7 @@ void QgsDiagramProperties::on_mDiagramTypeComboBox_currentIndexChanged( const QS
mLabelPlacementLabel->hide();
}

if ( tr( "Histogram" ) == itemtext )
if ( diagramType == DIAGRAM_NAME_HISTOGRAM )
{
mBarWidthLabel->show();
mBarWidthSpinBox->show();
Expand All @@ -320,7 +321,7 @@ void QgsDiagramProperties::on_mDiagramTypeComboBox_currentIndexChanged( const QS
mOrientationFrame->hide();
}

if ( tr( "Histogram" ) == itemtext || tr( "Text diagram" ) == itemtext )
if ( diagramType == DIAGRAM_NAME_HISTOGRAM || diagramType == DIAGRAM_NAME_TEXT )
{
mDiagramPropertiesTabWidget->setTabEnabled( 3, true );
}
Expand All @@ -329,7 +330,7 @@ void QgsDiagramProperties::on_mDiagramTypeComboBox_currentIndexChanged( const QS
mDiagramPropertiesTabWidget->setTabEnabled( 3, false );
}

if ( tr( "Text diagram" ) == itemtext || tr( "Pie chart" ) == itemtext )
if ( diagramType == DIAGRAM_NAME_TEXT || diagramType == DIAGRAM_NAME_PIE )
{
mScaleDependencyComboBox->show();
mScaleDependencyLabel->show();
Expand Down Expand Up @@ -419,7 +420,7 @@ void QgsDiagramProperties::on_mDisplayDiagramsGroupBox_toggled( bool checked )
// if enabled show diagram specific options
if ( checked )
{
on_mDiagramTypeComboBox_currentIndexChanged( mDiagramTypeComboBox->currentText() );
on_mDiagramTypeComboBox_currentIndexChanged( mDiagramTypeComboBox->currentIndex() );
// Update enabled/disabled state
}
}
Expand Down Expand Up @@ -464,15 +465,17 @@ void QgsDiagramProperties::apply()
}

QgsDiagram* diagram = 0;
if ( mDiagramTypeComboBox->itemData( mDiagramTypeComboBox->currentIndex() ) == DIAGRAM_NAME_TEXT )
int index = mDiagramTypeComboBox->currentIndex();
QString diagramType = mDiagramTypeComboBox->itemData( index ).toString();
if ( diagramType == DIAGRAM_NAME_TEXT )
{
diagram = new QgsTextDiagram();
}
else if ( mDiagramTypeComboBox->itemData( mDiagramTypeComboBox->currentIndex() ) == DIAGRAM_NAME_PIE )
else if ( diagramType == DIAGRAM_NAME_PIE )
{
diagram = new QgsPieDiagram();
}
else if ( mDiagramTypeComboBox->itemData( mDiagramTypeComboBox->currentIndex() ) == DIAGRAM_NAME_HISTOGRAM )
else // if ( diagramType == DIAGRAM_NAME_HISTOGRAM )
{
diagram = new QgsHistogramDiagram();
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsdiagramproperties.h
Expand Up @@ -34,7 +34,7 @@ class QgsDiagramProperties : public QWidget, private Ui::QgsDiagramPropertiesBas

public slots:
void apply();
void on_mDiagramTypeComboBox_currentIndexChanged( const QString& itemtext );
void on_mDiagramTypeComboBox_currentIndexChanged( int index );
void on_mTransparencySlider_valueChanged( int value );
void on_mAddCategoryPushButton_clicked();
void on_mBackgroundColorButton_clicked();
Expand Down

0 comments on commit c8a3321

Please sign in to comment.