From 867e8727c15d229f53a42a43934e2a47db1c6db9 Mon Sep 17 00:00:00 2001 From: matlabbe Date: Sun, 5 Mar 2017 11:55:22 -0500 Subject: [PATCH] GraphViewer: Fixed scale of saved PNG/SVG --- guilib/src/DatabaseViewer.cpp | 1 + guilib/src/GraphViewer.cpp | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/guilib/src/DatabaseViewer.cpp b/guilib/src/DatabaseViewer.cpp index 9f3bed2c..b0754939 100644 --- a/guilib/src/DatabaseViewer.cpp +++ b/guilib/src/DatabaseViewer.cpp @@ -594,6 +594,7 @@ bool DatabaseViewer::openDatabase(const QString & path) { pathDatabase_ = UDirectory::getDir(path.toStdString()).c_str(); databaseFileName_ = UFile::getName(path.toStdString()); + ui_->graphViewer->setWorkingDirectory(pathDatabase_); // look if there are saved parameters ParametersMap parameters = dbDriver_->getLastParameters(); diff --git a/guilib/src/GraphViewer.cpp b/guilib/src/GraphViewer.cpp index 99ddc8fc..c67d1107 100644 --- a/guilib/src/GraphViewer.cpp +++ b/guilib/src/GraphViewer.cpp @@ -39,6 +39,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include #include #include @@ -1391,7 +1392,7 @@ void GraphViewer::contextMenuEvent(QContextMenuEvent * event) if(_gridCellSize) { - _root->setScale(1.0f/_gridCellSize); // grid map precision (for 5cm grid cell, x20 to have 1pix/5cm) + _root->setScale(1.0f/(_gridCellSize*100.0f)); // grid map precision (for 5cm grid cell, x20 to have 1pix/5cm) } else { @@ -1409,7 +1410,16 @@ void GraphViewer::contextMenuEvent(QContextMenuEvent * event) QPainter painter(&image); this->scene()->render(&painter); - image.save(targetDir + name); + if(!image.isNull()) + { + image.save(targetDir + name); + } + else + { + QMessageBox::warning(this, + tr("Save PNG"), + tr("Could not export in PNG (the scene may be too large %1x%2), try saving in SVG.").arg(sceneSize.width()).arg(sceneSize.height())); + } } else {