1 /***************************************************************************
2                          qgsactivelayerfeatureslocatorfilters.h
3                          --------------------------
4     begin                : May 2017
5     copyright            : (C) 2017 by Nyall Dawson
6     email                : nyall dot dawson at gmail dot com
7  ***************************************************************************/
8 
9 /***************************************************************************
10  *                                                                         *
11  *   This program is free software; you can redistribute it and/or modify  *
12  *   it under the terms of the GNU General Public License as published by  *
13  *   the Free Software Foundation; either version 2 of the License, or     *
14  *   (at your option) any later version.                                   *
15  *                                                                         *
16  ***************************************************************************/
17 
18 #ifndef QGSACTIVELAYERFEATURESLOCATORFILTERS_H
19 #define QGSACTIVELAYERFEATURESLOCATORFILTERS_H
20 
21 #include "qgis_app.h"
22 #include "qgslocatorfilter.h"
23 #include "qgsexpression.h"
24 #include "qgsfeatureiterator.h"
25 
26 
27 class APP_EXPORT QgsActiveLayerFeaturesLocatorFilter : public QgsLocatorFilter
28 {
29     Q_OBJECT
30 
31   public:
32     QgsActiveLayerFeaturesLocatorFilter( QObject *parent = nullptr );
33     QgsActiveLayerFeaturesLocatorFilter *clone() const override;
name()34     QString name() const override { return QStringLiteral( "features" ); }
displayName()35     QString displayName() const override { return tr( "Active Layer Features" ); }
priority()36     Priority priority() const override { return Medium; }
prefix()37     QString prefix() const override { return QStringLiteral( "f" ); }
38 
39     QStringList prepare( const QString &string, const QgsLocatorContext &context ) override;
40     void fetchResults( const QString &string, const QgsLocatorContext &context, QgsFeedback *feedback ) override;
41     void triggerResult( const QgsLocatorResult &result ) override;
42     void triggerResultFromAction( const QgsLocatorResult &result, const int actionId ) override;
hasConfigWidget()43     bool hasConfigWidget() const override {return true;}
44     void openConfigWidget( QWidget *parent ) override;
45 
46     enum class ResultType
47     {
48       Feature,
49       FieldRestriction,
50     };
51     Q_ENUM( ResultType )
52 
53   private:
54     enum ContextMenuEntry
55     {
56       NoEntry,
57       OpenForm
58     };
59 
60     /**
61      * Returns the field restriction if defined (starting with @)
62      * The \a searchString is modified accordingly by removing the field restriction
63      */
64     static QString fieldRestriction( QString &searchString, bool *isRestricting = nullptr );
65 
66     QgsExpression mDispExpression;
67     QgsExpressionContext mContext;
68     QgsFeatureIterator mDisplayTitleIterator;
69     QgsFeatureIterator mFieldIterator;
70     QString mLayerId;
71     bool mLayerIsSpatial = false;
72     QIcon mLayerIcon;
73     QStringList mAttributeAliases;
74     QStringList mFieldsCompletion;
75     int mMaxTotalResults = 30;
76 
77     friend class TestQgsAppLocatorFilters;
78 };
79 
80 
81 #endif // QGSACTIVELAYERFEATURESLOCATORFILTERS_H
82