-
Notifications
You must be signed in to change notification settings - Fork 0
/
iqamesymbol.cpp
166 lines (143 loc) · 4.49 KB
/
iqamesymbol.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#include "iqamesymbol.h"
#include "iqameshapesattributes.h"
#include "iqameapplication.h"
#include <QRegExp>
#include <QDebug>
#include "iqameapplication.h"
IqAmeSymbol::IqAmeSymbol(QObject *parent) :
IqAmeNamedShapeObject(parent),
m_point(Q_NULLPTR),
m_graphicsSymbolItem(Q_NULLPTR)
{
}
IqAmeSymbol::~IqAmeSymbol()
{
if (m_graphicsSymbolItem)
delete m_graphicsSymbolItem;
}
QList<QGraphicsItem *> IqAmeSymbol::graphicsItems()
{
QList<QGraphicsItem *> result;
result << symbolGraphicsItem();
return result;
}
void IqAmeSymbol::updateGraphicsItems()
{
IqAmeSymbolGraphicsItem *symbolItem = symbolGraphicsItem();
Q_CHECK_PTR(symbolItem);
symbolItem->setVisible(visible());
}
IqAmeSymbolGraphicsItem *IqAmeSymbol::symbolGraphicsItem()
{
if (!m_graphicsSymbolItem) {
m_graphicsSymbolItem = new IqAmeSymbolGraphicsItem();
m_graphicsSymbolItem->setSymbol(this);
m_graphicsSymbolItem->setNamedShapeObject(this);
}
return m_graphicsSymbolItem;
}
bool IqAmeSymbol::loadFromString(const QString &string)
{
QRegExp textRx("^\\s*(SYMP|S)\\s*:\\s*(\\*([^\\*]*)\\*){0,1}");
textRx.setCaseSensitivity(Qt::CaseInsensitive);
if (textRx.indexIn(string) == -1)
return false;
setName(textRx.cap(3));
//Получим оставшуюся строку
QString clearString = string.mid(textRx.matchedLength());
//Выделим комментарий
QRegExp commentRx("\\*([^\\*]*)\\*\\W*$");
if (commentRx.indexIn(clearString) != -1)
setComment(commentRx.cap(1));
//Удалим все комментарии из строки
QRegExp extraCommentsRx("\\*[^\\*]*\\*");
clearString.remove(extraCommentsRx);
//Выделим тип символа
QRegExp symbolType("^\"(\\d+)\"(.*)");
if (symbolType.indexIn(clearString.trimmed()) == -1)
return false;
switch (symbolType.cap(1).toInt()) {
case 1:
setType(PointRequedReport);
break;
case 2:
setType(PointRequestReport);
break;
case 3:
setType(Ndb);
break;
case 4:
setType(ArtificalObstaclesWithouLight);
break;
case 6:
setType(VorDme);
break;
case 7:
setType(CivilAirport);
break;
case 8:
setType(MixedAirport);
break;
case 9:
setType(MilitaryAirport);
break;
default:
qWarning() << tr("Symbol type \"%0\" not know. Symbol element skipped...")
.arg(symbolType.cap(1));
return false;
}
clearString = symbolType.cap(2).trimmed();
QString symbolString = clearString.trimmed();
//Выделим атрибуты
QRegExp attributeRx("(<\\s*[^>]*\\s*>)(.*)");
attributeRx.setCaseSensitivity(Qt::CaseInsensitive);
if (attributeRx.indexIn(clearString) != -1) {
//Нашли атрибуты, создадим их
if (!attributes()) {
setAttributes(new IqAmeShapesAttributes(this));
}
attributes()->loadFromString(attributeRx.cap(1));
symbolString = attributeRx.cap(2).trimmed();
}
QString pName = symbolString;
if (!pName.isEmpty()) {
IqAmeGeoPoint *p = IqAmeApplication::aeroMapModel()->pointsModel()->point(pName.trimmed(), Qt::CaseInsensitive);
if (!p) {
//Если не нашли точку, то попробуем ее создать
IqAmeGeoPoint newPoint;
if (newPoint.fromCoordinate(pName)) {
int newPointRow = IqAmeApplication::aeroMapModel()->pointsModel()->rowCount();
IqAmeApplication::aeroMapModel()->pointsModel()->insertRow(newPointRow);
p = IqAmeApplication::aeroMapModel()->pointsModel()->at(newPointRow);
p->setName(newPoint.name());
p->setLatitude(newPoint.latitude());
p->setLongitude(newPoint.longitude());
} else {
qWarning() << tr("Point \"%0\" not found and can not create. Symbol element skipped...").arg(pName);
return false;
}
}
setPoint(p);
return true;
}
return false;
}
IqAmeSymbol::Type IqAmeSymbol::type() const
{
return m_type;
}
void IqAmeSymbol::setType(const Type &type)
{
m_type = type;
}
IqAmeGeoPoint *IqAmeSymbol::point() const
{
return m_point;
}
void IqAmeSymbol::setPoint(IqAmeGeoPoint *geoPoint)
{
if (m_point != geoPoint) {
m_point = geoPoint;
emit pointChanged();
}
}