Skip to content

Commit

Permalink
Layout
Browse files Browse the repository at this point in the history
  • Loading branch information
elpaso authored and nyalldawson committed Nov 8, 2022
1 parent ddeccb4 commit 31a5d63
Show file tree
Hide file tree
Showing 22 changed files with 60 additions and 86 deletions.
Expand Up @@ -137,6 +137,7 @@ Sets the color ramp for the row at ``rowIndex`` to ``colorMin`` and ``colorMax``
Returns the list of field usages.
%End


QColor color( 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 definition.
Expand Down
Expand Up @@ -52,8 +52,6 @@ Returns ``True`` if the option to open the newly created attribute table is chec
%Docstring
Sets the message ``bar`` associated with the widget. This allows the widget to push feedback messages
to the appropriate message bar.

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

void setOpenWhenDoneVisible( bool visible );
Expand Down
Expand Up @@ -37,8 +37,6 @@ Creates a new :py:class:`QgsCreateRasterAttributeTableDialog`.
%Docstring
Sets the message ``bar`` associated with the widget. This allows the widget to push feedback messages
to the appropriate message bar.

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

void setOpenWhenDoneVisible( bool visible );
Expand Down
Expand Up @@ -24,7 +24,6 @@ The :py:class:`QgsRasterAttributeTableAddColumnDialog` class collects options to
%Docstring
Creates a new QgsRasterAttributeTableAddRowDialog

:param attributeTable: the raster attribute table
:param parent: optional parent
%End

Expand Down
Expand Up @@ -22,6 +22,9 @@ The :py:class:`QgsRasterAttributeTableDialog` class embeds an attribute table wi
public:

QgsRasterAttributeTableDialog( QgsRasterLayer *rasterLayer, int bandNumber = 0, QWidget *parent /TransferThis/ = 0 );
%Docstring
Create a new QgsRasterAttributeTableDialog
%End

public slots:

Expand Down
Expand Up @@ -110,8 +110,6 @@ Create RGBA minimum and maximum fields and inserts them at ``position``, optiona
Removes the row at ``position``, optionally reporting any error in ``errorMessage``, returns ``True`` on success.
%End

static QString RAT_COLOR_HEADER_NAME;

public:
virtual int rowCount( const QModelIndex &parent ) const;

Expand All @@ -126,6 +124,7 @@ Removes the row at ``position``, optionally reporting any error in ``errorMessag
virtual Qt::ItemFlags flags( const QModelIndex &index ) const;



};

