Skip to content
Permalink
Browse files
[FEATURE] feature form updates:
- make NULL value string representation configurable
- fix feature updates in feature form from attribute table
- add support for NULL values in value maps (comboboxes)
- use layer names instead of ids in drop down list when loading value
  maps from layers.
- support feature form expression fields: line edits on the form
  which name prefix "expr_" are evaluated.  Their value is interpreted
  as field calculator string and replaced with the calculated value.
- support search for NULL in attribute table

git-svn-id: http://svn.osgeo.org/qgis/trunk@15054 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Jan 17, 2011
1 parent 44187c0 commit b6a878e1de8afb77034926d4852b0daad3dacef4
@@ -647,11 +647,25 @@ void QgsAttributeTableDialog::search()
sensString = "LIKE";
}

QString str = QString( "%1 %2 '%3'" )
.arg( QgsSearchTreeNode::quotedColumnRef( fieldName ) )
.arg( numeric ? "=" : sensString )
.arg( numeric ? mQuery->displayText().replace( "'", "''" ) :
"%" + mQuery->displayText().replace( "'", "''" ) + "%" ); // escape quotes
QSettings settings;
QString nullValue = settings.value( "qgis/nullValue", "NULL" ).toString();

QString str;
if ( mQuery->displayText() == nullValue )
{
str = QString( "%1 IS NULL" ).arg( QgsSearchTreeNode::quotedColumnRef( fieldName ) );
}
else
{
str = QString( "%1 %2 '%3'" )
.arg( QgsSearchTreeNode::quotedColumnRef( fieldName ) )
.arg( numeric ? "=" : sensString )
.arg( numeric
? mQuery->displayText().replace( "'", "''" )
:
"%" + mQuery->displayText().replace( "'", "''" ) + "%" ); // escape quotes
}

doSearch( str );
}

@@ -414,7 +414,8 @@ QVariant QgsAttributeTableModel::data( const QModelIndex &index, int role ) cons
}
else
{
return QVariant( "NULL" );
QSettings settings;
return settings.value( "qgis/nullValue", "NULL" );
}
}

@@ -497,6 +498,7 @@ void QgsAttributeTableModel::featureForm( QModelIndex &idx )
QgsFeature f;
QgsAttributeMap attributes;

f.setFeatureId( rowToId( idx.row() ) );
for ( int i = 0; i < mAttributes.size(); i++ )
{
f.changeAttribute( i, data( index( idx.row(), i ), Qt::EditRole ) );
@@ -25,6 +25,8 @@
#include "qgssymbol.h"
#include "qgsattributeeditor.h"
#include "qgsrubberband.h"
#include "qgssearchstring.h"
#include "qgssearchtreenode.h"

#include "qgisapp.h"

@@ -193,6 +195,48 @@ QgsAttributeDialog::QgsAttributeDialog( QgsVectorLayer *vl, QgsFeature *thepFeat
mpIndizes << it.key();
mpWidgets << myWidget;
}

foreach( QLineEdit *le, mDialog->findChildren<QLineEdit*>() )
{
if ( !le->objectName().startsWith( "expr_" ) )
continue;

le->setReadOnly( true );
QString expr = le->text();
le->setText( tr( "Error" ) );

QgsSearchString ss;
if ( !ss.setString( expr ) )
continue;

QgsSearchTreeNode *st = ss.tree();
if ( !st )
continue;

if ( !mFeature->geometry() && st->needsGeometry() )
{
QgsFeature f;
if ( vl->featureAtId( mFeature->id(), f, true, false ) && f.geometry() )
{
mFeature->setGeometry( *f.geometry() );
}
}

QgsSearchTreeValue value;
st->getValue( value, st, vl->pendingFields(), *mFeature );

if ( !value.isError() )
{
if ( value.isNumeric() )
le->setText( QString::number( value.number() ) );
else
le->setText( value.string() );
}
else
{
le->setText( tr( "Error: %1" ).arg( st->errorMsg() ) );
}
}
}

