Skip to content

Commit

Permalink
RAT GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
elpaso authored and nyalldawson committed Nov 8, 2022
1 parent 0e58c3d commit 62dff87
Show file tree
Hide file tree
Showing 43 changed files with 3,159 additions and 176 deletions.
Expand Up @@ -91,6 +91,9 @@ Returns a map of multi value to classes (colors) used by the renderer.
.. versionadded:: 3.30
%End

virtual bool canCreateRasterAttributeTable( ) const;


void setMultiValueClasses( const MultiValueClassData &classes );
%Docstring
Sets the multi value classes to ``setMultiValueClasses``.
Expand Down Expand Up @@ -157,9 +160,13 @@ Converts a raster color ``table`` to paletted renderer class data.
.. versionadded:: 3.0
%End

static QgsPalettedRasterRenderer::MultiValueClassData rasterAttributeTableToClassData( const QgsRasterAttributeTable *attributeTable, QgsColorRamp *ramp = 0 );
static QgsPalettedRasterRenderer::MultiValueClassData rasterAttributeTableToClassData( const QgsRasterAttributeTable *attributeTable, const int classificationColumn = -1, QgsColorRamp *ramp = 0 );
%Docstring
Read classes from the Raster Attribute Table ``attributeTable``, optionally settings the colors from ``ramp``.
Reads and returns classes from the Raster Attribute Table ``attributeTable``, optionally classifying the attribute table by ``classificationColumn`` and settings the colors from ``ramp``. The default value of -1 for the classificationColumn uses the first available value column.

.. note::

The method will return an empty list of classes in case the Raster Attribute Table is not thematic.

.. versionadded:: 3.30
%End
Expand Down
88 changes: 77 additions & 11 deletions python/core/auto_generated/raster/qgsrasterattributetable.sip.in
Expand Up @@ -25,10 +25,16 @@ methods to handle data from QGIS and to import/export a Raster Attribute Table f
%End
public:

struct Ramp
struct UsageInformation
{
QColor min;
QColor max;
QString description; //! Usage description
bool unique; //! Usage must be unique
bool required; //! Usage is required
bool isColor; //! Usage is part of a color component
bool isRamp; //! Usage is part of a ramp component
bool supported; //! Usage is supported
bool maybeClass; //! May be suitable for classification
QList<QVariant::Type> allowedTypes; //! Usage allowed types
};

struct Field
Expand Down Expand Up @@ -151,9 +157,9 @@ Returns the color of the rat ``row`` or an invalid color if row does not exist o
.. seealso:: :py:func:`ramp`
%End

Ramp ramp( int row ) const;
QgsGradientColorRamp ramp( int row ) const;
%Docstring
Returns the color of the rat ``row`` or an invalid color if row does not exist or if there is no color ramp definition.
Returns the gradient color ramp of the rat ``row`` or a default constructed gradient if row does not exist or if there is no color ramp definition.

.. seealso:: :py:func:`hasRamp`

Expand Down Expand Up @@ -190,7 +196,7 @@ Returns the Raster Attribute Table rows as a list of :py:class:`QgsFeature`.
Returns ``True`` if the Raster Attribute Table was modified from its last reading from the storage.
%End

void setIsDirty( bool isDirty );
void setDirty( bool isDirty );
%Docstring
Sets the Raster Attribute Table dirty state to ``isDirty``;
%End
Expand All @@ -212,11 +218,21 @@ Inserts a new ``field`` at ``position``, optionally reporting any error in ``err
bool insertField( int position, const QString &name, const Qgis::RasterAttributeTableFieldUsage usage, const QVariant::Type type, QString *errorMessage /Out/ = 0 );
%Docstring
Creates a new field from ``name``, ``usage`` and ``type`` and inserts it at ``position``, optionally reporting any error in ``errorMessage``, returns ``True`` on success.
%End

bool insertColor( int position, QString *errorMessage /Out/ = 0 );
%Docstring
Create RGBA fields and inserts them at ``position``, optionally reporting any error in ``errorMessage``, returns ``True`` on success.
%End

bool insertRamp( int position, QString *errorMessage /Out/ = 0 );
%Docstring
Create RGBA minimum and maximum fields and inserts them at ``position``, optionally reporting any error in ``errorMessage``, returns ``True`` on success.
%End

bool appendField( const QString &name, const Qgis::RasterAttributeTableFieldUsage usage, const QVariant::Type type, QString *errorMessage /Out/ = 0 );
%Docstring
Creates a new field from ``name``, ``usage`` and ``type`` and appends it to the fields, returns ``True`` on success.
Creates a new field from ``name``, ``usage`` and ``type`` and appends it to the fields, optionally reporting any error in ``errorMessage``, returns ``True`` on success.
%End

