16#include "moc_qgspointcloudquerybuilder.cpp"
19#include "qgspointcloudexpression.h"
24#include <QDomDocument>
43 connect( lstAttributes->selectionModel(), &QItemSelectionModel::currentChanged,
this, &QgsPointCloudQueryBuilder::lstAttributes_currentChanged );
44 connect( lstAttributes, &QListView::doubleClicked,
this, &QgsPointCloudQueryBuilder::lstAttributes_doubleClicked );
45 connect( lstValues, &QListView::doubleClicked,
this, &QgsPointCloudQueryBuilder::lstValues_doubleClicked );
46 connect( btnEqual, &QPushButton::clicked,
this, &QgsPointCloudQueryBuilder::btnEqual_clicked );
47 connect( btnLessThan, &QPushButton::clicked,
this, &QgsPointCloudQueryBuilder::btnLessThan_clicked );
48 connect( btnGreaterThan, &QPushButton::clicked,
this, &QgsPointCloudQueryBuilder::btnGreaterThan_clicked );
49 connect( btnIn, &QPushButton::clicked,
this, &QgsPointCloudQueryBuilder::btnIn_clicked );
50 connect( btnNotIn, &QPushButton::clicked,
this, &QgsPointCloudQueryBuilder::btnNotIn_clicked );
51 connect( btnLessEqual, &QPushButton::clicked,
this, &QgsPointCloudQueryBuilder::btnLessEqual_clicked );
52 connect( btnGreaterEqual, &QPushButton::clicked,
this, &QgsPointCloudQueryBuilder::btnGreaterEqual_clicked );
53 connect( btnNotEqual, &QPushButton::clicked,
this, &QgsPointCloudQueryBuilder::btnNotEqual_clicked );
54 connect( btnAnd, &QPushButton::clicked,
this, &QgsPointCloudQueryBuilder::btnAnd_clicked );
55 connect( btnOr, &QPushButton::clicked,
this, &QgsPointCloudQueryBuilder::btnOr_clicked );
57 QPushButton *pbn =
new QPushButton( tr(
"&Test" ) );
58 buttonBox->addButton( pbn, QDialogButtonBox::ActionRole );
59 connect( pbn, &QAbstractButton::clicked,
this, &QgsPointCloudQueryBuilder::test );
61 pbn =
new QPushButton( tr(
"&Clear" ) );
62 buttonBox->addButton( pbn, QDialogButtonBox::ActionRole );
63 connect( pbn, &QAbstractButton::clicked,
this, &QgsPointCloudQueryBuilder::clear );
65 pbn =
new QPushButton( tr(
"&Save…" ) );
66 buttonBox->addButton( pbn, QDialogButtonBox::ActionRole );
67 pbn->setToolTip( tr(
"Save query to QQF file" ) );
68 connect( pbn, &QAbstractButton::clicked,
this, &QgsPointCloudQueryBuilder::saveQuery );
70 pbn =
new QPushButton( tr(
"&Load…" ) );
71 buttonBox->addButton( pbn, QDialogButtonBox::ActionRole );
72 pbn->setToolTip( tr(
"Load query from QQF file" ) );
73 connect( pbn, &QAbstractButton::clicked,
this, &QgsPointCloudQueryBuilder::loadQuery );
75 lblDataUri->setText( tr(
"Set provider filter on %1" ).arg( layer->
name() ) );
81 QDialog::showEvent( event );
84void QgsPointCloudQueryBuilder::setupGuiViews()
87 mModelAttributes =
new QStandardItemModel();
88 mModelValues =
new QStandardItemModel();
91 lstAttributes->setViewMode( QListView::ListMode );
92 lstValues->setViewMode( QListView::ListMode );
93 lstAttributes->setSelectionBehavior( QAbstractItemView::SelectRows );
94 lstValues->setSelectionBehavior( QAbstractItemView::SelectRows );
95 lstAttributes->setEditTriggers( QAbstractItemView::NoEditTriggers );
96 lstValues->setEditTriggers( QAbstractItemView::NoEditTriggers );
98 lstAttributes->setUniformItemSizes(
true );
99 lstValues->setUniformItemSizes(
true );
101 lstAttributes->setAlternatingRowColors(
true );
102 lstValues->setAlternatingRowColors(
true );
104 lstAttributes->setModel( mModelAttributes );
105 lstValues->setModel( mModelValues );
108void QgsPointCloudQueryBuilder::populateAttributes()
111 mTxtSql->setFields( fields );
112 for (
int idx = 0; idx < fields.
count(); ++idx )
115 mModelAttributes->insertRow( mModelAttributes->rowCount(), myItem );
119void QgsPointCloudQueryBuilder::lstAttributes_currentChanged(
const QModelIndex ¤t,
const QModelIndex &previous )
123 mModelValues->clear();
124 const QString attribute = current.data().toString();
125 if ( attribute.compare( QLatin1String(
"Classification" ), Qt::CaseInsensitive ) == 0 )
128 for (
int i = 0; i <= 18; ++i )
130 QStandardItem *item =
new QStandardItem( QString(
"%1: %2" ).arg( i ).arg( codes.value( i ) ) );
131 item->setData( i, Qt::UserRole );
132 mModelValues->insertRow( mModelValues->rowCount(), item );
138 double value = stats.
minimum( attribute );
139 QString valueString = std::isnan( value ) ? tr(
"n/a" ) : QString::number( value );
140 QStandardItem *item =
new QStandardItem( tr(
"Minimum: %1" ).arg( valueString ) );
141 item->setData( value, Qt::UserRole );
142 mModelValues->insertRow( mModelValues->rowCount(), item );
144 value = stats.
maximum( attribute );
145 valueString = std::isnan( value ) ? tr(
"n/a" ) : QString::number( value );
146 item =
new QStandardItem( tr(
"Maximum: %1" ).arg( valueString ) );
147 item->setData( value, Qt::UserRole );
148 mModelValues->insertRow( mModelValues->rowCount(), item );
150 value = stats.
mean( attribute );
151 valueString = std::isnan( value ) ? tr(
"n/a" ) : QString::number( value );
152 item =
new QStandardItem( tr(
"Mean: %1" ).arg( valueString ) );
153 item->setData( value, Qt::UserRole );
154 mModelValues->insertRow( mModelValues->rowCount(), item );
156 value = stats.
stDev( attribute );
157 valueString = std::isnan( value ) ? tr(
"n/a" ) : QString::number( value );
158 item =
new QStandardItem( tr(
"StdDev: %1" ).arg( valueString ) );
159 item->setData( value, Qt::UserRole );
160 mModelValues->insertRow( mModelValues->rowCount(), item );
164void QgsPointCloudQueryBuilder::lstAttributes_doubleClicked(
const QModelIndex &index )
166 mTxtSql->insertText( QStringLiteral(
"%1 " ).arg( mModelAttributes->data( index ).toString() ) );
170void QgsPointCloudQueryBuilder::lstValues_doubleClicked(
const QModelIndex &index )
172 mTxtSql->insertText( QStringLiteral(
"%1 " ).arg( mModelValues->data( index, Qt::UserRole ).toString() ) );
176void QgsPointCloudQueryBuilder::btnEqual_clicked()
178 mTxtSql->insertText( QStringLiteral(
"= " ) );
182void QgsPointCloudQueryBuilder::btnLessThan_clicked()
184 mTxtSql->insertText( QStringLiteral(
"< " ) );
188void QgsPointCloudQueryBuilder::btnGreaterThan_clicked()
190 mTxtSql->insertText( QStringLiteral(
"> " ) );
194void QgsPointCloudQueryBuilder::btnIn_clicked()
196 mTxtSql->insertText( QStringLiteral(
"IN () " ) );
198 mTxtSql->getCursorPosition( &i, &j );
199 mTxtSql->setCursorPosition( i, j - 2 );
203void QgsPointCloudQueryBuilder::btnNotIn_clicked()
205 mTxtSql->insertText( QStringLiteral(
"NOT IN () " ) );
207 mTxtSql->getCursorPosition( &i, &j );
208 mTxtSql->setCursorPosition( i, j - 2 );
212void QgsPointCloudQueryBuilder::btnLessEqual_clicked()
214 mTxtSql->insertText( QStringLiteral(
"<= " ) );
218void QgsPointCloudQueryBuilder::btnGreaterEqual_clicked()
220 mTxtSql->insertText( QStringLiteral(
">= " ) );
224void QgsPointCloudQueryBuilder::btnNotEqual_clicked()
226 mTxtSql->insertText( QStringLiteral(
"!= " ) );
230void QgsPointCloudQueryBuilder::btnAnd_clicked()
232 mTxtSql->insertText( QStringLiteral(
"AND " ) );
236void QgsPointCloudQueryBuilder::btnOr_clicked()
238 mTxtSql->insertText( QStringLiteral(
"OR " ) );
252 mTxtSql->setText( mOrigSubsetString );
257bool QgsPointCloudQueryBuilder::test(
bool skipConfirmation )
259 QgsPointCloudExpression expression( mTxtSql->text() );
260 if ( !expression.isValid() && !mTxtSql->text().isEmpty() )
262 QMessageBox::warning(
this, tr(
"Query Result" ), tr(
"An error occurred while parsing the expression:\n%1" ).arg( expression.parserErrorString() ) );
267 const QSet<QString> attributes = expression.referencedAttributes();
269 for (
const auto &attribute : attributes )
273 QMessageBox::warning(
this, tr(
"Query Result" ), tr(
"\"%1\" not recognized as an available attribute." ).arg( attribute ) );
278 if ( !skipConfirmation )
279 QMessageBox::information(
this, tr(
"Query Result" ), tr(
"The expression was successfully parsed." ) );
284void QgsPointCloudQueryBuilder::clear()
289void QgsPointCloudQueryBuilder::saveQuery()
295void QgsPointCloudQueryBuilder::loadQuery()
301 mTxtSql->insertText( subset );
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).
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...
const QgsPointCloudAttribute * find(const QString &attributeName, int &offset) const
Finds the attribute with the name.
QgsFields toFields() const
Converts the attribute collection to an equivalent QgsFields collection.
virtual QgsPointCloudAttributeCollection attributes() const =0
Returns the attributes available from this data provider.
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.
QgsPointCloudDataProvider * dataProvider() override
Returns the layer's data provider, it may be nullptr.
const QgsPointCloudStatistics statistics() const
Returns the object containing statistics.
QgsPointCloudQueryBuilder(QgsPointCloudLayer *layer, QWidget *parent=nullptr, Qt::WindowFlags fl=QgsGuiUtils::ModalDialogFlags)
This constructor is used when the query builder is called from the layer properties dialog.
void showEvent(QShowEvent *event) override
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 ...
static bool loadQueryFromFile(QString &subset)
Load query from the XML file.
static bool saveQueryToFile(const QString &subset)
Save query to the XML file.
Interface for a dialog that can edit subset strings.