[scribus-dev] scribus*format_save.cpp beautifying

Nick Shaforostoff shaforostoff at kde.ru
Thu Jul 30 14:27:04 CEST 2009


Hi.

Reading Scribus134Format::WritePages() code I found out that it may be 
shortened a bit by using functional style programming.

Instead of making checks for 'master' on each loop iteration, we may 
precompute values that depend on it (because'master' is constant in this 
context). Also I switched the code to use Qt's Q_FOREACH macro.

This resulted in the following patch:

 void Scribus134Format::WritePages(ScribusDoc *doc, ScXmlStreamWriter& docu, 
QProgressBar *dia2, uint maxC, bool master)
 {
        uint ObCount = maxC;
-       Page *page;
-       uint pages;
        QDomElement pg;
        QString tmp;
-       if (master)
-               pages = doc->MasterPages.count();
-       else
-               pages = doc->DocPages.count();
-       for(uint i = 0; i < pages; ++i)
+    QString elementName=master?"MASTERPAGE":"PAGE";
+       Q_FOREACH(Page *page, (master?doc->MasterPages:doc->DocPages))
        {
                ObCount++;
                if (dia2 != 0)
                        dia2->setValue(ObCount);
-               if (master)
-               {
-                       docu.writeStartElement("MASTERPAGE");
-                       page = doc->MasterPages.at(i);
-               }
-               else
-               {
-                       docu.writeStartElement("PAGE");
-                       page = doc->DocPages.at(i);
-               }
+               docu.writeStartElement(elementName);
+

I  believe it makes code more readable.
Do you think it can be integrated into repository?

P.S. I'm sorry for sounding rude in my previous emails.



More information about the scribus-dev mailing list