Skip to content

Commit

Permalink
QgsValueMapSearchW inherits QgsSearchW
Browse files Browse the repository at this point in the history
and not QgsDefaultSearchW anymore
fixes expression creation
  • Loading branch information
3nids committed Nov 13, 2015
1 parent 7f556fd commit b2034f2
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 7 deletions.
31 changes: 28 additions & 3 deletions src/gui/editorwidgets/qgsvaluemapsearchwidgetwrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include <QSizePolicy>

QgsValueMapSearchWidgetWrapper::QgsValueMapSearchWidgetWrapper( QgsVectorLayer* vl, int fieldIdx, QWidget* parent )
: QgsDefaultSearchWidgetWrapper( vl, fieldIdx, parent ),
: QgsSearchWidgetWrapper( vl, fieldIdx, parent ),
mComboBox( NULL )
{
}
Expand All @@ -33,17 +33,30 @@ QWidget* QgsValueMapSearchWidgetWrapper::createWidget( QWidget* parent )
return new QComboBox( parent );
}

void QgsValueMapSearchWidgetWrapper::comboBoxIndexChanged( int )
void QgsValueMapSearchWidgetWrapper::comboBoxIndexChanged( int idx )
{
if ( mComboBox )
setExpression( mComboBox->itemData( mComboBox->currentIndex() ).toString() );
{
setExpression( mComboBox->itemData( idx ).toString() );
emit expressionChanged( mExpression );
}
}

bool QgsValueMapSearchWidgetWrapper::applyDirectly()
{
return true;
}

QString QgsValueMapSearchWidgetWrapper::expression()
{
return mExpression;
}

bool QgsValueMapSearchWidgetWrapper::valid()
{
return true;
}

void QgsValueMapSearchWidgetWrapper::initWidget( QWidget* editor )
{
mComboBox = qobject_cast<QComboBox*>( editor );
Expand All @@ -63,3 +76,15 @@ void QgsValueMapSearchWidgetWrapper::initWidget( QWidget* editor )
}
}

void QgsValueMapSearchWidgetWrapper::setExpression( QString exp )
{
QString fieldName = layer()->fields().at( mFieldIdx ).name();
QString str;

str = QString( "%1 = '%2'" )
.arg( QgsExpression::quotedColumnRef( fieldName ),
exp.replace( '\'', "''" ) );

mExpression = str;
}

17 changes: 13 additions & 4 deletions src/gui/editorwidgets/qgsvaluemapsearchwidgetwrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,33 @@
#ifndef QGSVALUEMAPSEARCHWIDGETWRAPPER_H
#define QGSVALUEMAPSEARCHWIDGETWRAPPER_H

#include "qgsdefaultsearchwidgetwrapper.h"
#include "qgssearchwidgetwrapper.h"
#include <QComboBox>

/**
* Wraps a value map search widget. This widget will offer a combobox with values from another layer
* referenced by a foreign key (a constraint may be set but is not required on data level).
* It will be used as a search widget and produces expression to look for in the layer.
*/


class GUI_EXPORT QgsValueMapSearchWidgetWrapper : public QgsDefaultSearchWidgetWrapper
class GUI_EXPORT QgsValueMapSearchWidgetWrapper : public QgsSearchWidgetWrapper
{
Q_OBJECT
public:
explicit QgsValueMapSearchWidgetWrapper( QgsVectorLayer* vl, int fieldIdx, QWidget* parent = 0 );
bool applyDirectly() override;
QString expression() override;
bool valid() override;

protected:
QWidget* createWidget( QWidget* parent ) override;
void initWidget( QWidget* editor ) override;

protected slots:
void setExpression( QString exp ) override;

private slots:
void comboBoxIndexChanged( int );
void comboBoxIndexChanged( int idx );

private:
QComboBox * mComboBox;
Expand Down

0 comments on commit b2034f2

Please sign in to comment.