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() )
165 return QVariant::fromValue( mResults.at( index.row() ).result.actions );
173 if ( !index.isValid() || index.row() < 0 || index.column() < 0 ||
174 index.row() >=
rowCount( QModelIndex() ) || index.column() >=
columnCount( QModelIndex() ) )
175 return QAbstractTableModel::flags( index );
177 Qt::ItemFlags
flags = QAbstractTableModel::flags( index );
178 if ( mResults.at( index.row() ).filter )
180 flags =
flags & ~( Qt::ItemIsSelectable | Qt::ItemIsEnabled );
187 QHash<int, QByteArray> roles;
195 roles[Qt::DisplayRole] =
"Text";
201 mDeferredClearTimer.stop();
202 if ( mDeferredClear )
204 mFoundResultsFromFilterNames.clear();
205 mFoundResultsFilterGroups.clear();
208 int pos = mResults.size();
211 mFoundResultsFromFilterNames << result.
filter->
name();
213 bool addingGroup = !result.
group.isEmpty() && ( !mFoundResultsFilterGroups.contains( result.
filter )
214 || !mFoundResultsFilterGroups.value( result.
filter ).contains( result.
group ) );
217 if ( !mFoundResultsFilterGroups.contains( result.
filter ) )
218 mFoundResultsFilterGroups[result.
filter] = QStringList();
219 mFoundResultsFilterGroups[result.
filter] << result.
group ;
221 if ( mDeferredClear )
227 beginInsertRows( QModelIndex(), pos, pos + (
static_cast<int>( addingFilter ) +
static_cast<int>( addingGroup ) ) );
233 entry.filter = result.
filter;
240 entry.groupTitle = result.
group;
243 entry.groupSorting = mFoundResultsFilterGroups[result.
filter].count();
244 entry.filter = result.
filter;
248 entry.result = result;
250 entry.groupSorting = result.
group.isEmpty() ?
NoGroup : mFoundResultsFilterGroups[result.
filter].indexOf( result.
group ) + 1;
253 if ( mDeferredClear )
258 mDeferredClear =
false;
268 , mLocator( locator )
270 Q_ASSERT( mLocator );
288 mNextRequestedString = string;
289 mHasQueuedRequest =
true;
304 void QgsLocatorAutomaticModel::searchFinished()
306 if ( mHasQueuedRequest )
309 QString nextSearch = mNextRequestedString;
310 mNextRequestedString.clear();
311 mHasQueuedRequest =
false;
325 : QSortFilterProxyModel( parent )
327 setDynamicSortFilter(
true );
328 setSortLocaleAware(
true );
329 setFilterCaseSensitivity( Qt::CaseInsensitive );
338 if ( leftFilterPriority != rightFilterPriority )
339 return leftFilterPriority < rightFilterPriority;
344 if ( leftFilter != rightFilter )
345 return QString::localeAwareCompare( leftFilter, rightFilter ) < 0;
350 if ( leftTypeRole != rightTypeRole )
351 return leftTypeRole < rightTypeRole;
356 if ( leftGroupRole != rightGroupRole )
357 return leftGroupRole < rightGroupRole;
363 return leftScore > rightScore;
366 leftFilter = sourceModel()->data( left, Qt::DisplayRole ).toString();
367 rightFilter = sourceModel()->data( right, Qt::DisplayRole ).toString();
368 return QString::localeAwareCompare( leftFilter, rightFilter ) < 0;