/************************************************************************
Expand Down
Expand Up @@ -32,7 +32,6 @@ 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 );
Expand All @@ -52,8 +51,6 @@ Returns ``True`` if the associated raster attribute table is dirty
%Docstring
Sets the message ``bar`` associated with the widget. This allows the widget to push feedback messages
to the appropriate message bar.

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

signals:
Expand Down
6 changes: 3 additions & 3 deletions src/app/qgisapp.cpp
Expand Up @@ -13408,10 +13408,10 @@ bool QgisApp::checkUnsavedRasterAttributeTableEdits( const QList<QgsMapLayer *>
QString errorMessage;
if ( rat->filePath().isEmpty( ) )
{
if ( ! rasterLayer->dataProvider()->writeNativeAttributeTable( &errorMessage ) )
if ( ! rasterLayer->dataProvider()->writeNativeAttributeTable( &errorMessage ) ) //#spellok
{
visibleMessageBar()->pushMessage( tr( "Error Saving Raster Attribute Table" ),
tr( "An error occourred while saving raster attribute table for layer '%1': %2" ).arg( rasterLayer->name(), errorMessage ),
tr( "An error occurred while saving raster attribute table for layer '%1': %2" ).arg( rasterLayer->name(), errorMessage ),
Qgis::MessageLevel::Critical );
retVal = false;
}
Expand All @@ -13421,7 +13421,7 @@ bool QgisApp::checkUnsavedRasterAttributeTableEdits( const QList<QgsMapLayer *>
if ( ! rat->writeToFile( rat->filePath(), &errorMessage ) )
{
visibleMessageBar()->pushMessage( tr( "Error Saving Raster Attribute Table" ),
tr( "An error occourred while saving raster attribute table for layer '%1' to VAT.DBF file '%2': %3" ).arg( rasterLayer->name(), rat->filePath(), errorMessage ),
tr( "An error occurred while saving raster attribute table for layer '%1' to VAT.DBF file '%2': %3" ).arg( rasterLayer->name(), rat->filePath(), errorMessage ),
Qgis::MessageLevel::Critical );
retVal = false;
}
Expand Down
66 changes: 18 additions & 48 deletions src/core/raster/qgsrasterattributetable.cpp
Expand Up @@ -28,7 +28,7 @@
///@cond private
std::once_flag usageInformationLoaderFlag;
QHash<Qgis::RasterAttributeTableFieldUsage, QgsRasterAttributeTable::UsageInformation> QgsRasterAttributeTable::sUsageInformation;
///@endcond
///@endcond private


Qgis::RasterAttributeTableType QgsRasterAttributeTable::type() const
Expand Down Expand Up @@ -146,7 +146,7 @@ QList<int> QgsRasterAttributeTable::intUsages( ) const
}
return usages;
}
///@endcond
///@endcond private

QColor QgsRasterAttributeTable::color( int row ) const
{
Expand Down Expand Up @@ -826,7 +826,7 @@ QVariantList QgsRasterAttributeTable::row( const double matchValue ) const

if ( fieldUsages.contains( Qgis::RasterAttributeTableFieldUsage::MinMax ) )
{
const int colIdx { fieldUsages.indexOf( Qgis::RasterAttributeTableFieldUsage::MinMax ) };
const int colIdx { static_cast<int>( fieldUsages.indexOf( Qgis::RasterAttributeTableFieldUsage::MinMax ) ) };
for ( int rowIdx = 0; rowIdx < mData.count(); ++rowIdx )
{
bool ok;
Expand All @@ -838,8 +838,8 @@ QVariantList QgsRasterAttributeTable::row( const double matchValue ) const
}
else
{
const int minColIdx { fieldUsages.indexOf( Qgis::RasterAttributeTableFieldUsage::Min ) };
const int maxColIdx { fieldUsages.indexOf( Qgis::RasterAttributeTableFieldUsage::Max ) };
const int minColIdx { static_cast<int>( fieldUsages.indexOf( Qgis::RasterAttributeTableFieldUsage::Min ) ) };
const int maxColIdx { static_cast<int>( fieldUsages.indexOf( Qgis::RasterAttributeTableFieldUsage::Max ) ) };
for ( int rowIdx = 0; rowIdx < mData.count(); ++rowIdx )
{
bool ok;
Expand Down Expand Up @@ -1223,6 +1223,8 @@ void QgsRasterAttributeTable::setType()
mType = fieldUsages.contains( Qgis::RasterAttributeTableFieldUsage::MinMax ) ? Qgis::RasterAttributeTableType::Thematic : Qgis::RasterAttributeTableType::Athematic;
}


///@cond PRIVATE
QHash<int, QgsRasterAttributeTable::UsageInformation> QgsRasterAttributeTable::usageInformationInt()
{
QHash<int, QgsRasterAttributeTable::UsageInformation> usageInfoInt;
Expand All @@ -1233,6 +1235,7 @@ QHash<int, QgsRasterAttributeTable::UsageInformation> QgsRasterAttributeTable::u
}
return usageInfoInt;
}
///@endcond PRIVATE

const QString &QgsRasterAttributeTable::filePath() const
{
Expand All @@ -1256,7 +1259,7 @@ QList<QgsRasterAttributeTable::MinMaxClass> QgsRasterAttributeTable::minMaxClass
return classes;
}

const int minMaxIndex { fieldUsages.indexOf( Qgis::RasterAttributeTableFieldUsage::MinMax ) };
const int minMaxIndex { static_cast<int>( fieldUsages.indexOf( Qgis::RasterAttributeTableFieldUsage::MinMax ) ) };

Q_ASSERT( minMaxIndex >= 0 );

Expand Down Expand Up @@ -1323,8 +1326,8 @@ QgsGradientColorRamp QgsRasterAttributeTable::colorRamp( QStringList &labels, co
{
QgsGradientColorRamp ramp{ Qt::GlobalColor::white, Qt::GlobalColor::black };
const QList<Qgis::RasterAttributeTableFieldUsage> fieldUsages { usages() };
const int minIdx { fieldUsages.indexOf( Qgis::RasterAttributeTableFieldUsage::Min ) };
const int maxIdx { fieldUsages.indexOf( Qgis::RasterAttributeTableFieldUsage::Max ) };
const int minIdx { static_cast<int>( fieldUsages.indexOf( Qgis::RasterAttributeTableFieldUsage::Min ) ) };
const int maxIdx { static_cast<int>( fieldUsages.indexOf( Qgis::RasterAttributeTableFieldUsage::Max ) ) };
const bool isRange { minIdx >= 0 && maxIdx >= 0 };

int labelIdx { labelColumn };
Expand Down Expand Up @@ -1528,7 +1531,7 @@ QgsRasterRenderer *QgsRasterAttributeTable::createRenderer( QgsRasterDataProvide

if ( labelsAreUsable )
{
QList<QgsColorRampShader::ColorRampItem> deduplicatedDitemList;
QList<QgsColorRampShader::ColorRampItem> newItemList;
const double range { maxValue() - minValue() };
int stopIdx { 0 };
for ( const QString &label : std::as_const( labels ) )
Expand All @@ -1539,46 +1542,13 @@ QgsRasterRenderer *QgsRasterAttributeTable::createRenderer( QgsRasterDataProvide
}
double value { minValue() + ramp->stops().at( stopIdx ).offset * range };
QgsColorRampShader::ColorRampItem item { value, ramp->stops().at( stopIdx ).color, label };
deduplicatedDitemList.push_back( item );
newItemList.push_back( item );
stopIdx++;
}

QgsColorRampShader::ColorRampItem item { maxValue(), ramp->color2(), labels.last() };
deduplicatedDitemList.push_back( item );


#if 0
QList<QgsColorRampShader::ColorRampItem> deduplicatedDitemList;
// Deduplicate entries, this is necessary when the ramp for athematic
// ramp rasters creates a stop for each class limit (min and max) which
// may be coincident with the previous class max and next class min.
// When this happens and the colors for the previous class max and
// next class min are equal we can squash the legend classes.
QgsColorRampShader::ColorRampItem item { itemList.first() };
if ( labelsAreUsable )
{
item.label = labels.first();
}
deduplicatedDitemList.push_back( item );
for ( int idx = 1; idx < itemList.count(); ++idx )
{
QgsColorRampShader::ColorRampItem item { itemList.at( idx ) };
if ( qgsDoubleNear( item.value, deduplicatedDitemList.last().value ) && item.color == deduplicatedDitemList.last().color )
{
continue;
}
else
{
if ( labelsAreUsable )
{
item.label = labels.at( idx );
}
deduplicatedDitemList.push_back( item );
}
}
#endif

shaderFunction->setColorRampItemList( deduplicatedDitemList );
newItemList.push_back( item );
shaderFunction->setColorRampItemList( newItemList );
}
}
renderer = pseudoColorRenderer;
Expand All @@ -1589,8 +1559,8 @@ QgsRasterRenderer *QgsRasterAttributeTable::createRenderer( QgsRasterDataProvide
QList<QList<QVariant> > QgsRasterAttributeTable::orderedRows() const
{
const QList<Qgis::RasterAttributeTableFieldUsage> fieldUsages { usages() };
const int minIdx { fieldUsages.indexOf( Qgis::RasterAttributeTableFieldUsage::Min ) };
const int maxIdx { fieldUsages.indexOf( Qgis::RasterAttributeTableFieldUsage::Max ) };
const int minIdx { static_cast<int>( fieldUsages.indexOf( Qgis::RasterAttributeTableFieldUsage::Min ) ) };
const int maxIdx { static_cast<int>( fieldUsages.indexOf( Qgis::RasterAttributeTableFieldUsage::Max ) ) };
const bool isRange { minIdx >= 0 && maxIdx >= 0 };
QList<QVariantList> dataCopy( mData );

Expand All @@ -1603,7 +1573,7 @@ QList<QList<QVariant> > QgsRasterAttributeTable::orderedRows() const
}
else
{
const int minMaxIdx { fieldUsages.indexOf( Qgis::RasterAttributeTableFieldUsage::MinMax ) };
const int minMaxIdx { static_cast<int>( fieldUsages.indexOf( Qgis::RasterAttributeTableFieldUsage::MinMax ) ) };
if ( minMaxIdx < 0 )
{
return dataCopy;
Expand Down
5 changes: 3 additions & 2 deletions src/core/raster/qgsrasterattributetable.h
Expand Up @@ -155,7 +155,8 @@ class CORE_EXPORT QgsRasterAttributeTable
* Returns the list of field usages.
*/
QList<int> intUsages( ) const SIP_PYNAME( usages );
///@encond

