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 ebb5f0d commit 8da8700
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
Expand Up @@ -23,7 +23,7 @@
#include <QSizePolicy> #include <QSizePolicy>


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


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


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


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

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

void QgsValueMapSearchWidgetWrapper::initWidget( QWidget* editor ) void QgsValueMapSearchWidgetWrapper::initWidget( QWidget* editor )
{ {
mComboBox = qobject_cast<QComboBox*>( 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
Expand Up @@ -16,24 +16,33 @@
#ifndef QGSVALUEMAPSEARCHWIDGETWRAPPER_H #ifndef QGSVALUEMAPSEARCHWIDGETWRAPPER_H
#define QGSVALUEMAPSEARCHWIDGETWRAPPER_H #define QGSVALUEMAPSEARCHWIDGETWRAPPER_H


#include "qgsdefaultsearchwidgetwrapper.h" #include "qgssearchwidgetwrapper.h"
#include <QComboBox> #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 QgsSearchWidgetWrapper
class GUI_EXPORT QgsValueMapSearchWidgetWrapper : public QgsDefaultSearchWidgetWrapper
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit QgsValueMapSearchWidgetWrapper( QgsVectorLayer* vl, int fieldIdx, QWidget* parent = 0 ); explicit QgsValueMapSearchWidgetWrapper( QgsVectorLayer* vl, int fieldIdx, QWidget* parent = 0 );
bool applyDirectly() override; bool applyDirectly() override;
QString expression() override;
bool valid() override;


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


protected slots:
void setExpression( QString exp ) override;

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


private: private:
QComboBox * mComboBox; QComboBox * mComboBox;
Expand Down

0 comments on commit 8da8700

Please sign in to comment.