Warning, file /office/calligra/libs/text/KoSectionUtils.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002  *  Copyright (c) 2014 Denis Kuplyakov <dener.kup@gmail.com>
0003  *
0004  * This library is free software; you can redistribute it and/or
0005  * modify it under the terms of the GNU Lesser General Public
0006  * License as published by the Free Software Foundation; either
0007  * version 2.1 of the License, or (at your option) any later version.
0008  *
0009  * This library is distributed in the hope that it will be useful,
0010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012  * Lesser General Public License for more details.
0013  *
0014  * You should have received a copy of the GNU Lesser General Public License
0015  * along with this library; see the file COPYING.LIB.  If not, write to
0016  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0017  * Boston, MA 02110-1301, USA.
0018  */
0019 
0020 #include <KoSectionUtils.h>
0021 #include <KoParagraphStyle.h>
0022 
0023 bool KoSectionUtils::getNextBlock(QTextCursor &cur)
0024 {
0025     QTextCursor next = cur;
0026     bool ok = next.movePosition(QTextCursor::NextBlock);
0027 
0028     while (ok && next.currentFrame() != cur.currentFrame()) {
0029         ok = next.movePosition(QTextCursor::NextBlock);
0030     }
0031 
0032     if (!ok || next.currentFrame() != cur.currentFrame()) {
0033         // There is no previous block.
0034         return false;
0035     }
0036     cur = next;
0037     return true;
0038 }
0039 
0040 void KoSectionUtils::setSectionStartings(QTextBlockFormat &fmt, const QList<KoSection *> &list)
0041 {
0042     if (list.empty()) {
0043         fmt.clearProperty(KoParagraphStyle::SectionStartings);
0044     } else {
0045         fmt.setProperty(KoParagraphStyle::SectionStartings,
0046             QVariant::fromValue< QList<KoSection *> >(list));
0047     }
0048 }
0049 
0050 void KoSectionUtils::setSectionEndings(QTextBlockFormat &fmt, const QList<KoSectionEnd *> &list)
0051 {
0052     if (list.empty()) {
0053         fmt.clearProperty(KoParagraphStyle::SectionEndings);
0054     } else {
0055         fmt.setProperty(KoParagraphStyle::SectionEndings,
0056             QVariant::fromValue< QList<KoSectionEnd *> >(list));
0057     }
0058 }
0059 
0060 QList<KoSection *> KoSectionUtils::sectionStartings(const QTextBlockFormat &fmt)
0061 {
0062     if (!fmt.hasProperty(KoParagraphStyle::SectionStartings)) {
0063         return QList<KoSection *>();
0064     } else {
0065         return fmt.property(KoParagraphStyle::SectionStartings).value< QList<KoSection *> >();
0066     }
0067 }
0068 
0069 QList<KoSectionEnd *> KoSectionUtils::sectionEndings(const QTextBlockFormat &fmt)
0070 {
0071     if (!fmt.hasProperty(KoParagraphStyle::SectionEndings)) {
0072         return QList<KoSectionEnd *>();
0073     } else {
0074         return fmt.property(KoParagraphStyle::SectionEndings).value< QList<KoSectionEnd *> >();
0075     }
0076 }