Skip to content
Permalink
Browse files

Fix tests, fixes after rebase

  • Loading branch information
wonder-sk committed Apr 27, 2016
1 parent ad82ac0 commit 6f3032a622fa59795f53cad9abd33e6f9e65ea44
@@ -548,7 +548,7 @@ bool QgsMapToolLabel::dataDefinedShowHide( QgsVectorLayer* vlayer, QgsFeatureId
return false;
}

if ( mCurrentLabelPos.isDiagram )
if ( mCurrentLabel.pos.isDiagram )
{
if ( ! diagramCanShowHide( vlayer, showCol ) )
{
@@ -661,12 +661,10 @@ bool QgsMapToolLabel::isPinned()
return rc;
}

bool QgsMapToolLabel::diagramCanShowHide( QgsMapLayer* ml, int& showCol ) const
bool QgsMapToolLabel::diagramCanShowHide( QgsVectorLayer* vlayer, int& showCol ) const
{
bool rc = false;

QgsVectorLayer* vlayer = qobject_cast<QgsVectorLayer*>( ml );

if ( vlayer && vlayer->isEditable() && vlayer->diagramsEnabled() )
{
const QgsDiagramLayerSettings *dls = vlayer->diagramLayerSettings();
@@ -52,7 +52,7 @@ class APP_EXPORT QgsMapToolLabel: public QgsMapTool
/** Returns true if layer has attribute field set up for diagrams
@param showCol out: attribute column for data defined diagram showing
@note added in QGIS 2.16 */
bool diagramCanShowHide( QgsMapLayer* layer, int& showCol ) const;
bool diagramCanShowHide( QgsVectorLayer* vlayer, int& showCol ) const;
/** Returns true if layer has attribute field set up
@param showCol out: attribute column for data defined label showing*/
bool labelCanShowHide( QgsVectorLayer* vlayer, int& showCol ) const;
@@ -187,6 +187,8 @@ void QgsMapToolPinLabels::highlightPinnedLabels()
{
const QgsLabelPosition& pos = *it;

mCurrentLabel = LabelDetails( pos );

if ( isPinned() )
{
QString labelStringID = QString( "%0|%1|%2" ).arg( QString::number( pos.isDiagram ), pos.layerID, QString::number( pos.featureId ) );
@@ -445,6 +447,7 @@ bool QgsMapToolPinLabels::pinUnpinCurrentDiagram( bool pin )
return false;

// edit attribute table
QgsVectorLayer* vlayer = mCurrentLabel.layer;
int fid = mCurrentLabel.pos.featureId;

bool writeFailed = false;
@@ -130,24 +130,26 @@ void QgsMapToolShowHideLabels::showHideLabels( QMouseEvent * e )
QgsFeatureIds selectedFeatIds;
if ( !selectedFeatures( vlayer, selectedFeatIds ) )
{
vlayer->destroyEditCommand();
return;
}

QgsDebugMsg( "Number of selected labels or features: " + QString::number( selectedFeatIds.size() ) );

if ( selectedFeatIds.isEmpty() )
{
vlayer->destroyEditCommand();
return;
}

Q_FOREACH ( QgsFeatureId fid, selectedFeatIds )
{
mCurrentLabelPos.featureId = fid;
mCurrentLabel.pos.featureId = fid;

mCurrentLabelPos.isDiagram = false;
mCurrentLabel.pos.isDiagram = false;
bool labChanged = showHide( vlayer, true );

mCurrentLabelPos.isDiagram = true;
mCurrentLabel.pos.isDiagram = true;
bool diagChanged = showHide( vlayer, true );

if ( labChanged || diagChanged )
@@ -166,7 +168,7 @@ void QgsMapToolShowHideLabels::showHideLabels( QMouseEvent * e )
{
Q_FOREACH ( QgsLabelPosition pos, positions )
{
mCurrentLabelPos = pos;
mCurrentLabel.pos = pos;

if ( showHide( vlayer, false ) )
labelChanged = labelChanged || true;
@@ -280,7 +282,7 @@ bool QgsMapToolShowHideLabels::showHide( QgsVectorLayer *vl, const bool show )
int showCol;
int showVal;

if ( !dataDefinedShowHide( vl, mCurrentLabelPos.featureId, showVal,
if ( !dataDefinedShowHide( vl, mCurrentLabel.pos.featureId, showVal,
showSuccess, showCol ) )
{
return false;
@@ -300,7 +302,7 @@ bool QgsMapToolShowHideLabels::showHide( QgsVectorLayer *vl, const bool show )
}

// different attribute value, edit table
if ( ! vl->changeAttributeValue( mCurrentLabelPos.featureId, showCol, show ) )
if ( ! vl->changeAttributeValue( mCurrentLabel.pos.featureId, showCol, show ) )
{
QgsDebugMsg( "Failed write to attribute table" );
return false;
@@ -127,7 +127,7 @@ void TestQgsLabelingEngineV2::testBasic()

QgsLabelingEngineV2 engine;
engine.setMapSettings( mapSettings );
engine.addProvider( new QgsVectorLayerLabelProvider( vl ) );
engine.addProvider( new QgsVectorLayerLabelProvider( vl, QString() ) );
//engine.setFlags( QgsLabelingEngineV2::RenderOutlineLabels | QgsLabelingEngineV2::DrawLabelRectOnly );
engine.run( context );

@@ -302,7 +302,7 @@ void TestQgsLabelingEngineV2::zOrder()
pls1.setDataDefinedProperty( QgsPalLayerSettings::Color, true, true, "case when \"Class\"='Jet' then '#ff5500' when \"Class\"='B52' then '#00ffff' else '#ff00ff' end", QString() );
pls1.setDataDefinedProperty( QgsPalLayerSettings::Size, true, true, "case when \"Class\"='Jet' then 100 when \"Class\"='B52' then 30 else 50 end", QString() );

QgsVectorLayerLabelProvider* provider1 = new QgsVectorLayerLabelProvider( vl, true, &pls1 );
QgsVectorLayerLabelProvider* provider1 = new QgsVectorLayerLabelProvider( vl, QString(), true, &pls1 );
QgsLabelingEngineV2 engine;
engine.setMapSettings( mapSettings );
engine.addProvider( provider1 );
@@ -318,7 +318,7 @@ void TestQgsLabelingEngineV2::zOrder()

//test data defined z-index
pls1.setDataDefinedProperty( QgsPalLayerSettings::ZIndex, true, true, "case when \"Class\"='Jet' then 3 when \"Class\"='B52' then 1 else 2 end", QString() );
provider1 = new QgsVectorLayerLabelProvider( vl, true, &pls1 );
provider1 = new QgsVectorLayerLabelProvider( vl, QString(), true, &pls1 );
engine.addProvider( provider1 );
p.begin( &img );
engine.run( context );
@@ -332,7 +332,7 @@ void TestQgsLabelingEngineV2::zOrder()
pls1.removeAllDataDefinedProperties();
pls1.textColor = QColor( 255, 50, 100 );
pls1.textFont.setPointSizeF( 30 );
provider1 = new QgsVectorLayerLabelProvider( vl, true, &pls1 );
provider1 = new QgsVectorLayerLabelProvider( vl, QString(), true, &pls1 );
engine.addProvider( provider1 );

//add a second layer
@@ -343,7 +343,7 @@ void TestQgsLabelingEngineV2::zOrder()

QgsPalLayerSettings pls2( pls1 );
pls2.textColor = QColor( 0, 0, 0 );
QgsVectorLayerLabelProvider* provider2 = new QgsVectorLayerLabelProvider( vl2, true, &pls2 );
QgsVectorLayerLabelProvider* provider2 = new QgsVectorLayerLabelProvider( vl2, QString(), true, &pls2 );
engine.addProvider( provider2 );

mapSettings.setLayers( QStringList() << vl->id() << vl2->id() );
@@ -371,7 +371,7 @@ void TestQgsLabelingEngineV2::zOrder()
//try mixing layer order and z-index
engine.removeProvider( provider1 );
pls1.setDataDefinedProperty( QgsPalLayerSettings::ZIndex, true, true, "if(\"Class\"='Jet',3,0)", QString() );
provider1 = new QgsVectorLayerLabelProvider( vl, true, &pls1 );
provider1 = new QgsVectorLayerLabelProvider( vl, QString(), true, &pls1 );
engine.addProvider( provider1 );

p.begin( &img );

0 comments on commit 6f3032a

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