Skip to content

Commit

Permalink
[gui] Introduce StackedDiagramProperties and use it as dialog and as …
Browse files Browse the repository at this point in the history
…vector properties page. For the moment, it works with single diagrams, hiding controls for stacked diagrams
  • Loading branch information
gacarrillor committed Aug 23, 2024
1 parent 77cdffe commit c56cd64
Show file tree
Hide file tree
Showing 20 changed files with 446 additions and 18 deletions.
4 changes: 3 additions & 1 deletion python/PyQt6/core/auto_additions/qgsdiagramrenderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
QgsDiagramLayerSettings.StartAngle.__doc__ = "Angle offset for pie diagram"
QgsDiagramLayerSettings.Property.__doc__ = "Data definable properties.\n\n" + '* ``BackgroundColor``: ' + QgsDiagramLayerSettings.Property.BackgroundColor.__doc__ + '\n' + '* ``StrokeColor``: ' + QgsDiagramLayerSettings.Property.StrokeColor.__doc__ + '\n' + '* ``StrokeWidth``: ' + QgsDiagramLayerSettings.Property.StrokeWidth.__doc__ + '\n' + '* ``PositionX``: ' + QgsDiagramLayerSettings.Property.PositionX.__doc__ + '\n' + '* ``PositionY``: ' + QgsDiagramLayerSettings.Property.PositionY.__doc__ + '\n' + '* ``Distance``: ' + QgsDiagramLayerSettings.Property.Distance.__doc__ + '\n' + '* ``Priority``: ' + QgsDiagramLayerSettings.Property.Priority.__doc__ + '\n' + '* ``ZIndex``: ' + QgsDiagramLayerSettings.Property.ZIndex.__doc__ + '\n' + '* ``IsObstacle``: ' + QgsDiagramLayerSettings.Property.IsObstacle.__doc__ + '\n' + '* ``Show``: ' + QgsDiagramLayerSettings.Property.Show.__doc__ + '\n' + '* ``AlwaysShow``: ' + QgsDiagramLayerSettings.Property.AlwaysShow.__doc__ + '\n' + '* ``StartAngle``: ' + QgsDiagramLayerSettings.Property.StartAngle.__doc__
# --
QgsDiagramLayerSettings.Single = QgsDiagramLayerSettings.DiagramType.Single
QgsDiagramLayerSettings.Stacked = QgsDiagramLayerSettings.DiagramType.Stacked
QgsDiagramSettings.Height = QgsDiagramSettings.LabelPlacementMethod.Height
QgsDiagramSettings.XHeight = QgsDiagramSettings.LabelPlacementMethod.XHeight
QgsDiagramSettings.Up = QgsDiagramSettings.DiagramOrientation.Up
Expand All @@ -67,4 +69,4 @@
QgsDiagramInterpolationSettings.__attribute_docs__ = {'classificationField': 'Name of the field for classification'}
except NameError:
pass
QgsDiagramRenderer.dpiPaintDevice = staticmethod(QgsDiagramRenderer.dpiPaintDevice
QgsDiagramRenderer.dpiPaintDevice = staticmethod(QgsDiagramRenderer.dpiPaintDevice)
9 changes: 9 additions & 0 deletions python/PyQt6/core/auto_additions/qgsstackeddiagram.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# The following has been generated automatically from src/core/diagram/qgsstackeddiagram.h
try:
QgsStackedDiagram.__group__ = ['diagram']
except NameError:
pass
try:
QgsStackedDiagram.DiagramData.__group__ = ['diagram']
except NameError:
pass
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* *
* src/core/diagram/qgsstackeddiagram.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
* Do not edit manually ! Edit header and run scripts/sipify.py again *
************************************************************************/


Expand Down Expand Up @@ -88,5 +88,5 @@ Calculates the position for the next subdiagram, updating the ``newPos`` object.
* *
* src/core/diagram/qgsstackeddiagram.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
* Do not edit manually ! Edit header and run scripts/sipify.py again *
************************************************************************/
6 changes: 6 additions & 0 deletions python/PyQt6/core/auto_generated/qgsdiagramrenderer.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ Stores the settings for rendering of all diagrams for a layer.
StartAngle,
};

enum DiagramType /BaseType=IntEnum/
{
Single,
Stacked
};

