17#include "moc_qgscreaterasterattributetabledialog.cpp"
25 , mRasterLayer( rasterLayer )
27 Q_ASSERT( mRasterLayer );
36 connect( mNativeRadioButton, &QRadioButton::toggled,
this, &QgsCreateRasterAttributeTableDialog::updateButtons );
37 connect( mDbfRadioButton, &QRadioButton::toggled,
this, &QgsCreateRasterAttributeTableDialog::updateButtons );
41 QStringList existingRatsInfo;
44 for (
int bandNo = 1; bandNo <= mRasterLayer->
bandCount(); ++bandNo )
51 nativeRatSupported =
false;
52 existingRatsInfo.push_back( tr(
"The data provider supports attribute table storage but some drivers do not support 'thematic' types, for this reason the option is disabled." ) );
54 if ( !rat->filePath().isEmpty() )
56 existingRatsInfo.push_back( tr(
"Raster band %1 already has an associated attribute table at %2." ).arg( QString::number( bandNo ), rat->filePath() ) );
60 existingRatsInfo.push_back( tr(
"Raster band %1 already has an associated attribute table." ).arg( bandNo ) );
66 if ( !existingRatsInfo.isEmpty() )
68 mCreateInfoLabel->setText( mCreateInfoLabel->text().append( QStringLiteral(
"<br><ul><li>" ) + existingRatsInfo.join( QLatin1String(
"</li><li>" ) ) ).append( QStringLiteral(
"</ul>" ) ) );
69 mCreateInfoLabel->adjustSize();
70 mCreateInfoLabel->show();
73 if ( !nativeRatSupported )
75 mNativeRadioButton->setEnabled(
false );
76 mDbfRadioButton->setChecked(
true );
80 mDbfPathWidget->setFilter( QStringLiteral(
"VAT DBF Files (*.vat.dbf)" ) );
87 connect( mButtonBox, &QDialogButtonBox::accepted,
this, &QDialog::accept );
88 connect( mButtonBox, &QDialogButtonBox::rejected,
this, &QDialog::reject );
97 return mDbfPathWidget->filePath();
102 return mDbfRadioButton->isChecked();
107 return mOpenRat->isChecked();
119 mOpenRat->setChecked(
false );
122 mOpenRat->setVisible( visible );
127 QString errorMessage;
128 int bandNumber { 0 };
130 bool success {
false };
134 notify( tr(
"Error Creating Raster Attribute Table" ), tr(
"The raster attribute table could not be created." ),
Qgis::MessageLevel::Critical );
144 const QString destinationPath {
filePath() };
145 if ( !QFile::exists( destinationPath ) || QMessageBox::warning(
nullptr, tr(
"Confirm Overwrite" ), tr(
"Are you sure you want to overwrite the existing attribute table at '%1'?" ).arg( destinationPath ), QMessageBox::Yes | QMessageBox::No, QMessageBox::No ) == QMessageBox::Yes )
147 success = rat->writeToFile( destinationPath, &errorMessage );
168 notify( tr(
"Raster Attribute Table Saved" ), tr(
"The new Raster Attribute Table was successfully created." ),
Qgis::MessageLevel::Success );
174void QgsCreateRasterAttributeTableDialog::notify(
const QString &title,
const QString &message,
Qgis::MessageLevel level )
188 QMessageBox::information(
nullptr, title, message );
193 QMessageBox::warning(
nullptr, title, message );
198 QMessageBox::critical(
nullptr, title, message );
205void QgsCreateRasterAttributeTableDialog::updateButtons()
207 mDbfPathWidget->setEnabled( mDbfRadioButton->isChecked() );
@ NativeRasterAttributeTable
Indicates that the provider supports native raster attribute table.
MessageLevel
Level for messages This will be used both for message log and message bar in application.
@ Warning
Warning message.
@ Critical
Critical/error message.
@ Info
Information message.
@ Success
Used for reporting a successful operation.
QgsCreateRasterAttributeTableDialog(QgsRasterLayer *rasterLayer, QWidget *parent=nullptr)
Creates a new QgsCreateRasterAttributeTableDialog.
void setOpenWhenDoneVisible(bool visible)
Sets the visibility of the "Open newly created raster attribute table" option to visible,...
QString filePath() const
Returns the file path in case of VAT.DBF save option.
void setMessageBar(QgsMessageBar *bar)
Sets the message bar associated with the widget.
bool openWhenDone() const
Returns true if the option to open the newly created attribute table is checked.
bool saveToFile() const
Returns true if the option to save to a file is selected.
virtual QString dataSourceUri(bool expandAuthConfig=false) const
Gets the data source specification.
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...
A bar for displaying non-blocking messages to the user.
void pushMessage(const QString &text, Qgis::MessageLevel level=Qgis::MessageLevel::Info, int duration=-1)
A convenience method for pushing a message with the specified text to the bar.
The QgsRasterAttributeTable class represents a Raster Attribute Table (RAT).
static QgsRasterAttributeTable * createFromRaster(QgsRasterLayer *rasterLayer, int *bandNumber=nullptr)
Creates a new Raster Attribute Table from a raster layer, the renderer must be Paletted or SingleBand...
virtual bool writeNativeAttributeTable(QString *errorMessage=nullptr)
Writes the native attribute table, optionally reporting any error in errorMessage,...
void setAttributeTable(int bandNumber, QgsRasterAttributeTable *attributeTable)
Set the attribute table to attributeTable for the specified bandNumber, if the attributeTable is null...
virtual Qgis::RasterProviderCapabilities providerCapabilities() const
Returns flags containing the supported capabilities of the data provider.
Represents a raster layer.
bool canCreateRasterAttributeTable()
Returns true if the raster renderer is suitable for creation of a raster attribute table.
QgsRasterAttributeTable * attributeTable(int bandNumber) const
Returns the (possibly NULL) raster attribute table for the given band bandNumber.
int attributeTableCount() const
Returns the number of attribute tables for the raster by counting the number of bands that have an as...
int bandCount() const
Returns the number of bands in this layer.
QgsRasterDataProvider * dataProvider() override
Returns the source data provider.