relToY = ctrl->valueToRel(dlg.toY());
ImageDrawer imageDrawer(ctrl);
- drwRet = imageDrawer.render(dlg.path() + "." + dlg.imageFormat(), dlg.imageFormat().toLatin1(), dlg.imageWidth(), dlg.imageHeight(),
+ drwRet = imageDrawer.render(dlg.path(), dlg.imageFormat().toLatin1(), dlg.imageWidth(), dlg.imageHeight(),
relFromX, relFromY, relToX, relToY, gl);
switch (drwRet) {
case ImageDrawer::ReturnCode::SUCCESS:
ImageDrawer::ReturnCode ImageDrawer::render(const QString& filename, const QByteArray format, const int width, const int height,
const double fromX, const double fromY, const double toX, const double toY, const GraphLayers layers)
{
+ QString formatSuffix(format);
+ QString augFilename;
QImage image;
- QFile file(filename);
+ int dotIdx;
if (m_controller == nullptr)
return ReturnCode::E_NO_CONTROLLER;
if (!draw(fromX, fromY, toX, toY, layers))
return ReturnCode::E_CANNOT_DRAW;
- m_imageWriter.setFileName(filename);
+ /* Check the extension */
+ dotIdx = filename.lastIndexOf('.');
+ if (dotIdx > 0) {
+ QString realSuffix = filename.mid(dotIdx+1);
+ if (realSuffix.compare(QString(formatSuffix)) != 0)
+ augFilename = filename + "." + formatSuffix;
+ else
+ augFilename = filename;
+ } else
+ augFilename = filename + "." + formatSuffix;
+
+ m_imageWriter.setFileName(augFilename);
m_imageWriter.setFormat(format);
image = m_pixmap->toImage();
if (image.isNull())
return ReturnCode::E_CANNOT_CREATE_IMAGE;
+ QFile file(augFilename);
if (file.exists()) {
int ret = QMessageBox::question(nullptr, "Data export", "The selected file already exists. Do you wish to overwrite it?");
if (ret == QMessageBox::No)