///@endcond PRIVATE

/**
* Returns the color of the rat \a row or an invalid color if row does not exist or if there is no color definition.
Expand Down Expand Up @@ -404,7 +405,7 @@ class CORE_EXPORT QgsRasterAttributeTable

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

///@encond
///@endcond PRIVATE

private:

Expand Down
4 changes: 2 additions & 2 deletions src/core/raster/qgsrasterlayer.cpp
Expand Up @@ -1053,9 +1053,9 @@ void QgsRasterLayer::writeRasterAttributeTableExternalPaths( QDomNode &layerNode
}
}

void QgsRasterLayer::readRasterAttributeTableExternalPaths( const QDomNode &layer_node, QgsReadWriteContext &context ) const
void QgsRasterLayer::readRasterAttributeTableExternalPaths( const QDomNode &layerNode, QgsReadWriteContext &context ) const
{
const QDomElement ratsElement = layer_node.firstChildElement( QStringLiteral( "FileBasedAttributeTables" ) );
const QDomElement ratsElement = layerNode.firstChildElement( QStringLiteral( "FileBasedAttributeTables" ) );
if ( !ratsElement.isNull() && ratsElement.childNodes().count() > 0 )
{
const QDomNodeList ratElements { ratsElement.childNodes() };
Expand Down
3 changes: 1 addition & 2 deletions src/core/raster/qgsrasterlayer.h
Expand Up @@ -577,11 +577,10 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer, public QgsAbstractProfile
/**
* Reads the paths to the external raster attribute table files associated with the raster bands and loads the raster attribute tables, the raster symbology is not changed.
* \param layerNode layer node
* \param doc document
* \param context read-write context
* \since QGIS 3.30
*/
void readRasterAttributeTableExternalPaths( const QDomNode &layer_node, QgsReadWriteContext &context ) const;
void readRasterAttributeTableExternalPaths( const QDomNode &layerNode, QgsReadWriteContext &context ) const;

