QGIS API Documentation 3.41.0-Master (88383c3d16f)
Loading...
Searching...
No Matches
qgsstackeddiagramproperties.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsstackeddiagramproperties.h
3 Properties for stacked diagram layers
4 -------------------
5 begin : August 2024
6 copyright : (C) Germán Carrillo
7 email : german at opengis dot ch
8
9 ***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
23
24#include "qgsgui.h"
27#include "qgsproject.h"
29#include "moc_qgsstackeddiagramproperties.cpp"
30#include "qgsvectorlayer.h"
31#include "qgshelp.h"
32
33#include <QMimeData>
34
36 : QgsPanelWidget( parent )
37 , mLayer( layer )
38 , mMapCanvas( canvas )
39{
40 if ( !layer )
41 {
42 return;
43 }
44
45 setupUi( this );
46 connect( mSubDiagramsView, &QAbstractItemView::doubleClicked, this, static_cast<void ( QgsStackedDiagramProperties::* )( const QModelIndex & )>( &QgsStackedDiagramProperties::editSubDiagramRenderer ) );
47
48 connect( mAddSubDiagramButton, &QPushButton::clicked, this, &QgsStackedDiagramProperties::addSubDiagramRenderer );
49 connect( mEditSubDiagramButton, &QAbstractButton::clicked, this, static_cast<void ( QgsStackedDiagramProperties::* )()>( &QgsStackedDiagramProperties::editSubDiagramRenderer ) );
50 connect( mRemoveSubDiagramButton, &QPushButton::clicked, this, &QgsStackedDiagramProperties::removeSubDiagramRenderer );
51
52 // Initialize stacked diagram controls
53 mStackedDiagramModeComboBox->addItem( tr( "Horizontal" ), QgsDiagramSettings::Horizontal );
54 mStackedDiagramModeComboBox->addItem( tr( "Vertical" ), QgsDiagramSettings::Vertical );
55
56 mStackedDiagramSpacingSpinBox->setClearValue( 0 );
58
59 connect( mStackedDiagramModeComboBox, qOverload<int>( &QComboBox::currentIndexChanged ), this, &QgsStackedDiagramProperties::widgetChanged );
60 connect( mStackedDiagramSpacingSpinBox, qOverload<double>( &QgsDoubleSpinBox::valueChanged ), this, &QgsStackedDiagramProperties::widgetChanged );
61 connect( mStackedDiagramSpacingUnitComboBox, &QgsUnitSelectionWidget::changed, this, &QgsStackedDiagramProperties::widgetChanged );
62
64 mSubDiagramsView->setModel( mModel );
65
66 connect( mModel, &QAbstractItemModel::dataChanged, this, &QgsStackedDiagramProperties::widgetChanged );
67 connect( mModel, &QAbstractItemModel::rowsInserted, this, &QgsStackedDiagramProperties::widgetChanged );
68 connect( mModel, &QAbstractItemModel::rowsRemoved, this, &QgsStackedDiagramProperties::widgetChanged );
69
71}
72
73void QgsStackedDiagramProperties::addSubDiagramRenderer()
74{
75 // Create a single category renderer by default
76 std::unique_ptr<QgsDiagramRenderer> renderer;
77 auto dr = std::make_unique<QgsSingleCategoryDiagramRenderer>();
78 renderer = std::move( dr );
79
80 QItemSelectionModel *sel = mSubDiagramsView->selectionModel();
81 const QModelIndex index = sel->currentIndex();
82
83 if ( index.isValid() )
84 {
85 // add after this subDiagram
86 const QModelIndex currentIndex = mSubDiagramsView->selectionModel()->currentIndex();
87 mModel->insertSubDiagram( currentIndex.row() + 1, renderer.release() );
88 const QModelIndex newIndex = mModel->index( currentIndex.row() + 1, 0 );
89 mSubDiagramsView->selectionModel()->setCurrentIndex( newIndex, QItemSelectionModel::ClearAndSelect );
90 }
91 else
92 {
93 // append to root
94 appendSubDiagramRenderer( renderer.release() );
95 }
96 editSubDiagramRenderer();
97}
98
99void QgsStackedDiagramProperties::appendSubDiagramRenderer( QgsDiagramRenderer *dr )
100{
101 const int rows = mModel->rowCount();
102 mModel->insertSubDiagram( rows, dr ); // Transfers ownership
103 const QModelIndex newIndex = mModel->index( rows, 0 );
104 mSubDiagramsView->selectionModel()->setCurrentIndex( newIndex, QItemSelectionModel::ClearAndSelect );
105}
106
107void QgsStackedDiagramProperties::editSubDiagramRenderer()
108{
109 editSubDiagramRenderer( mSubDiagramsView->selectionModel()->currentIndex() );
110}
111
112void QgsStackedDiagramProperties::editSubDiagramRenderer( const QModelIndex &index )
113{
114 if ( !index.isValid() )
115 return;
116
117 QgsDiagramRenderer *renderer = mModel->subDiagramForIndex( index );
120
121 if ( panel && panel->dockMode() )
122 {
123 QgsDiagramProperties *widget = new QgsDiagramProperties( mLayer, this, mMapCanvas );
124 widget->setPanelTitle( tr( "Edit Sub Diagram" ) );
125 widget->layout()->setContentsMargins( 0, 0, 0, 0 );
126 widget->syncToRenderer( renderer );
127 widget->syncToSettings( &dls );
128 if ( !couldBeFirstSubDiagram( index ) )
129 {
131 }
132
134 connect( widget, &QgsPanelWidget::panelAccepted, this, &QgsStackedDiagramProperties::subDiagramWidgetPanelAccepted );
135 connect( widget, &QgsDiagramProperties::widgetChanged, this, &QgsStackedDiagramProperties::liveUpdateSubDiagramFromPanel );
136 openPanel( widget );
137 return;
138 }
139
140 QgsStackedDiagramPropertiesDialog dlg( mLayer, this, mMapCanvas );
141 dlg.syncToRenderer( renderer );
142 dlg.syncToSettings( &dls );
143 if ( !couldBeFirstSubDiagram( index ) )
144 {
145 dlg.setAllowedToEditDiagramLayerSettings( false );
146 }
147
148 if ( dlg.exec() )
149 {
150 const QModelIndex index = mSubDiagramsView->selectionModel()->currentIndex();
151 if ( dlg.isAllowedToEditDiagramLayerSettings() )
152 mModel->updateDiagramLayerSettings( dlg.diagramLayerSettings() );
153
154 // This call will emit dataChanged, which in turns triggers widgetChanged()
155 mModel->updateSubDiagram( index, dlg.renderer() );
156 }
157}
158
159void QgsStackedDiagramProperties::removeSubDiagramRenderer()
160{
161 const QItemSelection sel = mSubDiagramsView->selectionModel()->selection();
162 const auto constSel = sel;
163 for ( const QItemSelectionRange &range : constSel )
164 {
165 if ( range.isValid() )
166 mModel->removeRows( range.top(), range.bottom() - range.top() + 1, range.parent() );
167 }
168 // make sure that the selection is gone
169 mSubDiagramsView->selectionModel()->clear();
170}
171
173{
174 const QgsDiagramRenderer *dr = mLayer->diagramRenderer();
175
176 if ( dr && dr->diagram() )
177 {
178 const QList<QgsDiagramSettings> settingList = dr->diagramSettings();
179 mStackedDiagramModeComboBox->setCurrentIndex( settingList.at( 0 ).stackedDiagramMode );
180 mStackedDiagramSpacingSpinBox->setValue( settingList.at( 0 ).stackedDiagramSpacing() );
181 mStackedDiagramSpacingUnitComboBox->setUnit( settingList.at( 0 ).stackedDiagramSpacingUnit() );
182
184 {
185 const QgsStackedDiagramRenderer *stackedDiagramRenderer = static_cast<const QgsStackedDiagramRenderer *>( dr );
186 const QList<QgsDiagramRenderer *> renderers = stackedDiagramRenderer->renderers();
187 for ( const QgsDiagramRenderer *renderer : renderers )
188 {
189 appendSubDiagramRenderer( renderer->clone() );
190 }
191 }
192 else
193 {
194 // Take this single renderer as the first stacked renderer
195 appendSubDiagramRenderer( dr->clone() );
196 }
197
198 const QgsDiagramLayerSettings *dls = mLayer->diagramLayerSettings();
199 mModel->updateDiagramLayerSettings( *dls );
200 }
201}
202
204{
205 auto ds = std::make_unique<QgsDiagramSettings>();
206 ds->stackedDiagramMode = static_cast<QgsDiagramSettings::StackedDiagramMode>( mStackedDiagramModeComboBox->currentData().toInt() );
207 ds->setStackedDiagramSpacingUnit( mStackedDiagramSpacingUnitComboBox->unit() );
208 ds->setStackedDiagramSpacing( mStackedDiagramSpacingSpinBox->value() );
209
210 // Create diagram renderer for the StackedDiagram
212 dr->setDiagram( new QgsStackedDiagram() );
213
214 // Get DiagramSettings from each subdiagram
215 const QList<QgsDiagramRenderer *> renderers = mModel->subRenderers();
216 for ( const QgsDiagramRenderer *renderer : renderers )
217 {
218 const QList<QgsDiagramSettings> ds1 = renderer->diagramSettings();
219 if ( !ds1.isEmpty() )
220 {
221 ds->categoryAttributes += ds1.at( 0 ).categoryAttributes;
222 ds->categoryLabels += ds1.at( 0 ).categoryLabels;
223 ds->categoryColors += ds1.at( 0 ).categoryColors;
224 }
225 dr->addRenderer( renderer->clone() );
226 }
227
228 dr->setDiagramSettings( *ds );
229 mLayer->setDiagramRenderer( dr );
230
231 // Get DiagramLayerSettings from the model
233 mLayer->setDiagramLayerSettings( dls );
234
235 // refresh
237 mLayer->triggerRepaint();
238}
239
240bool QgsStackedDiagramProperties::couldBeFirstSubDiagram( const QModelIndex &index ) const
241{
242 if ( !index.isValid() )
243 return false;
244
245 if ( mModel->rowCount() == 1 )
246 return true;
247
248 // Is there any enabled subdiagram before our index.row()?
249 // If so, ours cannot be the first diagram.
250 const QList<QgsDiagramRenderer *> renderers = mModel->subRenderers();
251
252 for ( int i = 0; i < index.row(); i++ )
253 {
254 const QgsDiagramRenderer *renderer = renderers.at( i );
255 const QList<QgsDiagramSettings> ds = renderer->diagramSettings();
256 if ( !ds.isEmpty() && ds.at( 0 ).enabled )
257 {
258 // First enabled subdiagram found, and we know our row is after.
259 // Therefore, return false to disallow showing DLS settings for it.
260 return false;
261 }
262 }
263 // Either our row is the first subdiagram enabled or it's disabled,
264 // but there are no enabled ones before. So, ours could be the first
265 // enabled one after being edited.
266 // Therefore, we should allow DLS settings on its corresponding widget.
267 return true;
268}
269
270void QgsStackedDiagramProperties::subDiagramWidgetPanelAccepted( QgsPanelWidget *panel )
271{
272 QgsDiagramProperties *widget = qobject_cast<QgsDiagramProperties *>( panel );
273
274 std::unique_ptr<QgsDiagramRenderer> renderer = widget->createRenderer();
275
276 const QModelIndex index = mSubDiagramsView->selectionModel()->currentIndex();
278 mModel->updateDiagramLayerSettings( widget->createDiagramLayerSettings() );
279
280 mModel->updateSubDiagram( index, renderer.release() );
281}
282
283void QgsStackedDiagramProperties::liveUpdateSubDiagramFromPanel()
284{
285 subDiagramWidgetPanelAccepted( qobject_cast<QgsPanelWidget *>( sender() ) );
286}
287
289
290#include "qgsvscrollarea.h"
291
293 : QDialog( parent )
294{
295#ifdef Q_OS_MAC
296 setWindowModality( Qt::WindowModal );
297#endif
298
299 QVBoxLayout *layout = new QVBoxLayout( this );
300 QgsVScrollArea *scrollArea = new QgsVScrollArea( this );
301 scrollArea->setFrameShape( QFrame::NoFrame );
302 layout->addWidget( scrollArea );
303
304 buttonBox = new QDialogButtonBox( QDialogButtonBox::Cancel | QDialogButtonBox::Help | QDialogButtonBox::Ok );
305 mPropsWidget = new QgsDiagramProperties( layer, this, mapCanvas );
306 mPropsWidget->setDockMode( false );
307
308 scrollArea->setWidget( mPropsWidget );
309 layout->addWidget( buttonBox );
310 this->setWindowTitle( "Edit Sub Diagram" );
312
313 connect( buttonBox, &QDialogButtonBox::accepted, this, &QgsStackedDiagramPropertiesDialog::accept );
314 connect( buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject );
315 connect( buttonBox, &QDialogButtonBox::helpRequested, this, &QgsStackedDiagramPropertiesDialog::showHelp );
316}
317
319{
320 mPropsWidget->syncToRenderer( dr );
321}
322
324{
325 mPropsWidget->syncToSettings( dls );
326}
327
329{
330 // Get renderer and diagram layer settings from widget
331 mRenderer = mPropsWidget->createRenderer();
332 mDiagramLayerSettings = mPropsWidget->createDiagramLayerSettings();
333 QDialog::accept();
334}
335
337{
338 return mRenderer.release();
339}
340
345
350
355
356void QgsStackedDiagramPropertiesDialog::showHelp()
357{
358 QgsHelp::openHelp( QStringLiteral( "working_with_vector/vector_properties.html#diagrams-properties" ) );
359}
360
362
364 : QAbstractTableModel( parent )
365{
366}
367
372
373Qt::ItemFlags QgsStackedDiagramPropertiesModel::flags( const QModelIndex &index ) const
374{
375 const Qt::ItemFlag checkable = ( index.column() == 0 ? Qt::ItemIsUserCheckable : Qt::NoItemFlags );
376
377 // allow drop only at first column
378 const Qt::ItemFlag drop = ( index.column() == 0 ? Qt::ItemIsDropEnabled : Qt::NoItemFlags );
379
380 return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | drop | checkable;
381}
382
384{
385 return Qt::MoveAction; // | Qt::CopyAction
386}
387
389{
390 QStringList types;
391 types << QStringLiteral( "application/vnd.text.list" );
392 return types;
393}
394
395QMimeData *QgsStackedDiagramPropertiesModel::mimeData( const QModelIndexList &indexes ) const
396{
397 QMimeData *mimeData = new QMimeData();
398 QByteArray encodedData;
399
400 QDataStream stream( &encodedData, QIODevice::WriteOnly );
401
402 for ( const QModelIndex &index : indexes )
403 {
404 // each item consists of several columns - let's add it with just first one
405 if ( !index.isValid() || index.column() != 0 )
406 continue;
407
408 if ( QgsDiagramRenderer *diagram = mRenderers.at( index.row() ) )
409 {
410 QDomDocument doc;
411
412 QDomElement rootElem = doc.createElement( QStringLiteral( "diagram_mime" ) );
413 diagram->writeXml( rootElem, doc, QgsReadWriteContext() );
414 doc.appendChild( rootElem );
415 stream << doc.toString( -1 );
416 }
417 }
418
419 mimeData->setData( QStringLiteral( "application/vnd.text.list" ), encodedData );
420 return mimeData;
421}
422
423bool QgsStackedDiagramPropertiesModel::dropMimeData( const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent )
424{
425 Q_UNUSED( column )
426
427 if ( action == Qt::IgnoreAction )
428 return true;
429
430 if ( !data->hasFormat( QStringLiteral( "application/vnd.text.list" ) ) )
431 return false;
432
433 if ( parent.column() > 0 )
434 return false;
435
436 QByteArray encodedData = data->data( QStringLiteral( "application/vnd.text.list" ) );
437 QDataStream stream( &encodedData, QIODevice::ReadOnly );
438 int rows = 0;
439
440 if ( row == -1 )
441 {
442 // the item was dropped at a parent - we may decide where to put the items - let's append them
443 row = rowCount( parent );
444 }
445
446 while ( !stream.atEnd() )
447 {
448 QString text;
449 stream >> text;
450
451 QDomDocument doc;
452 if ( !doc.setContent( text ) )
453 continue;
454 const QDomElement rootElem = doc.documentElement();
455 if ( rootElem.tagName() != QLatin1String( "diagram_mime" ) || !rootElem.hasChildNodes() )
456 continue;
457 const QDomElement childElem = rootElem.firstChild().toElement();
458
459 QgsDiagramRenderer *diagram = nullptr;
460 if ( childElem.nodeName() == QLatin1String( "SingleCategoryDiagramRenderer" ) )
461 {
462 diagram = new QgsSingleCategoryDiagramRenderer();
463 diagram->readXml( childElem, QgsReadWriteContext() );
464 }
465 else if ( childElem.nodeName() == QLatin1String( "LinearlyInterpolatedDiagramRenderer" ) )
466 {
468 diagram->readXml( childElem, QgsReadWriteContext() );
469 }
470 else if ( childElem.nodeName() == QLatin1String( "StackedDiagramRenderer" ) )
471 {
472 diagram = new QgsStackedDiagramRenderer();
473 diagram->readXml( childElem, QgsReadWriteContext() );
474 }
475
476 if ( diagram )
477 {
478 insertSubDiagram( row + rows, diagram );
479 rows++;
480 }
481 }
482
483 return true;
484}
485
486QVariant QgsStackedDiagramPropertiesModel::data( const QModelIndex &index, int role ) const
487{
488 if ( !index.isValid() )
489 return QVariant();
490
492
493 if ( role == Qt::DisplayRole || role == Qt::ToolTipRole )
494 {
495 switch ( index.column() )
496 {
497 case 0:
498 if ( dr && dr->diagram() )
499 {
501 {
502 return tr( "Pie Chart" );
503 }
505 {
506 return tr( "Text Diagram" );
507 }
509 {
510 return tr( "Histogram" );
511 }
513 {
514 return tr( "Stacked Bars" );
515 }
517 {
518 return tr( "Stacked Diagram" );
519 }
520 else
521 {
522 return dr->diagram()->diagramName();
523 }
524 }
525 else
526 {
527 return tr( "(no diagram)" );
528 }
529 case 1:
530 if ( !dr )
531 {
532 return tr( "(no renderer)" );
533 }
534 else
535 {
537 return tr( "Fixed" );
539 return tr( "Scaled" );
540 else
541 return tr( "Unknown" );
542 }
543 case 2:
544 if ( dr && dr->diagram() && !dr->diagramSettings().isEmpty() )
545 {
547 {
548 switch ( dr->diagramSettings().at( 0 ).diagramOrientation )
549 {
551 return tr( "Left" );
553 return tr( "Right" );
555 return tr( "Up" );
557 return tr( "Down" );
558 }
559 }
560 }
561 return QVariant();
562 default:
563 return QVariant();
564 }
565 }
566 else if ( role == Qt::CheckStateRole )
567 {
568 if ( index.column() != 0 )
569 return QVariant();
570
571 return ( dr && !dr->diagramSettings().isEmpty() && dr->diagramSettings().at( 0 ).enabled ) ? Qt::Checked : Qt::Unchecked;
572 }
573 else
574 {
575 return QVariant();
576 }
577}
578
579QVariant QgsStackedDiagramPropertiesModel::headerData( int section, Qt::Orientation orientation, int role ) const
580{
581 if ( orientation == Qt::Horizontal && role == Qt::DisplayRole && section >= 0 && section < 3 )
582 {
583 QStringList lst;
584 lst << tr( "Diagram type" ) << tr( "Size" ) << tr( "Orientation" );
585 return lst[section];
586 }
587
588 return QVariant();
589}
590
591int QgsStackedDiagramPropertiesModel::rowCount( const QModelIndex & ) const
592{
593 return mRenderers.size();
594}
595
596int QgsStackedDiagramPropertiesModel::columnCount( const QModelIndex & ) const
597{
598 return 3;
599}
600
601bool QgsStackedDiagramPropertiesModel::setData( const QModelIndex &index, const QVariant &value, int role )
602{
603 if ( !index.isValid() )
604 return false;
605
607
608 if ( role == Qt::CheckStateRole )
609 {
610 if ( dr && !dr->diagramSettings().isEmpty() )
611 {
612 QgsDiagramSettings ds = dr->diagramSettings().at( 0 );
613 ds.enabled = ( value.toInt() == Qt::Checked );
614
616 {
618 dsr->setDiagramSettings( ds );
619 }
620 else
621 {
623 dlir->setDiagramSettings( ds );
624 }
625
626 emit dataChanged( index, index );
627 return true;
628 }
629 }
630 return false;
631}
632
633bool QgsStackedDiagramPropertiesModel::removeRows( int row, int count, const QModelIndex &parent )
634{
635 if ( row < 0 || row >= mRenderers.size() )
636 return false;
637
638 beginRemoveRows( parent, row, row + count - 1 );
639 while ( count-- )
640 mRenderers.removeAt( row );
641 endRemoveRows();
642
643 return true;
644}
645
647{
648 if ( index.isValid() )
649 return mRenderers.at( index.row() );
650 return nullptr;
651}
652
654{
655 beginInsertRows( QModelIndex(), index, index );
656 mRenderers.insert( index, newSubDiagram );
657 endInsertRows();
658}
659
661{
662 if ( !index.isValid() )
663 return;
664
665 delete mRenderers.at( index.row() );
666 mRenderers.replace( index.row(), dr );
667 emit dataChanged( index, index );
668}
669
670QList<QgsDiagramRenderer *> QgsStackedDiagramPropertiesModel::subRenderers() const
671{
672 return mRenderers;
673}
674
679
@ Millimeters
Millimeters.
@ Points
Points (e.g., for font sizes)
@ MapUnits
Map units.
@ MetersInMapUnits
Meters value as Map units.
Stores the settings for rendering of all diagrams for a layer.
void syncToSettings(const QgsDiagramLayerSettings *dls)
Updates the widget to reflect the diagram layer settings.
void setDockMode(bool dockMode) override
Sets the widget in dock mode.
bool isAllowedToEditDiagramLayerSettings() const
Returns whether this widget is allowed to edit diagram layer settings.
void syncToRenderer(const QgsDiagramRenderer *dr)
Updates the widget to reflect the diagram renderer.
void setAllowedToEditDiagramLayerSettings(bool allowed)
Sets whether the widget should show diagram layer settings.
Evaluates and returns the diagram settings relating to a diagram for a specific feature.
virtual QString rendererName() const =0
QgsDiagram * diagram() const
virtual QList< QgsDiagramSettings > diagramSettings() const =0
Returns list with all diagram settings in the renderer.
virtual void readXml(const QDomElement &elem, const QgsReadWriteContext &context)=0
Reads diagram state from a DOM element.
void setDiagram(QgsDiagram *d)
virtual QgsDiagramRenderer * clone() const =0
Returns new instance that is equivalent to this one.
Stores the settings for rendering a single diagram.
StackedDiagramMode
Orientation of the stacked diagrams.
virtual QString diagramName() const =0
Gets a descriptive name for this diagram type.
static void enableAutoGeometryRestore(QWidget *widget, const QString &key=QString())
Register the widget to allow its position to be automatically saved and restored when open and closed...
Definition qgsgui.cpp:210
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
Definition qgshelp.cpp:39
static const QString DIAGRAM_NAME_HISTOGRAM
Alters the size of rendered diagrams using a linear scaling.
void setDiagramSettings(const QgsDiagramSettings &s)
static const QString DIAGRAM_RENDERER_NAME_LINEARLY_INTERPOLATED
Map canvas is a class for displaying all GIS data types on a canvas.
void triggerRepaint(bool deferredUpdate=false)
Will advise the map canvas (and any other interested party) that this layer requires to be repainted.
Base class for any widget that can be shown as a inline panel.
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 panelAccepted(QgsPanelWidget *panel)
Emitted when the panel is accepted by the user.
void widgetChanged()
Emitted when the widget state changes.
static QgsPanelWidget * findParentPanel(QWidget *widget)
Traces through the parents of a widget to find if it is contained within a QgsPanelWidget widget.
void setPanelTitle(const QString &panelTitle)
Set the title of the panel when shown in the interface.
bool dockMode()
Returns the dock mode state.
static const QString DIAGRAM_NAME_PIE
static QgsProject * instance()
Returns the QgsProject singleton instance.
void setDirty(bool b=true)
Flag the project as dirty (modified).
The class is used as a container of context for various read/write operations on other objects.
Renders the diagrams for all features with the same settings.
void setDiagramSettings(const QgsDiagramSettings &s)
static const QString DIAGRAM_RENDERER_NAME_SINGLE_CATEGORY
static const QString DIAGRAM_NAME_STACKED_BAR
QgsStackedDiagramPropertiesDialog(QgsVectorLayer *layer, QWidget *parent=nullptr, QgsMapCanvas *mapCanvas=nullptr)
Constructor for QgsStackedDiagramPropertiesDialog.
QgsDiagramLayerSettings diagramLayerSettings() const
Gets diagram layer settings built from the diagram properties widget.
void setAllowedToEditDiagramLayerSettings(bool allowed) const
Delegates to the main widget to set whether the widget should show diagram layer settings to be edite...
void syncToRenderer(const QgsDiagramRenderer *dr) const
Delegates to the diagram properties widget to sync with the given renderer.
void syncToSettings(const QgsDiagramLayerSettings *dls) const
Delegates to the diagram properties widget to sync with the given diagram layer settings.
bool isAllowedToEditDiagramLayerSettings() const
Returns whether the main widget is allowed to edit diagram layer settings.
void accept() override
Applies changes from the widget to the internal renderer and diagram layer settings.
QgsDiagramRenderer * renderer()
Gets a renderer object built from the diagram properties widget.
Model for sub diagrams in a stacked diagram view.
Qt::DropActions supportedDropActions() const override
QMimeData * mimeData(const QModelIndexList &indexes) const override
void updateSubDiagram(const QModelIndex &index, QgsDiagramRenderer *dr)
Replaces the diagram located at index by dr. Takes ownership.
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override
bool removeRows(int row, int count, const QModelIndex &parent=QModelIndex()) override
void insertSubDiagram(const int index, QgsDiagramRenderer *newSubDiagram)
Inserts a new diagram at the specified position. Takes ownership.
QList< QgsDiagramRenderer * > mRenderers
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
QgsDiagramRenderer * subDiagramForIndex(const QModelIndex &index) const
Returns the diagram renderer at the specified index. Does not transfer ownership.
void updateDiagramLayerSettings(QgsDiagramLayerSettings dls)
Sets the diagram layer settings for the model.
Qt::ItemFlags flags(const QModelIndex &index) const override
QgsDiagramLayerSettings diagramLayerSettings() const
Returns the diagram layer settings from the model.
QList< QgsDiagramRenderer * > subRenderers() const
Returns the list of diagram renderers from the model. Does not transfer ownership.
int columnCount(const QModelIndex &=QModelIndex()) const override
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
QgsStackedDiagramPropertiesModel(QObject *parent=nullptr)
constructor
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
int rowCount(const QModelIndex &=QModelIndex()) const override
void syncToLayer()
Updates the widget to reflect the layer's current diagram settings.
QgsStackedDiagramProperties(QgsVectorLayer *layer, QWidget *parent, QgsMapCanvas *canvas)
Renders diagrams using mixed diagram render types.
void setDiagramSettings(const QgsDiagramSettings &s)
static const QString DIAGRAM_RENDERER_NAME_STACKED
void addRenderer(QgsDiagramRenderer *renderer)
Adds a renderer to the stacked renderer object.
QList< QgsDiagramRenderer * > renderers(bool sortByDiagramMode=false) const
Returns an ordered list with the renderers of the stacked renderer object.
A diagram composed of several subdiagrams, located side by side.
static const QString DIAGRAM_NAME_STACKED
static const QString DIAGRAM_NAME_TEXT
void changed()
Emitted when the selected unit is changed, or the definition of the map unit scale is changed.
QgsVScrollArea is a QScrollArea subclass which only displays a vertical scrollbar and fits the width ...
Represents a vector layer which manages a vector based data sets.
const QgsDiagramLayerSettings * diagramLayerSettings() const
void setDiagramLayerSettings(const QgsDiagramLayerSettings &s)
void setDiagramRenderer(QgsDiagramRenderer *r)
Sets diagram rendering object (takes ownership)
const QgsDiagramRenderer * diagramRenderer() const