Skip to content
Permalink
Browse files

Merge pull request #6068 from elpaso/bugfix-17845-raster-transparency…

…-from-display

[bugfix] Transfer focus to canvas when selecting transparency
  • Loading branch information
elpaso committed Jan 29, 2018
2 parents e2fcf70 + eeaca68 commit cdf697d951df13fe6902d3a928b984bf134f32bd
Showing with 31 additions and 21 deletions.
  1. +15 −3 src/app/qgisapp.cpp
  2. +13 −15 src/app/qgsrasterlayerproperties.cpp
  3. +3 −3 src/app/qgsrasterlayerproperties.h
@@ -12613,9 +12613,21 @@ void QgisApp::showLayerProperties( QgsMapLayer *ml )
#else
QgsRasterLayerProperties *rlp = new QgsRasterLayerProperties( ml, mMapCanvas, this );
#endif

rlp->exec();
delete rlp; // delete since dialog cannot be reused without updating code
// 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();
// Delete (later, for safety) since dialog cannot be reused without
// updating code
connect( rlp, &QgsRasterLayerProperties::accepted, [ rlp ]
{
rlp->deleteLater();
} );
connect( rlp, &QgsRasterLayerProperties::rejected, [ rlp ]
{
rlp->deleteLater();
} );
}
else if ( ml->type() == QgsMapLayer::VectorLayer ) // VECTOR
{
@@ -176,11 +176,10 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer *lyr, QgsMapCanv
pbnImportTransparentPixelValues->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionFileOpen.svg" ) ) );
pbnExportTransparentPixelValues->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionFileSave.svg" ) ) );

mPixelSelectorTool = nullptr;
if ( mMapCanvas )
{
mPixelSelectorTool = new QgsMapToolEmitPoint( canvas );
connect( mPixelSelectorTool, &QgsMapToolEmitPoint::canvasClicked, this, &QgsRasterLayerProperties::pixelSelected );
mPixelSelectorTool = qgis::make_unique<QgsMapToolEmitPoint>( canvas );
connect( mPixelSelectorTool.get(), &QgsMapToolEmitPoint::canvasClicked, this, &QgsRasterLayerProperties::pixelSelected );
}
else
{
@@ -455,10 +454,6 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer *lyr, QgsMapCanv

QgsRasterLayerProperties::~QgsRasterLayerProperties()
{
if ( mPixelSelectorTool )
{
delete mPixelSelectorTool;
}
}

void QgsRasterLayerProperties::setupTransparencyTable( int nBands )
@@ -1197,16 +1192,18 @@ void QgsRasterLayerProperties::pbnAddValuesFromDisplay_clicked()
{
if ( mMapCanvas && mPixelSelectorTool )
{
mMapCanvas->setMapTool( mPixelSelectorTool );
//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.
hide();
setModal( false );

showMinimized();

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

@@ -1630,8 +1627,9 @@ void QgsRasterLayerProperties::pbnRemoveSelectedRow_clicked()
}
}

void QgsRasterLayerProperties::pixelSelected( const QgsPointXY &canvasPoint )
void QgsRasterLayerProperties::pixelSelected( const QgsPointXY &canvasPoint, const Qt::MouseButton &btn )
{
Q_UNUSED( btn );
QgsRasterRenderer *renderer = mRendererWidget->renderer();
if ( !renderer )
{
@@ -1645,7 +1643,7 @@ void QgsRasterLayerProperties::pixelSelected( const QgsPointXY &canvasPoint )
//Get the pixel values and add a new entry to the transparency table
if ( mMapCanvas && mPixelSelectorTool )
{
mMapCanvas->unsetMapTool( mPixelSelectorTool );
mMapCanvas->unsetMapTool( mPixelSelectorTool.get() );

const QgsMapSettings &ms = mMapCanvas->mapSettings();
QgsPointXY myPoint = ms.mapToLayerCoordinates( mRasterLayer, canvasPoint );
@@ -26,13 +26,13 @@
#include "qgsguiutils.h"
#include "qgshelp.h"
#include "qgsmaplayerstylemanager.h"
#include "qgsmaptoolemitpoint.h"
#include "qgis_app.h"

class QgsPointXY;
class QgsMapLayer;
class QgsMapCanvas;
class QgsRasterLayer;
class QgsMapToolEmitPoint;
class QgsMetadataWidget;
class QgsRasterRenderer;
class QgsRasterRendererWidget;
@@ -91,7 +91,7 @@ class APP_EXPORT QgsRasterLayerProperties : public QgsOptionsDialogBase, private
*/
//void on_btnResetNull_clicked();

void pixelSelected( const QgsPointXY & );
void pixelSelected( const QgsPointXY &, const Qt::MouseButton & );

private slots:
void mRenderTypeComboBox_currentIndexChanged( int index );
@@ -206,7 +206,7 @@ class APP_EXPORT QgsRasterLayerProperties : public QgsOptionsDialogBase, private
qreal mGradientWidth;

QgsMapCanvas *mMapCanvas = nullptr;
QgsMapToolEmitPoint *mPixelSelectorTool = nullptr;
std::unique_ptr<QgsMapToolEmitPoint> mPixelSelectorTool;

QgsRasterHistogramWidget *mHistogramWidget = nullptr;

0 comments on commit cdf697d

Please sign in to comment.
You can’t perform that action at this time.