17#include "moc_qgsrasterattributetableaddcolumndialog.cpp"
26 , mAttributeTable( attributeTable )
29 Q_ASSERT( mAttributeTable );
33 connect( mName, &QLineEdit::textChanged,
this, [=](
const QString & ) { updateDialog(); } );
34 connect( mStandardColumn, &QRadioButton::toggled,
this, [=](
bool ) { updateDialog(); } );
35 connect( mColor, &QRadioButton::toggled,
this, [=](
bool ) { updateDialog(); } );
36 connect( mUsage, qOverload<int>( &QComboBox::currentIndexChanged ),
this, [=](
int ) { updateDialog(); } );
38 mDataType->addItem(
QgsFields::iconForFieldType( QMetaType::Type::QString ), tr(
"String" ),
static_cast<int>( QMetaType::Type::QString ) );
39 mDataType->addItem(
QgsFields::iconForFieldType( QMetaType::Type::Int ), tr(
"Integer" ),
static_cast<int>( QMetaType::Type::Int ) );
40 mDataType->addItem(
QgsFields::iconForFieldType( QMetaType::Type::LongLong ), tr(
"Long Integer" ),
static_cast<int>( QMetaType::Type::LongLong ) );
41 mDataType->addItem(
QgsFields::iconForFieldType( QMetaType::Type::Double ), tr(
"Double" ),
static_cast<int>( QMetaType::Type::Double ) );
42 mStandardColumn->setChecked(
true );
51 if ( mAfter->isChecked() )
53 return mColumn->currentIndex() + 1;
57 return mColumn->currentIndex();
63 return mColor->isChecked();
68 return mRamp->isChecked();
83 return static_cast<QMetaType::Type
>( mDataType->currentData().toInt() );
86void QgsRasterAttributeTableAddColumnDialog::updateDialog()
88 mDefinition->setEnabled( mStandardColumn->isChecked() );
92 QList<Qgis::RasterAttributeTableFieldUsage> usages;
93 usages = mAttributeTable->
usages();
101 mColor->setChecked(
false );
102 mColor->setEnabled(
false );
103 mRamp->setChecked(
false );
104 mRamp->setEnabled(
false );
105 mStandardColumn->setChecked(
true );
109 mColor->setEnabled(
true );
110 mRamp->setChecked(
false );
111 mRamp->setEnabled(
false );
115 mColor->setEnabled(
true );
116 mRamp->setEnabled(
true );
119 bool isValid {
true };
120 if ( mStandardColumn->isChecked() )
122 const QString upperName { mName->text().trimmed().toUpper() };
123 if ( upperName.isEmpty() )
125 mError->setText( tr(
"A field name cannot be blank." ) );
129 const QList<QgsRasterAttributeTable::Field> fields { mAttributeTable->
fields() };
132 if ( f.name.toUpper() == upperName )
134 mError->setText( tr(
"A field with this name already exists." ) );
143 const int currentUsageIndex { mUsage->currentIndex() };
144 const QSignalBlocker usageBlocker( mUsage );
148 for (
auto it = usageInfo.cbegin(); it != usageInfo.cend(); ++it )
153 if ( !it.value().unique || !usages.contains( it.key() ) )
162 mUsage->setCurrentIndex( std::clamp( currentUsageIndex, 0,
static_cast<int>( mUsage->count() - 1 ) ) );
164 const QList<QgsRasterAttributeTable::Field> fields { mAttributeTable->
fields() };
166 int currentIndex { mColumn->currentIndex() };
167 if ( mColumn->currentIndex() < 0 )
169 currentIndex = fields.count() - 1;
172 const QSignalBlocker columnBlocker( mColumn );
176 mColumn->addItem( field.name );
178 mColumn->setCurrentIndex( std::clamp( currentIndex, 0,
static_cast<int>( fields.count() - 1 ) ) );
185 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.