Skip to content
Permalink
Browse files

Revert changes related to v1 labeling. Only going to support v2 label…

…s for now. Only return needed attributes for labeling to select (like before). Add handlers for Ok and Cancel in expression dialog box (only temp)
  • Loading branch information
NathanW2 committed Jun 13, 2011
1 parent 2b5fb21 commit 027efca0a12073c93fbeaf975071ad5e85fb8434
Showing with 40 additions and 29 deletions.
  1. +3 −1 src/app/qgslabelinggui.cpp
  2. +15 −2 src/core/qgspallabeling.cpp
  3. +10 −17 src/core/qgssearchtreenode.cpp
  4. +12 −9 src/core/qgsvectorlayer.cpp
@@ -468,8 +468,10 @@ void QgsLabelingGui::showExpressionDialog()
dlg->setLayout(layout);
layout->addWidget(builder);
layout->addWidget(buttonBox);
connect(buttonBox,SIGNAL( accepted() ),dlg,SLOT( accept() ) );
connect(buttonBox,SIGNAL( rejected() ),dlg,SLOT( reject() ) );

if ( dlg->exec() )
if ( dlg->exec() == QDialog::Accepted )
{
QString expression = builder->getExpressionString();
//Do validation here first before applying
@@ -713,6 +713,7 @@ bool QgsPalLabeling::willUseLayer( QgsVectorLayer* layer )

int QgsPalLabeling::prepareLayer( QgsVectorLayer* layer, QSet<int>& attrIndices, QgsRenderContext& ctx )
{
QgsDebugMsg("PREPARE LAYER");
Q_ASSERT( mMapRenderer != NULL );

// start with a temporary settings class, find out labeling info
@@ -722,10 +723,22 @@ int QgsPalLabeling::prepareLayer( QgsVectorLayer* layer, QSet<int>& attrIndices,
if ( !lyrTmp.enabled )
return 0;

// If we aren't an expression, we check to see if we can find the column.

int fldIndex ;
if (!lyrTmp.isExpression)
if(lyrTmp.isExpression)
{
QgsSearchString searchString;
searchString.setString( lyrTmp.fieldName );
searchString.tree()->referencedColumns();
foreach(QString name, searchString.tree()->referencedColumns() )
{
fldIndex = layer->fieldNameIndex( name );
attrIndices.insert(fldIndex);
}
}
else
{
// If we aren't an expression, we check to see if we can find the column.
fldIndex = layer->fieldNameIndex( lyrTmp.fieldName );
if ( fldIndex == -1)
return 0;
@@ -586,58 +586,51 @@ QgsSearchTreeValue QgsSearchTreeNode::valueAgainst( const QgsFieldMap& fields,

QgsSearchTreeValue QgsSearchTreeNode::valueAgainst( const QgsFieldMap& fields, QgsFeature &f )
{
QgsDebugMsg( "VALUE AGAINST: " + makeSearchString());
QgsDebugMsgLevel( "valueAgainst: " + makeSearchString(), 2 );

switch ( mType )
{
case tNumber:
QgsDebugMsg( "number: " + QString::number( mNumber ));
QgsDebugMsgLevel( "number: " + QString::number( mNumber ), 2 );
return QgsSearchTreeValue( mNumber );

case tString:
QgsDebugMsg( "text: " + EVAL_STR( mText ) );
QgsDebugMsgLevel( "text: " + EVAL_STR( mText ), 2 );
return QgsSearchTreeValue( mText );

case tColumnRef:
{
QgsDebugMsg( "column (" + mText.toLower() + "): " );
QgsDebugMsgLevel( "column (" + mText.toLower() + "): ", 2 );
// find field index for the column
QgsFieldMap::const_iterator it;
for ( it = fields.begin(); it != fields.end(); it++ )
{
QgsDebugMsg(it->name());
if ( QString::compare( it->name(), mText, Qt::CaseInsensitive ) == 0 )
break;
if ( QString::compare( it->name(), mText, Qt::CaseInsensitive ) == 0 )
break;
}

if ( it == fields.end() )
{
// report missing column if not found
QgsDebugMsg( "ERROR!" );
QgsDebugMsgLevel( "ERROR!", 2 );
return QgsSearchTreeValue( 1, mText );
}

// get the value
QVariant val = f.attributeMap()[it.key()];
QgsAttributeMap::const_iterator its;
for ( its = f.attributeMap().begin(); its != f.attributeMap().end(); its++ )
{
QgsDebugMsg(its->toString());
}

if ( val.isNull() )
{
QgsDebugMsg( " NULL" );
QgsDebugMsgLevel( " NULL", 2 );
return QgsSearchTreeValue();
}
else if ( val.type() == QVariant::Bool || val.type() == QVariant::Int || val.type() == QVariant::Double )
{
QgsDebugMsg( " number: " + QString::number( val.toDouble() ) );
QgsDebugMsgLevel( " number: " + QString::number( val.toDouble() ), 2 );
return QgsSearchTreeValue( val.toDouble() );
}
else
{
QgsDebugMsg( " text: " + EVAL_STR( val.toString() ) );
QgsDebugMsgLevel( " text: " + EVAL_STR( val.toString() ), 2 );
return QgsSearchTreeValue( val.toString() );
}

@@ -334,19 +334,22 @@ void QgsVectorLayer::drawLabels( QgsRenderContext& rendererContext )
QgsAttributeList attributes;
if ( mRenderer )
{
//attributes = mRenderer->classificationAttributes();
attributes = mRenderer->classificationAttributes();
}
else if ( mRendererV2 )
{
// foreach( QString attrName, mRendererV2->usedAttributes() )
// {
// int attrNum = fieldNameIndex( attrName );
// attributes.append( attrNum );
// }
foreach( QString attrName, mRendererV2->usedAttributes() )
{
int attrNum = fieldNameIndex( attrName );
attributes.append( attrNum );
}
// make sure the renderer is ready for classification ("symbolForFeature")
mRendererV2->startRender( rendererContext, this );
}

// Add fields required for labels
mLabel->addRequiredFields( attributes );

QgsDebugMsg( "Selecting features based on view extent" );

int featureCount = 0;
@@ -355,7 +358,7 @@ void QgsVectorLayer::drawLabels( QgsRenderContext& rendererContext )
{
// select the records in the extent. The provider sets a spatial filter
// and sets up the selection set for retrieval
select( pendingAllAttributesList(), rendererContext.extent() );
select( attributes, rendererContext.extent() );

QgsFeature fet;
while ( nextFeature( fet ) )
@@ -975,7 +978,7 @@ bool QgsVectorLayer::draw( QgsRenderContext& rendererContext )
//register label and diagram layer to the labeling engine
prepareLabelingAndDiagrams( rendererContext, attributes, labeling );

select( pendingAllAttributesList(), rendererContext.extent() );
select( attributes, rendererContext.extent() );

if ( mRendererV2->usingSymbolLevels() )
drawRendererV2Levels( rendererContext, labeling );
@@ -1022,7 +1025,7 @@ bool QgsVectorLayer::draw( QgsRenderContext& rendererContext )
bool labeling = false;
prepareLabelingAndDiagrams( rendererContext, attributes, labeling );

select( pendingAllAttributesList(), rendererContext.extent() );
select( attributes, rendererContext.extent() );

try
{

0 comments on commit 027efca

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