QGIS API Documentation
4.3.0-Master (52aa6503bed)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
core
locator
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
29
class
QgsLocator
;
30
class
QgsLocatorModel
;
31
class
QgsLocatorProxyModel
;
32
42
class
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
59
enum class
CustomRole
SIP_MONKEYPATCH_SCOPEENUM_UNNEST
(
QgsLocatorModel
, Role ) : int
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
157
class
CORE_EXPORT
QgsLocatorAutomaticModel
:
public
QgsLocatorModel
158
{
159
Q_OBJECT
160
161
public
:
167
explicit
QgsLocatorAutomaticModel
(
QgsLocator
*
locator
SIP_TRANSFERTHIS
);
168
172
QgsLocator
*
locator
();
173
183
void
search
(
const
QString &
string
);
184
190
virtual
QgsLocatorContext
createContext
();
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
209
class
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
QgsLocatorAutomaticModel::locator
QgsLocator * locator()
Returns a pointer to the locator utilized by this model.
Definition
qgslocatormodel.cpp:313
QgsLocatorAutomaticModel::QgsLocatorAutomaticModel
QgsLocatorAutomaticModel(QgsLocator *locator)
Constructor for QgsLocatorAutomaticModel, linked with the specified locator.
Definition
qgslocatormodel.cpp:304
QgsLocatorAutomaticModel::search
void search(const QString &string)
Enqueues a search for a specified string within the model.
Definition
qgslocatormodel.cpp:318
QgsLocatorAutomaticModel::createContext
virtual QgsLocatorContext createContext()
Returns a new locator context for searches.
Definition
qgslocatormodel.cpp:337
QgsLocatorContext
Encapsulates the properties relating to the context of a locator search.
Definition
qgslocatorcontext.h:32
QgsLocatorModel
An abstract list model for displaying the results of locator searches.
Definition
qgslocatormodel.h:43
QgsLocatorModel::CustomRole
CustomRole
Custom model roles.
Definition
qgslocatormodel.h:60
QgsLocatorModel::QgsLocatorModel
QgsLocatorModel(QObject *parent=nullptr)
Constructor for QgsLocatorModel.
Definition
qgslocatormodel.cpp:36
QgsLocatorModel::UnorderedGroup
static const int UnorderedGroup
Definition
qgslocatormodel.h:48
QgsLocatorModel::NoGroup
static const int NoGroup
Definition
qgslocatormodel.h:47
QgsLocatorProxyModel
A sort proxy model for QgsLocatorModel, which automatically sorts results by precedence.
Definition
qgslocatormodel.h:210
QgsLocatorProxyModel::lessThan
bool lessThan(const QModelIndex &left, const QModelIndex &right) const override
Definition
qgslocatormodel.cpp:368
QgsLocatorProxyModel::QgsLocatorProxyModel
QgsLocatorProxyModel(QObject *parent=nullptr)
Constructor for QgsLocatorProxyModel, with the specified parent object.
Definition
qgslocatormodel.cpp:359
QgsLocatorResult
Encapsulates properties of an individual matching result found by a QgsLocatorFilter.
Definition
qgslocatorfilter.h:41
QgsLocator
Handles the management of QgsLocatorFilter objects and async collection of search results from them.
Definition
qgslocator.h:65
SIP_TRANSFERTHIS
#define SIP_TRANSFERTHIS
Definition
qgis_sip.h:52
SIP_MONKEYPATCH_SCOPEENUM_UNNEST
#define SIP_MONKEYPATCH_SCOPEENUM_UNNEST(OUTSIDE_CLASS, FORMERNAME)
Definition
qgis_sip.h:270
SIP_MONKEYPATCH_COMPAT_NAME
#define SIP_MONKEYPATCH_COMPAT_NAME(FORMERNAME)
Definition
qgis_sip.h:272
qgslocatorfilter.h
Generated on
for QGIS API Documentation by
1.17.0