bool appendField( const QgsRasterAttributeTable::Field &field, QString *errorMessage /Out/ = 0 );
Expand Down Expand Up @@ -292,40 +308,90 @@ Sets the ``value`` for ``row`` and ``column``.
QVariant value( const int row, const int column ) const;
%Docstring
Returns the ``value`` for ``row`` and ``column``.
%End

double minValue( ) const;
%Docstring
Returns the minimum value of the MinMax (thematic) or Min (athematic) column, returns NaN on errors.
%End

double maxValue( ) const;
%Docstring
Returns the maximum value of the MinMax (thematic) or Max (athematic) column, returns NaN on errors.
%End

QVariantList row( const double matchValue ) const;
%Docstring
Returns a row of data for the given ``matchValue`` or and empty row if there is not match.
Returns a row of data for the given ``matchValue`` or and empty row
if there is not match.
%End

QList<QgsRasterAttributeTable::MinMaxClass> minMaxClasses( const int classificationColumn = -1 ) const;
%Docstring
Returns the classes for a thematic RAT, classified by ``classificationColumn``, the default value of -1 makes the method guess the classification column based on the field usage.
Returns the classes for a thematic Raster Attribute Table, classified
by ``classificationColumn``, the default value of -1 makes the method guess
the classification column based on the field usage.
%End

QgsGradientColorRamp colorRamp( QStringList &labels /Out/, const int labelColumn = -1 ) const;
%Docstring
Returns the color ramp for an athematic Raster Attribute Table
returning the ``labels``, optionally generated from ``labelColumn``.
%End

QgsRasterRenderer *createRenderer( QgsRasterDataProvider *provider, const int bandNumber, const int classificationColumn = -1 ) /Factory/;
%Docstring
Creates and returns a (possibly ``None``) raster renderer for the
specified ``provider`` and ``bandNumber`` and optionally classified
by ``classificationColumn``, the default value of -1 makes the method
guess the classification column based on the field usage.
%End

static Qgis::RasterAttributeTableFieldUsage guessFieldUsage( const QString &name, const QVariant::Type type );
%Docstring
Try to determine the field usage from its ``name`` and ``type``.
%End

const QString &filePath() const;
%Docstring
Returns the (possibly empty) path of the file-based RAT, the path is set when a RAT is read or written from/to a file.

.. seealso:: :py:func:`writeToFile`

.. seealso:: :py:func:`readFromFile`
%End

static QString usageName( const Qgis::RasterAttributeTableFieldUsage fieldusage );
%Docstring
Returns the translated human readable name of ``fieldUsage``.

.. seealso:: :py:func:`usageInformation`
%End

static QList<Qgis::RasterAttributeTableFieldUsage> valueAndColorFieldUsages();
%Docstring
Returns the list of field usages for colors and values.
%End

static QgsRasterAttributeTable *createFromRaster( QgsRasterLayer *rasterLayer ) /Factory/;
static QgsRasterAttributeTable *createFromRaster( QgsRasterLayer *rasterLayer, int *bandNumber /Out/ = 0 ) /Factory/;
%Docstring
Creates a new Raster Attribute Table from a ``rasterLayer``, the renderer must be one of Paletted or SingleBandPseudoColor.
Creates a new Raster Attribute Table from a ``rasterLayer``, the renderer must be Paletted or SingleBandPseudoColor, optionally reporting in ``bandNumber`` the raster band from which the attribute table was created.

:return: NULL in case of errors or unsupported renderer.
%End



static QHash<int, QgsRasterAttributeTable::UsageInformation> usageInformationInt( ) /PyName=usageInformation/;
%Docstring
Returns information about supported Raster Attribute Table usages.

.. seealso:: :py:func:`usageName`
%End

static QHash<Qgis::RasterAttributeTableFieldUsage, QgsRasterAttributeTable::UsageInformation> sUsageInformation;


};

/************************************************************************
Expand Down
14 changes: 14 additions & 0 deletions python/core/auto_generated/raster/qgsrasterlayer.sip.in
Expand Up @@ -258,6 +258,20 @@ Returns the name of a band given its number.
%Docstring
Returns the (possibly NULL) raster attribute table for the given band ``bandNumber``.

.. versionadded:: 3.30
%End

int attributeTableCount( );
%Docstring
Returns the number of attribute tables for the raster by counting the number of bands that have an associated attribute table.

.. versionadded:: 3.30
%End

bool canCreateRasterAttributeTable( );
%Docstring
Returns ``True`` if the raster renderer is suitable for creation of a raster attribute table. The supported renderers are :py:class:`QgsPalettedRasterRenderer` and :py:class:`QgsSingleBandPseudoColorRenderer`.

.. versionadded:: 3.30
%End

Expand Down
8 changes: 8 additions & 0 deletions python/core/auto_generated/raster/qgsrasterrenderer.sip.in
Expand Up @@ -54,6 +54,14 @@ Returns a unique string representation of the renderer type.
Returns flags which dictate renderer behavior.

.. versionadded:: 3.28
%End

virtual bool canCreateRasterAttributeTable( ) const;
%Docstring
Returns ``True`` if the renderer is suitable for attribute table creation.
The default implementation returns ``False``.

.. versionadded:: 3.30
%End

virtual bool setInput( QgsRasterInterface *input );
Expand Down
Expand Up @@ -57,6 +57,9 @@ Returns the raster shader
available in Python as constShader
%End

virtual bool canCreateRasterAttributeTable( ) const;


void createShader( QgsColorRamp *colorRamp /Transfer/ = 0,
QgsColorRampShader::Type colorRampType = QgsColorRampShader::Interpolated,
QgsColorRampShader::ClassificationMode classificationMode = QgsColorRampShader::Continuous,
Expand Down
Expand Up @@ -7,6 +7,7 @@
************************************************************************/



