Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
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
1 parent
71f7872
commit 1174b33
Showing
10 changed files
with
238 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ); | ||
} | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters