Skip to content

Commit

Permalink
RAT model
Browse files Browse the repository at this point in the history
  • Loading branch information
elpaso authored and nyalldawson committed Nov 8, 2022
1 parent 6184bd6 commit df4f7fe
Show file tree
Hide file tree
Showing 9 changed files with 295 additions and 62 deletions.
Expand Up @@ -190,7 +190,7 @@ Sets the RAT dirty state to ``isDirty``;
Returns ``True`` if the RAT is valid, optionally reporting validity checks results in ``errorMessage``.
%End

bool insertField( const QgsRasterAttributeTable::Field &field, int position = 0, QString *errorMessage /Out/ = 0 );
bool insertField( int position, const QgsRasterAttributeTable::Field &field, QString *errorMessage /Out/ = 0 );
%Docstring
Inserts a new ``field`` at ``position``, optionally reporting any error in ``errorMessage``, returns ``True`` on success.

Expand All @@ -199,7 +199,7 @@ Inserts a new ``field`` at ``position``, optionally reporting any error in ``err
Out of range position is automatically clamped to a valid value.
%End

bool insertField( const QString &name, const Qgis::RasterAttributeTableFieldUsage usage, const QVariant::Type type, int position = 0, QString *errorMessage /Out/ = 0 );
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
Expand All @@ -219,7 +219,7 @@ Appends a new ``field``, optionally reporting any error in ``errorMessage``, ret
Removes the field with ``name``, optionally reporting any error in ``errorMessage``, returns ``True`` on success.
%End

bool insertRow( const QVariantList &rowData, int position = 0, QString *errorMessage /Out/ = 0 );
bool insertRow( int position, const QVariantList &rowData, QString *errorMessage /Out/ = 0 );
%Docstring
Inserts a row of ``rowData`` in the RAT at ``position``, optionally reporting any error in ``errorMessage``, returns ``True`` on success.

Expand Down
Expand Up @@ -55,8 +55,18 @@ Returns all the header names, including the "virtual" color header if the RAT ha
Returns the tooltip for the given ``section``.
%End

bool isValid( QString *errorMessage /Out/ = 0 );
%Docstring
Checks if the RAT is valid, optionally returns validation errors in ``errorMessage``.
%End

bool isDirty( );
%Docstring
Returns ``True`` if the RAT was modified since it was last saved or read.
%End


bool insertField( const QString &name, const Qgis::RasterAttributeTableFieldUsage usage, const QVariant::Type type, const int position, QString *errorMessage /Out/ = 0 );
bool insertField( const int position, const QString &name, const Qgis::RasterAttributeTableFieldUsage usage, const QVariant::Type type, QString *errorMessage /Out/ = 0 );
%Docstring
Inserts a field at the given position.

Expand All @@ -68,21 +78,25 @@ Inserts a field at the given position.
:return: - true on success
- errorMessage: error message
%End

bool removeField( const int position, QString *errorMessage /Out/ = 0 );
%Docstring
Remove the field at given ``position``, optionally reporting any error in ``errorMessage``, returns ``True`` on success.
%End

bool removeColorOrRamp( QString *errorMessage /Out/ = 0 );
%Docstring
Removes all color or ramp information, returns ``True`` on success.
Removes all color or ramp information, optionally reporting any error in ``errorMessage``, returns ``True`` on success.
%End

bool insertRow( const QVariantList &rowData, const int position, QString *errorMessage /Out/ = 0 );
bool insertRow( const int position, const QVariantList &rowData, QString *errorMessage /Out/ = 0 );
%Docstring
Inserts a new row before ``position``, returns ``True`` on success.
Inserts a new row before ``position``, optionally reporting any error in ``errorMessage``, returns ``True`` on success.
%End

bool removeRow( const int position, QString *errorMessage /Out/ = 0 );
%Docstring
Removes the row at ``position``, returns ``True`` on success.
Removes the row at ``position``, optionally reporting any error in ``errorMessage``, returns ``True`` on success.
%End

static QString RAT_COLOR_HEADER_NAME;
Expand All @@ -98,11 +112,9 @@ Removes the row at ``position``, returns ``True`` on success.

virtual QVariant headerData( int section, Qt::Orientation orientation, int role ) const;


virtual Qt::ItemFlags flags( const QModelIndex &index ) const;



};