if ( mDialog )
@@ -74,7 +74,7 @@ void QgsAttributeTypeLoadDialog::fillLayerList()
QMap<QString, QgsMapLayer*>::iterator layer_it = QgsMapLayerRegistry::instance()->mapLayers().begin();
for ( ; layer_it != QgsMapLayerRegistry::instance()->mapLayers().end(); layer_it++ )
{
layerComboBox->addItem( layer_it.key() );
layerComboBox->addItem( layer_it.value()->name(), layer_it.key() );
}
}

@@ -89,7 +89,7 @@ void QgsAttributeTypeLoadDialog::fillComboBoxes( int layerIndex )
return;
}

QgsMapLayer* dataLayer = QgsMapLayerRegistry::instance()->mapLayer( layerComboBox->currentText() );
QgsMapLayer* dataLayer = QgsMapLayerRegistry::instance()->mapLayer( layerComboBox->itemData( layerComboBox->currentIndex() ).toString() );
QgsVectorLayer* vLayer = qobject_cast<QgsVectorLayer *>( dataLayer );
if ( vLayer == NULL )
{
@@ -120,7 +120,7 @@ void QgsAttributeTypeLoadDialog::createPreview( int fieldIndex, bool full )
}
int idx = keyComboBox->itemData( keyComboBox->currentIndex() ).toInt();
int idx2 = valueComboBox->itemData( valueComboBox->currentIndex() ).toInt();
QgsMapLayer* dataLayer = QgsMapLayerRegistry::instance()->mapLayer( layerComboBox->currentText() );
QgsMapLayer* dataLayer = QgsMapLayerRegistry::instance()->mapLayer( layerComboBox->itemData( layerComboBox->currentIndex() ).toString() );
QgsVectorLayer* vLayer = qobject_cast<QgsVectorLayer *>( dataLayer );
if ( vLayer == NULL )
{
@@ -170,7 +170,7 @@ void QgsAttributeTypeLoadDialog::loadDataToValueMap()
mValueMap.clear();
int idx = keyComboBox->itemData( keyComboBox->currentIndex() ).toInt();
int idx2 = valueComboBox->itemData( valueComboBox->currentIndex() ).toInt();
QgsMapLayer* dataLayer = QgsMapLayerRegistry::instance()->mapLayer( layerComboBox->currentText() );
QgsMapLayer* dataLayer = QgsMapLayerRegistry::instance()->mapLayer( layerComboBox->itemData( layerComboBox->currentIndex() ).toString() );
QgsVectorLayer* vLayer = qobject_cast<QgsVectorLayer *>( dataLayer );
if ( vLayer == NULL )
{
@@ -23,6 +23,7 @@
#include <QString>
#include <QStringList>
#include <QClipboard>
#include <QSettings>

#include "qgsclipboard.h"
#include "qgsfeature.h"
@@ -75,7 +76,10 @@ void QgsClipboard::replaceWithCopyOf( const QgsFieldMap& fields, QgsFeatureList&
if ( it->geometry() )
textFields += it->geometry()->exportToWkt();
else
textFields += "NULL";
{
QSettings settings;
textFields += settings.value( "qgis/nullValue", "NULL" ).toString();
}

// QgsDebugMsg("about to traverse fields.");
//
@@ -253,6 +253,7 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :
cbxAddPostgisDC->setChecked( settings.value( "/qgis/addPostgisDC", false ).toBool() );
cbxAddNewLayersToCurrentGroup->setChecked( settings.value( "/qgis/addNewLayersToCurrentGroup", false ).toBool() );
cbxCreateRasterLegendIcons->setChecked( settings.value( "/qgis/createRasterLegendIcons", true ).toBool() );
leNullValue->setText( settings.value( "qgis/nullValue", "NULL" ).toString() );

//set the color for selections
int myRed = settings.value( "/qgis/default_selection_color_red", 255 ).toInt();
@@ -524,6 +525,7 @@ void QgsOptions::saveOptions()
settings.setValue( "qgis/capitaliseLayerName", capitaliseCheckBox->isChecked() );
settings.setValue( "qgis/askToSaveProjectChanges", chbAskToSaveProjectChanges->isChecked() );
settings.setValue( "qgis/warnOldProjectVersion", chbWarnOldProjectVersion->isChecked() );
settings.setValue( "qgis/nullValue", leNullValue->text() );

//overlay placement method
int overlayIndex = mOverlayAlgorithmComboBox->currentIndex();
@@ -37,6 +37,7 @@
#include <QDial>
#include <QCalendarWidget>
#include <QDialogButtonBox>
#include <QSettings>

void QgsAttributeEditor::selectFileName( void )
{
@@ -451,12 +452,15 @@ bool QgsAttributeEditor::retrieveValue( QWidget *widget, QgsVectorLayer *vl, int
bool modified = false;
QString text;

QSettings settings;
QString nullValue = settings.value( "qgis/nullValue", "NULL" ).toString();

QLineEdit *le = qobject_cast<QLineEdit *>( widget );
if ( le )
{
text = le->text();
modified = le->isModified();
if ( text == "NULL" )
if ( text == nullValue )
{
text = QString::null;
}
@@ -467,7 +471,7 @@ bool QgsAttributeEditor::retrieveValue( QWidget *widget, QgsVectorLayer *vl, int
{
text = te->toHtml();
modified = te->document()->isModified();
if ( text == "NULL" )
if ( text == nullValue )
{
text = QString::null;
}
@@ -478,7 +482,7 @@ bool QgsAttributeEditor::retrieveValue( QWidget *widget, QgsVectorLayer *vl, int
{
text = pte->toPlainText();
modified = pte->document()->isModified();
if ( text == "NULL" )
if ( text == nullValue )
{
text = QString::null;
}
@@ -492,11 +496,16 @@ bool QgsAttributeEditor::retrieveValue( QWidget *widget, QgsVectorLayer *vl, int
editType == QgsVectorLayer::Classification )
{
text = cb->itemData( cb->currentIndex() ).toString();
if ( text == nullValue )
{
text = QString::null;
}
}
else
{
text = cb->currentText();
}
modified = true;
}

QSpinBox *sb = qobject_cast<QSpinBox *>( widget );
@@ -614,18 +623,27 @@ bool QgsAttributeEditor::setValue( QWidget *editor, QgsVectorLayer *vl, int idx,
const QgsField &field = vl->pendingFields()[idx];
QVariant::Type myFieldType = field.type();

QSettings settings;
QString nullValue = settings.value( "qgis/nullValue", "NULL" ).toString();

switch ( editType )
{
case QgsVectorLayer::Classification:
case QgsVectorLayer::UniqueValues:
case QgsVectorLayer::Enumeration:
case QgsVectorLayer::ValueMap:
{
QVariant v = value;
QComboBox *cb = qobject_cast<QComboBox *>( editor );
if ( cb == NULL )
return false;

int idx = cb->findData( value );
if ( v.isNull() )
{
v = nullValue;
}

int idx = cb->findData( v );
if ( idx < 0 )
return false;

@@ -693,7 +711,7 @@ bool QgsAttributeEditor::setValue( QWidget *editor, QgsVectorLayer *vl, int idx,
if ( myFieldType == QVariant::Int || myFieldType == QVariant::Double || myFieldType == QVariant::LongLong )
text = "";
else
text = "NULL";
text = nullValue;
else
text = value.toString();

@@ -31,7 +31,7 @@ class GUI_EXPORT QgsAttributeEditor : public QObject
Q_OBJECT

public:
QgsAttributeEditor( QObject *parent ) : QObject( parent ) {}
QgsAttributeEditor( QObject *parent ) : QObject( parent ) {};
static QWidget *createAttributeEditor( QWidget *parent, QWidget *editor, QgsVectorLayer *vl, int idx, const QVariant &value );
static bool retrieveValue( QWidget *widget, QgsVectorLayer *vl, int idx, QVariant &value );
static bool setValue( QWidget *widget, QgsVectorLayer *vl, int idx, const QVariant &value );

0 comments on commit b6a878e

Please sign in to comment.