Skip to content

Commit

Permalink
Allow the browser to search into table comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Hugo Mercier authored and m-kuhn committed Sep 25, 2015
1 parent 96f73fd commit 44d9b35
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
11 changes: 10 additions & 1 deletion src/app/qgsbrowserdockwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,10 @@ class QgsBrowserTreeFilterProxyModel : public QSortFilterProxyModel
if ( mFilter == "" || !mModel ) return true;

QModelIndex sourceIndex = mModel->index( sourceRow, 0, sourceParent );
return filterAcceptsItem( sourceIndex ) || filterAcceptsAncestor( sourceIndex ) || filterAcceptsDescendant( sourceIndex );
// also look into the comment column
QModelIndex commentIndex = mModel->index( sourceRow, 1, sourceParent );
return filterAcceptsItem( sourceIndex ) || filterAcceptsAncestor( sourceIndex ) || filterAcceptsDescendant( sourceIndex ) ||
filterAcceptsItem( commentIndex ) || filterAcceptsAncestor( commentIndex ) || filterAcceptsDescendant( commentIndex );
}

// returns true if at least one ancestor is accepted by filter
Expand Down Expand Up @@ -232,6 +235,11 @@ class QgsBrowserTreeFilterProxyModel : public QSortFilterProxyModel
return true;
if ( filterAcceptsDescendant( sourceChildIndex ) )
return true;
sourceChildIndex = mModel->index( i, 1, sourceIndex );
if ( filterAcceptsItem( sourceChildIndex ) )
return true;
if ( filterAcceptsDescendant( sourceChildIndex ) )
return true;
}
return false;
}
Expand Down Expand Up @@ -532,6 +540,7 @@ void QgsBrowserDockWidget::showEvent( QShowEvent * e )
// provide a horizontal scroll bar instead of using ellipse (...) for longer items
mBrowserView->setTextElideMode( Qt::ElideNone );
mBrowserView->header()->setResizeMode( 0, QHeaderView::ResizeToContents );
mBrowserView->header()->setResizeMode( 1, QHeaderView::ResizeToContents );
mBrowserView->header()->setStretchLastSection( false );

// selectionModel is created when model is set on tree
Expand Down
11 changes: 10 additions & 1 deletion src/core/qgsbrowsermodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,16 @@ QVariant QgsBrowserModel::data( const QModelIndex &index, int role ) const
}
else if ( role == Qt::DisplayRole )
{
return item->name();
if ( index.column() == 0 )
{
return item->name();
}
if ( item->type() == QgsDataItem::Layer )
{
QgsLayerItem* lyrItem = qobject_cast<QgsLayerItem*>(item);
return lyrItem->comments();
}
return "";
}
else if ( role == Qt::ToolTipRole )
{
Expand Down

0 comments on commit 44d9b35

Please sign in to comment.