QGIS API Documentation 3.99.0-Master (752b475928d)
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
24#include <QAbstractListModel>
25#include <QSet>
26#include <QSortFilterProxyModel>
27#include <QTimer>
28
29class QgsLocator;
30class QgsLocatorModel;
32
42class CORE_EXPORT QgsLocatorModel : public QAbstractTableModel
43{
44 Q_OBJECT
45
46 public:
47
48 static const int NoGroup = -1;
49 static const int UnorderedGroup = 0;
50
52 // *INDENT-OFF*
53
61 {
62 ResultData SIP_MONKEYPATCH_COMPAT_NAME(ResultDataRole) = Qt::UserRole + 1,
63 ResultType SIP_MONKEYPATCH_COMPAT_NAME(ResultTypeRole),
64 ResultFilterPriority SIP_MONKEYPATCH_COMPAT_NAME(ResultFilterPriorityRole),
65 ResultScore SIP_MONKEYPATCH_COMPAT_NAME(ResultScoreRole),
66 ResultFilterName SIP_MONKEYPATCH_COMPAT_NAME(ResultFilterNameRole),
67 ResultFilterGroupSorting SIP_MONKEYPATCH_COMPAT_NAME(ResultFilterGroupSortingRole),
68 ResultFilterGroupTitle,
69 ResultFilterGroupScore,
70 ResultActions SIP_MONKEYPATCH_COMPAT_NAME(ResultActionsRole),
71 };
72 Q_ENUM( CustomRole )
73 // *INDENT-ON*
74
75
78 QgsLocatorModel( QObject *parent SIP_TRANSFERTHIS = nullptr );
79
84 void clear();
85
92 void deferredClear();
93
94 int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
95 int columnCount( const QModelIndex &parent = QModelIndex() ) const override;
96 QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const override;
97 Qt::ItemFlags flags( const QModelIndex &index ) const override;
98 QHash<int, QByteArray> roleNames() const override;
99
100 public slots:
101
105 void addResult( const QgsLocatorResult &result );
106
107 private:
108
109 enum Column
110 {
111 Name = 0,
112 Description
113 };
114
115
116 // sorting is made on these values!
117 enum class EntryType : int
118 {
119 Filter = 0,
120 Group = 1,
121 Result = 2,
122 };
123
124 struct Entry
125 {
126 EntryType type = EntryType::Result;
127 QgsLocatorResult result;
128 QString filterTitle;
129 QgsLocatorFilter *filter = nullptr;
130 QString groupTitle = QString();
131 double groupScore = UnorderedGroup;
132 };
133
134 QList<Entry> mResults;
135 QSet<QString> mFoundResultsFromFilterNames;
136 // maps locator with pair of group title and group score
137 QMap<QgsLocatorFilter *, QList<std::pair<QString, double>>> mFoundResultsFilterGroups;
138 bool mDeferredClear = false;
139 QTimer mDeferredClearTimer;
140};
141
160{
161 Q_OBJECT
162
163 public:
164
171
176
186 void search( const QString &string );
187
194
195 private slots:
196
197 void searchFinished();
198
199 private:
200
201 QgsLocator *mLocator = nullptr;
202
203 QString mNextRequestedString;
204 bool mHasQueuedRequest = false;
205};
206
213class CORE_EXPORT QgsLocatorProxyModel : public QSortFilterProxyModel
214{
215 Q_OBJECT
216
217 public:
218
222 explicit QgsLocatorProxyModel( QObject *parent SIP_TRANSFERTHIS = nullptr );
223 bool lessThan( const QModelIndex &left, const QModelIndex &right ) const override;
224};
225
226#endif // QGSLOCATORMODEL_H
227
228
QgsLocator * locator()
Returns a pointer to the locator utilized by this model.
QgsLocatorAutomaticModel(QgsLocator *locator)
Constructor for QgsLocatorAutomaticModel, linked with the specified locator.
void search(const QString &string)
Enqueues a search for a specified string within the model.
virtual QgsLocatorContext createContext()
Returns a new locator context for searches.
Encapsulates the properties relating to the context of a locator search.
An abstract list model for displaying the results of locator searches.
CustomRole
Custom model roles.
QgsLocatorModel(QObject *parent=nullptr)
Constructor for QgsLocatorModel.
static const int UnorderedGroup
static const int NoGroup
A sort proxy model for QgsLocatorModel, which automatically sorts results by precedence.
bool lessThan(const QModelIndex &left, const QModelIndex &right) const override
QgsLocatorProxyModel(QObject *parent=nullptr)
Constructor for QgsLocatorProxyModel, with the specified parent object.
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:62
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53
#define SIP_MONKEYPATCH_SCOPEENUM_UNNEST(OUTSIDE_CLASS, FORMERNAME)
Definition qgis_sip.h:268
#define SIP_MONKEYPATCH_COMPAT_NAME(FORMERNAME)
Definition qgis_sip.h:270