static const QgsPropertiesDefinition &propertyDefinitions();
%Docstring
Returns the diagram property definitions.
Expand Down
9 changes: 9 additions & 0 deletions python/core/auto_additions/qgsstackeddiagram.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# The following has been generated automatically from src/core/diagram/qgsstackeddiagram.h
try:
QgsStackedDiagram.__group__ = ['diagram']
except NameError:
pass
try:
QgsStackedDiagram.DiagramData.__group__ = ['diagram']
except NameError:
pass
4 changes: 2 additions & 2 deletions python/core/auto_generated/diagram/qgsstackeddiagram.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* *
* src/core/diagram/qgsstackeddiagram.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
* Do not edit manually ! Edit header and run scripts/sipify.py again *
************************************************************************/


Expand Down Expand Up @@ -88,5 +88,5 @@ Calculates the position for the next subdiagram, updating the ``newPos`` object.
* *
* src/core/diagram/qgsstackeddiagram.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
* Do not edit manually ! Edit header and run scripts/sipify.py again *
************************************************************************/
6 changes: 6 additions & 0 deletions python/core/auto_generated/qgsdiagramrenderer.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ Stores the settings for rendering of all diagrams for a layer.
StartAngle,
};

enum DiagramType
{
Single,
Stacked
};

static const QgsPropertiesDefinition &propertyDefinitions();
%Docstring
Returns the diagram property definitions.
Expand Down
1 change: 1 addition & 0 deletions scripts/old_sipify.pl
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@
"QgsDataSourceUri::SslMode",
"QgsDiagramLayerSettings::LinePlacementFlag",
"QgsDiagramLayerSettings::Placement",
"QgsDiagramLayerSettings::DiagramType",
"QgsDiagramSettings::DiagramOrientation",
"QgsDiagramSettings::Direction",
"QgsDiagramSettings::LabelPlacementMethod",
Expand Down
2 changes: 2 additions & 0 deletions scripts/sipify.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,11 @@ def current_fully_qualified_struct_name(self) -> str:
"QgsDataSourceUri::SslMode",
"QgsDiagramLayerSettings::LinePlacementFlag",
"QgsDiagramLayerSettings::Placement",
"QgsDiagramLayerSettings::DiagramType",
"QgsDiagramSettings::DiagramOrientation",
"QgsDiagramSettings::Direction",
"QgsDiagramSettings::LabelPlacementMethod",
"QgsDiagramSettings::StackedDiagramMode",
"QgsDoubleSpinBox::ClearValueMode",
"QgsDualView::FeatureListBrowsingAction",
"QgsDualView::ViewMode",
Expand Down
6 changes: 3 additions & 3 deletions src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,6 @@
#include "qgsgpstoolbar.h"
#include "qgsgpscanvasbridge.h"
#include "qgsguivectorlayertools.h"
#include "qgsdiagramproperties.h"
#include "qgslayerdefinition.h"
#include "qgslayertree.h"
#include "qgslayertreefiltersettings.h"
Expand Down Expand Up @@ -383,6 +382,7 @@
#include "qgselevationshadingrenderersettingswidget.h"
#include "qgsshortcutsmanager.h"
#include "qgssnappingwidget.h"
#include "qgsstackeddiagramproperties.h"
#include "qgsstatisticalsummarydockwidget.h"
#include "qgsstatusbar.h"
#include "qgsstatusbarcoordinateswidget.h"
Expand Down Expand Up @@ -8064,7 +8064,7 @@ void QgisApp::diagramProperties()

