Skip to content

Commit 0a76ab4

Browse files
author
stopa85
committedJan 24, 2011
Road-Graph plugin added
git-svn-id: http://svn.osgeo.org/qgis/trunk@15068 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 864b1f0 commit 0a76ab4

31 files changed

+3186
-0
lines changed
 

‎src/plugins/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ SUBDIRS (copyright_label
1414
point_displacement_renderer
1515
spatialquery
1616
sqlanywhere
17+
roadgraph
1718
)
1819

1920
IF (WITH_SPATIALITE)

‎src/plugins/roadgraph/CMakeLists.txt

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
2+
########################################################
3+
# Files
4+
5+
SET (VRP_SRCS
6+
roadgraphplugin.cpp
7+
settingsdlg.cpp
8+
units.cpp
9+
utils.cpp
10+
shortestpathwidget.cpp
11+
linevectorlayersettings.cpp
12+
linevectorlayerwidget.cpp
13+
linevectorlayerdirector.cpp
14+
simplegraphbuilder.cpp
15+
exportdlg.cpp
16+
)
17+
18+
#SET ([pluginlcasename]_UIS [pluginlcasename]guibase.ui)
19+
20+
SET (VRP_MOC_HDRS
21+
roadgraphplugin.h
22+
settingsdlg.h
23+
shortestpathwidget.h
24+
linevectorlayerwidget.h
25+
exportdlg.h
26+
)
27+
SET (VRP_RCCS roadgraph.qrc)
28+
29+
INCLUDE_DIRECTORIES(
30+
${CMAKE_CURRENT_BINARY_DIR}
31+
../../core
32+
../../gui
33+
..
34+
)
35+
########################################################
36+
# Build
37+
38+
QT4_WRAP_CPP (VRP_MOC_SRCS ${VRP_MOC_HDRS})
39+
40+
QT4_ADD_RESOURCES(VRP_RCC_SRCS ${VRP_RCCS})
41+
42+
ADD_LIBRARY (roadgraphplugin MODULE ${VRP_SRCS} ${VRP_MOC_SRCS} ${VRP_RCC_SRCS})
43+
44+
45+
TARGET_LINK_LIBRARIES(roadgraphplugin
46+
qgis_core
47+
qgis_gui
48+
)
49+
50+
51+
########################################################
52+
# Install
53+
54+
INSTALL(TARGETS roadgraphplugin
55+
RUNTIME DESTINATION ${QGIS_PLUGIN_DIR}
56+
LIBRARY DESTINATION ${QGIS_PLUGIN_DIR})
57+

‎src/plugins/roadgraph/about.png

2.18 KB
Loading
1.64 KB
Loading

