Skip to content
Permalink
Browse files

Use QgsFeatureId instead of QString for feature IDs

This code has been funded by Tuscany Region (Italy) - SITA (CIG: 63526840AE) and commissioned to Gis3W s.a.s.
  • Loading branch information
wonder-sk committed Sep 21, 2015
1 parent c7b394d commit 59037eb12a9e4f8c60b0066897362791028cc483
@@ -50,7 +50,7 @@ void QgsDxfLabelProvider::drawLabel( QgsRenderContext& context, pal::LabelPositi
//angle
double angle = label->getAlpha() * 180 / M_PI;

QgsFeatureId fid = STRING_TO_FID( label->getFeaturePart()->getUID() );
QgsFeatureId fid = label->getFeaturePart()->featureId();
QString dxfLayer = mDxfLayerNames[fid];

//debug: show label rectangle
@@ -56,14 +56,14 @@

namespace pal
{
Feature::Feature( Layer* l, const QString &geom_id, PalGeometry* userG, double lx, double ly )
Feature::Feature( Layer* l, QgsFeatureId fid, PalGeometry* userG, double lx, double ly )
: layer( l )
, userGeom( userG )
, label_x( lx )
, label_y( ly )
, distlabel( 0 )
, labelInfo( NULL )
, uid( geom_id )
, uid( fid )
, fixedPos( false )
, fixedPosX( 0.0 )
, fixedPosY( 0.0 )
@@ -197,7 +197,7 @@ namespace pal
return mFeature->layer;
}

QString FeaturePart::getUID() const
QgsFeatureId FeaturePart::featureId() const
{
return mFeature->uid;
}
@@ -78,7 +78,7 @@ namespace pal
friend class FeaturePart;

public:
Feature( Layer* l, const QString& geom_id, PalGeometry* userG, double lx, double ly );
Feature( Layer* l, QgsFeatureId fid, PalGeometry* userG, double lx, double ly );
~Feature();

void setLabelInfo( LabelInfo* info ) { labelInfo = info; }
@@ -167,7 +167,7 @@ namespace pal
double distlabel;
LabelInfo* labelInfo; // optional

QString uid;
QgsFeatureId uid;

bool fixedPos; //true in case of fixed position (only 1 candidate position with cost 0)
double fixedPosX;
@@ -280,7 +280,7 @@ namespace pal

/** Returns the unique ID of the feature.
*/
QString getUID() const;
QgsFeatureId featureId() const;


#if 0
@@ -91,9 +91,9 @@ namespace pal
mMutex.unlock();
}

Feature* Layer::getFeature( const QString& geom_id )
Feature* Layer::getFeature( QgsFeatureId fid )
{
QHash< QString, Feature*>::const_iterator i = mHashtable.find( geom_id );
QHash< QgsFeatureId, Feature*>::const_iterator i = mHashtable.find( fid );
if ( i != mHashtable.constEnd() )
return *i;
else
@@ -110,16 +110,16 @@ namespace pal
mDefaultPriority = priority;
}