QDialog dlg;
dlg.setWindowTitle( tr( "Layer Diagram Properties" ) );
QgsDiagramProperties *gui = new QgsDiagramProperties( vlayer, &dlg, mMapCanvas );
QgsStackedDiagramProperties *gui = new QgsStackedDiagramProperties( vlayer, &dlg, mMapCanvas );
gui->layout()->setContentsMargins( 0, 0, 0, 0 );
QVBoxLayout *layout = new QVBoxLayout( &dlg );
layout->addWidget( gui );
Expand All @@ -8081,7 +8081,7 @@ void QgisApp::diagramProperties()
connect( buttonBox->button( QDialogButtonBox::Cancel ), &QAbstractButton::clicked,
&dlg, &QDialog::reject );
connect( buttonBox->button( QDialogButtonBox::Apply ), &QAbstractButton::clicked,
gui, &QgsDiagramProperties::apply );
gui, &QgsStackedDiagramProperties::apply );
connect( buttonBox->button( QDialogButtonBox::Help ), &QAbstractButton::clicked, gui, [ = ]
{
QgsHelp::openHelp( QStringLiteral( "working_with_vector/vector_properties.html#diagrams-properties" ) );
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgisapp.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class QgsDataItem;
class QgsTileScaleWidget;
class QgsLabelingWidget;
class QgsLayerStylingWidget;
class QgsDiagramProperties;
class QgsStackedDiagramProperties;
class QgsLocatorWidget;
class QgsNominatimGeocoder;
class QgsDataSourceManagerDialog;
Expand Down
2 changes: 0 additions & 2 deletions src/core/diagram/qgsstackeddiagram.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@

#define DIAGRAM_NAME_STACKED "Stacked"

//#include "qgis_core.h"
//#include "qgis.h"
#include "qgsdiagram.h"
#include <QPen>
#include <QBrush>
Expand Down
10 changes: 10 additions & 0 deletions src/core/qgsdiagramrenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,16 @@ class CORE_EXPORT QgsDiagramLayerSettings
};
// *INDENT-ON*

/**
* Diagram type
* \since QGIS 3.40
*/
enum DiagramType
{
Single,
Stacked
};

/**
* Returns the diagram property definitions.
*/
Expand Down
3 changes: 3 additions & 0 deletions src/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ set(QGIS_GUI_SRCS
vector/qgsfieldcalculator.cpp
vector/qgsjoindialog.cpp
vector/qgssourcefieldsproperties.cpp
vector/qgsstackeddiagramproperties.cpp
vector/qgsvectorlayerlegendwidget.cpp
vector/qgsvectorlayerproperties.cpp
vector/qgswmsdimensiondialog.cpp
Expand Down Expand Up @@ -1493,6 +1494,7 @@ set(QGIS_GUI_HDRS
vector/qgsfieldcalculator.h
vector/qgsjoindialog.h
vector/qgssourcefieldsproperties.h
vector/qgsstackeddiagramproperties.h
vector/qgsvectorlayerlegendwidget.h
vector/qgsvectorlayerproperties.h
vector/qgswmsdimensiondialog.h
Expand Down Expand Up @@ -1643,6 +1645,7 @@ endif()

add_library(qgis_gui ${LIBRARY_TYPE}
${QGIS_GUI_SRCS} ${QGIS_GUI_HDRS} ${QGIS_GUI_PRIVATE_HDRS}
vector/qgsstackeddiagramproperties.h vector/qgsstackeddiagramproperties.cpp
)

# require c++17
Expand Down
88 changes: 88 additions & 0 deletions src/gui/vector/qgsstackeddiagramproperties.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/***************************************************************************
qgsstackeddiagramproperties.h
Properties for stacked diagram layers
-------------------
begin : August 2024
copyright : (C) Germán Carrillo
email : german at opengis dot ch
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "qgsstackeddiagramproperties.h"
#include "qgsdiagramproperties.h"


QgsStackedDiagramProperties::QgsStackedDiagramProperties( QgsVectorLayer *layer, QWidget *parent, QgsMapCanvas *canvas )
: QWidget{parent}
, mMapCanvas( canvas )
{
mLayer = layer;
if ( !layer )
{
return;
}

setupUi( this );
connect( mDiagramTypeComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsStackedDiagramProperties::mDiagramTypeComboBox_currentIndexChanged );

// Initialize stacked diagram controls
mDiagramTypeComboBox->addItem( tr( "Single diagram" ), QgsDiagramLayerSettings::Single );
mDiagramTypeComboBox->addItem( tr( "Stacked diagrams" ), QgsDiagramLayerSettings::Stacked );
mStackedDiagramModeComboBox->addItem( tr( "Horizontal" ), QgsDiagramSettings::Horizontal );
mStackedDiagramModeComboBox->addItem( tr( "Vertical" ), QgsDiagramSettings::Vertical );

mStackedDiagramSpacingSpinBox->setClearValue( 0 );
mStackedDiagramSpacingUnitComboBox->setUnits( { Qgis::RenderUnit::Millimeters,
Qgis::RenderUnit::MetersInMapUnits,
Qgis::RenderUnit::MapUnits,
Qgis::RenderUnit::Pixels,
Qgis::RenderUnit::Points,
Qgis::RenderUnit::Inches } );

// Add default subdiagram tab
gui = new QgsDiagramProperties( layer, this, mMapCanvas );
gui->layout()->setContentsMargins( 0, 0, 0, 0 );
QVBoxLayout *vLayout = new QVBoxLayout();
vLayout->addWidget( gui );
QWidget *w = new QWidget();
w->setLayout( vLayout );

connect( gui, &QgsDiagramProperties::auxiliaryFieldCreated, this, &QgsStackedDiagramProperties::auxiliaryFieldCreated );

mSubDiagramsTabWidget->addTab( w, tr( "Diagram 1" ) );
}

void QgsStackedDiagramProperties::apply()
{
if ( mDiagramTypeComboBox->currentData( Qt::UserRole ) == QgsDiagramLayerSettings::Single )
{
gui->apply();
}
}

void QgsStackedDiagramProperties::syncToLayer()
{
if ( mDiagramTypeComboBox->currentData( Qt::UserRole ) == QgsDiagramLayerSettings::Single )
{
gui->syncToLayer();
}
}

void QgsStackedDiagramProperties::mDiagramTypeComboBox_currentIndexChanged( int index )
{
if ( index == 0 )
{
mStackedDiagramSettingsFrame->hide();
}
else
{
mStackedDiagramSettingsFrame->show();
}
}
67 changes: 67 additions & 0 deletions src/gui/vector/qgsstackeddiagramproperties.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/***************************************************************************
qgsstackeddiagramproperties.h
Properties for stacked diagram layers
-------------------
begin : August 2024
copyright : (C) Germán Carrillo
email : german at opengis dot ch
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#ifndef QGSSTACKEDDIAGRAMPROPERTIES_H
#define QGSSTACKEDDIAGRAMPROPERTIES_H

// We don't want to expose this in the public API
#define SIP_NO_FILE

#include "qgis_gui.h"
#include "ui_qgsstackeddiagrampropertiesbase.h"

#include <QWidget>
#include <QDialog>

class QgsVectorLayer;
class QgsMapCanvas;
class QgsDiagramProperties;


/**
* \ingroup gui
* \class QgsStackedDiagramProperties
*
* \since QGIS 3.40
*/
class GUI_EXPORT QgsStackedDiagramProperties : public QWidget, private Ui::QgsStackedDiagramPropertiesBase
{
Q_OBJECT

public:
explicit QgsStackedDiagramProperties( QgsVectorLayer *layer, QWidget *parent, QgsMapCanvas *canvas );

/**
* Updates the widget to reflect the layer's current diagram settings.
*/
void syncToLayer();

signals:
void auxiliaryFieldCreated();

public slots:
void apply();
void mDiagramTypeComboBox_currentIndexChanged( int index );

private:
QgsVectorLayer *mLayer = nullptr;
QgsMapCanvas *mMapCanvas = nullptr;
QgsDiagramProperties *gui = nullptr;

};

#endif // QGSSTACKEDDIAGRAMPROPERTIES_H
6 changes: 3 additions & 3 deletions src/gui/vector/qgsvectorlayerproperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include "qgsapplication.h"
#include "qgsattributeactiondialog.h"
#include "qgsdatumtransformdialog.h"
#include "qgsdiagramproperties.h"
#include "qgsstackeddiagramproperties.h"
#include "qgssourcefieldsproperties.h"
#include "qgsattributesformproperties.h"
#include "qgslabelingwidget.h"
Expand Down Expand Up @@ -335,9 +335,9 @@ QgsVectorLayerProperties::QgsVectorLayerProperties(

QVBoxLayout *diagLayout = new QVBoxLayout( mDiagramFrame );
diagLayout->setContentsMargins( 0, 0, 0, 0 );
diagramPropertiesDialog = new QgsDiagramProperties( mLayer, mDiagramFrame, mCanvas );
diagramPropertiesDialog = new QgsStackedDiagramProperties( mLayer, mDiagramFrame, mCanvas );
diagramPropertiesDialog->layout()->setContentsMargins( 0, 0, 0, 0 );
connect( diagramPropertiesDialog, &QgsDiagramProperties::auxiliaryFieldCreated, this, [ = ] { updateAuxiliaryStoragePage(); } );
connect( diagramPropertiesDialog, &QgsStackedDiagramProperties::auxiliaryFieldCreated, this, [ = ] { updateAuxiliaryStoragePage(); } );
diagLayout->addWidget( diagramPropertiesDialog );
mDiagramFrame->setLayout( diagLayout );

Expand Down
Loading

0 comments on commit c56cd64

Please sign in to comment.