31 : QAbstractTableModel( parent )
33 mDeferredClearTimer.setInterval( 100 );
34 mDeferredClearTimer.setSingleShot(
true );
40 mDeferredClearTimer.stop();
41 mDeferredClear =
false;
45 mFoundResultsFromFilterNames.clear();
46 mFoundResultsFilterGroups.clear();
52 mDeferredClear =
true;
53 mDeferredClearTimer.start();
58 return mResults.size();
68 if ( !index.isValid() || index.row() < 0 || index.column() < 0 ||
69 index.row() >=
rowCount( QModelIndex() ) || index.column() >=
columnCount( QModelIndex() ) )
77 switch ( index.column() )
80 if ( !mResults.at( index.row() ).filter )
81 return mResults.at( index.row() ).result.displayString;
82 else if ( mResults.at( index.row() ).filter && mResults.at( index.row() ).groupSorting == 0 )
83 return mResults.at( index.row() ).filterTitle;
86 QString groupTitle = mResults.at( index.row() ).groupTitle;
87 groupTitle.prepend(
" " );
91 if ( !mResults.at( index.row() ).filter )
92 return mResults.at( index.row() ).result.description;
100 if ( index.column() == Name && !mResults.at( index.row() ).groupTitle.isEmpty() )
103 font.setItalic(
true );
112 case Qt::DecorationRole:
113 switch ( index.column() )
116 if ( !mResults.at( index.row() ).filter )
118 QIcon icon = mResults.at( index.row() ).result.icon;
119 if ( !icon.isNull() )
131 if ( !mResults.at( index.row() ).filter )
132 return QVariant::fromValue( mResults.at( index.row() ).result );
138 return mResults.at( index.row() ).groupSorting;
141 if ( mResults.at( index.row() ).filter )
144 return ( mResults.at( index.row() ).result.score );
147 if ( !mResults.at( index.row() ).filter )
148 return mResults.at( index.row() ).result.filter->priority();
150 return mResults.at( index.row() ).filter->priority();
153 if ( !mResults.at( index.row() ).filter )
154 return mResults.at( index.row() ).result.filter->displayName();
156 return mResults.at( index.row() ).filterTitle;
159 if ( mResults.at( index.row() ).groupTitle.isEmpty() )
170 if ( !index.isValid() || index.row() < 0 || index.column() < 0 ||
171 index.row() >=
rowCount( QModelIndex() ) || index.column() >=
columnCount( QModelIndex() ) )
172 return QAbstractTableModel::flags( index );
174 Qt::ItemFlags
flags = QAbstractTableModel::flags( index );
175 if ( mResults.at( index.row() ).filter )
177 flags = flags & ~( Qt::ItemIsSelectable | Qt::ItemIsEnabled );
184 mDeferredClearTimer.stop();
185 if ( mDeferredClear )
187 mFoundResultsFromFilterNames.clear();
188 mFoundResultsFilterGroups.clear();
191 int pos = mResults.size();
194 mFoundResultsFromFilterNames << result.
filter->
name();
196 bool addingGroup = !result.
group.isEmpty() && ( !mFoundResultsFilterGroups.contains( result.
filter )
197 || !mFoundResultsFilterGroups.value( result.
filter ).contains( result.
group ) );
200 if ( !mFoundResultsFilterGroups.contains( result.
filter ) )
201 mFoundResultsFilterGroups[result.
filter] = QStringList();
202 mFoundResultsFilterGroups[result.
filter] << result.
group ;
204 if ( mDeferredClear )
210 beginInsertRows( QModelIndex(), pos, pos + ( static_cast<int>( addingFilter ) + static_cast<int>( addingGroup ) ) );
216 entry.filter = result.
filter;
223 entry.groupTitle = result.
group;
226 entry.groupSorting = mFoundResultsFilterGroups[result.
filter].count();
227 entry.filter = result.
filter;
231 entry.result = result;
233 entry.groupSorting = result.
group.isEmpty() ?
NoGroup : mFoundResultsFilterGroups[result.
filter].count();
236 if ( mDeferredClear )
241 mDeferredClear =
false;
251 , mLocator( locator )
253 Q_ASSERT( mLocator );
271 mNextRequestedString = string;
272 mHasQueuedRequest =
true;
287 void QgsLocatorAutomaticModel::searchFinished()
289 if ( mHasQueuedRequest )
292 QString nextSearch = mNextRequestedString;
293 mNextRequestedString.clear();
294 mHasQueuedRequest =
false;
308 : QSortFilterProxyModel( parent )
310 setDynamicSortFilter(
true );
311 setSortLocaleAware(
true );
312 setFilterCaseSensitivity( Qt::CaseInsensitive );
321 if ( leftFilterPriority != rightFilterPriority )
322 return leftFilterPriority < rightFilterPriority;
327 if ( leftFilter != rightFilter )
328 return QString::localeAwareCompare( leftFilter, rightFilter ) < 0;
333 if ( leftTypeRole != rightTypeRole )
334 return leftTypeRole < rightTypeRole;
339 if ( leftGroupRole != rightGroupRole )
340 return leftGroupRole < rightGroupRole;
346 return leftScore > rightScore;
349 leftFilter = sourceModel()->data( left, Qt::DisplayRole ).toString();
350 rightFilter = sourceModel()->data( right, Qt::DisplayRole ).toString();
351 return QString::localeAwareCompare( leftFilter, rightFilter ) < 0;
QgsLocatorAutomaticModel(QgsLocator *locator)
Constructor for QgsLocatorAutomaticModel, linked with the specified locator.
void cancelWithoutBlocking()
Triggers cancelation of any current running query without blocking.
virtual QString displayName() const =0
Returns a translated, user-friendly name for the filter.
void fetchResults(const QString &string, const QgsLocatorContext &context, QgsFeedback *feedback=nullptr)
Triggers the background fetching of filter results for a specified search string. ...
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
QgsLocatorProxyModel(QObject *parent=nullptr)
Constructor for QgsLocatorProxyModel, with the specified parent object.
static QIcon getThemeIcon(const QString &name)
Helper to get a theme icon.
bool isRunning() const
Returns true if a query is currently being executed by the locator.
QgsLocator * locator()
Returns a pointer to the locator utilized by this model.
Qt::ItemFlags flags(const QModelIndex &index) const override
QString group
Group the results by categories If left as empty string, this means that results are all shown withou...
void search(const QString &string)
Enqueues a search for a specified string within the model.
void finished()
Emitted when locator has finished a query, either as a result of successful completion or early cance...
bool lessThan(const QModelIndex &left, const QModelIndex &right) const override
QgsLocatorModel(QObject *parent=nullptr)
Constructor for QgsLocatorModel.
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Group results within the same filter results.
int columnCount(const QModelIndex &parent=QModelIndex()) const override
Encapsulates the properties relating to the context of a locator search.
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...
void foundResult(const QgsLocatorResult &result)
Emitted whenever a filter encounters a matching result after the fetchResults() method is called...
An abstract list model for displaying the results of locator searches.
Result priority, used by QgsLocatorProxyModel for sorting roles.
void deferredClear()
Resets the model and clears all existing results after a short delay, or whenever the next result is ...
Result match score, used by QgsLocatorProxyModel for sorting roles.
QgsLocatorFilter * filter
Filter from which the result was obtained.
virtual QString name() const =0
Returns the unique name for the filter.
void addResult(const QgsLocatorResult &result)
Adds a new result to the model.
void clear()
Resets the model and clears all existing results.
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
virtual QgsLocatorContext createContext()
Returns a new locator context for searches.
Associated filter name which created the result.