mirror of
https://github.com/qgis/QGIS.git
synced 2025-03-02 00:02:12 -05:00
PG raster: PR recommendations
This commit is contained in:
parent
e833a64dd1
commit
404fbb590b
@ -2623,7 +2623,7 @@ void QgisApp::createActions()
|
||||
connect( mActionSetLayerCRS, &QAction::triggered, this, &QgisApp::setLayerCrs );
|
||||
connect( mActionSetProjectCRSFromLayer, &QAction::triggered, this, &QgisApp::setProjectCrsFromLayer );
|
||||
connect( mActionLayerProperties, &QAction::triggered, this, &QgisApp::layerProperties );
|
||||
connect( mActionLayerSubsetString, &QAction::triggered, this, &QgisApp::layerSubsetString );
|
||||
connect( mActionLayerSubsetString, &QAction::triggered, this, qgis::overload<>::of( &QgisApp::layerSubsetString ) );
|
||||
connect( mActionAddToOverview, &QAction::triggered, this, &QgisApp::isInOverview );
|
||||
connect( mActionAddAllToOverview, &QAction::triggered, this, &QgisApp::addAllToOverview );
|
||||
connect( mActionRemoveAllFromOverview, &QAction::triggered, this, &QgisApp::removeAllFromOverview );
|
||||
@ -10479,13 +10479,20 @@ void QgisApp::duplicateVectorStyle( QgsVectorLayer *srcLayer, QgsVectorLayer *de
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void QgisApp::layerSubsetString()
|
||||
{
|
||||
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( activeLayer() );
|
||||
layerSubsetString( activeLayer() );
|
||||
}
|
||||
|
||||
void QgisApp::layerSubsetString( QgsMapLayer *mapLayer )
|
||||
{
|
||||
|
||||
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mapLayer );
|
||||
if ( !vlayer )
|
||||
{
|
||||
// Try PG raster
|
||||
QgsRasterLayer *rlayer = qobject_cast<QgsRasterLayer *>( activeLayer() );
|
||||
QgsRasterLayer *rlayer = qobject_cast<QgsRasterLayer *>( mapLayer );
|
||||
if ( rlayer )
|
||||
{
|
||||
QgsRasterDataProvider *provider = rlayer->dataProvider();
|
||||
|
@ -957,8 +957,14 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
|
||||
//! Duplicate map layer(s) in legend
|
||||
void duplicateLayers( const QList<QgsMapLayer *> &lyrList = QList<QgsMapLayer *>() );
|
||||
|
||||
//! change layer subset of current vector layer
|
||||
void layerSubsetString();
|
||||
/**
|
||||
* Changes layer subset of \a mapLayer
|
||||
* \since QGIS 3.12
|
||||
*/
|
||||
void layerSubsetString( QgsMapLayer *mapLayer );
|
||||
|
||||
//! change layer subset of the active layer
|
||||
void layerSubsetString( );
|
||||
|
||||
//! Sets scale visibility of selected layers
|
||||
void setLayerScaleVisibility();
|
||||
|
@ -248,17 +248,16 @@ QMenu *QgsAppLayerTreeViewMenuProvider::createContextMenu()
|
||||
|
||||
if ( provider && provider->supportsSubsetString() )
|
||||
{
|
||||
QAction *action = menu->addAction( tr( "&Filter…" ), QgisApp::instance(), &QgisApp::layerSubsetString );
|
||||
QAction *action = menu->addAction( tr( "&Filter…" ), QgisApp::instance(), qgis::overload<>::of( &QgisApp::layerSubsetString ) );
|
||||
action->setEnabled( !vlayer->isEditable() );
|
||||
}
|
||||
}
|
||||
|
||||
// PG raster: activate filter
|
||||
if ( rlayer &&
|
||||
rlayer->dataProvider() &&
|
||||
rlayer->dataProvider()->supportsSubsetString() )
|
||||
{
|
||||
menu->addAction( tr( "&Filter…" ), QgisApp::instance(), &QgisApp::layerSubsetString );
|
||||
menu->addAction( tr( "&Filter…" ), QgisApp::instance(), qgis::overload<>::of( &QgisApp::layerSubsetString ) );
|
||||
}
|
||||
|
||||
// change data source is only supported for vectors and rasters
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include "qgsquerybuilder.h"
|
||||
#include "qgsvectorlayer.h"
|
||||
#include "qgsrasterlayer.h"
|
||||
#include "qgisapp.h"
|
||||
|
||||
|
||||
QgsLayerTreeViewFilterIndicatorProvider::QgsLayerTreeViewFilterIndicatorProvider( QgsLayerTreeView *view )
|
||||
@ -35,42 +36,8 @@ void QgsLayerTreeViewFilterIndicatorProvider::onIndicatorClicked( const QModelIn
|
||||
if ( !QgsLayerTree::isLayer( node ) )
|
||||
return;
|
||||
|
||||
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( QgsLayerTree::toLayer( node )->layer() );
|
||||
if ( vlayer && !vlayer->isEditable() )
|
||||
{
|
||||
QgsQueryBuilder qb( vlayer );
|
||||
qb.setSql( vlayer->subsetString() );
|
||||
if ( qb.exec() )
|
||||
vlayer->setSubsetString( qb.sql() );
|
||||
}
|
||||
QgisApp::instance()->layerSubsetString( QgsLayerTree::toLayer( node )->layer() );
|
||||
|
||||
// raster
|
||||
QgsRasterLayer *rlayer = qobject_cast<QgsRasterLayer *>( QgsLayerTree::toLayer( node )->layer() );
|
||||
if ( rlayer && rlayer->dataProvider() && rlayer->dataProvider()->supportsSubsetString() )
|
||||
{
|
||||
// PG raster is the only one for now
|
||||
if ( rlayer->dataProvider()->name() == QStringLiteral( "postgresraster" ) )
|
||||
{
|
||||
QgsDataSourceUri vectorUri { rlayer->dataProvider()->dataSourceUri() };
|
||||
vectorUri.setGeometryColumn( QString() );
|
||||
vectorUri.setSrid( QString() );
|
||||
QgsVectorLayer vlayer { vectorUri.uri( ), QStringLiteral( "pgrasterlayer" ), QStringLiteral( "postgres" ) };
|
||||
if ( vlayer.isValid( ) )
|
||||
{
|
||||
// launch the query builder
|
||||
QgsQueryBuilder qb { &vlayer };
|
||||
QString subsetBefore = vlayer.subsetString();
|
||||
|
||||
// Set the sql in the query builder to the same in the prop dialog
|
||||
// (in case the user has already changed it)
|
||||
qb.setSql( rlayer->subsetString() );
|
||||
if ( qb.exec() && subsetBefore != qb.sql() )
|
||||
{
|
||||
rlayer->setSubsetString( qb.sql() );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QString QgsLayerTreeViewFilterIndicatorProvider::iconName( QgsMapLayer *layer )
|
||||
@ -114,7 +81,6 @@ void QgsLayerTreeViewFilterIndicatorProvider::disconnectSignals( QgsMapLayer *la
|
||||
if ( vlayer )
|
||||
disconnect( vlayer, &QgsVectorLayer::subsetStringChanged, this, &QgsLayerTreeViewFilterIndicatorProvider::onLayerChanged );
|
||||
|
||||
// PG raster
|
||||
QgsRasterLayer *rlayer = qobject_cast<QgsRasterLayer *>( layer );
|
||||
if ( rlayer && rlayer->dataProvider() && rlayer->dataProvider()->supportsSubsetString() )
|
||||
disconnect( rlayer, &QgsRasterLayer::subsetStringChanged, this, &QgsLayerTreeViewFilterIndicatorProvider::onLayerChanged );
|
||||
|
Loading…
x
Reference in New Issue
Block a user