19#include "moc_qgsprocessingpointcloudexpressionlineedit.cpp"
24#include "qgspointcloudexpression.h"
34QgsProcessingPointCloudExpressionLineEdit::QgsProcessingPointCloudExpressionLineEdit( QWidget *parent )
38 mLineEdit->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum );
40 mButton =
new QToolButton();
41 mButton->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
43 connect( mButton, &QAbstractButton::clicked,
this, &QgsProcessingPointCloudExpressionLineEdit::editExpression );
45 QHBoxLayout *layout =
new QHBoxLayout();
46 layout->setContentsMargins( 0, 0, 0, 0 );
47 layout->addWidget( mLineEdit );
48 layout->addWidget( mButton );
51 setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum );
52 setFocusProxy( mLineEdit );
53 connect( mLineEdit, &QLineEdit::textChanged,
this,
static_cast<void ( QgsProcessingPointCloudExpressionLineEdit::* )(
const QString & )
>( &QgsProcessingPointCloudExpressionLineEdit::expressionEdited ) );
55 setExpression( expression() );
58QgsProcessingPointCloudExpressionLineEdit::~QgsProcessingPointCloudExpressionLineEdit() =
default;
70QString QgsProcessingPointCloudExpressionLineEdit::expression()
const
73 return mLineEdit->text();
78void QgsProcessingPointCloudExpressionLineEdit::setExpression(
const QString &newExpression )
81 mLineEdit->setText( newExpression );
84void QgsProcessingPointCloudExpressionLineEdit::editExpression()
86 const QString currentExpression = expression();
87 QgsProcessingPointCloudExpressionDialog dlg( mLayer );
88 dlg.setExpression( currentExpression );
92 const QString newExpression = dlg.expression();
93 setExpression( newExpression );
97void QgsProcessingPointCloudExpressionLineEdit::expressionEdited()
99 emit expressionChanged( expression() );
102void QgsProcessingPointCloudExpressionLineEdit::expressionEdited(
const QString &expression )
104 emit expressionChanged( expression );
108QgsProcessingPointCloudExpressionDialog::QgsProcessingPointCloudExpressionDialog(
QgsPointCloudLayer *layer,
const QString &startExpression, QWidget *parent )
111 , mInitialText( startExpression )
116 mModelAttributes =
new QStandardItemModel();
117 mModelValues =
new QStandardItemModel();
118 lstAttributes->setModel( mModelAttributes );
119 lstValues->setModel( mModelValues );
121 populateAttributes();
123 connect( lstAttributes->selectionModel(), &QItemSelectionModel::currentChanged,
this, &QgsProcessingPointCloudExpressionDialog::lstAttributes_currentChanged );
124 connect( lstAttributes, &QListView::doubleClicked,
this, &QgsProcessingPointCloudExpressionDialog::lstAttributes_doubleClicked );
125 connect( lstValues, &QListView::doubleClicked,
this, &QgsProcessingPointCloudExpressionDialog::lstValues_doubleClicked );
126 connect( btnEqual, &QPushButton::clicked,
this, &QgsProcessingPointCloudExpressionDialog::btnEqual_clicked );
127 connect( btnLessThan, &QPushButton::clicked,
this, &QgsProcessingPointCloudExpressionDialog::btnLessThan_clicked );
128 connect( btnGreaterThan, &QPushButton::clicked,
this, &QgsProcessingPointCloudExpressionDialog::btnGreaterThan_clicked );
129 connect( btnIn, &QPushButton::clicked,
this, &QgsProcessingPointCloudExpressionDialog::btnIn_clicked );
130 connect( btnNotIn, &QPushButton::clicked,
this, &QgsProcessingPointCloudExpressionDialog::btnNotIn_clicked );
131 connect( btnLessEqual, &QPushButton::clicked,
this, &QgsProcessingPointCloudExpressionDialog::btnLessEqual_clicked );
132 connect( btnGreaterEqual, &QPushButton::clicked,
this, &QgsProcessingPointCloudExpressionDialog::btnGreaterEqual_clicked );
133 connect( btnNotEqual, &QPushButton::clicked,
this, &QgsProcessingPointCloudExpressionDialog::btnNotEqual_clicked );
134 connect( btnAnd, &QPushButton::clicked,
this, &QgsProcessingPointCloudExpressionDialog::btnAnd_clicked );
135 connect( btnOr, &QPushButton::clicked,
this, &QgsProcessingPointCloudExpressionDialog::btnOr_clicked );
137 QPushButton *pbn =
new QPushButton( tr(
"&Test" ) );
138 buttonBox->addButton( pbn, QDialogButtonBox::ActionRole );
139 connect( pbn, &QAbstractButton::clicked,
this, &QgsProcessingPointCloudExpressionDialog::test );
141 pbn =
new QPushButton( tr(
"&Clear" ) );
142 buttonBox->addButton( pbn, QDialogButtonBox::ActionRole );
143 connect( pbn, &QAbstractButton::clicked,
this, &QgsProcessingPointCloudExpressionDialog::clear );
145 mTxtSql->setText( mInitialText );
148void QgsProcessingPointCloudExpressionDialog::setExpression(
const QString &text )
150 mTxtSql->setText( text );
153QString QgsProcessingPointCloudExpressionDialog::expression()
155 return mTxtSql->text();
158void QgsProcessingPointCloudExpressionDialog::populateAttributes()
165 const QgsFields &fields = mLayer->dataProvider()->attributes().toFields();
166 mTxtSql->setFields( fields );
167 for (
int idx = 0; idx < fields.
count(); ++idx )
170 mModelAttributes->insertRow( mModelAttributes->rowCount(), myItem );
174void QgsProcessingPointCloudExpressionDialog::lstAttributes_currentChanged(
const QModelIndex ¤t,
const QModelIndex &previous )
178 mModelValues->clear();
179 const QString attribute = current.data().toString();
180 if ( attribute.compare( QLatin1String(
"Classification" ), Qt::CaseInsensitive ) == 0 )
183 for (
int i = 0; i <= 18; ++i )
185 QStandardItem *item =
new QStandardItem( QString(
"%1: %2" ).arg( i ).arg( codes.value( i ) ) );
186 item->setData( i, Qt::UserRole );
187 mModelValues->insertRow( mModelValues->rowCount(), item );
193 double value = stats.
minimum( attribute );
194 QString valueString = std::isnan( value ) ? tr(
"n/a" ) : QString::number( value );
195 QStandardItem *item =
new QStandardItem( tr(
"Minimum: %1" ).arg( valueString ) );
196 item->setData( value, Qt::UserRole );
197 mModelValues->insertRow( mModelValues->rowCount(), item );
199 value = stats.
maximum( attribute );
200 valueString = std::isnan( value ) ? tr(
"n/a" ) : QString::number( value );
201 item =
new QStandardItem( tr(
"Maximum: %1" ).arg( valueString ) );
202 item->setData( value, Qt::UserRole );
203 mModelValues->insertRow( mModelValues->rowCount(), item );
205 value = stats.
mean( attribute );
206 valueString = std::isnan( value ) ? tr(
"n/a" ) : QString::number( value );
207 item =
new QStandardItem( tr(
"Mean: %1" ).arg( valueString ) );
208 item->setData( value, Qt::UserRole );
209 mModelValues->insertRow( mModelValues->rowCount(), item );
211 value = stats.
stDev( attribute );
212 valueString = std::isnan( value ) ? tr(
"n/a" ) : QString::number( value );
213 item =
new QStandardItem( tr(
"StdDev: %1" ).arg( valueString ) );
214 item->setData( value, Qt::UserRole );
215 mModelValues->insertRow( mModelValues->rowCount(), item );
219void QgsProcessingPointCloudExpressionDialog::lstAttributes_doubleClicked(
const QModelIndex &index )
221 mTxtSql->insertText( QStringLiteral(
"%1 " ).arg( mModelAttributes->data( index ).toString() ) );
225void QgsProcessingPointCloudExpressionDialog::lstValues_doubleClicked(
const QModelIndex &index )
227 mTxtSql->insertText( QStringLiteral(
"%1 " ).arg( mModelValues->data( index, Qt::UserRole ).toString() ) );
231void QgsProcessingPointCloudExpressionDialog::btnEqual_clicked()
233 mTxtSql->insertText( QStringLiteral(
"= " ) );
237void QgsProcessingPointCloudExpressionDialog::btnLessThan_clicked()
239 mTxtSql->insertText( QStringLiteral(
"< " ) );
243void QgsProcessingPointCloudExpressionDialog::btnGreaterThan_clicked()
245 mTxtSql->insertText( QStringLiteral(
"> " ) );
249void QgsProcessingPointCloudExpressionDialog::btnIn_clicked()
251 mTxtSql->insertText( QStringLiteral(
"IN () " ) );
253 mTxtSql->getCursorPosition( &i, &j );
254 mTxtSql->setCursorPosition( i, j - 2 );
258void QgsProcessingPointCloudExpressionDialog::btnNotIn_clicked()
260 mTxtSql->insertText( QStringLiteral(
"NOT IN () " ) );
262 mTxtSql->getCursorPosition( &i, &j );
263 mTxtSql->setCursorPosition( i, j - 2 );
267void QgsProcessingPointCloudExpressionDialog::btnLessEqual_clicked()
269 mTxtSql->insertText( QStringLiteral(
"<= " ) );
273void QgsProcessingPointCloudExpressionDialog::btnGreaterEqual_clicked()
275 mTxtSql->insertText( QStringLiteral(
">= " ) );
279void QgsProcessingPointCloudExpressionDialog::btnNotEqual_clicked()
281 mTxtSql->insertText( QStringLiteral(
"!= " ) );
285void QgsProcessingPointCloudExpressionDialog::btnAnd_clicked()
287 mTxtSql->insertText( QStringLiteral(
"AND " ) );
291void QgsProcessingPointCloudExpressionDialog::btnOr_clicked()
293 mTxtSql->insertText( QStringLiteral(
"OR " ) );
297void QgsProcessingPointCloudExpressionDialog::test()
299 QgsPointCloudExpression expression( mTxtSql->text() );
301 if ( !expression.isValid() && !mTxtSql->text().isEmpty() )
303 QMessageBox::warning(
this, tr(
"Query Result" ), tr(
"An error occurred while parsing the expression:\n%1" ).arg( expression.parserErrorString() ) );
307 const QSet<QString> attributes = expression.referencedAttributes();
309 for (
const auto &attribute : attributes )
311 if ( mLayer && mLayer->dataProvider() && !mLayer->dataProvider()->attributes().find( attribute, offset ) )
313 QMessageBox::warning(
this, tr(
"Query Result" ), tr(
"\"%1\" not recognized as an available attribute." ).arg( attribute ) );
317 QMessageBox::information(
this, tr(
"Query Result" ), tr(
"The expression was successfully parsed." ) );
321void QgsProcessingPointCloudExpressionDialog::clear()
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
QString displayNameWithAlias() const
Returns the name to use when displaying this field and adds the alias in parenthesis if it is defined...
Container of fields for a vector layer.
QgsField at(int i) const
Returns the field at particular index (must be in range 0..N-1).
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...
static QMap< int, QString > translatedLasClassificationCodes()
Returns the map of LAS classification code to translated string value, corresponding to the ASPRS Sta...
Represents a map layer supporting display of point clouds.
Class used to store statistics of a point cloud dataset.
double maximum(const QString &attribute) const
Returns the maximum value for the attribute attribute If no matching statistic is available then NaN ...
double stDev(const QString &attribute) const
Returns the standard deviation value for the attribute attribute If no matching statistic is availabl...
double mean(const QString &attribute) const
Returns the mean value for the attribute attribute If no matching statistic is available then NaN wil...
double minimum(const QString &attribute) const
Returns the minimum value for the attribute attribute If no matching statistic is available then NaN ...