Skip to content

Commit

Permalink
Add Statistics tab to point cloud layer properties dialog, which
Browse files Browse the repository at this point in the history
shows any precalculated statistics from the metadata
  • Loading branch information
nyalldawson committed Dec 2, 2020
1 parent bdac7fd commit ed0073d
Show file tree
Hide file tree
Showing 4 changed files with 197 additions and 10 deletions.
118 changes: 118 additions & 0 deletions src/app/pointcloud/qgspointcloudlayerproperties.cpp
Expand Up @@ -27,6 +27,7 @@
#include "qgsmaplayerloadstyledialog.h"
#include "qgsmaplayerconfigwidgetfactory.h"
#include "qgsmaplayerconfigwidget.h"
#include "qgspointcloudattributemodel.h"
#include <QFileDialog>
#include <QMenu>
#include <QMessageBox>
Expand Down Expand Up @@ -96,6 +97,9 @@ QgsPointCloudLayerProperties::QgsPointCloudLayerProperties( QgsPointCloudLayer *
mBtnMetadata->setMenu( menuMetadata );
buttonBox->addButton( mBtnMetadata, QDialogButtonBox::ResetRole );

mStatisticsTableView->setModel( new QgsPointCloudAttributeStatisticsModel( mLayer, mStatisticsTableView ) );
mStatisticsTableView->verticalHeader()->hide();

if ( !mLayer->styleManager()->isDefault( mLayer->styleManager()->currentStyle() ) )
title += QStringLiteral( " (%1)" ).arg( mLayer->styleManager()->currentStyle() );
restoreOptionsBaseUi( title );
Expand Down Expand Up @@ -407,3 +411,117 @@ void QgsPointCloudLayerProperties::optionsStackedWidget_CurrentChanged( int inde
mBtnMetadata->setVisible( isMetadataPanel );
}

//
// QgsPointCloudAttributeStatisticsModel
//
QgsPointCloudAttributeStatisticsModel::QgsPointCloudAttributeStatisticsModel( QgsPointCloudLayer *layer, QObject *parent )
: QAbstractTableModel( parent )
, mLayer( layer )
, mAttributes( layer->attributes() )
{

}

int QgsPointCloudAttributeStatisticsModel::columnCount( const QModelIndex & ) const
{
return StDev + 1;
}

int QgsPointCloudAttributeStatisticsModel::rowCount( const QModelIndex & ) const
{
return mAttributes.count();
}

QVariant QgsPointCloudAttributeStatisticsModel::data( const QModelIndex &index, int role ) const
{
if ( index.row() < 0 || index.row() >= mAttributes.count() )
return QVariant();

const QgsPointCloudAttribute &attr = mAttributes.at( index.row() );

switch ( role )
{
case Qt::DisplayRole:
case Qt::ToolTipRole:
{
switch ( index.column() )
{
case Name:
return attr.name();

case Min:
return mLayer->dataProvider() ? mLayer->dataProvider()->metadataStatistic( attr.name(), QgsStatisticalSummary::Min ) : QVariant();

case Max:
return mLayer->dataProvider() ? mLayer->dataProvider()->metadataStatistic( attr.name(), QgsStatisticalSummary::Max ) : QVariant();

case Mean:
return mLayer->dataProvider() ? mLayer->dataProvider()->metadataStatistic( attr.name(), QgsStatisticalSummary::Mean ) : QVariant();

case StDev:
return mLayer->dataProvider() ? mLayer->dataProvider()->metadataStatistic( attr.name(), QgsStatisticalSummary::StDev ) : QVariant();

}
return QVariant();
}

case Qt::TextAlignmentRole:
{
switch ( index.column() )
{
case Name:
return QVariant( Qt::AlignLeft | Qt::AlignVCenter );

case Min:
case Max:
case Mean:
case StDev:
return QVariant( Qt::AlignRight | Qt::AlignVCenter );

}
return QVariant();
}

case Qt::FontRole:
{
if ( index.column() == Name )
{
QFont f;
f.setBold( true );
return f;
}
return QVariant();
}

case Qt::DecorationRole:
if ( index.column() == Name )
return QgsPointCloudAttributeModel::iconForAttributeType( attr.type() );
else
return QVariant();

default:
return QVariant();
}
}

QVariant QgsPointCloudAttributeStatisticsModel::headerData( int section, Qt::Orientation orientation, int role ) const
{
if ( orientation == Qt::Horizontal && role == Qt::DisplayRole )
{
switch ( section )
{
case Name:
return tr( "Attribute" );

case Min:
return tr( "Minimum" );
case Max:
return tr( "Maximum" );
case Mean:
return tr( "Mean" );
case StDev:
return tr( "Standard Deviation" );
}
}
return QVariant();
}
31 changes: 31 additions & 0 deletions src/app/pointcloud/qgspointcloudlayerproperties.h
Expand Up @@ -21,6 +21,9 @@
#include "ui_qgspointcloudlayerpropertiesbase.h"

#include "qgsmaplayerstylemanager.h"
#include <QAbstractTableModel>

#include "qgspointcloudlayer.h"

class QgsMapLayer;
class QgsMapCanvas;
Expand All @@ -30,6 +33,34 @@ class QgsMetadataWidget;
class QgsMapLayerConfigWidgetFactory;
class QgsMapLayerConfigWidget;


class QgsPointCloudAttributeStatisticsModel : public QAbstractTableModel
{
Q_OBJECT

public:

enum Columns
{
Name,
Min,
Max,
Mean,
StDev
};

QgsPointCloudAttributeStatisticsModel( QgsPointCloudLayer *layer, QObject *parent );
int columnCount( const QModelIndex &parent = QModelIndex() ) const override;
int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const override;
QVariant headerData( int section, Qt::Orientation orientation,
int role = Qt::DisplayRole ) const override;
private:

QgsPointCloudLayer *mLayer = nullptr;
QgsPointCloudAttributeCollection mAttributes;
};

class QgsPointCloudLayerProperties : public QgsOptionsDialogBase, private Ui::QgsPointCloudLayerPropertiesBase
{
Q_OBJECT
Expand Down
18 changes: 9 additions & 9 deletions src/ui/pointcloud/qgspointcloudrendererpropsdialogbase.ui
Expand Up @@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>371</width>
<width>374</width>
<height>501</height>
</rect>
</property>
Expand Down Expand Up @@ -119,7 +119,7 @@
</widget>
</item>
<item row="0" column="3">
<widget class="QgsUnitSelectionWidget" name="mPointSizeUnitWidget" native="true">
<widget class="QgsUnitSelectionWidget" name="mPointSizeUnitWidget">
<property name="minimumSize">
<size>
<width>0</width>
Expand Down Expand Up @@ -194,7 +194,7 @@
</widget>
</item>
<item row="0" column="3">
<widget class="QgsUnitSelectionWidget" name="mMaxErrorUnitWidget" native="true">
<widget class="QgsUnitSelectionWidget" name="mMaxErrorUnitWidget">
<property name="minimumSize">
<size>
<width>0</width>
Expand Down Expand Up @@ -245,6 +245,12 @@
<extends>QComboBox</extends>
<header>qgsblendmodecombobox.h</header>
</customwidget>
<customwidget>
<class>QgsUnitSelectionWidget</class>
<extends>QComboBox</extends>
<header>qgsunitselectionwidget.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsOpacityWidget</class>
<extends>QWidget</extends>
Expand All @@ -257,12 +263,6 @@
<header>qgspanelwidget.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsUnitSelectionWidget</class>
<extends>QWidget</extends>
<header>qgsunitselectionwidget.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>cboRenderers</tabstop>
Expand Down
40 changes: 39 additions & 1 deletion src/ui/qgspointcloudlayerpropertiesbase.ui
Expand Up @@ -122,6 +122,18 @@
<normaloff>:/images/themes/default/propertyicons/editmetadata.svg</normaloff>:/images/themes/default/propertyicons/editmetadata.svg</iconset>
</property>
</item>
<item>
<property name="text">
<string>Statistics</string>
</property>
<property name="toolTip">
<string>Statistics</string>
</property>
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/algorithms/mAlgorithmBasicStatistics.svg</normaloff>:/images/themes/default/algorithms/mAlgorithmBasicStatistics.svg</iconset>
</property>
</item>
</widget>
</item>
</layout>
Expand Down Expand Up @@ -164,7 +176,7 @@
<enum>QFrame::Plain</enum>
</property>
<property name="currentIndex">
<number>1</number>
<number>2</number>
</property>
<widget class="QWidget" name="mOptsPage_Information">
<layout class="QVBoxLayout" name="verticalLayout_4">
Expand Down Expand Up @@ -211,6 +223,26 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="mOptsPage_Statistics">
<layout class="QVBoxLayout" name="verticalLayout_6">
<item>
<widget class="QgsCollapsibleGroupBox" name="groupBox">
<property name="title">
<string>Attribute Statistics</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_7">
<item>
<widget class="QTableView" name="mStatisticsTableView">
<property name="alternatingRowColors">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
Expand Down Expand Up @@ -265,6 +297,12 @@
<extends>QLineEdit</extends>
<header>qgsfilterlineedit.h</header>
</customwidget>
<customwidget>
<class>QgsCollapsibleGroupBox</class>
<extends>QGroupBox</extends>
<header>qgscollapsiblegroupbox.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>mSearchLineEdit</tabstop>
Expand Down

0 comments on commit ed0073d

Please sign in to comment.