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( QVariant::Type::String ), tr(
"String" ),
static_cast<int>( QVariant::Type::String ) );
39 mDataType->addItem(
QgsFields::iconForFieldType( QVariant::Type::LongLong ), tr(
"Long Integer" ),
static_cast<int>( QVariant::Type::LongLong ) );
40 mDataType->addItem(
QgsFields::iconForFieldType( QVariant::Type::Double ), tr(
"Double" ),
static_cast<int>( QVariant::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<QVariant::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 );
181 mColumn->setCurrentIndex( std::clamp( currentIndex, 0,
static_cast<int>( fields.count( ) - 1 ) ) );
188 mButtonBox->button( QDialogButtonBox::StandardButton::Ok )->setEnabled( isValid );
RasterAttributeTableFieldUsage
Flags which control behavior of raster renderers.
@ MinMax
Field usage MinMax.
static QIcon iconForFieldType(QVariant::Type type, QVariant::Type subType=QVariant::Type::Invalid, 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...
QVariant::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.
QList< Qgis::RasterAttributeTableFieldUsage > usages() const
Returns the list of field usages.
Qgis::RasterAttributeTableType type() const
Returns the Raster Attribute Table type.
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.