Skip to content

Commit 027efca

Browse files
committed
Revert changes related to v1 labeling. Only going to support v2 labels for now. Only return needed attributes for labeling to select (like before). Add handlers for Ok and Cancel in expression dialog box (only temp)
1 parent 2b5fb21 commit 027efca

4 files changed

Lines changed: 40 additions & 29 deletions

File tree

‎src/app/qgslabelinggui.cpp‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,8 +468,10 @@ void QgsLabelingGui::showExpressionDialog()
468468
dlg->setLayout(layout);
469469
layout->addWidget(builder);
470470
layout->addWidget(buttonBox);
471+
connect(buttonBox,SIGNAL( accepted() ),dlg,SLOT( accept() ) );
472+
connect(buttonBox,SIGNAL( rejected() ),dlg,SLOT( reject() ) );
471473

472-
if ( dlg->exec() )
474+
if ( dlg->exec() == QDialog::Accepted )
473475
{
474476
QString expression = builder->getExpressionString();
475477
//Do validation here first before applying

‎src/core/qgspallabeling.cpp‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,7 @@ bool QgsPalLabeling::willUseLayer( QgsVectorLayer* layer )
713713

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

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

725-
// If we aren't an expression, we check to see if we can find the column.
726+
726727
int fldIndex ;
727-
if (!lyrTmp.isExpression)
728+
if(lyrTmp.isExpression)
729+
{
730+
QgsSearchString searchString;
731+
searchString.setString( lyrTmp.fieldName );
732+
searchString.tree()->referencedColumns();
733+
foreach(QString name, searchString.tree()->referencedColumns() )
734+
{
735+
fldIndex = layer->fieldNameIndex( name );
736+
attrIndices.insert(fldIndex);
737+
}
738+
}
739+
else
728740
{
741+
// If we aren't an expression, we check to see if we can find the column.
729742
fldIndex = layer->fieldNameIndex( lyrTmp.fieldName );
730743
if ( fldIndex == -1)
731744
return 0;

‎src/core/qgssearchtreenode.cpp‎

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -586,58 +586,51 @@ QgsSearchTreeValue QgsSearchTreeNode::valueAgainst( const QgsFieldMap& fields,
586586

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

591591
switch ( mType )
592592
{
593593
case tNumber:
594-
QgsDebugMsg( "number: " + QString::number( mNumber ));
594+
QgsDebugMsgLevel( "number: " + QString::number( mNumber ), 2 );
595595
return QgsSearchTreeValue( mNumber );
596596

597597
case tString:
598-
QgsDebugMsg( "text: " + EVAL_STR( mText ) );
598+
QgsDebugMsgLevel( "text: " + EVAL_STR( mText ), 2 );
599599
return QgsSearchTreeValue( mText );
600600

601601
case tColumnRef:
602602
{
603-
QgsDebugMsg( "column (" + mText.toLower() + "): " );
603+
QgsDebugMsgLevel( "column (" + mText.toLower() + "): ", 2 );
604604
// find field index for the column
605605
QgsFieldMap::const_iterator it;
606606
for ( it = fields.begin(); it != fields.end(); it++ )
607607
{
608-
QgsDebugMsg(it->name());
609-
if ( QString::compare( it->name(), mText, Qt::CaseInsensitive ) == 0 )
610-
break;
608+
if ( QString::compare( it->name(), mText, Qt::CaseInsensitive ) == 0 )
609+
break;
611610
}
612611

613612
if ( it == fields.end() )
614613
{
615614
// report missing column if not found
616-
QgsDebugMsg( "ERROR!" );
615+
QgsDebugMsgLevel( "ERROR!", 2 );
617616
return QgsSearchTreeValue( 1, mText );
618617
}
619618

620619
// get the value
621620
QVariant val = f.attributeMap()[it.key()];
622-
QgsAttributeMap::const_iterator its;
623-
for ( its = f.attributeMap().begin(); its != f.attributeMap().end(); its++ )
624-
{
625-
QgsDebugMsg(its->toString());
626-
}
627-
628621
if ( val.isNull() )
629622
{
630-
QgsDebugMsg( " NULL" );
623+
QgsDebugMsgLevel( " NULL", 2 );
631624
return QgsSearchTreeValue();
632625
}
633626
else if ( val.type() == QVariant::Bool || val.type() == QVariant::Int || val.type() == QVariant::Double )
634627
{
635-
QgsDebugMsg( " number: " + QString::number( val.toDouble() ) );
628+
QgsDebugMsgLevel( " number: " + QString::number( val.toDouble() ), 2 );
636629
return QgsSearchTreeValue( val.toDouble() );
637630
}
638631
else
639632
{
640-
QgsDebugMsg( " text: " + EVAL_STR( val.toString() ) );
633+
QgsDebugMsgLevel( " text: " + EVAL_STR( val.toString() ), 2 );
641634
return QgsSearchTreeValue( val.toString() );
642635
}
643636

‎src/core/qgsvectorlayer.cpp‎

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -334,19 +334,22 @@ void QgsVectorLayer::drawLabels( QgsRenderContext& rendererContext )
334334
QgsAttributeList attributes;
335335
if ( mRenderer )
336336
{
337-
//attributes = mRenderer->classificationAttributes();
337+
attributes = mRenderer->classificationAttributes();
338338
}
339339
else if ( mRendererV2 )
340340
{
341-
// foreach( QString attrName, mRendererV2->usedAttributes() )
342-
// {
343-
// int attrNum = fieldNameIndex( attrName );
344-
// attributes.append( attrNum );
345-
// }
341+
foreach( QString attrName, mRendererV2->usedAttributes() )
342+
{
343+
int attrNum = fieldNameIndex( attrName );
344+
attributes.append( attrNum );
345+
}
346346
// make sure the renderer is ready for classification ("symbolForFeature")
347347
mRendererV2->startRender( rendererContext, this );
348348
}
349349

350+
// Add fields required for labels
351+
mLabel->addRequiredFields( attributes );
352+
350353
QgsDebugMsg( "Selecting features based on view extent" );
351354

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

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

978-
select( pendingAllAttributesList(), rendererContext.extent() );
981+
select( attributes, rendererContext.extent() );
979982

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

1025-
select( pendingAllAttributesList(), rendererContext.extent() );
1028+
select( attributes, rendererContext.extent() );
10261029

10271030
try
10281031
{

0 commit comments

Comments
 (0)