Skip to content

Commit 7ce618a

Browse files
committed
Start modernising diagram ui
1 parent 12d92e4 commit 7ce618a

5 files changed

+1705
-1037
lines changed

src/app/qgsdiagramproperties.cpp

+110-52
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,11 @@ QgsDiagramProperties::QgsDiagramProperties( QgsVectorLayer* layer, QWidget* pare
4949

5050
setupUi( this );
5151

52-
int tabIdx = QSettings().value( "/Windows/VectorLayerProperties/diagram/tab", 0 ).toInt();
52+
// get rid of annoying outer focus rect on Mac
53+
mDiagramOptionsListWidget->setAttribute( Qt::WA_MacShowFocusRect, false );
5354

54-
mDiagramPropertiesTabWidget->setCurrentIndex( tabIdx );
55+
connect( mEnableDiagramsCheckBox, SIGNAL( toggled( bool ) ), mDiagramTypeFrame, SLOT( setEnabled( bool ) ) );
56+
connect( mEnableDiagramsCheckBox, SIGNAL( toggled( bool ) ), mDiagramFrame, SLOT( setEnabled( bool ) ) );
5557

5658
mBackgroundColorButton->setColorDialogTitle( tr( "Select background color" ) );
5759
mBackgroundColorButton->setAllowAlpha( true );
@@ -74,12 +76,14 @@ QgsDiagramProperties::QgsDiagramProperties( QgsVectorLayer* layer, QWidget* pare
7476
QGis::GeometryType layerType = layer->geometryType();
7577
if ( layerType == QGis::UnknownGeometry || layerType == QGis::NoGeometry )
7678
{
77-
mDisplayDiagramsGroupBox->setChecked( false );
78-
mDisplayDiagramsGroupBox->setEnabled( false );
79+
mEnableDiagramsCheckBox->setChecked( false );
80+
mEnableDiagramsCheckBox->setEnabled( false );
81+
mDiagramTypeFrame->setEnabled( false );
82+
mDiagramFrame->setEnabled( false );
7983
}
8084

8185
//insert placement options
82-
86+
mPlacementComboBox->blockSignals( true );
8387
if ( layerType == QGis::Point || layerType == QGis::Polygon )
8488
{
8589
mPlacementComboBox->addItem( tr( "Around Point" ), QgsDiagramLayerSettings::AroundPoint );
@@ -96,6 +100,7 @@ QgsDiagramProperties::QgsDiagramProperties( QgsVectorLayer* layer, QWidget* pare
96100
{
97101
mPlacementComboBox->addItem( tr( "Free" ), QgsDiagramLayerSettings::Free );
98102
}
103+
mPlacementComboBox->blockSignals( false );
99104

100105
if ( layerType == QGis::Line )
101106
{
@@ -110,12 +115,14 @@ QgsDiagramProperties::QgsDiagramProperties( QgsVectorLayer* layer, QWidget* pare
110115
mLineOptionsLabel->setVisible( false );
111116
}
112117

118+
mDiagramTypeComboBox->blockSignals( true );
113119
QPixmap pix = QgsApplication::getThemePixmap( "pie-chart" );
114120
mDiagramTypeComboBox->addItem( pix, tr( "Pie chart" ), DIAGRAM_NAME_PIE );
115121
pix = QgsApplication::getThemePixmap( "text" );
116122
mDiagramTypeComboBox->addItem( pix, tr( "Text diagram" ), DIAGRAM_NAME_TEXT );
117123
pix = QgsApplication::getThemePixmap( "histogram" );
118124
mDiagramTypeComboBox->addItem( pix, tr( "Histogram" ), DIAGRAM_NAME_HISTOGRAM );
125+
mDiagramTypeComboBox->blockSignals( false );
119126

120127
mLabelPlacementComboBox->addItem( tr( "Height" ), QgsDiagramSettings::Height );
121128
mLabelPlacementComboBox->addItem( tr( "x-height" ), QgsDiagramSettings::XHeight );
@@ -131,6 +138,25 @@ QgsDiagramProperties::QgsDiagramProperties( QgsVectorLayer* layer, QWidget* pare
131138
mAngleOffsetComboBox->addItem( tr( "Bottom" ), 270 * 16 );
132139
mAngleOffsetComboBox->addItem( tr( "Left" ), 180 * 16 );
133140

141+
QSettings settings;
142+
143+
// reset horiz strech of left side of options splitter (set to 1 for previewing in Qt Designer)
144+
QSizePolicy policy( mDiagramOptionsListFrame->sizePolicy() );
145+
policy.setHorizontalStretch( 0 );
146+
mDiagramOptionsListFrame->setSizePolicy( policy );
147+
if ( !settings.contains( QString( "/Windows/Diagrams/OptionsSplitState" ) ) )
148+
{
149+
// set left list widget width on intial showing
150+
QList<int> splitsizes;
151+
splitsizes << 115;
152+
mDiagramOptionsSplitter->setSizes( splitsizes );
153+
}
154+
155+
// restore dialog, splitters and current tab
156+
mDiagramOptionsSplitter->restoreState( settings.value( QString( "/Windows/Diagrams/OptionsSplitState" ) ).toByteArray() );
157+
mDiagramOptionsListWidget->setCurrentRow( settings.value( QString( "/Windows/Diagrams/Tab" ), 0 ).toInt() );
158+
159+
134160
//insert all attributes into the combo boxes
135161
const QgsFields& layerFields = layer->pendingFields();
136162
for ( int idx = 0; idx < layerFields.count(); ++idx )
@@ -153,11 +179,17 @@ QgsDiagramProperties::QgsDiagramProperties( QgsVectorLayer* layer, QWidget* pare
153179
const QgsDiagramRendererV2* dr = layer->diagramRenderer();
154180
if ( !dr ) //no diagram renderer yet, insert reasonable default
155181
{
156-
mDisplayDiagramsGroupBox->setChecked( false );
157-
mFixedSizeCheckBox->setChecked( true );
182+
mEnableDiagramsCheckBox->setChecked( false );
183+
mDiagramTypeFrame->setEnabled( false );
184+
mDiagramFrame->setEnabled( false );
185+
mFixedSizeRadio->setChecked( true );
158186
mDiagramUnitComboBox->setCurrentIndex( mDiagramUnitComboBox->findText( tr( "mm" ) ) );
159187
mLabelPlacementComboBox->setCurrentIndex( mLabelPlacementComboBox->findText( tr( "x-height" ) ) );
188+
mDiagramSizeSpinBox->setEnabled( true );
160189
mDiagramSizeSpinBox->setValue( 30 );
190+
mLinearScaleFrame->setEnabled( false );
191+
mIncreaseMinimumSizeSpinBox->setEnabled( false );
192+
mIncreaseMinimumSizeLabel->setEnabled( false );
161193
mBarWidthSpinBox->setValue( 5 );
162194
mVisibilityGroupBox->setChecked( layer->hasScaleBasedVisibility() );
163195
mShowAllCheckBox->setChecked( true );
@@ -181,17 +213,33 @@ QgsDiagramProperties::QgsDiagramProperties( QgsVectorLayer* layer, QWidget* pare
181213
break;
182214
}
183215
mBackgroundColorButton->setColor( QColor( 255, 255, 255, 255 ) );
216+
mDiagramTypeComboBox->blockSignals( true );
217+
mDiagramTypeComboBox->setCurrentIndex( 0 );
218+
mDiagramTypeComboBox->blockSignals( false );
219+
//force a refresh of widget status to match diagram type
220+
on_mDiagramTypeComboBox_currentIndexChanged( mDiagramTypeComboBox->currentIndex() );
184221
}
185222
else // already a diagram renderer present
186223
{
187224
//single category renderer or interpolated one?
188-
mFixedSizeCheckBox->setChecked( dr->rendererName() == "SingleCategory" );
225+
if ( dr->rendererName() == "SingleCategory" )
226+
{
227+
mFixedSizeRadio->setChecked( true );
228+
}
229+
else
230+
{
231+
mAttributeBasedScalingRadio->setChecked( true );
232+
}
233+
mDiagramSizeSpinBox->setEnabled( mFixedSizeRadio->isChecked() );
234+
mLinearScaleFrame->setEnabled( mAttributeBasedScalingRadio->isChecked() );
189235

190236
//assume single category or linearly interpolated diagram renderer for now
191237
QList<QgsDiagramSettings> settingList = dr->diagramSettings();
192238
if ( settingList.size() > 0 )
193239
{
194-
mDisplayDiagramsGroupBox->setChecked( settingList.at( 0 ).enabled );
240+
mEnableDiagramsCheckBox->setChecked( settingList.at( 0 ).enabled );
241+
mDiagramTypeFrame->setEnabled( mEnableDiagramsCheckBox->isChecked() );
242+
mDiagramFrame->setEnabled( mEnableDiagramsCheckBox->isChecked() );
195243
mDiagramFont = settingList.at( 0 ).font;
196244
QSizeF size = settingList.at( 0 ).size;
197245
mBackgroundColorButton->setColor( settingList.at( 0 ).backgroundColor );
@@ -248,7 +296,10 @@ QgsDiagramProperties::QgsDiagramProperties( QgsVectorLayer* layer, QWidget* pare
248296

249297
mBarWidthSpinBox->setValue( settingList.at( 0 ).barWidth );
250298

251-
mIncreaseSmallDiagramsGroupBox->setChecked( settingList.at( 0 ).minimumSize != 0 );
299+
mIncreaseSmallDiagramsCheck->setChecked( settingList.at( 0 ).minimumSize != 0 );
300+
mIncreaseMinimumSizeSpinBox->setEnabled( mIncreaseSmallDiagramsCheck->isChecked() );
301+
mIncreaseMinimumSizeLabel->setEnabled( mIncreaseSmallDiagramsCheck->isChecked() );
302+
252303
mIncreaseMinimumSizeSpinBox->setValue( settingList.at( 0 ).minimumSize );
253304

254305
if ( settingList.at( 0 ).scaleByArea )
@@ -282,6 +333,7 @@ QgsDiagramProperties::QgsDiagramProperties( QgsVectorLayer* layer, QWidget* pare
282333
if ( lidr )
283334
{
284335
mDiagramSizeSpinBox->setEnabled( false );
336+
mLinearScaleFrame->setEnabled( true );
285337
mValueLineEdit->setText( QString::number( lidr->upperValue(), 'f' ) );
286338
mSizeSpinBox->setValue(( lidr->upperSize().width() + lidr->upperSize().height() ) / 2 );
287339
if ( lidr->classificationAttributeIsExpression() )
@@ -315,7 +367,11 @@ QgsDiagramProperties::QgsDiagramProperties( QgsVectorLayer* layer, QWidget* pare
315367
if ( dr->diagram() )
316368
{
317369
QString diagramName = dr->diagram()->diagramName();
370+
mDiagramTypeComboBox->blockSignals( true );
318371
mDiagramTypeComboBox->setCurrentIndex( mDiagramTypeComboBox->findData( diagramName ) );
372+
mDiagramTypeComboBox->blockSignals( false );
373+
//force a refresh of widget status to match diagram type
374+
on_mDiagramTypeComboBox_currentIndexChanged( mDiagramTypeComboBox->currentIndex() );
319375
if ( mDiagramTypeComboBox->currentIndex() == -1 )
320376
{
321377
QMessageBox::warning( this, tr( "Unknown diagram type." ),
@@ -325,29 +381,31 @@ QgsDiagramProperties::QgsDiagramProperties( QgsVectorLayer* layer, QWidget* pare
325381
}
326382
} // if ( !dr )
327383

328-
// Trigger a clicked event, so all the items get properly enabled and disabled
329-
on_mDisplayDiagramsGroupBox_toggled( mDisplayDiagramsGroupBox->isChecked() );
330-
331384
connect( mSizeAttributeExpression, SIGNAL( clicked() ), this, SLOT( showSizeAttributeExpressionDialog() ) );
332385
connect( mAddAttributeExpression, SIGNAL( clicked() ), this, SLOT( showAddAttributeExpressionDialog() ) );
333386
}
334387

388+
QgsDiagramProperties::~QgsDiagramProperties()
389+
{
390+
QSettings settings;
391+
settings.setValue( QString( "/Windows/Diagrams/OptionsSplitState" ), mDiagramOptionsSplitter->saveState() );
392+
settings.setValue( QString( "/Windows/Diagrams/Tab" ), mDiagramOptionsListWidget->currentRow() );
393+
}
394+
335395
void QgsDiagramProperties::on_mDiagramTypeComboBox_currentIndexChanged( int index )
336396
{
337397
QString diagramType = mDiagramTypeComboBox->itemData( index ).toString();
338398

339399
if ( DIAGRAM_NAME_TEXT == diagramType )
340400
{
341-
mLabelPlacementComboBox->show();
342-
mLabelPlacementLabel->show();
401+
mTextOptionsFrame->show();
343402
mBackgroundColorLabel->show();
344403
mBackgroundColorButton->show();
345404
mDiagramFontButton->show();
346405
}
347406
else
348407
{
349-
mLabelPlacementComboBox->hide();
350-
mLabelPlacementLabel->hide();
408+
mTextOptionsFrame->hide();
351409
mBackgroundColorLabel->hide();
352410
mBackgroundColorButton->hide();
353411
mDiagramFontButton->hide();
@@ -357,30 +415,21 @@ void QgsDiagramProperties::on_mDiagramTypeComboBox_currentIndexChanged( int inde
357415
{
358416
mBarWidthLabel->show();
359417
mBarWidthSpinBox->show();
360-
mOrientationFrame->show();
361-
mFixedSizeCheckBox->setChecked( false );
362-
mFixedSizeCheckBox->setVisible( false );
363-
mDiagramSizeSpinBox->setVisible( false );
418+
mBarOptionsFrame->show();
419+
mAttributeBasedScalingRadio->setChecked( true );
420+
mFixedSizeRadio->setEnabled( false );
421+
mDiagramSizeSpinBox->setEnabled( false );
364422
mLinearlyScalingLabel->setText( tr( "Bar length: Scale linearly, such as the following value matches the specified size." ) );
365423
}
366424
else
367425
{
368426
mBarWidthLabel->hide();
369427
mBarWidthSpinBox->hide();
370-
mOrientationFrame->hide();
428+
mBarOptionsFrame->hide();
371429
mLinearlyScalingLabel->setText( tr( "Scale linearly between 0 and the following attribute value / diagram size:" ) );
372-
mAttributeBasedScalingOptions->show();
373-
mFixedSizeCheckBox->setVisible( true );
374-
mDiagramSizeSpinBox->setVisible( true );
375-
}
376-
377-
if ( DIAGRAM_NAME_HISTOGRAM == diagramType || DIAGRAM_NAME_TEXT == diagramType )
378-
{
379-
mDiagramPropertiesTabWidget->setTabEnabled( 3, true );
380-
}
381-
else
382-
{
383-
mDiagramPropertiesTabWidget->setTabEnabled( 3, false );
430+
mAttributeBasedScalingRadio->setEnabled( true );
431+
mFixedSizeRadio->setEnabled( true );
432+
mDiagramSizeSpinBox->setEnabled( mFixedSizeRadio->isChecked() );
384433
}
385434

386435
if ( DIAGRAM_NAME_TEXT == diagramType || DIAGRAM_NAME_PIE == diagramType )
@@ -481,16 +530,6 @@ void QgsDiagramProperties::on_mFindMaximumValueButton_clicked()
481530
mValueLineEdit->setText( QString( "%1" ).arg( maxValue ) );
482531
}
483532

484-
void QgsDiagramProperties::on_mDisplayDiagramsGroupBox_toggled( bool checked )
485-
{
486-
// if enabled show diagram specific options
487-
if ( checked )
488-
{
489-
on_mDiagramTypeComboBox_currentIndexChanged( mDiagramTypeComboBox->currentIndex() );
490-
// Update enabled/disabled state
491-
}
492-
}
493-
494533
void QgsDiagramProperties::on_mDiagramFontButton_clicked()
495534
{
496535
bool ok;
@@ -518,10 +557,7 @@ void QgsDiagramProperties::on_mEngineSettingsButton_clicked()
518557

519558
void QgsDiagramProperties::apply()
520559
{
521-
QSettings().setValue( "/Windows/VectorLayerProperties/diagram/tab",
522-
mDiagramPropertiesTabWidget->currentIndex() );
523-
524-
bool diagramsEnabled = mDisplayDiagramsGroupBox->isChecked();
560+
bool diagramsEnabled = mEnableDiagramsCheckBox->isChecked();
525561

526562
QgsDiagram* diagram = 0;
527563
int index = mDiagramTypeComboBox->currentIndex();
@@ -539,7 +575,7 @@ void QgsDiagramProperties::apply()
539575
// Check if a (usable) scale attribute value is inserted
540576
mValueLineEdit->text().toDouble( &scaleAttributeValueOk );
541577

542-
if ( !mFixedSizeCheckBox->isChecked() && !scaleAttributeValueOk )
578+
if ( !mFixedSizeRadio->isChecked() && !scaleAttributeValueOk )
543579
{
544580
double maxVal = DBL_MIN;
545581
QgsVectorDataProvider* provider = mLayer->dataProvider();
@@ -596,7 +632,7 @@ void QgsDiagramProperties::apply()
596632
}
597633

598634
QgsDiagramSettings ds;
599-
ds.enabled = mDisplayDiagramsGroupBox->isChecked();
635+
ds.enabled = mEnableDiagramsCheckBox->isChecked();
600636
ds.font = mDiagramFont;
601637
ds.transparency = mTransparencySlider->value();
602638

@@ -616,7 +652,7 @@ void QgsDiagramProperties::apply()
616652
ds.labelPlacementMethod = static_cast<QgsDiagramSettings::LabelPlacementMethod>( mLabelPlacementComboBox->itemData( mLabelPlacementComboBox->currentIndex() ).toInt() );
617653
ds.scaleByArea = mScaleDependencyComboBox->itemData( mScaleDependencyComboBox->currentIndex() ).toBool();
618654

619-
if ( mIncreaseSmallDiagramsGroupBox->isChecked() )
655+
if ( mIncreaseSmallDiagramsCheck->isChecked() )
620656
{
621657
ds.minimumSize = mIncreaseMinimumSizeSpinBox->value();
622658
}
@@ -647,7 +683,7 @@ void QgsDiagramProperties::apply()
647683

648684
ds.barWidth = mBarWidthSpinBox->value();
649685

650-
if ( mFixedSizeCheckBox->isChecked() )
686+
if ( mFixedSizeRadio->isChecked() )
651687
{
652688
QgsSingleCategoryDiagramRenderer* dr = new QgsSingleCategoryDiagramRenderer();
653689
dr->setDiagram( diagram );
@@ -768,3 +804,25 @@ void QgsDiagramProperties::showAddAttributeExpressionDialog()
768804
}
769805
activateWindow(); // set focus back parent
770806
}
807+
808+
void QgsDiagramProperties::on_mDiagramStackedWidget_currentChanged( int index )
809+
{
810+
mDiagramOptionsListWidget->blockSignals( true );
811+
mDiagramOptionsListWidget->setCurrentRow( index );
812+
mDiagramOptionsListWidget->blockSignals( false );
813+
}
814+
815+
void QgsDiagramProperties::on_mPlacementComboBox_currentIndexChanged( int index )
816+
{
817+
QgsDiagramLayerSettings::Placement currentPlacement = ( QgsDiagramLayerSettings::Placement )mPlacementComboBox->itemData( index ).toInt();
818+
if ( currentPlacement == QgsDiagramLayerSettings::OverPoint )
819+
{
820+
mDiagramDistanceLabel->setEnabled( false );
821+
mDiagramDistanceSpinBox->setEnabled( false );
822+
}
823+
else
824+
{
825+
mDiagramDistanceLabel->setEnabled( true );
826+
mDiagramDistanceSpinBox->setEnabled( true );
827+
}
828+
}

src/app/qgsdiagramproperties.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ class APP_EXPORT QgsDiagramProperties : public QWidget, private Ui::QgsDiagramPr
2929

3030
public:
3131
QgsDiagramProperties( QgsVectorLayer* layer, QWidget* parent );
32+
33+
~QgsDiagramProperties();
34+
3235
/**Adds an attribute from the list of available attributes to the assigned attributes with a random color.*/
3336
void addAttribute( QTreeWidgetItem * item );
3437

@@ -39,13 +42,14 @@ class APP_EXPORT QgsDiagramProperties : public QWidget, private Ui::QgsDiagramPr
3942
void on_mAddCategoryPushButton_clicked();
4043
void on_mAttributesTreeWidget_itemDoubleClicked( QTreeWidgetItem * item, int column );
4144
void on_mFindMaximumValueButton_clicked();
42-
void on_mDisplayDiagramsGroupBox_toggled( bool checked );
4345
void on_mRemoveCategoryPushButton_clicked();
4446
void on_mDiagramFontButton_clicked();
4547
void on_mDiagramAttributesTreeWidget_itemDoubleClicked( QTreeWidgetItem * item, int column );
4648
void on_mEngineSettingsButton_clicked();
4749
void showSizeAttributeExpressionDialog();
4850
void showAddAttributeExpressionDialog();
51+
void on_mDiagramStackedWidget_currentChanged( int index );
52+
void on_mPlacementComboBox_currentIndexChanged( int index );
4953

5054
protected:
5155
QFont mDiagramFont;
@@ -54,6 +58,7 @@ class APP_EXPORT QgsDiagramProperties : public QWidget, private Ui::QgsDiagramPr
5458

5559
private:
5660
int mAvailableAttributes;
61+
5762
};
5863

5964
#endif // QGSDIAGRAMPROPERTIES_H

src/app/qgsvectorlayerproperties.cpp

+6-4
Original file line numberDiff line numberDiff line change
@@ -239,11 +239,13 @@ QgsVectorLayerProperties::QgsVectorLayerProperties(
239239

240240
mOldJoins = layer->vectorJoins();
241241

242+
QVBoxLayout* diagLayout = new QVBoxLayout( mDiagramFrame );
243+
diagLayout->setMargin( 0 );
242244
diagramPropertiesDialog = new QgsDiagramProperties( layer, mDiagramFrame );
243-
diagramPropertiesDialog->layout()->setMargin( 0 );
244-
mDiagramFrame->setLayout( new QVBoxLayout( mDiagramFrame ) );
245-
mDiagramFrame->layout()->setMargin( 0 );
246-
mDiagramFrame->layout()->addWidget( diagramPropertiesDialog );
245+
diagramPropertiesDialog->layout()->setContentsMargins( -1, 0, -1, 0 );
246+
diagLayout->addWidget( diagramPropertiesDialog );
247+
mDiagramFrame->setLayout( diagLayout );
248+
247249

248250
//layer title and abstract
249251
mLayerTitleLineEdit->setText( layer->title() );

0 commit comments

Comments
 (0)