Skip to content
Permalink
Browse files

Merge pull request #905 from yellow-sky/show_partial_labels

Show partials labels
  • Loading branch information
dakcarto committed Sep 29, 2013
2 parents a95f07c + 3e382da commit cfa34641b0df011d1452daeccc24bf4ad9a20e0a
@@ -617,6 +617,9 @@ class QgsPalLabeling : QgsLabelingEngineInterface

bool isShowingAllLabels() const;
void setShowingAllLabels( bool showing );

bool isShowingPartialsLabels() const;
void setShowingPartialsLabels( bool showing );

// implemented methods from labeling engine interface

@@ -43,6 +43,8 @@ QgsLabelEngineConfigDialog::QgsLabelEngineConfigDialog( QgsPalLabeling* lbl, QWi
mShadowDebugRectChkBox->setChecked( mLBL->isShowingShadowRectangles() );

mSaveWithProjectChkBox->setChecked( mLBL->isStoredWithProject() );

chkShowPartialsLabels->setChecked( mLBL-> isShowingPartialsLabels() );
}


@@ -58,6 +60,7 @@ void QgsLabelEngineConfigDialog::onOK()
mLBL->setShowingCandidates( chkShowCandidates->isChecked() );
mLBL->setShowingShadowRectangles( mShadowDebugRectChkBox->isChecked() );
mLBL->setShowingAllLabels( chkShowAllLabels->isChecked() );
mLBL->setShowingPartialsLabels( chkShowPartialsLabels->isChecked() );

