26#include <QListWidgetItem>
30QgsProcessingRasterCalculatorExpressionLineEdit::QgsProcessingRasterCalculatorExpressionLineEdit( QWidget *parent )
34 mLineEdit->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum );
36 mButton =
new QToolButton();
37 mButton->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
39 connect( mButton, &QAbstractButton::clicked,
this, &QgsProcessingRasterCalculatorExpressionLineEdit::editExpression );
41 QHBoxLayout *layout =
new QHBoxLayout();
42 layout->setContentsMargins( 0, 0, 0, 0 );
43 layout->addWidget( mLineEdit );
44 layout->addWidget( mButton );
47 setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum );
48 setFocusProxy( mLineEdit );
49 connect( mLineEdit, &QLineEdit::textChanged,
this,
static_cast < void ( QgsProcessingRasterCalculatorExpressionLineEdit::* )(
const QString & )
> ( &QgsProcessingRasterCalculatorExpressionLineEdit::expressionEdited ) );
51 setExpression( expression() );
54QgsProcessingRasterCalculatorExpressionLineEdit::~QgsProcessingRasterCalculatorExpressionLineEdit() =
default;
56void QgsProcessingRasterCalculatorExpressionLineEdit::setLayers(
const QVariantList &layers )
61QString QgsProcessingRasterCalculatorExpressionLineEdit::expression()
const
64 return mLineEdit->text();
69void QgsProcessingRasterCalculatorExpressionLineEdit::setExpression(
const QString &newExpression )
72 mLineEdit->setText( newExpression );
75void QgsProcessingRasterCalculatorExpressionLineEdit::editExpression()
77 const QString currentExpression = expression();
78 QgsProcessingRasterCalculatorExpressionDialog dlg( mLayers );
79 dlg.setExpression( currentExpression );
83 const QString newExpression = dlg.expression();
84 setExpression( newExpression );
88void QgsProcessingRasterCalculatorExpressionLineEdit::expressionEdited()
90 emit expressionChanged( expression() );
93void QgsProcessingRasterCalculatorExpressionLineEdit::expressionEdited(
const QString &expression )
95 emit expressionChanged( expression );
99QgsProcessingRasterCalculatorExpressionDialog::QgsProcessingRasterCalculatorExpressionDialog(
const QVariantList &layers,
const QString &startExpression, QWidget *parent )
102 , mInitialText( startExpression )
109 connect( mLayersList, &QListWidget::itemDoubleClicked,
this, &QgsProcessingRasterCalculatorExpressionDialog::mLayersList_itemDoubleClicked );
111 connect( mBtnPlus, &QPushButton::clicked,
this, &QgsProcessingRasterCalculatorExpressionDialog::mBtnPlus_clicked );
112 connect( mBtnMinus, &QPushButton::clicked,
this, &QgsProcessingRasterCalculatorExpressionDialog::mBtnMinus_clicked );
113 connect( mBtnMultiply, &QPushButton::clicked,
this, &QgsProcessingRasterCalculatorExpressionDialog::mBtnMultiply_clicked );
114 connect( mBtnDivide, &QPushButton::clicked,
this, &QgsProcessingRasterCalculatorExpressionDialog::mBtnDivide_clicked );
115 connect( mBtnPower, &QPushButton::clicked,
this, &QgsProcessingRasterCalculatorExpressionDialog::mBtnPower_clicked );
116 connect( mBtnSqrt, &QPushButton::clicked,
this, &QgsProcessingRasterCalculatorExpressionDialog::mBtnSqrt_clicked );
117 connect( mBtnOpenBracket, &QPushButton::clicked,
this, &QgsProcessingRasterCalculatorExpressionDialog::mBtnOpenBracket_clicked );
118 connect( mBtnCloseBracket, &QPushButton::clicked,
this, &QgsProcessingRasterCalculatorExpressionDialog::mBtnCloseBracket_clicked );
119 connect( mBtnGreater, &QPushButton::clicked,
this, &QgsProcessingRasterCalculatorExpressionDialog::mBtnGreater_clicked );
120 connect( mBtnGreaterEqual, &QPushButton::clicked,
this, &QgsProcessingRasterCalculatorExpressionDialog::mBtnGreaterEqual_clicked );
121 connect( mBtnLess, &QPushButton::clicked,
this, &QgsProcessingRasterCalculatorExpressionDialog::mBtnLess_clicked );
122 connect( mBtnLessEqual, &QPushButton::clicked,
this, &QgsProcessingRasterCalculatorExpressionDialog::mBtnLessEqual_clicked );
123 connect( mBtnEqual, &QPushButton::clicked,
this, &QgsProcessingRasterCalculatorExpressionDialog::mBtnEqual_clicked );
124 connect( mBtnNotEqual, &QPushButton::clicked,
this, &QgsProcessingRasterCalculatorExpressionDialog::mBtnNotEqual_clicked );
125 connect( mBtnAnd, &QPushButton::clicked,
this, &QgsProcessingRasterCalculatorExpressionDialog::mBtnAnd_clicked );
126 connect( mBtnOr, &QPushButton::clicked,
this, &QgsProcessingRasterCalculatorExpressionDialog::mBtnOr_clicked );
127 connect( mBtnIf, &QPushButton::clicked,
this, &QgsProcessingRasterCalculatorExpressionDialog::mBtnIf_clicked );
128 connect( mBtnMin, &QPushButton::clicked,
this, &QgsProcessingRasterCalculatorExpressionDialog::mBtnMin_clicked );
129 connect( mBtnMax, &QPushButton::clicked,
this, &QgsProcessingRasterCalculatorExpressionDialog::mBtnMax_clicked );
130 connect( mBtnAbs, &QPushButton::clicked,
this, &QgsProcessingRasterCalculatorExpressionDialog::mBtnAbs_clicked );
131 connect( mBtnSin, &QPushButton::clicked,
this, &QgsProcessingRasterCalculatorExpressionDialog::mBtnSin_clicked );
132 connect( mBtnCos, &QPushButton::clicked,
this, &QgsProcessingRasterCalculatorExpressionDialog::mBtnCos_clicked );
133 connect( mBtnTan, &QPushButton::clicked,
this, &QgsProcessingRasterCalculatorExpressionDialog::mBtnTan_clicked );
134 connect( mBtnLog, &QPushButton::clicked,
this, &QgsProcessingRasterCalculatorExpressionDialog::mBtnLog_clicked );
135 connect( mBtnAsin, &QPushButton::clicked,
this, &QgsProcessingRasterCalculatorExpressionDialog::mBtnAsin_clicked );
136 connect( mBtnAcos, &QPushButton::clicked,
this, &QgsProcessingRasterCalculatorExpressionDialog::mBtnAcos_clicked );
137 connect( mBtnAtan, &QPushButton::clicked,
this, &QgsProcessingRasterCalculatorExpressionDialog::mBtnAtan_clicked );
138 connect( mBtnLn, &QPushButton::clicked,
this, &QgsProcessingRasterCalculatorExpressionDialog::mBtnLn_clicked );
140 mExpressionTextEdit->setPlainText( mInitialText );
143void QgsProcessingRasterCalculatorExpressionDialog::setExpression(
const QString &text )
145 mExpressionTextEdit->setPlainText( text );
148QString QgsProcessingRasterCalculatorExpressionDialog::expression()
150 return mExpressionTextEdit->toPlainText();
153void QgsProcessingRasterCalculatorExpressionDialog::populateLayers()
155 if ( mLayers.isEmpty() )
160 for (
const QVariant &layer : mLayers )
162 QListWidgetItem *item =
new QListWidgetItem( layer.toString(), mLayersList );
163 mLayersList->addItem( item );
167QString QgsProcessingRasterCalculatorExpressionDialog::quoteBandEntry(
const QString &layerName )
170 QString quotedName = layerName;
171 quotedName.replace(
'\"', QLatin1String(
"\\\"" ) );
172 quotedName.append(
'\"' );
173 quotedName.prepend(
'\"' );
177void QgsProcessingRasterCalculatorExpressionDialog::mLayersList_itemDoubleClicked( QListWidgetItem *item )
179 mExpressionTextEdit->insertPlainText( quoteBandEntry( QStringLiteral(
"%1@1" ).arg( item->text() ) ) );
182void QgsProcessingRasterCalculatorExpressionDialog::mBtnPlus_clicked()
184 mExpressionTextEdit->insertPlainText( QStringLiteral(
" + " ) );
187void QgsProcessingRasterCalculatorExpressionDialog::mBtnMinus_clicked()
189 mExpressionTextEdit->insertPlainText( QStringLiteral(
" - " ) );
192void QgsProcessingRasterCalculatorExpressionDialog::mBtnMultiply_clicked()
194 mExpressionTextEdit->insertPlainText( QStringLiteral(
" * " ) );
197void QgsProcessingRasterCalculatorExpressionDialog::mBtnDivide_clicked()
199 mExpressionTextEdit->insertPlainText( QStringLiteral(
" / " ) );
202void QgsProcessingRasterCalculatorExpressionDialog::mBtnPower_clicked()
204 mExpressionTextEdit->insertPlainText( QStringLiteral(
" ^ " ) );
207void QgsProcessingRasterCalculatorExpressionDialog::mBtnSqrt_clicked()
209 mExpressionTextEdit->insertPlainText( QStringLiteral(
" sqrt ( " ) );
212void QgsProcessingRasterCalculatorExpressionDialog::mBtnOpenBracket_clicked()
214 mExpressionTextEdit->insertPlainText( QStringLiteral(
" ( " ) );
217void QgsProcessingRasterCalculatorExpressionDialog::mBtnCloseBracket_clicked()
219 mExpressionTextEdit->insertPlainText( QStringLiteral(
" ) " ) );
222void QgsProcessingRasterCalculatorExpressionDialog::mBtnGreater_clicked()
224 mExpressionTextEdit->insertPlainText( QStringLiteral(
" > " ) );
227void QgsProcessingRasterCalculatorExpressionDialog::mBtnGreaterEqual_clicked()
229 mExpressionTextEdit->insertPlainText( QStringLiteral(
" >= " ) );
232void QgsProcessingRasterCalculatorExpressionDialog::mBtnLess_clicked()
234 mExpressionTextEdit->insertPlainText( QStringLiteral(
" < " ) );
237void QgsProcessingRasterCalculatorExpressionDialog::mBtnLessEqual_clicked()
239 mExpressionTextEdit->insertPlainText( QStringLiteral(
" <= " ) );
242void QgsProcessingRasterCalculatorExpressionDialog::mBtnEqual_clicked()
244 mExpressionTextEdit->insertPlainText( QStringLiteral(
" = " ) );
247void QgsProcessingRasterCalculatorExpressionDialog::mBtnNotEqual_clicked()
249 mExpressionTextEdit->insertPlainText( QStringLiteral(
" != " ) );
252void QgsProcessingRasterCalculatorExpressionDialog::mBtnAnd_clicked()
254 mExpressionTextEdit->insertPlainText( QStringLiteral(
" AND " ) );
257void QgsProcessingRasterCalculatorExpressionDialog::mBtnOr_clicked()
259 mExpressionTextEdit->insertPlainText( QStringLiteral(
" OR " ) );
262void QgsProcessingRasterCalculatorExpressionDialog::mBtnIf_clicked()
264 mExpressionTextEdit->insertPlainText( QStringLiteral(
" if ( " ) );
267void QgsProcessingRasterCalculatorExpressionDialog::mBtnMin_clicked()
269 mExpressionTextEdit->insertPlainText( QStringLiteral(
" MIN ( " ) );
272void QgsProcessingRasterCalculatorExpressionDialog::mBtnMax_clicked()
274 mExpressionTextEdit->insertPlainText( QStringLiteral(
" MAX ( " ) );
277void QgsProcessingRasterCalculatorExpressionDialog::mBtnAbs_clicked()
279 mExpressionTextEdit->insertPlainText( QStringLiteral(
" ABS ( " ) );
282void QgsProcessingRasterCalculatorExpressionDialog::mBtnSin_clicked()
284 mExpressionTextEdit->insertPlainText( QStringLiteral(
" sin ( " ) );
287void QgsProcessingRasterCalculatorExpressionDialog::mBtnCos_clicked()
289 mExpressionTextEdit->insertPlainText( QStringLiteral(
" cos ( " ) );
292void QgsProcessingRasterCalculatorExpressionDialog::mBtnTan_clicked()
294 mExpressionTextEdit->insertPlainText( QStringLiteral(
" tan ( " ) );
297void QgsProcessingRasterCalculatorExpressionDialog::mBtnLog_clicked()
299 mExpressionTextEdit->insertPlainText( QStringLiteral(
" log10 ( " ) );
302void QgsProcessingRasterCalculatorExpressionDialog::mBtnAsin_clicked()
304 mExpressionTextEdit->insertPlainText( QStringLiteral(
" asin ( " ) );
307void QgsProcessingRasterCalculatorExpressionDialog::mBtnAcos_clicked()
309 mExpressionTextEdit->insertPlainText( QStringLiteral(
" acos ( " ) );
312void QgsProcessingRasterCalculatorExpressionDialog::mBtnAtan_clicked()
314 mExpressionTextEdit->insertPlainText( QStringLiteral(
" atan ( " ) );
317void QgsProcessingRasterCalculatorExpressionDialog::mBtnLn_clicked()
319 mExpressionTextEdit->insertPlainText( QStringLiteral(
" ln ( " ) );
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
QLineEdit subclass with built in support for clearing the widget's value and handling custom null val...
static void enableAutoGeometryRestore(QWidget *widget, const QString &key=QString())
Register the widget to allow its position to be automatically saved and restored when open and closed...