@@ -48,8 +48,8 @@ QgsDiagramProperties::QgsDiagramProperties( QgsVectorLayer* layer, QWidget* pare
48
48
mMinimumDiagramScaleLineEdit ->setValidator ( new QDoubleValidator ( mMinimumDiagramScaleLineEdit ) );
49
49
mMaximumDiagramScaleLineEdit ->setValidator ( new QDoubleValidator ( mMaximumDiagramScaleLineEdit ) );
50
50
51
- mDiagramUnitComboBox ->insertItem ( 0 , tr ( " mm" ) );
52
- mDiagramUnitComboBox ->insertItem ( 1 , tr ( " Map units" ) );
51
+ mDiagramUnitComboBox ->insertItem ( 0 , tr ( " mm" ), QgsDiagramSettings::MM );
52
+ mDiagramUnitComboBox ->insertItem ( 1 , tr ( " Map units" ), QgsDiagramSettings::MapUnits );
53
53
54
54
QGis::GeometryType layerType = layer->geometryType ();
55
55
if ( layerType == QGis::UnknownGeometry || layerType == QGis::NoGeometry )
@@ -79,26 +79,26 @@ QgsDiagramProperties::QgsDiagramProperties( QgsVectorLayer* layer, QWidget* pare
79
79
80
80
if ( layerType == QGis::Line )
81
81
{
82
- mLineOptionsComboBox ->addItem ( tr ( " On line" ), 1 );
83
- mLineOptionsComboBox ->addItem ( tr ( " Above line" ), 2 );
84
- mLineOptionsComboBox ->addItem ( tr ( " Below Line" ), 4 );
85
- mLineOptionsComboBox ->addItem ( tr ( " Map orientation" ), 8 );
82
+ mLineOptionsComboBox ->addItem ( tr ( " On line" ), QgsDiagramLayerSettings::OnLine );
83
+ mLineOptionsComboBox ->addItem ( tr ( " Above line" ), QgsDiagramLayerSettings::AboveLine );
84
+ mLineOptionsComboBox ->addItem ( tr ( " Below Line" ), QgsDiagramLayerSettings::BelowLine );
85
+ mLineOptionsComboBox ->addItem ( tr ( " Map orientation" ), QgsDiagramLayerSettings::MapOrientation );
86
86
}
87
87
else
88
88
{
89
89
mLineOptionsComboBox ->setVisible ( false );
90
90
mLineOptionsLabel ->setVisible ( false );
91
91
}
92
92
93
- mDiagramTypeComboBox ->addItem ( tr ( " Pie chart" ) );
94
- mDiagramTypeComboBox ->addItem ( tr ( " Text diagram" ) );
95
- mDiagramTypeComboBox ->addItem ( tr ( " Histogram" ) );
93
+ mDiagramTypeComboBox ->addItem ( tr ( " Pie chart" ), " Pie " );
94
+ mDiagramTypeComboBox ->addItem ( tr ( " Text diagram" ), " Text " );
95
+ mDiagramTypeComboBox ->addItem ( tr ( " Histogram" ), DIAGRAM_NAME_HISTOGRAM );
96
96
97
- mLabelPlacementComboBox ->addItem ( tr ( " Height" ) );
98
- mLabelPlacementComboBox ->addItem ( tr ( " x-height" ) );
97
+ mLabelPlacementComboBox ->addItem ( tr ( " Height" ), QgsDiagramSettings::Height );
98
+ mLabelPlacementComboBox ->addItem ( tr ( " x-height" ), QgsDiagramSettings::XHeight );
99
99
100
- mScaleDependencyComboBox ->addItem ( tr ( " Area" ) );
101
- mScaleDependencyComboBox ->addItem ( tr ( " Diameter" ) );
100
+ mScaleDependencyComboBox ->addItem ( tr ( " Area" ), true );
101
+ mScaleDependencyComboBox ->addItem ( tr ( " Diameter" ), false );
102
102
103
103
// insert all attributes into the combo boxes
104
104
const QgsFieldMap& layerFields = layer->pendingFields ();
@@ -195,6 +195,10 @@ QgsDiagramProperties::QgsDiagramProperties( QgsVectorLayer* layer, QWidget* pare
195
195
mLabelPlacementComboBox ->setCurrentIndex ( 1 );
196
196
}
197
197
198
+ mOrientationLeftButton ->setProperty ( " direction" , QgsDiagramSettings::Left );
199
+ mOrientationRightButton ->setProperty ( " direction" , QgsDiagramSettings::Right );
200
+ mOrientationUpButton ->setProperty ( " direction" , QgsDiagramSettings::Up );
201
+ mOrientationDownButton ->setProperty ( " direction" , QgsDiagramSettings::Down );
198
202
switch ( settingList.at ( 0 ).diagramOrientation )
199
203
{
200
204
case QgsDiagramSettings::Left:
@@ -274,19 +278,8 @@ QgsDiagramProperties::QgsDiagramProperties( QgsVectorLayer* layer, QWidget* pare
274
278
if ( dr->diagram () )
275
279
{
276
280
QString diagramName = dr->diagram ()->diagramName ();
277
- if ( diagramName == " Text" )
278
- {
279
- mDiagramTypeComboBox ->setCurrentIndex ( mDiagramTypeComboBox ->findText ( tr ( " Text diagram" ) ) );
280
- }
281
- else if ( diagramName == " Pie" )
282
- {
283
- mDiagramTypeComboBox ->setCurrentIndex ( mDiagramTypeComboBox ->findText ( tr ( " Pie chart" ) ) );
284
- }
285
- else if ( diagramName == " Histogram" )
286
- {
287
- mDiagramTypeComboBox ->setCurrentIndex ( mDiagramTypeComboBox ->findText ( tr ( " Histogram" ) ) );
288
- }
289
- else
281
+ mDiagramTypeComboBox ->setCurrentIndex ( mDiagramTypeComboBox ->findData ( diagramName ) );
282
+ if ( mDiagramTypeComboBox ->currentIndex () == -1 )
290
283
{
291
284
QMessageBox::warning ( this , tr ( " Unknown diagram type." ),
292
285
tr ( " The diagram type '%1' is unknown. A default type is selected for you." ).arg ( diagramName ), QMessageBox::Ok );
@@ -468,15 +461,15 @@ void QgsDiagramProperties::apply()
468
461
}
469
462
470
463
QgsDiagram* diagram = 0 ;
471
- if ( mDiagramTypeComboBox ->currentText () == tr ( " Text diagram " ) )
464
+ if ( mDiagramTypeComboBox ->itemData ( mDiagramTypeComboBox -> currentIndex () ) == DIAGRAM_NAME_TEXT )
472
465
{
473
466
diagram = new QgsTextDiagram ();
474
467
}
475
- else if ( mDiagramTypeComboBox ->currentText () == tr ( " Pie chart " ) )
468
+ else if ( mDiagramTypeComboBox ->itemData ( mDiagramTypeComboBox -> currentIndex () ) == DIAGRAM_NAME_PIE )
476
469
{
477
470
diagram = new QgsPieDiagram ();
478
471
}
479
- else if ( mDiagramTypeComboBox ->currentText () == tr ( " Histogram " ) )
472
+ else if ( mDiagramTypeComboBox ->itemData ( mDiagramTypeComboBox -> currentIndex () ) == DIAGRAM_NAME_HISTOGRAM )
480
473
{
481
474
diagram = new QgsHistogramDiagram ();
482
475
}
@@ -497,33 +490,10 @@ void QgsDiagramProperties::apply()
497
490
ds.categoryColors = categoryColors;
498
491
ds.categoryIndices = categoryAttributes;
499
492
ds.size = QSizeF ( mDiagramSizeSpinBox ->value (), mDiagramSizeSpinBox ->value () );
500
- if ( mDiagramUnitComboBox ->currentText () == tr ( " Map units" ) )
501
- {
502
- ds.sizeType = QgsDiagramSettings::MapUnits;
503
- }
504
- else
505
- {
506
- ds.sizeType = QgsDiagramSettings::MM;
507
- }
508
-
509
- if ( tr ( " Height" ) == mLabelPlacementComboBox ->currentText () )
510
- {
511
- ds.labelPlacementMethod = QgsDiagramSettings::Height;
512
- }
513
- else
514
- {
515
- ds.labelPlacementMethod = QgsDiagramSettings::XHeight;
516
- }
517
-
518
- if ( tr ( " Area" ) == mScaleDependencyComboBox ->currentText () )
519
- {
520
- ds.scaleByArea = true ;
521
- }
522
- else
523
- {
524
- ds.scaleByArea = false ;
525
- }
526
-
493
+ ds.sizeType = static_cast <QgsDiagramSettings::SizeType> ( mDiagramUnitComboBox ->itemData ( mDiagramUnitComboBox ->currentIndex () ).toInt () );
494
+ ds.labelPlacementMethod = static_cast <QgsDiagramSettings::LabelPlacementMethod>( mLabelPlacementComboBox ->itemData ( mLabelPlacementComboBox ->currentIndex () ).toInt () );
495
+ ds.scaleByArea = mScaleDependencyComboBox ->itemData ( mScaleDependencyComboBox ->currentIndex () ).toBool ();
496
+
527
497
if ( mIncreaseSmallDiagramsGroupBox ->isChecked () )
528
498
{
529
499
ds.minimumSize = mIncreaseMinimumSizeSpinBox ->value ();
@@ -549,22 +519,7 @@ void QgsDiagramProperties::apply()
549
519
}
550
520
551
521
// Diagram orientation (histogram)
552
- if ( tr ( " Up" ) == mOrientationButtonGroup ->checkedButton ()->text () )
553
- {
554
- ds.diagramOrientation = QgsDiagramSettings::Up;
555
- }
556
- else if ( tr ( " Down" ) == mOrientationButtonGroup ->checkedButton ()->text () )
557
- {
558
- ds.diagramOrientation = QgsDiagramSettings::Down;
559
- }
560
- else if ( tr ( " Right" ) == mOrientationButtonGroup ->checkedButton ()->text () )
561
- {
562
- ds.diagramOrientation = QgsDiagramSettings::Right;
563
- }
564
- else if ( tr ( " Left" ) == mOrientationButtonGroup ->checkedButton ()->text () )
565
- {
566
- ds.diagramOrientation = QgsDiagramSettings::Left;
567
- }
522
+ ds.diagramOrientation = static_cast <QgsDiagramSettings::DiagramOrientation> ( mOrientationButtonGroup ->checkedButton ()->property ( " direction" ).toInt () );
568
523
569
524
ds.barWidth = mBarWidthSpinBox ->value ();
570
525
@@ -604,7 +559,7 @@ void QgsDiagramProperties::apply()
604
559
dls.placement = ( QgsDiagramLayerSettings::Placement )mPlacementComboBox ->itemData ( mPlacementComboBox ->currentIndex () ).toInt ();
605
560
if ( mLineOptionsComboBox ->isEnabled () )
606
561
{
607
- dls.placementFlags = ( QgsDiagramLayerSettings::LinePlacementFlags ) mLineOptionsComboBox ->itemData ( mLineOptionsComboBox ->currentIndex () ).toInt ();
562
+ dls.placementFlags = static_cast < QgsDiagramLayerSettings::LinePlacementFlags>( mLineOptionsComboBox ->itemData ( mLineOptionsComboBox ->currentIndex () ).toInt () );
608
563
}
609
564
mLayer ->setDiagramLayerSettings ( dls );
610
565
}
0 commit comments