-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypeio.cpp
84 lines (70 loc) · 1.92 KB
/
typeio.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
#include <QDebug>
#include <QFile>
#include "typeio.h"
QMap<int, SingleTypeIO *> TypeIO::m_mapTypeIO;
TypeIO::TypeIO()
{
}
TypeIO::~TypeIO()
{
clear();
}
bool TypeIO::init(const QDomDocument & doc)
{
clear();
// print out the element names of all elements that are direct children
// of the outermost element.
QDomElement docElem = doc.documentElement();
QDomNode n = docElem.firstChild();
while(!n.isNull()) {
QDomElement e = n.toElement(); // try to convert the node to an element.
if(!e.isNull()) {
SingleTypeIO *single = new SingleTypeIO;
single->load(e);
m_mapTypeIO.insert(single->value(), single);
}
n = n.nextSibling();
}
return true;
}
void TypeIO::clear ()
{
/*
while (!m_mapTypeIO.isEmpty())
delete m_mapTypeIO.takeFirst();
*/
QMap<int, SingleTypeIO*>::const_iterator i = m_mapTypeIO.constBegin();
while (i != m_mapTypeIO.constEnd()) {
delete i.value();
++i;
}
m_mapTypeIO.clear();
}
bool TypeIO::init(const QString &nomeFile)
{
QDomDocument doc("mydocument");
QFile file(nomeFile);
if (!file.open(QIODevice::ReadOnly))
{
qDebug() << "File \"" << nomeFile << "\" error: " << file.errorString();
return false;
}
QString errorMessage;
int errorLine;
int errorColumn;
if (!doc.setContent(&file, &errorMessage, &errorLine, &errorColumn)) {
file.close();
qDebug() << "File \"" << nomeFile << " error: " << errorMessage << " in " << errorLine << ":" << errorColumn;
return false;
}
file.close();
return init(doc);
}
bool TypeIO::canChangeTypeIn (const int& left, const int& right)
{
SingleTypeIO *singleLeft = at(left);
SingleTypeIO *singleRight = at(right);
if ((singleLeft == NULL) || (singleRight == NULL))
return false;
return (singleLeft->group() == singleRight->group());
}