-
Notifications
You must be signed in to change notification settings - Fork 0
/
puzzleconfig.cpp
45 lines (35 loc) · 953 Bytes
/
puzzleconfig.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
#include "puzzleconfig.h"
#include <QFile>
#include <QTextStream>
// TODO: Error handling
QVector<QPolygonF> PuzzleConfig::getPuzzlePolygons()
{
QVector<QPolygonF> result;
QFile file(":/config.txt");
if (!file.open((QIODevice::ReadOnly | QIODevice::Text)))
return result;
QTextStream in(&file);
while (!in.atEnd())
{
QString line = in.readLine();
QPolygonF polygon;
QRegExp regex("(\\d+)");
QStringList numbersList;
int pos = 0;
while ((pos = regex.indexIn(line, pos)) != -1)
{
numbersList << regex.cap(1);
pos += regex.matchedLength();
}
int i = 0;
while (i < numbersList.size())
{
QPointF point(numbersList[i].toInt(),numbersList[i+1].toInt());
polygon << point;
i += 2;
}
result.push_back(polygon);
}
file.close();
return result;
}