Skip to content

Commit e435d79

Browse files
committed
Fixes #17845 tested on Linux KDE and Win 10
1 parent fcb50a6 commit e435d79

File tree

4 files changed

+36
-27
lines changed

4 files changed

+36
-27
lines changed

src/app/qgisapp.cpp

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12568,7 +12568,7 @@ void QgisApp::readProject( const QDomDocument &doc )
1256812568
}
1256912569
}
1257012570

12571-
void QgisApp::showLayerProperties( QgsMapLayer *ml )
12571+
void QgisApp::showLayerProperties( QgsMapLayer *mapLayer )
1257212572
{
1257312573
/*
1257412574
TODO: Consider reusing the property dialogs again.
@@ -12579,15 +12579,15 @@ void QgisApp::showLayerProperties( QgsMapLayer *ml )
1257912579
a separate copy of the dialog pointer needs to be stored with each layer.
1258012580
*/
1258112581

12582-
if ( !ml )
12582+
if ( !mapLayer )
1258312583
return;
1258412584

12585-
if ( !QgsProject::instance()->layerIsEmbedded( ml->id() ).isEmpty() )
12585+
if ( !QgsProject::instance()->layerIsEmbedded( mapLayer->id() ).isEmpty() )
1258612586
{
1258712587
return; //don't show properties of embedded layers
1258812588
}
1258912589

12590-
if ( ml->type() == QgsMapLayer::RasterLayer )
12590+
if ( mapLayer->type() == QgsMapLayer::RasterLayer )
1259112591
{
1259212592
#if 0 // See note above about reusing this
1259312593
QgsRasterLayerProperties *rlp = nullptr;
@@ -12601,27 +12601,27 @@ void QgisApp::showLayerProperties( QgsMapLayer *ml )
1260112601
// handled by rendererChanged() connect( rlp, SIGNAL( refreshLegend( QString, bool ) ), mLayerTreeView, SLOT( refreshLayerSymbology( QString ) ) );
1260212602
}
1260312603
#else
12604-
QgsRasterLayerProperties *rlp = new QgsRasterLayerProperties( ml, mMapCanvas, this );
12604+
QgsRasterLayerProperties *rasterLayerPropertiesDialog = new QgsRasterLayerProperties( mapLayer, mMapCanvas, this );
1260512605
#endif
1260612606
// Cannot use exec here due to raster transparency map tool:
1260712607
// in order to pass focus to the canvas, the dialog needs to
1260812608
// be hidden and shown in non-modal mode.
12609-
rlp->setModal( true );
12610-
rlp->show();
12609+
rasterLayerPropertiesDialog->setModal( true );
12610+
rasterLayerPropertiesDialog->show();
1261112611
// Delete (later, for safety) since dialog cannot be reused without
1261212612
// updating code
12613-
connect( rlp, &QgsRasterLayerProperties::accepted, [ rlp ]
12613+
connect( rasterLayerPropertiesDialog, &QgsRasterLayerProperties::accepted, [ rasterLayerPropertiesDialog ]
1261412614
{
12615-
rlp->deleteLater();
12615+
rasterLayerPropertiesDialog->deleteLater();
1261612616
} );
12617-
connect( rlp, &QgsRasterLayerProperties::rejected, [ rlp ]
12617+
connect( rasterLayerPropertiesDialog, &QgsRasterLayerProperties::rejected, [ rasterLayerPropertiesDialog ]
1261812618
{
12619-
rlp->deleteLater();
12619+
rasterLayerPropertiesDialog->deleteLater();
1262012620
} );
1262112621
}
12622-
else if ( ml->type() == QgsMapLayer::VectorLayer ) // VECTOR
12622+
else if ( mapLayer->type() == QgsMapLayer::VectorLayer ) // VECTOR
1262312623
{
12624-
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( ml );
12624+
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mapLayer );
1262512625

1262612626
#if 0 // See note above about reusing this
1262712627
QgsVectorLayerProperties *vlp = nullptr;
@@ -12635,26 +12635,26 @@ void QgisApp::showLayerProperties( QgsMapLayer *ml )
1263512635
// handled by rendererChanged() connect( vlp, SIGNAL( refreshLegend( QString ) ), mLayerTreeView, SLOT( refreshLayerSymbology( QString ) ) );
1263612636
}
1263712637
#else
12638-
QgsVectorLayerProperties *vlp = new QgsVectorLayerProperties( vlayer, this );
12638+
QgsVectorLayerProperties *vectorLayerPropertiesDialog = new QgsVectorLayerProperties( vlayer, this );
1263912639
#endif
1264012640
Q_FOREACH ( QgsMapLayerConfigWidgetFactory *factory, mMapLayerPanelFactories )
1264112641
{
12642-
vlp->addPropertiesPageFactory( factory );
12642+
vectorLayerPropertiesDialog->addPropertiesPageFactory( factory );
1264312643
}
1264412644

1264512645
mMapStyleWidget->blockUpdates( true );
12646-
if ( vlp->exec() )
12646+
if ( vectorLayerPropertiesDialog->exec() )
1264712647
{
12648-
activateDeactivateLayerRelatedActions( ml );
12648+
activateDeactivateLayerRelatedActions( mapLayer );
1264912649
mMapStyleWidget->updateCurrentWidgetLayer();
1265012650
}
1265112651
mMapStyleWidget->blockUpdates( false );
1265212652

12653-
delete vlp; // delete since dialog cannot be reused without updating code
12653+
delete vectorLayerPropertiesDialog; // delete since dialog cannot be reused without updating code
1265412654
}
12655-
else if ( ml->type() == QgsMapLayer::PluginLayer )
12655+
else if ( mapLayer->type() == QgsMapLayer::PluginLayer )
1265612656
{
12657-
QgsPluginLayer *pl = qobject_cast<QgsPluginLayer *>( ml );
12657+
QgsPluginLayer *pl = qobject_cast<QgsPluginLayer *>( mapLayer );
1265812658
if ( !pl )
1265912659
return;
1266012660

src/app/qgisapp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
603603
QgsLocatorWidget *locatorWidget() { return mLocatorWidget; }
604604

605605
//! show layer properties
606-
void showLayerProperties( QgsMapLayer *ml );
606+
void showLayerProperties( QgsMapLayer *mapLayer );
607607

608608
//! returns pointer to map legend
609609
QgsLayerTreeView *layerTreeView();

src/app/qgsrasterlayerproperties.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer *lyr, QgsMapCanv
180180
{
181181
mPixelSelectorTool = qgis::make_unique<QgsMapToolEmitPoint>( canvas );
182182
connect( mPixelSelectorTool.get(), &QgsMapToolEmitPoint::canvasClicked, this, &QgsRasterLayerProperties::pixelSelected );
183+
connect( mPixelSelectorTool.get(), &QgsMapToolEmitPoint::deactivated, this, &QgsRasterLayerProperties::restoreWindowModality );
183184
}
184185
else
185186
{
@@ -1194,16 +1195,16 @@ void QgsRasterLayerProperties::pbnAddValuesFromDisplay_clicked()
11941195
{
11951196
//Need to work around the modality of the dialog but can not just hide() it.
11961197
// According to Qt5 docs, to change modality the dialog needs to be hidden
1197-
// and shown it again.
1198+
// and shown again.
11981199
hide();
11991200
setModal( false );
1200-
showMinimized();
12011201

12021202
// Transfer focus to the canvas to use the selector tool
12031203
mMapCanvas->window()->raise();
12041204
mMapCanvas->window()->activateWindow();
12051205
mMapCanvas->window()->setFocus();
12061206
mMapCanvas->setMapTool( mPixelSelectorTool.get() );
1207+
12071208
}
12081209
}
12091210

@@ -1636,10 +1637,6 @@ void QgsRasterLayerProperties::pixelSelected( const QgsPointXY &canvasPoint, con
16361637
return;
16371638
}
16381639

1639-
raise();
1640-
setModal( true );
1641-
activateWindow();
1642-
16431640
//Get the pixel values and add a new entry to the transparency table
16441641
if ( mMapCanvas && mPixelSelectorTool )
16451642
{
@@ -1872,6 +1869,15 @@ void QgsRasterLayerProperties::saveStyleAs_clicked()
18721869
QMessageBox::information( this, tr( "Saved Style" ), message );
18731870
}
18741871

1872+
void QgsRasterLayerProperties::restoreWindowModality()
1873+
{
1874+
hide();
1875+
setModal( true );
1876+
show();
1877+
raise();
1878+
activateWindow();
1879+
}
1880+
18751881
//
18761882
//
18771883
// Next four methods for saving and restoring QMD metadata

src/app/qgsrasterlayerproperties.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ class APP_EXPORT QgsRasterLayerProperties : public QgsOptionsDialogBase, private
103103
void loadStyle_clicked();
104104
//! Save a style when appriate button is pressed.
105105
void saveStyleAs_clicked();
106+
//! Restore dialog modality and focus, usually after a pixel clicked to pick transparency color
107+
void restoreWindowModality();
108+
106109

107110
//! Load a saved metadata file.
108111
void loadMetadata();

0 commit comments

Comments
 (0)