diff --git a/images/images.qrc b/images/images.qrc
index eafffedb6a4..5e8c9839ef9 100644
--- a/images/images.qrc
+++ b/images/images.qrc
@@ -172,6 +172,7 @@
themes/default/mIconClose.png
themes/default/mIconCollapse.png
themes/default/mIconConnect.png
+ themes/default/mIconClear.png
themes/default/mIconDbSchema.png
themes/default/mIconDelete.png
themes/default/mIconEditable.png
diff --git a/images/themes/default/mIconClear.png b/images/themes/default/mIconClear.png
new file mode 100644
index 00000000000..e6c8e8b9f34
Binary files /dev/null and b/images/themes/default/mIconClear.png differ
diff --git a/python/gui/gui.sip b/python/gui/gui.sip
index e281804ac11..76752b8372e 100644
--- a/python/gui/gui.sip
+++ b/python/gui/gui.sip
@@ -23,6 +23,7 @@
%Include qgsexpressionhighlighter.sip
%Include qgsfieldvalidator.sip
%Include qgsfiledropedit.sip
+%Include qgsfilterlineedit.sip
%Include qgsformannotationitem.sip
%Include qgsgenericprojectionselector.sip
%Include qgshtmlannotationitem.sip
diff --git a/python/gui/qgsfilterlineedit.sip b/python/gui/qgsfilterlineedit.sip
new file mode 100644
index 00000000000..f6bd905f65b
--- /dev/null
+++ b/python/gui/qgsfilterlineedit.sip
@@ -0,0 +1,15 @@
+
+/** LineEdit with builtin clear button
+ */
+class QgsFilterLineEdit : QLineEdit
+{
+%TypeHeaderCode
+#include
+%End
+
+ public:
+ QgsFilterLineEdit( QWidget* parent = 0 );
+
+ protected:
+ void resizeEvent( QResizeEvent * );
+};
diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt
index b16d066ff6d..2419da34304 100644
--- a/src/gui/CMakeLists.txt
+++ b/src/gui/CMakeLists.txt
@@ -98,6 +98,7 @@ qgsexpressionbuilderdialog.cpp
qgsexpressionhighlighter.cpp
qgsquerybuilder.cpp
qgscollapsiblegroupbox.cpp
+qgsfilterlineedit.cpp
)
IF (WITH_TOUCH)
@@ -186,6 +187,7 @@ qgsexpressionbuilderwidget.h
qgsexpressionhighlighter.h
qgsquerybuilder.h
qgscollapsiblegroupbox.h
+qgsfilterlineedit.h
)
QT4_WRAP_CPP(QGIS_GUI_MOC_SRCS ${QGIS_GUI_MOC_HDRS})
@@ -225,6 +227,7 @@ qgsexpressionbuilderwidget.h
qgsexpressionbuilderdialog.h
qgsexpressionhighlighter.h
qgscollapsiblegroupbox.h
+qgsfilterlineedit.h
attributetable/qgsattributetablemodel.h
attributetable/qgsattributetablememorymodel.h
diff --git a/src/gui/qgsfilterlineedit.cpp b/src/gui/qgsfilterlineedit.cpp
new file mode 100644
index 00000000000..77b905b7833
--- /dev/null
+++ b/src/gui/qgsfilterlineedit.cpp
@@ -0,0 +1,56 @@
+/***************************************************************************
+ qgsfilterlineedit.cpp
+ ------------------------
+ begin : October 27, 2012
+ copyright : (C) 2012 by Alexander Bruy
+ email : alexander dot bruy at gmail dot com
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#include "qgsfilterlineedit.h"
+#include "qgsapplication.h"
+
+#include
+#include
+
+QgsFilterLineEdit::QgsFilterLineEdit( QWidget* parent ) : QLineEdit( parent )
+{
+ btnClear = new QToolButton( this );
+ btnClear->setIcon( QgsApplication::getThemeIcon( "/mIconClear.png" ) );
+ btnClear->setCursor(Qt::ArrowCursor);
+ btnClear->setStyleSheet( "QToolButton { border: none; padding: 0px; }" );
+ btnClear->hide();
+
+ connect( btnClear, SIGNAL( clicked() ), this, SLOT( clear() ) );
+ 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 ) );
+
+ QSize msz = minimumSizeHint();
+ setMinimumSize( qMax( msz.width(), btnClear->sizeHint().height() + frameWidth * 2 + 2 ),
+ qMax( msz.height(), btnClear->sizeHint().height() + frameWidth * 2 + 2 ) );
+}
+
+void QgsFilterLineEdit::resizeEvent( QResizeEvent * )
+{
+ QSize sz = btnClear->sizeHint();
+ int frameWidth = style()->pixelMetric( QStyle::PM_DefaultFrameWidth );
+ btnClear->move( rect().right() - frameWidth - sz.width(),
+ ( rect().bottom() + 1 - sz.height() ) / 2 );
+}
+
+void QgsFilterLineEdit::toggleClearButton( const QString &text )
+{
+ btnClear->setVisible( !text.isEmpty() );
+}
diff --git a/src/gui/qgsfilterlineedit.h b/src/gui/qgsfilterlineedit.h
new file mode 100644
index 00000000000..a360ea19974
--- /dev/null
+++ b/src/gui/qgsfilterlineedit.h
@@ -0,0 +1,44 @@
+/***************************************************************************
+ qgsfilterlineedit.h
+ ------------------------
+ begin : October 27, 2012
+ copyright : (C) 2012 by Alexander Bruy
+ email : alexander dot bruy at gmail dot com
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#ifndef QGSFILTERLINEEDIT_H
+#define QGSFILTERLINEEDIT_H
+
+#include
+
+class QToolButton;
+
+/** \ingroup gui
+ * Lineedit with builtin clear button
+ **/
+class GUI_EXPORT QgsFilterLineEdit : public QLineEdit
+{
+ Q_OBJECT
+ public:
+ QgsFilterLineEdit( QWidget* parent = 0 );
+
+ protected:
+ void resizeEvent( QResizeEvent * );
+
+ private slots:
+ void toggleClearButton( const QString &text );
+
+ private:
+ QToolButton *btnClear;
+};
+
+#endif // QGSFILTERLINEEDIT_H