Skip to content

Commit

Permalink
Revert changes related to v1 labeling. Only going to support v2 label…
Browse files Browse the repository at this point in the history
…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 027efca
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 29 deletions.
4 changes: 3 additions & 1 deletion src/app/qgslabelinggui.cpp
Expand Up @@ -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
Expand Down
17 changes: 15 additions & 2 deletions src/core/qgspallabeling.cpp
Expand Up @@ -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
Expand All @@ -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;
Expand Down
27 changes: 10 additions & 17 deletions src/core/qgssearchtreenode.cpp
Expand Up @@ -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() );
}

Expand Down
21 changes: 12 additions & 9 deletions src/core/qgsvectorlayer.cpp
Expand Up @@ -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;
Expand All @@ -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 ) )
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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
{
Expand Down

0 comments on commit 027efca

Please sign in to comment.