75#include <QColorDialog>
76#include <QDesktopServices>
80#include <QLinearGradient>
86#include <QPainterPath>
88#include <QRegularExpression>
89#include <QRegularExpressionValidator>
92#include <QTableWidgetItem>
97#include "moc_qgsrasterlayerproperties.cpp"
99using namespace Qt::StringLiterals;
104 , TRSTRING_NOT_SET( tr(
"Not Set" ) )
107 mGrayMinimumMaximumEstimated =
true;
108 mRGBMinimumMaximumEstimated =
true;
113 mOptsPage_Information->layout()->addWidget( mMetadataViewer );
117 transparencyScrollArea->setWidget( mRasterTransparencyWidget );
120 QVBoxLayout *vl =
new QVBoxLayout();
121 vl->setContentsMargins( 0, 0, 0, 0 );
122 vl->addWidget( mLabelingWidget );
123 mOptsPage_Labeling->setLayout( vl );
125 connect( buttonBuildPyramids, &QPushButton::clicked,
this, &QgsRasterLayerProperties::buttonBuildPyramids_clicked );
127 connect( mRenderTypeComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsRasterLayerProperties::mRenderTypeComboBox_currentIndexChanged );
128 connect( mResetColorRenderingBtn, &QToolButton::clicked,
this, &QgsRasterLayerProperties::mResetColorRenderingBtn_clicked );
133 connect( buttonBox, &QDialogButtonBox::helpRequested,
this, &QgsRasterLayerProperties::showHelp );
135 mSourceGroupBox->hide();
137 mBtnStyle =
new QPushButton( tr(
"Style" ) );
138 buttonBox->addButton(
mBtnStyle, QDialogButtonBox::ResetRole );
152 connect( mSliderBrightness, &QAbstractSlider::valueChanged, mBrightnessSpinBox, &QSpinBox::setValue );
153 connect( mBrightnessSpinBox,
static_cast<void ( QSpinBox::* )(
int )
>( &QSpinBox::valueChanged ), mSliderBrightness, &QAbstractSlider::setValue );
154 mBrightnessSpinBox->setClearValue( 0 );
156 connect( mSliderContrast, &QAbstractSlider::valueChanged, mContrastSpinBox, &QSpinBox::setValue );
157 connect( mContrastSpinBox,
static_cast<void ( QSpinBox::* )(
int )
>( &QSpinBox::valueChanged ), mSliderContrast, &QAbstractSlider::setValue );
158 mContrastSpinBox->setClearValue( 0 );
161 connect( mSliderGamma, &QAbstractSlider::valueChanged,
this, &QgsRasterLayerProperties::updateGammaSpinBox );
162 connect( mGammaSpinBox,
static_cast<void ( QDoubleSpinBox::* )(
double )
>( &QDoubleSpinBox::valueChanged ),
this, &QgsRasterLayerProperties::updateGammaSlider );
163 mGammaSpinBox->setClearValue( 1.0 );
166 connect( sliderSaturation, &QAbstractSlider::valueChanged, spinBoxSaturation, &QSpinBox::setValue );
167 connect( spinBoxSaturation,
static_cast<void ( QSpinBox::* )(
int )
>( &QSpinBox::valueChanged ), sliderSaturation, &QAbstractSlider::setValue );
168 spinBoxSaturation->setClearValue( 0 );
171 connect( sliderColorizeStrength, &QAbstractSlider::valueChanged, spinColorizeStrength, &QSpinBox::setValue );
172 connect( spinColorizeStrength,
static_cast<void ( QSpinBox::* )(
int )
>( &QSpinBox::valueChanged ), sliderColorizeStrength, &QAbstractSlider::setValue );
173 spinColorizeStrength->setClearValue( 100 );
176 connect( comboGrayscale,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsRasterLayerProperties::toggleSaturationControls );
179 connect( mColorizeCheck, &QAbstractButton::toggled,
this, &QgsRasterLayerProperties::toggleColorizeControls );
182 connect( lbxPyramidResolutions, &QListWidget::itemSelectionChanged,
this, &QgsRasterLayerProperties::toggleBuildPyramidsButton );
184 mRefreshSettingsWidget->setLayer( mRasterLayer );
185 mMapLayerServerPropertiesWidget->setHasWfsTitle(
false );
186 mMapLayerServerPropertiesWidget->setServerProperties( mRasterLayer->serverProperties() );
189 mScaleRangeWidget->setMapCanvas(
mCanvas );
204 mEnableMapTips->setChecked( mRasterLayer->mapTipsEnabled() );
206 updateRasterAttributeTableOptionsPage();
210 connect( mCreateRasterAttributeTableButton, &QPushButton::clicked,
this, [
this] {
211 if ( mRasterLayer->canCreateRasterAttributeTable() )
216 if ( dlg.exec() == QDialog::Accepted )
218 updateRasterAttributeTableOptionsPage();
223 connect( mLoadRasterAttributeTableFromFileButton, &QPushButton::clicked,
this, [
this] {
227 if ( dlg.exec() == QDialog::Accepted )
229 updateRasterAttributeTableOptionsPage();
233 mBackupCrs = mRasterLayer->crs();
236 if (
mCanvas && mRasterTransparencyWidget->pixelSelectorTool() )
246 connect( mRasterTransparencyWidget->pbnAddValuesFromDisplay, &QPushButton::clicked,
this, [
this] {
251 mCanvas->window()->raise();
252 mCanvas->window()->activateWindow();
253 mCanvas->window()->setFocus();
259 mContext =
mCanvas->createExpressionContext();
274 connect( mInsertExpressionButton, &QAbstractButton::clicked,
this, [
this] {
276 int selectionStart = mMapTipWidget->selectionStart();
277 int selectionEnd = mMapTipWidget->selectionEnd();
281 exprDlg.setWindowTitle( tr(
"Insert Expression" ) );
282 if ( exprDlg.exec() == QDialog::Accepted && !exprDlg.
expressionText().trimmed().isEmpty() )
283 mMapTipWidget->insertText(
"[%" + exprDlg.
expressionText().trimmed() +
"%]" );
285 mMapTipWidget->setLinearSelection( selectionStart, selectionEnd );
294 cboResamplingMethod->clear();
297 for (
const QPair<QString, QString> &method : std::as_const( constProviderType ) )
299 cboResamplingMethod->addItem( method.second, method.first );
303 QString prefix = provider->name() +
"/driverOptions/_pyramids/";
305 QString defaultMethod = mySettings.
value( prefix +
"resampling",
"AVERAGE" ).toString();
306 int idx = cboResamplingMethod->findData( defaultMethod );
308 cboResamplingMethod->setCurrentIndex( idx );
312 const QList<QgsRasterPyramid> myPyramidList = provider->buildPyramidList();
316 if ( pyramid.getExists() )
318 lbxPyramidResolutions->addItem(
new QListWidgetItem( myPyramidPixmap, QString::number( pyramid.getXDim() ) + u
" x "_s + QString::number( pyramid.getYDim() ) ) );
322 lbxPyramidResolutions->addItem(
new QListWidgetItem( myNoPyramidPixmap, QString::number( pyramid.getXDim() ) + u
" x "_s + QString::number( pyramid.getYDim() ) ) );
329 mOptsPage_Pyramids->setEnabled(
false );
338 mOptsPage_Histogram->setEnabled(
false );
341 QVBoxLayout *layout =
new QVBoxLayout( metadataFrame );
342 layout->setContentsMargins( 0, 0, 0, 0 );
344 mMetadataWidget->layout()->setContentsMargins( 0, 0, 0, 0 );
345 mMetadataWidget->setMapCanvas(
mCanvas );
346 layout->addWidget( mMetadataWidget );
347 metadataFrame->setLayout( layout );
349 QVBoxLayout *temporalLayout =
new QVBoxLayout( temporalFrame );
350 temporalLayout->setContentsMargins( 0, 0, 0, 0 );
352 temporalLayout->addWidget( mTemporalWidget );
355 QgsDebugMsgLevel(
"Setting crs to " + mRasterLayer->crs().userFriendlyIdentifier(), 2 );
356 mCrsSelector->setCrs( mRasterLayer->crs() );
359 QString pyramidFormat( u
"<h2>%1</h2><p>%2 %3 %4</p><b><font color='red'><p>%5</p><p>%6</p>"_s );
360 QString pyramidHeader = tr(
"Description" );
361 QString pyramidSentence1 = tr(
"Large resolution raster layers can slow navigation in QGIS." );
362 QString pyramidSentence2 = tr(
363 "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."
365 QString pyramidSentence3 = tr(
"You must have write access in the directory where the original data is stored to build pyramids." );
366 QString pyramidSentence4 = tr(
"Please note that building internal pyramids may alter the original data file and once created they cannot be removed!" );
367 QString pyramidSentence5 = tr(
"Please note that building internal pyramids could corrupt your image - always make a backup of your data first!" );
369 tePyramidDescription->setHtml( pyramidFormat.arg( pyramidHeader, pyramidSentence1, pyramidSentence2, pyramidSentence3, pyramidSentence4, pyramidSentence5 ) );
372 mResamplingGroupBox->setSaveCheckedState(
true );
373 mResamplingUtils.initWidgets( mRasterLayer, mZoomedInResamplingComboBox, mZoomedOutResamplingComboBox, mMaximumOversamplingSpinBox, mCbEarlyResampling );
374 mResamplingUtils.refreshWidgetsFromLayer();
378 btnColorizeColor->setColorDialogTitle( tr(
"Select Color" ) );
379 btnColorizeColor->setContext( u
"symbology"_s );
384 if ( hueSaturationFilter )
386 sliderSaturation->setValue( hueSaturationFilter->
saturation() );
387 comboGrayscale->setCurrentIndex( (
int ) hueSaturationFilter->
grayscaleMode() );
390 toggleSaturationControls(
static_cast<int>( hueSaturationFilter->
grayscaleMode() ) );
393 mColorizeCheck->setChecked( hueSaturationFilter->
colorizeOn() );
394 btnColorizeColor->setColor( hueSaturationFilter->
colorizeColor() );
395 toggleColorizeControls( hueSaturationFilter->
colorizeOn() );
396 sliderColorizeStrength->setValue( hueSaturationFilter->
colorizeStrength() );
397 mInvertColorsCheck->setChecked( hueSaturationFilter->
invertColors() );
402 mBlendModeComboBox->setBlendMode( mRasterLayer->blendMode() );
407 mRasterTransparencyWidget->cboxTransparencyBand->setShowNotSetOption(
true, tr(
"None" ) );
408 mRasterTransparencyWidget->cboxTransparencyBand->setLayer( mRasterLayer );
417 cboxTransparencyBand->setCurrentIndex( cboxTransparencyBand->findData( renderer->
alphaBand() ) );
424 mHistogramWidget =
nullptr;
425 if ( mOptsPage_Histogram->isEnabled() )
428 mHistogramStackedWidget->addWidget( mHistogramWidget );
442 mDisableRenderTypeComboBoxCurrentIndexChanged =
true;
444 for (
const QString &name : constRenderersList )
455 mDisableRenderTypeComboBoxCurrentIndexChanged =
false;
460 QString rendererType = renderer->
type();
461 widgetIndex = mRenderTypeComboBox->findData( rendererType );
462 if ( widgetIndex != -1 )
464 mDisableRenderTypeComboBoxCurrentIndexChanged =
true;
465 mRenderTypeComboBox->setCurrentIndex( widgetIndex );
466 mDisableRenderTypeComboBoxCurrentIndexChanged =
false;
469 if ( rendererType ==
"singlebandcolordata"_L1 && mRenderTypeComboBox->count() == 1 )
472 QSizePolicy sizep = mBandRenderingGrpBx->sizePolicy();
473 sizep.setVerticalStretch( 0 );
474 sizep.setVerticalPolicy( QSizePolicy::Maximum );
475 mBandRenderingGrpBx->setSizePolicy( sizep );
476 mBandRenderingGrpBx->updateGeometry();
479 if ( mRasterLayer->providerType() !=
"wms"_L1 )
481 mWMSPrintGroupBox->hide();
482 mPublishDataSourceUrlCheckBox->hide();
483 mBackgroundLayerCheckBox->hide();
489 mRenderTypeComboBox_currentIndexChanged( widgetIndex );
493 QMenu *menuStyle =
new QMenu(
this );
496 menuStyle->addSeparator();
500 connect( menuStyle, &QMenu::aboutToShow,
this, &QgsRasterLayerProperties::aboutToShowStyleMenu );
502 mBtnMetadata =
new QPushButton( tr(
"Metadata" ),
this );
503 QMenu *menuMetadata =
new QMenu(
this );
506 menuMetadata->addSeparator();
510 buttonBox->addButton(
mBtnMetadata, QDialogButtonBox::ResetRole );
518 if ( !settings.
contains( u
"/Windows/RasterLayerProperties/tab"_s ) )
528 mOptsPage_Information->setProperty(
"helpPage", u
"working_with_raster/raster_properties.html#information-properties"_s );
529 mOptsPage_Source->setProperty(
"helpPage", u
"working_with_raster/raster_properties.html#source-properties"_s );
530 mOptsPage_Style->setProperty(
"helpPage", u
"working_with_raster/raster_properties.html#symbology-properties"_s );
531 mOptsPage_Transparency->setProperty(
"helpPage", u
"working_with_raster/raster_properties.html#transparency-properties"_s );
532 mOptsPage_Labeling->setProperty(
"helpPage", u
"working_with_raster/raster_properties.html#labels-properties"_s );
534 if ( mOptsPage_Histogram )
535 mOptsPage_Histogram->setProperty(
"helpPage", u
"working_with_raster/raster_properties.html#histogram-properties"_s );
537 mOptsPage_Rendering->setProperty(
"helpPage", u
"working_with_raster/raster_properties.html#rendering-properties"_s );
538 mOptsPage_Temporal->setProperty(
"helpPage", u
"working_with_raster/raster_properties.html#temporal-properties"_s );
540 if ( mOptsPage_Pyramids )
541 mOptsPage_Pyramids->setProperty(
"helpPage", u
"working_with_raster/raster_properties.html#pyramids-properties"_s );
543 if ( mOptsPage_Display )
544 mOptsPage_Display->setProperty(
"helpPage", u
"working_with_raster/raster_properties.html#display-properties"_s );
546 mOptsPage_Metadata->setProperty(
"helpPage", u
"working_with_raster/raster_properties.html#metadata-properties"_s );
547 mOptsPage_Legend->setProperty(
"helpPage", u
"working_with_raster/raster_properties.html#legend-properties"_s );
548 mOptsPage_RasterAttributeTable->setProperty(
"helpPage", u
"working_with_raster/raster_properties.html#raster-attribute-tables"_s );
549 mOptsPage_Server->setProperty(
"helpPage", u
"working_with_raster/raster_properties.html#server-properties"_s );
569 if ( beforePage.isEmpty() )
577 mTemporalWidget->addWidget( page );
587void QgsRasterLayerProperties::updateRasterAttributeTableOptionsPage()
589 if ( mRasterAttributeTableWidget )
591 mOptsPage_RasterAttributeTable->layout()->removeWidget( mRasterAttributeTableWidget );
592 mRasterAttributeTableWidget =
nullptr;
596 if ( mRasterLayer->attributeTableCount() > 0 )
598 mRasterAttributeTableWidget =
new QgsRasterAttributeTableWidget(
this, mRasterLayer );
599 mOptsPage_RasterAttributeTable->layout()->addWidget( mRasterAttributeTableWidget );
602 mNoRasterAttributeTableWidget->hide();
606 mNoRasterAttributeTableWidget->show();
607 mCreateRasterAttributeTableButton->setEnabled( mRasterLayer->canCreateRasterAttributeTable() );
611void QgsRasterLayerProperties::setRendererWidget(
const QString &rendererName )
614 QgsRasterRendererWidget *oldWidget = mRendererWidget;
615 QgsRasterRenderer *oldRenderer = mRasterLayer->renderer();
620 const QList<int> oldBands = oldRenderer ? oldRenderer->
usesBands() : QList<int>();
625 opacity = oldRenderer->
opacity();
629 QgsRasterRendererRegistryEntry rendererEntry;
636 QgsRectangle myExtent =
mCanvas->mapSettings().outputExtentToLayerExtent( mRasterLayer,
mCanvas->extent() );
637 if ( oldWidget && ( !oldRenderer || rendererName != oldRenderer->
type() ) )
639 if ( rendererName ==
"singlebandgray"_L1 )
642 whileBlocking( mRasterLayer )->setDefaultContrastEnhancement();
644 else if ( rendererName ==
"multibandcolor"_L1 )
647 whileBlocking( mRasterLayer )->setDefaultContrastEnhancement();
650 mRasterLayer->renderer()->setAlphaBand( alphaBand );
651 mRasterLayer->renderer()->setOpacity( opacity );
652 mRasterLayer->renderer()->setNodataColor( nodataColor );
654 mRendererWidget->setMapCanvas(
mCanvas );
655 mRendererStackedWidget->addWidget( mRendererWidget );
659 std::unique_ptr<QgsRasterRenderer> newRenderer;
660 newRenderer.reset( mRendererWidget->renderer() );
661 const QList<int> newBands = newRenderer->usesBands();
662 if ( oldBands != newBands )
664 mRasterTransparencyWidget->syncToLayer();
670 const int widgetIndex = mRenderTypeComboBox->findData( rendererName );
671 if ( widgetIndex != -1 )
673 mDisableRenderTypeComboBoxCurrentIndexChanged =
true;
674 mRenderTypeComboBox->setCurrentIndex( widgetIndex );
675 mDisableRenderTypeComboBoxCurrentIndexChanged =
false;
678 if ( mRendererWidget != oldWidget )
681 if ( mHistogramWidget )
683 mHistogramWidget->setRendererWidget( rendererName, mRendererWidget );
687void QgsRasterLayerProperties::sync()
689 QgsSettings myQSettings;
691 if ( !mSourceWidget )
696 QHBoxLayout *layout =
new QHBoxLayout();
697 layout->addWidget( mSourceWidget );
698 mSourceGroupBox->setLayout( layout );
699 if ( !mSourceWidget->groupTitle().isEmpty() )
700 mSourceGroupBox->setTitle( mSourceWidget->groupTitle() );
701 mSourceGroupBox->show();
704 buttonBox->button( QDialogButtonBox::Apply )->setEnabled( isValid );
705 buttonBox->button( QDialogButtonBox::Ok )->setEnabled( isValid );
712 mSourceWidget->setMapCanvas(
mCanvas );
713 mSourceWidget->setSourceUri( mRasterLayer->source() );
716 const QgsRasterDataProvider *provider = mRasterLayer->dataProvider();
720 mRasterTransparencyWidget->syncToLayer();
721 mLabelingWidget->syncToLayer( mRasterLayer );
725 mRasterTransparencyWidget->gboxNoDataValue->setEnabled(
false );
726 mRasterTransparencyWidget->gboxCustomTransparency->setEnabled(
false );
727 mOptionsStackedWidget->setCurrentWidget( mOptsPage_Server );
733 if ( mOptsPage_Pyramids )
735 delete mOptsPage_Pyramids;
736 mOptsPage_Pyramids =
nullptr;
742 if ( mOptsPage_Histogram )
744 delete mOptsPage_Histogram;
745 mOptsPage_Histogram =
nullptr;
746 delete mHistogramWidget;
747 mHistogramWidget =
nullptr;
758 QgsBrightnessContrastFilter *brightnessFilter = mRasterLayer->brightnessFilter();
759 if ( brightnessFilter )
761 mSliderBrightness->setValue( brightnessFilter->
brightness() );
762 mSliderContrast->setValue( brightnessFilter->
contrast() );
763 mGammaSpinBox->setValue( brightnessFilter->
gamma() );
767 const QgsHueSaturationFilter *hueSaturationFilter = mRasterLayer->hueSaturationFilter();
769 if ( hueSaturationFilter )
771 sliderSaturation->setValue( hueSaturationFilter->
saturation() );
772 comboGrayscale->setCurrentIndex( (
int ) hueSaturationFilter->
grayscaleMode() );
775 toggleSaturationControls(
static_cast<int>( hueSaturationFilter->
grayscaleMode() ) );
778 mColorizeCheck->setChecked( hueSaturationFilter->
colorizeOn() );
779 btnColorizeColor->setColor( hueSaturationFilter->
colorizeColor() );
780 toggleColorizeControls( hueSaturationFilter->
colorizeOn() );
781 sliderColorizeStrength->setValue( hueSaturationFilter->
colorizeStrength() );
782 mInvertColorsCheck->setChecked( hueSaturationFilter->
invertColors() );
786 mResamplingUtils.refreshWidgetsFromLayer();
788 mRefreshSettingsWidget->syncToLayer();
789 mMapLayerServerPropertiesWidget->sync();
796 mLayerOrigNameLineEd->setText( mRasterLayer->name() );
803 updateInformationContent();
805 mEnableMapTips->setChecked( mRasterLayer->mapTipsEnabled() );
806 mMapTipWidget->setText( mRasterLayer->mapTipTemplate() );
809 QVariant wmsPrintLayer = mRasterLayer->customProperty( u
"WMSPrintLayer"_s );
810 if ( wmsPrintLayer.isValid() )
812 mWMSPrintLayerLineEdit->setText( wmsPrintLayer.toString() );
815 QVariant wmsPublishDataSourceUrl = mRasterLayer->customProperty( u
"WMSPublishDataSourceUrl"_s,
false );
816 mPublishDataSourceUrlCheckBox->setChecked( wmsPublishDataSourceUrl.toBool() );
818 QVariant wmsBackgroundLayer = mRasterLayer->customProperty( u
"WMSBackgroundLayer"_s,
false );
819 mBackgroundLayerCheckBox->setChecked( wmsBackgroundLayer.toBool() );
821 mLegendPlaceholderWidget->setLastPathSettingsKey( u
"lastLegendPlaceholderDir"_s );
822 mLegendPlaceholderWidget->setSource( mRasterLayer->legendPlaceholderImage() );
823 mLegendConfigEmbeddedWidget->setLayer( mRasterLayer );
826 mTemporalWidget->syncToLayer();
828 mPropertyCollection = mRasterLayer->pipe()->dataDefinedProperties();
829 updateDataDefinedButtons();
831 for ( QgsMapLayerConfigWidget *page : std::as_const(
mConfigWidgets ) )
833 page->syncToLayer( mRasterLayer );
841 const QString newSource = mSourceWidget->sourceUri();
842 if ( newSource != mRasterLayer->source() )
849 if ( !mRasterLayer->isValid() )
862 mRasterLayer->setLegendPlaceholderImage( mLegendPlaceholderWidget->source() );
863 mLegendConfigEmbeddedWidget->applyToLayer();
873 mRasterLayer->brightnessFilter()->setBrightness( mSliderBrightness->value() );
874 mRasterLayer->brightnessFilter()->setContrast( mSliderContrast->value() );
875 mRasterLayer->brightnessFilter()->setGamma( mGammaSpinBox->value() );
882 mRasterTransparencyWidget->applyToRasterProvider( mRasterLayer->dataProvider() );
886 if ( rendererWidget )
890 mRasterLayer->setRenderer( rendererWidget->
renderer() );
893 mBackupCrs = mRasterLayer->crs();
894 mMetadataWidget->acceptMetadata();
895 mMetadataFilled =
false;
899 mRasterTransparencyWidget->applyToRasterRenderer( rasterRenderer );
901 mLabelingWidget->apply();
903 if ( rasterRenderer )
906 mRasterLayer->emitStyleChanged();
913 mRasterLayer->setName( mLayerOrigNameLineEd->text() );
916 mRasterLayer->setScaleBasedVisibility( chkUseScaleDependentRendering->isChecked() );
917 mRasterLayer->setMinimumScale( mScaleRangeWidget->minimumScale() );
918 mRasterLayer->setMaximumScale( mScaleRangeWidget->maximumScale() );
920 mRefreshSettingsWidget->saveToLayer();
921 if ( mMapLayerServerPropertiesWidget->save() )
922 mMetadataFilled =
true;
929 mResamplingUtils.refreshLayerFromWidgets();
933 if ( hueSaturationFilter )
935 hueSaturationFilter->
setSaturation( sliderSaturation->value() );
937 hueSaturationFilter->
setColorizeOn( mColorizeCheck->checkState() );
940 hueSaturationFilter->
setInvertColors( mInvertColorsCheck->isChecked() );
944 mRasterLayer->setBlendMode( mBlendModeComboBox->blendMode() );
947 mTemporalWidget->saveTemporalProperties();
949 mRasterLayer->setCrs( mCrsSelector->crs() );
951 if ( !mWMSPrintLayerLineEdit->text().isEmpty() )
953 mRasterLayer->setCustomProperty( u
"WMSPrintLayer"_s, mWMSPrintLayerLineEdit->text() );
956 mRasterLayer->setCustomProperty(
"WMSPublishDataSourceUrl", mPublishDataSourceUrlCheckBox->isChecked() );
957 mRasterLayer->setCustomProperty(
"WMSBackgroundLayer", mBackgroundLayerCheckBox->isChecked() );
959 mRasterLayer->pipe()->setDataDefinedProperties( mPropertyCollection );
961 mRasterLayer->setMapTipsEnabled( mEnableMapTips->isChecked() );
962 mRasterLayer->setMapTipTemplate( mMapTipWidget->text() );
972 mRasterLayer->triggerRepaint();
978void QgsRasterLayerProperties::buttonBuildPyramids_clicked()
982 auto feedback = std::make_unique<QgsRasterBlockFeedback>();
990 for (
int myCounterInt = 0; myCounterInt < lbxPyramidResolutions->count(); myCounterInt++ )
992 QListWidgetItem *myItem = lbxPyramidResolutions->item( myCounterInt );
994 myPyramidList[myCounterInt].setBuild( myItem->isSelected() || myPyramidList[myCounterInt].getExists() );
998 QString prefix = provider->
name() +
"/driverOptions/_pyramids/";
999 QgsSettings mySettings;
1000 QString resamplingMethod( cboResamplingMethod->currentData().toString() );
1001 mySettings.
setValue( prefix +
"resampling", resamplingMethod );
1008 QApplication::setOverrideCursor( Qt::WaitCursor );
1010 QApplication::restoreOverrideCursor();
1011 mPyramidProgress->setValue( 0 );
1012 buttonBuildPyramids->setEnabled(
false );
1013 if ( !res.isNull() )
1015 if ( res ==
"CANCELED"_L1 )
1019 else if ( res ==
"ERROR_WRITE_ACCESS"_L1 )
1021 QMessageBox::warning(
this, tr(
"Building Pyramids" ), tr(
"Write access denied. Adjust the file permissions and try again." ) );
1023 else if ( res ==
"ERROR_WRITE_FORMAT"_L1 )
1025 QMessageBox::warning(
1027 tr(
"Building Pyramids" ),
1029 "The file was not writable. Some formats do not "
1030 "support pyramid overviews. Consult the GDAL documentation if in doubt."
1034 else if ( res ==
"FAILED_NOT_SUPPORTED"_L1 )
1036 QMessageBox::warning(
this, tr(
"Building Pyramids" ), tr(
"Building pyramid overviews is not supported on this type of raster." ) );
1038 else if ( res ==
"ERROR_JPEG_COMPRESSION"_L1 )
1040 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." ) );
1042 else if ( res ==
"ERROR_VIRTUAL"_L1 )
1044 QMessageBox::warning(
this, tr(
"Building Pyramids" ), tr(
"Building pyramid overviews is not supported on this type of raster." ) );
1051 lbxPyramidResolutions->clear();
1057 for (
const QgsRasterPyramid &pyramid : std::as_const( myPyramidList ) )
1059 if ( pyramid.getExists() )
1061 lbxPyramidResolutions->addItem(
new QListWidgetItem( myPyramidPixmap, QString::number( pyramid.getXDim() ) + u
" x "_s + QString::number( pyramid.getYDim() ) ) );
1065 lbxPyramidResolutions->addItem(
new QListWidgetItem( myNoPyramidPixmap, QString::number( pyramid.getXDim() ) + u
" x "_s + QString::number( pyramid.getYDim() ) ) );
1074 updateInformationContent();
1077void QgsRasterLayerProperties::mRenderTypeComboBox_currentIndexChanged(
int index )
1079 if ( index < 0 || mDisableRenderTypeComboBoxCurrentIndexChanged || !mRasterLayer->renderer() )
1084 QString rendererName = mRenderTypeComboBox->itemData( index ).toString();
1085 setRendererWidget( rendererName );
1091 mRasterLayer->setCrs( crs );
1092 mMetadataWidget->crsChanged();
1095void QgsRasterLayerProperties::aboutToShowStyleMenu()
1099 QMenu *m = qobject_cast<QMenu *>( sender() );
1109 QgsRasterRenderer *renderer = mRasterLayer->renderer();
1112 setRendererWidget( renderer->
type() );
1115 mRasterLayer->triggerRepaint();
1122 if ( !mHistogramWidget )
1127 mHistogramWidget->setActive(
true );
1131 mHistogramWidget->setActive(
false );
1134 if ( index ==
mOptStackedWidget->indexOf( mOptsPage_Information ) || !mMetadataFilled )
1137 updateInformationContent();
1143 button->blockSignals(
true );
1147 button->blockSignals(
false );
1150void QgsRasterLayerProperties::updateDataDefinedButtons()
1152 const QList<QgsPropertyOverrideButton *> propertyOverrideButtons { findChildren<QgsPropertyOverrideButton *>() };
1153 for ( QgsPropertyOverrideButton *button : propertyOverrideButtons )
1155 updateDataDefinedButton( button );
1171void QgsRasterLayerProperties::updateProperty()
1173 QgsPropertyOverrideButton *button = qobject_cast<QgsPropertyOverrideButton *>( sender() );
1175 mPropertyCollection.setProperty( key, button->
toProperty() );
1178void QgsRasterLayerProperties::toggleSaturationControls(
int grayscaleMode )
1181 if ( grayscaleMode == 0 )
1183 sliderSaturation->setEnabled(
true );
1184 spinBoxSaturation->setEnabled(
true );
1188 sliderSaturation->setEnabled(
false );
1189 spinBoxSaturation->setEnabled(
false );
1193void QgsRasterLayerProperties::toggleColorizeControls(
bool colorizeEnabled )
1196 btnColorizeColor->setEnabled( colorizeEnabled );
1197 sliderColorizeStrength->setEnabled( colorizeEnabled );
1198 spinColorizeStrength->setEnabled( colorizeEnabled );
1202QLinearGradient QgsRasterLayerProperties::redGradient()
1206 QLinearGradient myGradient = QLinearGradient( mGradientWidth, 0, mGradientWidth, mGradientHeight );
1207 myGradient.setColorAt( 0.0, QColor( 242, 14, 25, 190 ) );
1208 myGradient.setColorAt( 0.5, QColor( 175, 29, 37, 190 ) );
1209 myGradient.setColorAt( 1.0, QColor( 114, 17, 22, 190 ) );
1212QLinearGradient QgsRasterLayerProperties::greenGradient()
1216 QLinearGradient myGradient = QLinearGradient( mGradientWidth, 0, mGradientWidth, mGradientHeight );
1217 myGradient.setColorAt( 0.0, QColor( 48, 168, 5, 190 ) );
1218 myGradient.setColorAt( 0.8, QColor( 36, 122, 4, 190 ) );
1219 myGradient.setColorAt( 1.0, QColor( 21, 71, 2, 190 ) );
1222QLinearGradient QgsRasterLayerProperties::blueGradient()
1226 QLinearGradient myGradient = QLinearGradient( mGradientWidth, 0, mGradientWidth, mGradientHeight );
1227 myGradient.setColorAt( 0.0, QColor( 30, 0, 106, 190 ) );
1228 myGradient.setColorAt( 0.2, QColor( 30, 72, 128, 190 ) );
1229 myGradient.setColorAt( 1.0, QColor( 30, 223, 196, 190 ) );
1232QLinearGradient QgsRasterLayerProperties::grayGradient()
1236 QLinearGradient myGradient = QLinearGradient( mGradientWidth, 0, mGradientWidth, mGradientHeight );
1237 myGradient.setColorAt( 0.0, QColor( 5, 5, 5, 190 ) );
1238 myGradient.setColorAt( 0.8, QColor( 122, 122, 122, 190 ) );
1239 myGradient.setColorAt( 1.0, QColor( 220, 220, 220, 190 ) );
1242QLinearGradient QgsRasterLayerProperties::highlightGradient()
1246 QLinearGradient myGradient = QLinearGradient( mGradientWidth, 0, mGradientWidth, mGradientHeight );
1247 myGradient.setColorAt( 1.0, QColor( 255, 255, 255, 50 ) );
1248 myGradient.setColorAt( 0.5, QColor( 255, 255, 255, 100 ) );
1249 myGradient.setColorAt( 0.0, QColor( 255, 255, 255, 150 ) );
1264void QgsRasterLayerProperties::restoreWindowModality()
1273void QgsRasterLayerProperties::toggleBuildPyramidsButton()
1275 if ( lbxPyramidResolutions->selectedItems().empty() )
1277 buttonBuildPyramids->setEnabled(
false );
1281 buttonBuildPyramids->setEnabled(
true );
1285void QgsRasterLayerProperties::mResetColorRenderingBtn_clicked()
1287 mBlendModeComboBox->setBlendMode( QPainter::CompositionMode_SourceOver );
1288 mSliderBrightness->setValue( 0 );
1289 mSliderContrast->setValue( 0 );
1290 mGammaSpinBox->setValue( 1.0 );
1291 sliderSaturation->setValue( 0 );
1293 mColorizeCheck->setChecked(
false );
1294 sliderColorizeStrength->setValue( 100 );
1295 mInvertColorsCheck->setChecked(
false );
1298bool QgsRasterLayerProperties::rasterIsMultiBandColor()
1300 return mRasterLayer &&
nullptr !=
dynamic_cast<QgsMultiBandColorRenderer *
>( mRasterLayer->renderer() );
1303void QgsRasterLayerProperties::updateInformationContent()
1307 const QString html { mRasterLayer->htmlMetadata().replace(
"<head>"_L1, QStringLiteral( R
"raw(<head><style type="text/css">%1</style>)raw" ) ).arg( myStyle ) };
1308 mMetadataViewer->setHtml( html );
1309 mMetadataFilled = true;
1315 if ( mRasterAttributeTableWidget && mRasterAttributeTableWidget->isDirty() )
1317 mRasterAttributeTableWidget->setEditable(
false,
false );
1321 if ( mBackupCrs != mRasterLayer->crs() )
1322 mRasterLayer->setCrs( mBackupCrs );
1325void QgsRasterLayerProperties::showHelp()
1327 const QVariant helpPage = mOptionsStackedWidget->currentWidget()->property(
"helpPage" );
1329 if ( helpPage.isValid() )
1339void QgsRasterLayerProperties::updateGammaSpinBox(
int value )
1344void QgsRasterLayerProperties::updateGammaSlider(
double value )
1353 if ( obj == mMapTipPreviewContainer && ev->type() == QEvent::Resize )
1357 return QgsOptionsDialogBase::eventFilter( obj, ev );
1360void QgsRasterLayerProperties::initMapTipPreview()
1363 mMapTipSplitter->setSizes( { 400, 200 } );
1365 mMapTipPreviewContainer->installEventFilter(
this );
1369 mMapTipPreview =
new QgsWebView( mMapTipPreviewContainer );
1370 mMapTipPreviewLayout->addWidget( mMapTipPreview );
1372 mMapTipPreview->page()->settings()->setAttribute( QWebSettings::DeveloperExtrasEnabled,
true );
1373 mMapTipPreview->page()->settings()->setAttribute( QWebSettings::JavascriptEnabled,
true );
1374 mMapTipPreview->page()->settings()->setAttribute( QWebSettings::LocalStorageEnabled,
true );
1377 mMapTipPreview->page()->mainFrame()->setScrollBarPolicy( Qt::Horizontal, Qt::ScrollBarAlwaysOff );
1378 mMapTipPreview->page()->mainFrame()->setScrollBarPolicy( Qt::Vertical, Qt::ScrollBarAlwaysOff );
1382 connect( mMapTipWidget, &QgsCodeEditorHTML::textChanged,
this, &QgsRasterLayerProperties::updateMapTipPreview );
1385void QgsRasterLayerProperties::updateMapTipPreview()
1387 mMapTipPreview->setMaximumSize( mMapTipPreviewContainer->width(), mMapTipPreviewContainer->height() );
1389 mMapTipPreview->setHtml( htmlContent );
1392void QgsRasterLayerProperties::resizeMapTip()
1395 mMapTipPreview->setMaximumSize( mMapTipPreviewContainer->width(), mMapTipPreviewContainer->height() );
1396 mMapTipPreview->adjustSize();
@ BuildPyramids
Supports building of pyramids (overviews) (since QGIS 3.38 – this is a replacement for RasterInterfac...
@ SingleBandColorData
Single band containing color data.
RasterPyramidFormat
Raster pyramid formats.
@ GeoTiff
Geotiff .ovr (external).
@ Erdas
Erdas Image .aux (external).
@ SingleBandGray
A single band image drawn as a range of gray colors.
@ MultiBandColor
A layer containing 2 or more bands, mapped to RGB color space. In the case of a multiband with only t...
@ BuildPyramids
Supports building of pyramids (overviews) (Deprecated since QGIS 3.38 – use RasterProviderCapability:...
@ Size
Original data source size (and thus resolution) is known, it is not always available,...
@ ExcludeByDefault
If set, the layer should not be included in legends by default, and must be manually added by a user.
@ ARGB32_Premultiplied
Color, alpha, red, green, blue, 4 bytes the same as QImage::Format_ARGB32_Premultiplied.
@ ARGB32
Color, alpha, red, green, blue, 4 bytes the same as QImage::Format_ARGB32.
@ Preferred
Preferred format, matching the most recent WKT ISO standard. Currently an alias to WKT2_2019,...
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.
@ WebBrowser
StyleSheet for embedded browsers (QtWebKit), supports full standard CSS.
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.
A generic dialog for building expression strings.
static QgsExpressionContextScope * projectScope(const QgsProject *project)
Creates a new scope which contains variables and functions relating to a QGIS project.
static QgsExpressionContextScope * atlasScope(const QgsLayoutAtlas *atlas)
Creates a new scope which contains variables and functions relating to a QgsLayoutAtlas.
static QgsExpressionContextScope * mapLayerPositionScope(const QgsPointXY &position)
Sets the expression context variables which are available for expressions triggered by moving the mou...
static QgsExpressionContextScope * mapSettingsScope(const QgsMapSettings &mapSettings)
Creates a new scope which contains variables and functions relating to a QgsMapSettings object.
static QgsExpressionContextScope * layerScope(const QgsMapLayer *layer)
Creates a new scope which contains variables and functions relating to a QgsMapLayer.
static QgsExpressionContextScope * globalScope()
Creates a new scope which contains variables and functions relating to the global QGIS context.
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.
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
Color and saturation filter pipe for rasters.
void setColorizeOn(bool colorizeOn)
void setSaturation(int saturation)
int colorizeStrength() const
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)
QColor colorizeColor() const
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.
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.
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 ¤tName)
Emitted when the current style has been changed.
Base class for all map layer types.
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 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 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).
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.
virtual Qgis::RasterInterfaceCapabilities capabilities() const
Returns the capabilities supported by the interface.
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...
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.
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.
Stores settings for use within QGIS.
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.
A collection of stubs to mimic the API of QWebView on systems where the real library is not available...
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.
#define QgsDebugMsgLevel(str, level)
Setting options for creating vector data providers.
Registry for raster renderer entries.
QgsRasterRendererWidgetCreateFunc widgetCreateFunction