/************************************************************************
Expand Down
16 changes: 8 additions & 8 deletions src/core/raster/qgsrasterattributetable.cpp
Expand Up @@ -217,7 +217,7 @@ void QgsRasterAttributeTable::setIsDirty( bool isDirty )
mIsDirty = isDirty;
}

bool QgsRasterAttributeTable::insertField( const Field &field, int position, QString *errorMessage )
bool QgsRasterAttributeTable::insertField( int position, const Field &field, QString *errorMessage )
{

const int realPos { std::clamp( position, 0, static_cast<int>( mFields.count() ) ) };
Expand Down Expand Up @@ -301,19 +301,19 @@ bool QgsRasterAttributeTable::insertField( const Field &field, int position, QSt
return true;
}

bool QgsRasterAttributeTable::insertField( const QString &name, const Qgis::RasterAttributeTableFieldUsage usage, const QVariant::Type type, int position, QString *errorMessage )
bool QgsRasterAttributeTable::insertField( int position, const QString &name, const Qgis::RasterAttributeTableFieldUsage usage, const QVariant::Type type, QString *errorMessage )
{
return insertField( { name, usage, type}, position, errorMessage );
return insertField( position, { name, usage, type}, errorMessage );
}

bool QgsRasterAttributeTable::appendField( const QString &name, const Qgis::RasterAttributeTableFieldUsage usage, const QVariant::Type type, QString *errorMessage )
{
return insertField( name, usage, type, mFields.count(), errorMessage );
return insertField( mFields.count(), name, usage, type, errorMessage );
}

bool QgsRasterAttributeTable::appendField( const Field &field, QString *errorMessage )
{
return insertField( field, mFields.count(), errorMessage );
return insertField( mFields.count(), field, errorMessage );
}

bool QgsRasterAttributeTable::removeField( const QString &name, QString *errorMessage )
Expand Down Expand Up @@ -341,10 +341,10 @@ bool QgsRasterAttributeTable::removeField( const QString &name, QString *errorMe
return false;
}

bool QgsRasterAttributeTable::insertRow( const QVariantList &rowData, int position, QString *errorMessage )
bool QgsRasterAttributeTable::insertRow( int position, const QVariantList &rowData, QString *errorMessage )
{

const int realPos { std::clamp( position, 0, static_cast<int>( mFields.count() ) ) };
const int realPos { std::clamp( position, 0, static_cast<int>( mData.count() ) ) };

if ( rowData.size() != mFields.size() )
{
Expand Down Expand Up @@ -395,7 +395,7 @@ bool QgsRasterAttributeTable::removeRow( int position, QString *errorMessage )

bool QgsRasterAttributeTable::appendRow( const QVariantList &data, QString *errorMessage )
{
return insertRow( data, mData.count(), errorMessage );
return insertRow( mData.count(), data, errorMessage );
}

bool QgsRasterAttributeTable::writeToFile( const QString &path, QString *errorMessage )
Expand Down
6 changes: 3 additions & 3 deletions src/core/raster/qgsrasterattributetable.h
Expand Up @@ -186,12 +186,12 @@ class CORE_EXPORT QgsRasterAttributeTable
* Inserts a new \a field at \a position, optionally reporting any error in \a errorMessage, returns TRUE on success.
* \note Out of range position is automatically clamped to a valid value.
*/
bool insertField( const QgsRasterAttributeTable::Field &field, int position = 0, QString *errorMessage SIP_OUT = nullptr );
bool insertField( int position, const QgsRasterAttributeTable::Field &field, QString *errorMessage SIP_OUT = nullptr );

/**
* Creates a new field from \a name, \a usage and \a type and inserts it at \a position, optionally reporting any error in \a errorMessage, returns TRUE on success.
*/
bool insertField( const QString &name, const Qgis::RasterAttributeTableFieldUsage usage, const QVariant::Type type, int position = 0, QString *errorMessage SIP_OUT = nullptr );
bool insertField( int position, const QString &name, const Qgis::RasterAttributeTableFieldUsage usage, const QVariant::Type type, QString *errorMessage SIP_OUT = nullptr );

/**
* Creates a new field from \a name, \a usage and \a type and appends it to the fields, returns TRUE on success.
Expand All @@ -212,7 +212,7 @@ class CORE_EXPORT QgsRasterAttributeTable
* Inserts a row of \a rowData in the RAT at \a position, optionally reporting any error in \a errorMessage, returns TRUE on success.
* \note Out of range position is automatically clamped to a valid value.
*/
bool insertRow( const QVariantList &rowData, int position = 0, QString *errorMessage SIP_OUT = nullptr );
bool insertRow( int position, const QVariantList &rowData, QString *errorMessage SIP_OUT = nullptr );

/**
* Removes the row in the RAT at \a position, optionally reporting any error in \a errorMessage, returns TRUE on success.
Expand Down

0 comments on commit df4f7fe

Please sign in to comment.