Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[gui] Fix enable/disable diagrams (as well as subdiagrams of a stacked diagram) #59098

Merged
merged 3 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion python/PyQt6/core/auto_generated/qgsdiagramrenderer.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -1040,7 +1040,7 @@ the left (horizontal mode) or more to the top (vertical mode).
%Docstring
Returns the renderer at the given ``index``.

:param index: index of the disired renderer in the stacked renderer
:param index: index of the desired renderer in the stacked renderer
%End

protected:
Expand Down
2 changes: 1 addition & 1 deletion python/core/auto_generated/qgsdiagramrenderer.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -1040,7 +1040,7 @@ the left (horizontal mode) or more to the top (vertical mode).
%Docstring
Returns the renderer at the given ``index``.

:param index: index of the disired renderer in the stacked renderer
:param index: index of the desired renderer in the stacked renderer
%End

protected:
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsdiagramrenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -1062,7 +1062,7 @@ class CORE_EXPORT QgsStackedDiagramRenderer : public QgsDiagramRenderer
/**
* Returns the renderer at the given \a index.
*
* \param index index of the disired renderer in the stacked renderer
* \param index index of the desired renderer in the stacked renderer
*/
const QgsDiagramRenderer *renderer( const int index ) const;

Expand Down
23 changes: 14 additions & 9 deletions src/gui/vector/qgsdiagramproperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ QgsDiagramProperties::QgsDiagramProperties( QgsVectorLayer *layer, QWidget *pare
widgets << mDiagramLineUnitComboBox;
widgets << mDiagramTypeComboBox;
widgets << mDiagramUnitComboBox;
widgets << mEnableDiagramCheckBox;
widgets << mFixedSizeRadio;
widgets << mIncreaseMinimumSizeSpinBox;
widgets << mIncreaseSmallDiagramsGroupBox;
Expand Down Expand Up @@ -453,8 +454,7 @@ void QgsDiagramProperties::syncToRenderer( const QgsDiagramRenderer *dr )
const QList<QgsDiagramSettings> settingList = dr->diagramSettings();
if ( !settingList.isEmpty() )
{
mOptionsTab->setEnabled( settingList.at( 0 ).enabled );
mDiagramFrame->setEnabled( settingList.at( 0 ).enabled );
setDiagramEnabled( settingList.at( 0 ).enabled );
mDiagramFontButton->setCurrentFont( settingList.at( 0 ).font );
const QSizeF size = settingList.at( 0 ).size;
mBackgroundColorButton->setColor( settingList.at( 0 ).backgroundColor );
Expand Down Expand Up @@ -651,8 +651,6 @@ void QgsDiagramProperties::updateProperty()

void QgsDiagramProperties::mDiagramTypeComboBox_currentIndexChanged( int index )
{
mDiagramFrame->setEnabled( true );

mDiagramType = mDiagramTypeComboBox->itemData( index ).toString();

if ( QgsTextDiagram::DIAGRAM_NAME_TEXT == mDiagramType )
Expand Down Expand Up @@ -880,7 +878,7 @@ std::unique_ptr< QgsDiagram > QgsDiagramProperties::createDiagramObject()
std::unique_ptr<QgsDiagramSettings> QgsDiagramProperties::createDiagramSettings()
{
std::unique_ptr< QgsDiagramSettings > ds = std::make_unique< QgsDiagramSettings>();
ds->enabled = ( mDiagramTypeComboBox->currentIndex() != -1 );
ds->enabled = isDiagramEnabled();
ds->font = mDiagramFontButton->currentFont();
ds->opacity = mOpacityWidget->opacity();

Expand Down Expand Up @@ -1044,14 +1042,11 @@ QgsDiagramLayerSettings QgsDiagramProperties::createDiagramLayerSettings()

void QgsDiagramProperties::apply()
{
const int index = mDiagramTypeComboBox->currentIndex();
const bool diagramsEnabled = ( index != -1 );

// Avoid this messageBox when in both dock and liveUpdate mode
QgsSettings settings;
if ( !dockMode() || !settings.value( QStringLiteral( "UI/autoApplyStyling" ), true ).toBool() )
{
if ( diagramsEnabled && 0 == mDiagramAttributesTreeWidget->topLevelItemCount() )
if ( isDiagramEnabled() && 0 == mDiagramAttributesTreeWidget->topLevelItemCount() )
{
QMessageBox::warning( this, tr( "Diagrams: No attributes added." ),
tr( "You did not add any attributes to this diagram layer. Please specify the attributes to visualize on the diagrams or disable diagrams." ) );
Expand Down Expand Up @@ -1324,3 +1319,13 @@ void QgsDiagramProperties::connectValueChanged( const QList<QWidget *> &widgets
}
}
}

void QgsDiagramProperties::setDiagramEnabled( bool enabled )
{
mEnableDiagramCheckBox->setChecked( enabled );
}

bool QgsDiagramProperties::isDiagramEnabled() const
{
return mEnableDiagramCheckBox->isChecked();
}
20 changes: 20 additions & 0 deletions src/gui/vector/qgsdiagramproperties.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,26 @@ class GUI_EXPORT QgsDiagramProperties : public QgsPanelWidget, private Ui::QgsDi
*/
void insertDefaults();

/**
* Sets widgets to reflect the \a enabled status of the diagram.
* \param enabled Whether the diagram is enabled or not.
*
* \see isDiagramEnabled()
*
* \since QGIS 3.40
*/
void setDiagramEnabled( const bool enabled );

/**
* Returns whether the current diagram should be enabled or not,
* according to changes in the corresponding widgets.
*
* \see setDiagramEnabled()
*
* \since QGIS 3.40
*/
bool isDiagramEnabled() const;

friend class QgsStackedDiagramProperties;
friend class QgsStackedDiagramPropertiesDialog;
};
Expand Down
11 changes: 10 additions & 1 deletion src/ui/qgsdiagrampropertiesbase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<height>491</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_8" stretch="0,0,1">
<layout class="QVBoxLayout" name="verticalLayout_8" stretch="0,0,0,1">
<property name="leftMargin">
<number>0</number>
</property>
Expand Down Expand Up @@ -51,6 +51,13 @@
</layout>
</widget>
</item>
<item>
<widget class="QCheckBox" name="mEnableDiagramCheckBox">
<property name="text">
<string>Enable diagram</string>
</property>
</widget>
</item>
<item>
<widget class="QTabWidget" name="mOptionsTab">
<property name="currentIndex">
Expand Down Expand Up @@ -2411,6 +2418,8 @@
</customwidgets>
<tabstops>
<tabstop>mDiagramTypeComboBox</tabstop>
<tabstop>mEnableDiagramCheckBox</tabstop>
<tabstop>mOptionsTab</tabstop>
<tabstop>mDiagramOptionsListWidget</tabstop>
<tabstop>scrollArea</tabstop>
<tabstop>mAttributesTreeWidget</tabstop>
Expand Down