31#include <QDesktopServices>
38#include "moc_qgspointcloudlayerproperties.cpp"
40using namespace Qt::StringLiterals;
48 connect(
this, &QDialog::accepted,
this, &QgsPointCloudLayerProperties::apply );
49 connect(
this, &QDialog::rejected,
this, &QgsPointCloudLayerProperties::rollback );
50 connect( buttonBox->button( QDialogButtonBox::Apply ), &QAbstractButton::clicked,
this, &QgsPointCloudLayerProperties::apply );
51 connect( buttonBox, &QDialogButtonBox::helpRequested,
this, &QgsPointCloudLayerProperties::showHelp );
52 connect( pbnQueryBuilder, &QPushButton::clicked,
this, &QgsPointCloudLayerProperties::pbnQueryBuilder_clicked );
56 mScaleRangeWidget->setMapCanvas( mCanvas );
63 initOptionsBase(
false );
65 mOptsPage_Information->setContentsMargins( 0, 0, 0, 0 );
67 QVBoxLayout *layout =
new QVBoxLayout( metadataFrame );
68 layout->setContentsMargins( 0, 0, 0, 0 );
69 metadataFrame->setContentsMargins( 0, 0, 0, 0 );
71 mMetadataWidget->layout()->setContentsMargins( 0, 0, 0, 0 );
72 mMetadataWidget->setMapCanvas( mCanvas );
73 layout->addWidget( mMetadataWidget );
74 metadataFrame->setLayout( layout );
75 mOptsPage_Metadata->setContentsMargins( 0, 0, 0, 0 );
77 setMetadataWidget( mMetadataWidget, mOptsPage_Metadata );
84 if ( !settings.
contains( u
"/Windows/PointCloudLayerProperties/tab"_s ) )
86 settings.
setValue( u
"Windows/PointCloudLayerProperties/tab"_s, mOptStackedWidget->indexOf( mOptsPage_Information ) );
89 mBtnStyle =
new QPushButton( tr(
"Style" ) );
90 QMenu *menuStyle =
new QMenu(
this );
93 menuStyle->addSeparator();
96 mBtnStyle->setMenu( menuStyle );
97 connect( menuStyle, &QMenu::aboutToShow,
this, &QgsPointCloudLayerProperties::aboutToShowStyleMenu );
99 buttonBox->addButton( mBtnStyle, QDialogButtonBox::ResetRole );
101 mBtnMetadata =
new QPushButton( tr(
"Metadata" ),
this );
102 QMenu *menuMetadata =
new QMenu(
this );
105 menuMetadata->addSeparator();
109 mBtnMetadata->setMenu( menuMetadata );
110 buttonBox->addButton( mBtnMetadata, QDialogButtonBox::ResetRole );
113 mOptsPage_Information->setProperty(
"helpPage", u
"working_with_point_clouds/point_clouds.html#information-properties"_s );
114 mOptsPage_Source->setProperty(
"helpPage", u
"working_with_point_clouds/point_clouds.html#source-properties"_s );
115 mOptsPage_Rendering->setProperty(
"helpPage", u
"working_with_point_clouds/point_clouds.html#rendering-properties"_s );
116 mOptsPage_Metadata->setProperty(
"helpPage", u
"working_with_point_clouds/point_clouds.html#metadata-properties"_s );
117 mOptsPage_Statistics->setProperty(
"helpPage", u
"working_with_point_clouds/point_clouds.html#statistics-properties"_s );
119 mStatisticsTableView->setModel(
new QgsPointCloudAttributeStatisticsModel( mLayer, mStatisticsTableView ) );
120 mStatisticsTableView->verticalHeader()->hide();
122 mBackupCrs = mLayer->crs();
126 if ( !stats.
classesOf( u
"Classification"_s ).isEmpty() )
128 mClassificationStatisticsTableView->setModel(
new QgsPointCloudClassificationStatisticsModel( mLayer, u
"Classification"_s, mStatisticsTableView ) );
129 mClassificationStatisticsTableView->verticalHeader()->hide();
133 mClassificationStatsGroupBox->hide();
147 mLegendConfigEmbeddedWidget->applyToLayer();
149 mMetadataWidget->acceptMetadata();
151 mLayer->setName( mLayerOrigNameLineEdit->text() );
153 mLayer->setScaleBasedVisibility( chkUseScaleDependentRendering->isChecked() );
154 mLayer->setMinimumScale( mScaleRangeWidget->minimumScale() );
155 mLayer->setMaximumScale( mScaleRangeWidget->maximumScale() );
157 mLayer->setSubsetString( txtSubsetSQL->text() );
159 mBackupCrs = mLayer->crs();
162 if ( QgsMapLayerLegend *legend = mLayer->legend() )
167 for ( QgsMapLayerConfigWidget *w : std::as_const(
mConfigWidgets ) )
170 mLayer->triggerRepaint();
175 if ( mBackupCrs != mLayer->crs() )
176 mLayer->setCrs( mBackupCrs );
184 mLayerOrigNameLineEdit->setText( mLayer->name() );
190 myStyle.append( u
"body { margin: 10px; }\n "_s );
191 mInformationTextBrowser->clear();
192 mInformationTextBrowser->document()->setDefaultStyleSheet( myStyle );
193 mInformationTextBrowser->setHtml( mLayer->htmlMetadata() );
194 mInformationTextBrowser->setOpenLinks(
false );
197 mCrsSelector->setCrs( mLayer->crs() );
199 mSubsetGroupBox->setEnabled(
true );
200 txtSubsetSQL->setText( mLayer->subsetString() );
201 txtSubsetSQL->setReadOnly(
true );
202 txtSubsetSQL->setCaretWidth( 0 );
203 txtSubsetSQL->setCaretLineVisible(
false );
204 pbnQueryBuilder->setEnabled( mLayer->dataProvider() && mLayer->dataProvider()->supportsSubsetString() && !mLayer->isEditable() );
206 for ( QgsMapLayerConfigWidget *w : std::as_const(
mConfigWidgets ) )
207 w->syncToLayer( mLayer );
212 mLegendConfigEmbeddedWidget->setLayer( mLayer );
216void QgsPointCloudLayerProperties::aboutToShowStyleMenu()
218 QMenu *m = qobject_cast<QMenu *>( sender() );
226void QgsPointCloudLayerProperties::showHelp()
228 const QVariant helpPage = mOptionsStackedWidget->currentWidget()->property(
"helpPage" );
230 if ( helpPage.isValid() )
240void QgsPointCloudLayerProperties::pbnQueryBuilder_clicked()
242 QgsPointCloudQueryBuilder qb { mLayer };
253 mLayer->setCrs( crs );
254 mMetadataWidget->crsChanged();
262QgsPointCloudAttributeStatisticsModel::QgsPointCloudAttributeStatisticsModel(
QgsPointCloudLayer *layer, QObject *parent )
263 : QAbstractTableModel( parent )
265 , mAttributes( layer->attributes() )
269int QgsPointCloudAttributeStatisticsModel::columnCount(
const QModelIndex & )
const
274int QgsPointCloudAttributeStatisticsModel::rowCount(
const QModelIndex & )
const
276 return mAttributes.count();
279QVariant QgsPointCloudAttributeStatisticsModel::data(
const QModelIndex &index,
int role )
const
281 if ( index.row() < 0 || index.row() >= mAttributes.count() )
289 case Qt::DisplayRole:
290 case Qt::ToolTipRole:
292 switch ( index.column() )
309 case Qt::TextAlignmentRole:
311 switch ( index.column() )
314 return static_cast<Qt::Alignment::Int
>( Qt::AlignLeft | Qt::AlignVCenter );
320 return static_cast<Qt::Alignment::Int
>( Qt::AlignRight | Qt::AlignVCenter );
327 if ( index.column() == Name )
336 case Qt::DecorationRole:
337 if ( index.column() == Name )
347QVariant QgsPointCloudAttributeStatisticsModel::headerData(
int section, Qt::Orientation orientation,
int role )
const
349 if ( orientation == Qt::Horizontal && role == Qt::DisplayRole )
354 return tr(
"Attribute" );
357 return tr(
"Minimum" );
359 return tr(
"Maximum" );
363 return tr(
"Standard Deviation" );
373QgsPointCloudClassificationStatisticsModel::QgsPointCloudClassificationStatisticsModel(
QgsPointCloudLayer *layer,
const QString &attribute, QObject *parent )
374 : QAbstractTableModel( parent )
376 , mAttribute( attribute )
378 mClassifications = layer->
statistics().classesOf( attribute );
379 std::sort( mClassifications.begin(), mClassifications.end(), [](
int a,
int b ) ->
bool { return a < b; } );
382int QgsPointCloudClassificationStatisticsModel::columnCount(
const QModelIndex & )
const
387int QgsPointCloudClassificationStatisticsModel::rowCount(
const QModelIndex & )
const
389 return mClassifications.count();
392QVariant QgsPointCloudClassificationStatisticsModel::data(
const QModelIndex &index,
int role )
const
394 if ( index.row() < 0 || index.row() >= mClassifications.count() )
397 const QVariant classValue = mClassifications.at( index.row() );
402 case Qt::DisplayRole:
403 case Qt::ToolTipRole:
405 switch ( index.column() )
408 return classValue.toString();
419 return ( (
double ) stats.
availableClasses( mAttribute ).value( classValue.toInt(), 0 ) ) / pointCount * 100;
425 case Qt::TextAlignmentRole:
427 switch ( index.column() )
430 return QVariant( Qt::AlignLeft | Qt::AlignVCenter );
435 return QVariant( Qt::AlignRight | Qt::AlignVCenter );
442 if ( index.column() == Classification )
456QVariant QgsPointCloudClassificationStatisticsModel::headerData(
int section, Qt::Orientation orientation,
int role )
const
458 if ( orientation == Qt::Horizontal && role == Qt::DisplayRole )
466 return tr(
"Classification" );
468 return tr(
"Count" );
@ ExcludeByDefault
If set, the layer should not be included in legends by default, and must be manually added by a user.
static QString reportStyleSheet(QgsApplication::StyleSheetType styleSheetType=QgsApplication::StyleSheetType::Qt)
Returns a css style sheet for reports, the styleSheetType argument determines what type of stylesheet...
Represents a coordinate reference system (CRS).
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
Base class for "layer properties" dialogs, containing common utilities for handling functionality in ...
void saveMetadataToFile()
Allows the user to save the layer's metadata as a file.
virtual void rollback()
Rolls back changes made to the layer.
void saveStyleAsDefault()
Saves the current layer style as the default for the layer.
QList< QgsMapLayerConfigWidget * > mConfigWidgets
Layer config widgets.
void loadDefaultStyle()
Reloads the default style for the layer.
virtual void apply()=0
Applies the dialog settings to the layer.
virtual void syncToLayer()=0
Resets the dialog to the current layer state.
void saveStyleToFile()
Allows the user to save the layer's style to a file.
QgsMapCanvas * mCanvas
Associated map canvas.
void loadDefaultMetadata()
Reloads the default layer metadata for the layer.
void loadMetadataFromFile()
Allows the user to load layer metadata from a file.
void loadStyleFromFile()
Allows the user to load layer style from a file.
void saveMetadataAsDefault()
Saves the current layer metadata as the default for the layer.
void openUrl(const QUrl &url)
Handles opening a url from the dialog.
Map canvas is a class for displaying all GIS data types on a canvas.
void removesExtraMenuSeparators(QMenu *m)
removes extra separators from the menu
void addStyleManagerActions(QMenu *m, QgsMapLayer *layer)
adds actions to the menu in accordance to the layer
static QgsMapLayerStyleGuiUtils * instance()
returns a singleton instance of this class
void currentStyleChanged(const QString ¤tName)
Emitted when the current style has been changed.
bool hasScaleBasedVisibility() const
Returns whether scale based visibility is enabled for the layer.
double minimumScale() const
Returns the minimum map scale (i.e.
QgsMapLayerStyleManager * styleManager() const
Gets access to the layer's style manager.
double maximumScale() const
Returns the maximum map scale (i.e.
A bar for displaying non-blocking messages to the user.
static QIcon iconForAttributeType(QgsPointCloudAttribute::DataType type)
Returns an icon corresponding to an attribute type.
Attribute for point cloud data pair of name and size in bytes.
QString name() const
Returns name of the attribute.
DataType type() const
Returns the data type.
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.
PointCloudStatisticsCalculationState
Point cloud statistics calculation task.
@ Calculated
The statistics calculation task is done and statistics are available.
void statisticsCalculationStateChanged(QgsPointCloudLayer::PointCloudStatisticsCalculationState state)
Emitted when statistics calculation state has changed.
const QgsPointCloudStatistics statistics() const
Returns the object containing statistics.
QString subsetString() const override
Returns the subset string entered in the dialog.
void setSubsetString(const QString &subsetString) override
Sets a subset string into the dialog.
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...
QMap< int, int > availableClasses(const QString &attribute) const
Returns a map containing the count of each class of the attribute attribute If no matching statistic ...
QList< int > classesOf(const QString &attribute) const
Returns a list of existing classes which are present for the specified attribute.
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 ...
int sampledPointsCount() const
Returns the number of points used to calculate the statistics.
static QgsProject * instance()
Returns the QgsProject singleton instance.
Stores settings for use within QGIS.
bool contains(const QString &key, QgsSettings::Section section=QgsSettings::NoSection) const
Returns true if there exists a setting called key; returns false otherwise.
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.