Skip to content

Commit

Permalink
Use QgsFeatureId instead of QString for feature IDs
Browse files Browse the repository at this point in the history
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 59037eb
Show file tree
Hide file tree
Showing 13 changed files with 32 additions and 34 deletions.
2 changes: 1 addition & 1 deletion src/core/dxf/qgsdxfpallabeling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/core/pal/feature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down Expand Up @@ -197,7 +197,7 @@ namespace pal
return mFeature->layer;
}

QString FeaturePart::getUID() const
QgsFeatureId FeaturePart::featureId() const
{
return mFeature->uid;
}
Expand Down
6 changes: 3 additions & 3 deletions src/core/pal/feature.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -280,7 +280,7 @@ namespace pal

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


#if 0
Expand Down
18 changes: 9 additions & 9 deletions src/core/pal/layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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 );
Expand Down Expand Up @@ -250,7 +250,7 @@ namespace pal
if ( addedFeature )
{
features << f;
mHashtable.insert( geom_id, f );
mHashtable.insert( fid, f );
}
else
{
Expand All @@ -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() );
Expand Down
8 changes: 4 additions & 4 deletions src/core/pal/layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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();
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/core/pal/pointset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/core/pal/pointset.h
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgslabelingenginev2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
6 changes: 3 additions & 3 deletions src/core/qgslabelingenginev2.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions src/core/qgspalgeometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ class QgsPalGeometry : public PalGeometry
, mWordSpacing( wordSpacing )
, mCurvedLabeling( curvedLabeling )
{
mStrId = FID_TO_STRING( mId );
mDefinedFont = QFont();
}

Expand All @@ -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
Expand Down Expand Up @@ -157,7 +156,6 @@ class QgsPalGeometry : public PalGeometry
GEOSGeometry* mG;
QString mText;
QStringList mClusters;
QString mStrId;
QgsFeatureId mId;
LabelInfo* mInfo;
bool mIsDiagram;
Expand Down
4 changes: 2 additions & 2 deletions src/core/qgspallabeling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) );
Expand Down Expand Up @@ -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 );
}

Expand Down
4 changes: 2 additions & 2 deletions src/core/qgsvectorlayerdiagramprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

}

Expand Down Expand Up @@ -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 );
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsvectorlayerlabelprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() );
}


Expand Down

0 comments on commit 59037eb

Please sign in to comment.