QGIS API Documentation 4.1.0-Master (5bf3c20f3c9)
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 connect( mXAxisLabelSuffixEdit, &QLineEdit::textChanged, this, [this] {
308 if ( mBlockChanges )
309 return;
310 emit widgetChanged();
311 } );
312
313 mXAxisLabelsCombo->addItem( tr( "None" ), QVariant::fromValue( Qgis::PlotAxisSuffixPlacement::NoLabels ) );
314 mXAxisLabelsCombo->addItem( tr( "Every Value" ), QVariant::fromValue( Qgis::PlotAxisSuffixPlacement::EveryLabel ) );
315 mXAxisLabelsCombo->addItem( tr( "First Value" ), QVariant::fromValue( Qgis::PlotAxisSuffixPlacement::FirstLabel ) );
316 mXAxisLabelsCombo->addItem( tr( "Last Value" ), QVariant::fromValue( Qgis::PlotAxisSuffixPlacement::LastLabel ) );
317 mXAxisLabelsCombo->addItem( tr( "First and Last Values" ), QVariant::fromValue( Qgis::PlotAxisSuffixPlacement::FirstAndLastLabels ) );
318 connect( mXAxisLabelsCombo, qOverload<int>( &QComboBox::currentIndexChanged ), this, [this]( int ) {
319 if ( mBlockChanges )
320 return;
321 emit widgetChanged();
322 } );
323
324 mXAxisMajorLinesSymbolButton->registerExpressionContextGenerator( this );
325 mXAxisMinorLinesSymbolButton->registerExpressionContextGenerator( this );
326 mXAxisLabelFontButton->registerExpressionContextGenerator( this );
327 mYAxisMajorLinesSymbolButton->registerExpressionContextGenerator( this );
328 mYAxisMinorLinesSymbolButton->registerExpressionContextGenerator( this );
329 mYAxisLabelFontButton->registerExpressionContextGenerator( this );
330 mChartBackgroundSymbolButton->registerExpressionContextGenerator( this );
331 mChartBorderSymbolButton->registerExpressionContextGenerator( this );
332
337
344
349}
350
351void QgsBarChartPlotWidget::mAddSymbolPushButton_clicked()
352{
353 const int row = mSymbolsList->rowCount();
354 mSymbolsList->insertRow( row );
355
356 QTableWidgetItem *item = new QTableWidgetItem();
357 item->setData( Qt::DisplayRole, tr( "Symbol" ) );
358 mSymbolsList->setItem( row, 0, item );
359
360 QgsSymbolButton *symbolButton = new QgsSymbolButton( this );
361 symbolButton->setSymbolType( Qgis::SymbolType::Fill );
362 symbolButton->setShowNull( true );
364 symbolButton->registerExpressionContextGenerator( this );
365 connect( symbolButton, &QgsSymbolButton::changed, this, [this] {
366 if ( mBlockChanges )
367 return;
368 emit widgetChanged();
369 } );
370 mSymbolsList->setCellWidget( row, 1, symbolButton );
371
372 emit widgetChanged();
373}
374
375void QgsBarChartPlotWidget::mRemoveSymbolPushButton_clicked()
376{
377 QTableWidgetItem *item = mSymbolsList->currentItem();
378 if ( !item )
379 {
380 return;
381 }
382
383 mSymbolsList->removeRow( mSymbolsList->row( item ) );
384
385 emit widgetChanged();
386}
387
388void QgsBarChartPlotWidget::updateXAxisProperties()
389{
390 const bool enable = mXAxisTypeCombo->currentData().value<Qgis::PlotAxisType>() == Qgis::PlotAxisType::Interval;
391
392 mXAxisLabelSuffixLabel->setEnabled( enable );
393 mXAxisLabelSuffixEdit->setEnabled( enable );
394 mLabelMinXAxis->setEnabled( enable );
395 mSpinMinXAxis->setEnabled( enable );
396 mDDBtnMinXAxis->setEnabled( enable );
397 mLabelMaxXAxis->setEnabled( enable );
398 mSpinMaxXAxis->setEnabled( enable );
399 mDDBtnMaxXAxis->setEnabled( enable );
400
401 mXAxisMajorIntervalLabel->setEnabled( enable );
402 mXAxisMajorIntervalSpin->setEnabled( enable );
403 mDDBtnXAxisMajorInterval->setEnabled( enable );
404 mXAxisMajorLinesLabel->setEnabled( enable );
405 mXAxisMajorLinesSymbolButton->setEnabled( enable );
406 mXAxisMinorIntervalLabel->setEnabled( enable );
407 mXAxisMinorIntervalSpin->setEnabled( enable );
408 mDDBtnXAxisMinorInterval->setEnabled( enable );
409 mXAxisMinorLinesLabel->setEnabled( enable );
410 mXAxisMinorLinesSymbolButton->setEnabled( enable );
411}
412
414{
415 QgsBarChartPlot *chartPlot = dynamic_cast<QgsBarChartPlot *>( plot );
416 if ( !chartPlot )
417 {
418 return;
419 }
420
421 mBlockChanges++;
422
423 mSymbolsList->clear();
424 const int symbolCount = chartPlot->fillSymbolCount();
425 for ( int i = 0; i < symbolCount; i++ )
426 {
427 const int row = mSymbolsList->rowCount();
428 mSymbolsList->insertRow( row );
429
430 QTableWidgetItem *item = new QTableWidgetItem();
431 item->setData( Qt::DisplayRole, tr( "Symbol" ) );
432 mSymbolsList->setItem( row, 0, item );
433
434 QgsSymbolButton *symbolButton = new QgsSymbolButton( this );
435 symbolButton->setSymbolType( Qgis::SymbolType::Fill );
436 symbolButton->setShowNull( true );
437 symbolButton->setSymbol( chartPlot->fillSymbolAt( i )->clone() );
438 symbolButton->registerExpressionContextGenerator( this );
439 connect( symbolButton, &QgsSymbolButton::changed, this, [this] {
440 if ( mBlockChanges )
441 return;
442 emit widgetChanged();
443 } );
444 mSymbolsList->setCellWidget( row, 1, symbolButton );
445 }
446
447 mSpinMinXAxis->setValue( chartPlot->xMinimum() );
448 mSpinMaxXAxis->setValue( chartPlot->xMaximum() );
449 mSpinMinYAxis->setValue( chartPlot->yMinimum() );
450 mSpinMaxYAxis->setValue( chartPlot->yMaximum() );
451
452 if ( chartPlot->xAxis().gridMajorSymbol() )
453 mXAxisMajorLinesSymbolButton->setSymbol( chartPlot->xAxis().gridMajorSymbol()->clone() );
454 if ( chartPlot->xAxis().gridMinorSymbol() )
455 mXAxisMinorLinesSymbolButton->setSymbol( chartPlot->xAxis().gridMinorSymbol()->clone() );
456 if ( chartPlot->yAxis().gridMajorSymbol() )
457 mYAxisMajorLinesSymbolButton->setSymbol( chartPlot->yAxis().gridMajorSymbol()->clone() );
458 if ( chartPlot->yAxis().gridMinorSymbol() )
459 mYAxisMinorLinesSymbolButton->setSymbol( chartPlot->yAxis().gridMinorSymbol()->clone() );
460
461 mXAxisLabelFontButton->setTextFormat( chartPlot->xAxis().textFormat() );
462 mXAxisNumericFormat.reset( chartPlot->xAxis().numericFormat()->clone() );
463 mYAxisLabelFontButton->setTextFormat( chartPlot->yAxis().textFormat() );
464 mYAxisNumericFormat.reset( chartPlot->yAxis().numericFormat()->clone() );
465
466 mXAxisTypeCombo->setCurrentIndex( mXAxisTypeCombo->findData( QVariant::fromValue( chartPlot->xAxis().type() ) ) );
467 mXAxisLabelSuffixEdit->setText( chartPlot->xAxis().labelSuffix() );
468 mXAxisLabelsCombo->setCurrentIndex( mXAxisLabelsCombo->findData( QVariant::fromValue( chartPlot->xAxis().labelSuffixPlacement() ) ) );
469
470 mXAxisMajorIntervalSpin->setValue( chartPlot->xAxis().gridIntervalMajor() );
471 mXAxisMinorIntervalSpin->setValue( chartPlot->xAxis().gridIntervalMinor() );
472 mXAxisLabelIntervalSpin->setValue( chartPlot->xAxis().labelInterval() );
473
474 mYAxisMajorIntervalSpin->setValue( chartPlot->yAxis().gridIntervalMajor() );
475 mYAxisMinorIntervalSpin->setValue( chartPlot->yAxis().gridIntervalMinor() );
476 mYAxisLabelIntervalSpin->setValue( chartPlot->yAxis().labelInterval() );
477
478 if ( chartPlot->chartBackgroundSymbol() )
479 mChartBackgroundSymbolButton->setSymbol( chartPlot->chartBackgroundSymbol()->clone() );
480 if ( chartPlot->chartBorderSymbol() )
481 mChartBorderSymbolButton->setSymbol( chartPlot->chartBorderSymbol()->clone() );
482
483 mSpinLeftMargin->setValue( chartPlot->margins().left() );
484 mSpinRightMargin->setValue( chartPlot->margins().right() );
485 mSpinTopMargin->setValue( chartPlot->margins().top() );
486 mSpinBottomMargin->setValue( chartPlot->margins().bottom() );
487
488 mFlipAxes = chartPlot->flipAxes();
489
491
492 updateDataDefinedButton( mDDBtnMinXAxis );
493 updateDataDefinedButton( mDDBtnMaxXAxis );
494 updateDataDefinedButton( mDDBtnMinYAxis );
495 updateDataDefinedButton( mDDBtnMaxYAxis );
496
497 updateDataDefinedButton( mDDBtnXAxisMajorInterval );
498 updateDataDefinedButton( mDDBtnXAxisMinorInterval );
499 updateDataDefinedButton( mDDBtnXAxisLabelInterval );
500 updateDataDefinedButton( mDDBtnYAxisMajorInterval );
501 updateDataDefinedButton( mDDBtnYAxisMinorInterval );
502 updateDataDefinedButton( mDDBtnYAxisLabelInterval );
503
504 updateDataDefinedButton( mDDBtnLeftMargin );
505 updateDataDefinedButton( mDDBtnRightMargin );
506 updateDataDefinedButton( mDDBtnTopMargin );
507 updateDataDefinedButton( mDDBtnBottomMargin );
508
509 mBlockChanges--;
510}
511
513{
514 QgsPlot *plot = QgsApplication::plotRegistry()->createPlot( u"bar"_s );
515 QgsBarChartPlot *chartPlot = dynamic_cast<QgsBarChartPlot *>( plot );
516 if ( !chartPlot )
517 {
518 return nullptr;
519 }
520
521 const int rowCount = mSymbolsList->rowCount();
522 for ( int i = 0; i < rowCount; i++ )
523 {
524 QgsSymbolButton *symbolButton = dynamic_cast<QgsSymbolButton *>( mSymbolsList->cellWidget( i, 1 ) );
525 if ( symbolButton )
526 {
527 chartPlot->setFillSymbolAt( i, symbolButton->clonedSymbol<QgsFillSymbol>() );
528 }
529 }
530
531 chartPlot->setXMinimum( mSpinMinXAxis->value() );
532 chartPlot->setXMaximum( mSpinMaxXAxis->value() );
533 chartPlot->setYMinimum( mSpinMinYAxis->value() );
534 chartPlot->setYMaximum( mSpinMaxYAxis->value() );
535
536 chartPlot->xAxis().setGridMajorSymbol( mXAxisMajorLinesSymbolButton->clonedSymbol<QgsLineSymbol>() );
537 chartPlot->xAxis().setGridMinorSymbol( mXAxisMinorLinesSymbolButton->clonedSymbol<QgsLineSymbol>() );
538 chartPlot->yAxis().setGridMajorSymbol( mYAxisMajorLinesSymbolButton->clonedSymbol<QgsLineSymbol>() );
539 chartPlot->yAxis().setGridMinorSymbol( mYAxisMinorLinesSymbolButton->clonedSymbol<QgsLineSymbol>() );
540
541 chartPlot->xAxis().setTextFormat( mXAxisLabelFontButton->textFormat() );
542 chartPlot->xAxis().setNumericFormat( mXAxisNumericFormat.get()->clone() );
543 chartPlot->yAxis().setTextFormat( mYAxisLabelFontButton->textFormat() );
544 chartPlot->yAxis().setNumericFormat( mYAxisNumericFormat.get()->clone() );
545
546 chartPlot->xAxis().setType( mXAxisTypeCombo->currentData().value<Qgis::PlotAxisType>() );
547 chartPlot->xAxis().setLabelSuffix( mXAxisLabelSuffixEdit->text() );
548 chartPlot->xAxis().setLabelSuffixPlacement( mXAxisLabelsCombo->currentData().value<Qgis::PlotAxisSuffixPlacement>() );
549
550 chartPlot->xAxis().setGridIntervalMajor( mXAxisMajorIntervalSpin->value() );
551 chartPlot->xAxis().setGridIntervalMinor( mXAxisMinorIntervalSpin->value() );
552 chartPlot->xAxis().setLabelInterval( mXAxisLabelIntervalSpin->value() );
553
554 chartPlot->yAxis().setGridIntervalMajor( mYAxisMajorIntervalSpin->value() );
555 chartPlot->yAxis().setGridIntervalMinor( mYAxisMinorIntervalSpin->value() );
556 chartPlot->yAxis().setLabelInterval( mYAxisLabelIntervalSpin->value() );
557
558 chartPlot->setChartBackgroundSymbol( mChartBackgroundSymbolButton->clonedSymbol<QgsFillSymbol>() );
559 chartPlot->setChartBorderSymbol( mChartBorderSymbolButton->clonedSymbol<QgsFillSymbol>() );
560
561 QgsMargins margins;
562 margins.setLeft( mSpinLeftMargin->value() );
563 margins.setRight( mSpinRightMargin->value() );
564 margins.setTop( mSpinTopMargin->value() );
565 margins.setBottom( mSpinBottomMargin->value() );
566 chartPlot->setMargins( margins );
567
568 chartPlot->setFlipAxes( mFlipAxes );
570
571 return plot;
572}
573
574
576 : QgsPlotWidget( parent )
577{
578 setupUi( this );
579
580 setPanelTitle( tr( "Line Chart Plot Properties" ) );
581
582 mSymbolsList->setColumnCount( 3 );
583 mSymbolsList->setSelectionBehavior( QAbstractItemView::SelectRows );
584 mSymbolsList->setSelectionMode( QAbstractItemView::ExtendedSelection );
585 mSymbolsList->setSortingEnabled( false );
586 mSymbolsList->horizontalHeader()->setSectionResizeMode( 0, QHeaderView::Stretch );
587 mSymbolsList->horizontalHeader()->setSectionResizeMode( 1, QHeaderView::Stretch );
588 mSymbolsList->horizontalHeader()->setSectionResizeMode( 2, QHeaderView::Stretch );
589 mSymbolsList->horizontalHeader()->hide();
590 mSymbolsList->verticalHeader()->hide();
591
592 connect( mAddSymbolPushButton, &QPushButton::clicked, this, &QgsLineChartPlotWidget::mAddSymbolPushButton_clicked );
593 connect( mRemoveSymbolPushButton, &QPushButton::clicked, this, &QgsLineChartPlotWidget::mRemoveSymbolPushButton_clicked );
594
595 mSpinMinXAxis->setClearValue( 0 );
596 connect( mSpinMinXAxis, qOverload<double>( &QDoubleSpinBox::valueChanged ), this, [this]( double ) {
597 if ( mBlockChanges )
598 return;
599 emit widgetChanged();
600 } );
601
602 connect( mSpinMaxXAxis, qOverload<double>( &QDoubleSpinBox::valueChanged ), this, [this]( double ) {
603 if ( mBlockChanges )
604 return;
605 emit widgetChanged();
606 } );
607
608 mSpinMinYAxis->setClearValue( 0 );
609 connect( mSpinMinYAxis, qOverload<double>( &QDoubleSpinBox::valueChanged ), this, [this]( double ) {
610 if ( mBlockChanges )
611 return;
612 emit widgetChanged();
613 } );
614
615 mSpinMaxYAxis->setClearValue( 0 );
616 connect( mSpinMaxYAxis, qOverload<double>( &QDoubleSpinBox::valueChanged ), this, [this]( double ) {
617 if ( mBlockChanges )
618 return;
619 emit widgetChanged();
620 } );
621
622 mXAxisMajorLinesSymbolButton->setSymbolType( Qgis::SymbolType::Line );
623 connect( mXAxisMajorLinesSymbolButton, &QgsSymbolButton::changed, this, [this] {
624 if ( mBlockChanges )
625 return;
626 emit widgetChanged();
627 } );
628 mXAxisMajorLinesSymbolButton->setDefaultSymbol( QgsPlotDefaultSettings::axisGridMajorSymbol() );
629
630 mXAxisMinorLinesSymbolButton->setSymbolType( Qgis::SymbolType::Line );
631 connect( mXAxisMinorLinesSymbolButton, &QgsSymbolButton::changed, this, [this] {
632 if ( mBlockChanges )
633 return;
634 emit widgetChanged();
635 } );
636 mXAxisMinorLinesSymbolButton->setDefaultSymbol( QgsPlotDefaultSettings::axisGridMinorSymbol() );
637
638 connect( mXAxisMajorIntervalSpin, qOverload<double>( &QDoubleSpinBox::valueChanged ), this, [this]( double ) {
639 if ( mBlockChanges )
640 return;
641 emit widgetChanged();
642 } );
643
644 connect( mXAxisMinorIntervalSpin, qOverload<double>( &QDoubleSpinBox::valueChanged ), this, [this]( double ) {
645 if ( mBlockChanges )
646 return;
647 emit widgetChanged();
648 } );
649
650 connect( mXAxisLabelIntervalSpin, qOverload<double>( &QDoubleSpinBox::valueChanged ), this, [this]( double ) {
651 if ( mBlockChanges )
652 return;
653 emit widgetChanged();
654 } );
655
656 mYAxisMajorLinesSymbolButton->setSymbolType( Qgis::SymbolType::Line );
657 connect( mYAxisMajorLinesSymbolButton, &QgsSymbolButton::changed, this, [this] {
658 if ( mBlockChanges )
659 return;
660 emit widgetChanged();
661 } );
662 mYAxisMajorLinesSymbolButton->setDefaultSymbol( QgsPlotDefaultSettings::axisGridMajorSymbol() );
663
664 mYAxisMinorLinesSymbolButton->setSymbolType( Qgis::SymbolType::Line );
665 connect( mYAxisMinorLinesSymbolButton, &QgsSymbolButton::changed, this, [this] {
666 if ( mBlockChanges )
667 return;
668 emit widgetChanged();
669 } );
670 mYAxisMinorLinesSymbolButton->setDefaultSymbol( QgsPlotDefaultSettings::axisGridMinorSymbol() );
671
672 connect( mYAxisLabelIntervalSpin, qOverload<double>( &QDoubleSpinBox::valueChanged ), this, [this]( double ) {
673 if ( mBlockChanges )
674 return;
675 emit widgetChanged();
676 } );
677
678 connect( mYAxisMajorIntervalSpin, qOverload<double>( &QDoubleSpinBox::valueChanged ), this, [this]( double ) {
679 if ( mBlockChanges )
680 return;
681 emit widgetChanged();
682 } );
683
684 connect( mYAxisMinorIntervalSpin, qOverload<double>( &QDoubleSpinBox::valueChanged ), this, [this]( double ) {
685 if ( mBlockChanges )
686 return;
687 emit widgetChanged();
688 } );
689
690 mChartBackgroundSymbolButton->setSymbolType( Qgis::SymbolType::Fill );
691 connect( mChartBackgroundSymbolButton, &QgsSymbolButton::changed, this, [this] {
692 if ( mBlockChanges )
693 return;
694 emit widgetChanged();
695 } );
696 mChartBackgroundSymbolButton->setDefaultSymbol( QgsPlotDefaultSettings::chartBackgroundSymbol() );
697
698 mChartBorderSymbolButton->setSymbolType( Qgis::SymbolType::Fill );
699 connect( mChartBorderSymbolButton, &QgsSymbolButton::changed, this, [this] {
700 if ( mBlockChanges )
701 return;
702 emit widgetChanged();
703 } );
704 mChartBorderSymbolButton->setDefaultSymbol( QgsPlotDefaultSettings::chartBorderSymbol() );
705
706 connect( mXAxisLabelFormatButton, &QPushButton::clicked, this, [this] {
708 widget->setPanelTitle( tr( "X Axis Number Format" ) );
709 widget->setFormat( mXAxisNumericFormat.get() );
710 connect( widget, &QgsNumericFormatSelectorWidget::changed, this, [this, widget] {
711 mXAxisNumericFormat.reset( widget->format() );
712 emit widgetChanged();
713 } );
714 openPanel( widget );
715 } );
716
717 connect( mYAxisLabelFormatButton, &QPushButton::clicked, this, [this] {
719 widget->setPanelTitle( tr( "Y Axis Number Format" ) );
720 widget->setFormat( mYAxisNumericFormat.get() );
721 connect( widget, &QgsNumericFormatSelectorWidget::changed, this, [this, widget] {
722 mYAxisNumericFormat.reset( widget->format() );
723 emit widgetChanged();
724 } );
725 openPanel( widget );
726 } );
727
728 mXAxisLabelFontButton->setDialogTitle( tr( "X Axis Label Font" ) );
729 mYAxisLabelFontButton->setDialogTitle( tr( "Y Axis Label Font" ) );
730 mXAxisLabelFontButton->setMode( QgsFontButton::ModeTextRenderer );
731 mYAxisLabelFontButton->setMode( QgsFontButton::ModeTextRenderer );
732
733 connect( mXAxisLabelFontButton, &QgsFontButton::changed, this, [this] {
734 if ( mBlockChanges )
735 return;
736 emit widgetChanged();
737 } );
738
739 connect( mYAxisLabelFontButton, &QgsFontButton::changed, this, [this] {
740 if ( mBlockChanges )
741 return;
742 emit widgetChanged();
743 } );
744
745 mSpinLeftMargin->setClearValue( 0 );
746 connect( mSpinLeftMargin, qOverload<double>( &QDoubleSpinBox::valueChanged ), this, [this]( double ) {
747 if ( mBlockChanges )
748 return;
749 emit widgetChanged();
750 } );
751
752 mSpinRightMargin->setClearValue( 0 );
753 connect( mSpinRightMargin, qOverload<double>( &QDoubleSpinBox::valueChanged ), this, [this]( double ) {
754 if ( mBlockChanges )
755 return;
756 emit widgetChanged();
757 } );
758
759 mSpinTopMargin->setClearValue( 0 );
760 connect( mSpinTopMargin, qOverload<double>( &QDoubleSpinBox::valueChanged ), this, [this]( double ) {
761 if ( mBlockChanges )
762 return;
763 emit widgetChanged();
764 } );
765
766 mSpinBottomMargin->setClearValue( 0 );
767 connect( mSpinBottomMargin, qOverload<double>( &QDoubleSpinBox::valueChanged ), this, [this]( double ) {
768 if ( mBlockChanges )
769 return;
770 emit widgetChanged();
771 } );
772
773 mXAxisTypeCombo->addItem( tr( "Interval" ), QVariant::fromValue( Qgis::PlotAxisType::Interval ) );
774 mXAxisTypeCombo->addItem( tr( "Categorical" ), QVariant::fromValue( Qgis::PlotAxisType::Categorical ) );
775 connect( mXAxisTypeCombo, qOverload<int>( &QComboBox::currentIndexChanged ), this, &QgsLineChartPlotWidget::updateXAxisProperties );
776 connect( mXAxisTypeCombo, qOverload<int>( &QComboBox::currentIndexChanged ), this, [this]( int ) {
777 if ( mBlockChanges )
778 return;
779 emit widgetChanged();
780 } );
781
782 connect( mXAxisLabelSuffixEdit, &QLineEdit::textChanged, this, [this] {
783 if ( mBlockChanges )
784 return;
785 emit widgetChanged();
786 } );
787
788 mXAxisLabelsCombo->addItem( tr( "None" ), QVariant::fromValue( Qgis::PlotAxisSuffixPlacement::NoLabels ) );
789 mXAxisLabelsCombo->addItem( tr( "Every Value" ), QVariant::fromValue( Qgis::PlotAxisSuffixPlacement::EveryLabel ) );
790 mXAxisLabelsCombo->addItem( tr( "First Value" ), QVariant::fromValue( Qgis::PlotAxisSuffixPlacement::FirstLabel ) );
791 mXAxisLabelsCombo->addItem( tr( "Last Value" ), QVariant::fromValue( Qgis::PlotAxisSuffixPlacement::LastLabel ) );
792 mXAxisLabelsCombo->addItem( tr( "First and Last Values" ), QVariant::fromValue( Qgis::PlotAxisSuffixPlacement::FirstAndLastLabels ) );
793 connect( mXAxisLabelsCombo, qOverload<int>( &QComboBox::currentIndexChanged ), this, [this]( int ) {
794 if ( mBlockChanges )
795 return;
796 emit widgetChanged();
797 } );
798
799 mXAxisMajorLinesSymbolButton->registerExpressionContextGenerator( this );
800 mXAxisMinorLinesSymbolButton->registerExpressionContextGenerator( this );
801 mXAxisLabelFontButton->registerExpressionContextGenerator( this );
802 mYAxisMajorLinesSymbolButton->registerExpressionContextGenerator( this );
803 mYAxisMinorLinesSymbolButton->registerExpressionContextGenerator( this );
804 mYAxisLabelFontButton->registerExpressionContextGenerator( this );
805 mChartBackgroundSymbolButton->registerExpressionContextGenerator( this );
806 mChartBorderSymbolButton->registerExpressionContextGenerator( this );
807
812
819
824}
825
826void QgsLineChartPlotWidget::mAddSymbolPushButton_clicked()
827{
828 const int row = mSymbolsList->rowCount();
829 mSymbolsList->insertRow( row );
830
831 QTableWidgetItem *item = new QTableWidgetItem();
832 item->setData( Qt::DisplayRole, tr( "Symbol" ) );
833 mSymbolsList->setItem( row, 0, item );
834
835 // Line
836 QgsSymbolButton *symbolButton = new QgsSymbolButton( this );
837 symbolButton->setSymbolType( Qgis::SymbolType::Line );
838 symbolButton->setShowNull( true );
840 symbolButton->registerExpressionContextGenerator( this );
841 connect( symbolButton, &QgsSymbolButton::changed, this, [this] {
842 if ( mBlockChanges )
843 return;
844 emit widgetChanged();
845 } );
846 mSymbolsList->setCellWidget( row, 1, symbolButton );
847
848 // Marker
849 symbolButton = new QgsSymbolButton( this );
850 symbolButton->setFixedSizeConstraints( false );
852 symbolButton->setShowNull( true );
854 symbolButton->registerExpressionContextGenerator( this );
855 connect( symbolButton, &QgsSymbolButton::changed, this, [this] {
856 if ( mBlockChanges )
857 return;
858 emit widgetChanged();
859 } );
860 mSymbolsList->setCellWidget( row, 2, symbolButton );
861
862 emit widgetChanged();
863}
864
865void QgsLineChartPlotWidget::mRemoveSymbolPushButton_clicked()
866{
867 QTableWidgetItem *item = mSymbolsList->currentItem();
868 if ( !item )
869 {
870 return;
871 }
872
873 mSymbolsList->removeRow( mSymbolsList->row( item ) );
874
875 emit widgetChanged();
876}
877
878void QgsLineChartPlotWidget::updateXAxisProperties()
879{
880 const bool enable = mXAxisTypeCombo->currentData().value<Qgis::PlotAxisType>() == Qgis::PlotAxisType::Interval;
881
882 mXAxisLabelSuffixLabel->setEnabled( enable );
883 mXAxisLabelSuffixEdit->setEnabled( enable );
884 mLabelMinXAxis->setEnabled( enable );
885 mSpinMinXAxis->setEnabled( enable );
886 mDDBtnMinXAxis->setEnabled( enable );
887 mLabelMaxXAxis->setEnabled( enable );
888 mSpinMaxXAxis->setEnabled( enable );
889 mDDBtnMaxXAxis->setEnabled( enable );
890
891 mXAxisMajorIntervalLabel->setEnabled( enable );
892 mXAxisMajorIntervalSpin->setEnabled( enable );
893 mDDBtnXAxisMajorInterval->setEnabled( enable );
894 mXAxisMajorLinesLabel->setEnabled( enable );
895 mXAxisMajorLinesSymbolButton->setEnabled( enable );
896 mXAxisMinorIntervalLabel->setEnabled( enable );
897 mXAxisMinorIntervalSpin->setEnabled( enable );
898 mDDBtnXAxisMinorInterval->setEnabled( enable );
899 mXAxisMinorLinesLabel->setEnabled( enable );
900 mXAxisMinorLinesSymbolButton->setEnabled( enable );
901}
902
904{
905 QgsLineChartPlot *chartPlot = dynamic_cast<QgsLineChartPlot *>( plot );
906 if ( !chartPlot )
907 {
908 return;
909 }
910
911 mBlockChanges++;
912
913 mSymbolsList->clear();
914 const int symbolCount = std::max( chartPlot->markerSymbolCount(), chartPlot->lineSymbolCount() );
915 for ( int i = 0; i < symbolCount; i++ )
916 {
917 const int row = mSymbolsList->rowCount();
918 mSymbolsList->insertRow( row );
919
920 QTableWidgetItem *item = new QTableWidgetItem();
921 item->setData( Qt::DisplayRole, tr( "Symbol" ) );
922 mSymbolsList->setItem( row, 0, item );
923
924 // Line
925 QgsSymbolButton *symbolButton = new QgsSymbolButton( this );
926 symbolButton->setSymbolType( Qgis::SymbolType::Line );
927 symbolButton->setShowNull( true );
928 symbolButton->setSymbol( i < chartPlot->lineSymbolCount() ? chartPlot->lineSymbolAt( i )->clone() : nullptr );
929 symbolButton->registerExpressionContextGenerator( this );
930 connect( symbolButton, &QgsSymbolButton::changed, this, [this] {
931 if ( mBlockChanges )
932 return;
933 emit widgetChanged();
934 } );
935 mSymbolsList->setCellWidget( row, 1, symbolButton );
936
937 // Marker
938 symbolButton = new QgsSymbolButton( this );
939 symbolButton->setFixedSizeConstraints( false );
941 symbolButton->setShowNull( true );
942 symbolButton->setSymbol( i < chartPlot->markerSymbolCount() ? chartPlot->markerSymbolAt( i )->clone() : nullptr );
943 symbolButton->registerExpressionContextGenerator( this );
944 connect( symbolButton, &QgsSymbolButton::changed, this, [this] {
945 if ( mBlockChanges )
946 return;
947 emit widgetChanged();
948 } );
949 mSymbolsList->setCellWidget( row, 2, symbolButton );
950 }
951
952 mSpinMinXAxis->setValue( chartPlot->xMinimum() );
953 mSpinMaxXAxis->setValue( chartPlot->xMaximum() );
954 mSpinMinYAxis->setValue( chartPlot->yMinimum() );
955 mSpinMaxYAxis->setValue( chartPlot->yMaximum() );
956
957 if ( chartPlot->xAxis().gridMajorSymbol() )
958 mXAxisMajorLinesSymbolButton->setSymbol( chartPlot->xAxis().gridMajorSymbol()->clone() );
959 if ( chartPlot->xAxis().gridMinorSymbol() )
960 mXAxisMinorLinesSymbolButton->setSymbol( chartPlot->xAxis().gridMinorSymbol()->clone() );
961 if ( chartPlot->yAxis().gridMajorSymbol() )
962 mYAxisMajorLinesSymbolButton->setSymbol( chartPlot->yAxis().gridMajorSymbol()->clone() );
963 if ( chartPlot->yAxis().gridMinorSymbol() )
964 mYAxisMinorLinesSymbolButton->setSymbol( chartPlot->yAxis().gridMinorSymbol()->clone() );
965
966 mXAxisLabelFontButton->setTextFormat( chartPlot->xAxis().textFormat() );
967 mYAxisLabelFontButton->setTextFormat( chartPlot->yAxis().textFormat() );
968
969 mXAxisTypeCombo->setCurrentIndex( mXAxisTypeCombo->findData( QVariant::fromValue( chartPlot->xAxis().type() ) ) );
970 mXAxisLabelSuffixEdit->setText( chartPlot->xAxis().labelSuffix() );
971 mXAxisLabelsCombo->setCurrentIndex( mXAxisLabelsCombo->findData( QVariant::fromValue( chartPlot->xAxis().labelSuffixPlacement() ) ) );
972
973 mXAxisMajorIntervalSpin->setValue( chartPlot->xAxis().gridIntervalMajor() );
974 mXAxisMinorIntervalSpin->setValue( chartPlot->xAxis().gridIntervalMinor() );
975 mXAxisLabelIntervalSpin->setValue( chartPlot->xAxis().labelInterval() );
976
977 mYAxisMajorIntervalSpin->setValue( chartPlot->yAxis().gridIntervalMajor() );
978 mYAxisMinorIntervalSpin->setValue( chartPlot->yAxis().gridIntervalMinor() );
979 mYAxisLabelIntervalSpin->setValue( chartPlot->yAxis().labelInterval() );
980
981 if ( chartPlot->chartBackgroundSymbol() )
982 mChartBackgroundSymbolButton->setSymbol( chartPlot->chartBackgroundSymbol()->clone() );
983 if ( chartPlot->chartBorderSymbol() )
984 mChartBorderSymbolButton->setSymbol( chartPlot->chartBorderSymbol()->clone() );
985
986 mSpinLeftMargin->setValue( chartPlot->margins().left() );
987 mSpinRightMargin->setValue( chartPlot->margins().right() );
988 mSpinTopMargin->setValue( chartPlot->margins().top() );
989 mSpinBottomMargin->setValue( chartPlot->margins().bottom() );
990
991 mFlipAxes = chartPlot->flipAxes();
992
994
995 updateDataDefinedButton( mDDBtnMinXAxis );
996 updateDataDefinedButton( mDDBtnMaxXAxis );
997 updateDataDefinedButton( mDDBtnMinYAxis );
998 updateDataDefinedButton( mDDBtnMaxYAxis );
999
1000 updateDataDefinedButton( mDDBtnXAxisMajorInterval );
1001 updateDataDefinedButton( mDDBtnXAxisMinorInterval );
1002 updateDataDefinedButton( mDDBtnXAxisLabelInterval );
1003 updateDataDefinedButton( mDDBtnYAxisMajorInterval );
1004 updateDataDefinedButton( mDDBtnYAxisMinorInterval );
1005 updateDataDefinedButton( mDDBtnYAxisLabelInterval );
1006
1007 updateDataDefinedButton( mDDBtnLeftMargin );
1008 updateDataDefinedButton( mDDBtnRightMargin );
1009 updateDataDefinedButton( mDDBtnTopMargin );
1010 updateDataDefinedButton( mDDBtnBottomMargin );
1011
1012 mBlockChanges--;
1013}
1014
1016{
1017 QgsPlot *plot = QgsApplication::plotRegistry()->createPlot( u"line"_s );
1018 QgsLineChartPlot *chartPlot = dynamic_cast<QgsLineChartPlot *>( plot );
1019 if ( !chartPlot )
1020 {
1021 return nullptr;
1022 }
1023
1024 const int rowCount = mSymbolsList->rowCount();
1025 for ( int i = 0; i < rowCount; i++ )
1026 {
1027 QgsSymbolButton *symbolButton = dynamic_cast<QgsSymbolButton *>( mSymbolsList->cellWidget( i, 1 ) );
1028 if ( symbolButton )
1029 {
1030 chartPlot->setLineSymbolAt( i, symbolButton->clonedSymbol<QgsLineSymbol>() );
1031 }
1032
1033 symbolButton = dynamic_cast<QgsSymbolButton *>( mSymbolsList->cellWidget( i, 2 ) );
1034 if ( symbolButton )
1035 {
1036 chartPlot->setMarkerSymbolAt( i, symbolButton->clonedSymbol<QgsMarkerSymbol>() );
1037 }
1038 }
1039
1040 chartPlot->setXMinimum( mSpinMinXAxis->value() );
1041 chartPlot->setXMaximum( mSpinMaxXAxis->value() );
1042 chartPlot->setYMinimum( mSpinMinYAxis->value() );
1043 chartPlot->setYMaximum( mSpinMaxYAxis->value() );
1044
1045 chartPlot->xAxis().setGridMajorSymbol( mXAxisMajorLinesSymbolButton->clonedSymbol<QgsLineSymbol>() );
1046 chartPlot->xAxis().setGridMinorSymbol( mXAxisMinorLinesSymbolButton->clonedSymbol<QgsLineSymbol>() );
1047 chartPlot->yAxis().setGridMajorSymbol( mYAxisMajorLinesSymbolButton->clonedSymbol<QgsLineSymbol>() );
1048 chartPlot->yAxis().setGridMinorSymbol( mYAxisMinorLinesSymbolButton->clonedSymbol<QgsLineSymbol>() );
1049
1050 chartPlot->xAxis().setTextFormat( mXAxisLabelFontButton->textFormat() );
1051 chartPlot->yAxis().setTextFormat( mYAxisLabelFontButton->textFormat() );
1052
1053 chartPlot->xAxis().setType( mXAxisTypeCombo->currentData().value<Qgis::PlotAxisType>() );
1054 chartPlot->xAxis().setLabelSuffix( mXAxisLabelSuffixEdit->text() );
1055 chartPlot->xAxis().setLabelSuffixPlacement( mXAxisLabelsCombo->currentData().value<Qgis::PlotAxisSuffixPlacement>() );
1056
1057 chartPlot->xAxis().setGridIntervalMajor( mXAxisMajorIntervalSpin->value() );
1058 chartPlot->xAxis().setGridIntervalMinor( mXAxisMinorIntervalSpin->value() );
1059 chartPlot->xAxis().setLabelInterval( mXAxisLabelIntervalSpin->value() );
1060
1061 chartPlot->yAxis().setGridIntervalMajor( mYAxisMajorIntervalSpin->value() );
1062 chartPlot->yAxis().setGridIntervalMinor( mYAxisMinorIntervalSpin->value() );
1063 chartPlot->yAxis().setLabelInterval( mYAxisLabelIntervalSpin->value() );
1064
1065 chartPlot->setChartBackgroundSymbol( mChartBackgroundSymbolButton->clonedSymbol<QgsFillSymbol>() );
1066 chartPlot->setChartBorderSymbol( mChartBorderSymbolButton->clonedSymbol<QgsFillSymbol>() );
1067
1068 QgsMargins margins;
1069 margins.setLeft( mSpinLeftMargin->value() );
1070 margins.setRight( mSpinRightMargin->value() );
1071 margins.setTop( mSpinTopMargin->value() );
1072 margins.setBottom( mSpinBottomMargin->value() );
1073 chartPlot->setMargins( margins );
1074
1075 chartPlot->setFlipAxes( mFlipAxes );
1077
1078 return plot;
1079}
1080
1081
1083 : QgsPlotWidget( parent )
1084{
1085 setupUi( this );
1086
1087 setPanelTitle( tr( "Pie Chart Plot Properties" ) );
1088
1089 mSymbolsList->setColumnCount( 3 );
1090 mSymbolsList->setSelectionBehavior( QAbstractItemView::SelectRows );
1091 mSymbolsList->setSelectionMode( QAbstractItemView::ExtendedSelection );
1092 mSymbolsList->setSortingEnabled( false );
1093 mSymbolsList->horizontalHeader()->setSectionResizeMode( 0, QHeaderView::Stretch );
1094 mSymbolsList->horizontalHeader()->setSectionResizeMode( 1, QHeaderView::Stretch );
1095 mSymbolsList->horizontalHeader()->setSectionResizeMode( 2, QHeaderView::Stretch );
1096 mSymbolsList->horizontalHeader()->hide();
1097 mSymbolsList->verticalHeader()->hide();
1098
1099 mLabelCombo->addItem( tr( "None" ), QVariant::fromValue( Qgis::PieChartLabelType::NoLabels ) );
1100 mLabelCombo->addItem( tr( "Category Labels" ), QVariant::fromValue( Qgis::PieChartLabelType::Categories ) );
1101 mLabelCombo->addItem( tr( "Value Labels" ), QVariant::fromValue( Qgis::PieChartLabelType::Values ) );
1102 connect( mLabelCombo, qOverload<int>( &QComboBox::currentIndexChanged ), this, [this]( int ) {
1103 if ( mBlockChanges )
1104 return;
1105 emit widgetChanged();
1106 } );
1107
1108 mLabelFontButton->setDialogTitle( tr( "Chart Label Font" ) );
1109 mLabelFontButton->setMode( QgsFontButton::ModeTextRenderer );
1110 connect( mLabelFontButton, &QgsFontButton::changed, this, [this] {
1111 if ( mBlockChanges )
1112 return;
1113 emit widgetChanged();
1114 } );
1115
1116 connect( mLabelFormatButton, &QPushButton::clicked, this, [this] {
1118 widget->setPanelTitle( tr( "Chart Number Format" ) );
1119 widget->setFormat( mNumericFormat.get() );
1120 connect( widget, &QgsNumericFormatSelectorWidget::changed, this, [this, widget] {
1121 mNumericFormat.reset( widget->format() );
1122 emit widgetChanged();
1123 } );
1124 openPanel( widget );
1125 } );
1126
1127 mSpinLeftMargin->setClearValue( 0 );
1128 connect( mSpinLeftMargin, qOverload<double>( &QDoubleSpinBox::valueChanged ), this, [this]( double ) {
1129 if ( mBlockChanges )
1130 return;
1131 emit widgetChanged();
1132 } );
1133
1134 mSpinRightMargin->setClearValue( 0 );
1135 connect( mSpinRightMargin, qOverload<double>( &QDoubleSpinBox::valueChanged ), this, [this]( double ) {
1136 if ( mBlockChanges )
1137 return;
1138 emit widgetChanged();
1139 } );
1140
1141 mSpinTopMargin->setClearValue( 0 );
1142 connect( mSpinTopMargin, qOverload<double>( &QDoubleSpinBox::valueChanged ), this, [this]( double ) {
1143 if ( mBlockChanges )
1144 return;
1145 emit widgetChanged();
1146 } );
1147
1148 mSpinBottomMargin->setClearValue( 0 );
1149 connect( mSpinBottomMargin, qOverload<double>( &QDoubleSpinBox::valueChanged ), this, [this]( double ) {
1150 if ( mBlockChanges )
1151 return;
1152 emit widgetChanged();
1153 } );
1154
1155 connect( mAddSymbolPushButton, &QPushButton::clicked, this, &QgsPieChartPlotWidget::mAddSymbolPushButton_clicked );
1156 connect( mRemoveSymbolPushButton, &QPushButton::clicked, this, &QgsPieChartPlotWidget::mRemoveSymbolPushButton_clicked );
1157
1158 mLabelFontButton->registerExpressionContextGenerator( this );
1159
1164}
1165
1166void QgsPieChartPlotWidget::mAddSymbolPushButton_clicked()
1167{
1168 const int row = mSymbolsList->rowCount();
1169 mSymbolsList->insertRow( row );
1170
1171 QTableWidgetItem *item = new QTableWidgetItem();
1172 item->setData( Qt::DisplayRole, tr( "Symbol" ) );
1173 mSymbolsList->setItem( row, 0, item );
1174
1175 // Fill
1176 QgsSymbolButton *symbolButton = new QgsSymbolButton( this );
1177 symbolButton->setSymbolType( Qgis::SymbolType::Fill );
1178 symbolButton->setShowNull( true );
1180 symbolButton->registerExpressionContextGenerator( this );
1181 connect( symbolButton, &QgsSymbolButton::changed, this, [this] {
1182 if ( mBlockChanges )
1183 return;
1184 emit widgetChanged();
1185 } );
1186 mSymbolsList->setCellWidget( row, 1, symbolButton );
1187
1188 // Color ramp
1189 QgsColorRampButton *colorRampButton = new QgsColorRampButton( this );
1190 colorRampButton->setShowNull( true );
1192 connect( colorRampButton, &QgsColorRampButton::colorRampChanged, this, [this] {
1193 if ( mBlockChanges )
1194 return;
1195 emit widgetChanged();
1196 } );
1197 mSymbolsList->setCellWidget( row, 2, colorRampButton );
1198
1199 emit widgetChanged();
1200}
1201
1202void QgsPieChartPlotWidget::mRemoveSymbolPushButton_clicked()
1203{
1204 QTableWidgetItem *item = mSymbolsList->currentItem();
1205 if ( !item )
1206 {
1207 return;
1208 }
1209
1210 mSymbolsList->removeRow( mSymbolsList->row( item ) );
1211
1212 emit widgetChanged();
1213}
1214
1216{
1217 QgsPieChartPlot *chartPlot = dynamic_cast<QgsPieChartPlot *>( plot );
1218 if ( !chartPlot )
1219 {
1220 return;
1221 }
1222
1223 mBlockChanges++;
1224
1225 mSymbolsList->clear();
1226 const int symbolCount = std::max( chartPlot->fillSymbolCount(), chartPlot->colorRampCount() );
1227 for ( int i = 0; i < symbolCount; i++ )
1228 {
1229 const int row = mSymbolsList->rowCount();
1230 mSymbolsList->insertRow( row );
1231
1232 QTableWidgetItem *item = new QTableWidgetItem();
1233 item->setData( Qt::DisplayRole, tr( "Symbol" ) );
1234 mSymbolsList->setItem( row, 0, item );
1235
1236 // Fill
1237 QgsSymbolButton *symbolButton = new QgsSymbolButton( this );
1238 symbolButton->setSymbolType( Qgis::SymbolType::Fill );
1239 symbolButton->setShowNull( true );
1240 symbolButton->setSymbol( i < chartPlot->fillSymbolCount() ? chartPlot->fillSymbolAt( i )->clone() : nullptr );
1241 symbolButton->registerExpressionContextGenerator( this );
1242 connect( symbolButton, &QgsSymbolButton::changed, this, [this] {
1243 if ( mBlockChanges )
1244 return;
1245 emit widgetChanged();
1246 } );
1247 mSymbolsList->setCellWidget( row, 1, symbolButton );
1248
1249 // Color ramp
1250 QgsColorRampButton *colorRampButton = new QgsColorRampButton( this );
1251 colorRampButton->setShowNull( true );
1252 colorRampButton->setColorRamp( i < chartPlot->colorRampCount() ? chartPlot->colorRampAt( i )->clone() : nullptr );
1253 connect( colorRampButton, &QgsColorRampButton::colorRampChanged, this, [this] {
1254 if ( mBlockChanges )
1255 return;
1256 emit widgetChanged();
1257 } );
1258 mSymbolsList->setCellWidget( row, 2, colorRampButton );
1259 }
1260
1261 mNumericFormat.reset( chartPlot->numericFormat()->clone() );
1262 mLabelFontButton->setTextFormat( chartPlot->textFormat() );
1263
1264 mLabelCombo->setCurrentIndex( mLabelCombo->findData( QVariant::fromValue( chartPlot->labelType() ) ) );
1265
1267
1268 updateDataDefinedButton( mDDBtnLeftMargin );
1269 updateDataDefinedButton( mDDBtnRightMargin );
1270 updateDataDefinedButton( mDDBtnTopMargin );
1271 updateDataDefinedButton( mDDBtnBottomMargin );
1272
1273 mBlockChanges--;
1274}
1275
1277{
1278 QgsPlot *plot = QgsApplication::plotRegistry()->createPlot( u"pie"_s );
1279 QgsPieChartPlot *chartPlot = dynamic_cast<QgsPieChartPlot *>( plot );
1280 if ( !chartPlot )
1281 {
1282 return nullptr;
1283 }
1284
1285 const int rowCount = mSymbolsList->rowCount();
1286 for ( int i = 0; i < rowCount; i++ )
1287 {
1288 QgsSymbolButton *symbolButton = dynamic_cast<QgsSymbolButton *>( mSymbolsList->cellWidget( i, 1 ) );
1289 if ( symbolButton )
1290 {
1291 chartPlot->setFillSymbolAt( i, symbolButton->clonedSymbol<QgsFillSymbol>() );
1292 }
1293
1294 QgsColorRampButton *colorRampButton = dynamic_cast<QgsColorRampButton *>( mSymbolsList->cellWidget( i, 2 ) );
1295 if ( colorRampButton )
1296 {
1297 chartPlot->setColorRampAt( i, colorRampButton->colorRamp()->clone() );
1298 }
1299 }
1300
1301 chartPlot->setNumericFormat( mNumericFormat.get()->clone() );
1302 chartPlot->setTextFormat( mLabelFontButton->textFormat() );
1303 chartPlot->setLabelType( mLabelCombo->currentData().value<Qgis::PieChartLabelType>() );
1304
1305 QgsMargins margins;
1306 margins.setLeft( mSpinLeftMargin->value() );
1307 margins.setRight( mSpinRightMargin->value() );
1308 margins.setTop( mSpinTopMargin->value() );
1309 margins.setBottom( mSpinBottomMargin->value() );
1310 chartPlot->setMargins( margins );
1311
1313
1314 return plot;
1315}
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 setLabelSuffix(const QString &suffix)
Sets the axis label suffix.
Definition qgsplot.cpp:200
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
QString labelSuffix() const
Returns the axis label suffix, or an empty string if no label suffix is to be used.
Definition qgsplot.cpp:195
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.