Skip to content
Snippets Groups Projects
Commit c24e9666 authored by Juan Manuel Carmona Loaiza's avatar Juan Manuel Carmona Loaiza :ghost:
Browse files

Add a function to open a dialog and save the pic as a png file

parent a5f38257
No related branches found
No related tags found
No related merge requests found
...@@ -12,6 +12,8 @@ ...@@ -12,6 +12,8 @@
// //
// ************************************************************************** // // ************************************************************************** //
#include "AppSvc.h"
#include "projectmanager.h"
#include "RealSpaceCanvas.h" #include "RealSpaceCanvas.h"
#include "RealSpaceBuilder.h" #include "RealSpaceBuilder.h"
#include "RealSpaceModel.h" #include "RealSpaceModel.h"
...@@ -20,8 +22,10 @@ ...@@ -20,8 +22,10 @@
#include "SessionItemUtils.h" #include "SessionItemUtils.h"
#include "WarningSign.h" #include "WarningSign.h"
#include "FilterPropertyProxy.h" #include "FilterPropertyProxy.h"
#include <QFileDialog>
#include <QApplication> #include <QApplication>
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QMessageBox>
RealSpaceCanvas::RealSpaceCanvas(QWidget* parent) RealSpaceCanvas::RealSpaceCanvas(QWidget* parent)
: QWidget(parent), m_sampleModel(nullptr), m_view(new RealSpaceView), m_selectionModel(nullptr), : QWidget(parent), m_sampleModel(nullptr), m_view(new RealSpaceView), m_selectionModel(nullptr),
...@@ -123,10 +127,33 @@ void RealSpaceCanvas::onChangeLayerSizeAction(double layerSizeChangeScale) ...@@ -123,10 +127,33 @@ void RealSpaceCanvas::onChangeLayerSizeAction(double layerSizeChangeScale)
void RealSpaceCanvas::onSavePictureAction() void RealSpaceCanvas::onSavePictureAction()
{ {
QPixmap pixmap(this->size()); QPixmap pixmap(this->size());
this->render(&pixmap, QPoint(), childrenRegion()); render(&pixmap, QPoint(), childrenRegion());
//pixmap.save("path/to/save/file.png"); savePicture(pixmap);
}
void RealSpaceCanvas::savePicture(const QPixmap &pixmap)
{
QString dirname = AppSvc::projectManager()->userExportDir();
QString defaultExtension = ".png";
QString selectedFilter("*"+defaultExtension);
QString defaultName = dirname + QString("/untitled");
QString fileName =QFileDialog::getSaveFileName(nullptr, "Save 3D real space view", defaultName, selectedFilter);
QString nameToSave = fileName.endsWith(defaultExtension) ? fileName : fileName + defaultExtension;
if(!nameToSave.isEmpty()) {
try {
pixmap.save(nameToSave);
} catch(const std::exception &ex) {
QString message = "Attempt to save file with the name '";
message.append(nameToSave);
message.append("' has failed with following error message\n\n");
message.append(QString::fromStdString(ex.what()));
QMessageBox::warning(nullptr, "Houston, we have a problem.", message);
}
}
} }
void RealSpaceCanvas::onDataChanged(const QModelIndex& index) void RealSpaceCanvas::onDataChanged(const QModelIndex& index)
{ {
auto item = m_sampleModel->itemForIndex(index); auto item = m_sampleModel->itemForIndex(index);
......
...@@ -119,6 +119,7 @@ private: ...@@ -119,6 +119,7 @@ private:
bool m_view_locked; bool m_view_locked;
std::unique_ptr<SceneGeometry> m_sceneGeometry; std::unique_ptr<SceneGeometry> m_sceneGeometry;
WarningSign* m_warningSign; WarningSign* m_warningSign;
void savePicture(const QPixmap &pixmap);
}; };
#endif // REALSPACESCENE_H #endif // REALSPACESCENE_H
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment