Skip to content
Permalink
Browse files

browser dock filter: use QgsFilterLineEdit, ui and code cleanup ; add…

… QgsFilterLineEdit::cleared() signal
  • Loading branch information
etiennesky committed Nov 3, 2012
1 parent e3ccde1 commit dbe54d080bca81f6558c120c5f06649e7e7f4291
@@ -78,7 +78,6 @@
<file>themes/default/mActionFileSave.png</file>
<file>themes/default/mActionFileSmall.png</file>
<file>themes/default/mActionFilter.png</file>
<file>themes/default/mActionFilterDelete.png</file>
<file>themes/default/mActionFolder.png</file>
<file>themes/default/mActionFormAnnotation.png</file>
<file>themes/default/mActionFromSelectedFeature.png</file>
Binary file not shown.
@@ -83,6 +83,9 @@ class QgsBrowserTreeView : public QTreeView
}
};

/**
Utility class for filtering browser items
*/
class QgsBrowserTreeFilterProxyModel : public QSortFilterProxyModel
{
public:
@@ -125,7 +128,7 @@ class QgsBrowserTreeFilterProxyModel : public QSortFilterProxyModel
if ( mPatternSyntax == QRegExp::Wildcard ||
mPatternSyntax == QRegExp::WildcardUnix )
{
foreach( QString f, mFilter.split( "|" ) )
foreach ( QString f, mFilter.split( "|" ) )
{
QRegExp rx( f.trimmed() );
rx.setPatternSyntax( mPatternSyntax );
@@ -150,11 +153,10 @@ class QgsBrowserTreeFilterProxyModel : public QSortFilterProxyModel

bool filterAcceptsString( const QString & value ) const
{
// return ( filterRegExp().exactMatch( fileInfo.fileName() ) );
if ( mPatternSyntax == QRegExp::Wildcard ||
mPatternSyntax == QRegExp::WildcardUnix )
{
foreach( QRegExp rx, mREList )
foreach ( QRegExp rx, mREList )
{
QgsDebugMsg( QString( "value: [%1] rx: [%2] match: %3" ).arg( value ).arg( rx.pattern() ).arg( rx.exactMatch( value ) ) );
if ( rx.exactMatch( value ) )
@@ -163,15 +165,9 @@ class QgsBrowserTreeFilterProxyModel : public QSortFilterProxyModel
}
else
{
foreach( QRegExp rx, mREList )
foreach ( QRegExp rx, mREList )
{
QgsDebugMsg( QString( "value: [%1] rx: [%2] match: %3" ).arg( value ).arg( rx.pattern() ).arg( rx.indexIn( value ) ) );
QRegExp rx2( "\\b(mail|letter|correspondence)\\b" );
QgsDebugMsg( QString( "value: [%1] rx2: [%2] match: %3" ).arg( value ).arg( rx2.pattern() ).arg( rx2.indexIn( value ) ) );
QgsDebugMsg( QString( "T1 %1" ).arg( rx2.indexIn( "I sent you an email" ) ) ); // returns -1 (no match)
QgsDebugMsg( QString( "T2 %2" ).arg( rx2.indexIn( "Please write the letter" ) ) ); // returns -1 (no match)
QgsDebugMsg( QString( "T3 %2" ).arg( rx.indexIn( "Please write the letter" ) ) ); // returns -1 (no match)

if ( rx.indexIn( value ) != -1 )
return true;
}
@@ -226,15 +222,14 @@ QgsBrowserDockWidget::QgsBrowserDockWidget( QWidget * parent ) :
mBrowserView = new QgsBrowserTreeView( this );
mLayoutBrowser->addWidget( mBrowserView );

mBtnRefresh->setIcon( QgisApp::instance()->getThemeIcon( "mActionRefresh.png" ) );
mBtnAddLayers->setIcon( QgisApp::instance()->getThemeIcon( "mActionAdd.png" ) );
mBtnCollapse->setIcon( QgisApp::instance()->getThemeIcon( "mActionCollapseTree.png" ) );
mBtnRefresh->setIcon( QgsApplication::getThemeIcon( "mActionRefresh.png" ) );
mBtnAddLayers->setIcon( QgsApplication::getThemeIcon( "mActionAdd.png" ) );
mBtnCollapse->setIcon( QgsApplication::getThemeIcon( "mActionCollapseTree.png" ) );

mWidgetFilter->hide();
// icons from http://www.fatcow.com/free-icons License: CC Attribution 3.0
mBtnFilterShow->setIcon( QgisApp::instance()->getThemeIcon( "mActionFilter.png" ) );
mBtnFilter->setIcon( QgisApp::instance()->getThemeIcon( "mActionFilter.png" ) );
mBtnFilterClear->setIcon( QgisApp::instance()->getThemeIcon( "mActionFilterDelete.png" ) );
mBtnFilterShow->setIcon( QgsApplication::getThemeIcon( "mActionFilter.png" ) );
mBtnFilter->setIcon( QgsApplication::getThemeIcon( "mActionFilter.png" ) );

QMenu* menu = new QMenu( this );
menu->setSeparatorsCollapsible( false );
@@ -243,27 +238,24 @@ QgsBrowserDockWidget::QgsBrowserDockWidget( QWidget * parent ) :
QAction* action = new QAction( tr( "Filter Pattern Syntax" ), group );
action->setSeparator( true );
menu->addAction( action );
// group->addAction( action );
action = new QAction( tr( "Wildcard(s)" ), group );
action->setData( QVariant(( int ) QRegExp::Wildcard ) );
action->setCheckable( true );
action->setChecked( true );
menu->addAction( action );
// group->addAction( action );
// menu->addSeparator()->setText( tr( "Pattern Syntax" ) );
action = new QAction( tr( "Regular Expression" ), group );
action->setData( QVariant(( int ) QRegExp::RegExp ) );
action->setCheckable( true );
menu->addAction( action );
// group->addAction( action );

connect( mBtnRefresh, SIGNAL( clicked() ), this, SLOT( refresh() ) );
connect( mBtnAddLayers, SIGNAL( clicked() ), this, SLOT( addSelectedLayers() ) );
connect( mBtnCollapse, SIGNAL( clicked() ), mBrowserView, SLOT( collapseAll() ) );
connect( mBtnFilterShow, SIGNAL( toggled( bool ) ), this, SLOT( showFilterWidget( bool ) ) );
connect( mBtnFilter, SIGNAL( clicked() ), this, SLOT( setFilter() ) );
connect( mLeFilter, SIGNAL( returnPressed() ), this, SLOT( setFilter() ) );
connect( mBtnFilterClear, SIGNAL( clicked() ), this, SLOT( clearFilter() ) );
connect( mLeFilter, SIGNAL( cleared() ), this, SLOT( setFilter() ) );
// connect( mLeFilter, SIGNAL( textChanged( const QString & ) ), this, SLOT( setFilter() ) );
connect( group, SIGNAL( triggered( QAction * ) ), this, SLOT( setFilterSyntax( QAction * ) ) );

connect( mBrowserView, SIGNAL( customContextMenuRequested( const QPoint & ) ), this, SLOT( showContextMenu( const QPoint & ) ) );
@@ -624,7 +616,10 @@ void QgsBrowserDockWidget::showFilterWidget( bool visible )
{
mWidgetFilter->setVisible( visible );
if ( ! visible )
clearFilter();
{
mLeFilter->setText( "" );
setFilter();
}
}

void QgsBrowserDockWidget::setFilter( )
@@ -641,12 +636,6 @@ void QgsBrowserDockWidget::setFilterSyntax( QAction * action )
mProxyModel->setFilterSyntax(( QRegExp::PatternSyntax ) action->data().toInt() );
}

void QgsBrowserDockWidget::clearFilter( )
{
mLeFilter->setText( "" );
setFilter();
}

QgsDataItem* QgsBrowserDockWidget::dataItem( const QModelIndex& index )
{
if ( ! mProxyModel )
@@ -46,7 +46,6 @@ class QgsBrowserDockWidget : public QDockWidget, private Ui::QgsBrowserDockWidge
void showFilterWidget( bool visible );
void setFilterSyntax( QAction * );
void setFilter();
void clearFilter();

// layer menu items
void addCurrentLayer();
@@ -25,17 +25,18 @@ QgsFilterLineEdit::QgsFilterLineEdit( QWidget* parent ) : QLineEdit( parent )
{
btnClear = new QToolButton( this );
btnClear->setIcon( QgsApplication::getThemeIcon( "/mIconClear.png" ) );
btnClear->setCursor(Qt::ArrowCursor);
btnClear->setCursor( Qt::ArrowCursor );
btnClear->setStyleSheet( "QToolButton { border: none; padding: 0px; }" );
btnClear->hide();

connect( btnClear, SIGNAL( clicked() ), this, SLOT( clear() ) );
connect( btnClear, SIGNAL( clicked() ), this, SIGNAL( cleared() ) );
connect( this, SIGNAL( textChanged( const QString& ) ), this,
SLOT( toggleClearButton( const QString& ) ) );

int frameWidth = style()->pixelMetric( QStyle::PM_DefaultFrameWidth );
setStyleSheet( QString( "QLineEdit { padding-right: %1px; } " )
.arg( btnClear->sizeHint().width() + frameWidth + 1 ) );
.arg( btnClear->sizeHint().width() + frameWidth + 1 ) );

QSize msz = minimumSizeHint();
setMinimumSize( qMax( msz.width(), btnClear->sizeHint().height() + frameWidth * 2 + 2 ),
@@ -31,6 +31,9 @@ class GUI_EXPORT QgsFilterLineEdit : public QLineEdit
public:
QgsFilterLineEdit( QWidget* parent = 0 );

signals:
void cleared();

protected:
void resizeEvent( QResizeEvent * );

0 comments on commit dbe54d0

Please sign in to comment.
You can’t perform that action at this time.