@@ -66,6 +66,8 @@ QgsLocatorWidget::QgsLocatorWidget( QWidget *parent )
66
66
mProxyModel = new QgsLocatorProxyModel ( mLocatorModel );
67
67
mProxyModel ->setSourceModel ( mLocatorModel );
68
68
mResultsView ->setModel ( mProxyModel );
69
+ mResultsView ->setUniformRowHeights ( true );
70
+ mResultsView ->setIconSize ( QSize ( 16 , 16 ) );
69
71
mResultsView ->recalculateSize ();
70
72
71
73
connect ( mLocator , &QgsLocator::foundResult, this , &QgsLocatorWidget::addResult );
@@ -123,6 +125,14 @@ void QgsLocatorWidget::showList()
123
125
mResultsContainer ->raise ();
124
126
}
125
127
128
+ void QgsLocatorWidget::triggerSearchAndShowList ()
129
+ {
130
+ if ( mProxyModel ->rowCount () == 0 )
131
+ performSearch ();
132
+ else
133
+ showList ();
134
+ }
135
+
126
136
void QgsLocatorWidget::searchFinished ()
127
137
{
128
138
if ( mHasQueuedRequest )
@@ -146,15 +156,15 @@ bool QgsLocatorWidget::eventFilter( QObject *obj, QEvent *event )
146
156
case Qt::Key_Down:
147
157
case Qt::Key_PageUp:
148
158
case Qt::Key_PageDown:
149
- showList ();
159
+ triggerSearchAndShowList ();
150
160
mHasSelectedResult = true ;
151
161
QgsApplication::sendEvent ( mResultsView , event );
152
162
return true ;
153
163
case Qt::Key_Home:
154
164
case Qt::Key_End:
155
165
if ( keyEvent->modifiers () & Qt::ControlModifier )
156
166
{
157
- showList ();
167
+ triggerSearchAndShowList ();
158
168
mHasSelectedResult = true ;
159
169
QgsApplication::sendEvent ( mResultsView , event );
160
170
return true ;
@@ -192,7 +202,7 @@ bool QgsLocatorWidget::eventFilter( QObject *obj, QEvent *event )
192
202
}
193
203
else if ( event->type () == QEvent::FocusIn && obj == mLineEdit )
194
204
{
195
- showList ();
205
+ triggerSearchAndShowList ();
196
206
}
197
207
else if ( obj == window () && event->type () == QEvent::Resize )
198
208
{
@@ -272,7 +282,7 @@ QgsLocatorContext QgsLocatorWidget::createContext()
272
282
//
273
283
274
284
QgsLocatorModel::QgsLocatorModel ( QObject *parent )
275
- : QAbstractListModel ( parent )
285
+ : QAbstractTableModel ( parent )
276
286
{}
277
287
278
288
void QgsLocatorModel::clear ()
@@ -290,7 +300,7 @@ int QgsLocatorModel::rowCount( const QModelIndex & ) const
290
300
291
301
int QgsLocatorModel::columnCount ( const QModelIndex & ) const
292
302
{
293
- return 1 ;
303
+ return 2 ;
294
304
}
295
305
296
306
QVariant QgsLocatorModel::data ( const QModelIndex &index, int role ) const
@@ -304,17 +314,37 @@ QVariant QgsLocatorModel::data( const QModelIndex &index, int role ) const
304
314
case Qt::DisplayRole:
305
315
case Qt::EditRole:
306
316
{
307
- if ( !mResults .at ( index.row () ).filter )
308
- return mResults .at ( index.row () ).result .displayString ;
309
- else
310
- return mResults .at ( index.row () ).filterTitle ;
317
+ switch ( index.column () )
318
+ {
319
+ case Name:
320
+ if ( !mResults .at ( index.row () ).filter )
321
+ return mResults .at ( index.row () ).result .displayString ;
322
+ else
323
+ return mResults .at ( index.row () ).filterTitle ;
324
+ case Description:
325
+ if ( !mResults .at ( index.row () ).filter )
326
+ return mResults .at ( index.row () ).result .description ;
327
+ else
328
+ return QVariant ();
329
+ }
311
330
}
312
331
313
332
case Qt::DecorationRole:
314
- if ( !mResults .at ( index.row () ).filter )
315
- return mResults .at ( index.row () ).result .icon ;
316
- else
317
- return QVariant ();
333
+ switch ( index.column () )
334
+ {
335
+ case Name:
336
+ if ( !mResults .at ( index.row () ).filter )
337
+ {
338
+ QIcon icon = mResults .at ( index.row () ).result .icon ;
339
+ if ( !icon.isNull () )
340
+ return icon;
341
+ return QgsApplication::getThemeIcon ( " /search.svg" );
342
+ }
343
+ else
344
+ return QVariant ();
345
+ case Description:
346
+ return QVariant ();
347
+ }
318
348
319
349
case ResultDataRole:
320
350
if ( !mResults .at ( index.row () ).filter )
@@ -354,9 +384,9 @@ Qt::ItemFlags QgsLocatorModel::flags( const QModelIndex &index ) const
354
384
{
355
385
if ( !index.isValid () || index.row () < 0 || index.column () < 0 ||
356
386
index.row () >= rowCount ( QModelIndex () ) || index.column () >= columnCount ( QModelIndex () ) )
357
- return QAbstractListModel ::flags ( index );
387
+ return QAbstractTableModel ::flags ( index );
358
388
359
- Qt::ItemFlags flags = QAbstractListModel ::flags ( index );
389
+ Qt::ItemFlags flags = QAbstractTableModel ::flags ( index );
360
390
if ( !mResults .at ( index.row () ).filterTitle .isEmpty () )
361
391
{
362
392
flags = flags & ~( Qt::ItemIsSelectable | Qt::ItemIsEnabled );
@@ -411,6 +441,9 @@ void QgsLocatorResultsView::recalculateSize()
411
441
// resize the floating widget this is contained within
412
442
parentWidget ()->resize ( newSize );
413
443
QTreeView::resize ( newSize );
444
+
445
+ header ()->resizeSection ( 0 , width / 2 );
446
+ header ()->resizeSection ( 1 , 0 );
414
447
}
415
448
416
449
void QgsLocatorResultsView::selectNextResult ()
@@ -497,9 +530,10 @@ void QgsLocatorFilterFilter::fetchResults( const QString &string, const QgsLocat
497
530
498
531
QgsLocatorResult result;
499
532
result.filter = this ;
500
- result.displayString = QString ( " %1 (%2)" ).arg ( fIt .key (), fIt .value ()->displayName () );
533
+ result.displayString = fIt .key ();
534
+ result.description = fIt .value ()->displayName ();
501
535
result.userData = fIt .key () + ' ' ;
502
- // result.icon = action->icon( );
536
+ result.icon = QgsApplication::getThemeIcon ( " /search.svg " );
503
537
emit resultFetched ( result );
504
538
}
505
539
}
0 commit comments