@@ -176,11 +176,10 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer *lyr, QgsMapCanv
176
176
pbnImportTransparentPixelValues->setIcon ( QgsApplication::getThemeIcon ( QStringLiteral ( " /mActionFileOpen.svg" ) ) );
177
177
pbnExportTransparentPixelValues->setIcon ( QgsApplication::getThemeIcon ( QStringLiteral ( " /mActionFileSave.svg" ) ) );
178
178
179
- mPixelSelectorTool = nullptr ;
180
179
if ( mMapCanvas )
181
180
{
182
- mPixelSelectorTool = new QgsMapToolEmitPoint ( canvas );
183
- connect ( mPixelSelectorTool , &QgsMapToolEmitPoint::canvasClicked, this , &QgsRasterLayerProperties::pixelSelected );
181
+ mPixelSelectorTool = qgis::make_unique< QgsMapToolEmitPoint> ( canvas );
182
+ connect ( mPixelSelectorTool . get () , &QgsMapToolEmitPoint::canvasClicked, this , &QgsRasterLayerProperties::pixelSelected );
184
183
}
185
184
else
186
185
{
@@ -455,10 +454,6 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer *lyr, QgsMapCanv
455
454
456
455
QgsRasterLayerProperties::~QgsRasterLayerProperties ()
457
456
{
458
- if ( mPixelSelectorTool )
459
- {
460
- delete mPixelSelectorTool ;
461
- }
462
457
}
463
458
464
459
void QgsRasterLayerProperties::setupTransparencyTable ( int nBands )
@@ -1197,16 +1192,18 @@ void QgsRasterLayerProperties::pbnAddValuesFromDisplay_clicked()
1197
1192
{
1198
1193
if ( mMapCanvas && mPixelSelectorTool )
1199
1194
{
1200
- mMapCanvas ->setMapTool ( mPixelSelectorTool );
1201
1195
// Need to work around the modality of the dialog but can not just hide() it.
1196
+ // According to Qt5 docs, to change modality the dialog needs to be hidden
1197
+ // and shown it again.
1198
+ hide ();
1202
1199
setModal ( false );
1203
-
1204
1200
showMinimized ();
1205
1201
1206
- // Q_ASSERT( parentWidget()->parentWidget() );
1207
- parentWidget ()->activateWindow ();
1208
- parentWidget ()->raise ();
1209
- // lower();
1202
+ // Transfer focus to the canvas to use the selector tool
1203
+ mMapCanvas ->window ()->raise ();
1204
+ mMapCanvas ->window ()->activateWindow ();
1205
+ mMapCanvas ->window ()->setFocus ();
1206
+ mMapCanvas ->setMapTool ( mPixelSelectorTool .get () );
1210
1207
}
1211
1208
}
1212
1209
@@ -1630,8 +1627,9 @@ void QgsRasterLayerProperties::pbnRemoveSelectedRow_clicked()
1630
1627
}
1631
1628
}
1632
1629
1633
- void QgsRasterLayerProperties::pixelSelected ( const QgsPointXY &canvasPoint )
1630
+ void QgsRasterLayerProperties::pixelSelected ( const QgsPointXY &canvasPoint, const Qt::MouseButton &btn )
1634
1631
{
1632
+ Q_UNUSED ( btn );
1635
1633
QgsRasterRenderer *renderer = mRendererWidget ->renderer ();
1636
1634
if ( !renderer )
1637
1635
{
@@ -1645,7 +1643,7 @@ void QgsRasterLayerProperties::pixelSelected( const QgsPointXY &canvasPoint )
1645
1643
// Get the pixel values and add a new entry to the transparency table
1646
1644
if ( mMapCanvas && mPixelSelectorTool )
1647
1645
{
1648
- mMapCanvas ->unsetMapTool ( mPixelSelectorTool );
1646
+ mMapCanvas ->unsetMapTool ( mPixelSelectorTool . get () );
1649
1647
1650
1648
const QgsMapSettings &ms = mMapCanvas ->mapSettings ();
1651
1649
QgsPointXY myPoint = ms.mapToLayerCoordinates ( mRasterLayer , canvasPoint );
0 commit comments