From 37abf82fc28d4640bed153bb83b6d6354fc3505a Mon Sep 17 00:00:00 2001 From: Fredrik Arvidsson Date: Mon, 10 Sep 2012 22:37:39 +0200 Subject: [PATCH] OP-39 Added saving as image to the connection diagram dialog. --- .../plugins/setupwizard/connectiondiagram.cpp | 25 ++++-- .../plugins/setupwizard/connectiondiagram.h | 6 +- .../plugins/setupwizard/connectiondiagram.ui | 82 ++++++++++++------- 3 files changed, 74 insertions(+), 39 deletions(-) diff --git a/ground/openpilotgcs/src/plugins/setupwizard/connectiondiagram.cpp b/ground/openpilotgcs/src/plugins/setupwizard/connectiondiagram.cpp index 6ded9bda6..f3dbd2dca 100644 --- a/ground/openpilotgcs/src/plugins/setupwizard/connectiondiagram.cpp +++ b/ground/openpilotgcs/src/plugins/setupwizard/connectiondiagram.cpp @@ -27,6 +27,7 @@ #include #include +#include #include "connectiondiagram.h" #include "ui_connectiondiagram.h" @@ -62,8 +63,8 @@ void ConnectionDiagram::setupGraphicsScene() m_renderer->load(QString(":/setupwizard/resources/connection-diagrams.svg")) && m_renderer->isValid()) { - QGraphicsScene *scene = new QGraphicsScene(this); - ui->connectionDiagram->setScene(scene); + m_scene = new QGraphicsScene(this); + ui->connectionDiagram->setScene(m_scene); //ui->connectionDiagram->setViewportUpdateMode(QGraphicsView::FullViewportUpdate); m_background = new QGraphicsSvgItem(); @@ -72,7 +73,7 @@ void ConnectionDiagram::setupGraphicsScene() m_background->setOpacity(0); //m_background->setFlags(QGraphicsItem::ItemClipsToShape); m_background->setZValue(-1); - scene->addItem(m_background); + m_scene->addItem(m_background); QList elementsToShow; @@ -139,7 +140,7 @@ void ConnectionDiagram::setupGraphicsScene() break; } - setupGraphicsSceneItems(scene, elementsToShow); + setupGraphicsSceneItems(elementsToShow); ui->connectionDiagram->setSceneRect(m_background->boundingRect()); ui->connectionDiagram->fitInView(m_background, Qt::KeepAspectRatio); @@ -148,7 +149,7 @@ void ConnectionDiagram::setupGraphicsScene() } } -void ConnectionDiagram::setupGraphicsSceneItems(QGraphicsScene *scene, QList elementsToShow) +void ConnectionDiagram::setupGraphicsSceneItems(QList elementsToShow) { qreal z = 0; QRectF backgBounds = m_renderer->boundsOnElement("background"); @@ -168,7 +169,7 @@ void ConnectionDiagram::setupGraphicsSceneItems(QGraphicsScene *scene, QListboundsOnElement(elementId); //element->setPos(orig.x() - backgBounds.x(), orig.y() - backgBounds.y()); - scene->addItem(element); + m_scene->addItem(element); qDebug() << "Adding " << elementId << " to scene at " << element->pos(); } else { @@ -177,4 +178,14 @@ void ConnectionDiagram::setupGraphicsSceneItems(QGraphicsScene *scene, QListrender(&painter); + QString fileName = QFileDialog::getSaveFileName(this, tr("Save File"), "", tr("Images (*.png *.xpm *.jpg)")); + if(!fileName.isEmpty()) { + image.save(fileName); + } +} diff --git a/ground/openpilotgcs/src/plugins/setupwizard/connectiondiagram.h b/ground/openpilotgcs/src/plugins/setupwizard/connectiondiagram.h index 2063403a5..e03ed6b0e 100644 --- a/ground/openpilotgcs/src/plugins/setupwizard/connectiondiagram.h +++ b/ground/openpilotgcs/src/plugins/setupwizard/connectiondiagram.h @@ -54,13 +54,17 @@ private: QSvgRenderer *m_renderer; QGraphicsSvgItem* m_background; + QGraphicsScene *m_scene; void setupGraphicsScene(); - void setupGraphicsSceneItems(QGraphicsScene *scene, QList elementsToShow); + void setupGraphicsSceneItems(QList elementsToShow); protected: void resizeEvent(QResizeEvent *event); void showEvent(QShowEvent *event); +private slots: + + void on_saveButton_clicked(); }; #endif // CONNECTIONDIAGRAM_H diff --git a/ground/openpilotgcs/src/plugins/setupwizard/connectiondiagram.ui b/ground/openpilotgcs/src/plugins/setupwizard/connectiondiagram.ui index 690364a6d..7e86a99a2 100644 --- a/ground/openpilotgcs/src/plugins/setupwizard/connectiondiagram.ui +++ b/ground/openpilotgcs/src/plugins/setupwizard/connectiondiagram.ui @@ -43,48 +43,68 @@ - - - Qt::Horizontal - - - QDialogButtonBox::Close|QDialogButtonBox::Save - - + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + Save + + + + + + + + 0 + 0 + + + + Close + + + true + + + + - buttonBox - accepted() + closeButton + clicked() ConnectionDiagram - accept() + close() - 248 - 254 + 752 + 418 - 157 - 274 - - - - - buttonBox - rejected() - ConnectionDiagram - reject() - - - 316 - 260 - - - 286 - 274 + 399 + 219