r23010 by jghali - Refactor Insert Page dialog anhd make all its widgets private

scribus-commit scribus-commit at lists.scribus.net
Sat Jun 8 17:19:06 UTC 2019


Author: jghali
Date: Sat Jun  8 17:19:06 2019
New Revision: 23010

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=23010
Log:
Refactor Insert Page dialog anhd make all its widgets private

Modified:
    trunk/Scribus/scribus/scribus.cpp
    trunk/Scribus/scribus/ui/inspage.cpp
    trunk/Scribus/scribus/ui/inspage.h

Modified: trunk/Scribus/scribus/scribus.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23010&path=/trunk/Scribus/scribus/scribus.cpp
==============================================================================
--- trunk/Scribus/scribus/scribus.cpp	(original)
+++ trunk/Scribus/scribus/scribus.cpp	Sat Jun  8 17:19:06 2019
@@ -5348,11 +5348,11 @@
 	if (dia->exec())
 	{
 		QStringList base(dia->getMasterPages());
-		double height=dia->heightSpinBox->value() / doc->unitRatio();
-		double width=dia->widthSpinBox->value() / doc->unitRatio();
-		int orientation=dia->orientationQComboBox->currentIndex();
+		double height = dia->pageWidth();
+		double width = dia->pageHeight();
+		int orientation = dia->orientation();
 		addNewPages(dia->getWherePage(), dia->getWhere(), dia->getCount(), height, width, orientation, 
-			dia->prefsPageSizeName, dia->moveObjects->isChecked(), &base, dia->overrideMPSizingCheckBox->checkState()==Qt::Checked);
+			dia->prefsPageSizeName, dia->moveObjects(), &base, dia->overrideMasterPageSizing());
 	}
 	delete dia;
 }
@@ -5430,10 +5430,10 @@
 	}
 	int cc;
 	int wot = wo;
-	if (where==0)
+	if (where == 0)
 		--wot;
-	else if (where==2)
-		wot=doc->Pages->count();
+	else if (where == 2)
+		wot = doc->Pages->count();
 	qApp->setOverrideCursor(QCursor(Qt::WaitCursor));
 	view->updatesOn(false);
 	const PageSet& pageSet = doc->pageSets()[doc->pagePositioning()];

