- Allow user to use undo, to clear, save and load drawn maps
- Fix a couple of bugs related to those operations
--- a/QTfrontend/drawmapwidget.cpp Mon Dec 20 20:55:45 2010 +0300
+++ b/QTfrontend/drawmapwidget.cpp Mon Dec 20 21:45:10 2010 +0300
@@ -1,4 +1,5 @@
#include <QFile>
+#include <QMessageBox>
#include "drawmapwidget.h"
@@ -31,6 +32,7 @@
void DrawMapWidget::setScene(DrawMapScene * scene)
{
ui->graphicsView->setScene(scene);
+ m_scene = scene;
}
void DrawMapWidget::resizeEvent(QResizeEvent * event)
@@ -55,15 +57,31 @@
void DrawMapWidget::clear()
{
- if(m_scene) m_scene->clear();
+ if(m_scene) m_scene->clearMap();
}
void DrawMapWidget::save(const QString & fileName)
{
- Q_UNUSED(fileName);
+ if(m_scene)
+ {
+ QFile file(fileName);
+
+ if(!file.open(QIODevice::WriteOnly))
+ QMessageBox::warning(this, tr("File error"), tr("Cannot open file '%1' for writing").arg(fileName));
+ else
+ file.write(qCompress(m_scene->encode()).toBase64());
+ }
}
void DrawMapWidget::load(const QString & fileName)
{
- Q_UNUSED(fileName);
+ if(m_scene)
+ {
+ QFile f(fileName);
+
+ if(!f.open(QIODevice::ReadOnly))
+ QMessageBox::warning(this, tr("File error"), tr("Cannot read file '%1'").arg(fileName));
+ else
+ m_scene->decode(qUncompress(QByteArray::fromBase64(f.readAll())));
+ }
}
--- a/QTfrontend/pages.cpp Mon Dec 20 20:55:45 2010 +0300
+++ b/QTfrontend/pages.cpp Mon Dec 20 21:45:10 2010 +0300
@@ -40,6 +40,7 @@
#include <QDataWidgetMapper>
#include <QTime>
#include <QSlider>
+#include <QFileDialog>
#include "ammoSchemeModel.h"
#include "pages.h"
@@ -2017,8 +2018,34 @@
{
QGridLayout * pageLayout = new QGridLayout(this);
- BtnBack = addButton(":/res/Exit.png", pageLayout, 1, 0, true);
+ QPushButton * pbUndo = addButton(tr("Undo"), pageLayout, 0, 0);
+ QPushButton * pbClear = addButton(tr("Clear"), pageLayout, 1, 0);
+ QPushButton * pbLoad = addButton(tr("Load"), pageLayout, 2, 0);
+ QPushButton * pbSave = addButton(tr("Save"), pageLayout, 3, 0);
+
+ BtnBack = addButton(":/res/Exit.png", pageLayout, 5, 0, true);
drawMapWidget = new DrawMapWidget(this);
- pageLayout->addWidget(drawMapWidget, 0, 0, 1, 2);
+ pageLayout->addWidget(drawMapWidget, 0, 1, 5, 1);
+
+ connect(pbUndo, SIGNAL(clicked()), drawMapWidget, SLOT(undo()));
+ connect(pbClear, SIGNAL(clicked()), drawMapWidget, SLOT(clear()));
+ connect(pbLoad, SIGNAL(clicked()), this, SLOT(load()));
+ connect(pbSave, SIGNAL(clicked()), this, SLOT(save()));
}
+
+void PageDrawMap::load()
+{
+ QString fileName = QFileDialog::getOpenFileName(this, tr("Load drawn map"), ".", tr("Drawn Maps (*.hwmap);;All files (*.*)"));
+
+ if(!fileName.isEmpty())
+ drawMapWidget->load(fileName);
+}
+
+void PageDrawMap::save()
+{
+ QString fileName = QFileDialog::getSaveFileName(this, tr("Save drawn map"), ".", tr("Drawn Maps (*.hwmap);;All files (*.*)"));
+
+ if(!fileName.isEmpty())
+ drawMapWidget->save(fileName);
+}
--- a/QTfrontend/pages.h Mon Dec 20 20:55:45 2010 +0300
+++ b/QTfrontend/pages.h Mon Dec 20 21:45:10 2010 +0300
@@ -587,6 +587,10 @@
QPushButton * BtnBack;
DrawMapWidget * drawMapWidget;
+
+private slots:
+ void load();
+ void save();
};
#endif // PAGES_H