View Issue Details

IDProjectCategoryView StatusLast Update
0017175ScribusGeneralpublic2024-03-14 16:07
Reporterale Assigned To 
PrioritynormalSeverityfeatureReproducibilityN/A
Status newResolutionopen 
Product Version1.7.0.svn 
Summary0017175: [PATCH] Multiple duplicate by page: optionally limit the number of copies
Descriptioncurrently, multiple duplicate duplicates to the end of the document.

it should be possible to limit the number of copies to a given number.
TagsNo tags attached.
PatchYes

Relationships

related to 0017174 new Multiple duplicate by page: optionally adjust according to the margins 

Activities

ale

2024-03-14 11:59

manager   ~0051038

Last edited: 2024-03-14 12:01

the patch adds a new field in the "by page" tab that limits the maximal number of copies being done.

it also disables the custom page range, for multi page selections (for continuous ranges, this patch is a better solution; for non continuous one, the current code would probably not have worked and: who does something like that?)

(most changes in the diff are due to a new indenting due to slightly modified ifs)
duplicate-copies.diff (7,314 bytes)   
diff --git a/scribus/scribusdoc.cpp b/scribus/scribusdoc.cpp
index 041f139e7..e16169c31 100644
--- a/scribus/scribusdoc.cpp
+++ b/scribus/scribusdoc.cpp
@@ -13796,45 +13796,51 @@ void ScribusDoc::multipleDuplicateByPage(const ItemMultipleDuplicateData& dialog
 		int firstPage = Pages->count(), lastPage = 0;
 		for (auto item: selection.items())
 		{
-			if ((item->OwnPage >= 0) && (item->OwnPage < firstPage))
-				firstPage = item->OwnPage;
-			if ((item->OwnPage) >= 0 && (item->OwnPage > lastPage))
-				lastPage = item->OwnPage;
+			if (item->OwnPage >= 0)
+			{
+				if (item->OwnPage < firstPage)
+					firstPage = item->OwnPage;
+				if (item->OwnPage > lastPage)
+					lastPage = item->OwnPage;
+			}
 		}
 		setCurrentPage(Pages->at(firstPage));
 		int pageSpread = lastPage - firstPage + 1;
 		QStringList pageList;
+		// with multi-page selection, only "following pages" is available
+		for (int i = lastPage + 2; i < Pages->count(); i += pageSpread)
+			pageList << QString::number(i);
+		pageRange = pageList.join(',');
+	}
+	else
+	{
 		if (dialogData.pageSelection == 1)
-			for (int i = lastPage + 2; i < Pages->count(); i += pageSpread)
+			pageRange = QString("%1-%2").arg(currPageNumber + 2).arg(Pages->count());
+		else if ((dialogData.pageSelection == 2) || dialogData.pageSelection == 3)
+		{
+			int start = currPageNumber + 2;
+			// round to the next odd / even number
+			if (dialogData.pageSelection == 2)
+				start += start % 2;
+			else
+				start += 1 - (start % 2);
+
+			QStringList pageList;
+			for (int i = start; i <= Pages->count(); i += 2)
 				pageList << QString::number(i);
+			pageRange = pageList.join(',');
+		}
 		else if (dialogData.pageSelection == 4)
 		{
-			// TODO: what to do with manual selections?
 			pageRange = dialogData.pageRange;
 		}
-		pageRange = pageList.join(',');
 	}
-	else if (dialogData.pageSelection == 1)
-		pageRange = QString("%1-%2").arg(currPageNumber + 2).arg(Pages->count());
-	else if ((dialogData.pageSelection == 2) || dialogData.pageSelection == 3)
-	{
-		int start = currPageNumber + 2;
-		// round to the next odd / even number
-		if (dialogData.pageSelection == 2)
-			start += start % 2;
-		else
-			start += 1 - (start % 2);
+	parsePagesString(pageRange, &pages, Pages->count());
 
-		QStringList pageList;
-		for (int i = start; i <= Pages->count(); i += 2)
-			pageList << QString::number(i);
-		pageRange = pageList.join(',');
+	if (dialogData.copyCount > 0 && dialogData.copyCount < pages.size()) {
+		pages.resize(dialogData.copyCount);
+		pages.shrink_to_fit();
 	}
-	else if (dialogData.pageSelection == 4)
-	{
-		pageRange = dialogData.pageRange;
-	}
-	parsePagesString(pageRange, &pages, Pages->count());
 
 	PageItem* lastInChain = nullptr;
 	if (dialogData.pageLinkText)
diff --git a/scribus/ui/multipleduplicate.cpp b/scribus/ui/multipleduplicate.cpp
index d569dbf0b..796d1b7f5 100644
--- a/scribus/ui/multipleduplicate.cpp
+++ b/scribus/ui/multipleduplicate.cpp
@@ -50,12 +50,22 @@ MultipleDuplicate::MultipleDuplicate(QWidget* parent, ScribusDoc *doc) : QDialog
 	{
 		radioButtonPageOdd->setEnabled(false);
 		radioButtonPageEven->setEnabled(false);
+		radioButtonPageRange->setEnabled(false);
+		lineEditPageRange->setEnabled(false);
+		toolButtonPageRange->setEnabled(false);
 	}
 	
 	createGapRadioButton->setChecked(true);
 	setCopiesGap();
 
+	spinBoxMaxCopies->setToolTip(tr("Maximal number of duplicates to be created"));
+	spinBoxMaxCopies->setMinimum(0);
+	spinBoxMaxCopies->setSpecialValueText( tr( "Auto" ));
+	spinBoxMaxCopies->setDecimals(0);
+	spinBoxMaxCopies->setSuffix("");
+
 	toolButtonPageRange->setIcon(IconManager::instance().loadIcon("ellipsis.png"));
+
 	radioButtonPageAll->setChecked(true);
 
 	// signals and slots connections
@@ -96,16 +106,20 @@ void MultipleDuplicate::getMultiplyData(ItemMultipleDuplicateData& mdData)
 	mdData.gridCols = gridColsSpinBox->value();
 	mdData.gridGapH = horizRCGapSpinBox->value();
 	mdData.gridGapV = vertRCGapSpinBox->value();
-	if (radioButtonPageAll->isChecked())
-		mdData.pageSelection = 1;
-	else if (radioButtonPageEven->isChecked())
-		mdData.pageSelection = 2;
-	else if (radioButtonPageOdd->isChecked())
-		mdData.pageSelection = 3;
-	else if (radioButtonPageRange->isChecked())
-		mdData.pageSelection = 4;
-	mdData.pageRange = lineEditPageRange->text();
-	mdData.pageLinkText = checkBoxPageLinkText->isChecked();
+	if (mdData.type == 2)
+	{
+		if (radioButtonPageAll->isChecked())
+			mdData.pageSelection = 1;
+		else if (radioButtonPageEven->isChecked())
+			mdData.pageSelection = 2;
+		else if (radioButtonPageOdd->isChecked())
+			mdData.pageSelection = 3;
+		else if (radioButtonPageRange->isChecked())
+			mdData.pageSelection = 4;
+		mdData.pageRange = lineEditPageRange->text();
+		mdData.pageLinkText = checkBoxPageLinkText->isChecked();
+		mdData.copyCount = spinBoxMaxCopies->value();
+	}
 }
 
 void MultipleDuplicate::selectRangeOfPages()
