25#include "moc_qgsrasterattributetableaddcolumndialog.cpp"
27using namespace Qt::StringLiterals;
31 , mAttributeTable( attributeTable )
34 Q_ASSERT( mAttributeTable );
38 connect( mName, &QLineEdit::textChanged,
this, [
this](
const QString & ) { updateDialog(); } );
39 connect( mStandardColumn, &QRadioButton::toggled,
this, [
this](
bool ) { updateDialog(); } );
40 connect( mColor, &QRadioButton::toggled,
this, [
this](
bool ) { updateDialog(); } );
41 connect( mUsage, qOverload<int>( &QComboBox::currentIndexChanged ),
this, [
this](
int ) { updateDialog(); } );
42 connect( mButtonBox, &QDialogButtonBox::helpRequested,
this, [] {
QgsHelp::openHelp( u
"working_with_raster/raster_properties.html#raster-attribute-tables"_s ); } );
44 mDataType->addItem(
QgsFields::iconForFieldType( QMetaType::Type::QString ), tr(
"String" ),
static_cast<int>( QMetaType::Type::QString ) );
45 mDataType->addItem(
QgsFields::iconForFieldType( QMetaType::Type::Int ), tr(
"Integer" ),
static_cast<int>( QMetaType::Type::Int ) );
46 mDataType->addItem(
QgsFields::iconForFieldType( QMetaType::Type::LongLong ), tr(
"Long Integer" ),
static_cast<int>( QMetaType::Type::LongLong ) );
47 mDataType->addItem(
QgsFields::iconForFieldType( QMetaType::Type::Double ), tr(
"Double" ),
static_cast<int>( QMetaType::Type::Double ) );
48 mStandardColumn->setChecked(
true );
57 if ( mAfter->isChecked() )
59 return mColumn->currentIndex() + 1;
63 return mColumn->currentIndex();
69 return mColor->isChecked();
74 return mRamp->isChecked();
89 return static_cast<QMetaType::Type
>( mDataType->currentData().toInt() );
92void QgsRasterAttributeTableAddColumnDialog::updateDialog()
94 mDefinition->setEnabled( mStandardColumn->isChecked() );
98 QList<Qgis::RasterAttributeTableFieldUsage> usages;
99 usages = mAttributeTable->
usages();
105 if ( mAttributeTable->hasColor() || mAttributeTable->hasRamp() )
107 mColor->setChecked(
false );
108 mColor->setEnabled(
false );
109 mRamp->setChecked(
false );
110 mRamp->setEnabled(
false );
111 mStandardColumn->setChecked(
true );
115 mColor->setEnabled(
true );
116 mRamp->setChecked(
false );
117 mRamp->setEnabled(
false );
121 mColor->setEnabled(
true );
122 mRamp->setEnabled(
true );
125 bool isValid {
true };
126 if ( mStandardColumn->isChecked() )
128 const QString upperName { mName->text().trimmed().toUpper() };
129 if ( upperName.isEmpty() )
131 mError->setText( tr(
"A field name cannot be blank." ) );
135 const QList<QgsRasterAttributeTable::Field> fields { mAttributeTable->fields() };
136 for (
const QgsRasterAttributeTable::Field &f : std::as_const( fields ) )
138 if ( f.name.toUpper() == upperName )
140 mError->setText( tr(
"A field with this name already exists." ) );
149 const int currentUsageIndex { mUsage->currentIndex() };
150 const QSignalBlocker usageBlocker( mUsage );
154 for (
auto it = usageInfo.cbegin(); it != usageInfo.cend(); ++it )
159 if ( !it.value().unique || !usages.contains( it.key() ) )
164 || ( it.value().isColor )
165 || ( it.value().isRamp ) )
172 mUsage->setCurrentIndex( std::clamp( currentUsageIndex, 0,
static_cast<int>( mUsage->count() - 1 ) ) );
174 const QList<QgsRasterAttributeTable::Field> fields { mAttributeTable->fields() };
176 int currentIndex { mColumn->currentIndex() };
177 if ( mColumn->currentIndex() < 0 )
179 currentIndex = fields.count() - 1;
182 const QSignalBlocker columnBlocker( mColumn );
184 for (
const QgsRasterAttributeTable::Field &field : std::as_const( fields ) )
186 mColumn->addItem( field.name );
188 mColumn->setCurrentIndex( std::clamp( currentIndex, 0,
static_cast<int>( fields.count() - 1 ) ) );
195 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...
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
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.