Browse Source

Limpiando el código, documentando

Rafael Arce Nazario 9 years ago
parent
commit
b7578ad059
10 changed files with 1171747 additions and 68 deletions
  1. 0
    18
      country.cpp
  2. 5
    23
      country.h
  3. 0
    1
      mainwindow.cpp
  4. 1
    1
      mainwindow.h
  5. 11
    16
      map.cpp
  6. 35
    9
      map.h
  7. 89
    0
      moc_mainwindow.cpp
  8. 89
    0
      moc_map.cpp
  9. 1171448
    0
      qrc_prmap.cpp
  10. 69
    0
      ui_mainwindow.h

+ 0
- 18
country.cpp View File

@@ -27,25 +27,7 @@ void Country::limits(){
27 27
     qDebug() << minX << minY << maxX << maxY ;
28 28
 }
29 29
 
30
-void Country::topLeft(QString &st, DoublePoint &p ) {
31
-    QMap<QString,City*>::iterator it = Cities.begin();
32
-    st = it.key();
33
-    p.x = it.value()->getGeometry()->at(0).x;
34
-    p.y = it.value()->getGeometry()->at(0).y;
35
-
36
-    qDebug() << p.x << ". " << p.y;
37
-    for (it = Cities.begin(); it != Cities.end(); ++it) {
38
-        QVector<DoublePoint> *geometry = it.value()->getGeometry();
39
-        for (int i = 0; i < geometry->size(); i++) {
40
-            if (geometry->at(i).x > p.x && geometry->at(i).y < p.y)  {
41
-                p.x = geometry->at(i).x;
42
-                p.y = geometry->at(i).y;
43
-                st = it.key();
44
-            }
45
-        }
46 30
 
47
-    }
48
-}
49 31
 unsigned long  *colorMap;
50 32
 bool Country::readInfoFromJSON(const QString &fileName) {
51 33
     QFile loadFile(fileName);

+ 5
- 23
country.h View File

@@ -35,34 +35,16 @@ public:
35 35
     ///
36 36
     bool readInfoFromJSON(const QString &fileName);
37 37
 
38
-    /// \fn topLeft(QString &st, DoublePoint &p );
39
-    /// \~English
40
-    /// \brief ??
41
-    /// \param ??
42
-    /// \~Spanish
43
-    /// \brief ??
44
-    /// \param ??
45
-    ///
46
-    void topLeft(QString &st, DoublePoint &p );
47
-
48 38
     /// \fn void limits();
49 39
     /// \~English
50
-    /// \brief ??
51
-    /// \param ??
52
-    /// \~Spanish
53
-    /// \brief ??
54
-    /// \param ??
40
+    /// \brief Determines the coordinates of the top left and bottom right
41
+    ///        corners of the map.
42
+    /// \~Spanish 
43
+    /// \brief Determina las coordenadas de las esquinas superior izquierda
44
+    ///        e inferior derecha del mapa.
55 45
     ///
56 46
     void limits();
57 47
 
58
-    /// \fn QMap<QString,City*> getCities()
59
-    /// \~English
60
-    /// \brief gets the Cities map structure.
61
-    /// \~Spanish
62
-    /// \brief consigue la estructura de mapa de Cities.
63
-    ///
64
-    QMap<QString,City*> getCities() { return Cities;}
65
-    //~Country() { delete Cities; }
66 48
 };
67 49
 
68 50
 #endif // COUNTRY_H

+ 0
- 1
mainwindow.cpp View File

@@ -13,7 +13,6 @@
13 13
 #include <QPoint>
14 14
 #include <string>
15 15
 #include <QPolygon>
16
-#include <census.h>
17 16
 #include <city.h>
18 17
 #include <country.h>
19 18
 #include <doublepoint.h>

+ 1
- 1
mainwindow.h View File

@@ -2,7 +2,7 @@
2 2
 #define MAINWINDOW_H
3 3
 
4 4
 #include <QMainWindow>
5
-#include <census.h>
5
+// #include <census.h>
6 6
 #include "map.h"
