Skip to content
Permalink
Browse files

Better QgsFilterLineEdit support for several edit widgets

  • Loading branch information
m-kuhn committed Sep 22, 2014
1 parent b1474c8 commit c23b1678d721f1bb76f35fe9532e9a474c3eb28a
@@ -18,6 +18,7 @@
#include "qgsfilterlineedit.h"

#include <QFileDialog>
#include <QSettings>
#include <QGridLayout>

QgsFileNameWidgetWrapper::QgsFileNameWidgetWrapper( QgsVectorLayer* vl, int fieldIdx, QWidget* editor, QWidget* parent )
@@ -30,7 +31,12 @@ QVariant QgsFileNameWidgetWrapper::value()
QVariant value;

if ( mLineEdit )
value = mLineEdit->text();
{
if ( mLineEdit->text() == QSettings().value( "qgis/nullValue", "NULL" ).toString() )
value = QVariant( field().type() );
else
value = mLineEdit->text();
}

if ( mLabel )
value = mLabel->text();
@@ -73,13 +79,26 @@ void QgsFileNameWidgetWrapper::initWidget( QWidget* editor )
mLabel = qobject_cast<QLabel*>( editor );

if ( mLineEdit )
{
QgsFilterLineEdit* fle = qobject_cast<QgsFilterLineEdit*>( editor );
if ( fle )
{
fle->setNullValue( QSettings().value( "qgis/nullValue", "NULL" ).toString() );
}

connect( mLineEdit, SIGNAL( textChanged( QString ) ), this, SLOT( valueChanged( QString ) ) );
}
}

void QgsFileNameWidgetWrapper::setValue( const QVariant& value )
{
if ( mLineEdit )
mLineEdit->setText( value.toString() );
{
if ( value.isNull() )
mLineEdit->setText( QSettings().value( "qgis/nullValue", "NULL" ).toString() );
else
mLineEdit->setText( value.toString() );
}

if ( mLabel )
mLabel->setText( value.toString() );
@@ -120,6 +120,13 @@ void QgsPhotoWidgetWrapper::initWidget( QWidget* editor )

if ( mLineEdit )
{

QgsFilterLineEdit *fle = qobject_cast<QgsFilterLineEdit*>( mLineEdit );
if ( fle )
{
fle->setNullValue( QSettings().value( "qgis/nullValue", "NULL" ).toString() );
}

connect( mLineEdit, SIGNAL( textChanged( QString ) ), this, SLOT( valueChanged( QString ) ) );
connect( mLineEdit, SIGNAL( textChanged( QString ) ), this, SLOT( loadPixmap( QString ) ) );
}
@@ -16,8 +16,10 @@
#include "qgsuniquevaluewidgetwrapper.h"

#include "qgsvectorlayer.h"
#include "qgsfilterlineedit.h"

#include <QCompleter>
#include <QSettings>

QgsUniqueValuesWidgetWrapper::QgsUniqueValuesWidgetWrapper( QgsVectorLayer* vl, int fieldIdx, QWidget* editor, QWidget* parent )
: QgsEditorWidgetWrapper( vl, fieldIdx, editor, parent )
@@ -32,15 +34,20 @@ QVariant QgsUniqueValuesWidgetWrapper::value()
value = mComboBox->itemData( mComboBox->currentIndex() );

if ( mLineEdit )
value = mLineEdit->text();
{
if ( mLineEdit->text() == QSettings().value( "qgis/nullValue", "NULL" ).toString() )
value = QVariant( field().type() );
else
value = mLineEdit->text();
}

return value;
}

QWidget* QgsUniqueValuesWidgetWrapper::createWidget( QWidget* parent )
{
if ( config( "Editable" ).toBool() )
return new QLineEdit( parent );
return new QgsFilterLineEdit( parent );
else
return new QComboBox( parent );
}
@@ -56,7 +63,7 @@ void QgsUniqueValuesWidgetWrapper::initWidget( QWidget* editor )

layer()->uniqueValues( fieldIdx(), values );

Q_FOREACH ( QVariant v, values )
Q_FOREACH( QVariant v, values )
{
if ( mComboBox )
{
@@ -71,6 +78,12 @@ void QgsUniqueValuesWidgetWrapper::initWidget( QWidget* editor )

if ( mLineEdit )
{
QgsFilterLineEdit* fle = qobject_cast<QgsFilterLineEdit*>( editor );
if ( fle && !( field().type() == QVariant::Int || field().type() == QVariant::Double || field().type() == QVariant::LongLong || field().type() == QVariant::Date ) )
{
fle->setNullValue( QSettings().value( "qgis/nullValue", "NULL" ).toString() );
}

QCompleter* c = new QCompleter( sValues );
c->setCompletionMode( QCompleter::PopupCompletion );
mLineEdit->setCompleter( c );
@@ -93,6 +106,9 @@ void QgsUniqueValuesWidgetWrapper::setValue( const QVariant& value )

if ( mLineEdit )
{
mLineEdit->setText( value.toString() );
if ( value.isNull() )
mLineEdit->setText( QSettings().value( "qgis/nullValue", "NULL" ).toString() );
else
mLineEdit->setText( value.toString() );
}
}
@@ -75,6 +75,13 @@ void QgsWebViewWidgetWrapper::initWidget( QWidget* editor )

if ( mLineEdit )
{

QgsFilterLineEdit* fle = qobject_cast<QgsFilterLineEdit*>( mLineEdit );
if ( fle )
{
fle->setNullValue( QSettings().value( "qgis/nullValue", "NULL" ).toString() );
}

container = qobject_cast<QWidget*>( mLineEdit->parent() );
}
else

0 comments on commit c23b167

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