-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.cpp
72 lines (62 loc) · 2.09 KB
/
mainwindow.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
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QGraphicsItem>
#include <QXmlStreamReader>
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
{
ui->setupUi(this);
mScene = new QGraphicsScene(this);
ui->graphicsView->setScene(mScene);
mFileDialog = new QFileDialog(this);
ui->graphicsView->resize(600, 600);
ui->graphicsView->setRenderHint(QPainter::Antialiasing);
ui->graphicsView->setCacheMode(QGraphicsView::CacheBackground);
ui->graphicsView->setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
mPrintPoints.clear();
mScene->clear();
mScene->setSceneRect(-20, -20, 40, 40);
ui->graphicsView->fitInView(mScene->sceneRect(), Qt::KeepAspectRatio);
auto filePath = mFileDialog->getOpenFileUrl(this,
"Выбирите XML файл",
QApplication::applicationDirPath(),
"XML файл (*.xml)");
ui->lineEdit_fileName->setText(filePath.toString().remove("file:///"));
QFile file(filePath.toString().remove("file:///"));
file.open(QFile::OpenModeFlag::ReadOnly);
auto xmlData = file.readAll();
file.close();
QXmlStreamReader readXml(xmlData);
readXml.readNext();
readXml.readNext();
auto atribs = readXml.attributes();
QStringList atrKeys;
for (int i = 0; i < atribs.size(); ++i) {
atrKeys.push_back(atribs[i].name().toString());
}
auto caption = atribs[atrKeys.indexOf("Caption")].value().toString();
int sizePoint = caption.remove("A").remove(" ").remove("Point").remove("s").toInt();
QPoint point;
readXml.readNext();
for (int i = 0; i < sizePoint && !readXml.atEnd(); ++i, readXml.readNext()) {
foreach (const auto &var, readXml.attributes()) {
if (var.name() == "X")
point.setX(var.value().toDouble());
if (var.name() == "Y")
point.setY(var.value().toDouble());
}
mPrintPoints.push_back(QSharedPointer<QGraphicsEllipseItem>(
new QGraphicsEllipseItem(point.x(), point.y(), 1, 1)));
}
QGraphicsEllipseItem a;
for (auto p : mPrintPoints) {
mScene->addItem(p.get());
}
this->repaint();
}