24 , mRasterLayer( rasterLayer )
26 Q_ASSERT( mRasterLayer );
35 connect( mNativeRadioButton, &QRadioButton::toggled,
this, &QgsCreateRasterAttributeTableDialog::updateButtons );
36 connect( mDbfRadioButton, &QRadioButton::toggled,
this, &QgsCreateRasterAttributeTableDialog::updateButtons );
40 QStringList existingRatsInfo;
43 for (
int bandNo = 1; bandNo <= mRasterLayer->
bandCount(); ++bandNo )
50 nativeRatSupported =
false;
51 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." ) );
53 if ( ! rat->filePath().isEmpty() )
55 existingRatsInfo.push_back( tr(
"Raster band %1 already has an associated attribute table at %2." ).arg( QString::number( bandNo ), rat->filePath() ) );
59 existingRatsInfo.push_back( tr(
"Raster band %1 already has an associated attribute table." ).arg( bandNo ) );
65 if ( ! existingRatsInfo.isEmpty() )
67 mCreateInfoLabel->setText( mCreateInfoLabel->text().append( QStringLiteral(
"<br><ul><li>" ) + existingRatsInfo.join( QLatin1String(
"</li><li>" ) ) ).append( QStringLiteral(
"</ul>" ) ) );
68 mCreateInfoLabel->adjustSize();
69 mCreateInfoLabel->show();
72 if ( ! nativeRatSupported )
74 mNativeRadioButton->setEnabled(
false );
75 mDbfRadioButton->setChecked(
true );
79 mDbfPathWidget->setFilter( QStringLiteral(
"VAT DBF Files (*.vat.dbf)" ) );
86 connect( mButtonBox, &QDialogButtonBox::accepted,
this, &QDialog::accept );
87 connect( mButtonBox, &QDialogButtonBox::rejected,
this, &QDialog::reject );
96 return mDbfPathWidget->filePath();
101 return mDbfRadioButton->isChecked();
106 return mOpenRat->isChecked();
118 mOpenRat->setChecked(
false );
121 mOpenRat->setVisible( visible );
126 QString errorMessage;
127 int bandNumber { 0 };
129 bool success {
false };
133 notify( tr(
"Error Creating Raster Attribute Table" ),
134 tr(
"The raster attribute table could not be created." ),
145 const QString destinationPath {
filePath() };
146 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 )
148 success = rat->writeToFile( destinationPath, &errorMessage );
151 notify( tr(
"Error Saving Raster Attribute Table" ),
163 notify( tr(
"Error Saving Raster Attribute Table" ),
174 notify( tr(
"Raster Attribute Table Saved" ),
175 tr(
"The new Raster Attribute Table was successfully created." ),
182void QgsCreateRasterAttributeTableDialog::notify(
const QString &title,
const QString &message,
Qgis::MessageLevel level )
196 QMessageBox::information(
nullptr, title, message );
201 QMessageBox::warning(
nullptr, title, message );
206 QMessageBox::critical(
nullptr, title, message );
213void QgsCreateRasterAttributeTableDialog::updateButtons()
215 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.