]> Devoid-pointer.net GitWeb - anyanka.git/commitdiff
Handle output file suffix in a sensible manner in ImageDrawer
authorMichal Malý <madcatxster@prifuk.cz>
Sat, 15 Mar 2014 17:47:43 +0000 (18:47 +0100)
committerMichal Malý <madcatxster@prifuk.cz>
Sat, 15 Mar 2014 17:47:43 +0000 (18:47 +0100)
datamanager.cpp
imagedrawer.cpp

index e3fd1617cecb444a5356055f6e2efc543cb0c741..81ed7afee269bc38ed7e9b65988f15544970c837 100644 (file)
@@ -489,7 +489,7 @@ void DataManager::onExportGraphToImage()
       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:
index e7e81256cc3c6e44e1d096b80e312b6d4e3f78f8..af82ad6ef8395f1b5c455fc8a2fe1aa53274f3ad 100644 (file)
@@ -41,8 +41,10 @@ ImageDrawer::ImageDrawer(std::shared_ptr<SignalController> controller, QObject*
 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;
@@ -52,12 +54,24 @@ ImageDrawer::ReturnCode ImageDrawer::render(const QString& filename, const QByte
   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)