Browse Source

Removed the doublePoint class, using QPointF

Rafael Arce Nazario 9 years ago
parent
commit
2f661ce6d3
10 changed files with 27 additions and 64 deletions
  1. 1
    1
      city.cpp
  2. 4
    4
      city.h
  3. 11
    11
      country.cpp
  4. 1
    1
      country.h
  5. 0
    3
      doublepoint.cpp
  6. 0
    32
      doublepoint.h
  7. 1
    1
      gispoi.h
  8. 1
    1
      mainwindow.cpp
  9. 8
    8
      map.cpp
  10. 0
    2
      prMap.pro

+ 1
- 1
city.cpp View File

@@ -1,6 +1,6 @@
1 1
 #include "city.h"
2 2
 
3 3
 void City::pushPoint(double x, double y) {
4
-    geometry->push_back(DoublePoint(x,y));
4
+    geometry->push_back(QPointF(x,y));
5 5
 
6 6
 }

+ 4
- 4
city.h View File

@@ -1,7 +1,7 @@
1 1
 #ifndef CITY_H
2 2
 #define CITY_H
3 3
 
4
-#include <doublepoint.h>
4
+#include <QPointF>
5 5
 #include <QVector>
6 6
 
7 7
 ///
@@ -11,7 +11,7 @@
11 11
 
