r21907 by craig - #14704: When loading a 1.5.x doc, check the size of the page is the same as the size of a standard page and set to Custom if not

scribus-commit scribus-commit at lists.scribus.net
Sat Apr 15 21:12:46 UTC 2017


Author: craig
Date: Sat Apr 15 21:12:46 2017
New Revision: 21907

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=21907
Log:
#14704: When loading a 1.5.x doc, check the size of the page is the same as the size of a standard page and set to Custom if not

Modified:
    trunk/Scribus/scribus/pagesize.cpp
    trunk/Scribus/scribus/pagesize.h
    trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format.cpp
    trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format_save.cpp
    trunk/Scribus/scribus/ui/pagepropertiesdialog.cpp

Modified: trunk/Scribus/scribus/pagesize.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=21907&path=/trunk/Scribus/scribus/pagesize.cpp
==============================================================================
--- trunk/Scribus/scribus/pagesize.cpp	(original)
+++ trunk/Scribus/scribus/pagesize.cpp	Sat Apr 15 21:12:46 2017
@@ -30,8 +30,32 @@
 #include "commonstrings.h"
 
 
-PageSize::PageSize(const QString sizeName)
-{
+PageSize::PageSize(const QString& sizeName)
+{
+	init(sizeName);
+}
+
+PageSize::PageSize(const double w, const double h)
+{
+	m_width=w;
+	m_height=h;
+	m_pageUnitIndex=-1;
+	m_pageSizeName=CommonStrings::customPageSize;
+	m_trPageSizeName=CommonStrings::trCustomPageSize;
+}
+
+PageSize&PageSize::operator=(const PageSize& other)
+{
+	init(other.name());
+}
+
+void PageSize::init(const QString& sizeName)
+{
+	m_width=m_height=0.0;
+	m_pageUnitIndex=-1;
+	m_pageSizeName=QString::null;
+	m_trPageSizeName=QString::null;
+
 	bool valuesSet=false;
 	generateSizeList();
 	//Build based on untranslated key value
@@ -61,24 +85,15 @@
 			}
 		}
 	}
-	
+
 	if (!valuesSet)
 	{
 		//qDebug("Non-existant page size selected");
 		m_width=m_height=0.0;
 		m_pageUnitIndex=-1;
 		m_pageSizeName=CommonStrings::customPageSize;
-		m_trPageSizeName=CommonStrings::trCustomPageSize;	
-	}
-}
-
-PageSize::PageSize(const double w, const double h)
-{
-	m_width=w;
-	m_height=h;
-	m_pageUnitIndex=-1;
-	m_pageSizeName=CommonStrings::customPageSize;
-	m_trPageSizeName=CommonStrings::trCustomPageSize;	
+		m_trPageSizeName=CommonStrings::trCustomPageSize;
+	}
 }
 
 QStringList PageSize::sizeList(void) const

Modified: trunk/Scribus/scribus/pagesize.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=21907&path=/trunk/Scribus/scribus/pagesize.h
==============================================================================
--- trunk/Scribus/scribus/pagesize.h	(original)
+++ trunk/Scribus/scribus/pagesize.h	Sat Apr 15 21:12:46 2017
@@ -35,14 +35,15 @@
 	int pageUnitIndex;
 };
 