‎src/plugins/roadgraph/exportdlg.cpp

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/***************************************************************************
2+
* Copyright (C) 2010 by Sergey Yakushev *
3+
* yakushevs@list.ru *
4+
* *
5+
* This program is free software; you can redistribute it and/or modify *
6+
* it under the terms of the GNU General Public License as published by *
7+
* the Free Software Foundation; either version 2 of the License, or *
8+
* (at your option) any later version. *
9+
***************************************************************************/
10+
#include "exportdlg.h"
11+
#include <qgscontexthelp.h>
12+
13+
//qt includes
14+
#include <qlabel.h>
15+
#include <qcombobox.h>
16+
#include <QHBoxLayout>
17+
#include <QVBoxLayout>
18+
#include <qdialogbuttonbox.h>
19+
#include <qmessagebox.h>
20+
21+
22+
// Qgis includes
23+
#include <qgsvectorlayer.h>
24+
#include <qgsmaplayerregistry.h>
25+
#include <qgsproviderregistry.h>
26+
#include <qgsvectordataprovider.h>
27+
28+
//standard includes
29+
30+
RgExportDlg::RgExportDlg( QWidget* parent, Qt::WFlags fl )
31+
: QDialog( parent, fl )
32+
{
33+
// create base widgets;
34+
setWindowTitle( tr("Export feature") );
35+
QVBoxLayout *v = new QVBoxLayout( this );
36+
37+
QHBoxLayout *h = new QHBoxLayout();
38+
QLabel *l = new QLabel( tr("Select destination layer:"), this);
39+
h->addWidget(l);
40+
mcbLayers = new QComboBox( this );
41+
h->addWidget(mcbLayers);
42+
v->addLayout(h);
43+
44+
QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this);
45+
connect(bb, SIGNAL(accepted()), this, SLOT(on_buttonBox_accepted()) );
46+
connect(bb, SIGNAL(rejected()), this, SLOT(on_buttonBox_rejected()) );
47+
v->addWidget(bb);
48+
49+
//fill list of layers
50+
mcbLayers->insertItem( 0, tr("new temporary layer"), QVariant("-1") );
51+
52+
QMap<QString, QgsMapLayer*> mapLayers = QgsMapLayerRegistry::instance()->mapLayers();
53+
QMap<QString, QgsMapLayer*>::iterator layer_it = mapLayers.begin();
54+
55+
for ( ; layer_it != mapLayers.end(); ++layer_it )
56+
{
57+
QgsVectorLayer* vl = dynamic_cast<QgsVectorLayer*>( layer_it.value() );
58+
if ( !vl )
59+
continue;
60+
if ( vl->geometryType() != QGis::Line )
61+
continue;
62+
mcbLayers->insertItem( 0, vl->name(), QVariant( vl->getLayerID() ) );
63+
}
64+
65+
} // RgSettingsDlg::RgSettingsDlg()
66+
67+
RgExportDlg::~RgExportDlg()
68+
{
69+
}
70+
71+
QgsVectorLayer* RgExportDlg::mapLayer() const
72+
{
73+
QgsVectorLayer* myLayer = NULL;
74+
QString layerId = mcbLayers->itemData( mcbLayers->currentIndex() ).toString();
75+
76+
if ( layerId == QString("-1") )
77+
{
78+
// create a temporary layer
79+
myLayer = new QgsVectorLayer( "LineString", "shortest path", "memory" );
80+
81+
QgsVectorDataProvider *prov = myLayer->dataProvider();
82+
if ( prov == NULL)
83+
return NULL;
84+
85+
QList<QgsField> attrList;
86+
attrList.append( QgsField("one", QVariant::Int) );
87+
prov->addAttributes( attrList );
88+
QgsMapLayerRegistry::instance()->addMapLayer( myLayer );
89+
90+
}else
91+
{
92+
// retrun selected layer
93+
myLayer = dynamic_cast<QgsVectorLayer*>( QgsMapLayerRegistry::instance()->mapLayer( layerId ) );
94+
}
95+
96+
return myLayer;
97+
} // QgsVectorLayer* RgExportDlg::vectorLayer() const
98+
99+
void RgExportDlg::on_buttonBox_accepted()
100+
{
101+
accept();
102+
} // void RgExportDlg::on_buttonBox_accepted()
103+
104+
void RgExportDlg::on_buttonBox_rejected()
105+
{
106+
reject();
107+
}
108+
109+
void RgExportDlg::on_buttonBox_helpRequested()
110+
{
111+
QgsContextHelp::run( context_id );
112+
}

‎src/plugins/roadgraph/exportdlg.h

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/***************************************************************************
2+
exportdlg.h
3+
--------------------------------------
4+
Date : 2010-11-29
5+
Copyright : (C) 2010 by Yakushev Sergey
6+
Email : YakushevS <at> list.ru
7+
****************************************************************************
8+
* *
9+
* This program is free software; you can redistribute it and/or modify *
10+
* it under the terms of the GNU General Public License as published by *
11+
* the Free Software Foundation; either version 2 of the License, or *
12+
* (at your option) any later version. *
13+
* *
14+
***************************************************************************/
15+
#ifndef ROADGRAPH_EXPORTDLG_H
16+
#define ROADGRAPH_EXPORTDLG_H
17+
18+
#include <QDialog>
19+
20+
// forward declaration QT-classes
21+
class QComboBox;
22+
23+
// forward declaration Qgis-classes
24+
25+
//forward declaration RoadGraph plugins classes
26+
class QgsVectorLayer;
27+
28+
/**
29+
@author Sergey Yakushev
30+
*/
31+
/**
32+
* \class RgSettingsDlg
33+
* \brief implement of export dialog
34+
*/
35+
class RgExportDlg : public QDialog
36+
{
37+
Q_OBJECT
38+
public:
39+
RgExportDlg( QWidget* parent = 0, Qt::WFlags fl = 0 );
40+
~RgExportDlg();
41+
public:
42+
QgsVectorLayer* mapLayer() const;
43+
private:
44+
static const int context_id = 0;
45+
46+
private slots:
47+
void on_buttonBox_accepted();
48+
void on_buttonBox_rejected();
49+
void on_buttonBox_helpRequested();
50+
51+
private:
52+
QComboBox *mcbLayers;
53+
};
54+
#endif

