QGIS API Documentation 4.0.0-Norrköping (1ddcee3d0e4)
Loading...
Searching...
No Matches
qgsplotwidget.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsplotwidget.cpp
3 -----------------
4 begin : August 2025
5 copyright : (C) 2025 by Mathieu Pellerin
6 email : mathieu dot opengis dot ch
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
16#include "qgsplotwidget.h"
17
18#include "qgsapplication.h"
19#include "qgsbarchartplot.h"
20#include "qgscolorrampbutton.h"
22#include "qgsfillsymbol.h"
23#include "qgslinechartplot.h"
24#include "qgslinesymbol.h"
26#include "qgspiechartplot.h"
27#include "qgsplotregistry.h"
28
29#include <QString>
30
31#include "moc_qgsplotwidget.cpp"
32
33using namespace Qt::StringLiterals;
34
36{
37 mExpressionContextGenerator = generator;
38}
39
41{
43 if ( mExpressionContextGenerator )
44 {
45 context = mExpressionContextGenerator->createExpressionContext();
46 }
47 else
48 {
50 }
51
52 auto plotScope = std::make_unique<QgsExpressionContextScope>( u"plot"_s );
53 plotScope->addVariable( QgsExpressionContextScope::StaticVariable( u"plot_axis"_s, QString(), true ) );
54 plotScope->addVariable( QgsExpressionContextScope::StaticVariable( u"plot_axis_value"_s, 0.0, true ) );
55 context.appendScope( plotScope.release() );
56
57 auto chartScope = std::make_unique<QgsExpressionContextScope>( u"chart"_s );
58 chartScope->addVariable( QgsExpressionContextScope::StaticVariable( u"chart_series_name"_s, QString(), true ) );
59 chartScope->addVariable( QgsExpressionContextScope::StaticVariable( u"chart_category"_s, QString(), true ) );
60 chartScope->addVariable( QgsExpressionContextScope::StaticVariable( u"chart_value"_s, 0.0, true ) );
61 context.appendScope( chartScope.release() );
62
63 context.setHighlightedVariables( { u"plot_axis"_s, u"plot_axis_value"_s, u"chart_series_name"_s, u"chart_category"_s, u"chart_value"_s } );
64
65 return context;
66}
67
69{
70 button->blockSignals( true );
71 button->init( static_cast< int >( key ), mPropertyCollection, QgsPlot::propertyDefinitions(), nullptr );
72 connect( button, &QgsPropertyOverrideButton::changed, this, &QgsPlotWidget::updateProperty );
74 button->blockSignals( false );
75}
76
78{
79 if ( !button )
80 {
81 return;
82 }
83
84 if ( button->propertyKey() < 0 )
85 {
86 return;
87 }
88
89 const QgsPlot::DataDefinedProperty key = static_cast<QgsPlot::DataDefinedProperty>( button->propertyKey() );
90 whileBlocking( button )->setToProperty( mPropertyCollection.property( key ) );
91}
92
93void QgsPlotWidget::updateProperty()
94{
95 QgsPropertyOverrideButton *button = qobject_cast<QgsPropertyOverrideButton *>( sender() );
96 const QgsPlot::DataDefinedProperty key = static_cast<QgsPlot::DataDefinedProperty>( button->propertyKey() );
98 emit widgetChanged();
99}
100
102 : QgsPlotWidget( parent )
103{
104 setupUi( this );
105
106 setPanelTitle( tr( "Bar Chart Plot Properties" ) );
107
108 mSymbolsList->setColumnCount( 2 );
109 mSymbolsList->setSelectionBehavior( QAbstractItemView::SelectRows );
110 mSymbolsList->setSelectionMode( QAbstractItemView::ExtendedSelection );
111 mSymbolsList->setSortingEnabled( false );
112 mSymbolsList->horizontalHeader()->setSectionResizeMode( 0, QHeaderView::Stretch );
113 mSymbolsList->horizontalHeader()->setSectionResizeMode( 1, QHeaderView::Stretch );
114 mSymbolsList->horizontalHeader()->hide();
115 mSymbolsList->verticalHeader()->hide();
116
117 connect( mAddSymbolPushButton, &QPushButton::clicked, this, &QgsBarChartPlotWidget::mAddSymbolPushButton_clicked );
118 connect( mRemoveSymbolPushButton, &QPushButton::clicked, this, &QgsBarChartPlotWidget::mRemoveSymbolPushButton_clicked );
119
120 mSpinMinXAxis->setClearValue( 0 );
121 connect( mSpinMinXAxis, qOverload<double>( &QDoubleSpinBox::valueChanged ), this, [this]( double ) {
122 if ( mBlockChanges )
123 return;
124 emit widgetChanged();
125 } );
126
127 connect( mSpinMaxXAxis, qOverload<double>( &QDoubleSpinBox::valueChanged ), this, [this]( double ) {
128 if ( mBlockChanges )
129 return;
130 emit widgetChanged();
131 } );
132
133 mSpinMinYAxis->setClearValue( 0 );
134 connect( mSpinMinYAxis, qOverload<double>( &QDoubleSpinBox::valueChanged ), this, [this]( double ) {
135 if ( mBlockChanges )
136 return;
137 emit widgetChanged();
138 } );
139
140 mSpinMaxYAxis->setClearValue( 0 );
141 connect( mSpinMaxYAxis, qOverload<double>( &QDoubleSpinBox::valueChanged ), this, [this]( double ) {
142 if ( mBlockChanges )
143 return;
144 emit widgetChanged();
145 } );
146
147 mXAxisMajorLinesSymbolButton->setSymbolType( Qgis::SymbolType::Line );
148 connect( mXAxisMajorLinesSymbolButton, &QgsSymbolButton::changed, this, [this] {
149 if ( mBlockChanges )
150 return;
151 emit widgetChanged();
152 } );
153 mXAxisMajorLinesSymbolButton->setDefaultSymbol( QgsPlotDefaultSettings::axisGridMajorSymbol() );
154
155 mXAxisMinorLinesSymbolButton->setSymbolType( Qgis::SymbolType::Line );
156 connect( mXAxisMinorLinesSymbolButton, &QgsSymbolButton::changed, this, [this] {
157 if ( mBlockChanges )
158 return;
159 emit widgetChanged();
160 } );
161 mXAxisMinorLinesSymbolButton->setDefaultSymbol( QgsPlotDefaultSettings::axisGridMinorSymbol() );
162
163 connect( mXAxisMajorIntervalSpin, qOverload<double>( &QDoubleSpinBox::valueChanged ), this, [this]( double ) {
164 if ( mBlockChanges )
165 return;
166 emit widgetChanged();
167 } );
168
169 connect( mXAxisMinorIntervalSpin, qOverload<double>( &QDoubleSpinBox::valueChanged ), this, [this]( double ) {
170 if ( mBlockChanges )
171 return;
172 emit widgetChanged();
173 } );
174
175 connect( mXAxisLabelIntervalSpin, qOverload<double>( &QDoubleSpinBox::valueChanged ), this, [this]( double ) {
176 if ( mBlockChanges )
177 return;
178 emit widgetChanged();
179 } );
180
181 mYAxisMajorLinesSymbolButton->setSymbolType( Qgis::SymbolType::Line );
182 connect( mYAxisMajorLinesSymbolButton, &QgsSymbolButton::changed, this, [this] {
183 if ( mBlockChanges )
184 return;
185 emit widgetChanged();
186 } );
187 mYAxisMajorLinesSymbolButton->setDefaultSymbol( QgsPlotDefaultSettings::axisGridMajorSymbol() );
188
189 mYAxisMinorLinesSymbolButton->setSymbolType( Qgis::SymbolType::Line );
190 connect( mYAxisMinorLinesSymbolButton, &QgsSymbolButton::changed, this, [this] {
191 if ( mBlockChanges )
192 return;
193 emit widgetChanged();
194 } );
195 mYAxisMinorLinesSymbolButton->setDefaultSymbol( QgsPlotDefaultSettings::axisGridMinorSymbol() );
196
197 connect( mYAxisLabelIntervalSpin, qOverload<double>( &QDoubleSpinBox::valueChanged ), this, [this]( double ) {
198 if ( mBlockChanges )
199 return;
200 emit widgetChanged();
201 } );
202
203 connect( mYAxisMajorIntervalSpin, qOverload<double>( &QDoubleSpinBox::valueChanged ), this, [this]( double ) {
204 if ( mBlockChanges )
205 return;
206 emit widgetChanged();
207 } );
208
209 connect( mYAxisMinorIntervalSpin, qOverload<double>( &QDoubleSpinBox::valueChanged ), this, [this]( double ) {
210 if ( mBlockChanges )
211 return;
212 emit widgetChanged();
213 } );
214
215 mChartBackgroundSymbolButton->setSymbolType( Qgis::SymbolType::Fill );
216 connect( mChartBackgroundSymbolButton, &QgsSymbolButton::changed, this, [this] {
217 if ( mBlockChanges )
218 return;
219 emit widgetChanged();
220 } );
221 mChartBackgroundSymbolButton->setDefaultSymbol( QgsPlotDefaultSettings::chartBackgroundSymbol() );
222
223 mChartBorderSymbolButton->setSymbolType( Qgis::SymbolType::Fill );
224 connect( mChartBorderSymbolButton, &QgsSymbolButton::changed, this, [this] {
225 if ( mBlockChanges )
226 return;
227 emit widgetChanged();
228 } );
229 mChartBorderSymbolButton->setDefaultSymbol( QgsPlotDefaultSettings::chartBorderSymbol() );
230
231 connect( mXAxisLabelFormatButton, &QPushButton::clicked, this, [this] {
233 widget->setPanelTitle( tr( "X Axis Number Format" ) );
234 widget->setFormat( mXAxisNumericFormat.get() );
235 connect( widget, &QgsNumericFormatSelectorWidget::changed, this, [this, widget] {
236 mXAxisNumericFormat.reset( widget->format() );
237 emit widgetChanged();
238 } );
239 openPanel( widget );
240 } );
241
242 connect( mYAxisLabelFormatButton, &QPushButton::clicked, this, [this] {
244 widget->setPanelTitle( tr( "Y Axis Number Format" ) );
245 widget->setFormat( mYAxisNumericFormat.get() );
246 connect( widget, &QgsNumericFormatSelectorWidget::changed, this, [this, widget] {
247 mYAxisNumericFormat.reset( widget->format() );
248 emit widgetChanged();
249 } );
250 openPanel( widget );
251 } );
252
253 mXAxisLabelFontButton->setDialogTitle( tr( "X Axis Label Font" ) );
254 mYAxisLabelFontButton->setDialogTitle( tr( "Y Axis Label Font" ) );
255 mXAxisLabelFontButton->setMode( QgsFontButton::ModeTextRenderer );
256 mYAxisLabelFontButton->setMode( QgsFontButton::ModeTextRenderer );
257
258 connect( mXAxisLabelFontButton, &QgsFontButton::changed, this, [this] {
259 if ( mBlockChanges )
260 return;
261 emit widgetChanged();
262 } );
263
264 connect( mYAxisLabelFontButton, &QgsFontButton::changed, this, [this] {
265 if ( mBlockChanges )
266 return;
267 emit widgetChanged();
268 } );
269
270 mSpinLeftMargin->setClearValue( 0 );
271 connect( mSpinLeftMargin, qOverload<double>( &QDoubleSpinBox::valueChanged ), this, [this]( double ) {
272 if ( mBlockChanges )
273 return;
274 emit widgetChanged();
275 } );
276
277 mSpinRightMargin->setClearValue( 0 );
278 connect( mSpinRightMargin, qOverload<double>( &QDoubleSpinBox::valueChanged ), this, [this]( double ) {
279 if ( mBlockChanges )
280 return;
281 emit widgetChanged();
282 } );
283
284 mSpinTopMargin->setClearValue( 0 );
285 connect( mSpinTopMargin, qOverload<double>( &QDoubleSpinBox::valueChanged ), this, [this]( double ) {
286 if ( mBlockChanges )
287 return;
288 emit widgetChanged();
289 } );
290
291 mSpinBottomMargin->setClearValue( 0 );
292 connect( mSpinBottomMargin, qOverload<double>( &QDoubleSpinBox::valueChanged ), this, [this]( double ) {
293 if ( mBlockChanges )
294 return;
295 emit widgetChanged();
296 } );
297
298 mXAxisTypeCombo->addItem( tr( "Interval" ), QVariant::fromValue( Qgis::PlotAxisType::Interval ) );
299 mXAxisTypeCombo->addItem( tr( "Categorical" ), QVariant::fromValue( Qgis::PlotAxisType::Categorical ) );
300 connect( mXAxisTypeCombo, qOverload<int>( &QComboBox::currentIndexChanged ), this, &QgsBarChartPlotWidget::updateXAxisProperties );
301 connect( mXAxisTypeCombo, qOverload<int>( &QComboBox::currentIndexChanged ), this, [this]( int ) {
302 if ( mBlockChanges )
303 return;
304 emit widgetChanged();
305 } );
306
307 mXAxisLabelsCombo->addItem( tr( "None" ), QVariant::fromValue( Qgis::PlotAxisSuffixPlacement::NoLabels ) );
308 mXAxisLabelsCombo->addItem( tr( "Every Value" ), QVariant::fromValue( Qgis::PlotAxisSuffixPlacement::EveryLabel ) );
309 mXAxisLabelsCombo->addItem( tr( "First Value" ), QVariant::fromValue( Qgis::PlotAxisSuffixPlacement::FirstLabel ) );
310 mXAxisLabelsCombo->addItem( tr( "Last Value" ), QVariant::fromValue( Qgis::PlotAxisSuffixPlacement::LastLabel ) );
311 mXAxisLabelsCombo->addItem( tr( "First and Last Values" ), QVariant::fromValue( Qgis::PlotAxisSuffixPlacement::FirstAndLastLabels ) );
312 connect( mXAxisLabelsCombo, qOverload<int>( &QComboBox::currentIndexChanged ), this, [this]( int ) {
313 if ( mBlockChanges )
314 return;
315 emit widgetChanged();
316 } );
317
318 mXAxisMajorLinesSymbolButton->registerExpressionContextGenerator( this );
319 mXAxisMinorLinesSymbolButton->registerExpressionContextGenerator( this );
320 mXAxisLabelFontButton->registerExpressionContextGenerator( this );
321 mYAxisMajorLinesSymbolButton->registerExpressionContextGenerator( this );
322 mYAxisMinorLinesSymbolButton->registerExpressionContextGenerator( this );
323 mYAxisLabelFontButton->registerExpressionContextGenerator( this );
324 mChartBackgroundSymbolButton->registerExpressionContextGenerator( this );
325 mChartBorderSymbolButton->registerExpressionContextGenerator( this );
326
331
338
343}
344
345void QgsBarChartPlotWidget::mAddSymbolPushButton_clicked()
346{
347 const int row = mSymbolsList->rowCount();
348 mSymbolsList->insertRow( row );
349
350 QTableWidgetItem *item = new QTableWidgetItem();
351 item->setData( Qt::DisplayRole, tr( "Symbol" ) );
352 mSymbolsList->setItem( row, 0, item );
353
354 QgsSymbolButton *symbolButton = new QgsSymbolButton( this );
355 symbolButton->setSymbolType( Qgis::SymbolType::Fill );
356 symbolButton->setShowNull( true );
358 symbolButton->registerExpressionContextGenerator( this );
359 connect( symbolButton, &QgsSymbolButton::changed, this, [this] {
360 if ( mBlockChanges )
361 return;
362 emit widgetChanged();
363 } );
364 mSymbolsList->setCellWidget( row, 1, symbolButton );
365
366 emit widgetChanged();
367}
368
369void QgsBarChartPlotWidget::mRemoveSymbolPushButton_clicked()
370{
371 QTableWidgetItem *item = mSymbolsList->currentItem();
372 if ( !item )
373 {
374 return;
375 }
376
377 mSymbolsList->removeRow( mSymbolsList->row( item ) );
378
379 emit widgetChanged();
380}
381
382void QgsBarChartPlotWidget::updateXAxisProperties()
383{
384 const bool enable = mXAxisTypeCombo->currentData().value<Qgis::PlotAxisType>() == Qgis::PlotAxisType::Interval;
385
386 mLabelMinXAxis->setEnabled( enable );
387 mSpinMinXAxis->setEnabled( enable );
388 mDDBtnMinXAxis->setEnabled( enable );
389 mLabelMaxXAxis->setEnabled( enable );
390 mSpinMaxXAxis->setEnabled( enable );
391 mDDBtnMaxXAxis->setEnabled( enable );
392
393 mXAxisMajorIntervalLabel->setEnabled( enable );
394 mXAxisMajorIntervalSpin->setEnabled( enable );
395 mDDBtnXAxisMajorInterval->setEnabled( enable );
396 mXAxisMajorLinesLabel->setEnabled( enable );
397 mXAxisMajorLinesSymbolButton->setEnabled( enable );
398 mXAxisMinorIntervalLabel->setEnabled( enable );
399 mXAxisMinorIntervalSpin->setEnabled( enable );
400 mDDBtnXAxisMinorInterval->setEnabled( enable );
401 mXAxisMinorLinesLabel->setEnabled( enable );
402 mXAxisMinorLinesSymbolButton->setEnabled( enable );
403}
404
406{
407 QgsBarChartPlot *chartPlot = dynamic_cast<QgsBarChartPlot *>( plot );
408 if ( !chartPlot )
409 {
410 return;
411 }
412
413 mBlockChanges++;
414
415 mSymbolsList->clear();
416 const int symbolCount = chartPlot->fillSymbolCount();
417 for ( int i = 0; i < symbolCount; i++ )
418 {
419 const int row = mSymbolsList->rowCount();
420 mSymbolsList->insertRow( row );
421
422 QTableWidgetItem *item = new QTableWidgetItem();
423 item->setData( Qt::DisplayRole, tr( "Symbol" ) );
424 mSymbolsList->setItem( row, 0, item );
425
426 QgsSymbolButton *symbolButton = new QgsSymbolButton( this );
427 symbolButton->setSymbolType( Qgis::SymbolType::Fill );
428 symbolButton->setShowNull( true );
429 symbolButton->setSymbol( chartPlot->fillSymbolAt( i )->clone() );
430 symbolButton->registerExpressionContextGenerator( this );
431 connect( symbolButton, &QgsSymbolButton::changed, this, [this] {
432 if ( mBlockChanges )
433 return;
434 emit widgetChanged();
435 } );
436 mSymbolsList->setCellWidget( row, 1, symbolButton );
437 }
438
439 mSpinMinXAxis->setValue( chartPlot->xMinimum() );
440 mSpinMaxXAxis->setValue( chartPlot->xMaximum() );
441 mSpinMinYAxis->setValue( chartPlot->yMinimum() );
442 mSpinMaxYAxis->setValue( chartPlot->yMaximum() );
443
444 if ( chartPlot->xAxis().gridMajorSymbol() )
445 mXAxisMajorLinesSymbolButton->setSymbol( chartPlot->xAxis().gridMajorSymbol()->clone() );
446 if ( chartPlot->xAxis().gridMinorSymbol() )
447 mXAxisMinorLinesSymbolButton->setSymbol( chartPlot->xAxis().gridMinorSymbol()->clone() );
448 if ( chartPlot->yAxis().gridMajorSymbol() )
449 mYAxisMajorLinesSymbolButton->setSymbol( chartPlot->yAxis().gridMajorSymbol()->clone() );
450 if ( chartPlot->yAxis().gridMinorSymbol() )
451 mYAxisMinorLinesSymbolButton->setSymbol( chartPlot->yAxis().gridMinorSymbol()->clone() );
452
453 mXAxisLabelFontButton->setTextFormat( chartPlot->xAxis().textFormat() );
454 mXAxisNumericFormat.reset( chartPlot->xAxis().numericFormat()->clone() );
455 mYAxisLabelFontButton->setTextFormat( chartPlot->yAxis().textFormat() );
456 mYAxisNumericFormat.reset( chartPlot->yAxis().numericFormat()->clone() );
457
458 mXAxisTypeCombo->setCurrentIndex( mXAxisTypeCombo->findData( QVariant::fromValue( chartPlot->xAxis().type() ) ) );
459 mXAxisLabelsCombo->setCurrentIndex( mXAxisLabelsCombo->findData( QVariant::fromValue( chartPlot->xAxis().labelSuffixPlacement() ) ) );
460
461 mXAxisMajorIntervalSpin->setValue( chartPlot->xAxis().gridIntervalMajor() );
462 mXAxisMinorIntervalSpin->setValue( chartPlot->xAxis().gridIntervalMinor() );
463 mXAxisLabelIntervalSpin->setValue( chartPlot->xAxis().labelInterval() );
464
465 mYAxisMajorIntervalSpin->setValue( chartPlot->yAxis().gridIntervalMajor() );
466 mYAxisMinorIntervalSpin->setValue( chartPlot->yAxis().gridIntervalMinor() );
467 mYAxisLabelIntervalSpin->setValue( chartPlot->yAxis().labelInterval() );
468
469 if ( chartPlot->chartBackgroundSymbol() )
470 mChartBackgroundSymbolButton->setSymbol( chartPlot->chartBackgroundSymbol()->clone() );
471 if ( chartPlot->chartBorderSymbol() )
472 mChartBorderSymbolButton->setSymbol( chartPlot->chartBorderSymbol()->clone() );
473
474 mSpinLeftMargin->setValue( chartPlot->margins().left() );
475 mSpinRightMargin->setValue( chartPlot->margins().right() );
476 mSpinTopMargin->setValue( chartPlot->margins().top() );
477 mSpinBottomMargin->setValue( chartPlot->margins().bottom() );
478
479 mFlipAxes = chartPlot->flipAxes();
480
482
483 updateDataDefinedButton( mDDBtnMinXAxis );
484 updateDataDefinedButton( mDDBtnMaxXAxis );
485 updateDataDefinedButton( mDDBtnMinYAxis );
486 updateDataDefinedButton( mDDBtnMaxYAxis );
487
488 updateDataDefinedButton( mDDBtnXAxisMajorInterval );
489 updateDataDefinedButton( mDDBtnXAxisMinorInterval );
490 updateDataDefinedButton( mDDBtnXAxisLabelInterval );
491 updateDataDefinedButton( mDDBtnYAxisMajorInterval );
492 updateDataDefinedButton( mDDBtnYAxisMinorInterval );
493 updateDataDefinedButton( mDDBtnYAxisLabelInterval );
494
495 updateDataDefinedButton( mDDBtnLeftMargin );
496 updateDataDefinedButton( mDDBtnRightMargin );
497 updateDataDefinedButton( mDDBtnTopMargin );
498 updateDataDefinedButton( mDDBtnBottomMargin );
499
500 mBlockChanges--;
501}
502
504{
505 QgsPlot *plot = QgsApplication::plotRegistry()->createPlot( u"bar"_s );
506 QgsBarChartPlot *chartPlot = dynamic_cast<QgsBarChartPlot *>( plot );
507 if ( !chartPlot )
508 {
509 return nullptr;
510 }
511
512 const int rowCount = mSymbolsList->rowCount();
513 for ( int i = 0; i < rowCount; i++ )
514 {
515 QgsSymbolButton *symbolButton = dynamic_cast<QgsSymbolButton *>( mSymbolsList->cellWidget( i, 1 ) );
516 if ( symbolButton )
517 {
518 chartPlot->setFillSymbolAt( i, symbolButton->clonedSymbol<QgsFillSymbol>() );
519 }
520 }
521
522 chartPlot->setXMinimum( mSpinMinXAxis->value() );
523 chartPlot->setXMaximum( mSpinMaxXAxis->value() );
524 chartPlot->setYMinimum( mSpinMinYAxis->value() );
525 chartPlot->setYMaximum( mSpinMaxYAxis->value() );
526
527 chartPlot->xAxis().setGridMajorSymbol( mXAxisMajorLinesSymbolButton->clonedSymbol<QgsLineSymbol>() );
528 chartPlot->xAxis().setGridMinorSymbol( mXAxisMinorLinesSymbolButton->clonedSymbol<QgsLineSymbol>() );
529 chartPlot->yAxis().setGridMajorSymbol( mYAxisMajorLinesSymbolButton->clonedSymbol<QgsLineSymbol>() );
530 chartPlot->yAxis().setGridMinorSymbol( mYAxisMinorLinesSymbolButton->clonedSymbol<QgsLineSymbol>() );
531
532 chartPlot->xAxis().setTextFormat( mXAxisLabelFontButton->textFormat() );
533 chartPlot->xAxis().setNumericFormat( mXAxisNumericFormat.get()->clone() );
534 chartPlot->yAxis().setTextFormat( mYAxisLabelFontButton->textFormat() );
535 chartPlot->yAxis().setNumericFormat( mYAxisNumericFormat.get()->clone() );
536
537 chartPlot->xAxis().setType( mXAxisTypeCombo->currentData().value<Qgis::PlotAxisType>() );
538 chartPlot->xAxis().setLabelSuffixPlacement( mXAxisLabelsCombo->currentData().value<Qgis::PlotAxisSuffixPlacement>() );
539
540 chartPlot->xAxis().setGridIntervalMajor( mXAxisMajorIntervalSpin->value() );
541 chartPlot->xAxis().setGridIntervalMinor( mXAxisMinorIntervalSpin->value() );
542 chartPlot->xAxis().setLabelInterval( mXAxisLabelIntervalSpin->value() );
543
544 chartPlot->yAxis().setGridIntervalMajor( mYAxisMajorIntervalSpin->value() );
545 chartPlot->yAxis().setGridIntervalMinor( mYAxisMinorIntervalSpin->value() );
546 chartPlot->yAxis().setLabelInterval( mYAxisLabelIntervalSpin->value() );
547
548 chartPlot->setChartBackgroundSymbol( mChartBackgroundSymbolButton->clonedSymbol<QgsFillSymbol>() );
549 chartPlot->setChartBorderSymbol( mChartBorderSymbolButton->clonedSymbol<QgsFillSymbol>() );
550
551 QgsMargins margins;
552 margins.setLeft( mSpinLeftMargin->value() );
553 margins.setRight( mSpinRightMargin->value() );
554 margins.setTop( mSpinTopMargin->value() );
555 margins.setBottom( mSpinBottomMargin->value() );
556 chartPlot->setMargins( margins );
557
558 chartPlot->setFlipAxes( mFlipAxes );
560
561 return plot;
562}
563
564
566 : QgsPlotWidget( parent )
567{
568 setupUi( this );
569
570 setPanelTitle( tr( "Line Chart Plot Properties" ) );
571
572 mSymbolsList->setColumnCount( 3 );
573 mSymbolsList->setSelectionBehavior( QAbstractItemView::SelectRows );
574 mSymbolsList->setSelectionMode( QAbstractItemView::ExtendedSelection );
575 mSymbolsList->setSortingEnabled( false );
576 mSymbolsList->horizontalHeader()->setSectionResizeMode( 0, QHeaderView::Stretch );
577 mSymbolsList->horizontalHeader()->setSectionResizeMode( 1, QHeaderView::Stretch );
578 mSymbolsList->horizontalHeader()->setSectionResizeMode( 2, QHeaderView::Stretch );
579 mSymbolsList->horizontalHeader()->hide();
580 mSymbolsList->verticalHeader()->hide();
581
582 connect( mAddSymbolPushButton, &QPushButton::clicked, this, &QgsLineChartPlotWidget::mAddSymbolPushButton_clicked );
583 connect( mRemoveSymbolPushButton, &QPushButton::clicked, this, &QgsLineChartPlotWidget::mRemoveSymbolPushButton_clicked );
584
585 mSpinMinXAxis->setClearValue( 0 );
586 connect( mSpinMinXAxis, qOverload<double>( &QDoubleSpinBox::valueChanged ), this, [this]( double ) {
587 if ( mBlockChanges )
588 return;
589 emit widgetChanged();
590 } );
591
592 connect( mSpinMaxXAxis, qOverload<double>( &QDoubleSpinBox::valueChanged ), this, [this]( double ) {
593 if ( mBlockChanges )
594 return;
595 emit widgetChanged();
596 } );
597
598 mSpinMinYAxis->setClearValue( 0 );
599 connect( mSpinMinYAxis, qOverload<double>( &QDoubleSpinBox::valueChanged ), this, [this]( double ) {
600 if ( mBlockChanges )
601 return;
602 emit widgetChanged();
603 } );
604
605 mSpinMaxYAxis->setClearValue( 0 );
606 connect( mSpinMaxYAxis, qOverload<double>( &QDoubleSpinBox::valueChanged ), this, [this]( double ) {
607 if ( mBlockChanges )
608 return;
609 emit widgetChanged();
610 } );
611
612 mXAxisMajorLinesSymbolButton->setSymbolType( Qgis::SymbolType::Line );
613 connect( mXAxisMajorLinesSymbolButton, &QgsSymbolButton::changed, this, [this] {
614 if ( mBlockChanges )
615 return;
616 emit widgetChanged();
617 } );
618 mXAxisMajorLinesSymbolButton->setDefaultSymbol( QgsPlotDefaultSettings::axisGridMajorSymbol() );
619
620 mXAxisMinorLinesSymbolButton->setSymbolType( Qgis::SymbolType::Line );
621 connect( mXAxisMinorLinesSymbolButton, &QgsSymbolButton::changed, this, [this] {
622 if ( mBlockChanges )
623 return;
624 emit widgetChanged();
625 } );
626 mXAxisMinorLinesSymbolButton->setDefaultSymbol( QgsPlotDefaultSettings::axisGridMinorSymbol() );
627
628 connect( mXAxisMajorIntervalSpin, qOverload<double>( &QDoubleSpinBox::valueChanged ), this, [this]( double ) {
629 if ( mBlockChanges )
630 return;
631 emit widgetChanged();
632 } );
633
634 connect( mXAxisMinorIntervalSpin, qOverload<double>( &QDoubleSpinBox::valueChanged ), this, [this]( double ) {
635 if ( mBlockChanges )
636 return;
637 emit widgetChanged();
638 } );
639
640 connect( mXAxisLabelIntervalSpin, qOverload<double>( &QDoubleSpinBox::valueChanged ), this, [this]( double ) {
641 if ( mBlockChanges )
642 return;
643 emit widgetChanged();
644 } );
645
646 mYAxisMajorLinesSymbolButton->setSymbolType( Qgis::SymbolType::Line );
647 connect( mYAxisMajorLinesSymbolButton, &QgsSymbolButton::changed, this, [this] {
648 if ( mBlockChanges )
649 return;
650 emit widgetChanged();
651 } );
652 mYAxisMajorLinesSymbolButton->setDefaultSymbol( QgsPlotDefaultSettings::axisGridMajorSymbol() );
653
654 mYAxisMinorLinesSymbolButton->setSymbolType( Qgis::SymbolType::Line );
655 connect( mYAxisMinorLinesSymbolButton, &QgsSymbolButton::changed, this, [this] {
656 if ( mBlockChanges )
657 return;
658 emit widgetChanged();
659 } );
660 mYAxisMinorLinesSymbolButton->setDefaultSymbol( QgsPlotDefaultSettings::axisGridMinorSymbol() );
661
662 connect( mYAxisLabelIntervalSpin, qOverload<double>( &QDoubleSpinBox::valueChanged ), this, [this]( double ) {
663 if ( mBlockChanges )
664 return;
665 emit widgetChanged();
666 } );
667
668 connect( mYAxisMajorIntervalSpin, qOverload<double>( &QDoubleSpinBox::valueChanged ), this, [this]( double ) {
669 if ( mBlockChanges )
670 return;
671 emit widgetChanged();
672 } );
673
674 connect( mYAxisMinorIntervalSpin, qOverload<double>( &QDoubleSpinBox::valueChanged ), this, [this]( double ) {
675 if ( mBlockChanges )
676 return;
677 emit widgetChanged();
678 } );
679
680 mChartBackgroundSymbolButton->setSymbolType( Qgis::SymbolType::Fill );
681 connect( mChartBackgroundSymbolButton, &QgsSymbolButton::changed, this, [this] {
682 if ( mBlockChanges )
683 return;
684 emit widgetChanged();
685 } );
686 mChartBackgroundSymbolButton->setDefaultSymbol( QgsPlotDefaultSettings::chartBackgroundSymbol() );
687
688 mChartBorderSymbolButton->setSymbolType( Qgis::SymbolType::Fill );
689 connect( mChartBorderSymbolButton, &QgsSymbolButton::changed, this, [this] {
690 if ( mBlockChanges )
691 return;
692 emit widgetChanged();
693 } );
694 mChartBorderSymbolButton->setDefaultSymbol( QgsPlotDefaultSettings::chartBorderSymbol() );
695
696 connect( mXAxisLabelFormatButton, &QPushButton::clicked, this, [this] {
698 widget->setPanelTitle( tr( "X Axis Number Format" ) );
699 widget->setFormat( mXAxisNumericFormat.get() );
700 connect( widget, &QgsNumericFormatSelectorWidget::changed, this, [this, widget] {
701 mXAxisNumericFormat.reset( widget->format() );
702 emit widgetChanged();
703 } );
704 openPanel( widget );
705 } );
706
707 connect( mYAxisLabelFormatButton, &QPushButton::clicked, this, [this] {
709 widget->setPanelTitle( tr( "Y Axis Number Format" ) );
710 widget->setFormat( mYAxisNumericFormat.get() );
711 connect( widget, &QgsNumericFormatSelectorWidget::changed, this, [this, widget] {
712 mYAxisNumericFormat.reset( widget->format() );
713 emit widgetChanged();
714 } );
715 openPanel( widget );
716 } );
717
718 mXAxisLabelFontButton->setDialogTitle( tr( "X Axis Label Font" ) );
719 mYAxisLabelFontButton->setDialogTitle( tr( "Y Axis Label Font" ) );
720 mXAxisLabelFontButton->setMode( QgsFontButton::ModeTextRenderer );
721 mYAxisLabelFontButton->setMode( QgsFontButton::ModeTextRenderer );
722
723 connect( mXAxisLabelFontButton, &QgsFontButton::changed, this, [this] {
724 if ( mBlockChanges )
725 return;
726 emit widgetChanged();
727 } );
728
729 connect( mYAxisLabelFontButton, &QgsFontButton::changed, this, [this] {
730 if ( mBlockChanges )
731 return;
732 emit widgetChanged();
733 } );
734
735 mSpinLeftMargin->setClearValue( 0 );
736 connect( mSpinLeftMargin, qOverload<double>( &QDoubleSpinBox::valueChanged ), this, [this]( double ) {
737 if ( mBlockChanges )
738 return;
739 emit widgetChanged();
740 } );
741
742 mSpinRightMargin->setClearValue( 0 );
743 connect( mSpinRightMargin, qOverload<double>( &QDoubleSpinBox::valueChanged ), this, [this]( double ) {
744 if ( mBlockChanges )
745 return;
746 emit widgetChanged();
747 } );
748
749 mSpinTopMargin->setClearValue( 0 );
750 connect( mSpinTopMargin, qOverload<double>( &QDoubleSpinBox::valueChanged ), this, [this]( double ) {
751 if ( mBlockChanges )
752 return;
753 emit widgetChanged();
754 } );
755
756 mSpinBottomMargin->setClearValue( 0 );
757 connect( mSpinBottomMargin, qOverload<double>( &QDoubleSpinBox::valueChanged ), this, [this]( double ) {
758 if ( mBlockChanges )
759 return;
760 emit widgetChanged();
761 } );
762
763 mXAxisTypeCombo->addItem( tr( "Interval" ), QVariant::fromValue( Qgis::PlotAxisType::Interval ) );
764 mXAxisTypeCombo->addItem( tr( "Categorical" ), QVariant::fromValue( Qgis::PlotAxisType::Categorical ) );
765 connect( mXAxisTypeCombo, qOverload<int>( &QComboBox::currentIndexChanged ), this, &QgsLineChartPlotWidget::updateXAxisProperties );
766 connect( mXAxisTypeCombo, qOverload<int>( &QComboBox::currentIndexChanged ), this, [this]( int ) {
767 if ( mBlockChanges )
768 return;
769 emit widgetChanged();
770 } );
771
772 mXAxisLabelsCombo->addItem( tr( "None" ), QVariant::fromValue( Qgis::PlotAxisSuffixPlacement::NoLabels ) );
773 mXAxisLabelsCombo->addItem( tr( "Every Value" ), QVariant::fromValue( Qgis::PlotAxisSuffixPlacement::EveryLabel ) );
774 mXAxisLabelsCombo->addItem( tr( "First Value" ), QVariant::fromValue( Qgis::PlotAxisSuffixPlacement::FirstLabel ) );
775 mXAxisLabelsCombo->addItem( tr( "Last Value" ), QVariant::fromValue( Qgis::PlotAxisSuffixPlacement::LastLabel ) );
776 mXAxisLabelsCombo->addItem( tr( "First and Last Values" ), QVariant::fromValue( Qgis::PlotAxisSuffixPlacement::FirstAndLastLabels ) );
777 connect( mXAxisLabelsCombo, qOverload<int>( &QComboBox::currentIndexChanged ), this, [this]( int ) {
778 if ( mBlockChanges )
779 return;
780 emit widgetChanged();
781 } );
782
783 mXAxisMajorLinesSymbolButton->registerExpressionContextGenerator( this );
784 mXAxisMinorLinesSymbolButton->registerExpressionContextGenerator( this );
785 mXAxisLabelFontButton->registerExpressionContextGenerator( this );
786 mYAxisMajorLinesSymbolButton->registerExpressionContextGenerator( this );
787 mYAxisMinorLinesSymbolButton->registerExpressionContextGenerator( this );
788 mYAxisLabelFontButton->registerExpressionContextGenerator( this );
789 mChartBackgroundSymbolButton->registerExpressionContextGenerator( this );
790 mChartBorderSymbolButton->registerExpressionContextGenerator( this );
791
796
803
808}
809
810void QgsLineChartPlotWidget::mAddSymbolPushButton_clicked()
811{
812 const int row = mSymbolsList->rowCount();
813 mSymbolsList->insertRow( row );
814
815 QTableWidgetItem *item = new QTableWidgetItem();
816 item->setData( Qt::DisplayRole, tr( "Symbol" ) );
817 mSymbolsList->setItem( row, 0, item );
818
819 // Line
820 QgsSymbolButton *symbolButton = new QgsSymbolButton( this );
821 symbolButton->setSymbolType( Qgis::SymbolType::Line );
822 symbolButton->setShowNull( true );
824 symbolButton->registerExpressionContextGenerator( this );
825 connect( symbolButton, &QgsSymbolButton::changed, this, [this] {
826 if ( mBlockChanges )
827 return;
828 emit widgetChanged();
829 } );
830 mSymbolsList->setCellWidget( row, 1, symbolButton );
831
832 // Marker
833 symbolButton = new QgsSymbolButton( this );
834 symbolButton->setFixedSizeConstraints( false );
836 symbolButton->setShowNull( true );
838 symbolButton->registerExpressionContextGenerator( this );
839 connect( symbolButton, &QgsSymbolButton::changed, this, [this] {
840 if ( mBlockChanges )
841 return;
842 emit widgetChanged();
843 } );
844 mSymbolsList->setCellWidget( row, 2, symbolButton );
845
846 emit widgetChanged();
847}
848
849void QgsLineChartPlotWidget::mRemoveSymbolPushButton_clicked()
850{
851 QTableWidgetItem *item = mSymbolsList->currentItem();
852 if ( !item )
853 {
854 return;
855 }
856
857 mSymbolsList->removeRow( mSymbolsList->row( item ) );
858
859 emit widgetChanged();
860}
861
862void QgsLineChartPlotWidget::updateXAxisProperties()
863{
864 const bool enable = mXAxisTypeCombo->currentData().value<Qgis::PlotAxisType>() == Qgis::PlotAxisType::Interval;
865
866 mLabelMinXAxis->setEnabled( enable );
867 mSpinMinXAxis->setEnabled( enable );
868 mDDBtnMinXAxis->setEnabled( enable );
869 mLabelMaxXAxis->setEnabled( enable );
870 mSpinMaxXAxis->setEnabled( enable );
871 mDDBtnMaxXAxis->setEnabled( enable );
872
873 mXAxisMajorIntervalLabel->setEnabled( enable );
874 mXAxisMajorIntervalSpin->setEnabled( enable );
875 mDDBtnXAxisMajorInterval->setEnabled( enable );
876 mXAxisMajorLinesLabel->setEnabled( enable );
877 mXAxisMajorLinesSymbolButton->setEnabled( enable );
878 mXAxisMinorIntervalLabel->setEnabled( enable );
879 mXAxisMinorIntervalSpin->setEnabled( enable );
880 mDDBtnXAxisMinorInterval->setEnabled( enable );
881 mXAxisMinorLinesLabel->setEnabled( enable );
882 mXAxisMinorLinesSymbolButton->setEnabled( enable );
883}
884
886{
887 QgsLineChartPlot *chartPlot = dynamic_cast<QgsLineChartPlot *>( plot );
888 if ( !chartPlot )
889 {
890 return;
891 }
892
893 mBlockChanges++;
894
895 mSymbolsList->clear();
896 const int symbolCount = std::max( chartPlot->markerSymbolCount(), chartPlot->lineSymbolCount() );
897 for ( int i = 0; i < symbolCount; i++ )
898 {
899 const int row = mSymbolsList->rowCount();
900 mSymbolsList->insertRow( row );
901
902 QTableWidgetItem *item = new QTableWidgetItem();
903 item->setData( Qt::DisplayRole, tr( "Symbol" ) );
904 mSymbolsList->setItem( row, 0, item );
905
906 // Line
907 QgsSymbolButton *symbolButton = new QgsSymbolButton( this );
908 symbolButton->setSymbolType( Qgis::SymbolType::Line );
909 symbolButton->setShowNull( true );
910 symbolButton->setSymbol( i < chartPlot->lineSymbolCount() ? chartPlot->lineSymbolAt( i )->clone() : nullptr );
911 symbolButton->registerExpressionContextGenerator( this );
912 connect( symbolButton, &QgsSymbolButton::changed, this, [this] {
913 if ( mBlockChanges )
914 return;
915 emit widgetChanged();
916 } );
917 mSymbolsList->setCellWidget( row, 1, symbolButton );
918
919 // Marker
920 symbolButton = new QgsSymbolButton( this );
921 symbolButton->setFixedSizeConstraints( false );
923 symbolButton->setShowNull( true );
924 symbolButton->setSymbol( i < chartPlot->markerSymbolCount() ? chartPlot->markerSymbolAt( i )->clone() : nullptr );
925 symbolButton->registerExpressionContextGenerator( this );
926 connect( symbolButton, &QgsSymbolButton::changed, this, [this] {
927 if ( mBlockChanges )
928 return;
929 emit widgetChanged();
930 } );
931 mSymbolsList->setCellWidget( row, 2, symbolButton );
932 }
933
934 mSpinMinXAxis->setValue( chartPlot->xMinimum() );
935 mSpinMaxXAxis->setValue( chartPlot->xMaximum() );
936 mSpinMinYAxis->setValue( chartPlot->yMinimum() );
937 mSpinMaxYAxis->setValue( chartPlot->yMaximum() );
938
939 if ( chartPlot->xAxis().gridMajorSymbol() )
940 mXAxisMajorLinesSymbolButton->setSymbol( chartPlot->xAxis().gridMajorSymbol()->clone() );
941 if ( chartPlot->xAxis().gridMinorSymbol() )
942 mXAxisMinorLinesSymbolButton->setSymbol( chartPlot->xAxis().gridMinorSymbol()->clone() );
943 if ( chartPlot->yAxis().gridMajorSymbol() )
944 mYAxisMajorLinesSymbolButton->setSymbol( chartPlot->yAxis().gridMajorSymbol()->clone() );
945 if ( chartPlot->yAxis().gridMinorSymbol() )
946 mYAxisMinorLinesSymbolButton->setSymbol( chartPlot->yAxis().gridMinorSymbol()->clone() );
947
948 mXAxisLabelFontButton->setTextFormat( chartPlot->xAxis().textFormat() );
949 mYAxisLabelFontButton->setTextFormat( chartPlot->yAxis().textFormat() );
950
951 mXAxisTypeCombo->setCurrentIndex( mXAxisTypeCombo->findData( QVariant::fromValue( chartPlot->xAxis().type() ) ) );
952 mXAxisLabelsCombo->setCurrentIndex( mXAxisLabelsCombo->findData( QVariant::fromValue( chartPlot->xAxis().labelSuffixPlacement() ) ) );
953
954 mXAxisMajorIntervalSpin->setValue( chartPlot->xAxis().gridIntervalMajor() );
955 mXAxisMinorIntervalSpin->setValue( chartPlot->xAxis().gridIntervalMinor() );
956 mXAxisLabelIntervalSpin->setValue( chartPlot->xAxis().labelInterval() );
957
958 mYAxisMajorIntervalSpin->setValue( chartPlot->yAxis().gridIntervalMajor() );
959 mYAxisMinorIntervalSpin->setValue( chartPlot->yAxis().gridIntervalMinor() );
960 mYAxisLabelIntervalSpin->setValue( chartPlot->yAxis().labelInterval() );
961
962 if ( chartPlot->chartBackgroundSymbol() )
963 mChartBackgroundSymbolButton->setSymbol( chartPlot->chartBackgroundSymbol()->clone() );
964 if ( chartPlot->chartBorderSymbol() )
965 mChartBorderSymbolButton->setSymbol( chartPlot->chartBorderSymbol()->clone() );
966
967 mSpinLeftMargin->setValue( chartPlot->margins().left() );
968 mSpinRightMargin->setValue( chartPlot->margins().right() );
969 mSpinTopMargin->setValue( chartPlot->margins().top() );
970 mSpinBottomMargin->setValue( chartPlot->margins().bottom() );
971
972 mFlipAxes = chartPlot->flipAxes();
973
975
976 updateDataDefinedButton( mDDBtnMinXAxis );
977 updateDataDefinedButton( mDDBtnMaxXAxis );
978 updateDataDefinedButton( mDDBtnMinYAxis );
979 updateDataDefinedButton( mDDBtnMaxYAxis );
980
981 updateDataDefinedButton( mDDBtnXAxisMajorInterval );
982 updateDataDefinedButton( mDDBtnXAxisMinorInterval );
983 updateDataDefinedButton( mDDBtnXAxisLabelInterval );
984 updateDataDefinedButton( mDDBtnYAxisMajorInterval );
985 updateDataDefinedButton( mDDBtnYAxisMinorInterval );
986 updateDataDefinedButton( mDDBtnYAxisLabelInterval );
987
988 updateDataDefinedButton( mDDBtnLeftMargin );
989 updateDataDefinedButton( mDDBtnRightMargin );
990 updateDataDefinedButton( mDDBtnTopMargin );
991 updateDataDefinedButton( mDDBtnBottomMargin );
992
993 mBlockChanges--;
994}
995
997{
998 QgsPlot *plot = QgsApplication::plotRegistry()->createPlot( u"line"_s );
999 QgsLineChartPlot *chartPlot = dynamic_cast<QgsLineChartPlot *>( plot );
1000 if ( !chartPlot )
1001 {
1002 return nullptr;
1003 }
1004
1005 const int rowCount = mSymbolsList->rowCount();
1006 for ( int i = 0; i < rowCount; i++ )
1007 {
1008 QgsSymbolButton *symbolButton = dynamic_cast<QgsSymbolButton *>( mSymbolsList->cellWidget( i, 1 ) );
1009 if ( symbolButton )
1010 {
1011 chartPlot->setLineSymbolAt( i, symbolButton->clonedSymbol<QgsLineSymbol>() );
1012 }
1013
1014 symbolButton = dynamic_cast<QgsSymbolButton *>( mSymbolsList->cellWidget( i, 2 ) );
1015 if ( symbolButton )
1016 {
1017 chartPlot->setMarkerSymbolAt( i, symbolButton->clonedSymbol<QgsMarkerSymbol>() );
1018 }
1019 }
1020
1021 chartPlot->setXMinimum( mSpinMinXAxis->value() );
1022 chartPlot->setXMaximum( mSpinMaxXAxis->value() );
1023 chartPlot->setYMinimum( mSpinMinYAxis->value() );
1024 chartPlot->setYMaximum( mSpinMaxYAxis->value() );
1025
1026 chartPlot->xAxis().setGridMajorSymbol( mXAxisMajorLinesSymbolButton->clonedSymbol<QgsLineSymbol>() );
1027 chartPlot->xAxis().setGridMinorSymbol( mXAxisMinorLinesSymbolButton->clonedSymbol<QgsLineSymbol>() );
1028 chartPlot->yAxis().setGridMajorSymbol( mYAxisMajorLinesSymbolButton->clonedSymbol<QgsLineSymbol>() );
1029 chartPlot->yAxis().setGridMinorSymbol( mYAxisMinorLinesSymbolButton->clonedSymbol<QgsLineSymbol>() );
1030
1031 chartPlot->xAxis().setTextFormat( mXAxisLabelFontButton->textFormat() );
1032 chartPlot->yAxis().setTextFormat( mYAxisLabelFontButton->textFormat() );
1033
1034 chartPlot->xAxis().setType( mXAxisTypeCombo->currentData().value<Qgis::PlotAxisType>() );
1035 chartPlot->xAxis().setLabelSuffixPlacement( mXAxisLabelsCombo->currentData().value<Qgis::PlotAxisSuffixPlacement>() );
1036
1037 chartPlot->xAxis().setGridIntervalMajor( mXAxisMajorIntervalSpin->value() );
1038 chartPlot->xAxis().setGridIntervalMinor( mXAxisMinorIntervalSpin->value() );
1039 chartPlot->xAxis().setLabelInterval( mXAxisLabelIntervalSpin->value() );
1040
1041 chartPlot->yAxis().setGridIntervalMajor( mYAxisMajorIntervalSpin->value() );
1042 chartPlot->yAxis().setGridIntervalMinor( mYAxisMinorIntervalSpin->value() );
1043 chartPlot->yAxis().setLabelInterval( mYAxisLabelIntervalSpin->value() );
1044
1045 chartPlot->setChartBackgroundSymbol( mChartBackgroundSymbolButton->clonedSymbol<QgsFillSymbol>() );
1046 chartPlot->setChartBorderSymbol( mChartBorderSymbolButton->clonedSymbol<QgsFillSymbol>() );
1047
1048 QgsMargins margins;
1049 margins.setLeft( mSpinLeftMargin->value() );
1050 margins.setRight( mSpinRightMargin->value() );
1051 margins.setTop( mSpinTopMargin->value() );
1052 margins.setBottom( mSpinBottomMargin->value() );
1053 chartPlot->setMargins( margins );
1054
1055 chartPlot->setFlipAxes( mFlipAxes );
1057
1058 return plot;
1059}
1060
1061
1063 : QgsPlotWidget( parent )
1064{
1065 setupUi( this );
1066
1067 setPanelTitle( tr( "Pie Chart Plot Properties" ) );
1068
1069 mSymbolsList->setColumnCount( 3 );
1070 mSymbolsList->setSelectionBehavior( QAbstractItemView::SelectRows );
1071 mSymbolsList->setSelectionMode( QAbstractItemView::ExtendedSelection );
1072 mSymbolsList->setSortingEnabled( false );
1073 mSymbolsList->horizontalHeader()->setSectionResizeMode( 0, QHeaderView::Stretch );
1074 mSymbolsList->horizontalHeader()->setSectionResizeMode( 1, QHeaderView::Stretch );
1075 mSymbolsList->horizontalHeader()->setSectionResizeMode( 2, QHeaderView::Stretch );
1076 mSymbolsList->horizontalHeader()->hide();
1077 mSymbolsList->verticalHeader()->hide();
1078
1079 mLabelCombo->addItem( tr( "None" ), QVariant::fromValue( Qgis::PieChartLabelType::NoLabels ) );
1080 mLabelCombo->addItem( tr( "Category Labels" ), QVariant::fromValue( Qgis::PieChartLabelType::Categories ) );
1081 mLabelCombo->addItem( tr( "Value Labels" ), QVariant::fromValue( Qgis::PieChartLabelType::Values ) );
1082 connect( mLabelCombo, qOverload<int>( &QComboBox::currentIndexChanged ), this, [this]( int ) {
1083 if ( mBlockChanges )
1084 return;
1085 emit widgetChanged();
1086 } );
1087
1088 mLabelFontButton->setDialogTitle( tr( "Chart Label Font" ) );
1089 mLabelFontButton->setMode( QgsFontButton::ModeTextRenderer );
1090 connect( mLabelFontButton, &QgsFontButton::changed, this, [this] {
1091 if ( mBlockChanges )
1092 return;
1093 emit widgetChanged();
1094 } );
1095
1096 connect( mLabelFormatButton, &QPushButton::clicked, this, [this] {
1098 widget->setPanelTitle( tr( "Chart Number Format" ) );
1099 widget->setFormat( mNumericFormat.get() );
1100 connect( widget, &QgsNumericFormatSelectorWidget::changed, this, [this, widget] {
1101 mNumericFormat.reset( widget->format() );
1102 emit widgetChanged();
1103 } );
1104 openPanel( widget );
1105 } );
1106
1107 mSpinLeftMargin->setClearValue( 0 );
1108 connect( mSpinLeftMargin, qOverload<double>( &QDoubleSpinBox::valueChanged ), this, [this]( double ) {
1109 if ( mBlockChanges )
1110 return;
1111 emit widgetChanged();
1112 } );
1113
1114 mSpinRightMargin->setClearValue( 0 );
1115 connect( mSpinRightMargin, qOverload<double>( &QDoubleSpinBox::valueChanged ), this, [this]( double ) {
1116 if ( mBlockChanges )
1117 return;
1118 emit widgetChanged();
1119 } );
1120
1121 mSpinTopMargin->setClearValue( 0 );
1122 connect( mSpinTopMargin, qOverload<double>( &QDoubleSpinBox::valueChanged ), this, [this]( double ) {
1123 if ( mBlockChanges )
1124 return;
1125 emit widgetChanged();
1126 } );
1127
1128 mSpinBottomMargin->setClearValue( 0 );
1129 connect( mSpinBottomMargin, qOverload<double>( &QDoubleSpinBox::valueChanged ), this, [this]( double ) {
1130 if ( mBlockChanges )
1131 return;
1132 emit widgetChanged();
1133 } );
1134
1135 connect( mAddSymbolPushButton, &QPushButton::clicked, this, &QgsPieChartPlotWidget::mAddSymbolPushButton_clicked );
1136 connect( mRemoveSymbolPushButton, &QPushButton::clicked, this, &QgsPieChartPlotWidget::mRemoveSymbolPushButton_clicked );
1137
1138 mLabelFontButton->registerExpressionContextGenerator( this );
1139
1144}
1145
1146void QgsPieChartPlotWidget::mAddSymbolPushButton_clicked()
1147{
1148 const int row = mSymbolsList->rowCount();
1149 mSymbolsList->insertRow( row );
1150
1151 QTableWidgetItem *item = new QTableWidgetItem();
1152 item->setData( Qt::DisplayRole, tr( "Symbol" ) );
1153 mSymbolsList->setItem( row, 0, item );
1154
1155 // Fill
1156 QgsSymbolButton *symbolButton = new QgsSymbolButton( this );
1157 symbolButton->setSymbolType( Qgis::SymbolType::Fill );
1158 symbolButton->setShowNull( true );
1160 symbolButton->registerExpressionContextGenerator( this );
1161 connect( symbolButton, &QgsSymbolButton::changed, this, [this] {
1162 if ( mBlockChanges )
1163 return;
1164 emit widgetChanged();
1165 } );
1166 mSymbolsList->setCellWidget( row, 1, symbolButton );
1167
1168 // Color ramp
1169 QgsColorRampButton *colorRampButton = new QgsColorRampButton( this );
1170 colorRampButton->setShowNull( true );
1172 connect( colorRampButton, &QgsColorRampButton::colorRampChanged, this, [this] {
1173 if ( mBlockChanges )
1174 return;
1175 emit widgetChanged();
1176 } );
1177 mSymbolsList->setCellWidget( row, 2, colorRampButton );
1178
1179 emit widgetChanged();
1180}
1181
1182void QgsPieChartPlotWidget::mRemoveSymbolPushButton_clicked()
1183{
1184 QTableWidgetItem *item = mSymbolsList->currentItem();
1185 if ( !item )
1186 {
1187 return;
1188 }
1189
1190 mSymbolsList->removeRow( mSymbolsList->row( item ) );
1191
1192 emit widgetChanged();
1193}
1194
1196{
1197 QgsPieChartPlot *chartPlot = dynamic_cast<QgsPieChartPlot *>( plot );
1198 if ( !chartPlot )
1199 {
1200 return;
1201 }
1202
1203 mBlockChanges++;
1204
1205 mSymbolsList->clear();
1206 const int symbolCount = std::max( chartPlot->fillSymbolCount(), chartPlot->colorRampCount() );
1207 for ( int i = 0; i < symbolCount; i++ )
1208 {
1209 const int row = mSymbolsList->rowCount();
1210 mSymbolsList->insertRow( row );
1211
1212 QTableWidgetItem *item = new QTableWidgetItem();
1213 item->setData( Qt::DisplayRole, tr( "Symbol" ) );
1214 mSymbolsList->setItem( row, 0, item );
1215
1216 // Fill
1217 QgsSymbolButton *symbolButton = new QgsSymbolButton( this );
1218 symbolButton->setSymbolType( Qgis::SymbolType::Fill );
1219 symbolButton->setShowNull( true );
1220 symbolButton->setSymbol( i < chartPlot->fillSymbolCount() ? chartPlot->fillSymbolAt( i )->clone() : nullptr );
1221 symbolButton->registerExpressionContextGenerator( this );
1222 connect( symbolButton, &QgsSymbolButton::changed, this, [this] {
1223 if ( mBlockChanges )
1224 return;
1225 emit widgetChanged();
1226 } );
1227 mSymbolsList->setCellWidget( row, 1, symbolButton );
1228
1229 // Color ramp
1230 QgsColorRampButton *colorRampButton = new QgsColorRampButton( this );
1231 colorRampButton->setShowNull( true );
1232 colorRampButton->setColorRamp( i < chartPlot->colorRampCount() ? chartPlot->colorRampAt( i )->clone() : nullptr );
1233 connect( colorRampButton, &QgsColorRampButton::colorRampChanged, this, [this] {
1234 if ( mBlockChanges )
1235 return;
1236 emit widgetChanged();
1237 } );
1238 mSymbolsList->setCellWidget( row, 2, colorRampButton );
1239 }
1240
1241 mNumericFormat.reset( chartPlot->numericFormat()->clone() );
1242 mLabelFontButton->setTextFormat( chartPlot->textFormat() );
1243
1244 mLabelCombo->setCurrentIndex( mLabelCombo->findData( QVariant::fromValue( chartPlot->labelType() ) ) );
1245
1247
1248 updateDataDefinedButton( mDDBtnLeftMargin );
1249 updateDataDefinedButton( mDDBtnRightMargin );
1250 updateDataDefinedButton( mDDBtnTopMargin );
1251 updateDataDefinedButton( mDDBtnBottomMargin );
1252
1253 mBlockChanges--;
1254}
1255
1257{
1258 QgsPlot *plot = QgsApplication::plotRegistry()->createPlot( u"pie"_s );
1259 QgsPieChartPlot *chartPlot = dynamic_cast<QgsPieChartPlot *>( plot );
1260 if ( !chartPlot )
1261 {
1262 return nullptr;
1263 }
1264
1265 const int rowCount = mSymbolsList->rowCount();
1266 for ( int i = 0; i < rowCount; i++ )
1267 {
1268 QgsSymbolButton *symbolButton = dynamic_cast<QgsSymbolButton *>( mSymbolsList->cellWidget( i, 1 ) );
1269 if ( symbolButton )
1270 {
1271 chartPlot->setFillSymbolAt( i, symbolButton->clonedSymbol<QgsFillSymbol>() );
1272 }
1273
1274 QgsColorRampButton *colorRampButton = dynamic_cast<QgsColorRampButton *>( mSymbolsList->cellWidget( i, 2 ) );
1275 if ( colorRampButton )
1276 {
1277 chartPlot->setColorRampAt( i, colorRampButton->colorRamp()->clone() );
1278 }
1279 }
1280
1281 chartPlot->setNumericFormat( mNumericFormat.get()->clone() );
1282 chartPlot->setTextFormat( mLabelFontButton->textFormat() );
1283 chartPlot->setLabelType( mLabelCombo->currentData().value<Qgis::PieChartLabelType>() );
1284
1285 QgsMargins margins;
1286 margins.setLeft( mSpinLeftMargin->value() );
1287 margins.setRight( mSpinRightMargin->value() );
1288 margins.setTop( mSpinTopMargin->value() );
1289 margins.setBottom( mSpinBottomMargin->value() );
1290 chartPlot->setMargins( margins );
1291
1293
1294 return plot;
1295}
PieChartLabelType
Pie chart label types.
Definition qgis.h:3460
@ Categories
Category labels are drawn.
Definition qgis.h:3462
@ Values
Value labels are drawn.
Definition qgis.h:3463
@ NoLabels
Labels are not drawn.
Definition qgis.h:3461
PlotAxisSuffixPlacement
Placement options for suffixes in the labels for axis of plots.
Definition qgis.h:3432
@ FirstAndLastLabels
Place suffix after the first and last label values only.
Definition qgis.h:3437
@ EveryLabel
Place suffix after every value label.
Definition qgis.h:3434
@ FirstLabel
Place suffix after the first label value only.
Definition qgis.h:3435
@ LastLabel
Place suffix after the last label value only.
Definition qgis.h:3436
@ NoLabels
Do not place suffixes.
Definition qgis.h:3433
PlotAxisType
Plots axis types.
Definition qgis.h:3448
@ Categorical
The axis represents categories.
Definition qgis.h:3450
@ Interval
The axis represents a range of values.
Definition qgis.h:3449
@ Marker
Marker symbol.
Definition qgis.h:637
@ Line
Line symbol.
Definition qgis.h:638
@ Fill
Fill symbol.
Definition qgis.h:639
const QgsMargins & margins() const
Returns the margins of the plot area (in millimeters).
Definition qgsplot.cpp:338
void setMargins(const QgsMargins &margins)
Sets the margins of the plot area (in millimeters).
Definition qgsplot.cpp:343
void setXMaximum(double maximum)
Sets the maximum value of the x axis.
Definition qgsplot.h:762
double yMaximum() const
Returns the maximum value of the y axis.
Definition qgsplot.h:769
void setYMinimum(double minimum)
Sets the minimum value of the y axis.
Definition qgsplot.h:748
double xMinimum() const
Returns the minimum value of the x axis.
Definition qgsplot.h:727
void setChartBackgroundSymbol(QgsFillSymbol *symbol)
Sets the fill symbol used to render the background of the chart.
Definition qgsplot.cpp:1204
void setFlipAxes(bool flipAxes)
Sets whether the X and Y axes are flipped.
Definition qgsplot.cpp:1224
QgsPlotAxis & yAxis()
Returns a reference to the plot's y axis.
Definition qgsplot.h:797
void setChartBorderSymbol(QgsFillSymbol *symbol)
Sets the symbol used to render the border of the chart.
Definition qgsplot.cpp:1219
bool flipAxes() const
Returns whether the X and Y axes are flipped.
Definition qgsplot.h:856
QgsFillSymbol * chartBackgroundSymbol()
Returns the fill symbol used to render the background of the chart.
Definition qgsplot.cpp:1194
void setXMinimum(double minimum)
Sets the minimum value of the x axis.
Definition qgsplot.h:734
QgsPlotAxis & xAxis()
Returns a reference to the plot's x axis.
Definition qgsplot.h:783
QgsFillSymbol * chartBorderSymbol()
Returns the symbol used to render the border of the chart.
Definition qgsplot.cpp:1209
double yMinimum() const
Returns the minimum value of the y axis.
Definition qgsplot.h:741
void setYMaximum(double maximum)
Sets the maximum value of the y axis.
Definition qgsplot.h:776
double xMaximum() const
Returns the maximum value of the x axis.
Definition qgsplot.h:755
static QgsPlotRegistry * plotRegistry()
Returns the application's plot registry, used for plot types.
void setPlot(QgsPlot *plot) override
Sets the widget to match the settings of the plot.
QgsBarChartPlotWidget(QWidget *parent=nullptr)
Constructor for QgsBarChartPlotWidget.
QgsPlot * createPlot() override
Creates a plot defined by the current settings in the widget.
A simple bar chart class.
void setFillSymbolAt(int index, QgsFillSymbol *symbol)
Sets the fill symbol to use for the series with matching index.
int fillSymbolCount() const
Returns the fill symbols list count.
QgsFillSymbol * fillSymbolAt(int index) const
Returns the fill symbol for the series with matching index.
A cross platform button subclass for selecting color ramps.
void setColorRamp(QgsColorRamp *colorramp)
Sets the current color ramp for the button.
QgsColorRamp * colorRamp() const
Returns a copy of the current color ramp.
void setShowNull(bool showNull)
Sets whether a set to null (clear) option is shown in the button's drop-down menu.
void colorRampChanged()
Emitted whenever a new color ramp is set for the button.
virtual QgsColorRamp * clone() const =0
Creates a clone of the color ramp.
Abstract interface for generating an expression context.
static QgsExpressionContextScope * globalScope()
Creates a new scope which contains variables and functions relating to the global QGIS context.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
void appendScope(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
void setHighlightedVariables(const QStringList &variableNames)
Sets the list of variable names within the context intended to be highlighted to the user.
A fill symbol type, for rendering Polygon and MultiPolygon geometries.
QgsFillSymbol * clone() const override
Returns a deep copy of this symbol.
@ ModeTextRenderer
Configure font settings for use with QgsTextRenderer.
void changed()
Emitted when the widget's text format settings are changed.
QgsLineChartPlotWidget(QWidget *parent=nullptr)
Constructor for QgsLineChartPlotWidget.
void setPlot(QgsPlot *plot) override
Sets the widget to match the settings of the plot.
QgsPlot * createPlot() override
Creates a plot defined by the current settings in the widget.
A simple line chart class.
QgsMarkerSymbol * markerSymbolAt(int index) const
Returns the marker symbol for the series with matching index.
QgsLineSymbol * lineSymbolAt(int index) const
Returns the line symbol for the series with matching index.
void setLineSymbolAt(int index, QgsLineSymbol *symbol)
Sets the line symbol to use for the series with matching index.
int lineSymbolCount() const
Returns the line symbols list count.
void setMarkerSymbolAt(int index, QgsMarkerSymbol *symbol)
Sets the fill symbol to use for the series with matching index.
int markerSymbolCount() const
Returns the line symbols list count.
A line symbol type, for rendering LineString and MultiLineString geometries.
QgsLineSymbol * clone() const override
Returns a deep copy of this symbol.
Defines the four margins of a rectangle.
Definition qgsmargins.h:40
void setBottom(double bottom)
Sets the bottom margin to bottom.
Definition qgsmargins.h:112
double top() const
Returns the top margin.
Definition qgsmargins.h:76
void setLeft(double left)
Sets the left margin to left.
Definition qgsmargins.h:94
double right() const
Returns the right margin.
Definition qgsmargins.h:82
double bottom() const
Returns the bottom margin.
Definition qgsmargins.h:88
void setRight(double right)
Sets the right margin to right.
Definition qgsmargins.h:106
void setTop(double top)
Sets the top margin to top.
Definition qgsmargins.h:100
double left() const
Returns the left margin.
Definition qgsmargins.h:70
A marker symbol type, for rendering Point and MultiPoint geometries.
QgsMarkerSymbol * clone() const override
Returns a deep copy of this symbol.
A widget which allows choice of numeric formats and the properties of them.
QgsNumericFormat * format() const
Returns a new format object representing the settings currently configured in the widget.
void changed()
Emitted whenever the format configured55 in the widget is changed.
void setFormat(const QgsNumericFormat *format)
Sets the format to show in the widget.
virtual QgsNumericFormat * clone() const =0
Clones the format, returning a new object.
void openPanel(QgsPanelWidget *panel)
Open a panel or dialog depending on dock mode setting If dock mode is true this method will emit the ...
void widgetChanged()
Emitted when the widget state changes.
void setPanelTitle(const QString &panelTitle)
Set the title of the panel when shown in the interface.
QgsPlot * createPlot() override
Creates a plot defined by the current settings in the widget.
void setPlot(QgsPlot *plot) override
Sets the widget to match the settings of the plot.
QgsPieChartPlotWidget(QWidget *parent=nullptr)
Constructor for QgsLineChartPlotWidget.
A simple pie chart class.
void setTextFormat(const QgsTextFormat &format)
Sets the text format used for the pie chart labels.
QgsTextFormat textFormat() const
Returns the text format used for the pie chart labels.
QgsFillSymbol * fillSymbolAt(int index) const
Returns the fill symbol for the series with matching index.
void setNumericFormat(QgsNumericFormat *format)
Sets the numeric format used for the pie chart labels.
QgsColorRamp * colorRampAt(int index) const
Returns the color ramp for the series with matching index.
QgsNumericFormat * numericFormat() const
Returns the numeric format used for the pie chart labels.
void setLabelType(Qgis::PieChartLabelType type)
Sets the pie chart label type.
Qgis::PieChartLabelType labelType() const
Returns the pie chart label type.
int fillSymbolCount() const
Returns the fill symbols list count.
void setColorRampAt(int index, QgsColorRamp *ramp)
Sets the color ramp for the series with matching index.
void setFillSymbolAt(int index, QgsFillSymbol *symbol)
Sets the fill symbol to use for the series with matching index.
int colorRampCount() const
Returns the color ramps list count.
QgsLineSymbol * gridMinorSymbol()
Returns the line symbol used to render the minor lines in the axis grid.
Definition qgsplot.cpp:230
void setGridMajorSymbol(QgsLineSymbol *symbol)
Sets the symbol used to render the major lines in the axis grid.
Definition qgsplot.cpp:225
double gridIntervalMinor() const
Returns the interval of minor grid lines for the axis.
Definition qgsplot.h:389
double gridIntervalMajor() const
Returns the interval of major grid lines for the axis.
Definition qgsplot.h:403
void setType(Qgis::PlotAxisType type)
Sets the axis type.
Definition qgsplot.cpp:129
void setNumericFormat(QgsNumericFormat *format)
Sets the numeric format used for the axis labels.
Definition qgsplot.cpp:190
QgsTextFormat textFormat() const
Returns the text format used for the axis labels.
Definition qgsplot.cpp:245
void setGridIntervalMajor(double interval)
Sets the interval of major grid lines for the axis.
Definition qgsplot.h:410
void setLabelSuffixPlacement(Qgis::PlotAxisSuffixPlacement placement)
Sets the placement for the axis label suffixes.
Definition qgsplot.cpp:210
void setGridIntervalMinor(double interval)
Sets the interval of minor grid lines for the axis.
Definition qgsplot.h:396
void setLabelInterval(double interval)
Sets the interval of labels for the axis.
Definition qgsplot.h:424
Qgis::PlotAxisType type() const
Returns the axis type.
Definition qgsplot.cpp:124
double labelInterval() const
Returns the interval of labels for the axis.
Definition qgsplot.h:417
QgsLineSymbol * gridMajorSymbol()
Returns the line symbol used to render the major lines in the axis grid.
Definition qgsplot.cpp:215
void setTextFormat(const QgsTextFormat &format)
Sets the text format used for the axis labels.
Definition qgsplot.cpp:250
void setGridMinorSymbol(QgsLineSymbol *symbol)
Sets the symbol used to render the minor lines in the axis grid.
Definition qgsplot.cpp:240
QgsNumericFormat * numericFormat() const
Returns the numeric format used for the axis labels.
Definition qgsplot.cpp:185
Qgis::PlotAxisSuffixPlacement labelSuffixPlacement() const
Returns the placement for the axis label suffixes.
Definition qgsplot.cpp:205
static QgsFillSymbol * chartBorderSymbol()
Returns the default fill symbol to use for the chart area border.
Definition qgsplot.cpp:1407
static QgsColorRamp * pieChartColorRamp()
Returns the default color ramp to use for pie charts.
Definition qgsplot.cpp:1437
static QgsFillSymbol * barChartFillSymbol()
Returns the default fill symbol to use for bar charts.
Definition qgsplot.cpp:1425
static QgsLineSymbol * lineChartLineSymbol()
Returns the default line symbol to use for line charts.
Definition qgsplot.cpp:1419
static QgsLineSymbol * axisGridMinorSymbol()
Returns the default line symbol to use for axis minor grid lines.
Definition qgsplot.cpp:1394
static QgsFillSymbol * pieChartFillSymbol()
Returns the default fill symbol to use for pie charts.
Definition qgsplot.cpp:1431
static QgsMarkerSymbol * lineChartMarkerSymbol()
Returns the default marker symbol to use for line charts.
Definition qgsplot.cpp:1413
static QgsFillSymbol * chartBackgroundSymbol()
Returns the default fill symbol to use for the chart area background fill.
Definition qgsplot.cpp:1401
static QgsLineSymbol * axisGridMajorSymbol()
Returns the default line symbol to use for axis major grid lines.
Definition qgsplot.cpp:1387
QgsPlot * createPlot(const QString &type) const
Creates a new instance of a plot given the type.
void registerExpressionContextGenerator(QgsExpressionContextGenerator *generator)
Register an expression context generator class that will be used to retrieve an expression context fo...
QgsPropertyCollection mPropertyCollection
QgsExpressionContext createExpressionContext() const override
This method needs to be reimplemented in all classes which implement this interface and return an exp...
void updateDataDefinedButton(QgsPropertyOverrideButton *button)
Initiate a data-defined property button tied to a plot widget.
QgsPlotWidget(QWidget *parent=nullptr)
Constructor for QgsPlotWidget.
void initializeDataDefinedButton(QgsPropertyOverrideButton *button, QgsPlot::DataDefinedProperty key)
Initiate a data-defined property button tied to a plot widget.
Base class for plot/chart/graphs.
Definition qgsplot.h:48
void setDataDefinedProperties(const QgsPropertyCollection &collection)
Sets the plot's property collection, used for data defined overrides.
Definition qgsplot.h:151
static const QgsPropertiesDefinition & propertyDefinitions()
Returns the plot property definitions.
Definition qgsplot.cpp:95
QgsPropertyCollection & dataDefinedProperties()
Returns a reference to the plot's property collection, used for data defined overrides.
Definition qgsplot.h:136
DataDefinedProperty
Data defined properties for different plot types.
Definition qgsplot.h:96
@ YAxisMinorInterval
Minor grid line interval for Y axis.
Definition qgsplot.h:105
@ YAxisLabelInterval
Label interval for Y axis.
Definition qgsplot.h:106
@ XAxisMajorInterval
Major grid line interval for X axis.
Definition qgsplot.h:101
@ XAxisMaximum
Maximum X axis value.
Definition qgsplot.h:108
@ XAxisMinimum
Minimum X axis value.
Definition qgsplot.h:107
@ XAxisLabelInterval
Label interval for X axis.
Definition qgsplot.h:103
@ MarginBottom
Bottom margin.
Definition qgsplot.h:100
@ XAxisMinorInterval
Minor grid line interval for X axis.
Definition qgsplot.h:102
@ YAxisMajorInterval
Major grid line interval for Y axis.
Definition qgsplot.h:104
@ YAxisMaximum
Maximum Y axis value.
Definition qgsplot.h:110
@ MarginLeft
Left margin.
Definition qgsplot.h:97
@ MarginRight
Right margin.
Definition qgsplot.h:99
@ YAxisMinimum
Minimum Y axis value.
Definition qgsplot.h:109
void setProperty(int key, const QgsProperty &property)
Adds a property to the collection and takes ownership of it.
A button for controlling property overrides which may apply to a widget.
QgsProperty toProperty() const
Returns a QgsProperty object encapsulating the current state of the widget.
void changed()
Emitted when property definition changes.
void init(int propertyKey, const QgsProperty &property, const QgsPropertiesDefinition &definitions, const QgsVectorLayer *layer=nullptr, bool auxiliaryStorageEnabled=false)
Initialize a newly constructed property button (useful if button was included in a UI layout).
void registerExpressionContextGenerator(QgsExpressionContextGenerator *generator)
Register an expression context generator class that will be used to retrieve an expression context fo...
int propertyKey() const
Returns the property key linked to the button.
A button for creating and modifying QgsSymbol settings.
void setFixedSizeConstraints(bool fixedSizeConstraints)
Sets whether the widget adopts fixed size constraints.
void setSymbol(QgsSymbol *symbol)
Sets the symbol for the button.
void setSymbolType(Qgis::SymbolType type)
Sets the symbol type which the button requires.
void registerExpressionContextGenerator(QgsExpressionContextGenerator *generator)
Register an expression context generator class that will be used to retrieve an expression context fo...
void changed()
Emitted when the symbol's settings are changed.
void setShowNull(bool showNull)
Sets whether a set to null (clear) option is shown in the button's drop-down menu.
SymbolType * clonedSymbol()
Returns a clone of the current symbol (as the specified template type) defined by the button.
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.
Definition qgis.h:6880
Single variable definition for use within a QgsExpressionContextScope.