QGIS API Documentation 4.0.0-Norrköping (1ddcee3d0e4)
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 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 enum Column
108 {
109 Name = 0,
110 Description
111 };
112
113
114 // sorting is made on these values!
115 enum class EntryType : int
116 {
117 Filter = 0,
118 Group = 1,
119 Result = 2,
120 };
121
122 struct Entry
123 {
124 EntryType type = EntryType::Result;
125 QgsLocatorResult result;
126 QString filterTitle;
127 QgsLocatorFilter *filter = nullptr;
128 QString groupTitle = QString();
129 double groupScore = UnorderedGroup;
130 };
131
132 QList<Entry> mResults;
133 QSet<QString> mFoundResultsFromFilterNames;
134 // maps locator with pair of group title and group score
135 QMap<QgsLocatorFilter *, QList<std::pair<QString, double>>> mFoundResultsFilterGroups;
136 bool mDeferredClear = false;
137 QTimer mDeferredClearTimer;
138};
139
158{
159 Q_OBJECT
160
161 public:
168
173
183 void search( const QString &string );
184
191
192 private slots:
193
194 void searchFinished();
195
196 private:
197 QgsLocator *mLocator = nullptr;
198
199 QString mNextRequestedString;
200 bool mHasQueuedRequest = false;
201};
202
209class CORE_EXPORT QgsLocatorProxyModel : public QSortFilterProxyModel
210{
211 Q_OBJECT
212
213 public:
217 explicit QgsLocatorProxyModel( QObject *parent SIP_TRANSFERTHIS = nullptr );
218 bool lessThan( const QModelIndex &left, const QModelIndex &right ) const override;
219};
220
221#endif // QGSLOCATORMODEL_H
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:65
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:52
#define SIP_MONKEYPATCH_SCOPEENUM_UNNEST(OUTSIDE_CLASS, FORMERNAME)
Definition qgis_sip.h:267
#define SIP_MONKEYPATCH_COMPAT_NAME(FORMERNAME)
Definition qgis_sip.h:269