class QgsRasterAttributeTableModel : QAbstractTableModel
{
%Docstring(signature="appended")
Expand All @@ -20,7 +21,7 @@ The :py:class:`QgsRasterAttributeTableModel` class manages a :py:class:`QgsRaste
%End
public:

explicit QgsRasterAttributeTableModel( QgsRasterAttributeTable *rat, QObject *parent = 0 );
explicit QgsRasterAttributeTableModel( QgsRasterAttributeTable *rat, QObject *parent /TransferThis/ = 0 );
%Docstring
Creates a new QgsRasterAttributeTableModel from raster attribute table ``rat`` and optional ``parent``.
%End
Expand Down Expand Up @@ -92,6 +93,16 @@ Removes all color or ramp information, optionally reporting any error in ``error
bool insertRow( const int position, const QVariantList &rowData, QString *errorMessage /Out/ = 0 );
%Docstring
Inserts a new row before ``position``, optionally reporting any error in ``errorMessage``, returns ``True`` on success.
%End

bool insertColor( int position, QString *errorMessage /Out/ = 0 );
%Docstring
Create RGBA fields and inserts them at ``position``, optionally reporting any error in ``errorMessage``, returns ``True`` on success.
%End

bool insertRamp( int position, QString *errorMessage /Out/ = 0 );
%Docstring
Create RGBA minimum and maximum fields and inserts them at ``position``, optionally reporting any error in ``errorMessage``, returns ``True`` on success.
%End

bool removeRow( const int position, QString *errorMessage /Out/ = 0 );
Expand Down
@@ -0,0 +1,59 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/raster/qgsrasterattributetablewidget.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/







class QgsRasterAttributeTableWidget : QWidget
{
%Docstring(signature="appended")
The :py:class:`QgsRasterAttributeTableWidget` class provides an attribute table for rasters and methods to edit the table.

.. versionadded:: 3.30
%End

%TypeHeaderCode
#include "qgsrasterattributetablewidget.h"
%End
public:

explicit QgsRasterAttributeTableWidget( QWidget *parent /TransferThis/ = 0, QgsRasterLayer *rasterLayer = 0, const int bandNumber = 0 );
%Docstring
Creates a new QgsRasterAttributeTableWidget

:param parent: parent widget
:param rasterLayer: raster layer
:param bandNumber: optional initial selected band number (default to 0, which makes the widget use the first available RAT, if any)
:param parent: parent widget
%End

void setRasterLayer( QgsRasterLayer *rasterLayer, const int bandNumber = 0 );
%Docstring
Sets the raster layer and an optional band number.

:param rasterLayer: raster layer
:param bandNumber: optional initial selected band number (default to 0, which makes the widget use the first available RAT, if any)
%End

bool isDirty( ) const;
%Docstring
Returns ``True`` if the associated raster attribute table is dirty
%End

};

/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/raster/qgsrasterattributetablewidget.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
4 changes: 4 additions & 0 deletions python/gui/gui_auto.sip
Expand Up @@ -405,6 +405,10 @@
%Include auto_generated/processing/models/qgsmodelgraphicsscene.sip
%Include auto_generated/processing/models/qgsmodelgraphicsview.sip
%Include auto_generated/providers/qgsabstractdbsourceselect.sip
%Include auto_generated/raster/qgsrasterattributetablewidget.sip
%Include auto_generated/raster/qgscreaterasterattributetabledialog.sip
%Include auto_generated/raster/qgsrasterattributetabledialog.sip
%Include auto_generated/raster/qgsrasterattributetableaddcolumndialog.sip
%Include auto_generated/raster/qgscolorrampshaderwidget.sip
%Include auto_generated/raster/qgshillshaderendererwidget.sip
%Include auto_generated/raster/qgsmultibandcolorrendererwidget.sip
Expand Down

0 comments on commit 62dff87

Please sign in to comment.