19#include "moc_qgsprocessingrastercalculatorexpressionlineedit.cpp"
27#include <QListWidgetItem>
31QgsProcessingRasterCalculatorExpressionLineEdit::QgsProcessingRasterCalculatorExpressionLineEdit( QWidget *parent )
35 mLineEdit->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum );
37 mButton =
new QToolButton();
38 mButton->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
40 connect( mButton, &QAbstractButton::clicked,
this, &QgsProcessingRasterCalculatorExpressionLineEdit::editExpression );
42 QHBoxLayout *layout =
new QHBoxLayout();
43 layout->setContentsMargins( 0, 0, 0, 0 );
44 layout->addWidget( mLineEdit );
45 layout->addWidget( mButton );
48 setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum );
49 setFocusProxy( mLineEdit );
50 connect( mLineEdit, &QLineEdit::textChanged,
this,
static_cast<void ( QgsProcessingRasterCalculatorExpressionLineEdit::* )(
const QString & )
>( &QgsProcessingRasterCalculatorExpressionLineEdit::expressionEdited ) );
52 setExpression( expression() );
55QgsProcessingRasterCalculatorExpressionLineEdit::~QgsProcessingRasterCalculatorExpressionLineEdit() =
default;
57void QgsProcessingRasterCalculatorExpressionLineEdit::setLayers(
const QVariantList &layers )
62QString QgsProcessingRasterCalculatorExpressionLineEdit::expression()
const
65 return mLineEdit->text();
70void QgsProcessingRasterCalculatorExpressionLineEdit::setExpression(
const QString &newExpression )
73 mLineEdit->setText( newExpression );
76void QgsProcessingRasterCalculatorExpressionLineEdit::editExpression()
78 const QString currentExpression = expression();
79 QgsProcessingRasterCalculatorExpressionDialog dlg( mLayers );
80 dlg.setExpression( currentExpression );
84 const QString newExpression = dlg.expression();
85 setExpression( newExpression );
89void QgsProcessingRasterCalculatorExpressionLineEdit::expressionEdited()
91 emit expressionChanged( expression() );
94void QgsProcessingRasterCalculatorExpressionLineEdit::expressionEdited(
const QString &expression )
96 emit expressionChanged( expression );
100QgsProcessingRasterCalculatorExpressionDialog::QgsProcessingRasterCalculatorExpressionDialog(
const QVariantList &layers,
const QString &startExpression, QWidget *parent )
103 , mInitialText( startExpression )
110 connect( mLayersList, &QListWidget::itemDoubleClicked,
this, &QgsProcessingRasterCalculatorExpressionDialog::mLayersList_itemDoubleClicked );
112 connect( mBtnPlus, &QPushButton::clicked,
this, &QgsProcessingRasterCalculatorExpressionDialog::mBtnPlus_clicked );
113 connect( mBtnMinus, &QPushButton::clicked,
this, &QgsProcessingRasterCalculatorExpressionDialog::mBtnMinus_clicked );
114 connect( mBtnMultiply, &QPushButton::clicked,
this, &QgsProcessingRasterCalculatorExpressionDialog::mBtnMultiply_clicked );
115 connect( mBtnDivide, &QPushButton::clicked,
this, &QgsProcessingRasterCalculatorExpressionDialog::mBtnDivide_clicked );
116 connect( mBtnPower, &QPushButton::clicked,
this, &QgsProcessingRasterCalculatorExpressionDialog::mBtnPower_clicked );
117 connect( mBtnSqrt, &QPushButton::clicked,
this, &QgsProcessingRasterCalculatorExpressionDialog::mBtnSqrt_clicked );
118 connect( mBtnOpenBracket, &QPushButton::clicked,
this, &QgsProcessingRasterCalculatorExpressionDialog::mBtnOpenBracket_clicked );
119 connect( mBtnCloseBracket, &QPushButton::clicked,
this, &QgsProcessingRasterCalculatorExpressionDialog::mBtnCloseBracket_clicked );
120 connect( mBtnGreater, &QPushButton::clicked,
this, &QgsProcessingRasterCalculatorExpressionDialog::mBtnGreater_clicked );
121 connect( mBtnGreaterEqual, &QPushButton::clicked,
this, &QgsProcessingRasterCalculatorExpressionDialog::mBtnGreaterEqual_clicked );
122 connect( mBtnLess, &QPushButton::clicked,
this, &QgsProcessingRasterCalculatorExpressionDialog::mBtnLess_clicked );
123 connect( mBtnLessEqual, &QPushButton::clicked,
this, &QgsProcessingRasterCalculatorExpressionDialog::mBtnLessEqual_clicked );
124 connect( mBtnEqual, &QPushButton::clicked,
this, &QgsProcessingRasterCalculatorExpressionDialog::mBtnEqual_clicked );
125 connect( mBtnNotEqual, &QPushButton::clicked,
this, &QgsProcessingRasterCalculatorExpressionDialog::mBtnNotEqual_clicked );
126 connect( mBtnAnd, &QPushButton::clicked,
this, &QgsProcessingRasterCalculatorExpressionDialog::mBtnAnd_clicked );
127 connect( mBtnOr, &QPushButton::clicked,
this, &QgsProcessingRasterCalculatorExpressionDialog::mBtnOr_clicked );
128 connect( mBtnIf, &QPushButton::clicked,
this, &QgsProcessingRasterCalculatorExpressionDialog::mBtnIf_clicked );
129 connect( mBtnMin, &QPushButton::clicked,
this, &QgsProcessingRasterCalculatorExpressionDialog::mBtnMin_clicked );
130 connect( mBtnMax, &QPushButton::clicked,
this, &QgsProcessingRasterCalculatorExpressionDialog::mBtnMax_clicked );
131 connect( mBtnAbs, &QPushButton::clicked,
this, &QgsProcessingRasterCalculatorExpressionDialog::mBtnAbs_clicked );
132 connect( mBtnSin, &QPushButton::clicked,
this, &QgsProcessingRasterCalculatorExpressionDialog::mBtnSin_clicked );
133 connect( mBtnCos, &QPushButton::clicked,
this, &QgsProcessingRasterCalculatorExpressionDialog::mBtnCos_clicked );
134 connect( mBtnTan, &QPushButton::clicked,
this, &QgsProcessingRasterCalculatorExpressionDialog::mBtnTan_clicked );
135 connect( mBtnLog, &QPushButton::clicked,
this, &QgsProcessingRasterCalculatorExpressionDialog::mBtnLog_clicked );
136 connect( mBtnAsin, &QPushButton::clicked,
this, &QgsProcessingRasterCalculatorExpressionDialog::mBtnAsin_clicked );
137 connect( mBtnAcos, &QPushButton::clicked,
this, &QgsProcessingRasterCalculatorExpressionDialog::mBtnAcos_clicked );
138 connect( mBtnAtan, &QPushButton::clicked,
this, &QgsProcessingRasterCalculatorExpressionDialog::mBtnAtan_clicked );
139 connect( mBtnLn, &QPushButton::clicked,
this, &QgsProcessingRasterCalculatorExpressionDialog::mBtnLn_clicked );
141 mExpressionTextEdit->setPlainText( mInitialText );
144void QgsProcessingRasterCalculatorExpressionDialog::setExpression(
const QString &text )
146 mExpressionTextEdit->setPlainText( text );
149QString QgsProcessingRasterCalculatorExpressionDialog::expression()
151 return mExpressionTextEdit->toPlainText();
154void QgsProcessingRasterCalculatorExpressionDialog::populateLayers()
156 if ( mLayers.isEmpty() )
161 for (
const QVariant &layer : mLayers )
163 QListWidgetItem *item =
new QListWidgetItem( layer.toString(), mLayersList );
164 mLayersList->addItem( item );
168QString QgsProcessingRasterCalculatorExpressionDialog::quoteBandEntry(
const QString &layerName )
171 QString quotedName = layerName;
172 quotedName.replace(
'\"', QLatin1String(
"\\\"" ) );
173 quotedName.append(
'\"' );
174 quotedName.prepend(
'\"' );
178void QgsProcessingRasterCalculatorExpressionDialog::mLayersList_itemDoubleClicked( QListWidgetItem *item )
180 mExpressionTextEdit->insertPlainText( quoteBandEntry( QStringLiteral(
"%1@1" ).arg( item->text() ) ) );
183void QgsProcessingRasterCalculatorExpressionDialog::mBtnPlus_clicked()
185 mExpressionTextEdit->insertPlainText( QStringLiteral(
" + " ) );
188void QgsProcessingRasterCalculatorExpressionDialog::mBtnMinus_clicked()
190 mExpressionTextEdit->insertPlainText( QStringLiteral(
" - " ) );
193void QgsProcessingRasterCalculatorExpressionDialog::mBtnMultiply_clicked()
195 mExpressionTextEdit->insertPlainText( QStringLiteral(
" * " ) );
198void QgsProcessingRasterCalculatorExpressionDialog::mBtnDivide_clicked()
200 mExpressionTextEdit->insertPlainText( QStringLiteral(
" / " ) );
203void QgsProcessingRasterCalculatorExpressionDialog::mBtnPower_clicked()
205 mExpressionTextEdit->insertPlainText( QStringLiteral(
" ^ " ) );
208void QgsProcessingRasterCalculatorExpressionDialog::mBtnSqrt_clicked()
210 mExpressionTextEdit->insertPlainText( QStringLiteral(
" sqrt ( " ) );
213void QgsProcessingRasterCalculatorExpressionDialog::mBtnOpenBracket_clicked()
215 mExpressionTextEdit->insertPlainText( QStringLiteral(
" ( " ) );
218void QgsProcessingRasterCalculatorExpressionDialog::mBtnCloseBracket_clicked()
220 mExpressionTextEdit->insertPlainText( QStringLiteral(
" ) " ) );
223void QgsProcessingRasterCalculatorExpressionDialog::mBtnGreater_clicked()
225 mExpressionTextEdit->insertPlainText( QStringLiteral(
" > " ) );
228void QgsProcessingRasterCalculatorExpressionDialog::mBtnGreaterEqual_clicked()
230 mExpressionTextEdit->insertPlainText( QStringLiteral(
" >= " ) );
233void QgsProcessingRasterCalculatorExpressionDialog::mBtnLess_clicked()
235 mExpressionTextEdit->insertPlainText( QStringLiteral(
" < " ) );
238void QgsProcessingRasterCalculatorExpressionDialog::mBtnLessEqual_clicked()
240 mExpressionTextEdit->insertPlainText( QStringLiteral(
" <= " ) );
243void QgsProcessingRasterCalculatorExpressionDialog::mBtnEqual_clicked()
245 mExpressionTextEdit->insertPlainText( QStringLiteral(
" = " ) );
248void QgsProcessingRasterCalculatorExpressionDialog::mBtnNotEqual_clicked()
250 mExpressionTextEdit->insertPlainText( QStringLiteral(
" != " ) );
253void QgsProcessingRasterCalculatorExpressionDialog::mBtnAnd_clicked()
255 mExpressionTextEdit->insertPlainText( QStringLiteral(
" AND " ) );
258void QgsProcessingRasterCalculatorExpressionDialog::mBtnOr_clicked()
260 mExpressionTextEdit->insertPlainText( QStringLiteral(
" OR " ) );
263void QgsProcessingRasterCalculatorExpressionDialog::mBtnIf_clicked()
265 mExpressionTextEdit->insertPlainText( QStringLiteral(
" if ( " ) );
268void QgsProcessingRasterCalculatorExpressionDialog::mBtnMin_clicked()
270 mExpressionTextEdit->insertPlainText( QStringLiteral(
" MIN ( " ) );
273void QgsProcessingRasterCalculatorExpressionDialog::mBtnMax_clicked()
275 mExpressionTextEdit->insertPlainText( QStringLiteral(
" MAX ( " ) );
278void QgsProcessingRasterCalculatorExpressionDialog::mBtnAbs_clicked()
280 mExpressionTextEdit->insertPlainText( QStringLiteral(
" ABS ( " ) );
283void QgsProcessingRasterCalculatorExpressionDialog::mBtnSin_clicked()
285 mExpressionTextEdit->insertPlainText( QStringLiteral(
" sin ( " ) );
288void QgsProcessingRasterCalculatorExpressionDialog::mBtnCos_clicked()
290 mExpressionTextEdit->insertPlainText( QStringLiteral(
" cos ( " ) );
293void QgsProcessingRasterCalculatorExpressionDialog::mBtnTan_clicked()
295 mExpressionTextEdit->insertPlainText( QStringLiteral(
" tan ( " ) );
298void QgsProcessingRasterCalculatorExpressionDialog::mBtnLog_clicked()
300 mExpressionTextEdit->insertPlainText( QStringLiteral(
" log10 ( " ) );
303void QgsProcessingRasterCalculatorExpressionDialog::mBtnAsin_clicked()
305 mExpressionTextEdit->insertPlainText( QStringLiteral(
" asin ( " ) );
308void QgsProcessingRasterCalculatorExpressionDialog::mBtnAcos_clicked()
310 mExpressionTextEdit->insertPlainText( QStringLiteral(
" acos ( " ) );
313void QgsProcessingRasterCalculatorExpressionDialog::mBtnAtan_clicked()
315 mExpressionTextEdit->insertPlainText( QStringLiteral(
" atan ( " ) );
318void QgsProcessingRasterCalculatorExpressionDialog::mBtnLn_clicked()
320 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...