27#include "moc_qgsloadrasterattributetabledialog.cpp"
29using namespace Qt::StringLiterals;
33 , mRasterLayer( rasterLayer )
37 connect( mButtonBox, &QDialogButtonBox::accepted,
this, &QDialog::accept );
38 connect( mButtonBox, &QDialogButtonBox::rejected,
this, &QDialog::reject );
39 connect( mButtonBox, &QDialogButtonBox::helpRequested,
this, [] {
40 QgsHelp::openHelp( u
"working_with_raster/raster_properties.html#raster-attribute-tables"_s );
47 mRasterBand->setLayer( mRasterLayer );
49 mDbfPathWidget->setFilter( u
"VAT DBF Files (*.vat.dbf)"_s );
58 return mDbfPathWidget->filePath();
63 return mRasterBand->currentBand();
73 return mOpenRat->isChecked();
80 mOpenRat->setChecked(
false );
82 mOpenRat->setVisible( visible );
87 bool success {
false };
95 auto rat = std::make_unique<QgsRasterAttributeTable>();
98 success = rat->readFromFile(
filePath(), &errorMessage );
102 notify( tr(
"Error Loading Raster Attribute Table " ), tr(
"The raster attribute table could not be loaded.\n%1" ).arg( errorMessage ),
Qgis::MessageLevel::Critical );
106 if ( !rat->isValid( &errorMessage ) )
108 switch ( QMessageBox::warning(
nullptr, tr(
"Invalid Raster Attribute Table" ), tr(
"The raster attribute table is not valid:\n%1\nLoad anyway?" ).arg( errorMessage ), QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel ) )
110 case QMessageBox::Cancel:
112 case QMessageBox::Yes:
115 case QMessageBox::No:
124 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 ) )
126 case QMessageBox::Cancel:
128 case QMessageBox::Yes:
131 case QMessageBox::No:
140 mRasterLayer->dataProvider()->setAttributeTable(
rasterBand(), rat.release() );
141 notify( tr(
"Raster Attribute Table Loaded" ), tr(
"The new raster attribute table was successfully loaded." ),
Qgis::MessageLevel::Success );
149void QgsLoadRasterAttributeTableDialog::notify(
const QString &title,
const QString &message,
Qgis::MessageLevel level )
163 QMessageBox::information(
nullptr, title, message );
168 QMessageBox::warning(
nullptr, title, message );
173 QMessageBox::critical(
nullptr, title, message );
180void QgsLoadRasterAttributeTableDialog::updateButtons()
182 const bool isValidPath { !mDbfPathWidget->filePath().isEmpty() && QFile::exists( mDbfPathWidget->filePath() ) };
183 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...
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
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.
Represents a raster layer.