‎src/plugins/roadgraph/graphbuilder.h

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/***************************************************************************
2+
graphbuilder.h
3+
--------------------------------------
4+
Date : 2010-10-22
5+
Copyright : (C) 2010 by Yakushev Sergey
6+
Email : YakushevS <at> list.ru
7+
****************************************************************************
8+
* *
9+
* This program is free software; you can redistribute it and/or modify *
10+
* it under the terms of the GNU General Public License as published by *
11+
* the Free Software Foundation; either version 2 of the License, or *
12+
* (at your option) any later version. *
13+
* *
14+
***************************************************************************/
15+
#ifndef ROADGRAPH_GRAPHBUILDER
16+
#define ROADGRAPH_GRAPHBUILDER
17+
18+
#include "utils.h"
19+
20+
//QT4 includes
21+
22+
//QGIS includes
23+
#include <qgspoint.h>
24+
#include <qgscoordinatereferencesystem.h>
25+
26+
//forward declarations
27+
28+
/**
29+
* \class RgGraphDirector
30+
* \brief Determine making the graph
31+
* contained the settings
32+
*/
33+
class RgGraphBuilder
34+
{
35+
public:
36+
//! Destructor
37+
virtual ~RgGraphBuilder()
38+
{};
39+
/**
40+
* set source CRS
41+
*/
42+
virtual void setSourceCrs( const QgsCoordinateReferenceSystem& crs ) = 0;
43+
44+
/**
45+
* set destionation CRS
46+
*/
47+
virtual void setDestinationCrs( const QgsCoordinateReferenceSystem& crs ) = 0;
48+
49+
/**
50+
* add vertex
51+
*/
52+
virtual void addVertex( const QgsPoint& pt ) = 0;
53+
54+
/**
55+
* add arc
56+
*/
57+
virtual void addArc( const QgsPoint& pt1, const QgsPoint& pt2, double speed ) = 0;
58+
59+
/**
60+
* tie point
61+
* @param pt maps point
62+
* @param pt ok = false if tiePoint failed.
63+
* @return Graph vertex corresponding pt.
64+
* @note: graph can be modified
65+
*/
66+
virtual QgsPoint tiePoint( const QgsPoint &pt, bool &ok ) = 0;
67+
68+
};
69+
#endif //GRAPHBUILDER

‎src/plugins/roadgraph/graphdirector.h

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/***************************************************************************
2+
graphdirector.h
3+
--------------------------------------
4+
Date : 2010-10-18
5+
Copyright : (C) 2010 by Yakushev Sergey
6+
Email : YakushevS <at> list.ru
7+
****************************************************************************
8+
* *
9+
* This program is free software; you can redistribute it and/or modify *
10+
* it under the terms of the GNU General Public License as published by *
11+
* the Free Software Foundation; either version 2 of the License, or *
12+
* (at your option) any later version. *
13+
* *
14+
***************************************************************************/
15+
#ifndef ROADGRAPH_GRAPHDIRECTOR
16+
#define ROADGRAPH_GRAPHDIRECTOR
17+
18+
//QT4 includes
19+
20+
//QGIS includes
21+
#include <qgsrectangle.h>
22+
23+
//forward declarations
24+
class RgSettings;
25+
class RgGraphBuilder;
26+
27+
/**
28+
* \class RgGraphDirector
29+
* \brief Determine making the graph
30+
* contained the settings
31+
*/
32+
class RgGraphDirector
33+
{
34+
public:
35+
//! Destructor
36+
virtual ~RgGraphDirector() { };
37+
38+
/**
39+
* get adjacency matrix
40+
*/
41+
virtual void makeGraph( RgGraphBuilder * ) const = 0;
42+
43+
/**
44+
* return pointer to my Settings
45+
*/
46+
virtual RgSettings* settings() = 0;
47+
48+
/**
49+
* return Director name
50+
*/
51+
virtual QString name() const = 0;
52+
};
53+
#endif //GRAPHDIRECTOR

0 commit comments

Comments
 (0)
Please sign in to comment.