QGIS API Documentation 4.3.0-Master (c8cdfe19d7b)
Loading...
Searching...
No Matches
qgsrasterlayerproperties.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsrasterlayerproperties.cpp - description
3 -------------------
4 begin : 1/1/2004
5 copyright : (C) 2004 Tim Sutton
6 email : tim@linfiniti.com
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
19
20#include <limits>
21#include <typeinfo>
22
23#include "qgsapplication.h"
27#include "qgsdoublevalidator.h"
30#include "qgsexpressionfinder.h"
31#include "qgsfileutils.h"
32#include "qgsgui.h"
33#include "qgshelp.h"
37#include "qgslogger.h"
38#include "qgsmapcanvas.h"
40#include "qgsmaplayerlegend.h"
43#include "qgsmaptip.h"
44#include "qgsmaptoolemitpoint.h"
46#include "qgsmetadatawidget.h"
50#include "qgsproject.h"
51#include "qgsprojectutils.h"
59#include "qgsrasterlayer.h"
61#include "qgsrasterpyramid.h"
62#include "qgsrasterrange.h"
63#include "qgsrasterrenderer.h"
69#include "qgssettings.h"
72#include "qgsvectorlayer.h"
73#include "qgswebframe.h"
74#include "qgswebview.h"
75
76#include <QColorDialog>
77#include <QDesktopServices>
78#include <QFile>
79#include <QFileDialog>
80#include <QHeaderView>
81#include <QLinearGradient>
82#include <QList>
83#include <QMenu>
84#include <QMessageBox>
85#include <QMouseEvent>
86#include <QPainter>
87#include <QPainterPath>
88#include <QPolygonF>
89#include <QRegularExpression>
90#include <QRegularExpressionValidator>
91#include <QScreen>
92#include <QString>
93#include <QTableWidgetItem>
94#include <QTextStream>
95#include <QUrl>
96#include <QVector>
97
98#include "moc_qgsrasterlayerproperties.cpp"
99
100using namespace Qt::StringLiterals;
101
102QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer *lyr, QgsMapCanvas *canvas, QWidget *parent, Qt::WindowFlags fl )
103 : QgsLayerPropertiesDialog( lyr, canvas, u"RasterLayerProperties"_s, parent, fl )
104 // Constant that signals property not used.
105 , TRSTRING_NOT_SET( tr( "Not Set" ) )
106 , mRasterLayer( qobject_cast<QgsRasterLayer *>( lyr ) )
107{
108 mGrayMinimumMaximumEstimated = true;
109 mRGBMinimumMaximumEstimated = true;
110
111 setupUi( this );
112
113 mMetadataViewer = new QgsWebView( this );
114 mMetadataViewer->setOpenLinks( false );
115 connect( mMetadataViewer, &QTextBrowser::anchorClicked, this, &QgsRasterLayerProperties::openUrl );
116 mOptsPage_Information->layout()->addWidget( mMetadataViewer );
117
118 mRasterTransparencyWidget = new QgsRasterTransparencyWidget( mRasterLayer, canvas, this );
119
120 transparencyScrollArea->setWidget( mRasterTransparencyWidget );
121
122 mLabelingWidget = new QgsRasterLabelingWidget( mRasterLayer, canvas, this );
123 QVBoxLayout *vl = new QVBoxLayout();
124 vl->setContentsMargins( 0, 0, 0, 0 );
125 vl->addWidget( mLabelingWidget );
126 mOptsPage_Labeling->setLayout( vl );
127
128 connect( buttonBuildPyramids, &QPushButton::clicked, this, &QgsRasterLayerProperties::buttonBuildPyramids_clicked );
129 connect( mCrsSelector, &QgsProjectionSelectionWidget::crsChanged, this, &QgsRasterLayerProperties::mCrsSelector_crsChanged );
130 connect( mRenderTypeComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsRasterLayerProperties::mRenderTypeComboBox_currentIndexChanged );
131 connect( mResetColorRenderingBtn, &QToolButton::clicked, this, &QgsRasterLayerProperties::mResetColorRenderingBtn_clicked );
132 // QgsOptionsDialogBase handles saving/restoring of geometry, splitter and current tab states,
133 // switching vertical tabs between icon/text to icon-only modes (splitter collapsed to left),
134 // and connecting QDialogButtonBox's accepted/rejected signals to dialog's accept/reject slots
135 initOptionsBase( false );
136 connect( buttonBox, &QDialogButtonBox::helpRequested, this, &QgsRasterLayerProperties::showHelp );
137
138 mSourceGroupBox->hide();
139
140 mBtnStyle = new QPushButton( tr( "Style" ) );
141 buttonBox->addButton( mBtnStyle, QDialogButtonBox::ResetRole );
142
143 connect( lyr->styleManager(), &QgsMapLayerStyleManager::currentStyleChanged, this, &QgsRasterLayerProperties::syncToLayer );
144
145 connect( this, &QDialog::accepted, this, &QgsRasterLayerProperties::apply );
146 connect( this, &QDialog::rejected, this, &QgsRasterLayerProperties::rollback );
147
148 connect( buttonBox->button( QDialogButtonBox::Apply ), &QAbstractButton::clicked, this, &QgsRasterLayerProperties::apply );
149
150 cbxPyramidsFormat->addItem( tr( "External" ), QVariant::fromValue( Qgis::RasterPyramidFormat::GeoTiff ) );
151 cbxPyramidsFormat->addItem( tr( "Internal (if possible)" ), QVariant::fromValue( Qgis::RasterPyramidFormat::Internal ) );
152 cbxPyramidsFormat->addItem( tr( "External (Erdas Imagine)" ), QVariant::fromValue( Qgis::RasterPyramidFormat::Erdas ) );
153
154 // brightness/contrast controls
155 connect( mSliderBrightness, &QAbstractSlider::valueChanged, mBrightnessSpinBox, &QSpinBox::setValue );
156 connect( mBrightnessSpinBox, static_cast<void ( QSpinBox::* )( int )>( &QSpinBox::valueChanged ), mSliderBrightness, &QAbstractSlider::setValue );
157 mBrightnessSpinBox->setClearValue( 0 );
158
159 connect( mSliderContrast, &QAbstractSlider::valueChanged, mContrastSpinBox, &QSpinBox::setValue );
160 connect( mContrastSpinBox, static_cast<void ( QSpinBox::* )( int )>( &QSpinBox::valueChanged ), mSliderContrast, &QAbstractSlider::setValue );
161 mContrastSpinBox->setClearValue( 0 );
162
163 // gamma correction controls
164 connect( mSliderGamma, &QAbstractSlider::valueChanged, this, &QgsRasterLayerProperties::updateGammaSpinBox );
165 connect( mGammaSpinBox, static_cast<void ( QDoubleSpinBox::* )( double )>( &QDoubleSpinBox::valueChanged ), this, &QgsRasterLayerProperties::updateGammaSlider );
166 mGammaSpinBox->setClearValue( 1.0 );
167
168 // Connect saturation slider and spin box
169 connect( sliderSaturation, &QAbstractSlider::valueChanged, spinBoxSaturation, &QSpinBox::setValue );
170 connect( spinBoxSaturation, static_cast<void ( QSpinBox::* )( int )>( &QSpinBox::valueChanged ), sliderSaturation, &QAbstractSlider::setValue );
171 spinBoxSaturation->setClearValue( 0 );
172
173 // Connect colorize strength slider and spin box
174 connect( sliderColorizeStrength, &QAbstractSlider::valueChanged, spinColorizeStrength, &QSpinBox::setValue );
175 connect( spinColorizeStrength, static_cast<void ( QSpinBox::* )( int )>( &QSpinBox::valueChanged ), sliderColorizeStrength, &QAbstractSlider::setValue );
176 spinColorizeStrength->setClearValue( 100 );
177
178 // enable or disable saturation slider and spin box depending on grayscale combo choice
179 connect( comboGrayscale, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsRasterLayerProperties::toggleSaturationControls );
180
181 // enable or disable colorize colorbutton with colorize checkbox
182 connect( mColorizeCheck, &QAbstractButton::toggled, this, &QgsRasterLayerProperties::toggleColorizeControls );
183
184 // enable or disable Build Pyramids button depending on selection in pyramid list
185 connect( lbxPyramidResolutions, &QListWidget::itemSelectionChanged, this, &QgsRasterLayerProperties::toggleBuildPyramidsButton );
186
187 mRefreshSettingsWidget->setLayer( mRasterLayer );
188 mMapLayerServerPropertiesWidget->setHasWfsTitle( false );
189 mMapLayerServerPropertiesWidget->setServerProperties( mRasterLayer->serverProperties() );
190
191 // set up the scale based layer visibility stuff....
192 mScaleRangeWidget->setMapCanvas( mCanvas );
193 chkUseScaleDependentRendering->setChecked( lyr->hasScaleBasedVisibility() );
194 mScaleRangeWidget->setScaleRange( lyr->minimumScale(), lyr->maximumScale() );
195
196 // build GUI components
197 QIcon myPyramidPixmap( QgsApplication::getThemeIcon( "/mIconPyramid.svg" ) );
198 QIcon myNoPyramidPixmap( QgsApplication::getThemeIcon( "/mIconNoPyramid.svg" ) );
199
200 initMapTipPreview();
201
202 if ( !mRasterLayer )
203 {
204 return;
205 }
206
207 mEnableMapTips->setChecked( mRasterLayer->mapTipsEnabled() );
208
209 updateRasterAttributeTableOptionsPage();
210
211 connect( mRasterLayer, &QgsRasterLayer::rendererChanged, this, &QgsRasterLayerProperties::updateRasterAttributeTableOptionsPage );
212
213 connect( mCreateRasterAttributeTableButton, &QPushButton::clicked, this, [this] {
214 if ( mRasterLayer->canCreateRasterAttributeTable() )
215 {
216 // Create the attribute table from the renderer
217 QgsCreateRasterAttributeTableDialog dlg { mRasterLayer };
218 dlg.setOpenWhenDoneVisible( false );
219 if ( dlg.exec() == QDialog::Accepted )
220 {
221 updateRasterAttributeTableOptionsPage();
222 }
223 }
224 } );
225
226 connect( mLoadRasterAttributeTableFromFileButton, &QPushButton::clicked, this, [this] {
227 // Load the attribute table from a VAT.DBF file
228 QgsLoadRasterAttributeTableDialog dlg { mRasterLayer };
229 dlg.setOpenWhenDoneVisible( false );
230 if ( dlg.exec() == QDialog::Accepted )
231 {
232 updateRasterAttributeTableOptionsPage();
233 }
234 } );
235
236 mBackupCrs = mRasterLayer->crs();
237
238 // Handles window modality raising canvas
239 if ( mCanvas && mRasterTransparencyWidget->pixelSelectorTool() )
240 {
241 connect( mRasterTransparencyWidget->pixelSelectorTool(), &QgsMapToolEmitPoint::deactivated, this, [this] {
242 hide();
243 setModal( true );
244 show();
245 raise();
246 activateWindow();
247 } );
248
249 connect( mRasterTransparencyWidget->pbnAddValuesFromDisplay, &QPushButton::clicked, this, [this] {
250 hide();
251 setModal( false );
252
253 // Transfer focus to the canvas to use the selector tool
254 mCanvas->window()->raise();
255 mCanvas->window()->activateWindow();
256 mCanvas->window()->setFocus();
257 } );
258 }
259
260 if ( mCanvas )
261 {
262 mContext = mCanvas->createExpressionContext();
263 }
264 else
265 {
266 mContext
271 }
272
273 // Initialize with layer center
274 mContext << QgsExpressionContextUtils::mapLayerPositionScope( mRasterLayer->extent().center() );
275 mContext << QgsExpressionContextUtils::layerScope( mRasterLayer );
276
277 connect( mInsertExpressionButton, &QAbstractButton::clicked, this, [this] {
278 // Get the linear indexes if the start and end of the selection
279 int selectionStart = mMapTipWidget->selectionStart();
280 int selectionEnd = mMapTipWidget->selectionEnd();
281 QString expression = QgsExpressionFinder::findAndSelectActiveExpression( mMapTipWidget );
282 QgsExpressionBuilderDialog exprDlg( nullptr, expression, this, u"generic"_s, mContext );
283
284 exprDlg.setWindowTitle( tr( "Insert Expression" ) );
285 if ( exprDlg.exec() == QDialog::Accepted && !exprDlg.expressionText().trimmed().isEmpty() )
286 mMapTipWidget->insertText( "[%" + exprDlg.expressionText().trimmed() + "%]" );
287 else // Restore the selection
288 mMapTipWidget->setLinearSelection( selectionStart, selectionEnd );
289 } );
290
291 QgsRasterDataProvider *provider = mRasterLayer->dataProvider();
292
293 // Only do pyramids if dealing directly with GDAL.
294 if ( provider && ( provider->capabilities() & Qgis::RasterInterfaceCapability::BuildPyramids || provider->providerCapabilities() & Qgis::RasterProviderCapability::BuildPyramids ) )
295 {
296 // initialize resampling methods
297 cboResamplingMethod->clear();
298
299 const auto constProviderType = QgsRasterDataProvider::pyramidResamplingMethods( mRasterLayer->providerType() );
300 for ( const QPair<QString, QString> &method : std::as_const( constProviderType ) )
301 {
302 cboResamplingMethod->addItem( method.second, method.first );
303 }
304
305 // keep it in sync with qgsrasterpyramidsoptionwidget.cpp
306 QString prefix = provider->name() + "/driverOptions/_pyramids/";
307 QgsSettings mySettings;
308 QString defaultMethod = mySettings.value( prefix + "resampling", "AVERAGE" ).toString();
309 int idx = cboResamplingMethod->findData( defaultMethod );
310 if ( idx >= 0 )
311 cboResamplingMethod->setCurrentIndex( idx );
312
313
314 // build pyramid list
315 const QList<QgsRasterPyramid> myPyramidList = provider->buildPyramidList();
316
317 for ( const QgsRasterPyramid &pyramid : myPyramidList )
318 {
319 if ( pyramid.getExists() )
320 {
321 lbxPyramidResolutions->addItem( new QListWidgetItem( myPyramidPixmap, QString::number( pyramid.getXDim() ) + u" x "_s + QString::number( pyramid.getYDim() ) ) );
322 }
323 else
324 {
325 lbxPyramidResolutions->addItem( new QListWidgetItem( myNoPyramidPixmap, QString::number( pyramid.getXDim() ) + u" x "_s + QString::number( pyramid.getYDim() ) ) );
326 }
327 }
328 }
329 else
330 {
331 // disable Pyramids tab completely
332 mOptsPage_Pyramids->setEnabled( false );
333 }
334
335 // We can calculate histogram for all data sources but estimated only if
336 // size is unknown - could also be enabled if well supported (estimated histogram
337 // and let user know that it is estimated)
338 if ( !provider || !( provider->capabilities() & Qgis::RasterInterfaceCapability::Size ) )
339 {
340 // disable Histogram tab completely
341 mOptsPage_Histogram->setEnabled( false );
342 }
343
344 QVBoxLayout *layout = new QVBoxLayout( metadataFrame );
345 layout->setContentsMargins( 0, 0, 0, 0 );
346 mMetadataWidget = new QgsMetadataWidget( this, mRasterLayer );
347 mMetadataWidget->layout()->setContentsMargins( 0, 0, 0, 0 );
348 mMetadataWidget->setMapCanvas( mCanvas );
349 layout->addWidget( mMetadataWidget );
350 metadataFrame->setLayout( layout );
351
352 QVBoxLayout *temporalLayout = new QVBoxLayout( temporalFrame );
353 temporalLayout->setContentsMargins( 0, 0, 0, 0 );
354 mTemporalWidget = new QgsRasterLayerTemporalPropertiesWidget( this, mRasterLayer );
355 temporalLayout->addWidget( mTemporalWidget );
356
357 QgsDebugMsgLevel( "Setting crs to " + mRasterLayer->crs().toWkt( Qgis::CrsWktVariant::Preferred ), 2 );
358 QgsDebugMsgLevel( "Setting crs to " + mRasterLayer->crs().userFriendlyIdentifier(), 2 );
359 mCrsSelector->setCrs( mRasterLayer->crs() );
360
361 // Set text for pyramid info box
362 QString pyramidFormat( u"<h2>%1</h2><p>%2 %3 %4</p><b><font color='red'><p>%5</p><p>%6</p>"_s );
363 QString pyramidHeader = tr( "Description" );
364 QString pyramidSentence1 = tr( "Large resolution raster layers can slow navigation in QGIS." );
365 QString pyramidSentence2 = tr(
366 "By creating lower resolution copies of the data (pyramids) performance can be considerably improved as QGIS selects the most suitable resolution to use depending on the level of zoom."
367 );
368 QString pyramidSentence3 = tr( "You must have write access in the directory where the original data is stored to build pyramids." );
369 QString pyramidSentence4 = tr( "Please note that building internal pyramids may alter the original data file and once created they cannot be removed!" );
370 QString pyramidSentence5 = tr( "Please note that building internal pyramids could corrupt your image - always make a backup of your data first!" );
371
372 tePyramidDescription->setHtml( pyramidFormat.arg( pyramidHeader, pyramidSentence1, pyramidSentence2, pyramidSentence3, pyramidSentence4, pyramidSentence5 ) );
373
374 //resampling
375 mResamplingGroupBox->setSaveCheckedState( true );
376 mResamplingUtils.initWidgets( mRasterLayer, mZoomedInResamplingComboBox, mZoomedOutResamplingComboBox, mMaximumOversamplingSpinBox, mCbEarlyResampling );
377 mResamplingUtils.refreshWidgetsFromLayer();
378
379 const QgsRasterRenderer *renderer = mRasterLayer->renderer();
380
381 btnColorizeColor->setColorDialogTitle( tr( "Select Color" ) );
382 btnColorizeColor->setContext( u"symbology"_s );
383
384 // Hue and saturation color control
385 const QgsHueSaturationFilter *hueSaturationFilter = mRasterLayer->hueSaturationFilter();
386 //set hue and saturation controls to current values
387 if ( hueSaturationFilter )
388 {
389 sliderSaturation->setValue( hueSaturationFilter->saturation() );
390 comboGrayscale->setCurrentIndex( ( int ) hueSaturationFilter->grayscaleMode() );
391
392 // Set initial state of saturation controls based on grayscale mode choice
393 toggleSaturationControls( static_cast<int>( hueSaturationFilter->grayscaleMode() ) );
394
395 // Set initial state of colorize controls
396 mColorizeCheck->setChecked( hueSaturationFilter->colorizeOn() );
397 btnColorizeColor->setColor( hueSaturationFilter->colorizeColor() );
398 toggleColorizeControls( hueSaturationFilter->colorizeOn() );
399 sliderColorizeStrength->setValue( hueSaturationFilter->colorizeStrength() );
400 mInvertColorsCheck->setChecked( hueSaturationFilter->invertColors() );
401 }
402
403 //blend mode
404 mBlendModeComboBox->setShowClippingModes( QgsProjectUtils::layerIsContainedInGroupLayer( QgsProject::instance(), mRasterLayer ) );
405 mBlendModeComboBox->setBlendMode( mRasterLayer->blendMode() );
406
407 //transparency band
408 if ( provider )
409 {
410 mRasterTransparencyWidget->cboxTransparencyBand->setShowNotSetOption( true, tr( "None" ) );
411 mRasterTransparencyWidget->cboxTransparencyBand->setLayer( mRasterLayer );
412
413// Alpha band is set in sync()
414#if 0
415 if ( renderer )
416 {
417 QgsDebugMsgLevel( u"alphaBand = %1"_s.arg( renderer->alphaBand() ), 2 );
418 if ( renderer->alphaBand() > 0 )
419 {
420 cboxTransparencyBand->setCurrentIndex( cboxTransparencyBand->findData( renderer->alphaBand() ) );
421 }
422 }
423#endif
424 }
425
426 // create histogram widget
427 mHistogramWidget = nullptr;
428 if ( mOptsPage_Histogram->isEnabled() )
429 {
430 mHistogramWidget = new QgsRasterHistogramWidget( mRasterLayer, mOptsPage_Histogram );
431 mHistogramStackedWidget->addWidget( mHistogramWidget );
432 }
433
434 //insert renderer widgets into registry
443
444 //fill available renderers into combo box
446 mDisableRenderTypeComboBoxCurrentIndexChanged = true;
447 const auto constRenderersList = QgsApplication::rasterRendererRegistry()->renderersList();
448 for ( const QString &name : constRenderersList )
449 {
450 if ( QgsApplication::rasterRendererRegistry()->rendererData( name, entry ) )
451 {
452 if ( ( mRasterLayer->rasterType() != Qgis::RasterLayerType::SingleBandColorData && entry.name != "singlebandcolordata"_L1 )
453 || ( mRasterLayer->rasterType() == Qgis::RasterLayerType::SingleBandColorData && entry.name == "singlebandcolordata"_L1 ) )
454 {
455 mRenderTypeComboBox->addItem( entry.visibleName, entry.name );
456 }
457 }
458 }
459 mDisableRenderTypeComboBoxCurrentIndexChanged = false;
460
461 int widgetIndex = 0;
462 if ( renderer )
463 {
464 QString rendererType = renderer->type();
465 widgetIndex = mRenderTypeComboBox->findData( rendererType );
466 if ( widgetIndex != -1 )
467 {
468 mDisableRenderTypeComboBoxCurrentIndexChanged = true;
469 mRenderTypeComboBox->setCurrentIndex( widgetIndex );
470 mDisableRenderTypeComboBoxCurrentIndexChanged = false;
471 }
472
473 if ( rendererType == "singlebandcolordata"_L1 && mRenderTypeComboBox->count() == 1 )
474 {
475 // no band rendering options for singlebandcolordata, so minimize group box
476 QSizePolicy sizep = mBandRenderingGrpBx->sizePolicy();
477 sizep.setVerticalStretch( 0 );
478 sizep.setVerticalPolicy( QSizePolicy::Maximum );
479 mBandRenderingGrpBx->setSizePolicy( sizep );
480 mBandRenderingGrpBx->updateGeometry();
481 }
482
483 if ( mRasterLayer->providerType() != "wms"_L1 )
484 {
485 mWMSPrintGroupBox->hide();
486 mPublishDataSourceUrlCheckBox->hide();
487 mBackgroundLayerCheckBox->hide();
488 }
489 }
490
491 initializeDataDefinedButton( mRasterTransparencyWidget->mOpacityDDBtn, QgsRasterPipe::Property::RendererOpacity );
492
493 mRenderTypeComboBox_currentIndexChanged( widgetIndex );
494
495 setMetadataWidget( mMetadataWidget, mOptsPage_Metadata );
496
497 QMenu *menuStyle = new QMenu( this );
498 menuStyle->addAction( tr( "Load Style…" ), this, &QgsRasterLayerProperties::loadStyle );
499 menuStyle->addAction( tr( "Save Style…" ), this, &QgsRasterLayerProperties::saveStyleAs );
500 menuStyle->addSeparator();
501 menuStyle->addAction( tr( "Save as Default" ), this, &QgsRasterLayerProperties::saveStyleAsDefault );
502 menuStyle->addAction( tr( "Restore Default" ), this, &QgsRasterLayerProperties::loadDefaultStyle );
503 mBtnStyle->setMenu( menuStyle );
504 connect( menuStyle, &QMenu::aboutToShow, this, &QgsRasterLayerProperties::aboutToShowStyleMenu );
505
506 mBtnMetadata = new QPushButton( tr( "Metadata" ), this );
507 QMenu *menuMetadata = new QMenu( this );
508 mActionLoadMetadata = menuMetadata->addAction( tr( "Load Metadata…" ), this, &QgsRasterLayerProperties::loadMetadataFromFile );
509 mActionSaveMetadataAs = menuMetadata->addAction( tr( "Save Metadata…" ), this, &QgsRasterLayerProperties::saveMetadataToFile );
510 menuMetadata->addSeparator();
511 menuMetadata->addAction( tr( "Save as Default" ), this, &QgsRasterLayerProperties::saveMetadataAsDefault );
512 menuMetadata->addAction( tr( "Restore Default" ), this, &QgsRasterLayerProperties::loadDefaultMetadata );
513 mBtnMetadata->setMenu( menuMetadata );
514 buttonBox->addButton( mBtnMetadata, QDialogButtonBox::ResetRole );
515
516 // update based on lyr's current state
517 sync();
518
519 QgsSettings settings;
520 // if dialog hasn't been opened/closed yet, default to Styles tab, which is used most often
521 // this will be read by restoreOptionsBaseUi()
522 if ( !settings.contains( u"/Windows/RasterLayerProperties/tab"_s ) )
523 {
524 settings.setValue( u"Windows/RasterLayerProperties/tab"_s, mOptStackedWidget->indexOf( mOptsPage_Style ) );
525 }
526
527 mResetColorRenderingBtn->setIcon( QgsApplication::getThemeIcon( u"/mActionUndo.svg"_s ) );
528
529 optionsStackedWidget_CurrentChanged( mOptionsStackedWidget->currentIndex() );
530
531 //Add help page references
532 mOptsPage_Information->setProperty( "helpPage", u"working_with_raster/raster_properties.html#information-properties"_s );
533 mOptsPage_Source->setProperty( "helpPage", u"working_with_raster/raster_properties.html#source-properties"_s );
534 mOptsPage_Style->setProperty( "helpPage", u"working_with_raster/raster_properties.html#symbology-properties"_s );
535 mOptsPage_Transparency->setProperty( "helpPage", u"working_with_raster/raster_properties.html#transparency-properties"_s );
536 mOptsPage_Labeling->setProperty( "helpPage", u"working_with_raster/raster_properties.html#labels-properties"_s );
537
538 if ( mOptsPage_Histogram )
539 mOptsPage_Histogram->setProperty( "helpPage", u"working_with_raster/raster_properties.html#histogram-properties"_s );
540
541 mOptsPage_Rendering->setProperty( "helpPage", u"working_with_raster/raster_properties.html#rendering-properties"_s );
542 mOptsPage_Temporal->setProperty( "helpPage", u"working_with_raster/raster_properties.html#temporal-properties"_s );
543
544 if ( mOptsPage_Pyramids )
545 mOptsPage_Pyramids->setProperty( "helpPage", u"working_with_raster/raster_properties.html#pyramids-properties"_s );
546
547 if ( mOptsPage_Display )
548 mOptsPage_Display->setProperty( "helpPage", u"working_with_raster/raster_properties.html#display-properties"_s );
549
550 mOptsPage_Metadata->setProperty( "helpPage", u"working_with_raster/raster_properties.html#metadata-properties"_s );
551 mOptsPage_Legend->setProperty( "helpPage", u"working_with_raster/raster_properties.html#legend-properties"_s );
552 mOptsPage_RasterAttributeTable->setProperty( "helpPage", u"working_with_raster/raster_properties.html#raster-attribute-tables"_s );
553 mOptsPage_Server->setProperty( "helpPage", u"working_with_raster/raster_properties.html#server-properties"_s );
554
555 initialize();
556}
557
559{
560 if ( !factory->supportsLayer( mRasterLayer ) || !factory->supportLayerPropertiesDialog() )
561 {
562 return;
563 }
564
565 QgsMapLayerConfigWidget *page = factory->createWidget( mRasterLayer, nullptr, false, this );
566 switch ( factory->parentPage() )
567 {
569 {
570 mConfigWidgets << page;
571
572 const QString beforePage = factory->layerPropertiesPagePositionHint();
573 if ( beforePage.isEmpty() )
574 addPage( factory->title(), factory->title(), factory->icon(), page );
575 else
576 insertPage( factory->title(), factory->title(), factory->icon(), page, beforePage );
577 break;
578 }
579
581 mTemporalWidget->addWidget( page );
582 break;
583 }
584}
585
590
591void QgsRasterLayerProperties::updateRasterAttributeTableOptionsPage()
592{
593 if ( mRasterAttributeTableWidget )
594 {
595 mOptsPage_RasterAttributeTable->layout()->removeWidget( mRasterAttributeTableWidget );
596 mRasterAttributeTableWidget = nullptr;
597 }
598
599 // Setup raster attribute table
600 if ( mRasterLayer->attributeTableCount() > 0 )
601 {
602 mRasterAttributeTableWidget = new QgsRasterAttributeTableWidget( this, mRasterLayer );
603 mOptsPage_RasterAttributeTable->layout()->addWidget( mRasterAttributeTableWidget );
604 // When the renderer changes we need to sync the style options page
605 connect( mRasterAttributeTableWidget, &QgsRasterAttributeTableWidget::rendererChanged, this, &QgsRasterLayerProperties::syncToLayer );
606 mNoRasterAttributeTableWidget->hide();
607 }
608 else
609 {
610 mNoRasterAttributeTableWidget->show();
611 mCreateRasterAttributeTableButton->setEnabled( mRasterLayer->canCreateRasterAttributeTable() );
612 }
613}
614
615void QgsRasterLayerProperties::setRendererWidget( const QString &rendererName )
616{
617 QgsDebugMsgLevel( "rendererName = " + rendererName, 3 );
618 QgsRasterRendererWidget *oldWidget = mRendererWidget;
619 QgsRasterRenderer *oldRenderer = mRasterLayer->renderer();
620
621 int alphaBand = -1;
622 double opacity = 1;
623 QColor nodataColor;
624 const QList<int> oldBands = oldRenderer ? oldRenderer->usesBands() : QList<int>();
625 if ( oldRenderer )
626 {
627 // Retain alpha band and opacity when switching renderer
628 alphaBand = oldRenderer->alphaBand();
629 opacity = oldRenderer->opacity();
630 nodataColor = oldRenderer->nodataColor();
631 }
632
633 QgsRasterRendererRegistryEntry rendererEntry;
634 if ( QgsApplication::rasterRendererRegistry()->rendererData( rendererName, rendererEntry ) )
635 {
636 if ( rendererEntry.widgetCreateFunction ) //single band color data renderer e.g. has no widget
637 {
638 QgsDebugMsgLevel( u"renderer has widgetCreateFunction"_s, 3 );
639 // Current canvas extent (used to calc min/max) in layer CRS
640 QgsRectangle myExtent = mCanvas->mapSettings().outputExtentToLayerExtent( mRasterLayer, mCanvas->extent() );
641 if ( oldWidget && ( !oldRenderer || rendererName != oldRenderer->type() ) )
642 {
643 if ( rendererName == "singlebandgray"_L1 )
644 {
645 whileBlocking( mRasterLayer )->setRenderer( QgsApplication::rasterRendererRegistry()->defaultRendererForDrawingStyle( Qgis::RasterDrawingStyle::SingleBandGray, mRasterLayer->dataProvider() ).release() );
646 whileBlocking( mRasterLayer )->setDefaultContrastEnhancement();
647 }
648 else if ( rendererName == "multibandcolor"_L1 )
649 {
650 whileBlocking( mRasterLayer )->setRenderer( QgsApplication::rasterRendererRegistry()->defaultRendererForDrawingStyle( Qgis::RasterDrawingStyle::MultiBandColor, mRasterLayer->dataProvider() ).release() );
651 whileBlocking( mRasterLayer )->setDefaultContrastEnhancement();
652 }
653 }
654 mRasterLayer->renderer()->setAlphaBand( alphaBand );
655 mRasterLayer->renderer()->setOpacity( opacity );
656 mRasterLayer->renderer()->setNodataColor( nodataColor );
657 mRendererWidget = rendererEntry.widgetCreateFunction( mRasterLayer, myExtent );
658 mRendererWidget->setMapCanvas( mCanvas );
659 mRendererStackedWidget->addWidget( mRendererWidget );
660 if ( oldWidget )
661 {
662 //compare used bands in new and old renderer and reset transparency dialog if different
663 std::unique_ptr<QgsRasterRenderer> newRenderer;
664 newRenderer.reset( mRendererWidget->renderer() );
665 const QList<int> newBands = newRenderer->usesBands();
666 if ( oldBands != newBands )
667 {
668 mRasterTransparencyWidget->syncToLayer();
669 }
670 }
671 }
672 }
673
674 const int widgetIndex = mRenderTypeComboBox->findData( rendererName );
675 if ( widgetIndex != -1 )
676 {
677 mDisableRenderTypeComboBoxCurrentIndexChanged = true;
678 mRenderTypeComboBox->setCurrentIndex( widgetIndex );
679 mDisableRenderTypeComboBoxCurrentIndexChanged = false;
680 }
681
682 if ( mRendererWidget != oldWidget )
683 delete oldWidget;
684
685 if ( mHistogramWidget )
686 {
687 mHistogramWidget->setRendererWidget( rendererName, mRendererWidget );
688 }
689}
690
691void QgsRasterLayerProperties::sync()
692{
693 QgsSettings myQSettings;
694
695 if ( !mSourceWidget )
696 {
697 mSourceWidget = QgsGui::sourceWidgetProviderRegistry()->createWidget( mRasterLayer );
698 if ( mSourceWidget )
699 {
700 QHBoxLayout *layout = new QHBoxLayout();
701 layout->addWidget( mSourceWidget );
702 mSourceGroupBox->setLayout( layout );
703 if ( !mSourceWidget->groupTitle().isEmpty() )
704 mSourceGroupBox->setTitle( mSourceWidget->groupTitle() );
705 mSourceGroupBox->show();
706
707 connect( mSourceWidget, &QgsProviderSourceWidget::validChanged, this, [this]( bool isValid ) {
708 buttonBox->button( QDialogButtonBox::Apply )->setEnabled( isValid );
709 buttonBox->button( QDialogButtonBox::Ok )->setEnabled( isValid );
710 } );
711 }
712 }
713
714 if ( mSourceWidget )
715 {
716 mSourceWidget->setMapCanvas( mCanvas );
717 mSourceWidget->setSourceUri( mRasterLayer->source() );
718 }
719
720 const QgsRasterDataProvider *provider = mRasterLayer->dataProvider();
721 if ( !provider )
722 return;
723
724 mRasterTransparencyWidget->syncToLayer();
725 mLabelingWidget->syncToLayer( mRasterLayer );
726
727 if ( provider->dataType( 1 ) == Qgis::DataType::ARGB32 || provider->dataType( 1 ) == Qgis::DataType::ARGB32_Premultiplied )
728 {
729 mRasterTransparencyWidget->gboxNoDataValue->setEnabled( false );
730 mRasterTransparencyWidget->gboxCustomTransparency->setEnabled( false );
731 mOptionsStackedWidget->setCurrentWidget( mOptsPage_Server );
732 }
733
734 // TODO: Wouldn't it be better to just removeWidget() the tabs than delete them? [LS]
736 {
737 if ( mOptsPage_Pyramids )
738 {
739 delete mOptsPage_Pyramids;
740 mOptsPage_Pyramids = nullptr;
741 }
742 }
743
745 {
746 if ( mOptsPage_Histogram )
747 {
748 delete mOptsPage_Histogram;
749 mOptsPage_Histogram = nullptr;
750 delete mHistogramWidget;
751 mHistogramWidget = nullptr;
752 }
753 }
754
755 QgsDebugMsgLevel( u"populate transparency tab"_s, 3 );
756
757 /*
758 * Style tab
759 */
760
761 //set brightness, contrast and gamma
762 QgsBrightnessContrastFilter *brightnessFilter = mRasterLayer->brightnessFilter();
763 if ( brightnessFilter )
764 {
765 mSliderBrightness->setValue( brightnessFilter->brightness() );
766 mSliderContrast->setValue( brightnessFilter->contrast() );
767 mGammaSpinBox->setValue( brightnessFilter->gamma() );
768 }
769
770 // Hue and saturation color control
771 const QgsHueSaturationFilter *hueSaturationFilter = mRasterLayer->hueSaturationFilter();
772 //set hue and saturation controls to current values
773 if ( hueSaturationFilter )
774 {
775 sliderSaturation->setValue( hueSaturationFilter->saturation() );
776 comboGrayscale->setCurrentIndex( ( int ) hueSaturationFilter->grayscaleMode() );
777
778 // Set state of saturation controls based on grayscale mode choice
779 toggleSaturationControls( static_cast<int>( hueSaturationFilter->grayscaleMode() ) );
780
781 // Set state of colorize controls
782 mColorizeCheck->setChecked( hueSaturationFilter->colorizeOn() );
783 btnColorizeColor->setColor( hueSaturationFilter->colorizeColor() );
784 toggleColorizeControls( hueSaturationFilter->colorizeOn() );
785 sliderColorizeStrength->setValue( hueSaturationFilter->colorizeStrength() );
786 mInvertColorsCheck->setChecked( hueSaturationFilter->invertColors() );
787 }
788
789 // Resampling
790 mResamplingUtils.refreshWidgetsFromLayer();
791
792 mRefreshSettingsWidget->syncToLayer();
793 mMapLayerServerPropertiesWidget->sync();
794
795 QgsDebugMsgLevel( u"populate general tab"_s, 3 );
796 /*
797 * General Tab
798 */
799
800 mLayerOrigNameLineEd->setText( mRasterLayer->name() );
801
802 QgsDebugMsgLevel( u"populate metadata tab"_s, 2 );
803 /*
804 * Metadata Tab
805 */
806 //populate the metadata tab's text browser widget with gdal metadata info
807 updateInformationContent();
808
809 mEnableMapTips->setChecked( mRasterLayer->mapTipsEnabled() );
810 mMapTipWidget->setText( mRasterLayer->mapTipTemplate() );
811
812 //WMS print layer
813 QVariant wmsPrintLayer = mRasterLayer->customProperty( u"WMSPrintLayer"_s );
814 if ( wmsPrintLayer.isValid() )
815 {
816 mWMSPrintLayerLineEdit->setText( wmsPrintLayer.toString() );
817 }
818
819 QVariant wmsPublishDataSourceUrl = mRasterLayer->customProperty( u"WMSPublishDataSourceUrl"_s, false );
820 mPublishDataSourceUrlCheckBox->setChecked( wmsPublishDataSourceUrl.toBool() );
821
822 QVariant wmsBackgroundLayer = mRasterLayer->customProperty( u"WMSBackgroundLayer"_s, false );
823 mBackgroundLayerCheckBox->setChecked( wmsBackgroundLayer.toBool() );
824
825 mLegendPlaceholderWidget->setLastPathSettingsKey( u"lastLegendPlaceholderDir"_s );
826 mLegendPlaceholderWidget->setSource( mRasterLayer->legendPlaceholderImage() );
827 mLegendConfigEmbeddedWidget->setLayer( mRasterLayer );
828 mIncludeByDefaultInLayoutLegendsCheck->setChecked( mRasterLayer->legend() && !mRasterLayer->legend()->flags().testFlag( Qgis::MapLayerLegendFlag::ExcludeByDefault ) );
829
830 mTemporalWidget->syncToLayer();
831
832 mPropertyCollection = mRasterLayer->pipe()->dataDefinedProperties();
833 updateDataDefinedButtons();
834
835 for ( QgsMapLayerConfigWidget *page : std::as_const( mConfigWidgets ) )
836 {
837 page->syncToLayer( mRasterLayer );
838 }
839}
840
842{
843 if ( mSourceWidget )
844 {
845 const QString newSource = mSourceWidget->sourceUri();
846 if ( newSource != mRasterLayer->source() )
847 {
848 mRasterLayer->setDataSource( newSource, mRasterLayer->name(), mRasterLayer->providerType(), QgsDataProvider::ProviderOptions() );
849 }
850 }
851
852 // apply all plugin dialogs
853 for ( QgsMapLayerConfigWidget *page : std::as_const( mConfigWidgets ) )
854 {
855 page->apply();
856 }
857
858 /*
859 * Legend Tab
860 */
861 mRasterLayer->setLegendPlaceholderImage( mLegendPlaceholderWidget->source() );
862 mLegendConfigEmbeddedWidget->applyToLayer();
863
864 QgsDebugMsgLevel( u"apply processing symbology tab"_s, 3 );
865 /*
866 * Symbology Tab
867 */
868
869 //set whether the layer histogram should be inverted
870 //mRasterLayer->setInvertHistogram( cboxInvertColorMap->isChecked() );
871
872 if ( mRasterLayer->brightnessFilter() )
873 {
874 mRasterLayer->brightnessFilter()->setBrightness( mSliderBrightness->value() );
875 mRasterLayer->brightnessFilter()->setContrast( mSliderContrast->value() );
876 mRasterLayer->brightnessFilter()->setGamma( mGammaSpinBox->value() );
877 }
878
879 QgsDebugMsgLevel( u"processing transparency tab"_s, 3 );
880 /*
881 * Transparent Pixel Tab
882 */
883
884 mRasterTransparencyWidget->applyToRasterProvider( mRasterLayer->dataProvider() );
885
886 //set renderer from widget
887 QgsRasterRendererWidget *rendererWidget = dynamic_cast<QgsRasterRendererWidget *>( mRendererStackedWidget->currentWidget() );
888 if ( rendererWidget )
889 {
890 rendererWidget->doComputations();
891
892 mRasterLayer->setRenderer( rendererWidget->renderer() );
893 }
894
895 mBackupCrs = mRasterLayer->crs();
896 mMetadataWidget->acceptMetadata();
897 mMetadataFilled = false;
898
899 //transparency settings
900 QgsRasterRenderer *rasterRenderer = mRasterLayer->renderer();
901 mRasterTransparencyWidget->applyToRasterRenderer( rasterRenderer );
902
903 mLabelingWidget->apply();
904
905 if ( rasterRenderer )
906 {
907 // Sync the layer styling widget
908 mRasterLayer->emitStyleChanged();
909 }
910
911 QgsDebugMsgLevel( u"processing general tab"_s, 3 );
912 /*
913 * General Tab
914 */
915 mRasterLayer->setName( mLayerOrigNameLineEd->text() );
916
917 // set up the scale based layer visibility stuff....
918 mRasterLayer->setScaleBasedVisibility( chkUseScaleDependentRendering->isChecked() );
919 mRasterLayer->setMinimumScale( mScaleRangeWidget->minimumScale() );
920 mRasterLayer->setMaximumScale( mScaleRangeWidget->maximumScale() );
921
922 mRefreshSettingsWidget->saveToLayer();
923 if ( mMapLayerServerPropertiesWidget->save() )
924 mMetadataFilled = true;
925
926 //update the legend pixmap
927 // pixmapLegend->setPixmap( mRasterLayer->legendAsPixmap() );
928 // pixmapLegend->setScaledContents( true );
929 // pixmapLegend->repaint();
930
931 mResamplingUtils.refreshLayerFromWidgets();
932
933 // Hue and saturation controls
934 QgsHueSaturationFilter *hueSaturationFilter = mRasterLayer->hueSaturationFilter();
935 if ( hueSaturationFilter )
936 {
937 hueSaturationFilter->setSaturation( sliderSaturation->value() );
938 hueSaturationFilter->setGrayscaleMode( ( QgsHueSaturationFilter::GrayscaleMode ) comboGrayscale->currentIndex() );
939 hueSaturationFilter->setColorizeOn( mColorizeCheck->checkState() );
940 hueSaturationFilter->setColorizeColor( btnColorizeColor->color() );
941 hueSaturationFilter->setColorizeStrength( sliderColorizeStrength->value() );
942 hueSaturationFilter->setInvertColors( mInvertColorsCheck->isChecked() );
943 }
944
945 //set the blend mode for the layer
946 mRasterLayer->setBlendMode( mBlendModeComboBox->blendMode() );
947
948 // Update temporal properties
949 mTemporalWidget->saveTemporalProperties();
950
951 mRasterLayer->setCrs( mCrsSelector->crs() );
952
953 if ( !mWMSPrintLayerLineEdit->text().isEmpty() )
954 {
955 mRasterLayer->setCustomProperty( u"WMSPrintLayer"_s, mWMSPrintLayerLineEdit->text() );
956 }
957
958 mRasterLayer->setCustomProperty( "WMSPublishDataSourceUrl", mPublishDataSourceUrlCheckBox->isChecked() );
959 mRasterLayer->setCustomProperty( "WMSBackgroundLayer", mBackgroundLayerCheckBox->isChecked() );
960
961 mRasterLayer->pipe()->setDataDefinedProperties( mPropertyCollection );
962
963 mRasterLayer->setMapTipsEnabled( mEnableMapTips->isChecked() );
964 mRasterLayer->setMapTipTemplate( mMapTipWidget->text() );
965
966 // Force a redraw of the legend
967 mRasterLayer->setLegend( QgsMapLayerLegend::defaultRasterLegend( mRasterLayer ) );
968 if ( QgsMapLayerLegend *legend = mRasterLayer->legend() )
969 {
970 legend->setFlag( Qgis::MapLayerLegendFlag::ExcludeByDefault, !mIncludeByDefaultInLayoutLegendsCheck->isChecked() );
971 }
972
973 //make sure the layer is redrawn
974 mRasterLayer->triggerRepaint();
975
976 // notify the project we've made a change
978}
979
980void QgsRasterLayerProperties::buttonBuildPyramids_clicked()
981{
982 QgsRasterDataProvider *provider = mRasterLayer->dataProvider();
983
984 auto feedback = std::make_unique<QgsRasterBlockFeedback>();
985
986 connect( feedback.get(), &QgsRasterBlockFeedback::progressChanged, mPyramidProgress, &QProgressBar::setValue );
987 //
988 // Go through the list marking any files that are selected in the listview
989 // as true so that we can generate pyramids for them.
990 //
991 QList<QgsRasterPyramid> myPyramidList = provider->buildPyramidList();
992 for ( int myCounterInt = 0; myCounterInt < lbxPyramidResolutions->count(); myCounterInt++ )
993 {
994 QListWidgetItem *myItem = lbxPyramidResolutions->item( myCounterInt );
995 //mark to be pyramided
996 myPyramidList[myCounterInt].setBuild( myItem->isSelected() || myPyramidList[myCounterInt].getExists() );
997 }
998
999 // keep it in sync with qgsrasterpyramidsoptionwidget.cpp
1000 QString prefix = provider->name() + "/driverOptions/_pyramids/";
1001 QgsSettings mySettings;
1002 QString resamplingMethod( cboResamplingMethod->currentData().toString() );
1003 mySettings.setValue( prefix + "resampling", resamplingMethod );
1004
1005 //
1006 // Ask raster layer to build the pyramids
1007 //
1008
1009 // let the user know we're going to possibly be taking a while
1010 QApplication::setOverrideCursor( Qt::WaitCursor );
1011 QString res = provider->buildPyramids( myPyramidList, resamplingMethod, cbxPyramidsFormat->currentData().value<Qgis::RasterPyramidFormat>(), QStringList(), feedback.get() );
1012 QApplication::restoreOverrideCursor();
1013 mPyramidProgress->setValue( 0 );
1014 buttonBuildPyramids->setEnabled( false );
1015 if ( !res.isNull() )
1016 {
1017 if ( res == "CANCELED"_L1 )
1018 {
1019 // user canceled
1020 }
1021 else if ( res == "ERROR_WRITE_ACCESS"_L1 )
1022 {
1023 QMessageBox::warning( this, tr( "Building Pyramids" ), tr( "Write access denied. Adjust the file permissions and try again." ) );
1024 }
1025 else if ( res == "ERROR_WRITE_FORMAT"_L1 )
1026 {
1027 QMessageBox::warning(
1028 this,
1029 tr( "Building Pyramids" ),
1030 tr(
1031 "The file was not writable. Some formats do not "
1032 "support pyramid overviews. Consult the GDAL documentation if in doubt."
1033 )
1034 );
1035 }
1036 else if ( res == "FAILED_NOT_SUPPORTED"_L1 )
1037 {
1038 QMessageBox::warning( this, tr( "Building Pyramids" ), tr( "Building pyramid overviews is not supported on this type of raster." ) );
1039 }
1040 else if ( res == "ERROR_JPEG_COMPRESSION"_L1 )
1041 {
1042 QMessageBox::warning( this, tr( "Building Pyramids" ), tr( "Building internal pyramid overviews is not supported on raster layers with JPEG compression and your current libtiff library." ) );
1043 }
1044 else if ( res == "ERROR_VIRTUAL"_L1 )
1045 {
1046 QMessageBox::warning( this, tr( "Building Pyramids" ), tr( "Building pyramid overviews is not supported on this type of raster." ) );
1047 }
1048 }
1049
1050 //
1051 // repopulate the pyramids list
1052 //
1053 lbxPyramidResolutions->clear();
1054 // Need to rebuild list as some or all pyramids may have failed to build
1055 myPyramidList = provider->buildPyramidList();
1056 QIcon myPyramidPixmap( QgsApplication::getThemeIcon( "/mIconPyramid.svg" ) );
1057 QIcon myNoPyramidPixmap( QgsApplication::getThemeIcon( "/mIconNoPyramid.svg" ) );
1058
1059 for ( const QgsRasterPyramid &pyramid : std::as_const( myPyramidList ) )
1060 {
1061 if ( pyramid.getExists() )
1062 {
1063 lbxPyramidResolutions->addItem( new QListWidgetItem( myPyramidPixmap, QString::number( pyramid.getXDim() ) + u" x "_s + QString::number( pyramid.getYDim() ) ) );
1064 }
1065 else
1066 {
1067 lbxPyramidResolutions->addItem( new QListWidgetItem( myNoPyramidPixmap, QString::number( pyramid.getXDim() ) + u" x "_s + QString::number( pyramid.getYDim() ) ) );
1068 }
1069 }
1070 //update the legend pixmap
1071 // pixmapLegend->setPixmap( mRasterLayer->legendAsPixmap() );
1072 // pixmapLegend->setScaledContents( true );
1073 // pixmapLegend->repaint();
1074
1075 //populate the metadata tab's text browser widget with gdal metadata info
1076 updateInformationContent();
1077}
1078
1079void QgsRasterLayerProperties::mRenderTypeComboBox_currentIndexChanged( int index )
1080{
1081 if ( index < 0 || mDisableRenderTypeComboBoxCurrentIndexChanged || !mRasterLayer->renderer() )
1082 {
1083 return;
1084 }
1085
1086 QString rendererName = mRenderTypeComboBox->itemData( index ).toString();
1087 setRendererWidget( rendererName );
1088}
1089
1090void QgsRasterLayerProperties::mCrsSelector_crsChanged( const QgsCoordinateReferenceSystem &crs )
1091{
1092 QgsDatumTransformDialog::run( crs, QgsProject::instance()->crs(), this, mCanvas, tr( "Select Transformation" ) );
1093 mRasterLayer->setCrs( crs );
1094 mMetadataWidget->crsChanged();
1095}
1096
1097void QgsRasterLayerProperties::aboutToShowStyleMenu()
1098{
1099 // this should be unified with QgsVectorLayerProperties::aboutToShowStyleMenu()
1100
1101 QMenu *m = qobject_cast<QMenu *>( sender() );
1102
1104 // re-add style manager actions!
1105 m->addSeparator();
1107}
1108
1110{
1111 QgsRasterRenderer *renderer = mRasterLayer->renderer();
1112 if ( renderer )
1113 {
1114 setRendererWidget( renderer->type() );
1115 }
1116 sync();
1117 mRasterLayer->triggerRepaint();
1118}
1119
1121{
1123
1124 if ( !mHistogramWidget )
1125 return;
1126
1127 if ( index == mOptStackedWidget->indexOf( mOptsPage_Histogram ) )
1128 {
1129 mHistogramWidget->setActive( true );
1130 }
1131 else
1132 {
1133 mHistogramWidget->setActive( false );
1134 }
1135
1136 if ( index == mOptStackedWidget->indexOf( mOptsPage_Information ) || !mMetadataFilled )
1137 {
1138 //set the metadata contents (which can be expensive)
1139 updateInformationContent();
1140 }
1141}
1142
1143void QgsRasterLayerProperties::initializeDataDefinedButton( QgsPropertyOverrideButton *button, QgsRasterPipe::Property key )
1144{
1145 button->blockSignals( true );
1146 button->init( static_cast<int>( key ), mPropertyCollection, QgsRasterPipe::propertyDefinitions(), nullptr );
1147 connect( button, &QgsPropertyOverrideButton::changed, this, &QgsRasterLayerProperties::updateProperty );
1148 button->registerExpressionContextGenerator( this );
1149 button->blockSignals( false );
1150}
1151
1152void QgsRasterLayerProperties::updateDataDefinedButtons()
1153{
1154 const QList<QgsPropertyOverrideButton *> propertyOverrideButtons { findChildren<QgsPropertyOverrideButton *>() };
1155 for ( QgsPropertyOverrideButton *button : propertyOverrideButtons )
1156 {
1157 updateDataDefinedButton( button );
1158 }
1159}
1160
1161void QgsRasterLayerProperties::updateDataDefinedButton( QgsPropertyOverrideButton *button )
1162{
1163 if ( !button )
1164 return;
1165
1166 if ( button->propertyKey() < 0 )
1167 return;
1168
1169 QgsRasterPipe::Property key = static_cast<QgsRasterPipe::Property>( button->propertyKey() );
1170 whileBlocking( button )->setToProperty( mPropertyCollection.property( key ) );
1171}
1172
1173void QgsRasterLayerProperties::updateProperty()
1174{
1175 QgsPropertyOverrideButton *button = qobject_cast<QgsPropertyOverrideButton *>( sender() );
1176 QgsRasterPipe::Property key = static_cast<QgsRasterPipe::Property>( button->propertyKey() );
1177 mPropertyCollection.setProperty( key, button->toProperty() );
1178}
1179
1180void QgsRasterLayerProperties::toggleSaturationControls( int grayscaleMode )
1181{
1182 // Enable or disable saturation controls based on choice of grayscale mode
1183 if ( grayscaleMode == 0 )
1184 {
1185 sliderSaturation->setEnabled( true );
1186 spinBoxSaturation->setEnabled( true );
1187 }
1188 else
1189 {
1190 sliderSaturation->setEnabled( false );
1191 spinBoxSaturation->setEnabled( false );
1192 }
1193}
1194
1195void QgsRasterLayerProperties::toggleColorizeControls( bool colorizeEnabled )
1196{
1197 // Enable or disable colorize controls based on checkbox
1198 btnColorizeColor->setEnabled( colorizeEnabled );
1199 sliderColorizeStrength->setEnabled( colorizeEnabled );
1200 spinColorizeStrength->setEnabled( colorizeEnabled );
1201}
1202
1203
1204QLinearGradient QgsRasterLayerProperties::redGradient()
1205{
1206 //define a gradient
1207 // TODO change this to actual polygon dims
1208 QLinearGradient myGradient = QLinearGradient( mGradientWidth, 0, mGradientWidth, mGradientHeight );
1209 myGradient.setColorAt( 0.0, QColor( 242, 14, 25, 190 ) );
1210 myGradient.setColorAt( 0.5, QColor( 175, 29, 37, 190 ) );
1211 myGradient.setColorAt( 1.0, QColor( 114, 17, 22, 190 ) );
1212 return myGradient;
1213}
1214QLinearGradient QgsRasterLayerProperties::greenGradient()
1215{
1216 //define a gradient
1217 // TODO change this to actual polygon dims
1218 QLinearGradient myGradient = QLinearGradient( mGradientWidth, 0, mGradientWidth, mGradientHeight );
1219 myGradient.setColorAt( 0.0, QColor( 48, 168, 5, 190 ) );
1220 myGradient.setColorAt( 0.8, QColor( 36, 122, 4, 190 ) );
1221 myGradient.setColorAt( 1.0, QColor( 21, 71, 2, 190 ) );
1222 return myGradient;
1223}
1224QLinearGradient QgsRasterLayerProperties::blueGradient()
1225{
1226 //define a gradient
1227 // TODO change this to actual polygon dims
1228 QLinearGradient myGradient = QLinearGradient( mGradientWidth, 0, mGradientWidth, mGradientHeight );
1229 myGradient.setColorAt( 0.0, QColor( 30, 0, 106, 190 ) );
1230 myGradient.setColorAt( 0.2, QColor( 30, 72, 128, 190 ) );
1231 myGradient.setColorAt( 1.0, QColor( 30, 223, 196, 190 ) );
1232 return myGradient;
1233}
1234QLinearGradient QgsRasterLayerProperties::grayGradient()
1235{
1236 //define a gradient
1237 // TODO change this to actual polygon dims
1238 QLinearGradient myGradient = QLinearGradient( mGradientWidth, 0, mGradientWidth, mGradientHeight );
1239 myGradient.setColorAt( 0.0, QColor( 5, 5, 5, 190 ) );
1240 myGradient.setColorAt( 0.8, QColor( 122, 122, 122, 190 ) );
1241 myGradient.setColorAt( 1.0, QColor( 220, 220, 220, 190 ) );
1242 return myGradient;
1243}
1244QLinearGradient QgsRasterLayerProperties::highlightGradient()
1245{
1246 //define another gradient for the highlight
1247 // TODO change this to actual polygon dims
1248 QLinearGradient myGradient = QLinearGradient( mGradientWidth, 0, mGradientWidth, mGradientHeight );
1249 myGradient.setColorAt( 1.0, QColor( 255, 255, 255, 50 ) );
1250 myGradient.setColorAt( 0.5, QColor( 255, 255, 255, 100 ) );
1251 myGradient.setColorAt( 0.0, QColor( 255, 255, 255, 150 ) );
1252 return myGradient;
1253}
1254
1255//
1256//
1257// Next four methods for saving and restoring qml style state
1258//
1259//
1260
1265
1266void QgsRasterLayerProperties::restoreWindowModality()
1267{
1268 hide();
1269 setModal( true );
1270 show();
1271 raise();
1272 activateWindow();
1273}
1274
1275void QgsRasterLayerProperties::toggleBuildPyramidsButton()
1276{
1277 if ( lbxPyramidResolutions->selectedItems().empty() )
1278 {
1279 buttonBuildPyramids->setEnabled( false );
1280 }
1281 else
1282 {
1283 buttonBuildPyramids->setEnabled( true );
1284 }
1285}
1286
1287void QgsRasterLayerProperties::mResetColorRenderingBtn_clicked()
1288{
1289 mBlendModeComboBox->setBlendMode( QPainter::CompositionMode_SourceOver );
1290 mSliderBrightness->setValue( 0 );
1291 mSliderContrast->setValue( 0 );
1292 mGammaSpinBox->setValue( 1.0 );
1293 sliderSaturation->setValue( 0 );
1294 comboGrayscale->setCurrentIndex( ( int ) QgsHueSaturationFilter::GrayscaleOff );
1295 mColorizeCheck->setChecked( false );
1296 sliderColorizeStrength->setValue( 100 );
1297 mInvertColorsCheck->setChecked( false );
1298}
1299
1300bool QgsRasterLayerProperties::rasterIsMultiBandColor()
1301{
1302 return mRasterLayer && nullptr != dynamic_cast<QgsMultiBandColorRenderer *>( mRasterLayer->renderer() );
1303}
1304
1305void QgsRasterLayerProperties::updateInformationContent()
1306{
1307 QString myStyle = QgsApplication::reportStyleSheet();
1308 myStyle.append( u"body { margin: 10px; }\n "_s );
1309 mMetadataViewer->clear();
1310 mMetadataViewer->document()->setDefaultStyleSheet( myStyle );
1311 mMetadataViewer->setHtml( mRasterLayer->htmlMetadata() );
1312 mMetadataFilled = true;
1313}
1314
1316{
1317 // Give the user a chance to save the raster attribute table edits.
1318 if ( mRasterAttributeTableWidget && mRasterAttributeTableWidget->isDirty() )
1319 {
1320 mRasterAttributeTableWidget->setEditable( false, false );
1321 }
1323
1324 if ( mBackupCrs != mRasterLayer->crs() )
1325 mRasterLayer->setCrs( mBackupCrs );
1326}
1327
1328void QgsRasterLayerProperties::showHelp()
1329{
1330 const QVariant helpPage = mOptionsStackedWidget->currentWidget()->property( "helpPage" );
1331
1332 if ( helpPage.isValid() )
1333 {
1334 QgsHelp::openHelp( helpPage.toString() );
1335 }
1336 else
1337 {
1338 QgsHelp::openHelp( u"working_with_raster/raster_properties.html"_s );
1339 }
1340}
1341
1342void QgsRasterLayerProperties::updateGammaSpinBox( int value )
1343{
1344 whileBlocking( mGammaSpinBox )->setValue( value / 100.0 );
1345}
1346
1347void QgsRasterLayerProperties::updateGammaSlider( double value )
1348{
1349 whileBlocking( mSliderGamma )->setValue( value * 100 );
1350}
1351
1352
1353bool QgsRasterLayerProperties::eventFilter( QObject *obj, QEvent *ev )
1354{
1355 // If the map tip preview container is resized, resize the map tip
1356 if ( obj == mMapTipPreviewContainer && ev->type() == QEvent::Resize )
1357 {
1358 resizeMapTip();
1359 }
1360 return QgsOptionsDialogBase::eventFilter( obj, ev );
1361}
1362
1363void QgsRasterLayerProperties::initMapTipPreview()
1364{
1365 // HTML editor and preview are in a splitter. By default, the editor takes 2/3 of the space
1366 mMapTipSplitter->setSizes( { 400, 200 } );
1367 // Event filter is used to resize the map tip when the container is resized
1368 mMapTipPreviewContainer->installEventFilter( this );
1369
1370 // Note: there's quite a bit of overlap between this and the code in QgsMapTip::showMapTip
1371 // Create the WebView
1372 mMapTipPreview = new QgsWebView( mMapTipPreviewContainer );
1373 mMapTipPreviewLayout->addWidget( mMapTipPreview );
1374
1375 mMapTipPreview->page()->settings()->setAttribute( QWebSettings::DeveloperExtrasEnabled, true );
1376 mMapTipPreview->page()->settings()->setAttribute( QWebSettings::JavascriptEnabled, true );
1377 mMapTipPreview->page()->settings()->setAttribute( QWebSettings::LocalStorageEnabled, true );
1378
1379 // Disable scrollbars, avoid random resizing issues
1380 mMapTipPreview->page()->mainFrame()->setScrollBarPolicy( Qt::Horizontal, Qt::ScrollBarAlwaysOff );
1381 mMapTipPreview->page()->mainFrame()->setScrollBarPolicy( Qt::Vertical, Qt::ScrollBarAlwaysOff );
1382
1383
1384 // Update the map tip preview when the expression or the map tip template changes
1385 connect( mMapTipWidget, &QgsCodeEditorHTML::textChanged, this, &QgsRasterLayerProperties::updateMapTipPreview );
1386}
1387
1388void QgsRasterLayerProperties::updateMapTipPreview()
1389{
1390 mMapTipPreview->setMaximumSize( mMapTipPreviewContainer->width(), mMapTipPreviewContainer->height() );
1391 const QString htmlContent = QgsMapTip::rasterMapTipPreviewText( mRasterLayer, mCanvas, mMapTipWidget->text() );
1392 mMapTipPreview->setHtml( htmlContent );
1393}
1394
1395void QgsRasterLayerProperties::resizeMapTip()
1396{
1397 // Ensure the map tip is not bigger than the container
1398 mMapTipPreview->setMaximumSize( mMapTipPreviewContainer->width(), mMapTipPreviewContainer->height() );
1399 mMapTipPreview->adjustSize();
1400}
@ BuildPyramids
Supports building of pyramids (overviews) (since QGIS 3.38 – this is a replacement for RasterInterfac...
Definition qgis.h:5462
@ SingleBandColorData
Single band containing color data.
Definition qgis.h:5334
RasterPyramidFormat
Raster pyramid formats.
Definition qgis.h:5369
@ GeoTiff
Geotiff .ovr (external).
Definition qgis.h:5370
@ Erdas
Erdas Image .aux (external).
Definition qgis.h:5372
@ SingleBandGray
A single band image drawn as a range of gray colors.
Definition qgis.h:5348
@ MultiBandColor
A layer containing 2 or more bands, mapped to RGB color space. In the case of a multiband with only t...
Definition qgis.h:5356
@ BuildPyramids
Supports building of pyramids (overviews) (Deprecated since QGIS 3.38 – use RasterProviderCapability:...
Definition qgis.h:5425
@ Size
Original data source size (and thus resolution) is known, it is not always available,...
Definition qgis.h:5422
@ ExcludeByDefault
If set, the layer should not be included in legends by default, and must be manually added by a user.
Definition qgis.h:5080
@ ARGB32_Premultiplied
Color, alpha, red, green, blue, 4 bytes the same as QImage::Format_ARGB32_Premultiplied.
Definition qgis.h:428
@ ARGB32
Color, alpha, red, green, blue, 4 bytes the same as QImage::Format_ARGB32.
Definition qgis.h:427
@ Preferred
Preferred format, matching the most recent WKT ISO standard. Currently an alias to WKT2_2019,...
Definition qgis.h:2631
static QString reportStyleSheet(QgsApplication::StyleSheetType styleSheetType=QgsApplication::StyleSheetType::Qt)
Returns a css style sheet for reports, the styleSheetType argument determines what type of stylesheet...
static QgsRasterRendererRegistry * rasterRendererRegistry()
Returns the application's raster renderer registry, used for managing raster layer renderers.
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
int contrast() const
Returns current contrast level.
int brightness() const
Returns current brightness level.
double gamma() const
Returns current gamma value.
Represents a coordinate reference system (CRS).
A dialog which collects the information required to create a new raster attribute table.
void setOpenWhenDoneVisible(bool visible)
Sets the visibility of the "Open newly created raster attribute table" option to visible,...
virtual QString name() const =0
Returns a provider name.
static bool run(const QgsCoordinateReferenceSystem &sourceCrs=QgsCoordinateReferenceSystem(), const QgsCoordinateReferenceSystem &destinationCrs=QgsCoordinateReferenceSystem(), QWidget *parent=nullptr, QgsMapCanvas *mapCanvas=nullptr, const QString &windowTitle=QString())
Runs the dialog (if required) prompting for the desired transform to use from sourceCrs to destinatio...
A generic dialog for building expression strings.
static std::unique_ptr< QgsExpressionContextScope > globalScope()
Creates a new scope which contains variables and functions relating to the global QGIS context.
static std::unique_ptr< QgsExpressionContextScope > mapLayerPositionScope(const QgsPointXY &position)
Sets the expression context variables which are available for expressions triggered by moving the mou...
static std::unique_ptr< QgsExpressionContextScope > layerScope(const QgsMapLayer *layer)
Creates a new scope which contains variables and functions relating to a QgsMapLayer.
static std::unique_ptr< QgsExpressionContextScope > mapSettingsScope(const QgsMapSettings &mapSettings)
Creates a new scope which contains variables and functions relating to a QgsMapSettings object.
static std::unique_ptr< QgsExpressionContextScope > atlasScope(const QgsLayoutAtlas *atlas)
Creates a new scope which contains variables and functions relating to a QgsLayoutAtlas.
static std::unique_ptr< QgsExpressionContextScope > projectScope(const QgsProject *project)
Creates a new scope which contains variables and functions relating to a QGIS project.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
static QString findAndSelectActiveExpression(QgsCodeEditor *editor, const QString &pattern=QString())
Find the expression under the cursor in the given editor and select it.
void progressChanged(double progress)
Emitted when the feedback object reports a progress change.
static QgsProviderSourceWidgetProviderRegistry * sourceWidgetProviderRegistry()
Returns the registry of provider source widget providers.
Definition qgsgui.cpp:135
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
Definition qgshelp.cpp:41
static QgsRasterRendererWidget * create(QgsRasterLayer *layer, const QgsRectangle &extent)
Factory method to create the renderer for this type.
Color and saturation filter pipe for rasters.
void setColorizeOn(bool colorizeOn)
void setSaturation(int saturation)
bool invertColors() const
Returns true if the filter inverts colors.
void setGrayscaleMode(QgsHueSaturationFilter::GrayscaleMode grayscaleMode)
void setInvertColors(bool invertColors)
Sets whether the filter will invert colors.
QgsHueSaturationFilter::GrayscaleMode grayscaleMode() const
void setColorizeColor(const QColor &colorizeColor)
void setColorizeStrength(int colorizeStrength)
QPushButton * mBtnStyle
Style button.
void saveMetadataToFile()
Allows the user to save the layer's metadata as a file.
virtual void rollback()
Rolls back changes made to the layer.
void optionsStackedWidget_CurrentChanged(int index) override
void saveStyleAsDefault()
Saves the current layer style as the default for the layer.
QList< QgsMapLayerConfigWidget * > mConfigWidgets
Layer config widgets.
void setMetadataWidget(QgsMetadataWidget *widget, QWidget *page)
Sets the metadata widget and page associated with the dialog.
void loadDefaultStyle()
Reloads the default style for the layer.
void saveStyleAs()
Saves a style when appriate button is pressed.
virtual void syncToLayer()=0
Resets the dialog to the current layer state.
void loadStyle()
Triggers a dialog to load a saved style.
QgsMapCanvas * mCanvas
Associated map canvas.
void loadDefaultMetadata()
Reloads the default layer metadata for the layer.
QgsLayerPropertiesDialog(QgsMapLayer *layer, QgsMapCanvas *canvas, const QString &settingsKey, QWidget *parent=nullptr, Qt::WindowFlags fl=Qt::WindowFlags(), QgsSettings *settings=nullptr)
Constructor for QgsLayerPropertiesDialog.
void loadMetadataFromFile()
Allows the user to load layer metadata from a file.
QPushButton * mBtnMetadata
Metadata button.
void initialize()
Initialize the dialog.
void saveMetadataAsDefault()
Saves the current layer metadata as the default for the layer.
void openUrl(const QUrl &url)
Handles opening a url from the dialog.
A dialog allowing selection of a VAT.DBF file and associating the resulting raster attribute table wi...
void setOpenWhenDoneVisible(bool visible)
Sets the visibility of the "Open newly created raster attribute table" option to visible,...
Map canvas is a class for displaying all GIS data types on a canvas.
Factory class for creating custom map layer property pages.
virtual bool supportsLayer(QgsMapLayer *layer) const
Check if the layer is supported for this widget.
virtual QIcon icon() const
The icon that will be shown in the UI for the panel.
virtual QgsMapLayerConfigWidget * createWidget(QgsMapLayer *layer, QgsMapCanvas *canvas, bool dockWidget=true, QWidget *parent=nullptr) const =0
Factory function to create the widget on demand as needed by the dock.
virtual ParentPage parentPage() const
Returns the associated parent page, for factories which create sub-components of a standard page.
virtual QString title() const
The title of the panel.
virtual bool supportLayerPropertiesDialog() const
Flag if widget is supported for use in layer properties dialog.
@ Temporal
Factory creates sub-components of the temporal properties page (only supported for raster layer tempo...
@ NoParent
Factory creates pages itself, not sub-components.
virtual QString layerPropertiesPagePositionHint() const
Returns a tab name hinting at where this page should be inserted into the layer properties tab list.
A panel widget that can be shown in the map style dock.
An abstract interface for implementations of legends for one map layer.
static QgsMapLayerLegend * defaultRasterLegend(QgsRasterLayer *rl)
Create new legend implementation for raster layer.
void removesExtraMenuSeparators(QMenu *m)
removes extra separators from the menu
void addStyleManagerActions(QMenu *m, QgsMapLayer *layer)
adds actions to the menu in accordance to the layer
static QgsMapLayerStyleGuiUtils * instance()
returns a singleton instance of this class
void currentStyleChanged(const QString &currentName)
Emitted when the current style has been changed.
Base class for all map layer types.
Definition qgsmaplayer.h:83
void rendererChanged()
Signal emitted when renderer is changed.
bool hasScaleBasedVisibility() const
Returns whether scale based visibility is enabled for the layer.
double minimumScale() const
Returns the minimum map scale (i.e.
QgsMapLayerStyleManager * styleManager() const
Gets access to the layer's style manager.
double maximumScale() const
Returns the maximum map scale (i.e.
Contains configuration for rendering maps.
static QString rasterMapTipPreviewText(QgsMapLayer *layer, QgsMapCanvas *mapCanvas, const QString &mapTemplate)
Returns the html that would be displayed in a maptip for a given layer.
void deactivated()
Emitted when the map tool is deactivated.
A wizard to edit metadata on a map layer.
static QgsRasterRendererWidget * create(QgsRasterLayer *layer, const QgsRectangle &extent)
void addPage(const QString &title, const QString &tooltip, const QIcon &icon, QWidget *widget, const QStringList &path=QStringList(), const QString &key=QString())
Adds a new page to the dialog pages.
QStackedWidget * mOptStackedWidget
void initOptionsBase(bool restoreUi=true, const QString &title=QString())
Set up the base ui connections for vertical tabs.
void insertPage(const QString &title, const QString &tooltip, const QIcon &icon, QWidget *widget, const QString &before, const QStringList &path=QStringList(), const QString &key=QString())
Inserts a new page into the dialog pages.
static QgsRasterRendererWidget * create(QgsRasterLayer *layer, const QgsRectangle &extent)
static bool layerIsContainedInGroupLayer(QgsProject *project, QgsMapLayer *layer)
Returns true if the specified layer is a child layer from any QgsGroupLayer in the given project.
static QgsProject * instance()
Returns the QgsProject singleton instance.
void setDirty(bool b=true)
Flag the project as dirty (modified).
void crsChanged(const QgsCoordinateReferenceSystem &crs)
Emitted when the selected CRS is changed.
A button for controlling property overrides which may apply to a widget.
QgsProperty toProperty() const
Returns a QgsProperty object encapsulating the current state of the widget.
void changed()
Emitted when property definition changes.
void init(int propertyKey, const QgsProperty &property, const QgsPropertiesDefinition &definitions, const QgsVectorLayer *layer=nullptr, bool auxiliaryStorageEnabled=false)
Initialize a newly constructed property button (useful if button was included in a UI layout).
void registerExpressionContextGenerator(QgsExpressionContextGenerator *generator)
Register an expression context generator class that will be used to retrieve an expression context fo...
int propertyKey() const
Returns the property key linked to the button.
void setToProperty(const QgsProperty &property)
Sets the widget to reflect the current state of a QgsProperty.
QgsProviderSourceWidget * createWidget(QgsMapLayer *layer, QWidget *parent=nullptr)
Creates a new widget to configure the source of the specified layer.
void validChanged(bool isValid)
Emitted whenever the validation status of the widget changes.
static QgsRasterRendererWidget * create(QgsRasterLayer *layer, const QgsRectangle &extent)
Widget creation function (mainly for the use by the renderer registry).
Base class for raster data providers.
virtual QString buildPyramids(const QList< QgsRasterPyramid > &pyramidList, const QString &resamplingMethod="NEAREST", Qgis::RasterPyramidFormat format=Qgis::RasterPyramidFormat::GeoTiff, const QStringList &configOptions=QStringList(), QgsRasterBlockFeedback *feedback=nullptr)
Creates pyramid overviews.
Qgis::DataType dataType(int bandNo) const override=0
Returns data type for the band specified by number.
virtual Qgis::RasterProviderCapabilities providerCapabilities() const
Returns flags containing the supported capabilities of the data provider.
static QList< QPair< QString, QString > > pyramidResamplingMethods(const QString &providerKey)
Returns a list of pyramid resampling method name and label pairs for given provider.
virtual QList< QgsRasterPyramid > buildPyramidList(const QList< int > &overviewList=QList< int >())
Returns the raster layers pyramid list.
A widget for display and configuring a raster layer histogram.
virtual Qgis::RasterInterfaceCapabilities capabilities() const
Returns the capabilities supported by the interface.
Master widget for configuration of labeling of a raster layer.
void addPropertiesPageFactory(const QgsMapLayerConfigWidgetFactory *factory) final
Adds properties page from a factory.
Q_DECL_DEPRECATED void saveDefaultStyle()
Saves the default style when appropriate button is pressed.
QgsRasterLayerProperties(QgsMapLayer *lyr, QgsMapCanvas *canvas, QWidget *parent=nullptr, Qt::WindowFlags=QgsGuiUtils::ModalDialogFlags)
Constructor.
bool eventFilter(QObject *obj, QEvent *ev) override
void optionsStackedWidget_CurrentChanged(int index) final
QgsExpressionContext createExpressionContext() const override
This method needs to be reimplemented in all classes which implement this interface and return an exp...
A widget for configuring the temporal properties for a raster layer.
Represents a raster layer.
QgsRasterDataProvider * dataProvider() override
Returns the source data provider.
Property
Data definable properties.
@ RendererOpacity
Raster renderer global opacity.
static QgsPropertiesDefinition propertyDefinitions()
Returns the definitions for data defined properties available for use in raster pipes.
This struct is used to store pyramid info for the raster layer.
void insertWidgetFunction(const QString &rendererName, QgsRasterRendererWidgetCreateFunc func)
Sets the widget creation function for a renderer.
QStringList renderersList() const
Returns a list of the names of registered renderers.
Abstract base class for widgets which configure a QgsRasterRenderer.
virtual void doComputations()
Load programmatically with current values.
virtual QgsRasterRenderer * renderer()=0
Creates a new renderer, using the properties defined in the widget.
Raster renderer pipe that applies colors to a raster.
QColor nodataColor() const
Returns the color to use for shading nodata pixels.
virtual QString type() const
Returns a unique string representation of the renderer type.
double opacity() const
Returns the opacity for the renderer, where opacity is a value between 0 (totally transparent) and 1....
virtual QList< int > usesBands() const
Returns a list of band numbers used by the renderer.
static QgsRasterRendererWidget * create(QgsRasterLayer *layer, const QgsRectangle &extent)
Widget creation function (use by the renderer registry).
A widget for controlling a raster layer's transparency and related options.
static QgsRasterRendererWidget * create(QgsRasterLayer *layer, const QgsRectangle &extent)
Widget creation function (mainly for the use by the renderer registry).
Stores settings for use within QGIS.
Definition qgssettings.h:68
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
bool contains(const QString &key, QgsSettings::Section section=QgsSettings::NoSection) const
Returns true if there exists a setting called key; returns false otherwise.
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
static QgsRasterRendererWidget * create(QgsRasterLayer *layer, const QgsRectangle &extent)
static QgsRasterRendererWidget * create(QgsRasterLayer *layer, const QgsRectangle &extent)
Creates new raster renderer widget.
A collection of stubs to mimic the API of QWebView on systems where the real library is not available...
Definition qgswebview.h:39
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.
Definition qgis.h:7689
#define QgsDebugMsgLevel(str, level)
Definition qgslogger.h:80
Setting options for creating vector data providers.
Registry for raster renderer entries.
QgsRasterRendererWidgetCreateFunc widgetCreateFunction