r23440 by jghali - Add some const qualifiers in mark API

scribus-commit scribus-commit at lists.scribus.net
Sat Jan 11 02:03:15 UTC 2020


Author: jghali
Date: Sat Jan 11 02:03:14 2020
New Revision: 23440

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=23440
Log:
Add some const qualifiers in mark API

Modified:
    trunk/Scribus/scribus/marks.cpp
    trunk/Scribus/scribus/marks.h
    trunk/Scribus/scribus/scribusdoc.cpp
    trunk/Scribus/scribus/scribusdoc.h
    trunk/Scribus/scribus/sctextstruct.cpp
    trunk/Scribus/scribus/sctextstruct.h
    trunk/Scribus/scribus/text/storytext.cpp
    trunk/Scribus/scribus/text/storytext.h

Modified: trunk/Scribus/scribus/marks.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23440&path=/trunk/Scribus/scribus/marks.cpp
==============================================================================
--- trunk/Scribus/scribus/marks.cpp	(original)
+++ trunk/Scribus/scribus/marks.cpp	Sat Jan 11 02:03:14 2020
@@ -20,10 +20,24 @@
 	data = d;
 }
 
-void Mark::getMark(QString& l, MarkType& t)
+void Mark::getMark(QString& l, MarkType& t) const
 {
 	l = data.destmarkName;
 	t = data.destmarkType;
+}
+
+void Mark::setMark(Mark* mP)
+{
+	if (mP == nullptr)
+	{
+		data.destmarkName = "";
+		data.destmarkType = MARKNoType;
+	}
+	else
+	{
+		data.destmarkName = mP->label;
+		data.destmarkType = mP->getType();
+	}
 }
 
 void Mark::setMark(const QString& l, MarkType t)
@@ -32,7 +46,7 @@
 	data.destmarkType = t;
 }
 
-const QString Mark::getString()
+const QString Mark::getString() const
 {
 	return data.strtxt;
 }
@@ -47,34 +61,34 @@
 	data.notePtr = note;
 }
 
-bool Mark::hasItemPtr()
+bool Mark::hasItemPtr() const
 {
 	return data.itemPtr != nullptr;
 }
 
-bool Mark::hasString()
+bool Mark::hasString() const
 {
 	return !data.strtxt.isEmpty();
 }
 
-bool Mark::hasMark()
+bool Mark::hasMark() const
 {
 	return data.destmarkName != "";
 }
 
-bool Mark::isUnique()
+bool Mark::isUnique() const
 {
 	return ((typ != MARKVariableTextType) && (typ != MARKIndexType) && (typ != MARKBullNumType));
 }
 
-bool Mark::isNoteType()
+bool Mark::isNoteType() const
 {
-	return ((typ == MARKNoteMasterType) || (typ==MARKNoteFrameType));
+	return ((typ == MARKNoteMasterType) || (typ == MARKNoteFrameType));
 }
 
-bool Mark::isType(const MarkType t)
+bool Mark::isType(const MarkType t) const
 {
-	return t==typ;
+	return t == typ;
 }
 
 BulNumMark::BulNumMark()

Modified: trunk/Scribus/scribus/marks.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23440&path=/trunk/Scribus/scribus/marks.h
==============================================================================
--- trunk/Scribus/scribus/marks.h	(original)
+++ trunk/Scribus/scribus/marks.h	Sat Jan 11 02:03:14 2020
@@ -52,45 +52,34 @@
 	int OwnPage {-1};
 
 	void setValues(const QString& l, int p, MarkType t, const MarkData& d);
-	MarkType getType() { return typ; }
+
+	MarkType getType() const { return typ; }
 	void setType(MarkType t) { typ = t; }
-	const MarkData getData() { return data; }
+	const MarkData getData() const { return data; }
 	void setData(const MarkData d) { data = d; }
-	PageItem* getItemPtr() { return data.itemPtr; }
+	PageItem* getItemPtr() const { return data.itemPtr; }
 	void setItemPtr( PageItem* ptr ) { data.itemPtr = ptr; }
-	const QString getItemName() { return data.itemName; }
+	const QString getItemName() const { return data.itemName; }
 	void setItemName( const QString name ) { data.itemName = name; }
 
 	//for marks to marks - return label and type of target mark by reference