//! \brief Constant defining flag for XML and a constant that signals property not used
const QString QSTRING_NOT_SET;
Expand Down
2 changes: 1 addition & 1 deletion src/gui/raster/qgscreaterasterattributetabledialog.cpp
Expand Up @@ -157,7 +157,7 @@ void QgsCreateRasterAttributeTableDialog::accept()
}
else
{
success = mRasterLayer->dataProvider()->writeNativeAttributeTable( &errorMessage );
success = mRasterLayer->dataProvider()->writeNativeAttributeTable( &errorMessage ); //#spellok
if ( ! success )
{
notify( tr( "Error Saving Raster Attribute Table" ),
Expand Down
1 change: 0 additions & 1 deletion src/gui/raster/qgscreaterasterattributetabledialog.h
Expand Up @@ -63,7 +63,6 @@ class GUI_EXPORT QgsCreateRasterAttributeTableDialog : public QDialog, private U
/**
* Sets the message \a bar associated with the widget. This allows the widget to push feedback messages
* to the appropriate message bar.
* \see messageBar()
*/
void setMessageBar( QgsMessageBar *bar );

Expand Down
1 change: 0 additions & 1 deletion src/gui/raster/qgsloadrasterattributetabledialog.h
Expand Up @@ -52,7 +52,6 @@ class GUI_EXPORT QgsLoadRasterAttributeTableDialog: public QDialog, private Ui::
/**
* Sets the message \a bar associated with the widget. This allows the widget to push feedback messages
* to the appropriate message bar.
* \see messageBar()
*/
void setMessageBar( QgsMessageBar *bar );

Expand Down
3 changes: 2 additions & 1 deletion src/gui/raster/qgsrasterattributetableaddcolumndialog.h
Expand Up @@ -24,7 +24,8 @@
class QgsRasterAttributeTable;

/**
* The QgsRasterAttributeTableAddColumnDialog class collects options to add a new column to a raster attribute table.
* \ingroup gui
* \brief The QgsRasterAttributeTableAddColumnDialog class collects options to add a new column to a raster attribute table.
* \since QGIS 3.30
*/
class GUI_EXPORT QgsRasterAttributeTableAddColumnDialog : public QDialog, private Ui::QgsRasterAttributeTableAddColumnDialogBase
Expand Down
4 changes: 2 additions & 2 deletions src/gui/raster/qgsrasterattributetableaddrowdialog.h
Expand Up @@ -22,7 +22,8 @@
#include "ui_qgsrasterattributetableaddrowdialogbase.h"

/**
* The QgsRasterAttributeTableAddColumnDialog class collects options to add a new row to a raster attribute table.
* \ingroup gui
* \brief The QgsRasterAttributeTableAddColumnDialog class collects options to add a new row to a raster attribute table.
* \since QGIS 3.30
*/
class GUI_EXPORT QgsRasterAttributeTableAddRowDialog : public QDialog, private Ui::QgsRasterAttributeTableAddRowDialogBase
Expand All @@ -32,7 +33,6 @@ class GUI_EXPORT QgsRasterAttributeTableAddRowDialog : public QDialog, private U

/**
* Creates a new QgsRasterAttributeTableAddRowDialog
* \param attributeTable the raster attribute table
* \param parent optional parent
*/
QgsRasterAttributeTableAddRowDialog( QWidget *parent SIP_TRANSFERTHIS = nullptr );
Expand Down
3 changes: 3 additions & 0 deletions src/gui/raster/qgsrasterattributetabledialog.h
Expand Up @@ -35,6 +35,9 @@ class GUI_EXPORT QgsRasterAttributeTableDialog: public QDialog, private Ui::QRas

public:

/**
* Create a new QgsRasterAttributeTableDialog
*/
QgsRasterAttributeTableDialog( QgsRasterLayer *rasterLayer, int bandNumber = 0, QWidget *parent SIP_TRANSFERTHIS = nullptr );

// QDialog interface
Expand Down
11 changes: 7 additions & 4 deletions src/gui/raster/qgsrasterattributetablemodel.cpp
Expand Up @@ -18,8 +18,6 @@
#include <QFont>


QString QgsRasterAttributeTableModel::RAT_COLOR_HEADER_NAME = QObject::tr( "Color" );

QgsRasterAttributeTableModel::QgsRasterAttributeTableModel( QgsRasterAttributeTable *rat, QObject *parent )
: QAbstractTableModel( parent )
, mRat( rat )
Expand Down Expand Up @@ -59,7 +57,7 @@ QStringList QgsRasterAttributeTableModel::headerNames() const

if ( hasColor() || hasRamp() )
{
headers.append( RAT_COLOR_HEADER_NAME );
headers.append( ratColorHeaderName() );
}
}
return headers;
Expand Down Expand Up @@ -312,6 +310,11 @@ bool QgsRasterAttributeTableModel::editChecks( QString *errorMessage )
return true;
}

QString QgsRasterAttributeTableModel::ratColorHeaderName() const
{
return tr( "Color" );
}

int QgsRasterAttributeTableModel::rowCount( const QModelIndex &parent ) const
{
return ( !parent.isValid() && mRat ) ? mRat->data().count() : 0;
Expand Down Expand Up @@ -386,7 +389,7 @@ QVariant QgsRasterAttributeTableModel::data( const QModelIndex &index, int role
}
else if ( role == Qt::ItemDataRole::ToolTipRole && ( field.isColor() || field.isRamp() ) )
{
return tr( "This data is part of a color definition: click on '%1' column to edit." ).arg( RAT_COLOR_HEADER_NAME );
return tr( "This data is part of a color definition: click on '%1' column to edit." ).arg( ratColorHeaderName() );
}
else if ( role == Qt::ItemDataRole::DisplayRole || role == Qt::ItemDataRole::EditRole )
{
Expand Down

0 comments on commit 31a5d63

Please sign in to comment.