diff --git a/scribus/ui/multipleduplicate.ui b/scribus/ui/multipleduplicate.ui
index 61d54b178..1b21d2605 100644
--- a/scribus/ui/multipleduplicate.ui
+++ b/scribus/ui/multipleduplicate.ui
@@ -10,7 +10,7 @@
     <x>0</x>
     <y>0</y>
     <width>426</width>
-    <height>294</height>
+    <height>329</height>
    </rect>
   </property>
   <property name="sizePolicy">
@@ -381,6 +381,43 @@
          </item>
         </layout>
        </item>
+       <item>
+        <layout class="QHBoxLayout" name="horizontalLayout_3">
+         <item>
+          <widget class="QLabel" name="labelMaxCopies">
+           <property name="text">
+            <string>Number of copies:</string>
+           </property>
+          </widget>
+         </item>
+         <item>
+          <widget class="ScrSpinBox" name="spinBoxMaxCopies">
+           <property name="sizePolicy">
+            <sizepolicy hsizetype="Minimum" vsizetype="Fixed">
+             <horstretch>0</horstretch>
+             <verstretch>0</verstretch>
+            </sizepolicy>
+           </property>
+           <property name="specialValueText">
+            <string>Auto</string>
+           </property>
+          </widget>
+         </item>
+         <item>
+          <spacer name="horizontalSpacer_2">
+           <property name="orientation">
+            <enum>Qt::Horizontal</enum>
+           </property>
+           <property name="sizeHint" stdset="0">
+            <size>
+             <width>40</width>
+             <height>20</height>
+            </size>
+           </property>
+          </spacer>
+         </item>
+        </layout>
+       </item>
        <item>
         <layout class="QVBoxLayout" name="verticalLayout_9">
          <item>
@@ -423,7 +460,7 @@
   <customwidget>
    <class>ScrSpinBox</class>
    <extends>QDoubleSpinBox</extends>
-   <header location="global">ui/scrspinbox.h</header>
+   <header>ui/scrspinbox.h</header>
   </customwidget>
  </customwidgets>
  <tabstops>
diff --git a/scribus/usertaskstructs.h b/scribus/usertaskstructs.h
index 8c498283e..5ac48395f 100644
--- a/scribus/usertaskstructs.h
+++ b/scribus/usertaskstructs.h
@@ -34,7 +34,7 @@ struct InsertAFrameData
 
 struct ItemMultipleDuplicateData
 {
-	int type = 0;
+	int type = 0; // 0 = by number, 1 = by rows & columns, 2 = by page
 	int copyCount = 0;
 	int copyShiftOrGap = 0;
 	double copyShiftGapH = 0.0;
duplicate-copies.diff (7,314 bytes)   
duplicate-copies-only.png (37,973 bytes)   
duplicate-copies-only.png (37,973 bytes)   

Issue History

Date Modified Username Field Change
2024-03-14 10:53 ale New Issue
2024-03-14 11:59 ale Note Added: 0051038
2024-03-14 11:59 ale File Added: duplicate-copies.diff
2024-03-14 11:59 ale File Added: duplicate-copies-only.png
2024-03-14 12:00 ale Summary Multiple duplicate by page: optionally limit the number of copies => [PATCH] Multiple duplicate by page: optionally limit the number of copies
2024-03-14 12:00 ale Patch No => Yes
2024-03-14 12:01 ale Note Edited: 0051038
2024-03-14 16:07 ale Relationship added related to 0017174