@@ -183,15 +183,14 @@ QgsDiagramProperties::QgsDiagramProperties( QgsVectorLayer* layer, QWidget* pare
183
183
}
184
184
else // already a diagram renderer present
185
185
{
186
- mDisplayDiagramsGroupBox ->setChecked ( true );
187
-
188
186
// single category renderer or interpolated one?
189
187
mFixedSizeCheckBox ->setChecked ( dr->rendererName () == " SingleCategory" );
190
188
191
189
// assume single category or linearly interpolated diagram renderer for now
192
190
QList<QgsDiagramSettings> settingList = dr->diagramSettings ();
193
191
if ( settingList.size () > 0 )
194
192
{
193
+ mDisplayDiagramsGroupBox ->setChecked ( settingList.at ( 0 ).enabled );
195
194
mDiagramFont = settingList.at ( 0 ).font ;
196
195
QSizeF size = settingList.at ( 0 ).size ;
197
196
mBackgroundColorButton ->setColor ( settingList.at ( 0 ).backgroundColor );
@@ -520,184 +519,178 @@ void QgsDiagramProperties::apply()
520
519
QSettings ().setValue ( " /Windows/VectorLayerProperties/diagram/tab" ,
521
520
mDiagramPropertiesTabWidget ->currentIndex () );
522
521
523
- if ( !mDisplayDiagramsGroupBox ->isChecked () )
522
+ QgsDiagram* diagram = 0 ;
523
+ int index = mDiagramTypeComboBox ->currentIndex ();
524
+ QString diagramType = mDiagramTypeComboBox ->itemData ( index ).toString ();
525
+
526
+ if ( 0 == mDiagramAttributesTreeWidget ->topLevelItemCount () )
524
527
{
525
- mLayer ->setDiagramRenderer ( 0 );
528
+ QgisApp::instance ()->messageBar ()->pushMessage (
529
+ tr ( " Diagrams: No attributes added." ),
530
+ tr ( " You did not add any attributes to this diagram layer. Please specify the attributes to visualize on the diagrams or disable diagrams." ),
531
+ QgsMessageBar::WARNING );
526
532
}
527
- else
528
- {
529
- QgsDiagram* diagram = 0 ;
530
- int index = mDiagramTypeComboBox ->currentIndex ();
531
- QString diagramType = mDiagramTypeComboBox ->itemData ( index ).toString ();
532
533
533
- if ( 0 == mDiagramAttributesTreeWidget ->topLevelItemCount () )
534
- {
535
- QgisApp::instance ()->messageBar ()->pushMessage (
536
- tr ( " Diagrams: No attributes added." ),
537
- tr ( " You did not add any attributes to this diagram layer. Please specify the attributes to visualize on the diagrams or disable diagrams." ),
538
- QgsMessageBar::WARNING );
539
- }
534
+ bool scaleAttributeValueOk = false ;
535
+ // Check if a (usable) scale attribute value is inserted
536
+ mValueLineEdit ->text ().toDouble ( &scaleAttributeValueOk );
540
537
541
- bool scaleAttributeValueOk = false ;
542
- // Check if a (usable) scale attribute value is inserted
543
- mValueLineEdit ->text ().toDouble ( &scaleAttributeValueOk );
538
+ if ( !mFixedSizeCheckBox ->isChecked () && !scaleAttributeValueOk )
539
+ {
540
+ double maxVal = DBL_MIN;
541
+ QgsVectorDataProvider* provider = mLayer ->dataProvider ();
544
542
545
- if ( ! mFixedSizeCheckBox -> isChecked () && !scaleAttributeValueOk )
543
+ if ( provider )
546
544
{
547
- double maxVal = DBL_MIN;
548
- QgsVectorDataProvider* provider = mLayer ->dataProvider ();
549
-
550
- if ( provider )
545
+ if ( diagramType == DIAGRAM_NAME_HISTOGRAM )
551
546
{
552
- if ( diagramType == DIAGRAM_NAME_HISTOGRAM )
547
+ // Find maximum value
548
+ for ( int i = 0 ; i < mDiagramAttributesTreeWidget ->topLevelItemCount (); ++i )
553
549
{
554
- // Find maximum value
555
- for ( int i = 0 ; i < mDiagramAttributesTreeWidget ->topLevelItemCount (); ++i )
550
+ QString fldName = mDiagramAttributesTreeWidget ->topLevelItem ( i )->data ( 0 , Qt::UserRole ).toString ();
551
+ if ( fldName.count () >= 2 && fldName.at ( 0 ) == ' "' && fldName.at ( fldName.count () - 1 ) == ' "' )
552
+ fldName = fldName.mid ( 1 , fldName.count () - 2 ); // remove enclosing double quotes
553
+ int fld = provider->fieldNameIndex ( fldName );
554
+ if ( fld != -1 )
556
555
{
557
- QString fldName = mDiagramAttributesTreeWidget ->topLevelItem ( i )->data ( 0 , Qt::UserRole ).toString ();
558
- if ( fldName.count () >= 2 && fldName.at ( 0 ) == ' "' && fldName.at ( fldName.count () - 1 ) == ' "' )
559
- fldName = fldName.mid ( 1 , fldName.count () - 2 ); // remove enclosing double quotes
560
- int fld = provider->fieldNameIndex ( fldName );
561
- if ( fld != -1 )
562
- {
563
- bool ok = false ;
564
- double val = provider->maximumValue ( fld ).toDouble ( &ok );
565
- if ( ok )
566
- maxVal = qMax ( maxVal, val );
567
- }
556
+ bool ok = false ;
557
+ double val = provider->maximumValue ( fld ).toDouble ( &ok );
558
+ if ( ok )
559
+ maxVal = qMax ( maxVal, val );
568
560
}
569
561
}
570
- else
571
- {
572
- maxVal = provider->maximumValue ( mSizeAttributeComboBox ->itemData ( mSizeAttributeComboBox ->currentIndex () ).toInt () ).toDouble ();
573
- }
574
562
}
575
-
576
- if ( maxVal != DBL_MIN )
563
+ else
577
564
{
578
- QgisApp::instance ()->messageBar ()->pushMessage (
579
- tr ( " Interpolation value" ),
580
- tr ( " You did not specify an interpolation value. A default value of %1 has been set." ).arg ( QString::number ( maxVal ) ),
581
- QgsMessageBar::INFO,
582
- 5 );
583
-
584
- mValueLineEdit ->setText ( QString::number ( maxVal ) );
565
+ maxVal = provider->maximumValue ( mSizeAttributeComboBox ->itemData ( mSizeAttributeComboBox ->currentIndex () ).toInt () ).toDouble ();
585
566
}
586
567
}
587
568
588
- if ( diagramType == DIAGRAM_NAME_TEXT )
589
- {
590
- diagram = new QgsTextDiagram ();
591
- }
592
- else if ( diagramType == DIAGRAM_NAME_PIE )
593
- {
594
- diagram = new QgsPieDiagram ();
595
- }
596
- else // if ( diagramType == DIAGRAM_NAME_HISTOGRAM )
569
+ if ( maxVal != DBL_MIN )
597
570
{
598
- diagram = new QgsHistogramDiagram ();
571
+ QgisApp::instance ()->messageBar ()->pushMessage (
572
+ tr ( " Interpolation value" ),
573
+ tr ( " You did not specify an interpolation value. A default value of %1 has been set." ).arg ( QString::number ( maxVal ) ),
574
+ QgsMessageBar::INFO,
575
+ 5 );
576
+
577
+ mValueLineEdit ->setText ( QString::number ( maxVal ) );
599
578
}
579
+ }
600
580
601
- QgsDiagramSettings ds;
602
- ds.font = mDiagramFont ;
603
- ds.transparency = mTransparencySlider ->value ();
581
+ if ( diagramType == DIAGRAM_NAME_TEXT )
582
+ {
583
+ diagram = new QgsTextDiagram ();
584
+ }
585
+ else if ( diagramType == DIAGRAM_NAME_PIE )
586
+ {
587
+ diagram = new QgsPieDiagram ();
588
+ }
589
+ else // if ( diagramType == DIAGRAM_NAME_HISTOGRAM )
590
+ {
591
+ diagram = new QgsHistogramDiagram ();
592
+ }
604
593
605
- QList<QColor> categoryColors;
606
- QList<QString> categoryAttributes;
607
- for ( int i = 0 ; i < mDiagramAttributesTreeWidget ->topLevelItemCount (); ++i )
608
- {
609
- QColor color = mDiagramAttributesTreeWidget ->topLevelItem ( i )->background ( 1 ).color ();
610
- color.setAlpha ( 255 - ds.transparency );
611
- categoryColors.append ( color );
612
- categoryAttributes.append ( mDiagramAttributesTreeWidget ->topLevelItem ( i )->data ( 0 , Qt::UserRole ).toString () );
613
- }
614
- ds.categoryColors = categoryColors;
615
- ds.categoryAttributes = categoryAttributes;
616
- ds.size = QSizeF ( mDiagramSizeSpinBox ->value (), mDiagramSizeSpinBox ->value () );
617
- ds.sizeType = static_cast <QgsDiagramSettings::SizeType>( mDiagramUnitComboBox ->itemData ( mDiagramUnitComboBox ->currentIndex () ).toInt () );
618
- ds.labelPlacementMethod = static_cast <QgsDiagramSettings::LabelPlacementMethod>( mLabelPlacementComboBox ->itemData ( mLabelPlacementComboBox ->currentIndex () ).toInt () );
619
- ds.scaleByArea = mScaleDependencyComboBox ->itemData ( mScaleDependencyComboBox ->currentIndex () ).toBool ();
620
-
621
- if ( mIncreaseSmallDiagramsGroupBox ->isChecked () )
622
- {
623
- ds.minimumSize = mIncreaseMinimumSizeSpinBox ->value ();
624
- }
625
- else
626
- {
627
- ds.minimumSize = 0 ;
628
- }
594
+ QgsDiagramSettings ds;
595
+ ds.enabled = mDisplayDiagramsGroupBox ->isChecked ();
596
+ ds.font = mDiagramFont ;
597
+ ds.transparency = mTransparencySlider ->value ();
629
598
630
- ds.backgroundColor = mBackgroundColorButton ->color ();
631
- ds.penColor = mDiagramPenColorButton ->color ();
632
- ds.penWidth = mPenWidthSpinBox ->value ();
633
- if ( mVisibilityGroupBox ->isChecked () )
634
- {
635
- ds.minScaleDenominator = mMinimumDiagramScaleLineEdit ->text ().toDouble ();
636
- ds.maxScaleDenominator = mMaximumDiagramScaleLineEdit ->text ().toDouble ();
637
- }
638
- else
639
- {
640
- ds.minScaleDenominator = -1 ;
641
- ds.maxScaleDenominator = -1 ;
642
- }
599
+ QList<QColor> categoryColors;
600
+ QList<QString> categoryAttributes;
601
+ for ( int i = 0 ; i < mDiagramAttributesTreeWidget ->topLevelItemCount (); ++i )
602
+ {
603
+ QColor color = mDiagramAttributesTreeWidget ->topLevelItem ( i )->background ( 1 ).color ();
604
+ color.setAlpha ( 255 - ds.transparency );
605
+ categoryColors.append ( color );
606
+ categoryAttributes.append ( mDiagramAttributesTreeWidget ->topLevelItem ( i )->data ( 0 , Qt::UserRole ).toString () );
607
+ }
608
+ ds.categoryColors = categoryColors;
609
+ ds.categoryAttributes = categoryAttributes;
610
+ ds.size = QSizeF ( mDiagramSizeSpinBox ->value (), mDiagramSizeSpinBox ->value () );
611
+ ds.sizeType = static_cast <QgsDiagramSettings::SizeType>( mDiagramUnitComboBox ->itemData ( mDiagramUnitComboBox ->currentIndex () ).toInt () );
612
+ ds.labelPlacementMethod = static_cast <QgsDiagramSettings::LabelPlacementMethod>( mLabelPlacementComboBox ->itemData ( mLabelPlacementComboBox ->currentIndex () ).toInt () );
613
+ ds.scaleByArea = mScaleDependencyComboBox ->itemData ( mScaleDependencyComboBox ->currentIndex () ).toBool ();
643
614
644
- // Diagram angle offset (pie)
645
- ds.angleOffset = mAngleOffsetComboBox ->itemData ( mAngleOffsetComboBox ->currentIndex () ).toInt ();
615
+ if ( mIncreaseSmallDiagramsGroupBox ->isChecked () )
616
+ {
617
+ ds.minimumSize = mIncreaseMinimumSizeSpinBox ->value ();
618
+ }
619
+ else
620
+ {
621
+ ds.minimumSize = 0 ;
622
+ }
646
623
647
- // Diagram orientation (histogram)
648
- ds.diagramOrientation = static_cast <QgsDiagramSettings::DiagramOrientation>( mOrientationButtonGroup ->checkedButton ()->property ( " direction" ).toInt () );
624
+ ds.backgroundColor = mBackgroundColorButton ->color ();
625
+ ds.penColor = mDiagramPenColorButton ->color ();
626
+ ds.penWidth = mPenWidthSpinBox ->value ();
627
+ if ( mVisibilityGroupBox ->isChecked () )
628
+ {
629
+ ds.minScaleDenominator = mMinimumDiagramScaleLineEdit ->text ().toDouble ();
630
+ ds.maxScaleDenominator = mMaximumDiagramScaleLineEdit ->text ().toDouble ();
631
+ }
632
+ else
633
+ {
634
+ ds.minScaleDenominator = -1 ;
635
+ ds.maxScaleDenominator = -1 ;
636
+ }
649
637
650
- ds.barWidth = mBarWidthSpinBox ->value ();
638
+ // Diagram angle offset (pie)
639
+ ds.angleOffset = mAngleOffsetComboBox ->itemData ( mAngleOffsetComboBox ->currentIndex () ).toInt ();
651
640
652
- if ( mFixedSizeCheckBox ->isChecked () )
653
- {
654
- QgsSingleCategoryDiagramRenderer* dr = new QgsSingleCategoryDiagramRenderer ();
655
- dr->setDiagram ( diagram );
656
- dr->setDiagramSettings ( ds );
657
- mLayer ->setDiagramRenderer ( dr );
658
- }
659
- else
660
- {
661
- QgsLinearlyInterpolatedDiagramRenderer* dr = new QgsLinearlyInterpolatedDiagramRenderer ();
662
- dr->setLowerValue ( 0.0 );
663
- dr->setLowerSize ( QSizeF ( 0.0 , 0.0 ) );
664
- dr->setUpperValue ( mValueLineEdit ->text ().toDouble () );
665
- dr->setUpperSize ( QSizeF ( mSizeSpinBox ->value (), mSizeSpinBox ->value () ) );
666
- bool isExpression = mSizeAttributeComboBox ->currentIndex () >= mAvailableAttributes ;
667
- dr->setClassificationAttributeIsExpression ( isExpression );
668
- if ( isExpression )
669
- {
670
- dr->setClassificationAttributeExpression ( mSizeAttributeComboBox ->currentText () );
671
- }
672
- else
673
- {
674
- dr->setClassificationAttribute ( mSizeAttributeComboBox ->itemData ( mSizeAttributeComboBox ->currentIndex () ).toInt () );
675
- }
676
- dr->setDiagram ( diagram );
677
- dr->setDiagramSettings ( ds );
678
- mLayer ->setDiagramRenderer ( dr );
679
- }
641
+ // Diagram orientation (histogram)
642
+ ds.diagramOrientation = static_cast <QgsDiagramSettings::DiagramOrientation>( mOrientationButtonGroup ->checkedButton ()->property ( " direction" ).toInt () );
643
+
644
+ ds.barWidth = mBarWidthSpinBox ->value ();
680
645
681
- QgsDiagramLayerSettings dls;
682
- dls.dist = mDiagramDistanceSpinBox ->value ();
683
- dls.priority = mPrioritySlider ->value ();
684
- if ( mDataDefinedPositionGroupBox ->isChecked () )
646
+ if ( mFixedSizeCheckBox ->isChecked () )
647
+ {
648
+ QgsSingleCategoryDiagramRenderer* dr = new QgsSingleCategoryDiagramRenderer ();
649
+ dr->setDiagram ( diagram );
650
+ dr->setDiagramSettings ( ds );
651
+ mLayer ->setDiagramRenderer ( dr );
652
+ }
653
+ else
654
+ {
655
+ QgsLinearlyInterpolatedDiagramRenderer* dr = new QgsLinearlyInterpolatedDiagramRenderer ();
656
+ dr->setLowerValue ( 0.0 );
657
+ dr->setLowerSize ( QSizeF ( 0.0 , 0.0 ) );
658
+ dr->setUpperValue ( mValueLineEdit ->text ().toDouble () );
659
+ dr->setUpperSize ( QSizeF ( mSizeSpinBox ->value (), mSizeSpinBox ->value () ) );
660
+ bool isExpression = mSizeAttributeComboBox ->currentIndex () >= mAvailableAttributes ;
661
+ dr->setClassificationAttributeIsExpression ( isExpression );
662
+ if ( isExpression )
685
663
{
686
- dls.xPosColumn = mDataDefinedXComboBox ->itemData ( mDataDefinedXComboBox ->currentIndex () ).toInt ();
687
- dls.yPosColumn = mDataDefinedYComboBox ->itemData ( mDataDefinedYComboBox ->currentIndex () ).toInt ();
664
+ dr->setClassificationAttributeExpression ( mSizeAttributeComboBox ->currentText () );
688
665
}
689
666
else
690
667
{
691
- dls.xPosColumn = -1 ;
692
- dls.yPosColumn = -1 ;
668
+ dr->setClassificationAttribute ( mSizeAttributeComboBox ->itemData ( mSizeAttributeComboBox ->currentIndex () ).toInt () );
693
669
}
694
- dls.placement = ( QgsDiagramLayerSettings::Placement )mPlacementComboBox ->itemData ( mPlacementComboBox ->currentIndex () ).toInt ();
695
- if ( mLineOptionsComboBox ->isEnabled () )
696
- {
697
- dls.placementFlags = static_cast <QgsDiagramLayerSettings::LinePlacementFlags>( mLineOptionsComboBox ->itemData ( mLineOptionsComboBox ->currentIndex () ).toInt () );
698
- }
699
- mLayer ->setDiagramLayerSettings ( dls );
670
+ dr->setDiagram ( diagram );
671
+ dr->setDiagramSettings ( ds );
672
+ mLayer ->setDiagramRenderer ( dr );
673
+ }
674
+
675
+ QgsDiagramLayerSettings dls;
676
+ dls.dist = mDiagramDistanceSpinBox ->value ();
677
+ dls.priority = mPrioritySlider ->value ();
678
+ if ( mDataDefinedPositionGroupBox ->isChecked () )
679
+ {
680
+ dls.xPosColumn = mDataDefinedXComboBox ->itemData ( mDataDefinedXComboBox ->currentIndex () ).toInt ();
681
+ dls.yPosColumn = mDataDefinedYComboBox ->itemData ( mDataDefinedYComboBox ->currentIndex () ).toInt ();
682
+ }
683
+ else
684
+ {
685
+ dls.xPosColumn = -1 ;
686
+ dls.yPosColumn = -1 ;
687
+ }
688
+ dls.placement = ( QgsDiagramLayerSettings::Placement )mPlacementComboBox ->itemData ( mPlacementComboBox ->currentIndex () ).toInt ();
689
+ if ( mLineOptionsComboBox ->isEnabled () )
690
+ {
691
+ dls.placementFlags = static_cast <QgsDiagramLayerSettings::LinePlacementFlags>( mLineOptionsComboBox ->itemData ( mLineOptionsComboBox ->currentIndex () ).toInt () );
700
692
}
693
+ mLayer ->setDiagramLayerSettings ( dls );
701
694
}
702
695
703
696
void QgsDiagramProperties::showSizeAttributeExpressionDialog ()
0 commit comments