r22295 by craig -

scribus-commit scribus-commit at lists.scribus.net
Fri Dec 29 17:16:51 UTC 2017


Author: craig
Date: Fri Dec 29 17:16:50 2017
New Revision: 22295

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=22295
Log:
Fix Coverity 1396756 / 1396761 and code cleanup

Modified:
    trunk/Scribus/scribus/text/storytext.cpp
    trunk/Scribus/scribus/text/storytext.h

Modified: trunk/Scribus/scribus/text/storytext.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22295&path=/trunk/Scribus/scribus/text/storytext.cpp
==============================================================================
--- trunk/Scribus/scribus/text/storytext.cpp	(original)
+++ trunk/Scribus/scribus/text/storytext.cpp	Fri Dec 29 17:16:50 2017
@@ -43,14 +43,15 @@
 
 StoryText::StoryText(ScribusDoc * doc_) : m_doc(doc_)
 {
-	if (doc_) {
+	if (doc_)
+	{
 		d = new ScText_Shared(&doc_->paragraphStyles());
 		m_doc->paragraphStyles().connect(this, SLOT(invalidateAll()));
 		m_doc->charStyles().connect(this, SLOT(invalidateAll()));
 	}
-	else {
+	else
 		d = new ScText_Shared(NULL);
-	}
+
 	m_selFirst = 0;
 	m_selLast = -1;
 	
@@ -71,7 +72,7 @@
 
 	m_selFirst = 0;
 	m_selLast = -1;
-	
+	m_shapedTextCache = NULL;
 //	m_firstFrameItem = 0;
 //	m_lastFrameItem = -1;
 //	m_magicX = 0.0;
@@ -83,14 +84,15 @@
 	d = other.d;
 	d->refs++;
 	
-	if (m_doc) {
+	if (m_doc)
+	{
 		m_doc->paragraphStyles().connect(this, SLOT(invalidateAll()));
 		m_doc->charStyles().connect(this, SLOT(invalidateAll()));
 	}
 	
 	m_selFirst = 0;
 	m_selLast = -1;
-	
+	m_shapedTextCache = NULL;
 //	m_firstFrameItem = 0;
 //	m_lastFrameItem = -1;
 //	m_magicX = 0.0;
@@ -119,14 +121,16 @@
 
 void StoryText::setDoc(ScribusDoc *docin)
 {
-	if (m_doc) {
+	if (m_doc)
+	{
 		m_doc->paragraphStyles().disconnect(this, SLOT(invalidateAll()));
 		m_doc->charStyles().disconnect(this, SLOT(invalidateAll()));
 	}
 
 	m_doc = docin;
 
-	if (m_doc) {
+	if (m_doc)
+	{
 		m_doc->paragraphStyles().connect(this, SLOT(invalidateAll()));
 		m_doc->charStyles().connect(this, SLOT(invalidateAll()));
 	}
@@ -144,12 +148,14 @@
 	other.d->refs++;
 	
 	d->refs--;
-	if (d->refs == 0) {
+	if (d->refs == 0)
+	{
 		clear();
 		delete d;
 	}
 	
-	if (m_doc) {
+	if (m_doc)
+	{
 		m_doc->paragraphStyles().disconnect(this, SLOT(invalidateAll()));
 		m_doc->charStyles().disconnect(this, SLOT(invalidateAll()));
 	}
@@ -157,7 +163,8 @@
 	m_doc = other.m_doc; 
 	d = other.d;
 	
-	if (m_doc) {
+	if (m_doc)
+	{
 		m_doc->paragraphStyles().connect(this, SLOT(invalidateAll()));
 		m_doc->charStyles().connect(this, SLOT(invalidateAll()));
 	}
@@ -449,19 +456,22 @@
 	int otherStart  = onlySelection? other.startOfSelection() : 0;
 	int otherEnd    = onlySelection? other.endOfSelection() : other.length();
 	int cstyleStart = otherStart;
-	for (int i = otherStart; i < otherEnd; ++i) {
+	for (int i = otherStart; i < otherEnd; ++i)
+	{
 		if (other.charStyle(i) == cstyle 
 			&& other.text(i) != SpecialChars::OBJECT
 			&& other.text(i) != SpecialChars::PARSEP)
 			continue;
 		int len = i - cstyleStart;
-		if (len > 0) {
+		if (len > 0)
+		{
 			insertCharsWithSoftHyphens(pos, other.textWithSoftHyphens(cstyleStart, len));
 			applyCharStyle(pos, len, otherDefault.charStyle());
 			applyCharStyle(pos, len, cstyle);
 			pos += len;
 		}
-		if (other.text(i) == SpecialChars::PARSEP) {
+		if (other.text(i) == SpecialChars::PARSEP)
+		{
 			insertChars(pos, SpecialChars::PARSEP);
 			//#5845 : disable for now as it has nasty side effects when linking frames
 			//applyStyle(pos, otherDefault);
@@ -469,7 +479,8 @@
 			cstyleStart = i+1;
 			pos += 1;
 		}
-		else if (other.text(i) == SpecialChars::OBJECT) {
+		else if (other.text(i) == SpecialChars::OBJECT)
+		{
 			insertChars(pos, SpecialChars::OBJECT);
 			item(pos)->embedded = other.item(i)->embedded;
 			item(pos)->mark = other.item(i)->mark;
@@ -477,18 +488,21 @@
 			cstyleStart = i+1;
 			pos += 1;
 		}
-		else {
+		else
+		{
 			cstyle = other.charStyle(i);
 			cstyleStart = i;
 		}
 	}
 	int len = otherEnd - cstyleStart;
-	if (len > 0) {
+	if (len > 0)
+	{
 		insertCharsWithSoftHyphens(pos, other.textWithSoftHyphens(cstyleStart, len));
 		applyCharStyle(pos, len, otherDefault.charStyle());
 		applyCharStyle(pos, len, cstyle);
 		pos += len;
-		if (other.text(otherEnd-1) != SpecialChars::PARSEP) {
+		if (other.text(otherEnd-1) != SpecialChars::PARSEP)
+		{
 			//#5845 : disable for now as it has nasty side effects when linking frames
 			//applyStyle(pos, otherDefault);
 			applyStyle(pos, other.paragraphStyle(otherEnd-1));
@@ -504,7 +518,8 @@
 void StoryText::insertParSep(int pos)
 {
 	ScText* it = item(pos);
-	if (!it->parstyle) {
+	if (!it->parstyle)
+	{
 		it->parstyle = new ParagraphStyle(paragraphStyle(pos+1));
 		it->parstyle->setContext( & d->pstyleContext);
 		// #7432 : when inserting a paragraph separator, apply/erase the trailing Style
@@ -612,7 +627,7 @@
 	insertChars(d->cursorPosition, txt, applyNeighbourStyle);
 }
 
-void StoryText::insertChars(int pos, QString txt, bool applyNeighbourStyle) //, const CharStyle & charstyle)
+void StoryText::insertChars(int pos, const QString& txt, bool applyNeighbourStyle) //, const CharStyle & charstyle)
 {
 	if (pos < 0)
 		pos += length()+1;
@@ -633,19 +648,20 @@
 		clone.setEffects(ScStyle_Default);
 	}
 
-	for (int i = 0; i < txt.length(); ++i) {
+	for (int i = 0; i < txt.length(); ++i)
+	{
 		ScText * item = new ScText(clone);
 		item->ch= txt.at(i);
 		item->setContext(cStyleContext);
 		d->insert(pos + i, item);
 		d->len++;
-		if (item->ch == SpecialChars::PARSEP) {
+		if (item->ch == SpecialChars::PARSEP)
+		{
 //			qDebug() << QString("new PARSEP %2 at %1").arg(pos).arg(paragraphStyle(pos).name());
 			insertParSep(pos + i);
 		}
-		if (d->cursorPosition >= static_cast<uint>(pos + i)) {
+		if (d->cursorPosition >= static_cast<uint>(pos + i))
 			d->cursorPosition += 1;
-		}
 	}
 
 	d->len = d->count();
@@ -679,7 +695,8 @@
 		QChar ch = txt.at(i);
 		int  index  = pos + inserted;
 		bool insert = true; 
-		if (ch == SpecialChars::SHYPHEN && index > 0) {
+		if (ch == SpecialChars::SHYPHEN && index > 0)
+		{
 			ScText* lastItem = this->item(index - 1);
 			// qreal SHY means user provided SHY, single SHY is automatic one
 			if (lastItem->effects() & ScStyle_HyphenationPossible)
@@ -721,13 +738,11 @@
 	if (item->ch == ch)
 		return;
 	
-	if (d->at(pos)->ch == SpecialChars::PARSEP) {
+	if (d->at(pos)->ch == SpecialChars::PARSEP)
 		removeParSep(pos);
-	}
 	item->ch = ch;
-	if (d->at(pos)->ch == SpecialChars::PARSEP) {
+	if (d->at(pos)->ch == SpecialChars::PARSEP)
 		insertParSep(pos);
-	}
 	
 	invalidate(pos, pos + 1);
 }
@@ -777,7 +792,8 @@
 	for (int i=pos; i < pos+signed(len); ++i)
 	{
 //		dump += d->at(i)->ch;
-		if (hyphens && hyphens[i-pos] & 1) {
+		if (hyphens && hyphens[i-pos] & 1)
+		{
 			d->at(i)->setEffects(d->at(i)->effects() | ScStyle_HyphenationPossible);
 //			dump += "-";
 		}
@@ -882,9 +898,8 @@
 
 	QString result;
 	StoryText* that(const_cast<StoryText*>(this));
-	for (int i = pos; i < pos+signed(len); ++i) {
+	for (int i = pos; i < pos+signed(len); ++i)
 		result += that->d->at(i)->ch;
-	}
 
 	return result;
 }
@@ -912,14 +927,14 @@
 
 InlineFrame StoryText::object(int pos) const
 {
-	  if (pos < 0)
-                pos += length();
-
-        assert(pos >= 0);
-        assert(pos < length());
-
-        StoryText* that = const_cast<StoryText *>(this);
-        return InlineFrame(that->d->at(pos)->embedded);
+  if (pos < 0)
+		pos += length();
+
+	assert(pos >= 0);
+	assert(pos < length());
+
+	StoryText* that = const_cast<StoryText *>(this);
+	return InlineFrame(that->d->at(pos)->embedded);
 }
 
 
@@ -952,7 +967,7 @@
 
 QString StoryText::textWithSoftHyphens(int pos, uint len) const
 {
-	QString result("");
+	QString result;
 	int lastPos = pos;
 
 	len = qMin((uint) (length() - pos), len);
@@ -1041,9 +1056,7 @@
 	{
 		CharStyle marksStyle(m_doc->charStyle(chsName));
 		if (!currStyle.equiv(marksStyle))
-		{
 			currStyle.setParent(chsName);
-		}
 	}
 	
 	StyleFlag s(currStyle.effects());
@@ -1062,21 +1075,19 @@
 			s &= ~ScStyle_Superscript;
 	}
 	if (s != currStyle.effects())
-	{
 		currStyle.setFeatures(s.featureList());
-	}
 }
 
 
 void StoryText::replaceMark(int pos, Mark* mrk)
 {
-    if (pos < 0)
-        pos += length();
-
-    assert(pos >= 0);
-    assert(pos < length());
-
-    this->d->at(pos)->mark = mrk;
+	if (pos < 0)
+		pos += length();
+
+	assert(pos >= 0);
+	assert(pos < length());
+
+	this->d->at(pos)->mark = mrk;
 }
 
 
@@ -1093,47 +1104,47 @@
 
 LayoutFlags StoryText::flags(int pos) const
 {
-    if (pos < 0)
-        pos += length();
+	if (pos < 0)
+		pos += length();
 
 	assert(pos >= 0);
-    assert(pos < length());
-
-    StoryText* that = const_cast<StoryText *>(this);
+	assert(pos < length());
+
+	StoryText* that = const_cast<StoryText *>(this);
 	return  static_cast<LayoutFlags>((*that->d->at(pos)).effects().value & ScStyle_NonUserStyles);
 }
 
 bool StoryText::hasFlag(int pos, LayoutFlags flags) const
 {
-    if (pos < 0)
-        pos += length();
-
-    assert(pos >= 0);
-    assert(pos < length());
-    assert((flags & ScStyle_UserStyles) == ScStyle_None);
+	if (pos < 0)
+		pos += length();
+
+	assert(pos >= 0);
+	assert(pos < length());
+	assert((flags & ScStyle_UserStyles) == ScStyle_None);
 
 	return (flags & d->at(pos)->effects().value) == flags;
 }
 
 void StoryText::setFlag(int pos, LayoutFlags flags)
 {
-    if (pos < 0)
-        pos += length();
-
-    assert(pos >= 0);
-    assert(pos < length());
-    assert((flags & ScStyle_UserStyles) == ScStyle_None);
+	if (pos < 0)
+		pos += length();
+
+	assert(pos >= 0);
+	assert(pos < length());
+	assert((flags & ScStyle_UserStyles) == ScStyle_None);
 
 	d->at(pos)->setEffects(flags | d->at(pos)->effects().value);
 }
 
 void StoryText::clearFlag(int pos, LayoutFlags flags)
 {
-    if (pos < 0)
-        pos += length();
-
-    assert(pos >= 0);
-    assert(pos < length());
+	if (pos < 0)
+		pos += length();
+
+	assert(pos >= 0);
+	assert(pos < length());
 
 	d->at(pos)->setEffects(~(flags & ScStyle_NonUserStyles) & d->at(pos)->effects().value);
 }
@@ -1152,11 +1163,13 @@
 	assert(pos >= 0);
 	assert(pos <= length());
 
-	if (length() == 0) {
+	if (length() == 0)
+	{
 //		qDebug() << "storytext::charstyle: default";
 		return defaultStyle().charStyle();
 	}
-	else if (pos == length()) {
+	else if (pos == length())
+	{
 		qDebug() << "storytext::charstyle: access at end of text %i" << pos;
 		--pos;
 	}
@@ -1195,13 +1208,13 @@
 //	assert( that->at(pos)->cab < doc->docParagraphStyles.count() );
 //	return doc->docParagraphStyles[that->at(pos)->cab];
 	
-	while (pos < length() && that->d->at(pos)->ch != SpecialChars::PARSEP) {
+	while (pos < length() && that->d->at(pos)->ch != SpecialChars::PARSEP)
 		++pos;
-	}
-	if (pos >= length()) {
+
+	if (pos >= length())
 		return that->d->trailingStyle;
-	}
-	else if ( !that->d->at(pos)->parstyle ) {
+	else if ( !that->d->at(pos)->parstyle )
+	{
 		ScText* current = that->d->at(pos);
 		qDebug("inserting default parstyle at %i", pos);
 		current->parstyle = new ParagraphStyle();
@@ -1253,13 +1266,13 @@
 		return;
 	if (pos + signed(len) > length())
 		return;
-
 	if (len == 0)
 		return;
 
 //	int lastParStart = pos == 0? 0 : -1;
 	ScText* itText;
-	for (uint i=pos; i < pos+len; ++i) {
+	for (uint i=pos; i < pos+len; ++i)
+	{
 		itText = d->at(i);
 		// #6165 : applying style on last character applies style on whole text on next open 
 		/*if (itText->ch == SpecialChars::PARSEP && itText->parstyle != NULL)
@@ -1324,10 +1337,11 @@
 	assert(pos <= length());
 
 	int i = pos;
-	while (i < length() && d->at(i)->ch != SpecialChars::PARSEP) {
+	while (i < length() && d->at(i)->ch != SpecialChars::PARSEP)
 		++i;
-	}
-	if (i < length()) {
+
+	if (i < length())
+	{
 		if (!d->at(i)->parstyle) {
 			qDebug("PARSEP without style at pos %i", i);
 			d->at(i)->parstyle = new ParagraphStyle();
@@ -1365,10 +1379,11 @@
 	assert(pos <= length());
 		
 	int i = pos;
-	while (i < length() && d->at(i)->ch != SpecialChars::PARSEP) {
+	while (i < length() && d->at(i)->ch != SpecialChars::PARSEP)
 		++i;
-	}
-	if (i < length()) {
+
+	if (i < length())
+	{
 		if (!d->at(i)->parstyle) {
 			qDebug("PARSEP without style at pos %i", i);
 			d->at(i)->parstyle = new ParagraphStyle();
@@ -1409,7 +1424,8 @@
 		return;
 	
 	ScText* itText;
-	for (uint i=pos; i < pos+len; ++i) {
+	for (uint i=pos; i < pos+len; ++i)
+	{
 		itText = d->at(i);
 		// #6165 : applying style on last character applies style on whole text on next open 
 		/*if (itText->ch == SpecialChars::PARSEP && itText->parstyle != NULL)
@@ -1457,7 +1473,8 @@
 		return;
 	
 	ScText* itText;
-	for (int i=0; i < len; ++i) {
+	for (int i=0; i < len; ++i)
+	{
 		itText = d->at(i);
 		if (itText->parstyle)
 			itText->parstyle->replaceNamedResources(newNames);
@@ -1501,9 +1518,8 @@
 	assert(pos <= length());
 
 	int i = pos;
-	while (i > 0 && d->at(i - 1)->ch != SpecialChars::PARSEP) {
+	while (i > 0 && d->at(i - 1)->ch != SpecialChars::PARSEP)
 		--i;
-	}
 
 	const ParagraphStyle& parStyle = this->paragraphStyle(pos);
 	parStyle.validate();
@@ -1989,7 +2005,8 @@
 
 void StoryText::invalidate(int firstItem, int endItem)
 {
-	for (int i=firstItem; i < endItem; ++i) {
+	for (int i=firstItem; i < endItem; ++i)
+	{
 		ParagraphStyle* par = item(i)->parstyle;
 		if (par)
 			par->charStyleContext()->invalidate();

Modified: trunk/Scribus/scribus/text/storytext.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22295&path=/trunk/Scribus/scribus/text/storytext.h
==============================================================================
--- trunk/Scribus/scribus/text/storytext.h	(original)
+++ trunk/Scribus/scribus/text/storytext.h	Fri Dec 29 17:16:50 2017
@@ -122,7 +122,7 @@
 	// Insert chars at current cursor position
 	void insertChars(QString txt, bool applyNeighbourStyle = false);
 	// Insert chars ar specific position
- 	void insertChars(int pos, QString txt, bool applyNeighbourStyle = false);
+	void insertChars(int pos, const QString& txt, bool applyNeighbourStyle = false);
 	// Insert inline object at current cursor position
 	void insertObject(int obj);
 	// Insert object at specific position
@@ -158,7 +158,7 @@
 	// Get char at specific position
  	QChar   text(int pos) const;
 	// Get text with len chars at specific position
- 	QString text(int pos, uint len) const;
+	QString text(int pos, uint len) const;
  	//Get sentence at any position within it
 	QString sentence(int pos, int &posn);
 




More information about the scribus-commit mailing list