const QgsGraphDirector* RoadGraphPlugin::director() const { QList< QgsMapLayer* > mapLayers = QgsMapLayerRegistry::instance()->mapLayersByName( mSettings->mLayerName ); if ( mapLayers.isEmpty() ) return nullptr; QgsVectorLayer *layer = dynamic_cast< QgsVectorLayer* >( mapLayers.at( 0 ) ); if ( !layer ) return nullptr; if ( layer->wkbType() == QgsWkbTypes::LineString || layer->wkbType() == QgsWkbTypes::MultiLineString ) { SpeedUnit speedUnit = SpeedUnit::byName( mSettings->mSpeedUnitName ); QgsLineVectorLayerDirector * director = new QgsLineVectorLayerDirector( layer, layer->fields().lookupField( mSettings->mDirection ), mSettings->mFirstPointToLastPointDirectionVal, mSettings->mLastPointToFirstPointDirectionVal, mSettings->mBothDirectionVal, mSettings->mDefaultDirection ); director->addProperter( new QgsDistanceArcProperter() ); director->addProperter( new RgSpeedProperter( layer->fields().lookupField( mSettings->mSpeed ), mSettings->mDefaultSpeed, speedUnit.multipler() ) ); return director; } return nullptr; }
const QgsGraphDirector* RoadGraphPlugin::director() const { QgsVectorLayer *layer = nullptr; QMap< QString, QgsMapLayer* > mapLayers = QgsMapLayerRegistry::instance()->mapLayers(); QMap< QString, QgsMapLayer* >::const_iterator it; for ( it = mapLayers.begin(); it != mapLayers.end(); ++it ) { if ( it.value()->name() != mSettings->mLayer ) continue; layer = dynamic_cast< QgsVectorLayer* >( it.value() ); break; } if ( !layer ) return nullptr; if ( layer->wkbType() == QGis::WKBLineString || layer->wkbType() == QGis::WKBMultiLineString ) { QgsVectorDataProvider *provider = layer->dataProvider(); if ( !provider ) return nullptr; SpeedUnit speedUnit = SpeedUnit::byName( mSettings->mSpeedUnitName ); QgsLineVectorLayerDirector * director = new QgsLineVectorLayerDirector( layer, provider->fieldNameIndex( mSettings->mDirection ), mSettings->mFirstPointToLastPointDirectionVal, mSettings->mLastPointToFirstPointDirectionVal, mSettings->mBothDirectionVal, mSettings->mDefaultDirection ); director->addProperter( new QgsDistanceArcProperter() ); director->addProperter( new RgSpeedProperter( provider->fieldNameIndex( mSettings->mSpeed ), mSettings->mDefaultSpeed, speedUnit.multipler() ) ); return director; } return nullptr; }