QGIS API Documentation 3.39.0-Master (d85f3c2a281)
Loading...
Searching...
No Matches
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 = -1;
48 static const int UnorderedGroup = 0;
49
51 // *INDENT-OFF*
52
60 {
61 ResultData SIP_MONKEYPATCH_COMPAT_NAME(ResultDataRole) = Qt::UserRole + 1,
62 ResultType SIP_MONKEYPATCH_COMPAT_NAME(ResultTypeRole),
63 ResultFilterPriority SIP_MONKEYPATCH_COMPAT_NAME(ResultFilterPriorityRole),
64 ResultScore SIP_MONKEYPATCH_COMPAT_NAME(ResultScoreRole),
65 ResultFilterName SIP_MONKEYPATCH_COMPAT_NAME(ResultFilterNameRole),
66 ResultFilterGroupSorting SIP_MONKEYPATCH_COMPAT_NAME(ResultFilterGroupSortingRole),
67 ResultFilterGroupTitle,
68 ResultFilterGroupScore,
69 ResultActions SIP_MONKEYPATCH_COMPAT_NAME(ResultActionsRole),
70 };
71 Q_ENUM( CustomRole )
72 // *INDENT-ON*
73
74
77 QgsLocatorModel( QObject *parent SIP_TRANSFERTHIS = nullptr );
78
83 void clear();
84
91 void deferredClear();
92
93 int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
94 int columnCount( const QModelIndex &parent = QModelIndex() ) const override;
95 QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const override;
96 Qt::ItemFlags flags( const QModelIndex &index ) const override;
97 QHash<int, QByteArray> roleNames() const override;
98
99 public slots:
100
104 void addResult( const QgsLocatorResult &result );
105
106 private:
107
108 enum Column
109 {
110 Name = 0,
111 Description
112 };
113
114
115 // sorting is made on these values!
116 enum class EntryType : int
117 {
118 Filter = 0,
119 Group = 1,
120 Result = 2,
121 };
122
123 struct Entry
124 {
125 EntryType type = EntryType::Result;
126 QgsLocatorResult result;
127 QString filterTitle;
128 QgsLocatorFilter *filter = nullptr;
129 QString groupTitle = QString();
130 double groupScore = UnorderedGroup;
131 };
132
133 QList<Entry> mResults;
134 QSet<QString> mFoundResultsFromFilterNames;
135 // maps locator with pair of group title and group score
136 QMap<QgsLocatorFilter *, QList<std::pair<QString, double>>> mFoundResultsFilterGroups;
137 bool mDeferredClear = false;
138 QTimer mDeferredClearTimer;
139};
140
159{
160 Q_OBJECT
161
162 public:
163
170
174 QgsLocator *locator();
175
185 void search( const QString &string );
186
192 virtual QgsLocatorContext createContext();
193
194 private slots:
195
196 void searchFinished();
197
198 private:
199
200 QgsLocator *mLocator = nullptr;
201
202 QString mNextRequestedString;
203 bool mHasQueuedRequest = false;
204};
205
212class CORE_EXPORT QgsLocatorProxyModel : public QSortFilterProxyModel
213{
214 Q_OBJECT
215
216 public:
217
221 explicit QgsLocatorProxyModel( QObject *parent SIP_TRANSFERTHIS = nullptr );
222 bool lessThan( const QModelIndex &left, const QModelIndex &right ) const override;
223};
224
225#endif // QGSLOCATORMODEL_H
226
227
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