23#include "moc_qgsrasterattributetableaddcolumndialog.cpp"
27 , mAttributeTable( attributeTable )
30 Q_ASSERT( mAttributeTable );
34 connect( mName, &QLineEdit::textChanged,
this, [
this](
const QString & ) { updateDialog(); } );
35 connect( mStandardColumn, &QRadioButton::toggled,
this, [
this](
bool ) { updateDialog(); } );
36 connect( mColor, &QRadioButton::toggled,
this, [
this](
bool ) { updateDialog(); } );
37 connect( mUsage, qOverload<int>( &QComboBox::currentIndexChanged ),
this, [
this](
int ) { updateDialog(); } );
39 mDataType->addItem(
QgsFields::iconForFieldType( QMetaType::Type::QString ), tr(
"String" ),
static_cast<int>( QMetaType::Type::QString ) );
40 mDataType->addItem(
QgsFields::iconForFieldType( QMetaType::Type::Int ), tr(
"Integer" ),
static_cast<int>( QMetaType::Type::Int ) );
41 mDataType->addItem(
QgsFields::iconForFieldType( QMetaType::Type::LongLong ), tr(
"Long Integer" ),
static_cast<int>( QMetaType::Type::LongLong ) );
42 mDataType->addItem(
QgsFields::iconForFieldType( QMetaType::Type::Double ), tr(
"Double" ),
static_cast<int>( QMetaType::Type::Double ) );
43 mStandardColumn->setChecked(
true );
52 if ( mAfter->isChecked() )
54 return mColumn->currentIndex() + 1;
58 return mColumn->currentIndex();
64 return mColor->isChecked();
69 return mRamp->isChecked();
84 return static_cast<QMetaType::Type
>( mDataType->currentData().toInt() );
87void QgsRasterAttributeTableAddColumnDialog::updateDialog()
89 mDefinition->setEnabled( mStandardColumn->isChecked() );
93 QList<Qgis::RasterAttributeTableFieldUsage> usages;
94 usages = mAttributeTable->
usages();
100 if ( mAttributeTable->hasColor() || mAttributeTable->hasRamp() )
102 mColor->setChecked(
false );
103 mColor->setEnabled(
false );
104 mRamp->setChecked(
false );
105 mRamp->setEnabled(
false );
106 mStandardColumn->setChecked(
true );
110 mColor->setEnabled(
true );
111 mRamp->setChecked(
false );
112 mRamp->setEnabled(
false );
116 mColor->setEnabled(
true );
117 mRamp->setEnabled(
true );
120 bool isValid {
true };
121 if ( mStandardColumn->isChecked() )
123 const QString upperName { mName->text().trimmed().toUpper() };
124 if ( upperName.isEmpty() )
126 mError->setText( tr(
"A field name cannot be blank." ) );
130 const QList<QgsRasterAttributeTable::Field> fields { mAttributeTable->fields() };
131 for (
const QgsRasterAttributeTable::Field &f : std::as_const( fields ) )
133 if ( f.name.toUpper() == upperName )
135 mError->setText( tr(
"A field with this name already exists." ) );
144 const int currentUsageIndex { mUsage->currentIndex() };
145 const QSignalBlocker usageBlocker( mUsage );
149 for (
auto it = usageInfo.cbegin(); it != usageInfo.cend(); ++it )
154 if ( !it.value().unique || !usages.contains( it.key() ) )
163 mUsage->setCurrentIndex( std::clamp( currentUsageIndex, 0,
static_cast<int>( mUsage->count() - 1 ) ) );
165 const QList<QgsRasterAttributeTable::Field> fields { mAttributeTable->fields() };
167 int currentIndex { mColumn->currentIndex() };
168 if ( mColumn->currentIndex() < 0 )
170 currentIndex = fields.count() - 1;
173 const QSignalBlocker columnBlocker( mColumn );
175 for (
const QgsRasterAttributeTable::Field &field : std::as_const( fields ) )
177 mColumn->addItem( field.name );
179 mColumn->setCurrentIndex( std::clamp( currentIndex, 0,
static_cast<int>( fields.count() - 1 ) ) );
186 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.
Represents a Raster Attribute Table (RAT).
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.
static QString usageName(const Qgis::RasterAttributeTableFieldUsage fieldusage)
Returns the translated human readable name of fieldUsage.