QGIS API Documentation 3.99.0-Master (21b3aa880ba)
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 "moc_qgslayoutchartseriesdetailswidget.cpp"
23
25 : QgsPanelWidget( parent )
26 , mVectorLayer( layer )
27 , mIndex( index )
28{
29 setupUi( this );
30
31 if ( mVectorLayer )
32 {
33 mXExpressionWidget->setLayer( mVectorLayer.data() );
34 mYExpressionWidget->setLayer( mVectorLayer.data() );
35 }
36
37 mXExpressionWidget->setExpression( seriesDetails.xExpression() );
38 mYExpressionWidget->setExpression( seriesDetails.yExpression() );
39 mFilterLineEdit->setText( seriesDetails.filterExpression() );
40
41 connect( mXExpressionWidget, static_cast<void ( QgsFieldExpressionWidget::* )( const QString &, bool )>( &QgsFieldExpressionWidget::fieldChanged ), this, [this]( const QString &, bool ) { emit widgetChanged(); } );
42 connect( mYExpressionWidget, static_cast<void ( QgsFieldExpressionWidget::* )( const QString &, bool )>( &QgsFieldExpressionWidget::fieldChanged ), this, [this]( const QString &, bool ) { emit widgetChanged(); } );
43 connect( mFilterLineEdit, &QLineEdit::textChanged, this, [this] { emit widgetChanged(); } );
44 connect( mFilterButton, &QToolButton::clicked, this, &QgsLayoutChartSeriesDetailsWidget::mFilterButton_clicked );
45}
46
48{
49 return mIndex;
50}
51
53{
54 return mXExpressionWidget->asExpression();
55}
56
58{
59 return mYExpressionWidget->asExpression();
60}
61
63{
64 return mFilterLineEdit->text();
65}
66
67void QgsLayoutChartSeriesDetailsWidget::mFilterButton_clicked()
68{
69 if ( !mVectorLayer )
70 return;
71
72 const QgsExpressionContext context = mVectorLayer->createExpressionContext();
73 QgsExpressionBuilderDialog expressionBuilderDialog( mVectorLayer.data(), mFilterLineEdit->text(), this, QStringLiteral( "generic" ), context );
74 expressionBuilderDialog.setWindowTitle( tr( "Expression Based Filter" ) );
75
76 if ( expressionBuilderDialog.exec() == QDialog::Accepted )
77 {
78 const QString expression = expressionBuilderDialog.expressionText();
79 if ( !expression.isEmpty() )
80 {
81 mFilterLineEdit->setText( expression );
82 }
83 }
84}
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.