mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-14 00:07:35 -04:00
[FEATURE] add lineedit with builtin clear button
This commit is contained in:
parent
603c0dc3ea
commit
8694cb8cd5
@ -172,6 +172,7 @@
|
||||
<file>themes/default/mIconClose.png</file>
|
||||
<file>themes/default/mIconCollapse.png</file>
|
||||
<file>themes/default/mIconConnect.png</file>
|
||||
<file>themes/default/mIconClear.png</file>
|
||||
<file>themes/default/mIconDbSchema.png</file>
|
||||
<file>themes/default/mIconDelete.png</file>
|
||||
<file>themes/default/mIconEditable.png</file>
|
||||
|
BIN
images/themes/default/mIconClear.png
Normal file
BIN
images/themes/default/mIconClear.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 773 B |
@ -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
|
||||
|
15
python/gui/qgsfilterlineedit.sip
Normal file
15
python/gui/qgsfilterlineedit.sip
Normal file
@ -0,0 +1,15 @@
|
||||
|
||||
/** LineEdit with builtin clear button
|
||||
*/
|
||||
class QgsFilterLineEdit : QLineEdit
|
||||
{
|
||||
%TypeHeaderCode
|
||||
#include <qgsfilterlineedit.h>
|
||||
%End
|
||||
|
||||
public:
|
||||
QgsFilterLineEdit( QWidget* parent = 0 );
|
||||
|
||||
protected:
|
||||
void resizeEvent( QResizeEvent * );
|
||||
};
|
@ -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
|
||||
|
56
src/gui/qgsfilterlineedit.cpp
Normal file
56
src/gui/qgsfilterlineedit.cpp
Normal file
@ -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 <QToolButton>
|
||||
#include <QStyle>
|
||||
|
||||
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() );
|
||||
}
|
44
src/gui/qgsfilterlineedit.h
Normal file
44
src/gui/qgsfilterlineedit.h
Normal file
@ -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 <QLineEdit>
|
||||
|
||||
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
|
Loading…
x
Reference in New Issue
Block a user