QGIS API Documentation 3.37.0-Master (fdefdf9c27f)
qgslocatormodel.h
Go to the documentation of this file.
1/***************************************************************************
2 qgslocatormodel.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 QGSLOCATORMODEL_H
19#define QGSLOCATORMODEL_H
20
21#include "qgis_core.h"
22#include "qgslocatorfilter.h"
23#include <QAbstractListModel>
24#include <QTimer>
25#include <QSet>
26#include <QSortFilterProxyModel>
27
28class QgsLocator;
29class QgsLocatorModel;
31
41class CORE_EXPORT QgsLocatorModel : public QAbstractTableModel
42{
43 Q_OBJECT
44
45 public:
46
47 static const int NoGroup = 9999;
48
50 // *INDENT-OFF*
51
59 {
60 ResultData SIP_MONKEYPATCH_COMPAT_NAME(ResultDataRole) = Qt::UserRole + 1,
61 ResultType SIP_MONKEYPATCH_COMPAT_NAME(ResultTypeRole),
62 ResultFilterPriority SIP_MONKEYPATCH_COMPAT_NAME(ResultFilterPriorityRole),
63 ResultScore SIP_MONKEYPATCH_COMPAT_NAME(ResultScoreRole),
64 ResultFilterName SIP_MONKEYPATCH_COMPAT_NAME(ResultFilterNameRole),
65 ResultFilterGroupSorting SIP_MONKEYPATCH_COMPAT_NAME(ResultFilterGroupSortingRole),
66 ResultActions SIP_MONKEYPATCH_COMPAT_NAME(ResultActionsRole),
67 };
68 Q_ENUM( CustomRole )
69 // *INDENT-ON*
70
71
74 QgsLocatorModel( QObject *parent SIP_TRANSFERTHIS = nullptr );
75
80 void clear();
81
88 void deferredClear();
89
90 int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
91 int columnCount( const QModelIndex &parent = QModelIndex() ) const override;
92 QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const override;
93 Qt::ItemFlags flags( const QModelIndex &index ) const override;
94 QHash<int, QByteArray> roleNames() const override;
95
96 public slots:
97
101 void addResult( const QgsLocatorResult &result );
102
103 private:
104
105 enum ColumnCount
106 {
107 Name = 0,
108 Description
109 };
110
111 struct Entry
112 {
113 QgsLocatorResult result;
114 QString filterTitle;
115 QgsLocatorFilter *filter = nullptr;
116 QString groupTitle = QString();
117 int groupSorting = 0;
118 };
119
120 QList<Entry> mResults;
121 QSet<QString> mFoundResultsFromFilterNames;
122 QMap<QgsLocatorFilter *, QStringList> mFoundResultsFilterGroups;
123 bool mDeferredClear = false;
124 QTimer mDeferredClearTimer;
125};
126
145{
146 Q_OBJECT
147
148 public:
149
156
160 QgsLocator *locator();
161
171 void search( const QString &string );
172
178 virtual QgsLocatorContext createContext();
179
180 private slots:
181
182 void searchFinished();
183
184 private:
185
186 QgsLocator *mLocator = nullptr;
187
188 QString mNextRequestedString;
189 bool mHasQueuedRequest = false;
190};
191
198class CORE_EXPORT QgsLocatorProxyModel : public QSortFilterProxyModel
199{
200 Q_OBJECT
201
202 public:
203
207 explicit QgsLocatorProxyModel( QObject *parent SIP_TRANSFERTHIS = nullptr );
208 bool lessThan( const QModelIndex &left, const QModelIndex &right ) const override;
209};
210
211#endif // QGSLOCATORMODEL_H
212
213
A QgsLocatorModel which has is associated directly with a QgsLocator, and is automatically populated ...
Encapsulates the properties relating to the context of a locator search.
Abstract base class for filters which collect locator results.
An abstract list model for displaying the results of locator searches.
CustomRole
Custom model roles.
A sort proxy model for QgsLocatorModel, which automatically sorts results by precedence.
Encapsulates properties of an individual matching result found by a QgsLocatorFilter.
Handles the management of QgsLocatorFilter objects and async collection of search results from them.
Definition: qgslocator.h:61
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
#define SIP_MONKEYPATCH_SCOPEENUM_UNNEST(OUTSIDE_CLASS, FORMERNAME)
Definition: qgis_sip.h:271
#define SIP_MONKEYPATCH_COMPAT_NAME(FORMERNAME)
Definition: qgis_sip.h:273