r23009 by jghali - #15670: PDF Link annotations not updated when inserting/removing pages

scribus-commit scribus-commit at lists.scribus.net
Sat Jun 8 16:03:29 UTC 2019


Author: jghali
Date: Sat Jun  8 16:03:28 2019
New Revision: 23009

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=23009
Log:
#15670: PDF Link annotations not updated when inserting/removing pages

Modified:
    trunk/Scribus/scribus/scribus.cpp
    trunk/Scribus/scribus/scribusdoc.cpp
    trunk/Scribus/scribus/scribusdoc.h

Modified: trunk/Scribus/scribus/scribus.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23009&path=/trunk/Scribus/scribus/scribus.cpp
==============================================================================
--- trunk/Scribus/scribus/scribus.cpp	(original)
+++ trunk/Scribus/scribus/scribus.cpp	Sat Jun  8 16:03:28 2019
@@ -5321,9 +5321,15 @@
 	slotNewPage(wo, templ); //master page is applied now
 	//applyNewMaster(templ);
 	if (where == 2)
+	{
+		doc->addPageToAnnotLinks(wo, where, 1);
 		doc->addPageToSection(wo, where, 1);
+	}
 	else
-		doc->addPageToSection(wo+1, where, 1);
+	{
+		doc->addPageToAnnotLinks(wo + 1, where, 1);
+		doc->addPageToSection(wo + 1, where, 1);
+	}
 
 	doc->updateEndnotesFrames();
 	doc->changed();
@@ -5447,13 +5453,14 @@
 		//CB If we want to add this master page setting into the slotnewpage call, the pagenumber must be +1 I think
 	//Apply_MasterPage(base[(doc->currentPage()->pageNr()+doc->pageSets[doc->currentPageLayout].FirstPage) % doc->pageSets[doc->currentPageLayout].Columns],
 //						 doc->currentPage()->pageNr(), false); // this Apply_MasterPage avoids DreawNew and PagePalette->ReBuild, which is much faster for 100 pp :-)
-		wot ++;
+		++wot;
 	}
 	doc->setCurrentPage(currentPage);
 	view->updatesOn(true);
 	qApp->restoreOverrideCursor();
 	//Use wo, the dialog currently returns a page Index +1 due to old numbering scheme, function now does the -1 as required
 	doc->changed();
+	doc->addPageToAnnotLinks(wot, where, numPages);
 	doc->addPageToSection(wo, where, numPages);
 	doc->reformPages();
 	doc->updateEndnotesFrames();
@@ -6227,7 +6234,10 @@
 		else
 			doc->deletePage(a);
 		if (!isMasterPage) // Master pages are not added to sections when created
+		{
+			doc->removePageFromAnnotLinks(a);
 			doc->removePageFromSection(a);
+		}
 	}
 	pageSelector->setMaximum(doc->Pages->count());
 	pageSelector->blockSignals(b);

Modified: trunk/Scribus/scribus/scribusdoc.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23009&path=/trunk/Scribus/scribus/scribusdoc.cpp
==============================================================================
--- trunk/Scribus/scribus/scribusdoc.cpp	(original)
+++ trunk/Scribus/scribus/scribusdoc.cpp	Sat Jun  8 16:03:28 2019
@@ -7043,13 +7043,13 @@
 
 void ScribusDoc::updateSectionPageNumbersToPages()
 {
-	int docPageCount=DocPages.count();
-	for (int i=0; i < docPageCount; ++i)
+	int docPageCount = DocPages.count();
+	for (int i = 0; i < docPageCount; ++i)
 		DocPages.at(i)->setPageSectionNumber(getSectionPageNumberForPageIndex(i));
 }
 
 
-void ScribusDoc::addPageToSection(const uint otherPageIndex, const uint location, const uint count)
+void ScribusDoc::addPageToSection(uint otherPageIndex, uint location, uint count)
 {
 	uint fromIndex, toIndex;
 	uint searchedIndex = (otherPageIndex > 0) ? (otherPageIndex - 1) : 0;
@@ -7070,7 +7070,7 @@
 }
 
 
-void ScribusDoc::removePageFromSection(const uint pageIndex)
+void ScribusDoc::removePageFromSection(uint pageIndex)
 {
 	//Get the section of the new page index.
 	uint fromIndex, toIndex;
@@ -7107,6 +7107,63 @@
 	updateSectionPageNumbersToPages();
 }
 
+void ScribusDoc::addPageToAnnotLinks(int otherPageIndex, int location, int count)
+{
+	int searchedIndex = (otherPageIndex > 0) ? (otherPageIndex - 1) : 0;
+	if ((location == 0) && (searchedIndex > 0))
+		--searchedIndex;
+
+	QList<PageItem*> itemList = DocItems;
+	while (itemList.count() > 0)
+	{
+		PageItem *currItem = itemList.takeLast();
+		if (currItem->isGroup())
+		{
+			itemList += currItem->groupItemList;
+			continue;
+		}
+		if (!currItem->isAnnotation())
+			continue;
+		
+		Annotation& annotation = currItem->annotation();
+		if (annotation.ActionType() != Annotation::Action_GoTo)
+			continue;
+
+		int targetPage = annotation.Ziel();
+		if (targetPage >= searchedIndex)
+		{
+			targetPage += count;
+			annotation.setZiel(targetPage);
+		}
+	}
+}
+
+void ScribusDoc::removePageFromAnnotLinks(int pageIndex)
+{
+	QList<PageItem*> itemList = DocItems;
+	while (itemList.count() > 0)
+	{
+		PageItem *currItem = itemList.takeLast();
+		if (currItem->isGroup())
+		{
+			itemList += currItem->groupItemList;
+			continue;
+		}
+		if (!currItem->isAnnotation())
+			continue;
+		
+		Annotation& annotation = currItem->annotation();
+		if (annotation.ActionType() != Annotation::Action_GoTo)
+			continue;
+
+		int targetPage = annotation.Ziel();
+		if (targetPage >= pageIndex)
+		{
+			--targetPage;
+			annotation.setZiel(targetPage);
+		}
+	}
+}
 
 void ScribusDoc::copyPage(int pageNumberToCopy, int existingPage, int whereToInsert, int copyCount)
 {

Modified: trunk/Scribus/scribus/scribusdoc.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23009&path=/trunk/Scribus/scribus/scribusdoc.h
==============================================================================
--- trunk/Scribus/scribus/scribusdoc.h	(original)
+++ trunk/Scribus/scribus/scribusdoc.h	Sat Jun  8 16:03:28 2019
@@ -977,12 +977,11 @@
 	 */
 	void updateSectionPageNumbersToPages();
 	/**
-	 * 
 	 * @param otherPageIndex 
 	 * @param location 
 	 * @param count 
 	 */
-	void addPageToSection(const uint otherPageIndex, const uint location, const uint count=1);
+	void addPageToSection(uint otherPageIndex, uint location, uint count=1);
 	/**
 	 * 
 	 * @param pageIndex 
@@ -997,6 +996,16 @@
 	 * @brief Returns name of section where page is located
 	 */
 	QString getSectionNameForPageIndex(const uint pageIndex) const;
+
+	/**
+	 * Update annotation links when a page is added
+	 */
+	void addPageToAnnotLinks(int otherPageIndex, int location, int count=1);
+
+	/**
+	 * Update annotation links when a page is removed
+	 */
+	void removePageFromAnnotLinks(int pageIndex);
 
 	//! @brief Some internal align tools
 	typedef enum {alignFirst, alignLast, alignPage, alignMargins, alignGuide, alignSelection } AlignTo;




More information about the scribus-commit mailing list