r22667 by jghali - refactor util_file.cpp's getVectorFileFromData()

scribus-commit scribus-commit at lists.scribus.net
Tue Sep 4 23:16:09 UTC 2018


Author: jghali
Date: Tue Sep  4 23:16:09 2018
New Revision: 22667

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=22667
Log:
refactor util_file.cpp's getVectorFileFromData()

Modified:
    trunk/Scribus/scribus/util_file.cpp

Modified: trunk/Scribus/scribus/util_file.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22667&path=/trunk/Scribus/scribus/util_file.cpp
==============================================================================
--- trunk/Scribus/scribus/util_file.cpp	(original)
+++ trunk/Scribus/scribus/util_file.cpp	Tue Sep  4 23:16:09 2018
@@ -20,6 +20,7 @@
 #include <QFileInfo>
 #include <QString>
 #include <QProcess>
+#include <QScopedPointer>
 #include <QTemporaryFile>
 
 #include "fileloader.h"
@@ -241,43 +242,46 @@
 PageItem*  getVectorFileFromData(ScribusDoc *doc, QByteArray &data, const QString& ext, double x, double y, double w, double h)
 {
 	PageItem* retObj = nullptr;
-	QTemporaryFile *tempFile = new QTemporaryFile(QDir::tempPath() + "/scribus_temp_XXXXXX." + ext);
-	if (tempFile->open())
-	{
-		QString fileName = getLongPathName(tempFile->fileName());
-		if (!fileName.isEmpty())
-		{
-			tempFile->write(data);
-			tempFile->close();
-			FileLoader *fileLoader = new FileLoader(fileName);
-			int testResult = fileLoader->testFile();
-			delete fileLoader;
-			if (testResult != -1)
-			{
-				const FileFormat * fmt = LoadSavePlugin::getFormatById(testResult);
-				if (fmt)
-				{
-					doc->m_Selection->clear();
-					doc->m_Selection->delaySignalsOn();
-					fmt->setupTargets(doc, nullptr, nullptr, nullptr, &(PrefsManager::instance()->appPrefs.fontPrefs.AvailFonts));
-					fmt->loadFile(fileName, LoadSavePlugin::lfUseCurrentPage|LoadSavePlugin::lfInteractive|LoadSavePlugin::lfScripted);
-					if (!doc->m_Selection->isEmpty())
-					{
-						retObj = doc->groupObjectsSelection();
-						retObj->setTextFlowMode(PageItem::TextFlowUsesBoundingBox);
-						retObj->setXYPos(x, y, true);
-						if ((w >= 0) && (h >= 0))
-							retObj->setWidthHeight(w, h, true);
-						retObj->updateClip();
-						retObj->update();
-					}
-					doc->m_Selection->clear();
-					doc->m_Selection->delaySignalsOff();
-				}
-			}
-		}
-	}
-	delete tempFile;
+
+	QScopedPointer<QTemporaryFile> tempFile(new QTemporaryFile(QDir::tempPath() + "/scribus_temp_XXXXXX." + ext));
+	if (!tempFile->open())
+		return nullptr;
+
+	QString fileName = getLongPathName(tempFile->fileName());
+	if (fileName.isEmpty())
+		return nullptr;
+
+	tempFile->write(data);
+	tempFile->close();
+
+	FileLoader *fileLoader = new FileLoader(fileName);
+	int testResult = fileLoader->testFile();
+	delete fileLoader;
+
+	if (testResult == -1)
+		return nullptr;
+
+	const FileFormat * fmt = LoadSavePlugin::getFormatById(testResult);
+	if (!fmt)
+		return nullptr;
+
+	doc->m_Selection->clear();
+	doc->m_Selection->delaySignalsOn();
+	fmt->setupTargets(doc, nullptr, nullptr, nullptr, &(PrefsManager::instance()->appPrefs.fontPrefs.AvailFonts));
+	fmt->loadFile(fileName, LoadSavePlugin::lfUseCurrentPage|LoadSavePlugin::lfInteractive|LoadSavePlugin::lfScripted);
+	if (!doc->m_Selection->isEmpty())
+	{
+		retObj = doc->groupObjectsSelection();
+		retObj->setTextFlowMode(PageItem::TextFlowUsesBoundingBox);
+		retObj->setXYPos(x, y, true);
+		if ((w >= 0) && (h >= 0))
+			retObj->setWidthHeight(w, h, true);
+		retObj->updateClip();
+		retObj->update();
+	}
+	doc->m_Selection->clear();
+	doc->m_Selection->delaySignalsOff();
+
 	return retObj;
 }
 




More information about the scribus-commit mailing list