Skip to content

Commit

Permalink
GraphPanel widget: can now export a graph panel to various formats (e…
Browse files Browse the repository at this point in the history
….g. PDF, SVG) (#1123).
  • Loading branch information
agarny committed Sep 26, 2017
1 parent bb0eba8 commit de6a208
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/plugins/miscellaneous/Core/src/coreguiutils.cpp
Expand Up @@ -289,6 +289,16 @@ QString getSaveFileName(const QString &pCaption, const QString &pFileName,

//==============================================================================

QString getSaveFileName(const QString &pCaption, const QStringList &pFilters,
QString *pSelectedFilter)
{
// Retrieve and return a save file name

return getSaveFileName(pCaption, QString(), pFilters, pSelectedFilter);
}

//==============================================================================

QString getDirectory(const QString &pCaption, const QString &pDirName,
const bool &pEmptyDir)
{
Expand Down
3 changes: 3 additions & 0 deletions src/plugins/miscellaneous/Core/src/coreguiutils.h
Expand Up @@ -106,6 +106,9 @@ QString CORE_EXPORT getSaveFileName(const QString &pCaption,
const QString &pFileName,
const QStringList &pFilters = QStringList(),
QString *pSelectedFilter = 0);
QString CORE_EXPORT getSaveFileName(const QString &pCaption,
const QStringList &pFilters = QStringList(),
QString *pSelectedFilter = 0);

QString CORE_EXPORT getDirectory(const QString &pCaption,
const QString &pDirName = QString(),
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/widget/GraphPanelWidget/CMakeLists.txt
Expand Up @@ -23,4 +23,6 @@ ADD_PLUGIN(GraphPanelWidget
PLUGINS
Core
Qwt
QT_MODULES
PrintSupport
)
44 changes: 44 additions & 0 deletions src/plugins/widget/GraphPanelWidget/i18n/GraphPanelWidget_fr.ts
Expand Up @@ -90,6 +90,50 @@
<source>Reset the zoom level of the graph panel</source>
<translation>Réinitialiser la taille du panneau graphique</translation>
</message>
<message>
<source>PDF File - Portable Document Format (*.pdf)</source>
<translation>Fichier PDF - Portable Document Format (*.pdf)</translation>
</message>
<message>
<source>SVG File - Scalable Vector Graphics (*.svg)</source>
<translation>Fichier SVG - Scalable Vector Graphics (*.svg)</translation>
</message>
<message>
<source>BMP File - Windows Bitmap (*.bmp)</source>
<translation>Fichier BMP - Windows Bitmap (*.bmp)</translation>
</message>
<message>
<source>JPEG File - Joint Photographic Experts Group (*.jpg)</source>
<translation>Fichier JPEG - Joint Photographic Experts Group (*.jpg)</translation>
</message>
<message>
<source>PNG File - Portable Network Graphics (*.png)</source>
<translation>Fichier PNG - Portable Network Graphics (*.png)</translation>
</message>
<message>
<source>PBM File - Portable Bitmap (*.pbm)</source>
<translation>Fichier PBM - Portable Bitmap (*.pbm)</translation>
</message>
<message>
<source>PGM File - Portable Graymap (*.pgm)</source>
<translation>Fichier PGM - Portable Graymap (*.pgm)</translation>
</message>
<message>
<source>PPM File - Portable Pixmap (*.ppm)</source>
<translation>Fichier PPM - Portable Pixmap (*.ppm)</translation>
</message>
<message>
<source>XBM File - X11 Bitmap (*.xbm)</source>
<translation>Fichier XBM - X11 Bitmap (*.xbm)</translation>
</message>
<message>
<source>XPM File - X11 Pixmap (*.xpm)</source>
<translation>Fichier XPM - X11 Pixmap (*.xpm)</translation>
</message>
<message>
<source>Save As</source>
<translation>Sauvegarder Sous</translation>
</message>
</context>
<context>
<name>OpenCOR::GraphPanelWidget::GraphPanelWidgetCustomAxesDialog</name>
Expand Down
41 changes: 40 additions & 1 deletion src/plugins/widget/GraphPanelWidget/src/graphpanelplotwidget.cpp
Expand Up @@ -31,6 +31,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <QApplication>
#include <QClipboard>
#include <QDesktopWidget>
#include <QFileDialog>
#include <QImageWriter>
#include <QMenu>
#include <QPaintEvent>

Expand All @@ -46,6 +48,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "qwt_plot_directpainter.h"
#include "qwt_plot_grid.h"
#include "qwt_plot_layout.h"
#include "qwt_plot_renderer.h"
#include "qwt_scale_engine.h"
#include "qwt_scale_widget.h"
#include "qwtend.h"
Expand Down Expand Up @@ -1725,7 +1728,43 @@ void GraphPanelPlotWidget::cannotUpdateActions()

void GraphPanelPlotWidget::saveAs()
{
//---ISSUE1123--- TO BE DONE...
// Save our contents as a PDF, SVG, etc. file
// Note: if no file extension is given, then we save our contents as a PDF
// file...

QString pdfFilter = tr("PDF File - Portable Document Format (*.pdf)");
QStringList filters = QStringList() << pdfFilter
<< tr("SVG File - Scalable Vector Graphics (*.svg)");

foreach (const QString &supportedMimeType, QImageWriter::supportedMimeTypes()) {
if (!supportedMimeType.compare("image/bmp"))
filters << tr("BMP File - Windows Bitmap (*.bmp)");
else if (!supportedMimeType.compare("image/jpeg"))
filters << tr("JPEG File - Joint Photographic Experts Group (*.jpg)");
else if (!supportedMimeType.compare("image/png"))
filters << tr("PNG File - Portable Network Graphics (*.png)");
else if (!supportedMimeType.compare("image/x-portable-bitmap"))
filters << tr("PBM File - Portable Bitmap (*.pbm)");
else if (!supportedMimeType.compare("image/x-portable-graymap"))
filters << tr("PGM File - Portable Graymap (*.pgm)");
else if (!supportedMimeType.compare("image/x-portable-pixmap"))
filters << tr("PPM File - Portable Pixmap (*.ppm)");
else if (!supportedMimeType.compare("image/x-xbitmap"))
filters << tr("XBM File - X11 Bitmap (*.xbm)");
else if (!supportedMimeType.compare("image/x-xpixmap"))
filters << tr("XPM File - X11 Pixmap (*.xpm)");
}

std::sort(filters.begin(), filters.end());

QString fileName = Core::getSaveFileName(tr("Save As"), filters, &pdfFilter);

if (!fileName.isEmpty()) {
if (QFileInfo(fileName).completeSuffix().isEmpty())
QwtPlotRenderer().renderDocument(this, fileName, "pdf", QSizeF(width(), height()));
else
QwtPlotRenderer().renderDocument(this, fileName, QSizeF(width(), height()));
}
}

//==============================================================================
Expand Down

0 comments on commit de6a208

Please sign in to comment.