29 : QAbstractTableModel( parent )
31 mDeferredClearTimer.setInterval( 100 );
32 mDeferredClearTimer.setSingleShot(
true );
38 mDeferredClearTimer.stop();
39 mDeferredClear =
false;
43 mFoundResultsFromFilterNames.clear();
49 mDeferredClear =
true;
50 mDeferredClearTimer.start();
55 return mResults.size();
65 if ( !index.isValid() || index.row() < 0 || index.column() < 0 ||
66 index.row() >=
rowCount( QModelIndex() ) || index.column() >=
columnCount( QModelIndex() ) )
74 switch ( index.column() )
77 if ( !mResults.at( index.row() ).filter )
78 return mResults.at( index.row() ).result.displayString;
80 return mResults.at( index.row() ).filterTitle;
82 if ( !mResults.at( index.row() ).filter )
83 return mResults.at( index.row() ).result.description;
90 case Qt::DecorationRole:
91 switch ( index.column() )
94 if ( !mResults.at( index.row() ).filter )
96 QIcon icon = mResults.at( index.row() ).result.icon;
109 if ( !mResults.at( index.row() ).filter )
110 return QVariant::fromValue( mResults.at( index.row() ).result );
115 if ( mResults.at( index.row() ).filter )
121 if ( mResults.at( index.row() ).filter )
124 return ( mResults.at( index.row() ).result.score );
127 if ( !mResults.at( index.row() ).filter )
128 return mResults.at( index.row() ).result.filter->priority();
130 return mResults.at( index.row() ).filter->priority();
133 if ( !mResults.at( index.row() ).filter )
134 return mResults.at( index.row() ).result.filter->displayName();
136 return mResults.at( index.row() ).filterTitle;
144 if ( !index.isValid() || index.row() < 0 || index.column() < 0 ||
145 index.row() >=
rowCount( QModelIndex() ) || index.column() >=
columnCount( QModelIndex() ) )
146 return QAbstractTableModel::flags( index );
148 Qt::ItemFlags
flags = QAbstractTableModel::flags( index );
149 if ( !mResults.at( index.row() ).filterTitle.isEmpty() )
151 flags = flags & ~( Qt::ItemIsSelectable | Qt::ItemIsEnabled );
158 mDeferredClearTimer.stop();
159 if ( mDeferredClear )
161 mFoundResultsFromFilterNames.clear();
164 int pos = mResults.size();
167 mFoundResultsFromFilterNames << result.
filter->
name();
169 if ( mDeferredClear )
175 beginInsertRows( QModelIndex(), pos, pos + ( addingFilter ? 1 : 0 ) );
181 entry.filter = result.
filter;
185 entry.result = result;
188 if ( mDeferredClear )
193 mDeferredClear =
false;
203 , mLocator( locator )
205 Q_ASSERT( mLocator );
223 mNextRequestedString = string;
224 mHasQueuedRequest =
true;
239 void QgsLocatorAutomaticModel::searchFinished()
241 if ( mHasQueuedRequest )
244 QString nextSearch = mNextRequestedString;
245 mNextRequestedString.clear();
246 mHasQueuedRequest =
false;
260 : QSortFilterProxyModel( parent )
262 setDynamicSortFilter(
true );
263 setSortLocaleAware(
true );
264 setFilterCaseSensitivity( Qt::CaseInsensitive );
273 if ( leftFilterPriority != rightFilterPriority )
274 return leftFilterPriority < rightFilterPriority;
279 if ( leftFilter != rightFilter )
280 return QString::localeAwareCompare( leftFilter, rightFilter ) < 0;
285 if ( leftTypeRole != rightTypeRole )
286 return leftTypeRole < rightTypeRole;
292 return leftScore > rightScore;
295 leftFilter = sourceModel()->data( left, Qt::DisplayRole ).toString();
296 rightFilter = sourceModel()->data( right, Qt::DisplayRole ).toString();
297 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. ...
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
void search(const QString &string)
Enqueues a search for a specified string within the model.
bool qgsDoubleNear(double a, double b, double epsilon=4 *DBL_EPSILON)
Compare two doubles (but allow some difference)
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
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.