r23675 by jghali - #14140: Cutting/Pasting then deleting footnote frame results in crash
scribus-commit
scribus-commit at lists.scribus.net
Tue Apr 28 01:02:46 UTC 2020
Author: jghali
Date: Tue Apr 28 01:02:46 2020
New Revision: 23675
URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=23675
Log:
#14140: Cutting/Pasting then deleting footnote frame results in crash
Modified:
trunk/Scribus/scribus/pageitem_noteframe.cpp
trunk/Scribus/scribus/pageitem_noteframe.h
trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format.cpp
trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format.h
trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format_save.cpp
trunk/Scribus/scribus/scribusdoc.h
Modified: trunk/Scribus/scribus/pageitem_noteframe.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23675&path=/trunk/Scribus/scribus/pageitem_noteframe.cpp
==============================================================================
--- trunk/Scribus/scribus/pageitem_noteframe.cpp (original)
+++ trunk/Scribus/scribus/pageitem_noteframe.cpp Tue Apr 28 01:02:46 2020
@@ -204,7 +204,7 @@
void PageItem_NoteFrame::layout()
{
- if (!invalid || l_notes.isEmpty())
+ if (!invalid || m_notes.isEmpty())
return;
if (!m_Doc->flag_layoutNotesFrames)
return;
@@ -296,7 +296,7 @@
void PageItem_NoteFrame::updateNotes(const QList<TextNote*>& nList, bool clear)
{
- if (nList == l_notes && !clear)
+ if (nList == m_notes && !clear)
return;
UndoManager::instance()->setUndoEnabled(false);
m_Doc->setNotesChanged(true);
@@ -306,9 +306,9 @@
{
itemText.selectAll();
deleteSelectedTextFromFrame();
- l_notes = nList;
- for (int a=0; a < l_notes.count(); ++a)
- insertNote(l_notes.at(a));
+ m_notes = nList;
+ for (int a=0; a < m_notes.count(); ++a)
+ insertNote(m_notes.at(a));
}
else
{
@@ -319,9 +319,9 @@
for (int i=0; i< count; ++i)
{
TextNote* note = nList.at(i);
- if (!l_notes.contains(note))
+ if (!m_notes.contains(note))
{
- l_notes.append(note);
+ m_notes.append(note);
insertNote(note);
}
}
@@ -335,7 +335,7 @@
void PageItem_NoteFrame::updateNotesText()
{
//read texts from notes frame and copy it to note`s data
- if (l_notes.isEmpty() || (itemText.length() == 0))
+ if (m_notes.isEmpty() || (itemText.length() == 0))
return;
int oldSelStart = itemText.startOfSelection();
Modified: trunk/Scribus/scribus/pageitem_noteframe.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23675&path=/trunk/Scribus/scribus/pageitem_noteframe.h
==============================================================================
--- trunk/Scribus/scribus/pageitem_noteframe.h (original)
+++ trunk/Scribus/scribus/pageitem_noteframe.h Tue Apr 28 01:02:46 2020
@@ -35,6 +35,11 @@
//returns Notes Style
NotesStyle* notesStyle() { return m_nstyle; }
+ //return list of notes in noteframe
+ const QList<TextNote*>& notesList() const { return m_notes; }
+ //remove note from list
+ void removeNote(TextNote* note) { m_notes.removeOne(note); }
+
//insert notes content into notesframe
void updateNotes(const QList<TextNote*>& nList, bool clear = true);
//read notes text from notesframe itemText and store it in notes`s saxed text field
@@ -47,11 +52,6 @@
bool isAutoHeight() const { return m_nstyle->isAutoNotesHeight(); }
bool isAutoWidth() const { return m_nstyle->isAutoNotesWidth(); }
- //return list of notes in noteframe
- QList<TextNote*> notesList() { return l_notes; }
- //remove note from list
- void removeNote(TextNote* note) { l_notes.removeOne(note); }
-
void restoreDeleteNoteText(SimpleState *state, bool isUndo);
void restoreDeleteNoteParagraph(SimpleState *state, bool isUndo);
void restoreInsertNoteText(SimpleState *state, bool isUndo);
@@ -60,7 +60,7 @@
void unWeld(bool doUndo=true);
private:
- QList<TextNote*> l_notes;
+ QList<TextNote*> m_notes;
NotesStyle* m_nstyle;
PageItem_TextFrame *m_masterFrame;
Modified: trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23675&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 Tue Apr 28 01:02:46 2020
@@ -499,6 +499,10 @@
}
}
}
+
+ //update names to pointers
+ updateNames2Ptr();
+
if (itemNext.count() != 0)
{
QMap<int,int>::Iterator lc;
@@ -603,6 +607,10 @@
}
}
}
+
+ //update names to pointers
+ updateNames2Ptr();
+
// reestablish textframe links
if (itemNext.count() != 0)
{
Modified: trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23675&path=/trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format.h
==============================================================================
--- trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format.h (original)
+++ trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format.h Tue Apr 28 01:02:46 2020
@@ -24,6 +24,7 @@
class ColorList;
class multiLine;
+class PageItem_NoteFrame;
class ScLayer;
class ScribusDoc;
//struct ScribusDoc::BookMa;
@@ -31,6 +32,7 @@
class ScXmlStreamReader;
class ScXmlStreamWriter;
class StoryText;
+class TextNote;
class PLUGIN_API Scribus150Format : public LoadSavePlugin
{
@@ -192,8 +194,11 @@
void writeTOC(ScXmlStreamWriter& docu);
void writeMarks(ScXmlStreamWriter & docu);
void writeNotesStyles(ScXmlStreamWriter & docu);
+ void writeNotesStyles(ScXmlStreamWriter & docu, const QStringList& styleSelection);
void writeNotesFrames(ScXmlStreamWriter & docu);
+ void writeNotesFrames(ScXmlStreamWriter & docu, const QList<PageItem_NoteFrame*>& nfList);
void writeNotes(ScXmlStreamWriter & docu);
+ void writeNotes(ScXmlStreamWriter & docu, const QList<TextNote*>& noteList);
void writePageSets(ScXmlStreamWriter& docu);
void writeSections(ScXmlStreamWriter& docu);
void writePatterns(ScXmlStreamWriter& docu, const QString& baseDir, bool part = false, Selection* selection = 0);
Modified: trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format_save.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23675&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 Tue Apr 28 01:02:46 2020
@@ -92,6 +92,7 @@
}
}
+ // Write paragraph styles
QList<QString>::Iterator it;
QList<QString> names = lists.styleNames();
QList<int> styleList = m_Doc->getSortedStyleList();
@@ -102,6 +103,7 @@
putPStyle(writer, paragraphStyle, "STYLE");
}
+ // Write character styles
names = lists.charStyleNames();
styleList = m_Doc->getSortedCharStyleList();
for (int i = 0; i < styleList.count(); ++i)
@@ -115,6 +117,36 @@
}
writeLineStyles(writer);
+
+ // TODO Write used marks
+ // writeMarks(writer);
+
+ // Write note styles
+ names = lists.noteStyleNames();
+ writeNotesStyles(writer, names);
+
+ // Write note frames
+ QList<PageItem_NoteFrame*> nfList;
+ for (int i = 0; i < selection->count(); ++i)
+ {
+ PageItem* item = selection->itemAt(i);
+ if (!item->isNoteFrame())
+ continue;
+ nfList.append(dynamic_cast<PageItem_NoteFrame*>(item));
+ }
+ writeNotesFrames(writer, nfList);
+
+ // TODO Write text notes (once marks are also written)
+ // Do not uncomment before otherwise pasting note frame
+ // will trigger a crash
+ /*QList<TextNote*> textNotes;
+ for (int i = 0; i < nfList.count(); ++i)
+ {
+ PageItem_NoteFrame* noteFrame = nfList.at(i);
+ textNotes.append(noteFrame->notesList());
+ }
+ writeNotes(writer, textNotes);*/
+
writePatterns(writer, fileDir, true, selection);
if (!emF.isEmpty())
WriteObjects(m_Doc, writer, fileDir, nullptr, 0, ItemSelectionFrame, &emF);
@@ -1302,7 +1334,7 @@
return;
docu.writeStartElement("Marks");
- foreach(Mark* mrk, m_Doc->marksList())
+ for (Mark* mrk : m_Doc->marksList())
{
if (mrk->isType(MARKNoteFrameType))
continue;
@@ -1332,6 +1364,25 @@
void Scribus150Format::writeNotesStyles(ScXmlStreamWriter & docu)
{
+ if (m_Doc->m_docNotesStylesList.isEmpty())
+ return;
+
+ //write notes styles
+ QStringList noteStyleNames;
+ QList<NotesStyle*>::ConstIterator end = m_Doc->m_docNotesStylesList.constEnd();
+ for (auto itNS = m_Doc->m_docNotesStylesList.constBegin(); itNS != end; ++itNS)
+ {
+ const NotesStyle* noteStyle = (*itNS);
+ noteStyleNames.append(noteStyle->name());
+ }
+ writeNotesStyles(docu, noteStyleNames);
+}
+
+void Scribus150Format::writeNotesStyles(ScXmlStreamWriter & docu, const QStringList& styleSelection)
+{
+ if (styleSelection.isEmpty())
+ return;
+
//write notes styles
docu.writeStartElement("NotesStyles");
QList<NotesStyle*>::Iterator itNS;
@@ -1339,6 +1390,8 @@
for (itNS = m_Doc->m_docNotesStylesList.begin(); itNS != end; ++itNS)
{
NotesStyle* noteStyle = (*itNS);
+ if (!styleSelection.contains(noteStyle->name()))
+ continue;
docu.writeEmptyElement("notesStyle");
docu.writeAttribute("Name", noteStyle->name());
docu.writeAttribute("Start", noteStyle->start());
@@ -1399,15 +1452,23 @@
void Scribus150Format::writeNotesFrames(ScXmlStreamWriter &docu)
{
+ QList<PageItem_NoteFrame*> nfList;
+ for (NotesStyle* noteStyle : m_Doc->m_docNotesStylesList)
+ nfList.append(m_Doc->listNotesFrames(noteStyle));
+
+ writeNotesFrames(docu, nfList);
+}
+
+void Scribus150Format::writeNotesFrames(ScXmlStreamWriter & docu, const QList<PageItem_NoteFrame*>& itemList)
+{
+ if (itemList.isEmpty())
+ return;
+
docu.writeStartElement("NotesFrames");
- QList<PageItem_NoteFrame*> nfList;
- foreach (NotesStyle* noteStyle, m_Doc->m_docNotesStylesList)
- nfList.append(m_Doc->listNotesFrames(noteStyle));
-
- for (int it = 0; it < nfList.count(); ++it)
- {
- PageItem_NoteFrame* noteFrame = nfList.at(it);
+ for (int i = 0; i < itemList.count(); ++i)
+ {
+ PageItem_NoteFrame* noteFrame = itemList.at(i);
NotesStyle* noteStyle = noteFrame->notesStyle();
if (noteStyle->isEndNotes())
{
@@ -1415,21 +1476,17 @@
docu.writeAttribute("NSname", noteStyle->name());
docu.writeAttribute("range", (int) noteStyle->range());
docu.writeAttribute("myID", qHash(noteFrame) & 0x7FFFFFFF);
- //docu.writeAttribute("name", noteFrame->itemName());
rangeItem rI = m_Doc->m_docEndNotesFramesMap.value(noteFrame);
if (noteStyle->range() == NSRstory)
docu.writeAttribute("ItemID", qHash(rI.firstStoryFrame) & 0x7FFFFFFF);
- //docu.writeAttribute("item", rI.firstStoryFrame->itemName());
}
else //footnotes frame
{
docu.writeEmptyElement("FOOTNOTEFRAME");
docu.writeAttribute("NSname", noteStyle->name());
docu.writeAttribute("myID", qHash(noteFrame) & 0x7FFFFFFF);
- //docu.writeAttribute("name", noteFrame->itemName());
docu.writeAttribute("MasterID", qHash(noteFrame->masterFrame()) & 0x7FFFFFFF);
- //docu.writeAttribute("master", noteFrame->masterFrame()->itemName());
}
}
docu.writeEndElement();
@@ -1440,18 +1497,26 @@
//write notes
if (m_Doc->notesList().isEmpty())
return;
+
+ const QList<TextNote*>& noteList = m_Doc->notesList();
+ writeNotes(docu, noteList);
+}
+
+void Scribus150Format::writeNotes(ScXmlStreamWriter & docu, const QList<TextNote*>& noteList)
+{
+ if (noteList.isEmpty())
+ return;
+
docu.writeStartElement("Notes");
- QList<TextNote*>::const_iterator itTN;
- QList<TextNote*>::const_iterator end = m_Doc->notesList().end();
- for (auto itTN = m_Doc->notesList().begin(); itTN != end; ++itTN)
- {
- TextNote* TN = (*itTN);
- if (TN->masterMark() == nullptr)
+ for (int i = 0; i < noteList.count(); ++i)
+ {
+ TextNote* textNote = noteList.at(i);
+ if (textNote->masterMark() == nullptr)
continue;
docu.writeEmptyElement("Note");
- docu.writeAttribute("Master", TN->masterMark()->label);
- docu.writeAttribute("NStyle", TN->notesStyle()->name());
- docu.writeAttribute("Text", TN->saxedText());
+ docu.writeAttribute("Master", textNote->masterMark()->label);
+ docu.writeAttribute("NStyle", textNote->notesStyle()->name());
+ docu.writeAttribute("Text", textNote->saxedText());
}
docu.writeEndElement();
}
Modified: trunk/Scribus/scribus/scribusdoc.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23675&path=/trunk/Scribus/scribus/scribusdoc.h
==============================================================================
--- trunk/Scribus/scribus/scribusdoc.h (original)
+++ trunk/Scribus/scribus/scribusdoc.h Tue Apr 28 01:02:46 2020
@@ -1722,8 +1722,8 @@
void multipleDuplicateByPage(const ItemMultipleDuplicateData& mdData, Selection& selection, QString& tooltip);
public:
- const QList<Mark*> marksList() { return m_docMarksList; }
- const QList<TextNote*> notesList() { return m_docNotesList; }
+ const QList<Mark*>& marksList() { return m_docMarksList; }
+ const QList<TextNote*>& notesList() { return m_docNotesList; }
QList<NotesStyle*> m_docNotesStylesList;
QMap<PageItem_NoteFrame*, rangeItem> m_docEndNotesFramesMap;
QList<NotesStyle*> ns2Update; //list of notes styles to update
More information about the scribus-commit
mailing list