-typedef QMap<QString, PageSizeInfo > PageSizeInfoMap;
+typedef QMap<QString, PageSizeInfo> PageSizeInfoMap;
 
 class SCRIBUS_API PageSize
 {
 public:
-	PageSize(const QString);
+	PageSize(const QString&);
 	PageSize(const double, const double);
-		
+	PageSize& operator=(const PageSize& other);
+	void init(const QString&);
 	QString name() const { return m_pageSizeName; }
 	QString nameTR() const { return m_trPageSizeName; }
 	double width() const { return m_width; }
@@ -59,7 +60,7 @@
 	QStringList untransPageSizeList(const QStringList &transList);
 
 private:
-	QMap<QString, PageSizeInfo > m_pageSizeList;
+	PageSizeInfoMap m_pageSizeList;
 	double m_width;
 	double m_height;
 	int m_pageUnitIndex;

Modified: trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=21907&path=/trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format.cpp	(original)
+++ trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format.cpp	Sat Apr 15 21:12:46 2017
@@ -15,6 +15,7 @@
 #include "notesstyles.h"
 #include "pageitem_latexframe.h"
 #include "pageitem_noteframe.h"
+#include "pagesize.h"
 #include "prefsmanager.h"
 #include "qtiocompressor.h"
 #include "scclocale.h"
@@ -3619,24 +3620,38 @@
 	else
 		newPage->setWidth(attrs.valueAsDouble("PAGEWITH"));
 	newPage->setHeight(attrs.valueAsDouble("PAGEHEIGHT"));
+
+	//14704: Double check the page size should not be Custom in case the size doesn't match a standard size
+	if (attrs.hasAttribute("Size"))
+	{
+		QString pageSize(attrs.valueAsString("Size"));
+		PageSize ps(pageSize);
+		if (!compareDouble(ps.width(), newPage->width()) || !compareDouble(ps.height(), newPage->height()))
+			newPage->m_pageSize = CommonStrings::customPageSize;
+		else
+			newPage->m_pageSize = pageSize;
+	}
+
+
+
 	newPage->setInitialHeight(newPage->height());
 	newPage->setInitialWidth(newPage->width());
 	newPage->initialMargins.setTop(qMax(0.0, attrs.valueAsDouble("BORDERTOP")));
 	newPage->initialMargins.setBottom(qMax(0.0, attrs.valueAsDouble("BORDERBOTTOM")));
 	newPage->initialMargins.setLeft(qMax(0.0, attrs.valueAsDouble("BORDERLEFT")));
 	newPage->initialMargins.setRight(qMax(0.0, attrs.valueAsDouble("BORDERRIGHT")));
-	newPage->marginPreset   = attrs.valueAsInt("PRESET", 0);
+	newPage->marginPreset = attrs.valueAsInt("PRESET", 0);
 	newPage->Margins.setTop(newPage->initialMargins.top());
 	newPage->Margins.setBottom(newPage->initialMargins.bottom());
 	m_Doc->setMasterPageMode(false);
 	//m_Doc->Pages=&m_Doc->DocPages;
 	// guides reading
-	newPage->guides.setHorizontalAutoGap( attrs.valueAsDouble("AGhorizontalAutoGap", 0.0));
-	newPage->guides.setVerticalAutoGap  ( attrs.valueAsDouble("AGverticalAutoGap", 0.0));
-	newPage->guides.setHorizontalAutoCount( attrs.valueAsInt("AGhorizontalAutoCount", 0) );
-	newPage->guides.setVerticalAutoCount  ( attrs.valueAsInt("AGverticalAutoCount", 0) );
-	newPage->guides.setHorizontalAutoRefer( attrs.valueAsInt("AGhorizontalAutoRefer", 0) );
-	newPage->guides.setVerticalAutoRefer  ( attrs.valueAsInt("AGverticalAutoRefer", 0) );
+	newPage->guides.setHorizontalAutoGap(attrs.valueAsDouble("AGhorizontalAutoGap", 0.0));
+	newPage->guides.setVerticalAutoGap(attrs.valueAsDouble("AGverticalAutoGap", 0.0));
+	newPage->guides.setHorizontalAutoCount(attrs.valueAsInt("AGhorizontalAutoCount", 0) );
+	newPage->guides.setVerticalAutoCount(attrs.valueAsInt("AGverticalAutoCount", 0) );
+	newPage->guides.setHorizontalAutoRefer(attrs.valueAsInt("AGhorizontalAutoRefer", 0) );
+	newPage->guides.setVerticalAutoRefer(attrs.valueAsInt("AGverticalAutoRefer", 0) );
 	GuideManagerIO::readVerticalGuides(attrs.valueAsString("VerticalGuides"),
 			newPage,
 			GuideManagerCore::Standard,

Modified: trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format_save.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=21907&path=/trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format_save.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format_save.cpp	(original)
+++ trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format_save.cpp	Sat Apr 15 21:12:46 2017
@@ -178,7 +178,8 @@
 
 	// Create a random temporary file name
 	srand(time(NULL)); // initialize random sequence each time
-	long     randt = 0, randn = 1 + (int) (((double) rand() / ((double) RAND_MAX + 1)) * 10000);
+	long randt = 0;
+	long randn = 1 + (int) (((double) rand() / ((double) RAND_MAX + 1)) * 10000);
 	QString  tmpFileName  = QString("%1.%2").arg(fileName).arg(randn);
 	while (QFile::exists(tmpFileName) && (randt < 100))
 	{
@@ -425,7 +426,7 @@
 	writePageSets(docu);
 	writeSections(docu);
 	writePatterns(docu, fileDir);
-	writeContent (docu, fileDir);
+	writeContent(docu, fileDir);
 
 	docu.writeEndElement();
 	docu.writeEndDocument();

Modified: trunk/Scribus/scribus/ui/pagepropertiesdialog.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=21907&path=/trunk/Scribus/scribus/ui/pagepropertiesdialog.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/pagepropertiesdialog.cpp	(original)
+++ trunk/Scribus/scribus/ui/pagepropertiesdialog.cpp	Sat Apr 15 21:12:46 2017
@@ -45,16 +45,16 @@
 	TextLabel1 = new QLabel( tr( "&Size:" ), dsGroupBox7 );
 	dsGroupBox7Layout->addWidget( TextLabel1, 0, 0, 1, 2 );
 
-	PageSize *ps=new PageSize(doc->currentPage()->m_pageSize);
-	prefsPageSizeName=ps->name();
+	PageSize ps(doc->currentPage()->m_pageSize);
+	prefsPageSizeName=ps.name();
 	sizeQComboBox = new QComboBox(dsGroupBox7);
-	QStringList insertList(ps->activeSizeTRList());
-	if (insertList.indexOf(prefsPageSizeName)==-1)
+	QStringList insertList(ps.activeSizeTRList());
+	if (insertList.indexOf(prefsPageSizeName)==-1 && prefsPageSizeName!=CommonStrings::customPageSize)
 		insertList<<prefsPageSizeName;
 	insertList.sort();
 	insertList<<CommonStrings::trCustomPageSize;
 	sizeQComboBox->addItems(insertList);
-	int sizeIndex = insertList.indexOf(ps->nameTR());
+	int sizeIndex = insertList.indexOf(ps.nameTR());
 	if (sizeIndex != -1)
 		sizeQComboBox->setCurrentIndex(sizeIndex);
 	else
@@ -161,17 +161,9 @@
 	setMaximumSize(sizeHint());
 	pageWidth = widthSpinBox->value() / unitRatio;
 	pageHeight = heightSpinBox->value() / unitRatio;
-	if (sizeQComboBox->currentText() == CommonStrings::trCustomPageSize)
-	{
-		heightSpinBox->setEnabled( true );
-		widthSpinBox->setEnabled( true );
-	}
-	else
-	{
-		heightSpinBox->setEnabled( false );
-		widthSpinBox->setEnabled( false );
-	}
-	delete ps;
+	bool isCustom = (sizeQComboBox->currentText() == CommonStrings::trCustomPageSize);
+	heightSpinBox->setEnabled(isCustom);
+	widthSpinBox->setEnabled(isCustom);
 	// signals and slots connections
 	connect( okButton, SIGNAL( clicked() ), this, SLOT( accept() ) );
 	connect( cancelButton, SIGNAL( clicked() ), this, SLOT( reject() ) );




More information about the scribus-commit mailing list