Skip to content

Commit 06b2b66

Browse files
committed
Adding search widget capability
1 parent 1e3b820 commit 06b2b66

File tree

5 files changed

+46
-5
lines changed

5 files changed

+46
-5
lines changed

src/app/qgsattributetabledialog.cpp

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
#include "qgsexpressionselectiondialog.h"
4343
#include "qgsfeaturelistmodel.h"
4444
#include "qgsrubberband.h"
45+
#include "qgsfield.h"
46+
#include "qgseditorwidgetregistry.h"
4547

4648
class QgsAttributeTableDock : public QDockWidget
4749
{
@@ -64,6 +66,7 @@ QgsAttributeTableDialog::QgsAttributeTableDialog( QgsVectorLayer *theLayer, QWid
6466
, mDock( 0 )
6567
, mLayer( theLayer )
6668
, mRubberBand( 0 )
69+
, mCurrentSearchWidget( 0 )
6770
{
6871
setupUi( this );
6972

@@ -407,7 +410,24 @@ void QgsAttributeTableDialog::filterColumnChanged( QObject* filterAction )
407410
mFilterButton->setDefaultAction( qobject_cast<QAction *>( filterAction ) );
408411
mFilterButton->setPopupMode( QToolButton::InstantPopup );
409412
mCbxCaseSensitive->setVisible( true );
410-
mFilterQuery->setVisible( true );
413+
// replace the search line edit with a search widget that is suited to the selected field
414+
mFilterQuery->setVisible( false );
415+
// delete previous widget
416+
if ( mCurrentSearchWidget != 0 )
417+
{
418+
//mFilterContainer->removeWidget(mCurrentSearchWidget);
419+
delete mCurrentSearchWidget;
420+
}
421+
QString fieldName = mFilterButton->defaultAction()->text();
422+
// get the search widget
423+
int fldIdx = mLayer->fieldNameIndex( fieldName );
424+
if ( fldIdx < 0 )
425+
return;
426+
const QString widgetType = mLayer->editorWidgetV2( fldIdx );
427+
const QgsEditorWidgetConfig widgetConfig = mLayer->editorWidgetV2Config( fldIdx );
428+
QgsEditorWidgetWrapper* eww = QgsEditorWidgetRegistry::instance()->create( widgetType, mLayer, fldIdx, widgetConfig, 0 , mFilterContainer);
429+
mCurrentSearchWidget = eww->widget();
430+
411431
mApplyFilterButton->setVisible( true );
412432
}
413433

@@ -677,7 +697,6 @@ void QgsAttributeTableDialog::filterQueryChanged( const QString& query )
677697
else
678698
{
679699
QString fieldName = mFilterButton->defaultAction()->text();
680-
681700
const QgsFields& flds = mLayer->pendingFields();
682701
int fldIndex = mLayer->fieldNameIndex( fieldName );
683702
if ( fldIndex < 0 )

src/app/qgsattributetabledialog.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,8 @@ class APP_EXPORT QgsAttributeTableDialog : public QDialog, private Ui::QgsAttrib
207207
QgsVectorLayer* mLayer;
208208
QgsFieldModel* mFieldModel;
209209

210-
QgsRubberBand *mRubberBand;
210+
QgsRubberBand* mRubberBand;
211+
QWidget* mCurrentSearchWidget;
211212
};
212213

213214
#endif

src/gui/editorwidgets/core/qgseditorwidgetfactory.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
***************************************************************************/
1515

1616
#include "qgseditorwidgetfactory.h"
17+
#include "qgsfilterlineedit.h"
1718

1819
#include <QSettings>
1920

@@ -26,6 +27,11 @@ QgsEditorWidgetFactory::~QgsEditorWidgetFactory()
2627
{
2728
}
2829

30+
QgsEditorWidgetWrapper* QgsEditorWidgetFactory::createSearchWidget( QgsVectorLayer* vl, int fieldIdx, QWidget* parent ){
31+
32+
return create(vl, fieldIdx, 0, parent);
33+
}
34+
2935
QString QgsEditorWidgetFactory::name()
3036
{
3137
return mName;

src/gui/editorwidgets/core/qgseditorwidgetfactory.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ class GUI_EXPORT QgsEditorWidgetFactory
6060
*/
6161
virtual QgsEditorWidgetWrapper* create( QgsVectorLayer* vl, int fieldIdx, QWidget* editor, QWidget* parent ) const = 0;
6262

63+
/**
64+
* Override this in your implementation, to get
65+
* something different than a QLineEdit
66+
*/
67+
QgsEditorWidgetWrapper* createSearchWidget( QgsVectorLayer* vl, int fieldIdx, QWidget* parent );
68+
6369
/**
6470
* Return The human readable identifier name of this widget type
6571
*

src/ui/qgsattributetabledialog.ui

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,16 @@
541541
</widget>
542542
</item>
543543
<item>
544-
<widget class="QgsFilterLineEdit" name="mFilterQuery"/>
544+
<widget class="QWidget" name="mFilterContainer" native="true">
545+
<layout class="QGridLayout" name="gridLayout_2">
546+
<property name="margin">
547+
<number>0</number>
548+
</property>
549+
<item row="0" column="0">
550+
<widget class="QgsFilterLineEdit" name="mFilterQuery"/>
551+
</item>
552+
</layout>
553+
</widget>
545554
</item>
546555
<item>
547556
<widget class="QWidget" name="mSpacer" native="true"/>
@@ -656,7 +665,7 @@
656665
</widget>
657666
</item>
658667
<item>
659-
<widget class="QgsFieldExpressionWidget" name="mUpdateExpressionText" native="true">
668+
<widget class="QgsFieldExpressionWidget" name="mUpdateExpressionText">
660669
<property name="sizePolicy">
661670
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
662671
<horstretch>0</horstretch>

0 commit comments

Comments
 (0)