Allow the browser to search into table comments

This commit is contained in:
Hugo Mercier 2015-09-18 10:20:11 +02:00 committed by Matthias Kuhn
parent 96f73fd549
commit 44d9b35163
2 changed files with 20 additions and 2 deletions

View File

@ -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
@ -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;
}
@ -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

View File

@ -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 )
{