35 , mMapCanvas( canvas )
43 connect( mSubDiagramsView, &QAbstractItemView::doubleClicked,
this,
static_cast<void (
QgsStackedDiagramProperties::* )(
const QModelIndex & )
>( &QgsStackedDiagramProperties::editSubDiagram ) );
45 connect( mAddSubDiagramButton, &QPushButton::clicked,
this, &QgsStackedDiagramProperties::addSubDiagram );
46 connect( mEditSubDiagramButton, &QAbstractButton::clicked,
this,
static_cast<void (
QgsStackedDiagramProperties::* )()
>( &QgsStackedDiagramProperties::editSubDiagram ) );
47 connect( mRemoveSubDiagramButton, &QPushButton::clicked,
this, &QgsStackedDiagramProperties::removeSubDiagram );
53 mStackedDiagramSpacingSpinBox->setClearValue( 0 );
66 mSubDiagramsView->setModel( mModel );
67 mSubDiagramsView->resizeColumnToContents( 0 );
76void QgsStackedDiagramProperties::addSubDiagram()
79 std::unique_ptr< QgsDiagramRenderer > renderer;
80 std::unique_ptr< QgsSingleCategoryDiagramRenderer > dr = std::make_unique< QgsSingleCategoryDiagramRenderer >();
81 renderer = std::move( dr );
83 QItemSelectionModel *sel = mSubDiagramsView->selectionModel();
84 const QModelIndex index = sel->currentIndex();
86 if ( index.isValid() )
89 const QModelIndex currentIndex = mSubDiagramsView->selectionModel()->currentIndex();
91 const QModelIndex newIndex = mModel->index( currentIndex.row() + 1, 0 );
92 mSubDiagramsView->selectionModel()->setCurrentIndex( newIndex, QItemSelectionModel::ClearAndSelect );
97 appendSubDiagram( renderer.release() );
104 const int rows = mModel->
rowCount();
106 const QModelIndex newIndex = mModel->index( rows, 0 );
107 mSubDiagramsView->selectionModel()->setCurrentIndex( newIndex, QItemSelectionModel::ClearAndSelect );
110void QgsStackedDiagramProperties::editSubDiagram()
112 editSubDiagram( mSubDiagramsView->selectionModel()->currentIndex() );
115void QgsStackedDiagramProperties::editSubDiagram(
const QModelIndex &index )
117 if ( !index.isValid() )
128 widget->layout()->setContentsMargins( 0, 0, 0, 0 );
131 if ( !couldBeFirstSubDiagram( index ) )
144 dlg.syncToRenderer( renderer );
145 dlg.syncToSettings( &dls );
146 if ( !couldBeFirstSubDiagram( index ) )
148 dlg.setAllowedToEditDiagramLayerSettings(
false );
153 const QModelIndex index = mSubDiagramsView->selectionModel()->currentIndex();
154 if ( dlg.isAllowedToEditDiagramLayerSettings() )
162void QgsStackedDiagramProperties::removeSubDiagram()
164 const QItemSelection sel = mSubDiagramsView->selectionModel()->selection();
165 const auto constSel = sel;
166 for (
const QItemSelectionRange &range : constSel )
168 if ( range.isValid() )
169 mModel->
removeRows( range.top(), range.bottom() - range.top() + 1, range.parent() );
172 mSubDiagramsView->selectionModel()->clear();
182 mStackedDiagramModeComboBox->setCurrentIndex( settingList.at( 0 ).stackedDiagramMode );
183 mStackedDiagramSpacingSpinBox->setValue( settingList.at( 0 ).stackedDiagramSpacing() );
184 mStackedDiagramSpacingUnitComboBox->setUnit( settingList.at( 0 ).stackedDiagramSpacingUnit() );
189 const auto renderers = stackedDiagramRenderer->
renderers();
190 for (
const auto &renderer : renderers )
192 appendSubDiagram( renderer );
198 appendSubDiagram( dr->
clone() );
208 std::unique_ptr< QgsDiagramSettings> ds = std::make_unique< QgsDiagramSettings >();
210 ds->setStackedDiagramSpacingUnit( mStackedDiagramSpacingUnitComboBox->unit() );
211 ds->setStackedDiagramSpacing( mStackedDiagramSpacingSpinBox->value() );
218 const QList< QgsDiagramRenderer *> renderers = mModel->
subRenderers();
219 for (
const auto &renderer : renderers )
222 if ( !ds1.isEmpty() )
224 ds->categoryAttributes += ds1.at( 0 ).categoryAttributes;
225 ds->categoryLabels += ds1.at( 0 ).categoryLabels;
226 ds->categoryColors += ds1.at( 0 ).categoryColors;
243bool QgsStackedDiagramProperties::couldBeFirstSubDiagram(
const QModelIndex &index )
const
245 if ( !index.isValid() )
253 const QList< QgsDiagramRenderer * > renderers = mModel->
subRenderers();
255 for (
int i = 0; i < index.row(); i++ )
257 const auto &renderer = renderers.at( i );
259 if ( !ds.isEmpty() && ds.at( 0 ).enabled )
273void QgsStackedDiagramProperties::subDiagramWidgetPanelAccepted(
QgsPanelWidget *panel )
277 std::unique_ptr< QgsDiagramRenderer > renderer = widget->createRenderer();
279 const QModelIndex index = mSubDiagramsView->selectionModel()->currentIndex();
286void QgsStackedDiagramProperties::liveUpdateSubDiagramFromPanel()
288 subDiagramWidgetPanelAccepted( qobject_cast<QgsPanelWidget *>( sender() ) );
300 setWindowModality( Qt::WindowModal );
303 QVBoxLayout *layout =
new QVBoxLayout(
this );
305 scrollArea->setFrameShape( QFrame::NoFrame );
306 layout->addWidget( scrollArea );
308 buttonBox =
new QDialogButtonBox( QDialogButtonBox::Cancel | QDialogButtonBox::Help | QDialogButtonBox::Ok );
312 scrollArea->setWidget( mPropsWidget );
313 layout->addWidget( buttonBox );
314 this->setWindowTitle(
"Edit Sub Diagram" );
318 connect( buttonBox, &QDialogButtonBox::rejected,
this, &QDialog::reject );
319 connect( buttonBox, &QDialogButtonBox::helpRequested,
this, &QgsStackedDiagramPropertiesDialog::showHelp );
335 mRenderer = mPropsWidget->createRenderer();
336 mDiagramLayerSettings = mPropsWidget->createDiagramLayerSettings();
342 return mRenderer.release();
347 return mDiagramLayerSettings;
360void QgsStackedDiagramPropertiesDialog::showHelp()
362 QgsHelp::openHelp( QStringLiteral(
"working_with_vector/vector_properties.html#diagrams-properties" ) );
368 : QAbstractTableModel( parent )
374 const Qt::ItemFlag checkable = ( index.column() == 0 ? Qt::ItemIsUserCheckable : Qt::NoItemFlags );
376 return Qt::ItemIsEnabled | Qt::ItemIsSelectable | checkable;
381 if ( !index.isValid() )
386 if ( role == Qt::DisplayRole || role == Qt::ToolTipRole )
388 switch ( index.column() )
395 return tr(
"(no renderer)" );
400 return tr(
"Fixed" );
402 return tr(
"Scaled" );
404 return tr(
"Unknown" );
416 return tr(
"Right" );
430 else if ( role == Qt::TextAlignmentRole )
432 return index.column() == 0 ?
static_cast<Qt::Alignment::Int
>( Qt::AlignCenter ) :
static_cast<Qt::Alignment::Int
>( Qt::AlignLeft );
434 else if ( role == Qt::CheckStateRole )
436 if ( index.column() != 0 )
449 if ( orientation == Qt::Horizontal && role == Qt::DisplayRole && section >= 0 && section < 4 )
452 lst << tr(
"Enabled" ) << tr(
"Diagram type" ) << tr(
"Size" ) << tr(
"Orientation" );
471 if ( !index.isValid() )
476 if ( role == Qt::CheckStateRole )
481 ds.
enabled = ( value.toInt() == Qt::Checked );
494 emit dataChanged( index, index );
506 beginRemoveRows( parent, row, row + count - 1 );
516 if ( index.isValid() )
523 beginInsertRows( QModelIndex(), index, index );
531 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 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.
QList< QgsDiagramRenderer * > mRenderers
void updateSubDiagram(const QModelIndex &index, QgsDiagramRenderer *dr)
Replaces the diagram located at index by dr.
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.
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.
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.
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.
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