-	void getMark(QString& l, MarkType &t);
+	void getMark(QString& l, MarkType &t) const;
 	//for marks to marks - set label and type of target mark from mark pointer
-	void setMark(Mark* mP)
-	{
-		if (mP == nullptr)
-		{
-			data.destmarkName = "";
-			data.destmarkType = MARKNoType;
-		}
-		else
-		{
-			data.destmarkName = mP->label;
-			data.destmarkType = mP->getType();
-		}
-	}
+	void setMark(Mark* mP);
 	void setMark(const QString& l, MarkType t);
-	MarkType getMarkType() { return data.markTyp; }
+	MarkType getMarkType() const { return data.markTyp; }
 	void setMarkType(MarkType t) { data.markTyp = t; }
-	const QString getString();
+	const QString getString() const;
 	void setString(const QString& str );
-	TextNote* getNotePtr() { return data.notePtr; }
+	TextNote* getNotePtr() const { return data.notePtr; }
 	void setNotePtr(TextNote *note);
 
-	bool hasItemPtr();
-	bool hasString();
-	bool hasMark();
-	bool isUnique();
-	bool isNoteType();
-	bool isType(const MarkType t);
+	bool hasItemPtr() const;
+	bool hasString() const;
+	bool hasMark() const;
+	bool isUnique() const;
+	bool isNoteType() const;
+	bool isType(const MarkType t) const;
 
     virtual ~Mark() {}
 

Modified: trunk/Scribus/scribus/scribusdoc.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23440&path=/trunk/Scribus/scribus/scribusdoc.cpp
==============================================================================
--- trunk/Scribus/scribus/scribusdoc.cpp	(original)
+++ trunk/Scribus/scribus/scribusdoc.cpp	Sat Jan 11 02:03:14 2020
@@ -5618,7 +5618,7 @@
 	return ret;
 }
 
-PageItem* ScribusDoc::getItemFromName(const QString& name)
+PageItem* ScribusDoc::getItemFromName(const QString& name) const
 {
 	PageItem* ret = nullptr;
 	for (int i = 0; i < Items->count(); ++i)
@@ -17013,20 +17013,20 @@
 	return newNote;
 }
 
