Skip to content
Permalink
Browse files

QgsValueMapSearchW inherits QgsSearchW

and not QgsDefaultSearchW anymore
fixes expression creation
  • Loading branch information
3nids committed Nov 13, 2015
1 parent ebb5f0d commit 8da8700e32bec9f8a21fa27490af2ace0b002612
@@ -23,7 +23,7 @@
#include <QSizePolicy>

QgsValueMapSearchWidgetWrapper::QgsValueMapSearchWidgetWrapper( QgsVectorLayer* vl, int fieldIdx, QWidget* parent )
: QgsDefaultSearchWidgetWrapper( vl, fieldIdx, parent ),
: QgsSearchWidgetWrapper( vl, fieldIdx, parent ),
mComboBox( NULL )
{
}
@@ -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 );
@@ -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;
}

@@ -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;

0 comments on commit 8da8700

Please sign in to comment.
You can’t perform that action at this time.