forked from fbudin69500/QTGUI
-
Notifications
You must be signed in to change notification settings - Fork 3
/
parse.cpp
95 lines (81 loc) · 3.34 KB
/
parse.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
#include "parse.h"
Parser::Parser( std::string uifileuri , std::string prefix )
{
m_uifileuri = uifileuri ;
m_prefix = prefix.c_str() ;
}
int Parser::parseXML( std::map< std::pair< QString , QString > , QString> & m )
{
/* We'll parse the example.xml */
QFile* file = new QFile(m_uifileuri.data());
/* If we can't open it, let's show an error message. */
if (!file->open(QIODevice::ReadOnly | QIODevice::Text))
{
QString errMsg = file->errorString();
QFile::FileError err = QFile::NoError; //in Qt5, replace QFile by QFileDevice
err = file->error();
qDebug() << err;
return 1;
}
/* QXmlStreamReader takes any QIODevice. */
QXmlStreamReader xml(file);
/* We'll parse the XML until we reach end of it.*/
while(!xml.atEnd() && !xml.hasError())
{
QXmlStreamReader::TokenType token = xml.readNext(); // Read next element
if(token == QXmlStreamReader::StartDocument)
{ //If token is just StartDocument, we'll go to next
continue;
}
else if (xml.qualifiedName() == "widget" && xml.isEndElement() != true)
{
QString widgetType = xml.attributes().value("", "class").toString() ;
QString widgetName = xml.attributes().value("", "name").toString() ;
if( !widgetName.startsWith( m_prefix ) )
{
continue ;
}
if (widgetType.compare("QTextEdit") == 0
|| widgetType.compare("QComboBox") == 0
|| widgetType.compare("QLineEdit") == 0)
{
m[std::make_pair(widgetType, widgetName)] = "QString";
}
else if (widgetType.compare("QCheckBox") == 0
|| widgetType.compare("QRadioButton") == 0)
{
m[std::make_pair(widgetType, widgetName)] = "bool";
}
else if (widgetType.compare("QDoubleSpinBox") == 0)
{
m[std::make_pair(widgetType, widgetName)] = "double";
}
else if (widgetType.compare("QSpinBox") == 0
|| widgetType.compare("QScrollBar") == 0)
{
m[std::make_pair(widgetType, widgetName)] = "int";
}
else if (widgetType.compare("QListWidget") == 0)
{
m[std::make_pair(widgetType, widgetName)] = "std::map<std::pair<unsigned long,QString>,bool>";
}
else if (widgetType.compare("QTableView") == 0)
{
m[std::make_pair(widgetType, widgetName)] = "std::vector<std::vector<QString> >";
}
// Store values into the dictionary
// m[std::make_pair(widgetType, xml.attributes().at(1).value().toString())] = "";
// Print values to the console
}
}
/* Error handling. */
if(xml.hasError())
{
}
/* Removes any device() or data from the reader
* and resets its internal state to the initial state. */
xml.clear();
file->close();
delete file;
return 0;
}