-PageItem* ScribusDoc::findMarkItem(Mark* mrk, int &lastItem)
+PageItem* ScribusDoc::findMarkItem(const Mark* mrk, int &lastItem) const
 {
 	PageItem* item = nullptr;
-	for (int a = lastItem +1; a < DocItems.count(); ++a)
-	{
-		item = DocItems.at(a);
+	for (int i = lastItem + 1; i < DocItems.count(); ++i)
+	{
+		item = DocItems.at(i);
 		if (!item || !item->isTextFrame() || (item->itemText.length() <= 0))
 			continue;
-	//	for (int i = item->firstInFrame(); i <= item->lastInFrame(); ++i)
-		for (int i = 0; i < item->itemText.length(); ++i)
-		{
-			if (item->itemText.hasMark(i, mrk))
-			{
-				lastItem = a;
+	//	for (int j = item->firstInFrame(); j <= item->lastInFrame(); ++j)
+		for (int j = 0; j < item->itemText.length(); ++j)
+		{
+			if (item->itemText.hasMark(j, mrk))
+			{
+				lastItem = i;
 				return item;
 			}
 		}
@@ -17035,13 +17035,13 @@
 	return nullptr;
 }
 
-int ScribusDoc::findMarkCPos(Mark* mrk, PageItem* &currItem, int Start)
+int ScribusDoc::findMarkCPos(const Mark* mrk, PageItem* &currItem, int start) const
 {
 	if (currItem == nullptr)
 		currItem = findFirstMarkItem(mrk);
 	if (currItem == nullptr)
 	{
-		foreach (PageItem* item, DocItems)
+		for (PageItem* item : DocItems)
 		{
 			if (item->isTextFrame() && (item->prevInChain() == nullptr))
 			{
@@ -17059,10 +17059,10 @@
 	}
 	Q_ASSERT(currItem->isTextFrame());
 
-	if (Start < currItem->firstInFrame())
-		Start = currItem->firstInFrame();
-
-	for (int i = Start; i < currItem->itemText.length(); ++i)
+	if (start < currItem->firstInFrame())
+		start = currItem->firstInFrame();
+
+	for (int i = start; i < currItem->itemText.length(); ++i)
 	{
 		if (currItem->itemText.hasMark(i, mrk))
 			return i;
@@ -17070,9 +17070,9 @@
 	return -1;
 }
 
-bool ScribusDoc::isMarkUsed(Mark* mrk, bool visible)
-{
-	foreach (PageItem* currItem, DocItems)
+bool ScribusDoc::isMarkUsed(const Mark* mrk, bool visible) const
+{
+	for (const PageItem* currItem : qAsConst(DocItems))
 	{
 		if (currItem->isTextFrame() && (currItem->itemText.length() > 0))
 		{
@@ -17097,7 +17097,7 @@
 	return false;
 }
 
-void ScribusDoc::setCursor2MarkPos(Mark *mark)
+void ScribusDoc::setCursor2MarkPos(const Mark *mark)
 {
 	if (mark == nullptr)
 		return;
@@ -17111,11 +17111,11 @@
 	if (item == nullptr)
 		return;
 
-	int CPos = findMarkCPos(mark, item);
-	if (CPos > -1)
+	int cursorPos = findMarkCPos(mark, item);
+	if (cursorPos > -1)
 	{
 		scMW()->deselectAll();
-		scMW()->selectItemFromOutlines(item, true, CPos +1);
+		scMW()->selectItemFromOutlines(item, true, cursorPos + 1);
 	}
 }
 
@@ -17262,7 +17262,7 @@
 {
 	if (updateNotesMarks && !notesList().isEmpty())
 	{
-		foreach (PageItem* item, DocItems)
+		for (PageItem* item : DocItems)
 		{
 			if (!item->isTextFrame() || item->isNoteFrame())
 				continue;
@@ -17297,7 +17297,7 @@
 	if (!isLoading())
 	{
 		//run for variable text (invalidate frames with variable text)
-		foreach (Mark* mrk, m_docMarksList)
+		for (Mark* mrk : m_docMarksList)
 		{
 			if (mrk->isType(MARKVariableTextType))
 			{
@@ -17335,7 +17335,7 @@
 	}
 
 	//for all marks
-	foreach (Mark* mrk, m_docMarksList)
+	for (Mark* mrk : m_docMarksList)
 	{
 		//set mark page number
 		PageItem* mItem = findFirstMarkItem(mrk);
@@ -17361,7 +17361,7 @@
 		{
 			QString l;
 			MarkType t;
-			mrk->getMark(l,t);
+			mrk->getMark(l, t);
 			Mark* destMark = getMark(l,t);
 			if (destMark != nullptr)
 			{

Modified: trunk/Scribus/scribus/scribusdoc.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23440&path=/trunk/Scribus/scribus/scribusdoc.h
==============================================================================
--- trunk/Scribus/scribus/scribusdoc.h	(original)
+++ trunk/Scribus/scribus/scribusdoc.h	Sat Jan 11 02:03:14 2020
@@ -829,7 +829,7 @@
 
 	int getItemNrfromUniqueID(uint unique);
 	//return pointer to item
-	PageItem* getItemFromName(const QString& name);
+	PageItem* getItemFromName(const QString& name) const;
 	//itemDelete
 	//itemBlah...
 
@@ -1734,9 +1734,9 @@
 	Mark* newMark(Mark* mrk = nullptr);
 	TextNote* newNote(NotesStyle* NS);
 	
-	bool isMarkUsed(Mark* mrk, bool visible = false);
+	bool isMarkUsed(const Mark* mrk, bool visible = false) const;
 	//set cursor in text where given mark will be found
-	void setCursor2MarkPos(Mark* mark);
+	void setCursor2MarkPos(const Mark* mark);
 	//return false if mark was not found
 	bool eraseMark(Mark* mrk, bool fromText=false, PageItem* item = nullptr, bool force = false); //force is used only for deleting non-unique marks by MarksManager
 	void setUndoDelMark(Mark* mrk);
@@ -1784,20 +1784,21 @@
 	void endNoteFrameChanged(PageItem_NoteFrame* nF) { m_docEndNotesFramesChanged.append(nF); }
 	//update content for changed endnotesframes
 	void updateChangedEndNotesFrames();
+
 	//finds mark position in text
 	//return true if mark was found, CPos is set for mark`s position
 	//if item==nullptr then search in all items and if mark is found than item is set
-	int findMarkCPos(Mark* mrk, PageItem* &item, int Start = 0);
+	int findMarkCPos(const Mark* mrk, PageItem* &item, int start = 0) const;
 	QList<PageItem_NoteFrame*> m_docEndNotesFramesChanged;
 
 	//finds item which holds given mark, start searching from next to lastItem index in DocItems
-	PageItem* findMarkItem(Mark* mrk, int &lastItem);
+	PageItem* findMarkItem(const Mark* mrk, int &lastItem) const;
 	
 private:
 	//QMap<PageItem_NoteFrame*, QList<TextNote *> > map of notesframes and its list of notes
 	NotesInFrameMap m_docNotesInFrameMap;
 
-	PageItem* findFirstMarkItem(Mark* mrk) { int tmp = -1; return findMarkItem(mrk, tmp); }
+	PageItem* findFirstMarkItem(const Mark* mrk) const { int tmp = -1; return findMarkItem(mrk, tmp); }
 
 	//search for endnotesframe for given notes style and item holding master mark or section number
 	PageItem_NoteFrame* endNoteFrame(NotesStyle* nStyle, void* item = nullptr);

Modified: trunk/Scribus/scribus/sctextstruct.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23440&path=/trunk/Scribus/scribus/sctextstruct.cpp
==============================================================================
--- trunk/Scribus/scribus/sctextstruct.cpp	(original)
+++ trunk/Scribus/scribus/sctextstruct.cpp	Sat Jan 11 02:03:14 2020
@@ -33,13 +33,13 @@
 	return false;
 }
 
-bool ScText::hasMark(Mark* MRK) const
+bool ScText::hasMark(const Mark* mrk) const
 {
 	if (this->ch == SpecialChars::OBJECT)
 	{
-		if (MRK == nullptr)
+		if (mrk == nullptr)
 			return mark != nullptr;
-		return mark == MRK;
+		return mark == mrk;
 	}
 	return false;
 }

Modified: trunk/Scribus/scribus/sctextstruct.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23440&path=/trunk/Scribus/scribus/sctextstruct.h
==============================================================================
--- trunk/Scribus/scribus/sctextstruct.h	(original)
+++ trunk/Scribus/scribus/sctextstruct.h	Sat Jan 11 02:03:14 2020
@@ -150,7 +150,7 @@
 
 	bool hasObject(ScribusDoc *doc) const;
 	//returns true if given MRK is found, if MRK is nullptr then any mark returns true
-	bool hasMark(Mark * MRK = nullptr) const;
+	bool hasMark(const Mark * mrk = nullptr) const;
 	QList<PageItem*> getGroupedItems(ScribusDoc *doc);
 	PageItem* getItem(ScribusDoc *doc);
 private:

Modified: trunk/Scribus/scribus/text/storytext.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23440&path=/trunk/Scribus/scribus/text/storytext.cpp
==============================================================================
--- trunk/Scribus/scribus/text/storytext.cpp	(original)
+++ trunk/Scribus/scribus/text/storytext.cpp	Sat Jan 11 02:03:14 2020
@@ -1039,7 +1039,7 @@
 }
 
 
-bool StoryText::hasMark(int pos, Mark* mrk) const
+bool StoryText::hasMark(int pos, const Mark* mrk) const
 {
 	if (pos < 0)
 		pos += length();

Modified: trunk/Scribus/scribus/text/storytext.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23440&path=/trunk/Scribus/scribus/text/storytext.h
==============================================================================
--- trunk/Scribus/scribus/text/storytext.h	(original)
+++ trunk/Scribus/scribus/text/storytext.h	Sat Jan 11 02:03:14 2020
@@ -166,7 +166,7 @@
 
 	bool hasObject(int pos) const;
 	PageItem* getItem(int pos) const; // deprecated
-	bool hasMark(int pos, Mark* mrk = nullptr) const;
+	bool hasMark(int pos, const Mark* mrk = nullptr) const;
 	Mark *mark(int pos) const;
 	void replaceMark(int pos, Mark* mrk);
 	void applyMarkCharstyle(Mark* mrk, CharStyle& currStyle) const;




More information about the scribus-commit mailing list