Git commit 8d97de80344b9cf187a520e074868bad0f0bb16b by Benjamin Port. Committed on 31/03/2011 at 23:01. Pushed by bport into branch 'stage-outline-bport-artaud'. Optimize outline populate code, and some clean up M +10 -47 kpresenter/part/KPrViewModeOutline.cpp http://commits.kde.org/calligra/8d97de80344b9cf187a520e074868bad0f0bb16b diff --git a/kpresenter/part/KPrViewModeOutline.cpp b/kpresenter/part/KPrViewModeOutline.cpp index 3703b79..58e94ba 100644 --- a/kpresenter/part/KPrViewModeOutline.cpp +++ b/kpresenter/part/KPrViewModeOutline.cpp @@ -121,65 +121,28 @@ void KPrViewModeOutline::deactivate() void KPrViewModeOutline::populate() { - int recordPosition = m_outlineEditor->textCursor().position(); m_outlineEditor->clear(); QTextCursor currentCursor = m_outlineEditor->textCursor(); - int cpt = 0; // For each slides foreach (KoPAPageBase * pageBase, m_view->kopaDocument()->pages()) { if (KPrPage * page = dynamic_cast(pageBase)) { - cpt++; + int pageNumber = m_view->kopaDocument()->pages().indexOf(pageBase); // Copy relevant content of the title of the page in the frame foreach (OutlinePair pair, page->placeholders().outlineData()) { - if (pair.first == Title) { + QTextBlockFormat blockFormat; + blockFormat.setBackground((pageNumber%2)?QBrush(Qt::gray):QBrush(Qt::white)); + // set the page property + blockFormat.setProperty(0, pageNumber); + // set the type property + blockFormat.setProperty(1, pair.first); - QTextBlockFormat blockFormat; - blockFormat.setBackground((cpt%2)?QBrush(Qt::white):QBrush(Qt::gray)); - // set the page property - blockFormat.setProperty(0, cpt); - // set the type property - blockFormat.setProperty(1, Title); - - currentCursor.insertBlock(blockFormat, pair.second->document()->firstBlock().charFormat()); - currentCursor.insertText(pair.second->document()->toPlainText()); - } - } - - // Copy relevant content of the outline of the page in the frame - foreach (OutlinePair pair, page->placeholders().outlineData()) { - if (pair.first == Subtitle) { - - QTextBlockFormat blockFormat; - blockFormat.setBackground((cpt%2)?QBrush(Qt::white):QBrush(Qt::gray)); - // set the page property - blockFormat.setProperty(0, cpt); - // set the type property - blockFormat.setProperty(1, Subtitle); - - currentCursor.insertBlock(blockFormat, pair.second->document()->firstBlock().charFormat()); - currentCursor.insertText(pair.second->document()->toPlainText()); - } - } - - // Copy relevant content of the outline of the page in the frame - foreach (OutlinePair pair, page->placeholders().outlineData()) { - if (pair.first == Outline) { - - QTextBlockFormat blockFormat; - blockFormat.setBackground((cpt%2)?QBrush(Qt::white):QBrush(Qt::gray)); - // set the page property - blockFormat.setProperty(0, cpt); - // set the type property - blockFormat.setProperty(1, Outline); - - currentCursor.insertBlock(blockFormat, pair.second->document()->firstBlock().charFormat()); - currentCursor.insertText(pair.second->document()->toPlainText()); - } + currentCursor.insertBlock(blockFormat); + currentCursor.insertText(pair.second->document()->toPlainText()); } } } - currentCursor.setPosition(((recordPosition > 0) ? recordPosition : 0)); + currentCursor.setPosition(0); m_outlineEditor->setTextCursor(currentCursor); }