Skip to content
Permalink
Browse files

[dualview] Default preview text shows also up for NULL values

  • Loading branch information
m-kuhn committed Sep 2, 2013
1 parent a6b52b7 commit a10598733e94c7fa63d4fd21e65804adbfa7d920
Showing with 19 additions and 7 deletions.
  1. +19 −7 src/gui/attributetable/qgsdualview.cpp
@@ -80,13 +80,19 @@ void QgsDualView::columnBoxInit()
// load fields
QList<QgsField> fields = mLayerCache->layer()->pendingFields().toList();

QString defaultField;

// default expression: saved value
QString displayExpression = mLayerCache->layer()->displayExpression();

// if no display expression is saved: use display field instead
if ( displayExpression == "" )
{
displayExpression = mLayerCache->layer()->displayField();
if ( mLayerCache->layer()->displayField() != "" )
{
defaultField = mLayerCache->layer()->displayField();
displayExpression = QString( "COALESCE(\"%1\", '<NULL>')" ).arg( defaultField );
}
}

// if neither diaplay expression nor display field is saved...
@@ -96,31 +102,37 @@ void QgsDualView::columnBoxInit()

if ( pkAttrs.size() > 0 )
{
if ( pkAttrs.size() == 1 )
defaultField = pkAttrs.at( 0 );

// ... If there are primary key(s) defined
QStringList pkFields;

foreach ( int attr, pkAttrs )
Q_FOREACH( int attr, pkAttrs )
{
pkFields.append( "\"" + fields[attr].name() + "\"" );
pkFields.append( "COALESCE(\"" + fields[attr].name() + "\", '<NULL>')" );
}

displayExpression = pkFields.join( "||', '||" );
}
else if ( fields.size() > 0 )
{
if ( fields.size() == 1 )
defaultField = fields.at( 0 ).name();

// ... concat all fields
QStringList fieldNames;
foreach ( QgsField field, fields )
{
fieldNames.append( "\"" + field.name() + "\"" );
fieldNames.append( "COALESCE(\"" + field.name() + "\", '<NULL>')" );
}

displayExpression = fieldNames.join( "||', '||" );
}
else
{
// ... there isn't really much to display
displayExpression = "[Please define preview text]";
displayExpression = "'[Please define preview text]'";
}
}

@@ -151,7 +163,7 @@ void QgsDualView::columnBoxInit()
connect( previewAction, SIGNAL( triggered() ), mPreviewActionMapper, SLOT( map() ) );
mPreviewColumnsMenu->addAction( previewAction );

if ( text == displayExpression )
if ( text == defaultField )
{
mFeatureListPreviewButton->setDefaultAction( previewAction );
}
@@ -315,7 +327,7 @@ void QgsDualView::previewColumnChanged( QObject* action )

if ( previewAction )
{
if ( !mFeatureList->setDisplayExpression( previewAction->text() ) )
if ( !mFeatureList->setDisplayExpression( QString( "COALESCE( \"%1\", '<NULL>' )" ).arg( previewAction->text() ) ) )
{
QMessageBox::warning( this
, tr( "Could not set preview column" )

0 comments on commit a105987

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