12 12
 class City {
13 13
 public:
14
-    QVector<DoublePoint> *geometry;
14
+    QVector<QPointF> *geometry;
15 15
     
16 16
     /// \fn City()
17 17
     /// \~English
@@ -37,13 +37,13 @@ public:
37 37
     ///
38 38
     virtual int getSize() const { return geometry->size(); }
39 39
 
40
-    /// \fn QVector<DoublePoint> *getGeometry()
40
+    /// \fn QVector<QPointF> *getGeometry()
41 41
     /// \~English
42 42
     /// \brief get a pointer to the vector of points
43 43
     /// \~Spanish
44 44
     /// \brief devuelve un puntero al vector de puntos
45 45
     ///
46
-    QVector<DoublePoint> *getGeometry() const { return geometry; }
46
+    QVector<QPointF> *getGeometry() const { return geometry; }
47 47
     
48 48
 
49 49
     /// \fn ~City()

+ 11
- 11
country.cpp View File

@@ -8,19 +8,19 @@
8 8
 void Country::limits(){
9 9
     QMap<QString,City*>::iterator it = Cities.begin();
10 10
 
11
-    minX = maxX = Cities.begin().value()->geometry->at(0).x;
12
-    minY = maxY = Cities.begin().value()->geometry->at(0).y;
11
+    minX = maxX = Cities.begin().value()->geometry->at(0).x();
12
+    minY = maxY = Cities.begin().value()->geometry->at(0).y();
13 13
 
14 14
     for (it = Cities.begin() + 1; it != Cities.end(); ++it) {
15 15
 
16 16
         City *c = it.value();
17 17
 
18 18
         for (int i = 0; i < c->getSize(); i++) {
19
-            if (c->geometry->at(i).x != 0.0) {
20
-            if (c->geometry->at(i).x > maxX ) maxX = c->geometry->at(i).x;
21
-            if (c->geometry->at(i).y > maxY ) maxY = c->geometry->at(i).y;
22
-            if (c->geometry->at(i).x < minX ) minX = c->geometry->at(i).x;
23
-            if (c->geometry->at(i).y < minY ) minY = c->geometry->at(i).y;
19
+            if (c->geometry->at(i).x() != 0.0) {
20
+            if (c->geometry->at(i).x() > maxX ) maxX = c->geometry->at(i).x();
21
+            if (c->geometry->at(i).y() > maxY ) maxY = c->geometry->at(i).y();
22
+            if (c->geometry->at(i).x() < minX ) minX = c->geometry->at(i).x();
23
+            if (c->geometry->at(i).y() < minY ) minY = c->geometry->at(i).y();
24 24
             }
25 25
         }
26 26
     }
@@ -43,12 +43,12 @@ bool Country::readInfoFromJSON(const QString &fileName) {
43 43
 
44 44
     int ctr = 1;
45 45
     foreach(QJsonValue obj, topLevelArray) {
46
-        QVector<DoublePoint> *points = new QVector<DoublePoint>;
46
+        QVector<QPointF> *points = new QVector<QPointF>;
47 47
         QJsonArray geometryArray = obj.toObject()["geometry"].toObject()["coordinates"].toArray();
48 48
         QString polyType = obj.toObject()["geometry"].toObject()["type"].toString();
49 49
         if (polyType == "Polygon") {
50 50
             for (int i = 0; i < geometryArray[0].toArray().size(); i++) {
51
-                points->push_back(DoublePoint(
51
+                points->push_back(QPointF(
52 52
                                 geometryArray[0].toArray()[i].toArray()[0].toDouble(),
53 53
                                 geometryArray[0].toArray()[i].toArray()[1].toDouble()));
54 54
             }
@@ -58,13 +58,13 @@ bool Country::readInfoFromJSON(const QString &fileName) {
58 58
             for (int i = 0; i <geometryArray.size() ; i++) {
59 59
                 // for every point in the city's polygon
60 60
                 for (int j = 0; j < geometryArray[i].toArray()[0].toArray().size(); j++) {
61
-                    points->push_back(DoublePoint(
61
+                    points->push_back(QPointF(
62 62
                                           geometryArray[i].toArray()[0].toArray()[j].toArray()[0].toDouble(),
63 63
                                           geometryArray[i].toArray()[0].toArray()[j].toArray()[1].toDouble()));
64 64
 
65 65
                 }
66 66
                 // I will push a 0,0 between each polygon of a multipolygon to distinguish
67
-                points->push_back(DoublePoint(0,0));
67
+                points->push_back(QPointF(0,0));
68 68
             }
69 69
         }
70 70
 

+ 1
- 1
country.h View File

@@ -1,7 +1,7 @@
1 1
 #ifndef COUNTRY_H
2 2
 #define COUNTRY_H
3 3
 
4
-#include <doublepoint.h>
4
+#include <QPointF>
5 5
 #include <city.h>
6 6
 #include <QMap>
7 7
 

+ 0
- 3
doublepoint.cpp View File

@@ -1,3 +0,0 @@
1
-#include "doublepoint.h"
2
-
3
-

+ 0
- 32
doublepoint.h View File

@@ -1,32 +0,0 @@
1
-#ifndef DOUBLEPOINT_H
2
-#define DOUBLEPOINT_H
3
-
4
-/// \brief A class to display to represent a point in the x,y plane.
5
-
6
-class DoublePoint {
7
-public:
8
-    double x, y;
9
-
10
-    /// \fn DoublePoint()
11
-    /// \~English
12
-    /// \brief default constructor
13
-    /// \~Spanish
14
-    /// \brief constructor por defecto
15
-    ///
16
-    DoublePoint() {x = 0; y = 0;}
17
-
18
-
19
-    /// \fn DoublePoint(double xp, double yp)
20
-    /// \~English
21
-    /// \brief constructor that sets the coordinates
22
-    /// \param xp value for x
23
-    /// \param yp value for y
24
-    /// \~Spanish
25
-    /// \brief constructor que setea las coordenadas
26
-    /// \param xp valor para coordenada x
27
-    /// \param yp valor para coordenada y
28
-    ///
29
-    DoublePoint(double xp, double yp) { x = xp; y = yp; }
30
-};
31
-
32
-#endif // DOUBLEPOINT_H

+ 1
- 1
gispoi.h View File

@@ -4,7 +4,7 @@
4 4
 #include <iostream>
5 5
 #include <QDebug>
6 6
 #include <cmath>
7
-#include "doublepoint.h"
7
+#include <QPointF>
8 8
 using namespace std;
9 9
 
10 10
 const double EARTH_RADIUS =  6372.8;

+ 1
- 1
mainwindow.cpp View File

@@ -15,7 +15,7 @@
15 15
 #include <QPolygon>
16 16
 #include <city.h>
17 17
 #include <country.h>
18
-#include <doublepoint.h>
18
+#include <QPointF>
19 19
 #include <gispoi.h>
20 20
 
21 21
 using namespace std;

+ 8
- 8
map.cpp View File

@@ -94,11 +94,11 @@ void Map::paintEvent(QPaintEvent *) {
94 94
         City *c = it.value();
95 95
 
96 96
         int x1 ,y1, x2, y2;
97
-        x1 = factorX * (c->getGeometry()->at(0).x - myCountry->minX);
98
-        y1 = height() - factorY*(c->getGeometry()->at(0).y - myCountry->minY)  ;
97
+        x1 = factorX * (c->getGeometry()->at(0).x() - myCountry->minX);
98
+        y1 = height() - factorY*(c->getGeometry()->at(0).y() - myCountry->minY)  ;
99 99
 
100
-        DoublePoint p1 = c->getGeometry()->at(0);
101
-        DoublePoint p2;
100
+        QPointF p1 = c->getGeometry()->at(0);
101
+        QPointF p2;
102 102
         int ctr = 0;
103 103
 
104 104
         QPoint *qp = qpA[cityCounter];
@@ -116,16 +116,16 @@ void Map::paintEvent(QPaintEvent *) {
116 116
         for(int i = 0; i < c->getSize() + 1; i++) {
117 117
             p2 = c->getGeometry()->at((i+1)%c->getSize());
118 118
 
119
-            x2 = factorX * (p2.x - myCountry->minX);
120
-            y2 = height() - factorY*(p2.y - myCountry->minY)  ;
119
+            x2 = factorX * (p2.x() - myCountry->minX);
120
+            y2 = height() - factorY*(p2.y() - myCountry->minY)  ;
121 121
 
122
-            if (p2.x != 0 && p1.x != 0) {
122
+            if (p2.x() != 0 && p1.x() != 0) {
123 123
                 qp->setX(x2);
124 124
                 qp->setY(y2);
125 125
                 ctr++;
126 126
                 qp++;
127 127
             }
128
-            else if (p2.x == 0) {
128
+            else if (p2.x() == 0) {
129 129
                 QPolygon yourPoly;
130 130
                 for (int i = 0; i < ctr; i++) yourPoly.push_back(qpBegin[i]);
131 131
                 QPainterPath tmpPath;

+ 0
- 2
prMap.pro View File

@@ -17,14 +17,12 @@ SOURCES += main.cpp\
17 17
         mainwindow.cpp \
18 18
     city.cpp \
19 19
     country.cpp \
20
-    doublepoint.cpp \
21 20
     map.cpp \
22 21
     gispoi.cpp
23 22
 
24 23
 HEADERS  += mainwindow.h \
25 24
     city.h \
26 25
     country.h \
27
-    doublepoint.h \
28 26
     map.h \
29 27
     gispoi.h
30 28