Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixes #17845 tested on Linux KDE and Win 10
  • Loading branch information
elpaso committed Feb 9, 2018
1 parent fcb50a6 commit e435d79
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 27 deletions.
40 changes: 20 additions & 20 deletions src/app/qgisapp.cpp
Expand Up @@ -12568,7 +12568,7 @@ void QgisApp::readProject( const QDomDocument &doc )
}
}

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

if ( !ml )
if ( !mapLayer )
return;

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

if ( ml->type() == QgsMapLayer::RasterLayer )
if ( mapLayer->type() == QgsMapLayer::RasterLayer )
{
#if 0 // See note above about reusing this
QgsRasterLayerProperties *rlp = nullptr;
Expand All @@ -12601,27 +12601,27 @@ void QgisApp::showLayerProperties( QgsMapLayer *ml )
// handled by rendererChanged() connect( rlp, SIGNAL( refreshLegend( QString, bool ) ), mLayerTreeView, SLOT( refreshLayerSymbology( QString ) ) );
}
#else
QgsRasterLayerProperties *rlp = new QgsRasterLayerProperties( ml, mMapCanvas, this );
QgsRasterLayerProperties *rasterLayerPropertiesDialog = new QgsRasterLayerProperties( mapLayer, mMapCanvas, this );
#endif
// Cannot use exec here due to raster transparency map tool:
// in order to pass focus to the canvas, the dialog needs to
// be hidden and shown in non-modal mode.
rlp->setModal( true );
rlp->show();
rasterLayerPropertiesDialog->setModal( true );
rasterLayerPropertiesDialog->show();
// Delete (later, for safety) since dialog cannot be reused without
// updating code
connect( rlp, &QgsRasterLayerProperties::accepted, [ rlp ]
connect( rasterLayerPropertiesDialog, &QgsRasterLayerProperties::accepted, [ rasterLayerPropertiesDialog ]
{
rlp->deleteLater();
rasterLayerPropertiesDialog->deleteLater();
} );
connect( rlp, &QgsRasterLayerProperties::rejected, [ rlp ]
connect( rasterLayerPropertiesDialog, &QgsRasterLayerProperties::rejected, [ rasterLayerPropertiesDialog ]
{
rlp->deleteLater();
rasterLayerPropertiesDialog->deleteLater();
} );
}
else if ( ml->type() == QgsMapLayer::VectorLayer ) // VECTOR
else if ( mapLayer->type() == QgsMapLayer::VectorLayer ) // VECTOR
{
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( ml );
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mapLayer );

#if 0 // See note above about reusing this
QgsVectorLayerProperties *vlp = nullptr;
Expand All @@ -12635,26 +12635,26 @@ void QgisApp::showLayerProperties( QgsMapLayer *ml )
// handled by rendererChanged() connect( vlp, SIGNAL( refreshLegend( QString ) ), mLayerTreeView, SLOT( refreshLayerSymbology( QString ) ) );
}
#else
QgsVectorLayerProperties *vlp = new QgsVectorLayerProperties( vlayer, this );
QgsVectorLayerProperties *vectorLayerPropertiesDialog = new QgsVectorLayerProperties( vlayer, this );
#endif
Q_FOREACH ( QgsMapLayerConfigWidgetFactory *factory, mMapLayerPanelFactories )
{
vlp->addPropertiesPageFactory( factory );
vectorLayerPropertiesDialog->addPropertiesPageFactory( factory );
}

mMapStyleWidget->blockUpdates( true );
if ( vlp->exec() )
if ( vectorLayerPropertiesDialog->exec() )
{
activateDeactivateLayerRelatedActions( ml );
activateDeactivateLayerRelatedActions( mapLayer );
mMapStyleWidget->updateCurrentWidgetLayer();
}
mMapStyleWidget->blockUpdates( false );

delete vlp; // delete since dialog cannot be reused without updating code
delete vectorLayerPropertiesDialog; // delete since dialog cannot be reused without updating code
}
else if ( ml->type() == QgsMapLayer::PluginLayer )
else if ( mapLayer->type() == QgsMapLayer::PluginLayer )
{
QgsPluginLayer *pl = qobject_cast<QgsPluginLayer *>( ml );
QgsPluginLayer *pl = qobject_cast<QgsPluginLayer *>( mapLayer );
if ( !pl )
return;

Expand Down
2 changes: 1 addition & 1 deletion src/app/qgisapp.h
Expand Up @@ -603,7 +603,7 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
QgsLocatorWidget *locatorWidget() { return mLocatorWidget; }

//! show layer properties
void showLayerProperties( QgsMapLayer *ml );
void showLayerProperties( QgsMapLayer *mapLayer );

//! returns pointer to map legend
QgsLayerTreeView *layerTreeView();
Expand Down
18 changes: 12 additions & 6 deletions src/app/qgsrasterlayerproperties.cpp
Expand Up @@ -180,6 +180,7 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer *lyr, QgsMapCanv
{
mPixelSelectorTool = qgis::make_unique<QgsMapToolEmitPoint>( canvas );
connect( mPixelSelectorTool.get(), &QgsMapToolEmitPoint::canvasClicked, this, &QgsRasterLayerProperties::pixelSelected );
connect( mPixelSelectorTool.get(), &QgsMapToolEmitPoint::deactivated, this, &QgsRasterLayerProperties::restoreWindowModality );
}
else
{
Expand Down Expand Up @@ -1194,16 +1195,16 @@ void QgsRasterLayerProperties::pbnAddValuesFromDisplay_clicked()
{
//Need to work around the modality of the dialog but can not just hide() it.
// According to Qt5 docs, to change modality the dialog needs to be hidden
// and shown it again.
// and shown again.
hide();
setModal( false );
showMinimized();

// Transfer focus to the canvas to use the selector tool
mMapCanvas->window()->raise();
mMapCanvas->window()->activateWindow();
mMapCanvas->window()->setFocus();
mMapCanvas->setMapTool( mPixelSelectorTool.get() );

}
}

Expand Down Expand Up @@ -1636,10 +1637,6 @@ void QgsRasterLayerProperties::pixelSelected( const QgsPointXY &canvasPoint, con
return;
}

raise();
setModal( true );
activateWindow();

//Get the pixel values and add a new entry to the transparency table
if ( mMapCanvas && mPixelSelectorTool )
{
Expand Down Expand Up @@ -1872,6 +1869,15 @@ void QgsRasterLayerProperties::saveStyleAs_clicked()
QMessageBox::information( this, tr( "Saved Style" ), message );
}

void QgsRasterLayerProperties::restoreWindowModality()
{
hide();
setModal( true );
show();
raise();
activateWindow();
}

//
//
// Next four methods for saving and restoring QMD metadata
Expand Down
3 changes: 3 additions & 0 deletions src/app/qgsrasterlayerproperties.h
Expand Up @@ -103,6 +103,9 @@ class APP_EXPORT QgsRasterLayerProperties : public QgsOptionsDialogBase, private
void loadStyle_clicked();
//! Save a style when appriate button is pressed.
void saveStyleAs_clicked();
//! Restore dialog modality and focus, usually after a pixel clicked to pick transparency color
void restoreWindowModality();


//! Load a saved metadata file.
void loadMetadata();
Expand Down

0 comments on commit e435d79

Please sign in to comment.