Skip to content

Commit

Permalink
use QgsVectorLayer*, not use LayerId
Browse files Browse the repository at this point in the history
  • Loading branch information
stopa85milk committed Jun 3, 2011
1 parent 59a8a8d commit a568c7b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 23 deletions.
18 changes: 3 additions & 15 deletions src/analysis/network/qgslinevectorlayerdirector.cpp
Expand Up @@ -19,7 +19,6 @@

// Qgis includes
#include <qgsvectorlayer.h>
#include <qgsmaplayerregistry.h>
#include <qgsvectordataprovider.h>
#include <qgspoint.h>
#include <qgsgeometry.h>
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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() );
}
9 changes: 3 additions & 6 deletions src/analysis/network/qgslinevectorlayerdirector.h
Expand Up @@ -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,
Expand All @@ -70,13 +70,10 @@ class QgsLineVectorLayerDirector : public QgsGraphDirector

QString name() const;

private:

QgsVectorLayer* myLayer() const;

private:

QString mLayerId;
QgsVectorLayer *mVectorLayer;

int mDirectionFieldId;

Expand Down
3 changes: 1 addition & 2 deletions src/plugins/roadgraph/roadgraphplugin.cpp
Expand Up @@ -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;
}
Expand All @@ -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,
Expand Down

0 comments on commit a568c7b

Please sign in to comment.