View Issue Details
| ID | Project | Category | View Status | Date Submitted | Last Update |
|---|---|---|---|---|---|
| 0017984 | Scribus | Master Pages | public | 2026-09-23 12:45 | 2026-10-29 17:09 |
| Reporter | buttar | Assigned To | |||
| Priority | normal | Severity | feature | Reproducibility | N/A |
| Status | new | Resolution | open | ||
| Platform | Linux | OS | Fedora Workstation | OS Version | 44 |
| Product Version | 1.7.4.svn | ||||
| Target Version | 1.7.5.svn | ||||
| Summary | 0017984: [patch] Stable ID-based master-page foundation | ||||
| Description | Currently, - Master-page identity is substantially tied to editable names. - Renaming therefore requires rewriting assignments and master-item references. - Undo/redo, duplication, import, and persistence can all depend on name consistency rather than stable object identity. ## What this patch changes Applying cleanly on r27861, it introduces the following changes: - Adds persistent, document-local master-page IDs using `QUuid`. - Gives master pages their own stable IDs and document pages ID-based master assignments. - Adds ID-based master ownership to master items. - Keeps names as user-facing labels and compatibility lookup values rather than authoritative identity. - Persists master IDs and assignment IDs in SLA files while retaining existing name attributes for compatibility. - Migrates legacy name-based documents to IDs in memory when loaded. - Preserves master identity through add, apply, rename, delete, undo, and redo. - Gives duplicated masters new identities. - Maps imported master content onto the destination master identity, avoiding source-ID collisions. ## Design choices - `MasterNames` remains available as a name-to-index UI/compatibility index; it is no longer intended to define identity. - Existing name-based UI and scripting interfaces remain compatible and resolve through the new identity layer. - Renaming a master changes its label without rewriting document-page assignments. - Raw master IDs are never exposed in the UI. - Existing SLA name fields remain written alongside the new ID metadata to minimize compatibility disruption. | ||||
| Tags | #please_test | ||||
| Attached Files | mid-foundation-v1.0.patch (19,697 bytes)
Index: scribus/pageitem.cpp
===================================================================
--- scribus/pageitem.cpp (revision 27861)
+++ scribus/pageitem.cpp (working copy)
@@ -218,6 +218,7 @@
BoundingH(other.BoundingH),
ChangedMasterItem(other.ChangedMasterItem),
OnMasterPage(other.OnMasterPage),
+ m_masterPageId(other.m_masterPageId),
isEmbedded(other.isEmbedded),
m_roundedCornerRadius(other.m_roundedCornerRadius),
oldXpos(other.oldXpos),
@@ -657,6 +658,8 @@
m_columnGap = m_Doc->itemToolPrefs().textColumnGap;
OnMasterPage = m_Doc->currentPage() ? m_Doc->currentPage()->pageName() : QString();
+ if (m_Doc->currentPage())
+ m_masterPageId = m_Doc->currentPage()->masterPageId();
m_startArrowIndex = m_Doc->itemToolPrefs().lineStartArrow;
m_endArrowIndex = m_Doc->itemToolPrefs().lineEndArrow;
effectsInUse.clear();
@@ -2401,6 +2404,27 @@
p->drawPolygon(pts.constData() + firstVal, pts.size() - firstVal);
}
+
+void PageItem::setMasterPage(int page, const QString& mpName)
+{
+ OwnPage = page;
+ OnMasterPage = mpName;
+ m_masterPageId = m_Doc ? m_Doc->masterPageId(mpName) : QUuid();
+}
+
+void PageItem::setMasterPageName(const QString& mpName)
+{
+ OnMasterPage = mpName;
+ if (mpName.isEmpty())
+ m_masterPageId = QUuid();
+ else if (m_Doc)
+ {
+ const QUuid id = m_Doc->masterPageId(mpName);
+ if (!id.isNull())
+ m_masterPageId = id;
+ }
+}
+
void PageItem::setItemName(const QString& newName)
{
if (m_itemName == newName || newName.isEmpty())
Index: scribus/pageitem.h
===================================================================
--- scribus/pageitem.h (revision 27861)
+++ scribus/pageitem.h (working copy)
@@ -37,6 +37,7 @@
#include <QRectF>
#include <QString>
#include <QVector>
+#include <QUuid>
#include <QTemporaryFile>
#include "scribusapi.h"
@@ -837,13 +838,15 @@
* @brief Set the masterpage the object is on
* @param mpName name of the master page
*/
- virtual void setMasterPage(int page, const QString& mpName) { OwnPage = page; OnMasterPage = mpName; }
+ virtual void setMasterPage(int page, const QString& mpName);
+ const QUuid& masterPageId() const { return m_masterPageId; }
+ void setMasterPageId(const QUuid& id) { m_masterPageId = id; }
/**
* @brief Set the masterpage the object is on
* @param mpName name of the master page
*/
- virtual void setMasterPageName(const QString& mpName) { OnMasterPage = mpName; }
+ virtual void setMasterPageName(const QString& mpName);
/**
* @brief Set the page "owning" the object
@@ -1440,6 +1443,7 @@
double BoundingH;
bool ChangedMasterItem {false};
QString OnMasterPage;
+ QUuid m_masterPageId;
bool isEmbedded {false};
int inlineCharID {0};
/** Radius of rounded corners */
Index: scribus/plugins/fileloader/scribus171format/scribus171format.cpp
===================================================================
--- scribus/plugins/fileloader/scribus171format/scribus171format.cpp (revision 27861)
+++ scribus/plugins/fileloader/scribus171format/scribus171format.cpp (working copy)
@@ -4814,7 +4814,8 @@
bool savedMasterPageMode = m_Doc->masterPageMode();
m_Doc->setMasterPageMode(!pageName.isEmpty());
- ScPage* newPage = pageName.isEmpty() ? doc->addPage(pageNum) : doc->addMasterPage(pageNum, pageName);
+ const QUuid storedMasterId(attrs.valueAsString("MasterPageId"));
+ ScPage* newPage = pageName.isEmpty() ? doc->addPage(pageNum) : doc->addMasterPage(pageNum, pageName, storedMasterId);
//Remove uppercase in 1.8
if (attrs.hasAttribute("LEFT"))
@@ -4828,6 +4829,13 @@
else
mpName = attrs.valueAsString("MasterPageName", "Normal");
newPage->setMasterPageName(m_Doc->masterPageMode() ? QString() : mpName);
+ if (!m_Doc->masterPageMode())
+ {
+ QUuid appliedId(attrs.valueAsString("AppliedMasterPageId"));
+ if (appliedId.isNull())
+ appliedId = doc->masterPageId(mpName);
+ newPage->setAppliedMasterPageId(appliedId);
+ }
if (attrs.hasAttribute("Size"))
newPage->setSize(attrs.valueAsString("Size"));
if (attrs.hasAttribute("Orientation"))
@@ -4991,6 +4999,12 @@
clipPath.clear();
PageItem* newItem = pasteItem(doc, attrs, readObjectParams.baseDir, itemKind, pageNr);
+ QUuid itemMasterId(attrs.valueAsString("OnMasterPageId"));
+ if (!readObjectParams.renamedMasterPage.isEmpty())
+ itemMasterId = doc->masterPageId(readObjectParams.renamedMasterPage);
+ else if (itemMasterId.isNull() && !masterPageName.isEmpty())
+ itemMasterId = doc->masterPageId(masterPageName);
+ newItem->setMasterPageId(itemMasterId);
newItem->setRedrawBounding();
if (tagName == QLatin1String("MASTEROBJECT") || tagName == QLatin1String("MasterObject"))
newItem->setOwnerPage(doc->OnPage(newItem));
Index: scribus/plugins/fileloader/scribus171format/scribus171format_save.cpp
===================================================================
--- scribus/plugins/fileloader/scribus171format/scribus171format_save.cpp (revision 27861)
+++ scribus/plugins/fileloader/scribus171format/scribus171format_save.cpp (working copy)
@@ -1796,6 +1796,10 @@
docu.writeAttribute("PageNumber",page->pageNr());
docu.writeAttribute("PageName",page->pageName());
docu.writeAttribute("MasterPageName",page->masterPageName());
+ if (!page->masterPageId().isNull())
+ docu.writeAttribute("MasterPageId", page->masterPageId().toString(QUuid::WithoutBraces));
+ if (!page->appliedMasterPageId().isNull())
+ docu.writeAttribute("AppliedMasterPageId", page->appliedMasterPageId().toString(QUuid::WithoutBraces));
PageSize ps(page->width(), page->height());
docu.writeAttribute("Size", ps.name()); // legacy for Scribus < 1.7.4
docu.writeAttribute("Orientation", page->orientation());
@@ -2065,6 +2069,8 @@
SetItemProps(docu, item, baseDir);
if (!item->OnMasterPage.isEmpty())
docu.writeAttribute("OnMasterPage", item->OnMasterPage);
+ if (!item->masterPageId().isNull())
+ docu.writeAttribute("OnMasterPageId", item->masterPageId().toString(QUuid::WithoutBraces));
if (!item->pixm.imgInfo.usedPath.isEmpty())
docu.writeAttribute("ImageClip", item->pixm.imgInfo.usedPath);
if (item->pixm.imgInfo.lowResType != 1)
Index: scribus/scpage.cpp
===================================================================
--- scribus/scpage.cpp (revision 27861)
+++ scribus/scpage.cpp (working copy)
@@ -121,19 +121,39 @@
m_pageName.clear();
}
+QString ScPage::masterPageName() const
+{
+ if (m_Doc && !m_appliedMasterPageId.isNull())
+ {
+ const QString name = m_Doc->masterPageName(m_appliedMasterPageId);
+ if (!name.isEmpty())
+ return name;
+ }
+ return m_masterPageName;
+}
+
void ScPage::setMasterPageName(const QString& newName)
{
m_masterPageName = newName;
+ if (newName.isEmpty())
+ m_appliedMasterPageId = QUuid();
+ else if (m_Doc)
+ {
+ const QUuid id = m_Doc->masterPageId(newName);
+ if (!id.isNull())
+ m_appliedMasterPageId = id;
+ }
}
void ScPage::setMasterPageNameNormal()
{
- m_masterPageName = CommonStrings::trMasterPageNormal;
+ setMasterPageName(CommonStrings::trMasterPageNormal);
}
void ScPage::clearMasterPageName()
{
m_masterPageName.clear();
+ m_appliedMasterPageId = QUuid();
}
void ScPage::setSize(const QString& newSize)
Index: scribus/scpage.h
===================================================================
--- scribus/scpage.h (revision 27861)
+++ scribus/scpage.h (working copy)
@@ -30,6 +30,7 @@
#include <QPair>
#include <QRectF>
#include <QString>
+#include <QUuid>
#include "guidemanagercore.h"
#include "scribusapi.h"
@@ -89,9 +90,13 @@
bool pageNameEmpty() const {return m_pageName.isEmpty();}
void setPageName(const QString& newName);
void resetPageName();
- const QString& masterPageName() const {return m_masterPageName;}
- bool masterPageNameEmpty() const {return m_masterPageName.isEmpty();}
+ QString masterPageName() const;
+ bool masterPageNameEmpty() const { return m_appliedMasterPageId.isNull() && m_masterPageName.isEmpty(); }
void setMasterPageName(const QString& newName);
+ const QUuid& masterPageId() const { return m_masterPageId; }
+ void setMasterPageId(const QUuid& id) { m_masterPageId = id; }
+ const QUuid& appliedMasterPageId() const { return m_appliedMasterPageId; }
+ void setAppliedMasterPageId(const QUuid& id) { m_appliedMasterPageId = id; }
void setMasterPageNameNormal();
void clearMasterPageName();
const QString& size() const {return m_pageSize;}
@@ -130,6 +135,8 @@
//! Name of this page, currently only allowed to be used by a master page
QString m_pageName;
QString m_masterPageName;
+ QUuid m_masterPageId;
+ QUuid m_appliedMasterPageId;
QString m_pageSize;
QString m_pageSectionNumber;
ScribusDoc* m_Doc {nullptr};
Index: scribus/scribus.cpp
===================================================================
--- scribus/scribus.cpp (revision 27861)
+++ scribus/scribus.cpp (working copy)
@@ -6167,6 +6167,8 @@
ss->set("PAGENR", a + 1);
ss->set("PAGENAME", doc->Pages->at(a)->pageName());
ss->set("MASTERPAGE", doc->Pages->at(a)->masterPageName());
+ ss->set("MASTER_PAGE_ID", doc->Pages->at(a)->masterPageId().toString(QUuid::WithoutBraces));
+ ss->set("APPLIED_MASTER_PAGE_ID", doc->Pages->at(a)->appliedMasterPageId().toString(QUuid::WithoutBraces));
ss->set("MASTER_PAGE_MODE", doc->masterPageMode());
// replace the deleted page in the undostack by a dummy object that will
// replaced with the "undone" page if user choose to undo the action
@@ -7958,10 +7960,16 @@
if (savedMasterPageMode)
{
slotNewMasterPage(wo, pageName);
+ const QUuid restoredId(state->get("MASTER_PAGE_ID"));
+ if (!restoredId.isNull())
+ doc->Pages->at(pagenr - 1)->setMasterPageId(restoredId);
}
else
{
addNewPages(wo, where, 1, doc->pageHeight(), doc->pageWidth(), doc->pageOrientation(), doc->pageSize(), true, &tmpl);
+ const QUuid restoredId(state->get("APPLIED_MASTER_PAGE_ID"));
+ if (!restoredId.isNull())
+ doc->Pages->at(pagenr - 1)->setAppliedMasterPageId(restoredId);
}
UndoObject *tmp =
m_undoManager->replaceObject(state->getUInt("DUMMY_ID"), doc->Pages->at(pagenr - 1));
Index: scribus/scribusdoc.cpp
===================================================================
--- scribus/scribusdoc.cpp (revision 27861)
+++ scribus/scribusdoc.cpp (working copy)
@@ -2073,7 +2073,7 @@
}
else
{
- ScPage* Mpage = addMasterPage(pageNr, pageName);
+ ScPage* Mpage = addMasterPage(pageNr, pageName, QUuid(ss->get("MASTERPAGE_ID")));
setCurrentPage(Mpage);
UndoObject *tmp = m_undoManager->replaceObject(
ss->getUInt("DUMMY_ID"), Pages->at(MasterNames[pageName]));
@@ -2745,7 +2745,7 @@
}
-ScPage* ScribusDoc::addMasterPage(int pageNumber, const QString& pageName)
+ScPage* ScribusDoc::addMasterPage(int pageNumber, const QString& pageName, const QUuid& masterId)
{
ScPage* addedPage = new ScPage(m_docPrefsData.displayPrefs.scratch.left(), m_docPrefsData.displayPrefs.scratch.top(), m_docPrefsData.docSetupPrefs.pageWidth, m_docPrefsData.docSetupPrefs.pageHeight);
assert(addedPage != nullptr);
@@ -2761,9 +2761,14 @@
pgN = MasterPages.count();
addedPage->setPageName(pageName);
addedPage->setPageNr(pgN);
+ QUuid id = masterId;
+ if (id.isNull() || MasterPageIds.contains(id))
+ id = QUuid::createUuid();
+ addedPage->setMasterPageId(id);
MasterNames.insert(pageName, pgN);
MasterPages.insert(pgN, addedPage);
assert(MasterPages.at(pgN) != nullptr);
+ rebuildMasterNames();
if (!isLoading())
{
changed();
@@ -2775,6 +2780,7 @@
ss->set("MASTERPAGE_ADD");
ss->set("MASTERPAGE_NAME", pageName);
ss->set("MASTERPAGE_NBR", pgN);
+ ss->set("MASTERPAGE_ID", id.toString(QUuid::WithoutBraces));
m_undoManager->action(this, ss);
}
return addedPage;
@@ -2783,36 +2789,40 @@
bool ScribusDoc::renameMasterPage(const QString& oldPageName, const QString& newPageName)
{
- Q_ASSERT(oldPageName != CommonStrings::masterPageNormal && oldPageName != CommonStrings::trMasterPageNormal);
- if (!MasterNames.contains(oldPageName) || MasterNames.contains(newPageName))
+ if (!MasterNames.contains(oldPageName))
return false;
+ return renameMasterPage(masterPageId(oldPageName), newPageName);
+}
+
+bool ScribusDoc::renameMasterPage(const QUuid& masterId, const QString& newPageName)
+{
+ const int number = masterPageIndex(masterId);
+ if (number < 0 || MasterNames.contains(newPageName))
+ return false;
+
+ const QString oldPageName = MasterPages.at(number)->pageName();
+ Q_ASSERT(oldPageName != CommonStrings::masterPageNormal && oldPageName != CommonStrings::trMasterPageNormal);
- //Rename our master page lists
- int number = MasterNames[oldPageName];
- MasterNames.insert(newPageName, number);
MasterNames.remove(oldPageName);
- Q_ASSERT(MasterPages.at(number)->pageName() == oldPageName);
+ MasterNames.insert(newPageName, number);
MasterPages.at(number)->setPageName(newPageName);
- //Update any pages that were linking to our old name
- ScPage* docPage = nullptr;
- for (int i = 0; i < DocPages.count(); ++i)
- {
- docPage = DocPages[i];
- if (docPage->masterPageName() == oldPageName)
- docPage->setMasterPageName(newPageName);
- }
- //Update any items that were linking to our old name
- int masterItemsCount = MasterItems.count();
- for (int i = 0; i < masterItemsCount; ++i)
+
+ // Master item names remain as a compatibility mirror for legacy code and files.
+ for (PageItem* item : std::as_const(MasterItems))
{
- if (MasterItems.at(i)->OnMasterPage == oldPageName)
- MasterItems.at(i)->setMasterPageName(newPageName);
+ if (item->masterPageId() == masterId || (item->masterPageId().isNull() && item->OnMasterPage == oldPageName))
+ {
+ item->setMasterPageId(masterId);
+ item->setMasterPageName(newPageName);
+ }
}
+
changed();
if (UndoManager::undoEnabled())
{
- auto*ss = new SimpleState(Um::RenameMasterPage, "", Um::IDocument);
+ auto* ss = new SimpleState(Um::RenameMasterPage, "", Um::IDocument);
ss->set("MASTERPAGE_RENAME");
+ ss->set("MASTERPAGE_ID", masterId.toString(QUuid::WithoutBraces));
ss->set("OLD_MASTERPAGE", oldPageName);
ss->set("NEW_MASTERPAGE", newPageName);
m_undoManager->action(this, ss);
@@ -2837,6 +2847,7 @@
if (MasterItems.at(i)->OwnPage > pageNumber)
MasterItems.at(i)->OwnPage--;
}
+ rebuildMasterNames();
changed();
}
@@ -2844,8 +2855,35 @@
void ScribusDoc::rebuildMasterNames()
{
MasterNames.clear();
+ MasterPageIds.clear();
for (int i = 0; i < MasterPages.count(); ++i)
- MasterNames[MasterPages.at(i)->pageName()] = i;
+ {
+ ScPage* master = MasterPages.at(i);
+ if (master->masterPageId().isNull() || MasterPageIds.contains(master->masterPageId()))
+ master->setMasterPageId(QUuid::createUuid());
+ MasterNames[master->pageName()] = i;
+ MasterPageIds[master->masterPageId()] = i;
+ }
+}
+
+QUuid ScribusDoc::masterPageId(const QString& pageName) const
+{
+ auto it = MasterNames.constFind(pageName);
+ if (it == MasterNames.constEnd() || it.value() < 0 || it.value() >= MasterPages.count())
+ return QUuid();
+ return MasterPages.at(it.value())->masterPageId();
+}
+
+QString ScribusDoc::masterPageName(const QUuid& masterId) const
+{
+ const int index = masterPageIndex(masterId);
+ return index >= 0 ? MasterPages.at(index)->pageName() : QString();
+}
+
+int ScribusDoc::masterPageIndex(const QUuid& masterId) const
+{
+ auto it = MasterPageIds.constFind(masterId);
+ return it == MasterPageIds.constEnd() ? -1 : it.value();
}
@@ -4849,8 +4887,15 @@
bool ScribusDoc::applyMasterPage(const QString& pageName, int pageNumber)
{
- if (!MasterNames.contains(pageName))
+ return applyMasterPage(masterPageId(pageName), pageNumber);
+}
+
+bool ScribusDoc::applyMasterPage(const QUuid& masterId, int pageNumber)
+{
+ const int MpNr = masterPageIndex(masterId);
+ if (MpNr < 0)
return false;
+ const QString pageName = MasterPages.at(MpNr)->pageName();
if (UndoManager::undoEnabled())
{
@@ -4860,12 +4905,14 @@
ss->set("PAGE_NUMBER", pageNumber);
ss->set("OLD_MASTERPAGE", DocPages.at(pageNumber)->masterPageName());
ss->set("NEW_MASTERPAGE", pageName);
+ ss->set("OLD_MASTERPAGE_ID", DocPages.at(pageNumber)->appliedMasterPageId().toString(QUuid::WithoutBraces));
+ ss->set("NEW_MASTERPAGE_ID", masterId.toString(QUuid::WithoutBraces));
m_undoManager->action(this, ss);
}
}
ScPage* Ap = DocPages.at(pageNumber);
Ap->setMasterPageName(pageName);
- const int MpNr = MasterNames[pageName];
+ Ap->setAppliedMasterPageId(masterId);
const ScPage* Mp = MasterPages.at(MpNr);
PageItem *currItem;
Ap->FromMaster.clear();
@@ -4948,12 +4995,12 @@
void ScribusDoc::restoreMasterPageApplying(SimpleState* ss, bool isUndo)
{
int pageNumber = ss->getInt("PAGE_NUMBER");
- QString oldName = ss->get("OLD_MASTERPAGE");
- QString newName = ss->get("NEW_MASTERPAGE");
+ const QUuid oldId(ss->get("OLD_MASTERPAGE_ID"));
+ const QUuid newId(ss->get("NEW_MASTERPAGE_ID"));
if (isUndo)
- applyMasterPage(oldName, pageNumber);
+ applyMasterPage(oldId.isNull() ? masterPageId(ss->get("OLD_MASTERPAGE")) : oldId, pageNumber);
else
- applyMasterPage(newName, pageNumber);
+ applyMasterPage(newId.isNull() ? masterPageId(ss->get("NEW_MASTERPAGE")) : newId, pageNumber);
reformPages();
scMW()->pagePalette->rebuildPages();
}
@@ -4962,7 +5009,10 @@
{
QString oldName = ss->get("OLD_MASTERPAGE");
QString newName = ss->get("NEW_MASTERPAGE");
- if (isUndo)
+ const QUuid masterId(ss->get("MASTERPAGE_ID"));
+ if (!masterId.isNull())
+ renameMasterPage(masterId, isUndo ? oldName : newName);
+ else if (isUndo)
renameMasterPage(newName, oldName);
else
renameMasterPage(oldName, newName);
Index: scribus/scribusdoc.h
===================================================================
--- scribus/scribusdoc.h (revision 27861)
+++ scribus/scribusdoc.h (working copy)
@@ -261,14 +261,18 @@
ScPage* addPage(int pageNumber, const QString& masterPageName = QString(), bool addAutoFrame = false);
void deletePage(int);
//! @brief Add a master page with this function, do not use addPage
- ScPage* addMasterPage(int, const QString&);
+ ScPage* addMasterPage(int, const QString&, const QUuid& masterId = QUuid());
void deleteMasterPage(int);
//! @brief Rebuild master name list
void rebuildMasterNames();
+ QUuid masterPageId(const QString& pageName) const;
+ QString masterPageName(const QUuid& masterId) const;
+ int masterPageIndex(const QUuid& masterId) const;
//! @brief Replace a master page by default one
void replaceMasterPage(const QString& oldMasterPage);
//! @brief Rename a master page
bool renameMasterPage(const QString& oldPageName, const QString& newPageName);
+ bool renameMasterPage(const QUuid& masterId, const QString& newPageName);
//! @brief Create the default master pages based on the layout selected by the user, ie, Normal, Normal Left, etc.
void createDefaultMasterPages();
//! @brief Create the requested pages in a new document, run after createDefaultMasterPages()
@@ -834,6 +838,7 @@
* @brief Apply a master page
*/
bool applyMasterPage(const QString& pageName, int pageNumber);
+ bool applyMasterPage(const QUuid& masterId, int pageNumber);
/**
* @brief Undo function for applying a master page
*/
@@ -1410,6 +1415,7 @@
QList<ScPage*> TempPages;
/** \brief Mapping Master Page Name to Master Page numbers */
QMap<QString,int> MasterNames;
+ QHash<QUuid, int> MasterPageIds;
/** \brief List of Objects */
//! Items is a pointer to the lists of items that exist in a document. In Normal mode, it points to DocItems. In Master Page mode it points to MasterItems. See ScribusDoc::assignPageModeLists()
QList<PageItem*>* Items {nullptr};
| ||||
| Patch | Yes | ||||
|
|
Here is an update. ## MID v1.01 — Hardening changes (since v1.0) - Baseline: r27895 - ID/name consistency: Clear stale IDs when master-name resolution fails; keep stored master-name references synchronised after renaming. - Load-time reconciliation: Validate master references against available IDs and names; improve recovery from missing, invalid or duplicate IDs. - Master import: Resolve imported master objects to the destination master's ID instead of retaining foreign IDs. - Nested objects: Use ID-aware setters for grouped items and table-cell text frames, keeping their master ownership consistent. - Undo/redo: Preserve master identity through an additional master-page restoration path. - Code quality: Reuse existing ID-aware setters and retain the established MID architecture without introducing new abstractions. mid-foundation-v1.01.patch (24,797 bytes)
Index: scribus/pageitem.cpp
===================================================================
--- scribus/pageitem.cpp (revision 27895)
+++ scribus/pageitem.cpp (working copy)
@@ -218,6 +218,7 @@
BoundingH(other.BoundingH),
ChangedMasterItem(other.ChangedMasterItem),
OnMasterPage(other.OnMasterPage),
+ m_masterPageId(other.m_masterPageId),
isEmbedded(other.isEmbedded),
m_roundedCornerRadius(other.m_roundedCornerRadius),
oldXpos(other.oldXpos),
@@ -657,6 +658,8 @@
m_columnGap = m_Doc->itemToolPrefs().textColumnGap;
OnMasterPage = m_Doc->currentPage() ? m_Doc->currentPage()->pageName() : QString();
+ if (m_Doc->currentPage())
+ m_masterPageId = m_Doc->currentPage()->masterPageId();
m_startArrowIndex = m_Doc->itemToolPrefs().lineStartArrow;
m_endArrowIndex = m_Doc->itemToolPrefs().lineEndArrow;
effectsInUse.clear();
@@ -2399,6 +2402,20 @@
firstVal = (*it2);
}
p->drawPolygon(pts.constData() + firstVal, pts.size() - firstVal);
+}
+
+
+void PageItem::setMasterPage(int page, const QString& mpName)
+{
+ OwnPage = page;
+ OnMasterPage = mpName;
+ m_masterPageId = m_Doc ? m_Doc->masterPageId(mpName) : QUuid();
+}
+
+void PageItem::setMasterPageName(const QString& mpName)
+{
+ OnMasterPage = mpName;
+ m_masterPageId = m_Doc ? m_Doc->masterPageId(mpName) : QUuid();
}
void PageItem::setItemName(const QString& newName)
Index: scribus/pageitem.h
===================================================================
--- scribus/pageitem.h (revision 27895)
+++ scribus/pageitem.h (working copy)
@@ -37,6 +37,7 @@
#include <QRectF>
#include <QString>
#include <QVector>
+#include <QUuid>
#include <QTemporaryFile>
#include "scribusapi.h"
@@ -837,13 +838,15 @@
* @brief Set the masterpage the object is on
* @param mpName name of the master page
*/
- virtual void setMasterPage(int page, const QString& mpName) { OwnPage = page; OnMasterPage = mpName; }
+ virtual void setMasterPage(int page, const QString& mpName);
+ const QUuid& masterPageId() const { return m_masterPageId; }
+ void setMasterPageId(const QUuid& id) { m_masterPageId = id; }
/**
* @brief Set the masterpage the object is on
* @param mpName name of the master page
*/
- virtual void setMasterPageName(const QString& mpName) { OnMasterPage = mpName; }
+ virtual void setMasterPageName(const QString& mpName);
/**
* @brief Set the page "owning" the object
@@ -1442,6 +1445,7 @@
double BoundingH;
bool ChangedMasterItem {false};
QString OnMasterPage;
+ QUuid m_masterPageId;
bool isEmbedded {false};
int inlineCharID {0};
/** Radius of rounded corners */
Index: scribus/pageitem_table.cpp
===================================================================
--- scribus/pageitem_table.cpp (revision 27895)
+++ scribus/pageitem_table.cpp (working copy)
@@ -452,8 +452,7 @@
if (cell.row() == row && cell.column() == col)
{
PageItem* textFrame = cell.textFrame();
- textFrame->OwnPage = page;
- textFrame->OnMasterPage = mpName;
+ textFrame->setMasterPage(page, mpName);
}
}
}
@@ -474,7 +473,7 @@
if (cell.row() == row && cell.column() == col)
{
PageItem* textFrame = cell.textFrame();
- textFrame->OnMasterPage = mpName;
+ textFrame->setMasterPageName(mpName);
}
}
}
Index: scribus/plugins/fileloader/scribus171format/scribus171format.cpp
===================================================================
--- scribus/plugins/fileloader/scribus171format/scribus171format.cpp (revision 27895)
+++ scribus/plugins/fileloader/scribus171format/scribus171format.cpp (working copy)
@@ -4814,7 +4814,8 @@
bool savedMasterPageMode = m_Doc->masterPageMode();
m_Doc->setMasterPageMode(!pageName.isEmpty());
- ScPage* newPage = pageName.isEmpty() ? doc->addPage(pageNum) : doc->addMasterPage(pageNum, pageName);
+ const QUuid storedMasterId(attrs.valueAsString("MasterPageId"));
+ ScPage* newPage = pageName.isEmpty() ? doc->addPage(pageNum) : doc->addMasterPage(pageNum, pageName, storedMasterId);
//Remove uppercase in 1.8
if (attrs.hasAttribute("LEFT"))
@@ -4828,6 +4829,13 @@
else
mpName = attrs.valueAsString("MasterPageName", "Normal");
newPage->setMasterPageName(m_Doc->masterPageMode() ? QString() : mpName);
+ if (!m_Doc->masterPageMode())
+ {
+ QUuid appliedId(attrs.valueAsString("AppliedMasterPageId"));
+ if (appliedId.isNull())
+ appliedId = doc->masterPageId(mpName);
+ newPage->setAppliedMasterPageId(appliedId);
+ }
if (attrs.hasAttribute("Size"))
newPage->setSize(attrs.valueAsString("Size"));
if (attrs.hasAttribute("Orientation"))
@@ -4991,6 +4999,16 @@
clipPath.clear();
PageItem* newItem = pasteItem(doc, attrs, readObjectParams.baseDir, itemKind, pageNr);
+ QUuid itemMasterId(attrs.valueAsString("OnMasterPageId"));
+ if (tagName == QLatin1String("MASTEROBJECT") || tagName == QLatin1String("MasterObject"))
+ {
+ // Always bind a loaded/imported master object to the destination master.
+ // An ID from another document must not be used as its owner.
+ const QUuid destinationId = doc->masterPageId(masterPageName);
+ if (!destinationId.isNull())
+ itemMasterId = destinationId;
+ }
+ newItem->setMasterPageId(itemMasterId);
newItem->setRedrawBounding();
if (tagName == QLatin1String("MASTEROBJECT") || tagName == QLatin1String("MasterObject"))
newItem->setOwnerPage(doc->OnPage(newItem));
@@ -5345,8 +5363,7 @@
newItem->groupItemList.append(currItem);
currItem->Parent = newItem;
currItem->m_layerID = newItem->m_layerID;
- currItem->OwnPage = newItem->OwnPage;
- currItem->OnMasterPage = newItem->OnMasterPage;
+ currItem->setMasterPage(newItem->OwnPage, newItem->OnMasterPage);
}
doc->Items = docItems;
}
@@ -8493,8 +8510,8 @@
newItem->setOwnerPage(m_Doc->currentPageNumber());
if (tagName == QLatin1String("PAGEOBJECT") || tagName == QLatin1String("PageObject"))
newItem->setMasterPageName(QString());
- else if (Mpage && !renamedPageName.isEmpty())
- newItem->setMasterPageName(renamedPageName);
+ else if (Mpage)
+ newItem->setMasterPageName(newPage->pageName());
newItem->setLayer(layerTrans.value(newItem->m_layerID, newItem->m_layerID));
if (isNewFormat)
{
Index: scribus/plugins/fileloader/scribus171format/scribus171format_save.cpp
===================================================================
--- scribus/plugins/fileloader/scribus171format/scribus171format_save.cpp (revision 27895)
+++ scribus/plugins/fileloader/scribus171format/scribus171format_save.cpp (working copy)
@@ -1796,6 +1796,10 @@
docu.writeAttribute("PageNumber",page->pageNr());
docu.writeAttribute("PageName",page->pageName());
docu.writeAttribute("MasterPageName",page->masterPageName());
+ if (!page->masterPageId().isNull())
+ docu.writeAttribute("MasterPageId", page->masterPageId().toString(QUuid::WithoutBraces));
+ if (!page->appliedMasterPageId().isNull())
+ docu.writeAttribute("AppliedMasterPageId", page->appliedMasterPageId().toString(QUuid::WithoutBraces));
PageSize ps(page->width(), page->height());
docu.writeAttribute("Size", ps.name()); // legacy for Scribus < 1.7.4
docu.writeAttribute("Orientation", page->orientation());
@@ -2065,6 +2069,8 @@
SetItemProps(docu, item, baseDir);
if (!item->OnMasterPage.isEmpty())
docu.writeAttribute("OnMasterPage", item->OnMasterPage);
+ if (!item->masterPageId().isNull())
+ docu.writeAttribute("OnMasterPageId", item->masterPageId().toString(QUuid::WithoutBraces));
if (!item->pixm.imgInfo.usedPath.isEmpty())
docu.writeAttribute("ImageClip", item->pixm.imgInfo.usedPath);
if (item->pixm.imgInfo.lowResType != 1)
Index: scribus/scpage.cpp
===================================================================
--- scribus/scpage.cpp (revision 27895)
+++ scribus/scpage.cpp (working copy)
@@ -121,19 +121,32 @@
m_pageName.clear();
}
+QString ScPage::masterPageName() const
+{
+ if (m_Doc && !m_appliedMasterPageId.isNull())
+ {
+ const QString name = m_Doc->masterPageName(m_appliedMasterPageId);
+ if (!name.isEmpty())
+ return name;
+ }
+ return m_masterPageName;
+}
+
void ScPage::setMasterPageName(const QString& newName)
{
m_masterPageName = newName;
+ m_appliedMasterPageId = m_Doc ? m_Doc->masterPageId(newName) : QUuid();
}
void ScPage::setMasterPageNameNormal()
{
- m_masterPageName = CommonStrings::trMasterPageNormal;
+ setMasterPageName(CommonStrings::trMasterPageNormal);
}
void ScPage::clearMasterPageName()
{
m_masterPageName.clear();
+ m_appliedMasterPageId = QUuid();
}
void ScPage::setSize(const QString& newSize)
Index: scribus/scpage.h
===================================================================
--- scribus/scpage.h (revision 27895)
+++ scribus/scpage.h (working copy)
@@ -30,6 +30,7 @@
#include <QPair>
#include <QRectF>
#include <QString>
+#include <QUuid>
#include "guidemanagercore.h"
#include "scribusapi.h"
@@ -89,9 +90,14 @@
bool pageNameEmpty() const {return m_pageName.isEmpty();}
void setPageName(const QString& newName);
void resetPageName();
- const QString& masterPageName() const {return m_masterPageName;}
- bool masterPageNameEmpty() const {return m_masterPageName.isEmpty();}
+ QString masterPageName() const;
+ const QString& storedMasterPageName() const { return m_masterPageName; }
+ bool masterPageNameEmpty() const { return m_appliedMasterPageId.isNull() && m_masterPageName.isEmpty(); }
void setMasterPageName(const QString& newName);
+ const QUuid& masterPageId() const { return m_masterPageId; }
+ void setMasterPageId(const QUuid& id) { m_masterPageId = id; }
+ const QUuid& appliedMasterPageId() const { return m_appliedMasterPageId; }
+ void setAppliedMasterPageId(const QUuid& id) { m_appliedMasterPageId = id; }
void setMasterPageNameNormal();
void clearMasterPageName();
const QString& size() const {return m_pageSize;}
@@ -130,6 +136,8 @@
//! Name of this page, currently only allowed to be used by a master page
QString m_pageName;
QString m_masterPageName;
+ QUuid m_masterPageId;
+ QUuid m_appliedMasterPageId;
QString m_pageSize;
QString m_pageSectionNumber;
ScribusDoc* m_Doc {nullptr};
Index: scribus/scribus.cpp
===================================================================
--- scribus/scribus.cpp (revision 27895)
+++ scribus/scribus.cpp (working copy)
@@ -3728,6 +3728,8 @@
doc->setFirstSectionFromFirstPageNumber();
}
doc->RePos = true;
+ doc->rebuildMasterNames();
+ doc->reconcileMasterPageReferences();
doc->setMasterPageMode(true);
doc->reformPages();
doc->refreshGuides();
@@ -6198,6 +6200,8 @@
ss->set("PAGENR", a + 1);
ss->set("PAGENAME", doc->Pages->at(a)->pageName());
ss->set("MASTERPAGE", doc->Pages->at(a)->masterPageName());
+ ss->set("MASTER_PAGE_ID", doc->Pages->at(a)->masterPageId().toString(QUuid::WithoutBraces));
+ ss->set("APPLIED_MASTER_PAGE_ID", doc->Pages->at(a)->appliedMasterPageId().toString(QUuid::WithoutBraces));
ss->set("MASTER_PAGE_MODE", doc->masterPageMode());
// replace the deleted page in the undostack by a dummy object that will
// replaced with the "undone" page if user choose to undo the action
@@ -7986,10 +7990,16 @@
if (savedMasterPageMode)
{
slotNewMasterPage(wo, pageName);
+ const QUuid restoredId(state->get("MASTER_PAGE_ID"));
+ if (!restoredId.isNull())
+ doc->Pages->at(pagenr - 1)->setMasterPageId(restoredId);
}
else
{
addNewPages(wo, where, 1, doc->pageHeight(), doc->pageWidth(), doc->pageOrientation(), doc->pageSize(), true, &tmpl);
+ const QUuid restoredId(state->get("APPLIED_MASTER_PAGE_ID"));
+ if (!restoredId.isNull())
+ doc->Pages->at(pagenr - 1)->setAppliedMasterPageId(restoredId);
}
UndoObject *tmp =
m_undoManager->replaceObject(state->getUInt("DUMMY_ID"), doc->Pages->at(pagenr - 1));
@@ -8055,6 +8065,8 @@
if (isUndo)
{
+ if (savedMasterPageMode && delFrom > 0 && delFrom <= doc->Pages->count())
+ state->set("ADDED_MASTER_ID", doc->Pages->at(delFrom - 1)->masterPageId().toString(QUuid::WithoutBraces));
for (int i = delFrom - 1; i < delTo; ++i)
{
auto *duo = new DummyUndoObject();
@@ -8073,6 +8085,9 @@
{
assert (count == 1);
slotNewMasterPage(wo, based[0]);
+ const QUuid id(state->get("ADDED_MASTER_ID"));
+ if (!id.isNull() && delFrom > 0 && delFrom <= doc->Pages->count())
+ doc->Pages->at(delFrom - 1)->setMasterPageId(id);
}
else
{
Index: scribus/scribusdoc.cpp
===================================================================
--- scribus/scribusdoc.cpp (revision 27895)
+++ scribus/scribusdoc.cpp (working copy)
@@ -2084,7 +2084,7 @@
}
else
{
- ScPage* Mpage = addMasterPage(pageNr, pageName);
+ ScPage* Mpage = addMasterPage(pageNr, pageName, QUuid(ss->get("MASTERPAGE_ID")));
setCurrentPage(Mpage);
UndoObject *tmp = m_undoManager->replaceObject(
ss->getUInt("DUMMY_ID"), Pages->at(MasterNames[pageName]));
@@ -2756,7 +2756,7 @@
}
-ScPage* ScribusDoc::addMasterPage(int pageNumber, const QString& pageName)
+ScPage* ScribusDoc::addMasterPage(int pageNumber, const QString& pageName, const QUuid& masterId)
{
ScPage* addedPage = new ScPage(m_docPrefsData.displayPrefs.scratch.left(), m_docPrefsData.displayPrefs.scratch.top(), m_docPrefsData.docSetupPrefs.pageWidth, m_docPrefsData.docSetupPrefs.pageHeight);
assert(addedPage != nullptr);
@@ -2772,9 +2772,14 @@
pgN = MasterPages.count();
addedPage->setPageName(pageName);
addedPage->setPageNr(pgN);
+ QUuid id = masterId;
+ if (id.isNull() || MasterPageIds.contains(id))
+ id = QUuid::createUuid();
+ addedPage->setMasterPageId(id);
MasterNames.insert(pageName, pgN);
MasterPages.insert(pgN, addedPage);
assert(MasterPages.at(pgN) != nullptr);
+ rebuildMasterNames();
if (!isLoading())
{
changed();
@@ -2786,6 +2791,7 @@
ss->set("MASTERPAGE_ADD");
ss->set("MASTERPAGE_NAME", pageName);
ss->set("MASTERPAGE_NBR", pgN);
+ ss->set("MASTERPAGE_ID", id.toString(QUuid::WithoutBraces));
m_undoManager->action(this, ss);
}
return addedPage;
@@ -2794,36 +2800,48 @@
bool ScribusDoc::renameMasterPage(const QString& oldPageName, const QString& newPageName)
{
+ if (!MasterNames.contains(oldPageName))
+ return false;
+ return renameMasterPage(masterPageId(oldPageName), newPageName);
+}
+
+bool ScribusDoc::renameMasterPage(const QUuid& masterId, const QString& newPageName)
+{
+ const int number = masterPageIndex(masterId);
+ if (number < 0 || MasterNames.contains(newPageName))
+ return false;
+
+ const QString oldPageName = MasterPages.at(number)->pageName();
Q_ASSERT(oldPageName != CommonStrings::masterPageNormal && oldPageName != CommonStrings::trMasterPageNormal);
- if (!MasterNames.contains(oldPageName) || MasterNames.contains(newPageName))
- return false;
-
- //Rename our master page lists
- int number = MasterNames[oldPageName];
+
+ MasterNames.remove(oldPageName);
MasterNames.insert(newPageName, number);
- MasterNames.remove(oldPageName);
- Q_ASSERT(MasterPages.at(number)->pageName() == oldPageName);
MasterPages.at(number)->setPageName(newPageName);
- //Update any pages that were linking to our old name
- ScPage* docPage = nullptr;
- for (int i = 0; i < DocPages.count(); ++i)
- {
- docPage = DocPages[i];
- if (docPage->masterPageName() == oldPageName)
- docPage->setMasterPageName(newPageName);
- }
- //Update any items that were linking to our old name
- int masterItemsCount = MasterItems.count();
- for (int i = 0; i < masterItemsCount; ++i)
- {
- if (MasterItems.at(i)->OnMasterPage == oldPageName)
- MasterItems.at(i)->setMasterPageName(newPageName);
- }
+
+ // Keep the persisted name mirror consistent with its master ID.
+ for (ScPage* page : std::as_const(DocPages))
+ {
+ if (page->appliedMasterPageId() == masterId ||
+ (page->appliedMasterPageId().isNull() && page->storedMasterPageName() == oldPageName))
+ page->setMasterPageName(newPageName);
+ }
+
+ // Master item names remain as a compatibility mirror for legacy code and files.
+ for (PageItem* item : std::as_const(MasterItems))
+ {
+ if (item->masterPageId() == masterId || (item->masterPageId().isNull() && item->OnMasterPage == oldPageName))
+ {
+ item->setMasterPageId(masterId);
+ item->setMasterPageName(newPageName);
+ }
+ }
+
changed();
if (UndoManager::undoEnabled())
{
- auto*ss = new SimpleState(Um::RenameMasterPage, "", Um::IDocument);
+ auto* ss = new SimpleState(Um::RenameMasterPage, "", Um::IDocument);
ss->set("MASTERPAGE_RENAME");
+ ss->set("MASTERPAGE_ID", masterId.toString(QUuid::WithoutBraces));
ss->set("OLD_MASTERPAGE", oldPageName);
ss->set("NEW_MASTERPAGE", newPageName);
m_undoManager->action(this, ss);
@@ -2848,6 +2866,7 @@
if (MasterItems.at(i)->OwnPage > pageNumber)
MasterItems.at(i)->OwnPage--;
}
+ rebuildMasterNames();
changed();
}
@@ -2855,8 +2874,67 @@
void ScribusDoc::rebuildMasterNames()
{
MasterNames.clear();
+ MasterPageIds.clear();
for (int i = 0; i < MasterPages.count(); ++i)
- MasterNames[MasterPages.at(i)->pageName()] = i;
+ {
+ ScPage* master = MasterPages.at(i);
+ if (master->masterPageId().isNull() || MasterPageIds.contains(master->masterPageId()))
+ master->setMasterPageId(QUuid::createUuid());
+ MasterNames[master->pageName()] = i;
+ MasterPageIds[master->masterPageId()] = i;
+ }
+}
+
+void ScribusDoc::reconcileMasterPageReferences()
+{
+ // The names are retained in SLA for compatibility and for recovery from
+ // duplicate or invalid IDs. This is run after all master pages are loaded.
+ auto resolveId = [this](const QUuid& savedId, const QString& savedName) -> QUuid {
+ const int index = masterPageIndex(savedId);
+ if (index >= 0 && (savedName.isEmpty() ||
+ MasterPages.at(index)->pageName() == savedName || !MasterNames.contains(savedName)))
+ return savedId;
+ return masterPageId(savedName);
+ };
+
+ for (ScPage* page : std::as_const(DocPages))
+ {
+ const QString name = page->storedMasterPageName();
+ const QUuid id = resolveId(page->appliedMasterPageId(), name);
+ if (!id.isNull())
+ page->setMasterPageName(masterPageName(id));
+ else
+ page->setMasterPageName(name); // Keep the legacy name, not a dangling ID.
+ }
+
+ for (PageItem* item : std::as_const(MasterItems))
+ {
+ const QUuid id = resolveId(item->masterPageId(), item->OnMasterPage);
+ if (!id.isNull())
+ item->setMasterPageName(masterPageName(id));
+ else
+ item->setMasterPageName(item->OnMasterPage);
+ }
+}
+
+QUuid ScribusDoc::masterPageId(const QString& pageName) const
+{
+ auto it = MasterNames.constFind(pageName);
+ if (it == MasterNames.constEnd() || it.value() < 0 || it.value() >= MasterPages.count())
+ return QUuid();
+ return MasterPages.at(it.value())->masterPageId();
+}
+
+QString ScribusDoc::masterPageName(const QUuid& masterId) const
+{
+ const int index = masterPageIndex(masterId);
+ return index >= 0 ? MasterPages.at(index)->pageName() : QString();
+}
+
+int ScribusDoc::masterPageIndex(const QUuid& masterId) const
+{
+ auto it = MasterPageIds.constFind(masterId);
+ return it == MasterPageIds.constEnd() ? -1 : it.value();
}
@@ -4860,8 +4938,15 @@
bool ScribusDoc::applyMasterPage(const QString& pageName, int pageNumber)
{
- if (!MasterNames.contains(pageName))
+ return applyMasterPage(masterPageId(pageName), pageNumber);
+}
+
+bool ScribusDoc::applyMasterPage(const QUuid& masterId, int pageNumber)
+{
+ const int MpNr = masterPageIndex(masterId);
+ if (MpNr < 0)
return false;
+ const QString pageName = MasterPages.at(MpNr)->pageName();
if (UndoManager::undoEnabled())
{
@@ -4871,12 +4956,14 @@
ss->set("PAGE_NUMBER", pageNumber);
ss->set("OLD_MASTERPAGE", DocPages.at(pageNumber)->masterPageName());
ss->set("NEW_MASTERPAGE", pageName);
+ ss->set("OLD_MASTERPAGE_ID", DocPages.at(pageNumber)->appliedMasterPageId().toString(QUuid::WithoutBraces));
+ ss->set("NEW_MASTERPAGE_ID", masterId.toString(QUuid::WithoutBraces));
m_undoManager->action(this, ss);
}
}
ScPage* Ap = DocPages.at(pageNumber);
Ap->setMasterPageName(pageName);
- const int MpNr = MasterNames[pageName];
+ Ap->setAppliedMasterPageId(masterId);
const ScPage* Mp = MasterPages.at(MpNr);
PageItem *currItem;
Ap->FromMaster.clear();
@@ -4959,21 +5046,24 @@
void ScribusDoc::restoreMasterPageApplying(SimpleState* ss, bool isUndo)
{
int pageNumber = ss->getInt("PAGE_NUMBER");
+ const QUuid oldId(ss->get("OLD_MASTERPAGE_ID"));
+ const QUuid newId(ss->get("NEW_MASTERPAGE_ID"));
+ if (isUndo)
+ applyMasterPage(oldId.isNull() ? masterPageId(ss->get("OLD_MASTERPAGE")) : oldId, pageNumber);
+ else
+ applyMasterPage(newId.isNull() ? masterPageId(ss->get("NEW_MASTERPAGE")) : newId, pageNumber);
+ reformPages();
+ scMW()->pagePalette->rebuildPages();
+}
+
+void ScribusDoc::restoreMasterPageRenaming(SimpleState* ss, bool isUndo)
+{
QString oldName = ss->get("OLD_MASTERPAGE");
QString newName = ss->get("NEW_MASTERPAGE");
- if (isUndo)
- applyMasterPage(oldName, pageNumber);
- else
- applyMasterPage(newName, pageNumber);
- reformPages();
- scMW()->pagePalette->rebuildPages();
-}
-
-void ScribusDoc::restoreMasterPageRenaming(SimpleState* ss, bool isUndo)
-{
- QString oldName = ss->get("OLD_MASTERPAGE");
- QString newName = ss->get("NEW_MASTERPAGE");
- if (isUndo)
+ const QUuid masterId(ss->get("MASTERPAGE_ID"));
+ if (!masterId.isNull())
+ renameMasterPage(masterId, isUndo ? oldName : newName);
+ else if (isUndo)
renameMasterPage(newName, oldName);
else
renameMasterPage(oldName, newName);
Index: scribus/scribusdoc.h
===================================================================
--- scribus/scribusdoc.h (revision 27895)
+++ scribus/scribusdoc.h (working copy)
@@ -261,14 +261,19 @@
ScPage* addPage(int pageNumber, const QString& masterPageName = QString(), bool addAutoFrame = false);
void deletePage(int);
//! @brief Add a master page with this function, do not use addPage
- ScPage* addMasterPage(int, const QString&);
+ ScPage* addMasterPage(int, const QString&, const QUuid& masterId = QUuid());
void deleteMasterPage(int);
//! @brief Rebuild master name list
void rebuildMasterNames();
+ void reconcileMasterPageReferences();
+ QUuid masterPageId(const QString& pageName) const;
+ QString masterPageName(const QUuid& masterId) const;
+ int masterPageIndex(const QUuid& masterId) const;
//! @brief Replace a master page by default one
void replaceMasterPage(const QString& oldMasterPage);
//! @brief Rename a master page
bool renameMasterPage(const QString& oldPageName, const QString& newPageName);
+ bool renameMasterPage(const QUuid& masterId, const QString& newPageName);
//! @brief Create the default master pages based on the layout selected by the user, ie, Normal, Normal Left, etc.
void createDefaultMasterPages();
//! @brief Create the requested pages in a new document, run after createDefaultMasterPages()
@@ -834,6 +839,7 @@
* @brief Apply a master page
*/
bool applyMasterPage(const QString& pageName, int pageNumber);
+ bool applyMasterPage(const QUuid& masterId, int pageNumber);
/**
* @brief Undo function for applying a master page
*/
@@ -1410,6 +1416,7 @@
QList<ScPage*> TempPages;
/** \brief Mapping Master Page Name to Master Page numbers */
QMap<QString,int> MasterNames;
+ QHash<QUuid, int> MasterPageIds;
/** \brief List of Objects */
//! Items is a pointer to the lists of items that exist in a document. In Normal mode, it points to DocItems. In Master Page mode it points to MasterItems. See ScribusDoc::assignPageModeLists()
QList<PageItem*>* Items {nullptr};
Index: scribus/tablecell.cpp
===================================================================
--- scribus/tablecell.cpp (revision 27895)
+++ scribus/tablecell.cpp (working copy)
@@ -32,8 +32,7 @@
// Create a text frame for the cell.
d->textFrame = new PageItem_TextFrame(d->table->m_Doc, 0, 0, 0, 0, 0, CommonStrings::None, CommonStrings::None);
d->textFrame->Parent = table;
- d->textFrame->OwnPage = table->OwnPage;
- d->textFrame->OnMasterPage = table->OnMasterPage;
+ d->textFrame->setMasterPage(table->OwnPage, table->OnMasterPage);
d->textFrame->m_layerID = table->m_layerID;
d->textFrame->setIsTableCellTextFrame(true);
Index: scribus/util.cpp
===================================================================
--- scribus/util.cpp (revision 27895)
+++ scribus/util.cpp (working copy)
@@ -1146,8 +1146,7 @@
PageItem_Table* currItem = m_Doc->Items->takeAt(z)->asTable();
currItem->m_layerID = gItem->m_layerID;
- currItem->OwnPage = gItem->OwnPage;
- currItem->OnMasterPage = gItem->OnMasterPage;
+ currItem->setMasterPage(gItem->OwnPage, gItem->OnMasterPage);
currItem->insertRows(0, rowHeights.count() - 1);
m_Doc->dontResize = true;
|
|
|
Here we need a commitment from the team agreeing that it's a good idea to get Scribus to rely on stable IDs and not on names that can be changed by the user (and do not change when switching the UI language). Once we have that, this type of patches are very welcome! |
| Date Modified | Username | Field | Change |
|---|---|---|---|
| 2026-09-23 12:45 | buttar | New Issue | |
| 2026-09-23 12:45 | buttar | Tag Attached: #please_test | |
| 2026-09-23 12:45 | buttar | File Added: mid-foundation-v1.0.patch | |
| 2026-10-17 03:28 | buttar | Note Added: 0054529 | |
| 2026-10-17 03:28 | buttar | File Added: mid-foundation-v1.01.patch | |
| 2026-10-17 13:23 | ale | Note Added: 0054539 | |
| 2026-10-17 20:00 | cbradney | Target Version | => 1.8 Milestone |
| 2026-10-29 17:09 | cbradney | Target Version | 1.8 Milestone => 1.7.5.svn |