Skip to content

Commit

Permalink
Better QgsFilterLineEdit support for several edit widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Sep 22, 2014
1 parent b1474c8 commit c23b167
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 6 deletions.
23 changes: 21 additions & 2 deletions src/gui/editorwidgets/qgsfilenamewidgetwrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "qgsfilterlineedit.h"

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

QgsFileNameWidgetWrapper::QgsFileNameWidgetWrapper( QgsVectorLayer* vl, int fieldIdx, QWidget* editor, QWidget* parent )
Expand All @@ -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();
Expand Down Expand Up @@ -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() );
Expand Down
7 changes: 7 additions & 0 deletions src/gui/editorwidgets/qgsphotowidgetwrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) ) );
}
Expand Down
24 changes: 20 additions & 4 deletions src/gui/editorwidgets/qgsuniquevaluewidgetwrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand All @@ -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 );
}
Expand All @@ -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 )
{
Expand All @@ -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 );
Expand All @@ -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() );
}
}
7 changes: 7 additions & 0 deletions src/gui/editorwidgets/qgswebviewwidgetwrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c23b167

Please sign in to comment.