QGIS API Documentation 3.99.0-Master (09f76ad7019)
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
21
22#include <QString>
23
24#include "moc_qgslayoutchartseriesdetailswidget.cpp"
25
26using namespace Qt::StringLiterals;
27
29 : QgsPanelWidget( parent )
30 , mVectorLayer( layer )
31 , mIndex( index )
32{
33 setupUi( this );
34
35 if ( mVectorLayer )
36 {
37 mXExpressionWidget->setLayer( mVectorLayer.data() );
38 mYExpressionWidget->setLayer( mVectorLayer.data() );
39 }
40
41 mXExpressionWidget->setExpression( seriesDetails.xExpression() );
42 mYExpressionWidget->setExpression( seriesDetails.yExpression() );
43 mFilterLineEdit->setText( seriesDetails.filterExpression() );
44
45 connect( mXExpressionWidget, static_cast<void ( QgsFieldExpressionWidget::* )( const QString &, bool )>( &QgsFieldExpressionWidget::fieldChanged ), this, [this]( const QString &, bool ) { emit widgetChanged(); } );
46 connect( mYExpressionWidget, static_cast<void ( QgsFieldExpressionWidget::* )( const QString &, bool )>( &QgsFieldExpressionWidget::fieldChanged ), this, [this]( const QString &, bool ) { emit widgetChanged(); } );
47 connect( mFilterLineEdit, &QLineEdit::textChanged, this, [this] { emit widgetChanged(); } );
48 connect( mFilterButton, &QToolButton::clicked, this, &QgsLayoutChartSeriesDetailsWidget::mFilterButton_clicked );
49}
50
52{
53 return mIndex;
54}
55
57{
58 return mXExpressionWidget->asExpression();
59}
60
62{
63 return mYExpressionWidget->asExpression();
64}
65
67{
68 return mFilterLineEdit->text();
69}
70
71void QgsLayoutChartSeriesDetailsWidget::mFilterButton_clicked()
72{
73 if ( !mVectorLayer )
74 return;
75
76 const QgsExpressionContext context = mVectorLayer->createExpressionContext();
77 QgsExpressionBuilderDialog expressionBuilderDialog( mVectorLayer.data(), mFilterLineEdit->text(), this, u"generic"_s, context );
78 expressionBuilderDialog.setWindowTitle( tr( "Expression Based Filter" ) );
79
80 if ( expressionBuilderDialog.exec() == QDialog::Accepted )
81 {
82 const QString expression = expressionBuilderDialog.expressionText();
83 if ( !expression.isEmpty() )
84 {
85 mFilterLineEdit->setText( expression );
86 }
87 }
88}
A generic dialog for building expression strings.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
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.
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.