[scribus-dev] scribus*format_save.cpp beautifying

a.l.e ale.comp_06 at xox.ch
Thu Jul 30 15:09:19 CEST 2009


hi nick,

yes. your mail was very direct, for a first post...

still, i hope that they will be welcome by the team :-)


i'm curious about one thing: why are you proposing to use the Q_FOREACH 
macro instead of the normal foreach?

have a nice day
a.l.e
> 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.
>
> _______________________________________________
> scribus-dev mailing list
> scribus-dev at lists.scribus.net
> http://lists.scribus.net/mailman/listinfo/scribus-dev
>   




More information about the scribus-dev mailing list