25 , mRasterLayer( rasterLayer )
30 connect( mButtonBox, &QDialogButtonBox::accepted,
this, &QDialog::accept );
31 connect( mButtonBox, &QDialogButtonBox::rejected,
this, &QDialog::reject );
38 mRasterBand->setLayer( mRasterLayer );
40 mDbfPathWidget->setFilter( QStringLiteral(
"VAT DBF Files (*.vat.dbf)" ) );
49 return mDbfPathWidget->filePath();
54 return mRasterBand->currentBand();
64 return mOpenRat->isChecked();
71 mOpenRat->setChecked(
false );
73 mOpenRat->setVisible( visible );
78 bool success {
false };
82 notify( tr(
"Invalid Raster Band" ),
83 tr(
"The selected raster band %1 is not valid." ).arg(
rasterBand() ),
88 std::unique_ptr<QgsRasterAttributeTable> rat = std::make_unique<QgsRasterAttributeTable>( );
91 success = rat->readFromFile(
filePath(), &errorMessage );
95 notify( tr(
"Error Loading Raster Attribute Table " ),
96 tr(
"The raster attribute table could not be loaded.\n%1" ).arg( errorMessage ),
101 if ( ! rat->isValid( &errorMessage ) )
103 switch ( QMessageBox::warning(
nullptr, tr(
"Invalid Raster Attribute Table" ), tr(
"The raster attribute table is not valid:\n%1\nLoad anyway?" ), QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel ) )
105 case QMessageBox::Cancel:
107 case QMessageBox::Yes:
110 case QMessageBox::No:
119 switch ( QMessageBox::warning(
nullptr, tr(
"Confirm Attribute Table Replacement" ), tr(
"Raster band %1 already has an associated attribute table loaded from '%2'. Are you sure you want to replace the existing raster attribute table?" ).arg( QString::number(
rasterBand() ), mRasterLayer->
attributeTable(
rasterBand() )->
filePath() ), QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel ) )
121 case QMessageBox::Cancel:
123 case QMessageBox::Yes:
126 case QMessageBox::No:
136 notify( tr(
"Raster Attribute Table Loaded" ),
137 tr(
"The new raster attribute table was successfully loaded." ),
146void QgsLoadRasterAttributeTableDialog::notify(
const QString &title,
const QString &message,
Qgis::MessageLevel level )
160 QMessageBox::information(
nullptr, title, message );
165 QMessageBox::warning(
nullptr, title, message );
170 QMessageBox::critical(
nullptr, title, message );
177void QgsLoadRasterAttributeTableDialog::updateButtons()
179 const bool isValidPath { ! mDbfPathWidget->filePath().isEmpty() &&QFile::exists( mDbfPathWidget->filePath() ) };
180 mButtonBox->button( QDialogButtonBox::StandardButton::Ok )->setEnabled( isValidPath );
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.
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...
bool openWhenDone() const
Returns true if the option to open the newly created attribute table is checked.
int rasterBand()
Returns the raster band associated to the raster attribute table.
QgsLoadRasterAttributeTableDialog(QgsRasterLayer *rasterLayer, QWidget *parent=nullptr)
Creates a new QgsCreateRasterAttributeTableDialog.
QString filePath() const
Returns the file path to VAT.DBF.
void setMessageBar(QgsMessageBar *bar)
Sets the message bar associated with the widget.
void setOpenWhenDoneVisible(bool visible)
Sets the visibility of the "Open newly created raster attribute table" option to visible,...
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.
void setAttributeTable(int bandNumber, QgsRasterAttributeTable *attributeTable)
Set the attribute table to attributeTable for the specified bandNumber, if the attributeTable is null...
Represents a raster layer.
QgsRasterAttributeTable * attributeTable(int bandNumber) const
Returns the (possibly NULL) raster attribute table for the given band bandNumber.
QgsRasterDataProvider * dataProvider() override
Returns the source data provider.