Skip to content

Commit c8a3321

Browse files
committed
Fix text diagram
Assign userData properly to text diagram combobox item. Use id's instead of translated text for selected item identification in combobox.
1 parent 55b5dcb commit c8a3321

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

src/app/qgsdiagramproperties.cpp

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ QgsDiagramProperties::QgsDiagramProperties( QgsVectorLayer* layer, QWidget* pare
9393
QPixmap pix = QgsApplication::getThemePixmap( "pie-chart" );
9494
mDiagramTypeComboBox->addItem( pix, tr( "Pie chart" ), DIAGRAM_NAME_PIE );
9595
pix = QgsApplication::getThemePixmap( "text" );
96-
mDiagramTypeComboBox->addItem( pix, tr( "Text diagram", DIAGRAM_NAME_TEXT ) );
96+
mDiagramTypeComboBox->addItem( pix, tr( "Text diagram" ), DIAGRAM_NAME_TEXT );
9797
pix = QgsApplication::getThemePixmap( "histogram" );
9898
mDiagramTypeComboBox->addItem( pix, tr( "Histogram" ), DIAGRAM_NAME_HISTOGRAM );
9999

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

298-
void QgsDiagramProperties::on_mDiagramTypeComboBox_currentIndexChanged( const QString& itemtext )
298+
void QgsDiagramProperties::on_mDiagramTypeComboBox_currentIndexChanged( int index )
299299
{
300-
if ( tr( "Text diagram" ) == itemtext )
300+
QString diagramType = mDiagramTypeComboBox->itemData( index ).toString();
301+
if ( diagramType == DIAGRAM_NAME_TEXT )
301302
{
302303
mLabelPlacementComboBox->show();
303304
mLabelPlacementLabel->show();
@@ -307,7 +308,7 @@ void QgsDiagramProperties::on_mDiagramTypeComboBox_currentIndexChanged( const QS
307308
mLabelPlacementLabel->hide();
308309
}
309310

310-
if ( tr( "Histogram" ) == itemtext )
311+
if ( diagramType == DIAGRAM_NAME_HISTOGRAM )
311312
{
312313
mBarWidthLabel->show();
313314
mBarWidthSpinBox->show();
@@ -320,7 +321,7 @@ void QgsDiagramProperties::on_mDiagramTypeComboBox_currentIndexChanged( const QS
320321
mOrientationFrame->hide();
321322
}
322323

323-
if ( tr( "Histogram" ) == itemtext || tr( "Text diagram" ) == itemtext )
324+
if ( diagramType == DIAGRAM_NAME_HISTOGRAM || diagramType == DIAGRAM_NAME_TEXT )
324325
{
325326
mDiagramPropertiesTabWidget->setTabEnabled( 3, true );
326327
}
@@ -329,7 +330,7 @@ void QgsDiagramProperties::on_mDiagramTypeComboBox_currentIndexChanged( const QS
329330
mDiagramPropertiesTabWidget->setTabEnabled( 3, false );
330331
}
331332

332-
if ( tr( "Text diagram" ) == itemtext || tr( "Pie chart" ) == itemtext )
333+
if ( diagramType == DIAGRAM_NAME_TEXT || diagramType == DIAGRAM_NAME_PIE )
333334
{
334335
mScaleDependencyComboBox->show();
335336
mScaleDependencyLabel->show();
@@ -419,7 +420,7 @@ void QgsDiagramProperties::on_mDisplayDiagramsGroupBox_toggled( bool checked )
419420
// if enabled show diagram specific options
420421
if ( checked )
421422
{
422-
on_mDiagramTypeComboBox_currentIndexChanged( mDiagramTypeComboBox->currentText() );
423+
on_mDiagramTypeComboBox_currentIndexChanged( mDiagramTypeComboBox->currentIndex() );
423424
// Update enabled/disabled state
424425
}
425426
}
@@ -464,15 +465,17 @@ void QgsDiagramProperties::apply()
464465
}
465466

466467
QgsDiagram* diagram = 0;
467-
if ( mDiagramTypeComboBox->itemData( mDiagramTypeComboBox->currentIndex() ) == DIAGRAM_NAME_TEXT )
468+
int index = mDiagramTypeComboBox->currentIndex();
469+
QString diagramType = mDiagramTypeComboBox->itemData( index ).toString();
470+
if ( diagramType == DIAGRAM_NAME_TEXT )
468471
{
469472
diagram = new QgsTextDiagram();
470473
}
471-
else if ( mDiagramTypeComboBox->itemData( mDiagramTypeComboBox->currentIndex() ) == DIAGRAM_NAME_PIE )
474+
else if ( diagramType == DIAGRAM_NAME_PIE )
472475
{
473476
diagram = new QgsPieDiagram();
474477
}
475-
else if ( mDiagramTypeComboBox->itemData( mDiagramTypeComboBox->currentIndex() ) == DIAGRAM_NAME_HISTOGRAM )
478+
else // if ( diagramType == DIAGRAM_NAME_HISTOGRAM )
476479
{
477480
diagram = new QgsHistogramDiagram();
478481
}

src/app/qgsdiagramproperties.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class QgsDiagramProperties : public QWidget, private Ui::QgsDiagramPropertiesBas
3434

3535
public slots:
3636
void apply();
37-
void on_mDiagramTypeComboBox_currentIndexChanged( const QString& itemtext );
37+
void on_mDiagramTypeComboBox_currentIndexChanged( int index );
3838
void on_mTransparencySlider_valueChanged( int value );
3939
void on_mAddCategoryPushButton_clicked();
4040
void on_mBackgroundColorButton_clicked();

0 commit comments

Comments
 (0)