Skip to content
Permalink
Browse files

use QgsVectorLayer*, not use LayerId

  • Loading branch information
Sergey Yakushevs
Sergey Yakushevs committed Jun 3, 2011
1 parent 59a8a8d commit a568c7b99436f6869dd73620f7b345698b3d8af1
@@ -19,7 +19,6 @@

// Qgis includes
#include <qgsvectorlayer.h>
#include <qgsmaplayerregistry.h>
#include <qgsvectordataprovider.h>
#include <qgspoint.h>
#include <qgsgeometry.h>
@@ -84,15 +83,15 @@ template <typename RandIter, typename Type, typename CompareOp > RandIter my_bin
return not_found;
}

QgsLineVectorLayerDirector::QgsLineVectorLayerDirector( const QString& layerId,
QgsLineVectorLayerDirector::QgsLineVectorLayerDirector( QgsVectorLayer *myLayer,
int directionFieldId,
const QString& directDirectionValue,
const QString& reverseDirectionValue,
const QString& bothDirectionValue,
int defaultDirection
)
{
mLayerId = layerId;
mVectorLayer = myLayer;
mDirectionFieldId = directionFieldId;
mDirectDirectionValue = directDirectionValue;
mReverseDirectionValue = reverseDirectionValue;
@@ -113,7 +112,7 @@ QString QgsLineVectorLayerDirector::name() const
void QgsLineVectorLayerDirector::makeGraph( QgsGraphBuilderInterface *builder, const QVector< QgsPoint >& additionalPoints,
QVector< QgsPoint >& tiedPoint ) const
{
QgsVectorLayer *vl = myLayer();
QgsVectorLayer *vl = mVectorLayer;

if ( vl == NULL )
return;
@@ -346,14 +345,3 @@ void QgsLineVectorLayerDirector::makeGraph( QgsGraphBuilderInterface *builder, c
} // while( vl->nextFeature(feature) )
} // makeGraph( QgsGraphBuilderInterface *builder, const QVector< QgsPoint >& additionalPoints, QVector< QgsPoint >& tiedPoint )

QgsVectorLayer* QgsLineVectorLayerDirector::myLayer() const
{
QMap <QString, QgsMapLayer*> m = QgsMapLayerRegistry::instance()->mapLayers();
QMap <QString, QgsMapLayer*>::const_iterator it = m.find( mLayerId );
if ( it == m.end() )
{
return NULL;
}
// return NULL if it.value() isn't QgsVectorLayer()
return dynamic_cast<QgsVectorLayer*>( it.value() );
}
@@ -43,14 +43,14 @@ class QgsLineVectorLayerDirector : public QgsGraphDirector
};
public:
/**
* @param layerId
* @param vl source vector layer
* @param directionFieldId feield contain road direction value
* @param directDirectionValue value for one-way road
* @param reverseDirectionValue value for reverse one-way road
* @param bothDirectionValue value for road
* @param defaultDirection 1 - direct direction, 2 - reverse direction, 3 - both direction
*/
QgsLineVectorLayerDirector( const QString& layerId,
QgsLineVectorLayerDirector( QgsVectorLayer* vl,
int directionFieldId,
const QString& directDirectionValue,
const QString& reverseDirectionValue,
@@ -70,13 +70,10 @@ class QgsLineVectorLayerDirector : public QgsGraphDirector

QString name() const;

private:

QgsVectorLayer* myLayer() const;

private:

QString mLayerId;
QgsVectorLayer *mVectorLayer;

int mDirectionFieldId;

@@ -260,7 +260,6 @@ const QgsGraphDirector* RoadGraphPlugin::director() const
{
if ( it.value()->name() != mSettings->mLayer )
continue;
layerId = it.key();
layer = dynamic_cast< QgsVectorLayer* >( it.value() );
break;
}
@@ -274,7 +273,7 @@ const QgsGraphDirector* RoadGraphPlugin::director() const
SpeedUnit speedUnit = SpeedUnit::byName( mSettings->mSpeedUnitName );

QgsLineVectorLayerDirector * director =
new QgsLineVectorLayerDirector( layerId,
new QgsLineVectorLayerDirector( layer,
provider->fieldNameIndex( mSettings->mDirection ),
mSettings->mFirstPointToLastPointDirectionVal,
mSettings->mLastPointToFirstPointDirectionVal,

0 comments on commit a568c7b

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