29#include "moc_qgsstackeddiagramproperties.cpp"
36 , mMapCanvas( canvas )
44 connect( mSubDiagramsView, &QAbstractItemView::doubleClicked,
this,
static_cast<void (
QgsStackedDiagramProperties::* )(
const QModelIndex & )
>( &QgsStackedDiagramProperties::editSubDiagramRenderer ) );
46 connect( mAddSubDiagramButton, &QPushButton::clicked,
this, &QgsStackedDiagramProperties::addSubDiagramRenderer );
47 connect( mEditSubDiagramButton, &QAbstractButton::clicked,
this,
static_cast<void (
QgsStackedDiagramProperties::* )()
>( &QgsStackedDiagramProperties::editSubDiagramRenderer ) );
48 connect( mRemoveSubDiagramButton, &QPushButton::clicked,
this, &QgsStackedDiagramProperties::removeSubDiagramRenderer );
54 mStackedDiagramSpacingSpinBox->setClearValue( 0 );
67 mSubDiagramsView->setModel( mModel );
68 mSubDiagramsView->resizeColumnToContents( 0 );
77void QgsStackedDiagramProperties::addSubDiagramRenderer()
80 std::unique_ptr< QgsDiagramRenderer > renderer;
81 std::unique_ptr< QgsSingleCategoryDiagramRenderer > dr = std::make_unique< QgsSingleCategoryDiagramRenderer >();
82 renderer = std::move( dr );
84 QItemSelectionModel *sel = mSubDiagramsView->selectionModel();
85 const QModelIndex index = sel->currentIndex();
87 if ( index.isValid() )
90 const QModelIndex currentIndex = mSubDiagramsView->selectionModel()->currentIndex();
92 const QModelIndex newIndex = mModel->index( currentIndex.row() + 1, 0 );
93 mSubDiagramsView->selectionModel()->setCurrentIndex( newIndex, QItemSelectionModel::ClearAndSelect );
98 appendSubDiagramRenderer( renderer.release() );
100 editSubDiagramRenderer();
105 const int rows = mModel->
rowCount();
107 const QModelIndex newIndex = mModel->index( rows, 0 );
108 mSubDiagramsView->selectionModel()->setCurrentIndex( newIndex, QItemSelectionModel::ClearAndSelect );
111void QgsStackedDiagramProperties::editSubDiagramRenderer()
113 editSubDiagramRenderer( mSubDiagramsView->selectionModel()->currentIndex() );
116void QgsStackedDiagramProperties::editSubDiagramRenderer(
const QModelIndex &index )
118 if ( !index.isValid() )
129 widget->layout()->setContentsMargins( 0, 0, 0, 0 );
132 if ( !couldBeFirstSubDiagram( index ) )
145 dlg.syncToRenderer( renderer );
146 dlg.syncToSettings( &dls );
147 if ( !couldBeFirstSubDiagram( index ) )
149 dlg.setAllowedToEditDiagramLayerSettings(
false );
154 const QModelIndex index = mSubDiagramsView->selectionModel()->currentIndex();
155 if ( dlg.isAllowedToEditDiagramLayerSettings() )
163void QgsStackedDiagramProperties::removeSubDiagramRenderer()
165 const QItemSelection sel = mSubDiagramsView->selectionModel()->selection();
166 const auto constSel = sel;
167 for (
const QItemSelectionRange &range : constSel )
169 if ( range.isValid() )
170 mModel->
removeRows( range.top(), range.bottom() - range.top() + 1, range.parent() );
173 mSubDiagramsView->selectionModel()->clear();
183 mStackedDiagramModeComboBox->setCurrentIndex( settingList.at( 0 ).stackedDiagramMode );
184 mStackedDiagramSpacingSpinBox->setValue( settingList.at( 0 ).stackedDiagramSpacing() );
185 mStackedDiagramSpacingUnitComboBox->setUnit( settingList.at( 0 ).stackedDiagramSpacingUnit() );
190 const QList< QgsDiagramRenderer * > renderers = stackedDiagramRenderer->
renderers();
193 appendSubDiagramRenderer( renderer->
clone() );
199 appendSubDiagramRenderer( dr->
clone() );
209 std::unique_ptr< QgsDiagramSettings> ds = std::make_unique< QgsDiagramSettings >();
211 ds->setStackedDiagramSpacingUnit( mStackedDiagramSpacingUnitComboBox->unit() );
212 ds->setStackedDiagramSpacing( mStackedDiagramSpacingSpinBox->value() );
219 const QList< QgsDiagramRenderer *> renderers = mModel->
subRenderers();
223 if ( !ds1.isEmpty() )
225 ds->categoryAttributes += ds1.at( 0 ).categoryAttributes;
226 ds->categoryLabels += ds1.at( 0 ).categoryLabels;
227 ds->categoryColors += ds1.at( 0 ).categoryColors;
244bool QgsStackedDiagramProperties::couldBeFirstSubDiagram(
const QModelIndex &index )
const
246 if ( !index.isValid() )
254 const QList< QgsDiagramRenderer * > renderers = mModel->
subRenderers();
256 for (
int i = 0; i < index.row(); i++ )
260 if ( !ds.isEmpty() && ds.at( 0 ).enabled )
274void QgsStackedDiagramProperties::subDiagramWidgetPanelAccepted(
QgsPanelWidget *panel )
278 std::unique_ptr< QgsDiagramRenderer > renderer = widget->createRenderer();
280 const QModelIndex index = mSubDiagramsView->selectionModel()->currentIndex();
287void QgsStackedDiagramProperties::liveUpdateSubDiagramFromPanel()
289 subDiagramWidgetPanelAccepted( qobject_cast<QgsPanelWidget *>( sender() ) );
301 setWindowModality( Qt::WindowModal );
304 QVBoxLayout *layout =
new QVBoxLayout(
this );
306 scrollArea->setFrameShape( QFrame::NoFrame );
307 layout->addWidget( scrollArea );
309 buttonBox =
new QDialogButtonBox( QDialogButtonBox::Cancel | QDialogButtonBox::Help | QDialogButtonBox::Ok );
313 scrollArea->setWidget( mPropsWidget );
314 layout->addWidget( buttonBox );
315 this->setWindowTitle(
"Edit Sub Diagram" );
319 connect( buttonBox, &QDialogButtonBox::rejected,
this, &QDialog::reject );
320 connect( buttonBox, &QDialogButtonBox::helpRequested,
this, &QgsStackedDiagramPropertiesDialog::showHelp );
336 mRenderer = mPropsWidget->createRenderer();
337 mDiagramLayerSettings = mPropsWidget->createDiagramLayerSettings();
343 return mRenderer.release();
348 return mDiagramLayerSettings;
361void QgsStackedDiagramPropertiesDialog::showHelp()
363 QgsHelp::openHelp( QStringLiteral(
"working_with_vector/vector_properties.html#diagrams-properties" ) );
369 : QAbstractTableModel( parent )
380 const Qt::ItemFlag checkable = ( index.column() == 0 ? Qt::ItemIsUserCheckable : Qt::NoItemFlags );
382 return Qt::ItemIsEnabled | Qt::ItemIsSelectable | checkable;
387 if ( !index.isValid() )
392 if ( role == Qt::DisplayRole || role == Qt::ToolTipRole )
394 switch ( index.column() )
401 return tr(
"Pie Chart" );
405 return tr(
"Text Diagram" );
409 return tr(
"Histogram" );
413 return tr(
"Stacked Bars" );
417 return tr(
"Stacked Diagram" );
426 return tr(
"(no diagram)" );
431 return tr(
"(no renderer)" );
436 return tr(
"Fixed" );
438 return tr(
"Scaled" );
440 return tr(
"Unknown" );
452 return tr(
"Right" );
466 else if ( role == Qt::TextAlignmentRole )
468 return index.column() == 0 ?
static_cast<Qt::Alignment::Int
>( Qt::AlignCenter ) :
static_cast<Qt::Alignment::Int
>( Qt::AlignLeft );
470 else if ( role == Qt::CheckStateRole )
472 if ( index.column() != 0 )
485 if ( orientation == Qt::Horizontal && role == Qt::DisplayRole && section >= 0 && section < 4 )
488 lst << tr(
"Enabled" ) << tr(
"Diagram type" ) << tr(
"Size" ) << tr(
"Orientation" );
507 if ( !index.isValid() )
512 if ( role == Qt::CheckStateRole )
517 ds.
enabled = ( value.toInt() == Qt::Checked );
530 emit dataChanged( index, index );
542 beginRemoveRows( parent, row, row + count - 1 );
552 if ( index.isValid() )
559 beginInsertRows( QModelIndex(), index, index );
566 if ( !index.isValid() )
571 emit dataChanged( index, index );
@ Millimeters
Millimeters.
@ Points
Points (e.g., for font sizes)
@ 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 auxiliaryFieldCreated()
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.
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...
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
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.
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).
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
Dialog for editing sub diagrams.
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.
~QgsStackedDiagramPropertiesModel() override
QList< QgsDiagramRenderer * > mRenderers
void updateSubDiagram(const QModelIndex &index, QgsDiagramRenderer *dr)
Replaces the diagram located at index by dr. Takes ownership.
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.
QgsDiagramLayerSettings mDiagramLayerSettings
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.
void auxiliaryFieldCreated()
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
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