bool Layer::registerFeature( const QString& geom_id, PalGeometry *userGeom, double label_x, double label_y, const QString &labelText,
bool Layer::registerFeature( QgsFeatureId fid, PalGeometry *userGeom, double label_x, double label_y, const QString &labelText,
double labelPosX, double labelPosY, bool fixedPos, double angle, bool fixedAngle,
int xQuadOffset, int yQuadOffset, double xOffset, double yOffset, bool alwaysShow, double repeatDistance )
{
if ( geom_id.isEmpty() || label_x < 0 || label_y < 0 )
if ( label_x < 0 || label_y < 0 )
return false;

mMutex.lock();

if ( mHashtable.contains( geom_id ) )
if ( mHashtable.contains( fid ) )
{
mMutex.unlock();
//A feature with this id already exists. Don't throw an exception as sometimes,
@@ -130,7 +130,7 @@ namespace pal
// Split MULTI GEOM and Collection in simple geometries
const GEOSGeometry *the_geom = userGeom->getGeosGeometry();

Feature* f = new Feature( this, geom_id, userGeom, label_x, label_y );
Feature* f = new Feature( this, fid, userGeom, label_x, label_y );
if ( fixedPos )
{
f->setFixedPosition( labelPosX, labelPosY );
@@ -250,7 +250,7 @@ namespace pal
if ( addedFeature )
{
features << f;
mHashtable.insert( geom_id, f );
mHashtable.insert( fid, f );
}
else
{
@@ -263,15 +263,15 @@ namespace pal
bool Layer::registerFeature( QgsLabelFeature* label )
{
QgsPalGeometry* g = label->geometry();
if ( !registerFeature( g->strId(), g, label->size().width(), label->size().height(), label->labelText(),
if ( !registerFeature( g->featureId(), g, label->size().width(), label->size().height(), label->labelText(),
label->fixedPosition().x(), label->fixedPosition().y(), label->hasFixedPosition(),
label->fixedAngle(), label->hasFixedAngle(),
label->quadOffset().x(), label->quadOffset().y(),
label->positionOffset().x(), label->positionOffset().y(),
label->alwaysShow(), label->repeatDistance() ) )
return false;

pal::Feature* pf = getFeature( g->strId() );
pal::Feature* pf = getFeature( g->featureId() );
pf->setLabelInfo( g->info() );
pf->setPriority( label->priority() );
pf->setDistLabel( label->distLabel() );
@@ -228,7 +228,7 @@ namespace pal
bool fitInPolygonOnly() const { return mFitInPolygon; }

/** Register a feature in the layer.
* @param geom_id unique identifier
* @param fid unique identifier
* @param userGeom user's geometry that implements the PalGeometry interface
* @param label_x label width
* @param label_y label height
@@ -249,7 +249,7 @@ namespace pal
*
* @return true on success (i.e. valid geometry)
*/
bool registerFeature( const QString &geom_id, PalGeometry *userGeom, double label_x = -1, double label_y = -1,
bool registerFeature( QgsFeatureId fid, PalGeometry *userGeom, double label_x = -1, double label_y = -1,
const QString& labelText = QString(), double labelPosX = 0.0, double labelPosY = 0.0,
bool fixedPos = false, double angle = 0.0, bool fixedAngle = false,
int xQuadOffset = 0, int yQuadOffset = 0, double xOffset = 0.0, double yOffset = 0.0,
@@ -258,7 +258,7 @@ namespace pal
bool registerFeature( QgsLabelFeature* label );

/** Return pointer to feature or NULL if doesn't exist */
Feature* getFeature( const QString &geom_id );
Feature* getFeature( QgsFeatureId fid );

/** Join connected features with the same label text */
void joinConnectedFeatures();
@@ -296,7 +296,7 @@ namespace pal

// indexes (spatial and id)
RTree<FeaturePart*, double, 2, double, 8, 4> *rtree;
QHash< QString, Feature*> mHashtable;
QHash< QgsFeatureId, Feature*> mHashtable;

QHash< QString, QLinkedList<FeaturePart*>* > mConnectedHashtable;
QStringList mConnectedTexts;
@@ -362,7 +362,7 @@ namespace pal

void PointSet::splitPolygons( QLinkedList<PointSet*> &shapes_toProcess,
QLinkedList<PointSet*> &shapes_final,
double xrm, double yrm, const QString& uid )
double xrm, double yrm, const QgsFeatureId& uid )
{
#ifdef _DEBUG_
std::cout << "splitPolygons: " << uid << std::endl;
@@ -96,7 +96,7 @@ namespace pal
*/
static void splitPolygons( QLinkedList<PointSet *> &shapes_toProcess,
QLinkedList<PointSet *> &shapes_final,
double xrm, double yrm, const QString &uid );
double xrm, double yrm, const QgsFeatureId &uid );

/** Returns the squared minimum distance between the point set geometry and the point (px,py)
* Optionally, the nearest point is stored in (rx,ry).
@@ -344,7 +344,7 @@ QgsAbstractLabelProvider* QgsLabelingEngineV2::providerById( const QString& id )



QgsLabelFeature::QgsLabelFeature( QString id, QgsPalGeometry* geometry, const QSizeF& size )
QgsLabelFeature::QgsLabelFeature( QgsFeatureId id, QgsPalGeometry* geometry, const QSizeF& size )
: mId( id )
, mGeometry( geometry )
, mSize( size )
@@ -39,10 +39,10 @@ class QgsGeometry;
class CORE_EXPORT QgsLabelFeature
{
public:
QgsLabelFeature( QString id, QgsPalGeometry* geometry, const QSizeF& size );
QgsLabelFeature( QgsFeatureId id, QgsPalGeometry* geometry, const QSizeF& size );

//! Identifier of the label (unique within the parent label provider)
QString id() const { return mId; }
QgsFeatureId id() const { return mId; }

//! Get access to the associated geometry
QgsPalGeometry* geometry() const { return mGeometry; }
@@ -112,7 +112,7 @@ class CORE_EXPORT QgsLabelFeature
protected:

//! Associated ID unique within the parent label provider
QString mId;
QgsFeatureId mId;
//! Geometry wrapper for the feature
QgsPalGeometry* mGeometry;
//! Width and height of the label
@@ -24,7 +24,6 @@ class QgsPalGeometry : public PalGeometry
, mWordSpacing( wordSpacing )
, mCurvedLabeling( curvedLabeling )
{
mStrId = FID_TO_STRING( mId );
mDefinedFont = QFont();
}

@@ -47,7 +46,7 @@ class QgsPalGeometry : public PalGeometry
// nothing here - we'll delete the geometry in destructor
}

QString strId() { return mStrId; }
QgsFeatureId featureId() const { return mId; }
QString text() { return mText; }

/** Returns the text component corresponding to a specified label part
@@ -157,7 +156,6 @@ class QgsPalGeometry : public PalGeometry
GEOSGeometry* mG;
QString mText;
QStringList mClusters;
QString mStrId;
QgsFeatureId mId;
LabelInfo* mInfo;
bool mIsDiagram;
@@ -2183,7 +2183,7 @@ void QgsPalLayerSettings::registerFeature( QgsFeature& f, const QgsRenderContext
}

// feature to the layer
*labelFeature = new QgsLabelFeature( lbl->strId(), lbl, QSizeF( labelX, labelY ) );
*labelFeature = new QgsLabelFeature( lbl->featureId(), lbl, QSizeF( labelX, labelY ) );

( *labelFeature )->setHasFixedPosition( dataDefinedPosition );
( *labelFeature )->setFixedPosition( QgsPoint( xPos, yPos ) );
@@ -2333,7 +2333,7 @@ void QgsPalLayerSettings::registerObstacleFeature( QgsFeature& f, const QgsRende
geometries.append( lbl );

// feature to the layer
*obstacleFeature = new QgsLabelFeature( lbl->strId(), lbl, QSizeF( 0, 0 ) );
*obstacleFeature = new QgsLabelFeature( lbl->featureId(), lbl, QSizeF( 0, 0 ) );
( *obstacleFeature )->setIsObstacle( true );
}

@@ -154,7 +154,7 @@ void QgsVectorLayerDiagramProvider::drawLabel( QgsRenderContext& context, pal::L
//for diagrams, remove the additional 'd' at the end of the layer id
QString layerId = id();
layerId.chop( 1 );
mEngine->results()->mLabelSearchTree->insertLabel( label, QString( palGeometry->strId() ).toInt(), layerId, QString(), QFont(), true, false );
mEngine->results()->mLabelSearchTree->insertLabel( label, palGeometry->featureId(), layerId, QString(), QFont(), true, false );

}

@@ -342,7 +342,7 @@ QgsLabelFeature* QgsVectorLayerDiagramProvider::registerDiagram( QgsFeature& fea
}
}

QgsLabelFeature* lf = new QgsLabelFeature( lbl->strId(), lbl, QSizeF( diagramWidth, diagramHeight ) );
QgsLabelFeature* lf = new QgsLabelFeature( lbl->featureId(), lbl, QSizeF( diagramWidth, diagramHeight ) );
lf->setHasFixedPosition( ddPos );
lf->setFixedPosition( QgsPoint( ddPosX, ddPosY ) );
lf->setHasFixedAngle( true );
@@ -389,7 +389,7 @@ void QgsVectorLayerLabelProvider::drawLabel( QgsRenderContext& context, pal::Lab

// add to the results
QString labeltext = (( QgsPalGeometry* )label->getFeaturePart()->getUserGeometry() )->text();
mEngine->results()->mLabelSearchTree->insertLabel( label, QString( palGeometry->strId() ).toInt(), id(), labeltext, dFont, false, palGeometry->isPinned() );
mEngine->results()->mLabelSearchTree->insertLabel( label, palGeometry->featureId(), id(), labeltext, dFont, false, palGeometry->isPinned() );
}


0 comments on commit 59037eb

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