Modified: trunk/Scribus/scribus/ui/inspage.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23010&path=/trunk/Scribus/scribus/ui/inspage.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/inspage.cpp	(original)
+++ trunk/Scribus/scribus/ui/inspage.cpp	Sat Jun  8 17:19:06 2019
@@ -26,6 +26,8 @@
 InsPage::InsPage( QWidget* parent, ScribusDoc* currentDoc, int currentPage, int maxPages)
 	: QDialog( parent, nullptr )
 {
+	m_doc = currentDoc;
+
 	masterPageCombos.clear();
 	setModal(true);
 	setWindowTitle( tr( "Insert Page" ) );
@@ -71,14 +73,14 @@
 	masterPageLayout->setAlignment( Qt::AlignTop );
 	masterPageLayout->setSpacing( 5 );
 	masterPageLayout->setMargin( 5 );
-	if (currentDoc->pagePositioning() == 0)
+	if (m_doc->pagePositioning() == 0)
 	{
 		QComboBox* pageData = new QComboBox(masterPageGroup);
-		for (QMap<QString,int>::Iterator it = currentDoc->MasterNames.begin(); it != currentDoc->MasterNames.end(); ++it)
+		for (QMap<QString,int>::Iterator it = m_doc->MasterNames.begin(); it != m_doc->MasterNames.end(); ++it)
 		{
 			pageData->addItem(it.key() == CommonStrings::masterPageNormal ? CommonStrings::trMasterPageNormal : it.key(), it.key());
 		}
-		if (currentDoc->MasterNames.contains( CommonStrings::trMasterPageNormal))
+		if (m_doc->MasterNames.contains( CommonStrings::trMasterPageNormal))
 			setCurrentComboItem(pageData, CommonStrings::trMasterPageNormal);
 		masterPageLabel = new QLabel(tr("&Master Page:"), masterPageGroup);
 		masterPageLabel->setBuddy(pageData);
@@ -89,15 +91,15 @@
 	else
 	{
 		int row = 0;
-		for (int mp = 0; mp < currentDoc->pageSets()[currentDoc->pagePositioning()].pageNames.count(); ++mp)
+		for (int mp = 0; mp < m_doc->pageSets()[m_doc->pagePositioning()].pageNames.count(); ++mp)
 		{
 			QComboBox* pageData = new QComboBox(masterPageGroup);
-//			for (QMap<QString,int>::Iterator it = currentDoc->MasterNames.begin(); it != currentDoc->MasterNames.end(); ++it)
+//			for (QMap<QString,int>::Iterator it = m_doc->MasterNames.begin(); it != m_doc->MasterNames.end(); ++it)
 //				pageData->insertItem(it.key() == CommonStrings::masterPageNormal ? CommonStrings::trMasterPageNormal : it.key());
 			if (mp == 0)
 			{
-				bool conNam = currentDoc->MasterNames.contains( CommonStrings::trMasterPageNormalLeft);
-				for (QMap<QString,int>::Iterator it = currentDoc->MasterNames.begin(); it != currentDoc->MasterNames.end(); ++it)
+				bool conNam = m_doc->MasterNames.contains( CommonStrings::trMasterPageNormalLeft);
+				for (QMap<QString,int>::Iterator it = m_doc->MasterNames.begin(); it != m_doc->MasterNames.end(); ++it)
 				{
 					if ((it.key() == CommonStrings::masterPageNormal) && (!conNam))
 						pageData->addItem(CommonStrings::trMasterPageNormal, it.key());
@@ -105,19 +107,19 @@
 						pageData->addItem(CommonStrings::trMasterPageNormal, it.key());
 					else
 					{
-						if (currentDoc->MasterPages.at(it.value())->LeftPg == 1)
+						if (m_doc->MasterPages.at(it.value())->LeftPg == 1)
 							pageData->addItem(it.key(), it.key());
 					}
 				}
-				if (currentDoc->MasterNames.contains( CommonStrings::trMasterPageNormalLeft))
+				if (m_doc->MasterNames.contains( CommonStrings::trMasterPageNormalLeft))
 					setCurrentComboItem(pageData, CommonStrings::trMasterPageNormalLeft);
 			}
 			else if (mp == 1)
 			{
-				if (currentDoc->pageSets()[currentDoc->pagePositioning()].pageNames.count() > 2)
-				{
-					bool conNam = currentDoc->MasterNames.contains( CommonStrings::trMasterPageNormalMiddle);
-					for (QMap<QString,int>::Iterator it = currentDoc->MasterNames.begin(); it != currentDoc->MasterNames.end(); ++it)
+				if (m_doc->pageSets()[m_doc->pagePositioning()].pageNames.count() > 2)
+				{
+					bool conNam = m_doc->MasterNames.contains( CommonStrings::trMasterPageNormalMiddle);
+					for (QMap<QString,int>::Iterator it = m_doc->MasterNames.begin(); it != m_doc->MasterNames.end(); ++it)
 					{
 						if ((it.key() == CommonStrings::masterPageNormal) && (!conNam))
 							pageData->addItem(CommonStrings::trMasterPageNormal, it.key());
@@ -125,17 +127,17 @@
 							pageData->addItem(CommonStrings::trMasterPageNormal, it.key());
 						else
 						{
-							if ((currentDoc->MasterPages.at(it.value())->LeftPg != 0) && (currentDoc->MasterPages.at(it.value())->LeftPg != 1))
+							if ((m_doc->MasterPages.at(it.value())->LeftPg != 0) && (m_doc->MasterPages.at(it.value())->LeftPg != 1))
 								pageData->addItem(it.key(), it.key());
 						}
 					}
-					if (currentDoc->MasterNames.contains( CommonStrings::trMasterPageNormalMiddle))
+					if (m_doc->MasterNames.contains( CommonStrings::trMasterPageNormalMiddle))
 						setCurrentComboItem(pageData, CommonStrings::trMasterPageNormalMiddle);
 				}
 				else
 				{
-					bool conNam = currentDoc->MasterNames.contains( CommonStrings::trMasterPageNormalRight);
-					for (QMap<QString,int>::Iterator it = currentDoc->MasterNames.begin(); it != currentDoc->MasterNames.end(); ++it)
+					bool conNam = m_doc->MasterNames.contains( CommonStrings::trMasterPageNormalRight);
+					for (QMap<QString,int>::Iterator it = m_doc->MasterNames.begin(); it != m_doc->MasterNames.end(); ++it)
 					{
 						if ((it.key() == CommonStrings::masterPageNormal) && (!conNam))
 							pageData->addItem(CommonStrings::trMasterPageNormal, it.key());
@@ -143,20 +145,20 @@
 							pageData->addItem(CommonStrings::trMasterPageNormal, it.key());
 						else
 						{
-							if (currentDoc->MasterPages.at(it.value())->LeftPg == 0)
+							if (m_doc->MasterPages.at(it.value())->LeftPg == 0)
 								pageData->addItem(it.key(), it.key());
 						}
 					}
-					if (currentDoc->MasterNames.contains( CommonStrings::trMasterPageNormalRight))
+					if (m_doc->MasterNames.contains( CommonStrings::trMasterPageNormalRight))
 						setCurrentComboItem(pageData, CommonStrings::trMasterPageNormalRight);
 				}
 			}
 			else if (mp == 2)
 			{
-				if (currentDoc->pageSets()[currentDoc->pagePositioning()].pageNames.count() > 3)
-				{
-					bool conNam = currentDoc->MasterNames.contains( CommonStrings::trMasterPageNormalMiddle);
-					for (QMap<QString,int>::Iterator it = currentDoc->MasterNames.begin(); it != currentDoc->MasterNames.end(); ++it)
+				if (m_doc->pageSets()[m_doc->pagePositioning()].pageNames.count() > 3)
+				{
+					bool conNam = m_doc->MasterNames.contains( CommonStrings::trMasterPageNormalMiddle);
+					for (QMap<QString,int>::Iterator it = m_doc->MasterNames.begin(); it != m_doc->MasterNames.end(); ++it)
 					{
 						if ((it.key() == CommonStrings::masterPageNormal) && (!conNam))
 							pageData->addItem(CommonStrings::trMasterPageNormal, it.key());
@@ -164,17 +166,17 @@
 							pageData->addItem(CommonStrings::trMasterPageNormal, it.key());
 						else
 						{
-							if ((currentDoc->MasterPages.at(it.value())->LeftPg != 0) && (currentDoc->MasterPages.at(it.value())->LeftPg != 1))
+							if ((m_doc->MasterPages.at(it.value())->LeftPg != 0) && (m_doc->MasterPages.at(it.value())->LeftPg != 1))
 								pageData->addItem(it.key(), it.key());
 						}
 					}
-					if (currentDoc->MasterNames.contains( CommonStrings::trMasterPageNormalMiddle))
+					if (m_doc->MasterNames.contains( CommonStrings::trMasterPageNormalMiddle))
 						setCurrentComboItem(pageData, CommonStrings::trMasterPageNormalMiddle);
 				}
 				else
 				{
-					bool conNam = currentDoc->MasterNames.contains( CommonStrings::trMasterPageNormalRight);
-					for (QMap<QString,int>::Iterator it = currentDoc->MasterNames.begin(); it != currentDoc->MasterNames.end(); ++it)
+					bool conNam = m_doc->MasterNames.contains( CommonStrings::trMasterPageNormalRight);
+					for (QMap<QString,int>::Iterator it = m_doc->MasterNames.begin(); it != m_doc->MasterNames.end(); ++it)
 					{
 						if ((it.key() == CommonStrings::masterPageNormal) && (!conNam))
 							pageData->addItem(CommonStrings::trMasterPageNormal, it.key());
@@ -182,18 +184,18 @@
 							pageData->addItem(CommonStrings::trMasterPageNormal, it.key());
 						else
 						{
-							if (currentDoc->MasterPages.at(it.value())->LeftPg == 0)
+							if (m_doc->MasterPages.at(it.value())->LeftPg == 0)
 								pageData->addItem(it.key(), it.key());
 						}
 					}
-					if (currentDoc->MasterNames.contains( CommonStrings::trMasterPageNormalRight))
+					if (m_doc->MasterNames.contains( CommonStrings::trMasterPageNormalRight))
 						setCurrentComboItem(pageData, CommonStrings::trMasterPageNormalRight);
 				}
 			}
 			else if (mp == 3)
 			{
-				bool conNam = currentDoc->MasterNames.contains( CommonStrings::trMasterPageNormalRight);
-				for (QMap<QString,int>::Iterator it = currentDoc->MasterNames.begin(); it != currentDoc->MasterNames.end(); ++it)
+				bool conNam = m_doc->MasterNames.contains( CommonStrings::trMasterPageNormalRight);
+				for (QMap<QString,int>::Iterator it = m_doc->MasterNames.begin(); it != m_doc->MasterNames.end(); ++it)
 				{
 					if ((it.key() == CommonStrings::masterPageNormal) && (!conNam))
 						pageData->addItem(CommonStrings::trMasterPageNormal, it.key());
@@ -201,14 +203,14 @@
 						pageData->addItem(CommonStrings::trMasterPageNormal, it.key());
 					else
 					{
-						if (currentDoc->MasterPages.at(it.value())->LeftPg == 0)
+						if (m_doc->MasterPages.at(it.value())->LeftPg == 0)
 							pageData->addItem(it.key(), it.key());
 					}
 				}
-				if (currentDoc->MasterNames.contains( CommonStrings::trMasterPageNormalRight))
+				if (m_doc->MasterNames.contains( CommonStrings::trMasterPageNormalRight))
 					setCurrentComboItem(pageData, CommonStrings::trMasterPageNormalRight);
 			}
-			QString transLabel = currentDoc->pageSets()[currentDoc->pagePositioning()].pageNames[mp];
+			QString transLabel = m_doc->pageSets()[m_doc->pagePositioning()].pageNames[mp];
 			QLabel* pageLabel = new QLabel(CommonStrings::translatePageSetLocString(transLabel), masterPageGroup);
 			pageLabel->setBuddy(pageData);
 			masterPageLayout->addWidget(pageLabel, row, 0 );
@@ -228,7 +230,7 @@
 	TextLabel1 = new QLabel( tr( "&Size:" ), dsGroupBox7);
 	dsGroupBox7Layout->addWidget( TextLabel1, 0, 0);
 
-	PageSize *ps=new PageSize(currentDoc->pageSize());
+	PageSize *ps=new PageSize(m_doc->pageSize());
 	prefsPageSizeName=ps->name();
 	sizeQComboBox = new QComboBox(dsGroupBox7);
 	QStringList insertList(ps->activeSizeTRList());
@@ -250,25 +252,25 @@
 	orientationQComboBox = new QComboBox(dsGroupBox7);
 	orientationQComboBox->addItem( tr( "Portrait" ) );
 	orientationQComboBox->addItem( tr( "Landscape" ) );
-	orientationQComboBox->setCurrentIndex(currentDoc->pageOrientation() );
+	orientationQComboBox->setCurrentIndex(m_doc->pageOrientation() );
 	TextLabel2->setBuddy(orientationQComboBox);
 	dsGroupBox7Layout->addWidget( orientationQComboBox, 1, 1, 1, 3 );
-	widthSpinBox = new ScrSpinBox( 1, 10000, dsGroupBox7, currentDoc->unitIndex() );
+	widthSpinBox = new ScrSpinBox( 1, 10000, dsGroupBox7, m_doc->unitIndex() );
 	widthQLabel = new QLabel( tr( "&Width:" ), dsGroupBox7);
-	widthSpinBox->setValue(currentDoc->pageWidth() * currentDoc->unitRatio());
+	widthSpinBox->setValue(m_doc->pageWidth() * m_doc->unitRatio());
 	widthQLabel->setBuddy(widthSpinBox);
 	dsGroupBox7Layout->addWidget( widthQLabel, 2, 0 );
 	dsGroupBox7Layout->addWidget( widthSpinBox, 2, 1 );
-	heightSpinBox = new ScrSpinBox( 1, 10000, dsGroupBox7, currentDoc->unitIndex() );
-	heightSpinBox->setValue(currentDoc->pageHeight() * currentDoc->unitRatio());
+	heightSpinBox = new ScrSpinBox( 1, 10000, dsGroupBox7, m_doc->unitIndex() );
+	heightSpinBox->setValue(m_doc->pageHeight() * m_doc->unitRatio());
 	heightQLabel = new QLabel( tr( "&Height:" ), dsGroupBox7);
 	heightQLabel->setBuddy(heightSpinBox);
 	dsGroupBox7Layout->addWidget( heightQLabel, 2, 2 );
 	dsGroupBox7Layout->addWidget( heightSpinBox, 2, 3 );
-	moveObjects = new QCheckBox( dsGroupBox7);
-	moveObjects->setText( tr( "Move Objects with their Page" ) );
-	moveObjects->setChecked( true );
-	dsGroupBox7Layout->addWidget( moveObjects, 3, 0, 1, 4 );
+	moveObjectsCheckBox = new QCheckBox( dsGroupBox7);
+	moveObjectsCheckBox->setText( tr( "Move Objects with their Page" ) );
+	moveObjectsCheckBox->setChecked( true );
+	dsGroupBox7Layout->addWidget( moveObjectsCheckBox, 3, 0, 1, 4 );
 	dialogLayout->addWidget( dsGroupBox7 );
 	dsGroupBox7->setEnabled(false);
 	bool b=(sizeQComboBox->currentText() == CommonStrings::trCustomPageSize);
@@ -290,7 +292,7 @@
 	okCancelLayout->addWidget( cancelButton );
 	dialogLayout->addLayout( okCancelLayout );
 	setMaximumSize(sizeHint());
-	unitRatio = currentDoc->unitRatio();
+	m_unitRatio = m_doc->unitRatio();
 
 	// signals and slots connections
 	connect( insWhereData, SIGNAL( activated(int) ), this, SLOT( insWherePageDataDisable(int) ) );
@@ -315,8 +317,8 @@
 	}
 	else
 	{
-		widthSpinBox->setValue(ps2->width() * unitRatio);
-		heightSpinBox->setValue(ps2->height() * unitRatio);
+		widthSpinBox->setValue(ps2->width() * m_unitRatio);
+		heightSpinBox->setValue(ps2->height() * m_unitRatio);
 	}
 	delete ps2;
 }
@@ -368,6 +370,8 @@
 
 int InsPage::getWherePage() const
 {
+	if (insWhereData->currentIndex() == 2)
+		return m_doc->Pages->count();
 	return insWherePageData->value();
 }
 
@@ -376,6 +380,31 @@
 	return insCountData->value();
 }
 
+double InsPage::pageWidth() const
+{
+	return widthSpinBox->value() / m_unitRatio;
+}
+
+double InsPage::pageHeight() const
+{
+	return heightSpinBox->value() / m_unitRatio;
+}
+
+int InsPage::orientation() const
+{
+	return orientationQComboBox->currentIndex();
+}
+
+bool InsPage::overrideMasterPageSizing() const
+{
+	return (overrideMPSizingCheckBox->checkState() == Qt::Checked);
+}
+
+bool InsPage::moveObjects() const
+{
+	return moveObjectsCheckBox->isChecked();
+}
+
 void InsPage::insWherePageDataDisable(int index)
 {
 	insWherePageData->setDisabled((index==2));

Modified: trunk/Scribus/scribus/ui/inspage.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23010&path=/trunk/Scribus/scribus/ui/inspage.h
==============================================================================
--- trunk/Scribus/scribus/ui/inspage.h	(original)
+++ trunk/Scribus/scribus/ui/inspage.h	Sat Jun  8 17:19:06 2019
@@ -31,21 +31,8 @@
 public:
 	InsPage( QWidget* parent, ScribusDoc* currentDoc, int currentPage, int maxPages );
 	~InsPage() {};
-	QGroupBox* dsGroupBox7;
-	QGroupBox* masterPageGroup;
-	ScrSpinBox* widthSpinBox;
-	ScrSpinBox* heightSpinBox;
-	QLabel*	widthQLabel;
-	QLabel*	heightQLabel;
-	QLabel* TextLabel1;
-	QLabel* TextLabel2;
-	QComboBox* sizeQComboBox;
-	QComboBox* orientationQComboBox;
-	QCheckBox* moveObjects;
-	QCheckBox* overrideMPSizingCheckBox;
-	double unitRatio;
+
 	QString prefsPageSizeName;
-	QList<QComboBox*> masterPageCombos;
 
 	const QStringList getMasterPages();
 	const QString getMasterPageN(uint n);
@@ -53,7 +40,15 @@
 	int getWherePage() const;
 	int getCount() const;
 
+	double pageWidth() const;
+	double pageHeight() const;
+	int    orientation() const;
+	bool   overrideMasterPageSizing() const;
+	bool   moveObjects() const;
+
 private:
+	ScribusDoc* m_doc;
+
 	QLabel* insCountLabel;
 	QLabel* masterPageLabel;
 	QLabel* pagesLabel;
@@ -68,6 +63,22 @@
 	QHBoxLayout* okCancelLayout;
 	QGridLayout* dsGroupBox7Layout;
 
+	QGroupBox*  dsGroupBox7;
+	QGroupBox*  masterPageGroup;
+	ScrSpinBox* widthSpinBox;
+	ScrSpinBox* heightSpinBox;
+	QLabel*	    widthQLabel;
+	QLabel*	    heightQLabel;
+	QLabel*     TextLabel1;
+	QLabel*     TextLabel2;
+	QComboBox*  sizeQComboBox;
+	QComboBox*  orientationQComboBox;
+	QCheckBox*  moveObjectsCheckBox;
+	QCheckBox*  overrideMPSizingCheckBox;
+	
+	double m_unitRatio;
+	QList<QComboBox*> masterPageCombos;
+
 private slots:
 	void insWherePageDataDisable (int index);
 	void setSize(const QString &);




More information about the scribus-commit mailing list