QGIS API Documentation 3.99.0-Master (c22de0620c0)
Loading...
Searching...
No Matches
qgslayoutchartseriesdetailswidget.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgslayoutchartseriesdetailswidget.cpp
3 --------------------------
4 begin : August 2025
5 copyright : (C) 2025 by Mathieu
6 email : mathieu at opengis dot ch
7 ***************************************************************************/
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
19
22
23#include <QString>
24
25#include "moc_qgslayoutchartseriesdetailswidget.cpp"
26
27using namespace Qt::StringLiterals;
28
30 : QgsPanelWidget( parent )
31 , mVectorLayer( layer )
32 , mIndex( index )
33{
34 setupUi( this );
35
36 if ( mVectorLayer )
37 {
38 mXExpressionWidget->setLayer( mVectorLayer.data() );
39 mYExpressionWidget->setLayer( mVectorLayer.data() );
40 }
41
42 mXExpressionWidget->setExpression( seriesDetails.xExpression() );
43 mXExpressionWidget->registerExpressionContextGenerator( this );
44 mYExpressionWidget->setExpression( seriesDetails.yExpression() );
45 mYExpressionWidget->registerExpressionContextGenerator( this );
46 mFilterLineEdit->setText( seriesDetails.filterExpression() );
47
48 connect( mXExpressionWidget, static_cast<void ( QgsFieldExpressionWidget::* )( const QString &, bool )>( &QgsFieldExpressionWidget::fieldChanged ), this, [this]( const QString &, bool ) { emit widgetChanged(); } );
49 connect( mYExpressionWidget, static_cast<void ( QgsFieldExpressionWidget::* )( const QString &, bool )>( &QgsFieldExpressionWidget::fieldChanged ), this, [this]( const QString &, bool ) { emit widgetChanged(); } );
50 connect( mFilterLineEdit, &QLineEdit::textChanged, this, [this] { emit widgetChanged(); } );
51 connect( mFilterButton, &QToolButton::clicked, this, &QgsLayoutChartSeriesDetailsWidget::mFilterButton_clicked );
52}
53
55{
56 return mIndex;
57}
58
60{
61 return mXExpressionWidget->asExpression();
62}
63
65{
66 return mYExpressionWidget->asExpression();
67}
68
70{
71 return mFilterLineEdit->text();
72}
73
74void QgsLayoutChartSeriesDetailsWidget::mFilterButton_clicked()
75{
76 if ( !mVectorLayer )
77 return;
78
79 const QgsExpressionContext context = mVectorLayer->createExpressionContext();
80 QgsExpressionBuilderDialog expressionBuilderDialog( mVectorLayer.data(), mFilterLineEdit->text(), this, u"generic"_s, context );
81 expressionBuilderDialog.setExpressionContext( createExpressionContext() );
82 expressionBuilderDialog.setWindowTitle( tr( "Expression Based Filter" ) );
83
84 if ( expressionBuilderDialog.exec() == QDialog::Accepted )
85 {
86 const QString expression = expressionBuilderDialog.expressionText();
87 if ( !expression.isEmpty() )
88 {
89 mFilterLineEdit->setText( expression );
90 }
91 }
92}
93
95{
96 mExpressionContextGenerator = generator;
97}
98
100{
101 QgsExpressionContext context;
102 if ( mExpressionContextGenerator )
103 {
104 context = mExpressionContextGenerator->createExpressionContext();
105 }
106 else
107 {
109 }
110
111 return context;
112}
A generic dialog for building expression strings.
Abstract interface for generating an expression context.
static QgsExpressionContextScope * globalScope()
Creates a new scope which contains variables and functions relating to the global QGIS context.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
void appendScope(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
A widget for selection of layer fields or expression creation.
void fieldChanged(const QString &fieldName)
Emitted when the currently selected field changes.
QString yExpression() const
Returns the Y-axis expression.
QString filterExpression() const
Returns the filter expression.
QString xExpression() const
Returns the X-axis expression.
void registerExpressionContextGenerator(QgsExpressionContextGenerator *generator)
Register an expression context generator class that will be used to retrieve an expression context fo...
QgsExpressionContext createExpressionContext() const override
This method needs to be reimplemented in all classes which implement this interface and return an exp...
QgsLayoutChartSeriesDetailsWidget(QgsVectorLayer *layer, int index, const QgsLayoutItemChart::SeriesDetails &seriesDetails, QWidget *parent=nullptr)
Constructor for QgsLayoutChartSeriesDetailsWidget.
Chart series details covering all supported series types.
QString yExpression() const
Returns the expression used to generate Y-axis values.
QString filterExpression() const
Returns the filter expression used to generate a series against a subset of the source layer.
QString xExpression() const
Returns the expression used to generate X-axis values.
QgsPanelWidget(QWidget *parent=nullptr)
Base class for any widget that can be shown as an inline panel.
void widgetChanged()
Emitted when the widget state changes.
Represents a vector layer which manages a vector based dataset.