equal
deleted
inserted
replaced
1 #include <QFile> |
1 #include <QFile> |
|
2 #include <QMessageBox> |
2 |
3 |
3 #include "drawmapwidget.h" |
4 #include "drawmapwidget.h" |
4 |
5 |
5 DrawMapWidget::DrawMapWidget(QWidget *parent) : |
6 DrawMapWidget::DrawMapWidget(QWidget *parent) : |
6 QWidget(parent), |
7 QWidget(parent), |
29 } |
30 } |
30 |
31 |
31 void DrawMapWidget::setScene(DrawMapScene * scene) |
32 void DrawMapWidget::setScene(DrawMapScene * scene) |
32 { |
33 { |
33 ui->graphicsView->setScene(scene); |
34 ui->graphicsView->setScene(scene); |
|
35 m_scene = scene; |
34 } |
36 } |
35 |
37 |
36 void DrawMapWidget::resizeEvent(QResizeEvent * event) |
38 void DrawMapWidget::resizeEvent(QResizeEvent * event) |
37 { |
39 { |
38 Q_UNUSED(event); |
40 Q_UNUSED(event); |
53 if(m_scene) m_scene->undo(); |
55 if(m_scene) m_scene->undo(); |
54 } |
56 } |
55 |
57 |
56 void DrawMapWidget::clear() |
58 void DrawMapWidget::clear() |
57 { |
59 { |
58 if(m_scene) m_scene->clear(); |
60 if(m_scene) m_scene->clearMap(); |
59 } |
61 } |
60 |
62 |
61 void DrawMapWidget::save(const QString & fileName) |
63 void DrawMapWidget::save(const QString & fileName) |
62 { |
64 { |
63 Q_UNUSED(fileName); |
65 if(m_scene) |
|
66 { |
|
67 QFile file(fileName); |
|
68 |
|
69 if(!file.open(QIODevice::WriteOnly)) |
|
70 QMessageBox::warning(this, tr("File error"), tr("Cannot open file '%1' for writing").arg(fileName)); |
|
71 else |
|
72 file.write(qCompress(m_scene->encode()).toBase64()); |
|
73 } |
64 } |
74 } |
65 |
75 |
66 void DrawMapWidget::load(const QString & fileName) |
76 void DrawMapWidget::load(const QString & fileName) |
67 { |
77 { |
68 Q_UNUSED(fileName); |
78 if(m_scene) |
|
79 { |
|
80 QFile f(fileName); |
|
81 |
|
82 if(!f.open(QIODevice::ReadOnly)) |
|
83 QMessageBox::warning(this, tr("File error"), tr("Cannot read file '%1'").arg(fileName)); |
|
84 else |
|
85 m_scene->decode(qUncompress(QByteArray::fromBase64(f.readAll()))); |
|
86 } |
69 } |
87 } |