25 , mAttributeTable( attributeTable )
28 Q_ASSERT( mAttributeTable );
32 connect( mName, &QLineEdit::textChanged,
this, [ = ](
const QString & ) { updateDialog(); } );
33 connect( mStandardColumn, &QRadioButton::toggled,
this, [ = ](
bool ) { updateDialog(); } );
34 connect( mColor, &QRadioButton::toggled,
this, [ = ](
bool ) { updateDialog(); } );
35 connect( mUsage, qOverload<int>( &QComboBox::currentIndexChanged ),
this, [ = ](
int ) { updateDialog(); } );
37 mDataType->addItem(
QgsFields::iconForFieldType( QMetaType::Type::QString ), tr(
"String" ),
static_cast<int>( QMetaType::Type::QString ) );
38 mDataType->addItem(
QgsFields::iconForFieldType( QMetaType::Type::Int ), tr(
"Integer" ),
static_cast<int>( QMetaType::Type::Int ) );
39 mDataType->addItem(
QgsFields::iconForFieldType( QMetaType::Type::LongLong ), tr(
"Long Integer" ),
static_cast<int>( QMetaType::Type::LongLong ) );
40 mDataType->addItem(
QgsFields::iconForFieldType( QMetaType::Type::Double ), tr(
"Double" ),
static_cast<int>( QMetaType::Type::Double ) );
41 mStandardColumn->setChecked(
true );
50 if ( mAfter->isChecked() )
52 return mColumn->currentIndex() + 1;
56 return mColumn->currentIndex();
62 return mColor->isChecked();
67 return mRamp->isChecked();
82 return static_cast<QMetaType::Type
>( mDataType->currentData( ).toInt( ) );
85void QgsRasterAttributeTableAddColumnDialog::updateDialog()
87 mDefinition->setEnabled( mStandardColumn->isChecked() );
91 QList<Qgis::RasterAttributeTableFieldUsage> usages;
92 usages = mAttributeTable->
usages();
100 mColor->setChecked(
false );
101 mColor->setEnabled(
false );
102 mRamp->setChecked(
false );
103 mRamp->setEnabled(
false );
104 mStandardColumn->setChecked(
true );
108 mColor->setEnabled(
true );
109 mRamp->setChecked(
false );
110 mRamp->setEnabled(
false );
114 mColor->setEnabled(
true );
115 mRamp->setEnabled(
true );
118 bool isValid {
true };
119 if ( mStandardColumn->isChecked() )
121 const QString upperName { mName->text().trimmed().toUpper() };
122 if ( upperName.isEmpty() )
124 mError->setText( tr(
"A field name cannot be blank." ) );
128 const QList<QgsRasterAttributeTable::Field> fields { mAttributeTable->
fields() };
131 if ( f.name.toUpper() == upperName )
133 mError->setText( tr(
"A field with this name already exists." ) );
142 const int currentUsageIndex { mUsage->currentIndex()};
143 const QSignalBlocker usageBlocker( mUsage );
147 for (
auto it = usageInfo.cbegin(); it != usageInfo.cend(); ++it )
152 if ( ! it.value().unique || ! usages.contains( it.key() ) )
157 ( it.value().isColor ) ||
158 ( it.value().isRamp ) )
165 mUsage->setCurrentIndex( std::clamp( currentUsageIndex, 0,
static_cast<int>( mUsage->count() - 1 ) ) );
167 const QList<QgsRasterAttributeTable::Field> fields { mAttributeTable->
fields() };
169 int currentIndex { mColumn->currentIndex() };
170 if ( mColumn->currentIndex() < 0 )
172 currentIndex = fields.count( ) - 1;
175 const QSignalBlocker columnBlocker( mColumn );
179 mColumn->addItem( field.name );
181 mColumn->setCurrentIndex( std::clamp( currentIndex, 0,
static_cast<int>( fields.count( ) - 1 ) ) );
188 mButtonBox->button( QDialogButtonBox::StandardButton::Ok )->setEnabled( isValid );
RasterAttributeTableFieldUsage
The RasterAttributeTableFieldUsage enum represents the usage of a Raster Attribute Table field.
@ MinMax
Field usage MinMax.
static QIcon iconForFieldType(QMetaType::Type type, QMetaType::Type subType=QMetaType::Type::UnknownType, const QString &typeString=QString())
Returns an icon corresponding to a field type.
static void enableAutoGeometryRestore(QWidget *widget, const QString &key=QString())
Register the widget to allow its position to be automatically saved and restored when open and closed...
QMetaType::Type type() const
Returns the new column type.
bool isRamp() const
Returns true if the add color ramp column option was checked.
bool isColor() const
Returns true if the add color column option was checked.
int position() const
Returns the position where the new column (before) will be inserted.
QString name() const
Returns the new column name.
QgsRasterAttributeTableAddColumnDialog(QgsRasterAttributeTable *attributeTable, QWidget *parent=nullptr)
Creates a new QgsRasterAttributeTableAddColumnDialog.
Qgis::RasterAttributeTableFieldUsage usage() const
Returns the new column name.
The Field class represents a Raster Attribute Table field, including its name, usage and type.
The QgsRasterAttributeTable class represents a Raster Attribute Table (RAT).
bool hasColor() const
Returns true if the Raster Attribute Table has color RGBA information.
QList< QgsRasterAttributeTable::Field > fields() const
Returns the Raster Attribute Table fields.
static QHash< Qgis::RasterAttributeTableFieldUsage, QgsRasterAttributeTable::UsageInformation > usageInformation()
Returns information about supported Raster Attribute Table usages.
Qgis::RasterAttributeTableType type() const
Returns the Raster Attribute Table type.
QList< Qgis::RasterAttributeTableFieldUsage > usages() const
Returns the list of field usages.
static QString usageName(const Qgis::RasterAttributeTableFieldUsage fieldusage)
Returns the translated human readable name of fieldUsage.
bool hasRamp() const
Returns true if the Raster Attribute Table has ramp RGBA information.