KWPageManager::pages question

Thorsten Zachmann t.zachmann at zagge.de
Sat Dec 5 05:24:11 GMT 2015


Hello,

when working on getting cstester ported I noticed that the pages are in a 
random oder all the time.  Looking at the code I see that the pages are stored 
in q QHash and it seems that at least in Qt5 the order is not always the same 
in every run. 

In the header it is says that the pages are orderd.

    /**
     * Return an ordered list of all pages.
     * @param pageStyle if non empty return only the pages that follow the 
page style.
     */
    QList<KWPage> pages(const QString &pageStyle = QString()) const;

However when looking at the implementation you can clearly see that this is 
not the case.

QList<KWPage> KWPageManager::pages(const QString &pageStyle) const
{
    QList<KWPage> answer;
    const bool checkForStyle = !pageStyle.isEmpty();
    QHash<int, KWPageManagerPrivate::Page>::ConstIterator it = d-
>pages.constBegin();
    QHash<int, KWPageManagerPrivate::Page>::ConstIterator end = d-
>pages.constEnd();
    for(; it != end; ++it) {
        if (checkForStyle && it.value().style.name() != pageStyle)
            continue;
        answer << KWPage(d, it.key());
    }
    return answer;
}

Adding a 

std::sort(answer.begin(), answer.end()) ;

before returning fixes the problem of the pages not being sorted. 

Is it ok to add that or is the comment wrong and I could use the sort inside 
cstester. I don't know if any other code depends on the pages being sorted .

Have a nice day,

Thorsten



More information about the calligra-devel mailing list