Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Add inbuilt filters for project layers and compositions
The project layer filter allows you to quickly select a layer from the current project and highlight it in the layer tree. It's useful for complex project with lots of groups, where it's easy to "lose" layers somewhere in the tree... The composition filter allows searching for and opening compositions from the current project
- Loading branch information
Showing
with
238 additions
and 49 deletions.
- +7 −0 python/core/qgsmaplayermodel.sip
- +5 −0 python/gui/locator/qgslocatorfilter.sip
- +6 −0 src/app/CMakeLists.txt
- +99 −0 src/app/locator/qgsinbuiltlocatorfilters.cpp
- +49 −0 src/app/locator/qgsinbuiltlocatorfilters.h
- +8 −1 src/app/qgisapp.cpp
- +49 −48 src/core/qgsmaplayermodel.cpp
- +6 −0 src/core/qgsmaplayermodel.h
- +6 −0 src/gui/locator/qgslocatorfilter.h
- +3 −0 src/gui/locator/qgslocatorwidget.cpp
@@ -0,0 +1,99 @@ | ||
/*************************************************************************** | ||
qgsinbuiltlocatorfilters.cpp | ||
---------------------------- | ||
begin : May 2017 | ||
copyright : (C) 2017 by Nyall Dawson | ||
email : nyall dot dawson at gmail dot com | ||
***************************************************************************/ | ||
|
||
/*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
|
||
#include "qgsinbuiltlocatorfilters.h" | ||
#include "qgsproject.h" | ||
#include "qgslayertree.h" | ||
#include "qgsfeedback.h" | ||
#include "qgisapp.h" | ||
#include "qgsstringutils.h" | ||
#include "qgsmaplayermodel.h" | ||
#include "qgscomposition.h" | ||
#include "qgslayoutmanager.h" | ||
|
||
QgsLayerTreeLocatorFilter::QgsLayerTreeLocatorFilter( QObject *parent ) | ||
: QgsLocatorFilter( parent ) | ||
{} | ||
|
||
void QgsLayerTreeLocatorFilter::fetchResults( const QString &string, QgsFeedback *feedback ) | ||
{ | ||
QgsLayerTree *tree = QgsProject::instance()->layerTreeRoot(); | ||
QList<QgsLayerTreeLayer *> layers = tree->findLayers(); | ||
Q_FOREACH ( QgsLayerTreeLayer *layer, layers ) | ||
{ | ||
if ( feedback->isCanceled() ) | ||
return; | ||
|
||
if ( layer->layer() && layer->layer()->name().contains( string, Qt::CaseInsensitive ) ) | ||
{ | ||
QgsLocatorResult result; | ||
result.filter = this; | ||
result.displayString = layer->layer()->name(); | ||
result.userData = layer->layerId(); | ||
result.icon = QgsMapLayerModel::iconForLayer( layer->layer() ); | ||
emit resultFetched( result ); | ||
} | ||
} | ||
} | ||
|
||
void QgsLayerTreeLocatorFilter::triggerResult( const QgsLocatorResult &result ) | ||
{ | ||
QString layerId = result.userData.toString(); | ||
QgsMapLayer *layer = QgsProject::instance()->mapLayer( layerId ); | ||
QgisApp::instance()->setActiveLayer( layer ); | ||
} | ||
|
||
// | ||
// QgsLayoutLocatorFilter | ||
// | ||
|
||
QgsLayoutLocatorFilter::QgsLayoutLocatorFilter( QObject *parent ) | ||
: QgsLocatorFilter( parent ) | ||
{} | ||
|
||
void QgsLayoutLocatorFilter::fetchResults( const QString &string, QgsFeedback *feedback ) | ||
{ | ||
Q_FOREACH ( QgsComposition *composition, QgsProject::instance()->layoutManager()->compositions() ) | ||
{ | ||
if ( feedback->isCanceled() ) | ||
return; | ||
|
||
if ( composition && composition->name().contains( string, Qt::CaseInsensitive ) ) | ||
{ | ||
QgsLocatorResult result; | ||
result.filter = this; | ||
result.displayString = composition->name(); | ||
result.userData = composition->name(); | ||
//result.icon = QgsMapLayerModel::iconForLayer( layer->layer() ); | ||
emit resultFetched( result ); | ||
} | ||
} | ||
} | ||
|
||
void QgsLayoutLocatorFilter::triggerResult( const QgsLocatorResult &result ) | ||
{ | ||
QString layoutName = result.userData.toString(); | ||
QgsComposition *composition = QgsProject::instance()->layoutManager()->compositionByName( layoutName ); | ||
if ( !composition ) | ||
return; | ||
|
||
QgisApp::instance()->openComposer( composition ); | ||
} | ||
|
||
|
||
|
@@ -0,0 +1,49 @@ | ||
/*************************************************************************** | ||
qgsinbuiltlocatorfilters.h | ||
-------------------------- | ||
begin : May 2017 | ||
copyright : (C) 2017 by Nyall Dawson | ||
email : nyall dot dawson at gmail dot com | ||
***************************************************************************/ | ||
|
||
/*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#ifndef QGSINBUILTLOCATORFILTERS_H | ||
#define QGSINBUILTLOCATORFILTERS_H | ||
|
||
#include "qgslocatorfilter.h" | ||
|
||
class QgsLayerTreeLocatorFilter : public QgsLocatorFilter | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
|
||
QgsLayerTreeLocatorFilter( QObject *parent = nullptr ); | ||
void fetchResults( const QString &string, QgsFeedback *feedback ) override; | ||
void triggerResult( const QgsLocatorResult &result ) override; | ||
|
||
}; | ||
|
||
class QgsLayoutLocatorFilter : public QgsLocatorFilter | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
|
||
QgsLayoutLocatorFilter( QObject *parent = nullptr ); | ||
void fetchResults( const QString &string, QgsFeedback *feedback ) override; | ||
void triggerResult( const QgsLocatorResult &result ) override; | ||
|
||
}; | ||
|
||
#endif // QGSINBUILTLOCATORFILTERS_H | ||
|
||
|