if ( mSaveWithProjectChkBox->isChecked() )
{
@@ -80,4 +83,5 @@ void QgsLabelEngineConfigDialog::setDefaults()
chkShowCandidates->setChecked( false );
chkShowAllLabels->setChecked( false );
mShadowDebugRectChkBox->setChecked( false );
chkShowPartialsLabels->setChecked( p.getShowPartial() );
}
@@ -1361,7 +1361,12 @@ namespace pal
// purge candidates that are outside the bbox
for ( i = 0; i < nbp; i++ )
{
if ( !( *lPos )[i]->isIn( bbox ) )
bool outside = false;
if ( f->layer->pal->getShowPartial() )
outside = !( *lPos )[i]->isIntersect( bbox );
else
outside = !( *lPos )[i]->isInside( bbox );
if ( outside )
{
rnbp--;
( *lPos )[i]->setCost( DBL_MAX ); // infinite cost => do not use
@@ -184,6 +184,39 @@ namespace pal
return false;

}

bool LabelPosition::isIntersect( double *bbox )
{
int i;

for ( i = 0; i < 4; i++ )
{
if ( x[i] >= bbox[0] && x[i] <= bbox[2] &&
y[i] >= bbox[1] && y[i] <= bbox[3] )
return true;
}

if ( nextPart )
return nextPart->isIntersect( bbox );
else
return false;
}

bool LabelPosition::isInside( double *bbox )
{
for (int i = 0; i < 4; i++ )
{
if ( !( x[i] >= bbox[0] && x[i] <= bbox[2] &&
y[i] >= bbox[1] && y[i] <= bbox[3] ) )
return false;
}

if ( nextPart )
return nextPart->isInside( bbox );
else
return true;

}

void LabelPosition::print()
{
@@ -109,12 +109,26 @@ namespace pal


/**
* \brief is the labelposition in the bounding-box ?
* \brief Is the labelposition in the bounding-box ? (intersect or inside????)
*
*\param bbox the bounding-box double[4] = {xmin, ymin, xmax, ymax}
*/
bool isIn( double *bbox );

/**
* \brief Is the labelposition intersect the bounding-box ?
*
*\param bbox the bounding-box double[4] = {xmin, ymin, xmax, ymax}
*/
bool isIntersect( double *bbox );

/**
* \brief Is the labelposition inside the bounding-box ?
*
*\param bbox the bounding-box double[4] = {xmin, ymin, xmax, ymax}
*/
bool isInside( double *bbox );

/**
* \brief Check whether or not this overlap with another labelPosition
*
@@ -106,7 +106,9 @@ namespace pal
point_p = 8;
line_p = 8;
poly_p = 8;


showPartial = true;

this->map_unit = pal::METER;

std::cout.precision( 12 );
@@ -899,6 +901,11 @@ namespace pal
if ( dpi > 0 )
this->dpi = dpi;
}

void Pal::setShowPartial(bool show)
{
this->showPartial = show;
}

int Pal::getPointP()
{
@@ -929,6 +936,11 @@ namespace pal
{
return dpi;
}

bool Pal::getShowPartial()
{
return showPartial;
}

SearchMethod Pal::getSearch()
{
@@ -166,6 +166,11 @@ namespace pal
int ejChainDeg;
int tenure;
double candListSize;

/**
* \brief show partial labels (cut-off by the map canvas) or not
*/
bool showPartial;

/**
* \brief Problem factory
@@ -352,8 +357,20 @@ namespace pal
* @return map resolution (dot per inch)
*/
int getDpi();



/**
*\brief Set flag show partial label
*
* @param show flag value
*/
void setShowPartial(bool show);

/**
* \brief Get flag show partial label
*
* @return value of flag
*/
bool getShowPartial();

/**
* \brief set # candidates to generate for points features
@@ -3049,6 +3049,7 @@ QgsPalLabeling::QgsPalLabeling()
mShowingCandidates = false;
mShowingShadowRects = false;
mShowingAllLabels = false;
mShowingPartialsLabels = p.getShowPartial();

mLabelSearchTree = new QgsLabelSearchTree();
}
@@ -3444,6 +3445,8 @@ void QgsPalLabeling::init( QgsMapRenderer* mr )
mPal->setLineP( mCandLine );
mPal->setPolyP( mCandPolygon );

mPal->setShowPartial( mShowingPartialsLabels );

clearActiveLayers(); // free any previous QgsDataDefined objects
mActiveDiagramLayers.clear();
}
@@ -4812,6 +4815,8 @@ void QgsPalLabeling::loadEngineSettings()
"PAL", "/ShowingShadowRects", false, &saved );
mShowingAllLabels = QgsProject::instance()->readBoolEntry(
"PAL", "/ShowingAllLabels", false, &saved );
mShowingPartialsLabels = QgsProject::instance()->readBoolEntry(
"PAL", "/ShowingPartialsLabels", p.getShowPartial(), &saved );
mSavedWithProject = saved;
}

@@ -4824,6 +4829,7 @@ void QgsPalLabeling::saveEngineSettings()
QgsProject::instance()->writeEntry( "PAL", "/ShowingCandidates", mShowingCandidates );
QgsProject::instance()->writeEntry( "PAL", "/ShowingShadowRects", mShowingShadowRects );
QgsProject::instance()->writeEntry( "PAL", "/ShowingAllLabels", mShowingAllLabels );
QgsProject::instance()->writeEntry( "PAL", "/ShowingPartialsLabels", mShowingPartialsLabels );
mSavedWithProject = true;
}

@@ -4836,6 +4842,7 @@ void QgsPalLabeling::clearEngineSettings()
QgsProject::instance()->removeEntry( "PAL", "/ShowingCandidates" );
QgsProject::instance()->removeEntry( "PAL", "/ShowingShadowRects" );
QgsProject::instance()->removeEntry( "PAL", "/ShowingAllLabels" );
QgsProject::instance()->removeEntry( "PAL", "/ShowingPartialsLabels" );
mSavedWithProject = false;
}

@@ -4845,5 +4852,6 @@ QgsLabelingEngineInterface* QgsPalLabeling::clone()
lbl->mShowingAllLabels = mShowingAllLabels;
lbl->mShowingCandidates = mShowingCandidates;
lbl->mShowingShadowRects = mShowingShadowRects;
lbl->mShowingPartialsLabels = mShowingPartialsLabels;
return lbl;
}
@@ -685,6 +685,9 @@ class CORE_EXPORT QgsPalLabeling : public QgsLabelingEngineInterface
bool isShowingAllLabels() const { return mShowingAllLabels; }
void setShowingAllLabels( bool showing ) { mShowingAllLabels = showing; }

bool isShowingPartialsLabels() const { return mShowingPartialsLabels; }
void setShowingPartialsLabels( bool showing ) { mShowingPartialsLabels = showing; }

// implemented methods from labeling engine interface

//! called when we're going to start with rendering
@@ -781,6 +784,7 @@ class CORE_EXPORT QgsPalLabeling : public QgsLabelingEngineInterface
bool mShowingAllLabels; // whether to avoid collisions or not
bool mSavedWithProject; // whether engine settings have been read from project file
bool mShowingShadowRects; // whether to show debugging rectangles for drop shadows
bool mShowingPartialsLabels; // whether to avoid partials labels or not

QgsLabelSearchTree* mLabelSearchTree;
};
@@ -3661,5 +3661,12 @@ void QgsProjectParser::loadLabelSettings( QgsLabelingEngineInterface* lbl )
{
pal->setShowingAllLabels( showAllLabelsElem.text().compare( "true", Qt::CaseInsensitive ) == 0 );
}

//mShowingPartialsLabels
QDomElement showPartialsLabelsElem = palElem.firstChildElement( "ShowingPartialsLabels" );
if ( !showPartialsLabelsElem.isNull() )
{
pal->setShowingPartialsLabels( showPartialsLabelsElem.text().compare( "true", Qt::CaseInsensitive ) == 0 );
}
}
}
@@ -17,7 +17,7 @@
</size>
</property>
<property name="windowTitle">
<string>Dialog</string>
<string>Automated Placement Engine</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
@@ -215,7 +215,7 @@
<property name="verticalSpacing">
<number>6</number>
</property>
<item row="1" column="0">
<item row="2" column="0">
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
@@ -231,7 +231,7 @@
</property>
</spacer>
</item>
<item row="0" column="0" colspan="3">
<item row="1" column="0" colspan="3">
<widget class="QCheckBox" name="chkShowAllLabels">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
@@ -244,7 +244,7 @@
</property>
</widget>
</item>
<item row="4" column="0" colspan="3">
<item row="5" column="0" colspan="3">
<widget class="QCheckBox" name="mSaveWithProjectChkBox">
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
@@ -257,14 +257,14 @@
</property>
</widget>
</item>
<item row="2" column="0" colspan="3">
<item row="3" column="0" colspan="3">
<widget class="QCheckBox" name="chkShowCandidates">
<property name="text">
<string>Show candidates (for debugging)</string>
</property>
</widget>
</item>
<item row="1" column="1">
<item row="2" column="1">
<widget class="QLabel" name="label_6">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
@@ -277,7 +277,7 @@
</property>
</widget>
</item>
<item row="1" column="2">
<item row="2" column="2">
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
@@ -290,13 +290,20 @@
</property>
</spacer>
</item>
<item row="3" column="0" colspan="3">
<item row="4" column="0" colspan="3">
<widget class="QCheckBox" name="mShadowDebugRectChkBox">
<property name="text">
<string>Show shadow rectangles (for debugging)</string>
</property>
</widget>
</item>
<item row="0" column="0" colspan="3">
<widget class="QCheckBox" name="chkShowPartialsLabels">
<property name="text">
<string>Show partials labels</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
@@ -106,13 +106,18 @@ def setUpClass(cls):
cls._MapRenderer.setDestinationCrs(cls._CRS)
# use platform's native logical output dpi for QgsMapRenderer on launch

cls._Pal = QgsPalLabeling()
cls._MapRenderer.setLabelingEngine(cls._Pal)
cls._PalEngine = cls._MapRenderer.labelingEngine()
cls.setDefaultEngineSettings()
msg = ('\nCould not initialize PAL labeling engine, '
'SKIPPING TEST SUITE')
assert cls._PalEngine, msg

@classmethod
def setDefaultEngineSettings(cls):
"""Restore default settings for pal labelling"""
cls._Pal = QgsPalLabeling()
cls._MapRenderer.setLabelingEngine(cls._Pal)
cls._PalEngine = cls._MapRenderer.labelingEngine()

@classmethod
def tearDownClass(cls):
"""Run after all tests"""
@@ -294,6 +299,24 @@ def test_write_read_settings(self):

msg = '\nLayer settings read not same as settings written'
self.assertDictEqual(lyr1dict, lyr2dict, msg)

def test_default_partials_labels_enabled(self):
# Verify ShowingPartialsLabels is enabled for PAL by default
pal = QgsPalLabeling()
self.assertTrue(pal.isShowingPartialsLabels())

def test_partials_labels_activate(self):
pal = QgsPalLabeling()
# Enable partials labels
pal.setShowingPartialsLabels(True)
self.assertTrue(pal.isShowingPartialsLabels())

def test_partials_labels_deactivate(self):
pal = QgsPalLabeling()
# Disable partials labels
pal.setShowingPartialsLabels(False)
self.assertFalse(pal.isShowingPartialsLabels())



def runSuite(module, tests):

0 comments on commit cfa3464

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