Skip to content

Commit

Permalink
Adding search widget capability
Browse files Browse the repository at this point in the history
  • Loading branch information
carolinux committed May 21, 2015
1 parent 1e3b820 commit 06b2b66
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 5 deletions.
23 changes: 21 additions & 2 deletions src/app/qgsattributetabledialog.cpp
Expand Up @@ -42,6 +42,8 @@
#include "qgsexpressionselectiondialog.h"
#include "qgsfeaturelistmodel.h"
#include "qgsrubberband.h"
#include "qgsfield.h"
#include "qgseditorwidgetregistry.h"

class QgsAttributeTableDock : public QDockWidget
{
Expand All @@ -64,6 +66,7 @@ QgsAttributeTableDialog::QgsAttributeTableDialog( QgsVectorLayer *theLayer, QWid
, mDock( 0 )
, mLayer( theLayer )
, mRubberBand( 0 )
, mCurrentSearchWidget( 0 )
{
setupUi( this );

Expand Down Expand Up @@ -407,7 +410,24 @@ void QgsAttributeTableDialog::filterColumnChanged( QObject* filterAction )
mFilterButton->setDefaultAction( qobject_cast<QAction *>( filterAction ) );
mFilterButton->setPopupMode( QToolButton::InstantPopup );
mCbxCaseSensitive->setVisible( true );
mFilterQuery->setVisible( true );
// replace the search line edit with a search widget that is suited to the selected field
mFilterQuery->setVisible( false );
// delete previous widget
if ( mCurrentSearchWidget != 0 )
{
//mFilterContainer->removeWidget(mCurrentSearchWidget);
delete mCurrentSearchWidget;
}
QString fieldName = mFilterButton->defaultAction()->text();
// get the search widget
int fldIdx = mLayer->fieldNameIndex( fieldName );
if ( fldIdx < 0 )
return;
const QString widgetType = mLayer->editorWidgetV2( fldIdx );
const QgsEditorWidgetConfig widgetConfig = mLayer->editorWidgetV2Config( fldIdx );
QgsEditorWidgetWrapper* eww = QgsEditorWidgetRegistry::instance()->create( widgetType, mLayer, fldIdx, widgetConfig, 0 , mFilterContainer);
mCurrentSearchWidget = eww->widget();

mApplyFilterButton->setVisible( true );
}

Expand Down Expand Up @@ -677,7 +697,6 @@ void QgsAttributeTableDialog::filterQueryChanged( const QString& query )
else
{
QString fieldName = mFilterButton->defaultAction()->text();

const QgsFields& flds = mLayer->pendingFields();
int fldIndex = mLayer->fieldNameIndex( fieldName );
if ( fldIndex < 0 )
Expand Down
3 changes: 2 additions & 1 deletion src/app/qgsattributetabledialog.h
Expand Up @@ -207,7 +207,8 @@ class APP_EXPORT QgsAttributeTableDialog : public QDialog, private Ui::QgsAttrib
QgsVectorLayer* mLayer;
QgsFieldModel* mFieldModel;

QgsRubberBand *mRubberBand;
QgsRubberBand* mRubberBand;
QWidget* mCurrentSearchWidget;
};

#endif
6 changes: 6 additions & 0 deletions src/gui/editorwidgets/core/qgseditorwidgetfactory.cpp
Expand Up @@ -14,6 +14,7 @@
***************************************************************************/

#include "qgseditorwidgetfactory.h"
#include "qgsfilterlineedit.h"

#include <QSettings>

Expand All @@ -26,6 +27,11 @@ QgsEditorWidgetFactory::~QgsEditorWidgetFactory()
{
}

QgsEditorWidgetWrapper* QgsEditorWidgetFactory::createSearchWidget( QgsVectorLayer* vl, int fieldIdx, QWidget* parent ){

return create(vl, fieldIdx, 0, parent);
}

QString QgsEditorWidgetFactory::name()
{
return mName;
Expand Down
6 changes: 6 additions & 0 deletions src/gui/editorwidgets/core/qgseditorwidgetfactory.h
Expand Up @@ -60,6 +60,12 @@ class GUI_EXPORT QgsEditorWidgetFactory
*/
virtual QgsEditorWidgetWrapper* create( QgsVectorLayer* vl, int fieldIdx, QWidget* editor, QWidget* parent ) const = 0;

/**
* Override this in your implementation, to get
* something different than a QLineEdit
*/
QgsEditorWidgetWrapper* createSearchWidget( QgsVectorLayer* vl, int fieldIdx, QWidget* parent );

/**
* Return The human readable identifier name of this widget type
*
Expand Down
13 changes: 11 additions & 2 deletions src/ui/qgsattributetabledialog.ui
Expand Up @@ -541,7 +541,16 @@
</widget>
</item>
<item>
<widget class="QgsFilterLineEdit" name="mFilterQuery"/>
<widget class="QWidget" name="mFilterContainer" native="true">
<layout class="QGridLayout" name="gridLayout_2">
<property name="margin">
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QgsFilterLineEdit" name="mFilterQuery"/>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QWidget" name="mSpacer" native="true"/>
Expand Down Expand Up @@ -656,7 +665,7 @@
</widget>
</item>
<item>
<widget class="QgsFieldExpressionWidget" name="mUpdateExpressionText" native="true">
<widget class="QgsFieldExpressionWidget" name="mUpdateExpressionText">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
Expand Down

0 comments on commit 06b2b66

Please sign in to comment.