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

0001 /* This file is part of the KDE project
0002  * Copyright (C) 2011 C. Boemann, KO GmbH <cbo@kogmbh.com>
0003  *
0004  * This library is free software; you can redistribute it and/or
0005  * modify it under the terms of the GNU Library General Public
0006  * License as published by the Free Software Foundation; either
0007  * version 2 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  * Library General Public License for more details.
0013  *
0014  * You should have received a copy of the GNU Library 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 "FrameIterator.h"
0021 
0022 #include "TableIterator.h"
0023 
0024 #include <QTextFrame>
0025 #include <QTextTableCell>
0026 
0027 FrameIterator::FrameIterator(QTextFrame *frame)
0028 {
0029     it = frame->begin();
0030     m_frame = it.parentFrame();
0031     currentTableIterator = 0;
0032     currentSubFrameIterator = 0;
0033     lineTextStart = -1;
0034     endNoteIndex = 0;
0035 }
0036 
0037 FrameIterator::FrameIterator(const QTextTableCell &cell)
0038 {
0039     Q_ASSERT(cell.isValid());
0040     it = cell.begin();
0041     m_frame = it.parentFrame();
0042     currentTableIterator = 0;
0043     currentSubFrameIterator = 0;
0044     lineTextStart = -1;
0045     endNoteIndex = 0;
0046 }
0047 
0048 FrameIterator::FrameIterator(FrameIterator *other)
0049 {
0050     it = other->it;
0051     m_frame = it.parentFrame();
0052     masterPageName = other->masterPageName;
0053     lineTextStart = other->lineTextStart;
0054     fragmentIterator = other->fragmentIterator;
0055     endNoteIndex = other->endNoteIndex;
0056     if (other->currentTableIterator)
0057         currentTableIterator = new TableIterator(other->currentTableIterator);
0058     else
0059         currentTableIterator = 0;
0060 
0061     if (other->currentSubFrameIterator)
0062         currentSubFrameIterator = new FrameIterator(other->currentSubFrameIterator);
0063     else
0064         currentSubFrameIterator = 0;
0065 }
0066 
0067 FrameIterator::~FrameIterator()
0068 {
0069     delete currentTableIterator;
0070     delete currentSubFrameIterator;
0071 }
0072 
0073 bool FrameIterator::isValid() const
0074 {
0075     return m_frame;
0076 }
0077 
0078 bool FrameIterator::operator ==(const FrameIterator &other) const
0079 {
0080     if (it != other.it)
0081         return false;
0082     if (endNoteIndex != other.endNoteIndex)
0083         return false;
0084     if (currentTableIterator || other.currentTableIterator) {
0085         if (!currentTableIterator || !other.currentTableIterator)
0086             return false;
0087         return *currentTableIterator == *(other.currentTableIterator);
0088     } else if (currentSubFrameIterator || other.currentSubFrameIterator) {
0089         if (!currentSubFrameIterator || !other.currentSubFrameIterator)
0090             return false;
0091         return *currentSubFrameIterator == *(other.currentSubFrameIterator);
0092     } else {
0093         return lineTextStart == other.lineTextStart;
0094     }
0095 }
0096 
0097 TableIterator *FrameIterator::tableIterator(QTextTable *table)
0098 {
0099     if(table == 0) {
0100         delete currentTableIterator;
0101         currentTableIterator = 0;
0102     } else if(currentTableIterator == 0) {
0103         currentTableIterator = new TableIterator(table);
0104         currentTableIterator->masterPageName = masterPageName;
0105     }
0106     return currentTableIterator;
0107 }
0108 
0109 FrameIterator *FrameIterator::subFrameIterator(QTextFrame *subFrame)
0110 {
0111     if(subFrame == 0) {
0112         delete currentSubFrameIterator;
0113         currentSubFrameIterator = 0;
0114     } else if(currentSubFrameIterator == 0) {
0115         currentSubFrameIterator = new FrameIterator(subFrame);
0116         currentSubFrameIterator->masterPageName = masterPageName;
0117     }
0118     return currentSubFrameIterator;
0119 }