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, [] {
43 QgsHelp::openHelp( u
"working_with_raster/raster_properties.html#raster-attribute-tables"_s );
46 mDataType->addItem(
QgsFields::iconForFieldType( QMetaType::Type::QString ), tr(
"String" ),
static_cast<int>( QMetaType::Type::QString ) );
47 mDataType->addItem(
QgsFields::iconForFieldType( QMetaType::Type::Int ), tr(
"Integer" ),
static_cast<int>( QMetaType::Type::Int ) );
48 mDataType->addItem(
QgsFields::iconForFieldType( QMetaType::Type::LongLong ), tr(
"Long Integer" ),
static_cast<int>( QMetaType::Type::LongLong ) );
49 mDataType->addItem(
QgsFields::iconForFieldType( QMetaType::Type::Double ), tr(
"Double" ),
static_cast<int>( QMetaType::Type::Double ) );
50 mStandardColumn->setChecked(
true );
59 if ( mAfter->isChecked() )
61 return mColumn->currentIndex() + 1;
65 return mColumn->currentIndex();
71 return mColor->isChecked();
76 return mRamp->isChecked();
91 return static_cast<QMetaType::Type
>( mDataType->currentData().toInt() );
94void QgsRasterAttributeTableAddColumnDialog::updateDialog()
96 mDefinition->setEnabled( mStandardColumn->isChecked() );
100 QList<Qgis::RasterAttributeTableFieldUsage> usages;
101 usages = mAttributeTable->
usages();
107 if ( mAttributeTable->hasColor() || mAttributeTable->hasRamp() )
109 mColor->setChecked(
false );
110 mColor->setEnabled(
false );
111 mRamp->setChecked(
false );
112 mRamp->setEnabled(
false );
113 mStandardColumn->setChecked(
true );
117 mColor->setEnabled(
true );
118 mRamp->setChecked(
false );
119 mRamp->setEnabled(
false );
123 mColor->setEnabled(
true );
124 mRamp->setEnabled(
true );
127 bool isValid {
true };
128 if ( mStandardColumn->isChecked() )
130 const QString upperName { mName->text().trimmed().toUpper() };
131 if ( upperName.isEmpty() )
133 mError->setText( tr(
"A field name cannot be blank." ) );
137 const QList<QgsRasterAttributeTable::Field> fields { mAttributeTable->fields() };
138 for (
const QgsRasterAttributeTable::Field &f : std::as_const( fields ) )
140 if ( f.name.toUpper() == upperName )
142 mError->setText( tr(
"A field with this name already exists." ) );
151 const int currentUsageIndex { mUsage->currentIndex() };
152 const QSignalBlocker usageBlocker( mUsage );
156 for (
auto it = usageInfo.cbegin(); it != usageInfo.cend(); ++it )
161 if ( !it.value().unique || !usages.contains( it.key() ) )
170 mUsage->setCurrentIndex( std::clamp( currentUsageIndex, 0,
static_cast<int>( mUsage->count() - 1 ) ) );
172 const QList<QgsRasterAttributeTable::Field> fields { mAttributeTable->fields() };
174 int currentIndex { mColumn->currentIndex() };
175 if ( mColumn->currentIndex() < 0 )
177 currentIndex = fields.count() - 1;
180 const QSignalBlocker columnBlocker( mColumn );
182 for (
const QgsRasterAttributeTable::Field &field : std::as_const( fields ) )
184 mColumn->addItem( field.name );
186 mColumn->setCurrentIndex( std::clamp( currentIndex, 0,
static_cast<int>( fields.count() - 1 ) ) );
193 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.