Skip to content

Commit 44d9b35

Browse files
Hugo Mercierm-kuhn
Hugo Mercier
authored andcommittedSep 25, 2015
Allow the browser to search into table comments
1 parent 96f73fd commit 44d9b35

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed
 

‎src/app/qgsbrowserdockwidget.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,10 @@ class QgsBrowserTreeFilterProxyModel : public QSortFilterProxyModel
200200
if ( mFilter == "" || !mModel ) return true;
201201

202202
QModelIndex sourceIndex = mModel->index( sourceRow, 0, sourceParent );
203-
return filterAcceptsItem( sourceIndex ) || filterAcceptsAncestor( sourceIndex ) || filterAcceptsDescendant( sourceIndex );
203+
// also look into the comment column
204+
QModelIndex commentIndex = mModel->index( sourceRow, 1, sourceParent );
205+
return filterAcceptsItem( sourceIndex ) || filterAcceptsAncestor( sourceIndex ) || filterAcceptsDescendant( sourceIndex ) ||
206+
filterAcceptsItem( commentIndex ) || filterAcceptsAncestor( commentIndex ) || filterAcceptsDescendant( commentIndex );
204207
}
205208

206209
// returns true if at least one ancestor is accepted by filter
@@ -232,6 +235,11 @@ class QgsBrowserTreeFilterProxyModel : public QSortFilterProxyModel
232235
return true;
233236
if ( filterAcceptsDescendant( sourceChildIndex ) )
234237
return true;
238+
sourceChildIndex = mModel->index( i, 1, sourceIndex );
239+
if ( filterAcceptsItem( sourceChildIndex ) )
240+
return true;
241+
if ( filterAcceptsDescendant( sourceChildIndex ) )
242+
return true;
235243
}
236244
return false;
237245
}
@@ -532,6 +540,7 @@ void QgsBrowserDockWidget::showEvent( QShowEvent * e )
532540
// provide a horizontal scroll bar instead of using ellipse (...) for longer items
533541
mBrowserView->setTextElideMode( Qt::ElideNone );
534542
mBrowserView->header()->setResizeMode( 0, QHeaderView::ResizeToContents );
543+
mBrowserView->header()->setResizeMode( 1, QHeaderView::ResizeToContents );
535544
mBrowserView->header()->setStretchLastSection( false );
536545

537546
// selectionModel is created when model is set on tree

‎src/core/qgsbrowsermodel.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,16 @@ QVariant QgsBrowserModel::data( const QModelIndex &index, int role ) const
202202
}
203203
else if ( role == Qt::DisplayRole )
204204
{
205-
return item->name();
205+
if ( index.column() == 0 )
206+
{
207+
return item->name();
208+
}
209+
if ( item->type() == QgsDataItem::Layer )
210+
{
211+
QgsLayerItem* lyrItem = qobject_cast<QgsLayerItem*>(item);
212+
return lyrItem->comments();
213+
}
214+
return "";
206215
}
207216
else if ( role == Qt::ToolTipRole )
208217
{

0 commit comments

Comments
 (0)
Please sign in to comment.