r17457 by craig -

scribus-commit scribus-commit at lists.scribus.net
Thu Apr 19 20:32:44 UTC 2012


Author: craig
Date: Thu Apr 19 20:32:43 2012
New Revision: 17457

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=17457
Log:
Fix change offset for word replacements, and simplify code a decent amount

Modified:
    branches/Version14x/Scribus/scribus/plugins/tools/hunspellcheck/hunspelldialog.cpp
    branches/Version14x/Scribus/scribus/plugins/tools/hunspellcheck/hunspelldialog.h
    branches/Version14x/Scribus/scribus/plugins/tools/hunspellcheck/hunspellpluginimpl.cpp
    branches/Version14x/Scribus/scribus/plugins/tools/hunspellcheck/hunspellpluginstructs.h

Modified: branches/Version14x/Scribus/scribus/plugins/tools/hunspellcheck/hunspelldialog.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17457&path=/branches/Version14x/Scribus/scribus/plugins/tools/hunspellcheck/hunspelldialog.cpp
==============================================================================
--- branches/Version14x/Scribus/scribus/plugins/tools/hunspellcheck/hunspelldialog.cpp (original)
+++ branches/Version14x/Scribus/scribus/plugins/tools/hunspellcheck/hunspelldialog.cpp Thu Apr 19 20:32:43 2012
@@ -24,7 +24,6 @@
 	m_doc=doc;
 	m_docChanged=false;
 	fTC=frameToCheck;
-	changeOffset=0;
 }
 
 void HunspellDialog::set(QStringList *dictEntries, Hunspell **hspellers, QList<WordsFound> *wfList)
@@ -70,8 +69,8 @@
 	sentencePos=qMax(sentencePos, iText->nextWord(sentencePos));
 	int nextSentencePos=qMin(iText->length(), iText->nextSentence(currWF.end));
 	QString sentence=iText->text(sentencePos, nextSentencePos-sentencePos);
-	sentence.insert(currWF.end-sentencePos+changeOffset,"</b></font>");
-	sentence.insert(currWF.start-sentencePos+changeOffset,"<font color=red><b>");
+	sentence.insert(currWF.end-sentencePos+currWF.changeOffset,"</b></font>");
+	sentence.insert(currWF.start-sentencePos+currWF.changeOffset,"<font color=red><b>");
 	sentenceTextEdit->setText(sentence);
 
 }
@@ -118,30 +117,27 @@
 	QString newText(suggestionsListWidget->currentItem()->text());
 	if (newText.length()==currWF.w.length())
 	{
-		for (int i = 0; i < currWF.w.length(); ++i)
-			iText->replaceChar(currWF.start+i+changeOffset, newText[i]);
+		for (int j = 0; j < currWF.w.length(); ++j)
+			iText->replaceChar(currWF.start+j+currWF.changeOffset, newText[j]);
 	}
 	else
 	{
+		int lengthDiff=newText.length()-currWF.w.length();
 		if (newText.length()>currWF.w.length())
 		{
-			for (int i = 0; i < currWF.w.length(); ++i)
-				iText->replaceChar(currWF.start+i+changeOffset, newText[i]);
-			for (int i = currWF.w.length(); i < newText.length(); ++i)
-				iText->insertChars(currWF.start+i+changeOffset, newText.mid(i,1), true);
-			int lengthDiff=newText.length()-currWF.w.length();
-			changeOffset+=lengthDiff;
-			qDebug()<<"Change Offset is:"<<changeOffset;
+			for (int j = 0; j < currWF.w.length(); ++j)
+				iText->replaceChar(currWF.start+j+currWF.changeOffset, newText[j]);
+			for (int j = currWF.w.length(); j < newText.length(); ++j)
+				iText->insertChars(currWF.start+j+currWF.changeOffset, newText.mid(j,1), true);
 		}
 		else
 		{
-			for (int i = 0; i < newText.length(); ++i)
-				iText->replaceChar(currWF.start+i+changeOffset, newText[i]);
-			int lengthDiff=currWF.w.length() - newText.length();
-			iText->removeChars(currWF.start+changeOffset+newText.length(), lengthDiff);
-			changeOffset-=lengthDiff;
-			qDebug()<<"Change Offset is:"<<changeOffset;
+			for (int j = 0; j < newText.length(); ++j)
+				iText->replaceChar(currWF.start+j+currWF.changeOffset, newText[j]);
+			iText->removeChars(currWF.start+currWF.changeOffset+newText.length(), -lengthDiff);
 		}
+		for (int k=i; k<m_wfList->count();++k)
+			(*m_wfList)[k].changeOffset+=lengthDiff;
 	}
 	m_docChanged=true;
 }

Modified: branches/Version14x/Scribus/scribus/plugins/tools/hunspellcheck/hunspelldialog.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17457&path=/branches/Version14x/Scribus/scribus/plugins/tools/hunspellcheck/hunspelldialog.h
==============================================================================
--- branches/Version14x/Scribus/scribus/plugins/tools/hunspellcheck/hunspelldialog.h (original)
+++ branches/Version14x/Scribus/scribus/plugins/tools/hunspellcheck/hunspelldialog.h Thu Apr 19 20:32:43 2012
@@ -41,7 +41,6 @@
 		WordsFound currWF;
 		int wfListIndex;
 		bool m_docChanged;
-		int changeOffset;
 };
 
 #endif // HUNSPELLDIALOG_H

Modified: branches/Version14x/Scribus/scribus/plugins/tools/hunspellcheck/hunspellpluginimpl.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17457&path=/branches/Version14x/Scribus/scribus/plugins/tools/hunspellcheck/hunspellpluginimpl.cpp
==============================================================================
--- branches/Version14x/Scribus/scribus/plugins/tools/hunspellcheck/hunspellpluginimpl.cpp (original)
+++ branches/Version14x/Scribus/scribus/plugins/tools/hunspellcheck/hunspellpluginimpl.cpp Thu Apr 19 20:32:43 2012
@@ -177,6 +177,7 @@
 			wf.replacements=replacements;
 			wf.changed=false;
 			wf.ignore=false;
+			wf.changeOffset=0;
 			wordsToCorrect.append(wf);
 		}
 	}

Modified: branches/Version14x/Scribus/scribus/plugins/tools/hunspellcheck/hunspellpluginstructs.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17457&path=/branches/Version14x/Scribus/scribus/plugins/tools/hunspellcheck/hunspellpluginstructs.h
==============================================================================
--- branches/Version14x/Scribus/scribus/plugins/tools/hunspellcheck/hunspellpluginstructs.h (original)
+++ branches/Version14x/Scribus/scribus/plugins/tools/hunspellcheck/hunspellpluginstructs.h Thu Apr 19 20:32:43 2012
@@ -11,6 +11,7 @@
 	QStringList replacements;
 	bool changed;
 	bool ignore;
+	int changeOffset;
 };
 
 #endif // HUNSPELLPLUGINSTRUCTS_H




More information about the scribus-commit mailing list