7 7
 namespace Ui {
8 8
 class MainWindow;

+ 11
- 16
map.cpp View File

@@ -9,17 +9,19 @@ Map::Map(QWidget *parent) :
9 9
 {
10 10
     srand(time(NULL));
11 11
 
12
-
13
-    myCountry = new Country;
12
+    // Create country object and read data from the json file
13
+    myCountry = new Country;  
14 14
     myCountry->readInfoFromJSON(":/data/cityLimitsPR.json");
15 15
 
16 16
     cityColorMap = NULL;
17 17
     gisLocations = NULL;
18 18
     drawRoutes = false;
19 19
 
20
+    // Compute the limits of the coordinates 
20 21
     qDebug() << "Computing limits...";
21 22
     myCountry->limits();
22 23
 
24
+    // Create the main widget and resize according to the map aspect ratio
23 25
     QDesktopWidget widget;
24 26
     QRect mainScreenSize = widget.availableGeometry(widget.primaryScreen());
25 27
 
@@ -37,10 +39,11 @@ Map::~Map() {
37 39
     if (gisLocations != NULL)    delete [] gisLocations;
38 40
 }
39 41
 
42
+// These are used during the map drawing.
40 43
 QPoint **qpA = new QPoint*[100];
41 44
 unsigned int qpASize = 0;
42 45
 
43
-void Map::paintEvent(QPaintEvent *event) {
46
+void Map::paintEvent(QPaintEvent *) {
44 47
 
45 48
     // the QPainter is the 'canvas' to which we will draw
46 49
     // the QPen is the pen that will be used to draw to the 'canvas'
@@ -146,10 +149,6 @@ void Map::paintEvent(QPaintEvent *event) {
146 149
 
147 150
         p->drawPolygon(qpBegin,ctr,Qt::WindingFill);
148 151
 
149
-
150
-
151
-
152
-
153 152
         delete tmpPath;
154 153
         colorCtr++;
155 154
         cityCounter++;
@@ -163,15 +162,13 @@ void Map::paintEvent(QPaintEvent *event) {
163 162
     int cX, cY, pX, pY;
164 163
     cX = cY = pX = pY = -1;
165 164
 
166
-    //qDebug() << "gisLocations:" << gisLocations << endl;
167
-
168 165
     if(gisLocations) {
169 166
         myPen.setWidth(2);
170 167
         myPen.setColor(QColor(0x100000));
171 168
         myPen.setBrush(QBrush(Qt::black));
172 169
 
173 170
         p->setPen(myPen);
174
-        for (int i = 0; i < numLocations; i++) {
171
+        for (unsigned int i = 0; i < numLocations; i++) {
175 172
             qDebug() << "name from locations:" << gisLocations[i].getName();
176 173
 
177 174
             cX = factorX * (gisLocations[i].getLon() - myCountry->minX);
@@ -188,10 +185,12 @@ void Map::paintEvent(QPaintEvent *event) {
188 185
         }
189 186
     }
190 187
 
191
-     QVector < QPair<const GISPOI *,const GISPOI *> > ::iterator vit = this->cityLines.begin();
188
+    // Draws any lines between the cities which have been added using 
189
+    // the drawLine method.
190
+
191
+    QVector < QPair<const GISPOI *,const GISPOI *> > ::iterator vit = this->cityLines.begin();
192 192
     for (; vit != this->cityLines.end(); vit++) {
193 193
 
194
-//        qDebug() << "A line from " << linePair.first->getName() << " to " << linePair.second->getName() << endl;
195 194
         cX = factorX * (vit->first->getLon() - myCountry->minX);
196 195
         cY = height() - factorY*(vit->first->getLat()  - myCountry->minY);
197 196
         pX = factorX * (vit->second->getLon() - myCountry->minX);
@@ -213,7 +212,3 @@ void Map::paintEvent(QPaintEvent *event) {
213 212
     delete p;
214 213
 }
215 214
 
216
-
217
-void Map::drawLine(const GISPOI &city01, const GISPOI &city02) {
218
-    this->cityLines.push_back(QPair<const GISPOI *, const GISPOI *> (&city01, &city02));
219
-}

+ 35
- 9
map.h View File

@@ -4,31 +4,57 @@
4 4
 #include <QWidget>
5 5
 #include <QMap>
6 6
 #include <QRgb>
7
-#include <census.h>
7
+// #include <census.h>
8 8
 #include <country.h>
9 9
 #include <gispoi.h>
10 10
 #include <QVector>
11 11
 #include <QPair>
12 12
 
13
+/// This is the actual widget in charge of drawing the map
14
+
15
+
13 16
 class Map : public QWidget
14 17
 {
15 18
     Q_OBJECT
16 19
 public:
20
+    /// \fn Map(QWidget *parent = 0);
21
+    /// \~English
22
+    /// \brief default constructor
23
+    /// \~Spanish
24
+    /// \brief constructor por defecto
25
+    ///
17 26
     explicit Map(QWidget *parent = 0);
18
-    void setColorMap(QMap<QString,QRgb> *colorMap) {cityColorMap = colorMap;}
19
-    void drawPoints(GISPOI *v, unsigned int size) {gisLocations = v; numLocations = size;}
20
-    void setDrawRoutes(bool r) {drawRoutes = r;}
21
-    void drawLine(const GISPOI &city01, const GISPOI &city02);
27
+
28
+    /// \fn drawPoints(GISPOI *v, unsigned int size);
29
+    /// \~English 
30
+    /// \brief sets the array of GIS locations and sets its size
31
+    /// \~Spanish
32
+    /// \brief establece el arreglo de localizaciones de GIS y su tamaño
33
+    ///
34
+    void drawPoints(GISPOI *v, unsigned int size) 
35
+                { gisLocations = v; numLocations = size; }
36
+    
37
+    /// \fn drawLine(const GISPOI &city01, const GISPOI &city02)
38
+    /// \~English
39
+    /// \brief adds a line from city01 to city02
40
+    /// \~Spanish
41
+    /// \brief añade una linea entre los centroides de city01 a city02
42
+    ///
43
+    void drawLine(const GISPOI &city01, const GISPOI &city02) {
44
+        this->cityLines.push_back(
45
+            QPair<const GISPOI *, const GISPOI *> (&city01, &city02));
46
+    }
47
+    
22 48
     ~Map();
23 49
 signals:
24 50
 
25 51
 private:
26
-    Country *myCountry;
52
+    Country            *myCountry;
27 53
     QMap<QString,QRgb> *cityColorMap;
28
-    GISPOI *gisLocations;
54
+    GISPOI             *gisLocations;
55
+    unsigned int       numLocations;
56
+    bool               drawRoutes;
29 57
     QVector < QPair<const GISPOI *,const GISPOI *> > cityLines;
30
-    unsigned int numLocations;
31
-    bool drawRoutes;
32 58
 
33 59
 protected:
34 60
     void paintEvent(QPaintEvent *event);

+ 89
- 0
moc_mainwindow.cpp View File

@@ -0,0 +1,89 @@
1
+/****************************************************************************
2
+** Meta object code from reading C++ file 'mainwindow.h'
3
+**
4
+** Created by: The Qt Meta Object Compiler version 67 (Qt 5.4.0)
5
+**
6
+** WARNING! All changes made in this file will be lost!
7
+*****************************************************************************/
8
+
9
+#include "mainwindow.h"
10
+#include <QtCore/qbytearray.h>
11
+#include <QtCore/qmetatype.h>
12
+#if !defined(Q_MOC_OUTPUT_REVISION)
13
+#error "The header file 'mainwindow.h' doesn't include <QObject>."
14
+#elif Q_MOC_OUTPUT_REVISION != 67
15
+#error "This file was generated using the moc from 5.4.0. It"
16
+#error "cannot be used with the include files from this version of Qt."
17
+#error "(The moc has changed too much.)"
18
+#endif
19
+
20
+QT_BEGIN_MOC_NAMESPACE
21
+struct qt_meta_stringdata_MainWindow_t {
22
+    QByteArrayData data[1];
23
+    char stringdata[11];
24
+};
25
+#define QT_MOC_LITERAL(idx, ofs, len) \
26
+    Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER_WITH_OFFSET(len, \
27
+    qptrdiff(offsetof(qt_meta_stringdata_MainWindow_t, stringdata) + ofs \
28
+        - idx * sizeof(QByteArrayData)) \
29
+    )
30
+static const qt_meta_stringdata_MainWindow_t qt_meta_stringdata_MainWindow = {
31
+    {
32
+QT_MOC_LITERAL(0, 0, 10) // "MainWindow"
33
+
34
+    },
35
+    "MainWindow"
36
+};
37
+#undef QT_MOC_LITERAL
38
+
39
+static const uint qt_meta_data_MainWindow[] = {
40
+
41
+ // content:
42
+       7,       // revision
43
+       0,       // classname
44
+       0,    0, // classinfo
45
+       0,    0, // methods
46
+       0,    0, // properties
47
+       0,    0, // enums/sets
48
+       0,    0, // constructors
49
+       0,       // flags
50
+       0,       // signalCount
51
+
52
+       0        // eod
53
+};
54
+
55
+void MainWindow::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void **_a)
56
+{
57
+    Q_UNUSED(_o);
58
+    Q_UNUSED(_id);
59
+    Q_UNUSED(_c);
60
+    Q_UNUSED(_a);
61
+}
62
+
63
+const QMetaObject MainWindow::staticMetaObject = {
64
+    { &QMainWindow::staticMetaObject, qt_meta_stringdata_MainWindow.data,
65
+      qt_meta_data_MainWindow,  qt_static_metacall, Q_NULLPTR, Q_NULLPTR}
66
+};
67
+
68
+
69
+const QMetaObject *MainWindow::metaObject() const
70
+{
71
+    return QObject::d_ptr->metaObject ? QObject::d_ptr->dynamicMetaObject() : &staticMetaObject;
72
+}
73
+
74
+void *MainWindow::qt_metacast(const char *_clname)
75
+{
76
+    if (!_clname) return Q_NULLPTR;
77
+    if (!strcmp(_clname, qt_meta_stringdata_MainWindow.stringdata))
78
+        return static_cast<void*>(const_cast< MainWindow*>(this));
79
+    return QMainWindow::qt_metacast(_clname);
80
+}
81
+
82
+int MainWindow::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
83
+{
84
+    _id = QMainWindow::qt_metacall(_c, _id, _a);
85
+    if (_id < 0)
86
+        return _id;
87
+    return _id;
88
+}
89
+QT_END_MOC_NAMESPACE

+ 89
- 0
moc_map.cpp View File

@@ -0,0 +1,89 @@
1
+/****************************************************************************
2
+** Meta object code from reading C++ file 'map.h'
3
+**
4
+** Created by: The Qt Meta Object Compiler version 67 (Qt 5.4.0)
5
+**
6
+** WARNING! All changes made in this file will be lost!
7
+*****************************************************************************/
8
+
9
+#include "map.h"
10
+#include <QtCore/qbytearray.h>
11
+#include <QtCore/qmetatype.h>
12
+#if !defined(Q_MOC_OUTPUT_REVISION)
13
+#error "The header file 'map.h' doesn't include <QObject>."
14
+#elif Q_MOC_OUTPUT_REVISION != 67
15
+#error "This file was generated using the moc from 5.4.0. It"
16
+#error "cannot be used with the include files from this version of Qt."
17
+#error "(The moc has changed too much.)"
18
+#endif
19
+
20
+QT_BEGIN_MOC_NAMESPACE
21
+struct qt_meta_stringdata_Map_t {
22
+    QByteArrayData data[1];
23
+    char stringdata[4];
24
+};
25
+#define QT_MOC_LITERAL(idx, ofs, len) \
26
+    Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER_WITH_OFFSET(len, \
27
+    qptrdiff(offsetof(qt_meta_stringdata_Map_t, stringdata) + ofs \
28
+        - idx * sizeof(QByteArrayData)) \
29
+    )
30
+static const qt_meta_stringdata_Map_t qt_meta_stringdata_Map = {
31
+    {
32
+QT_MOC_LITERAL(0, 0, 3) // "Map"
33
+
34
+    },
35
+    "Map"
36
+};
37
+#undef QT_MOC_LITERAL
38
+
39
+static const uint qt_meta_data_Map[] = {
40
+
41
+ // content:
42
+       7,       // revision
43
+       0,       // classname
44
+       0,    0, // classinfo
45
+       0,    0, // methods
46
+       0,    0, // properties
47
+       0,    0, // enums/sets
48
+       0,    0, // constructors
49
+       0,       // flags
50
+       0,       // signalCount
51
+
52
+       0        // eod
53
+};
54
+
55
+void Map::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void **_a)
56
+{
57
+    Q_UNUSED(_o);
58
+    Q_UNUSED(_id);
59
+    Q_UNUSED(_c);
60
+    Q_UNUSED(_a);
61
+}
62
+
63
+const QMetaObject Map::staticMetaObject = {
64
+    { &QWidget::staticMetaObject, qt_meta_stringdata_Map.data,
65
+      qt_meta_data_Map,  qt_static_metacall, Q_NULLPTR, Q_NULLPTR}
66
+};
67
+
68
+
69
+const QMetaObject *Map::metaObject() const
70
+{
71
+    return QObject::d_ptr->metaObject ? QObject::d_ptr->dynamicMetaObject() : &staticMetaObject;
72
+}
73
+
74
+void *Map::qt_metacast(const char *_clname)
75
+{
76
+    if (!_clname) return Q_NULLPTR;
77
+    if (!strcmp(_clname, qt_meta_stringdata_Map.stringdata))
78
+        return static_cast<void*>(const_cast< Map*>(this));
79
+    return QWidget::qt_metacast(_clname);
80
+}
81
+
82
+int Map::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
83
+{
84
+    _id = QWidget::qt_metacall(_c, _id, _a);
85
+    if (_id < 0)
86
+        return _id;
87
+    return _id;
88
+}
89
+QT_END_MOC_NAMESPACE

+ 1171448
- 0
qrc_prmap.cpp
File diff suppressed because it is too large
View File


+ 69
- 0
ui_mainwindow.h View File

@@ -0,0 +1,69 @@
1
+/********************************************************************************
2
+** Form generated from reading UI file 'mainwindow.ui'
3
+**
4
+** Created by: Qt User Interface Compiler version 5.4.0
5
+**
6
+** WARNING! All changes made in this file will be lost when recompiling UI file!
7
+********************************************************************************/
8
+
9
+#ifndef UI_MAINWINDOW_H
10
+#define UI_MAINWINDOW_H
11
+
12
+#include <QtCore/QVariant>
13
+#include <QtWidgets/QAction>
14
+#include <QtWidgets/QApplication>
15
+#include <QtWidgets/QButtonGroup>
16
+#include <QtWidgets/QHeaderView>
17
+#include <QtWidgets/QMainWindow>
18
+#include <QtWidgets/QMenuBar>
19
+#include <QtWidgets/QStatusBar>
20
+#include <QtWidgets/QToolBar>
21
+#include <QtWidgets/QWidget>
22
+
23
+QT_BEGIN_NAMESPACE
24
+
25
+class Ui_MainWindow
26
+{
27
+public:
28
+    QMenuBar *menuBar;
29
+    QToolBar *mainToolBar;
30
+    QWidget *centralWidget;
31
+    QStatusBar *statusBar;
32
+
33
+    void setupUi(QMainWindow *MainWindow)
34
+    {
35
+        if (MainWindow->objectName().isEmpty())
36
+            MainWindow->setObjectName(QStringLiteral("MainWindow"));
37
+        MainWindow->resize(400, 300);
38
+        menuBar = new QMenuBar(MainWindow);
39
+        menuBar->setObjectName(QStringLiteral("menuBar"));
40
+        MainWindow->setMenuBar(menuBar);
41
+        mainToolBar = new QToolBar(MainWindow);
42
+        mainToolBar->setObjectName(QStringLiteral("mainToolBar"));
43
+        MainWindow->addToolBar(mainToolBar);
44
+        centralWidget = new QWidget(MainWindow);
45
+        centralWidget->setObjectName(QStringLiteral("centralWidget"));
46
+        MainWindow->setCentralWidget(centralWidget);
47
+        statusBar = new QStatusBar(MainWindow);
48
+        statusBar->setObjectName(QStringLiteral("statusBar"));
49
+        MainWindow->setStatusBar(statusBar);
50
+
51
+        retranslateUi(MainWindow);
52
+
53
+        QMetaObject::connectSlotsByName(MainWindow);
54
+    } // setupUi
55
+
56
+    void retranslateUi(QMainWindow *MainWindow)
57
+    {
58
+        MainWindow->setWindowTitle(QApplication::translate("MainWindow", "MainWindow", 0));
59
+    } // retranslateUi
60
+
61
+};
62
+
63
+namespace Ui {
64
+    class MainWindow: public Ui_MainWindow {};
65
+} // namespace Ui
66
+
67
+QT_END_NAMESPACE
68
+
69
+#endif // UI_MAINWINDOW_H