Warning, file /office/calligra/libs/textlayout/TableIterator.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 #include "TableIterator.h"
0020 
0021 #include "FrameIterator.h"
0022 
0023 #include <KoTableStyle.h>
0024 
0025 #include <QTextTable>
0026 
0027 TableIterator::TableIterator(QTextTable *t)
0028 {
0029     table = t;
0030     frameIterators.resize(table->columns());
0031     for (int col = 0; col < table->columns(); ++col) {
0032         frameIterators[col] = 0;
0033     }
0034     row = 0;
0035     headerRows = table->format().property(KoTableStyle::NumberHeadingRows).toInt();
0036     headerRowPositions.resize(headerRows + 1);
0037     headerCellAreas.resize(headerRows);
0038     for (int row = 0; row < headerRows; ++row) {
0039         headerCellAreas[row].resize(table->columns());
0040         for (int col = 0; col < table->columns(); ++col) {
0041             headerCellAreas[row][col] = 0;
0042         }
0043     }
0044 }
0045 
0046 TableIterator::TableIterator(TableIterator *other)
0047 {
0048     table = other->table;
0049     frameIterators.resize(table->columns());
0050     for (int col = 0; col < table->columns(); ++col) {
0051         if (other->frameIterators[col]) {
0052             frameIterators[col] = new FrameIterator(other->frameIterators[col]);
0053         } else {
0054             frameIterators[col] = 0;
0055         }
0056     }
0057     row = other->row;
0058     headerRows = other->headerRows;
0059     headerPositionX = other->headerPositionX;
0060     headerRowPositions.resize(headerRows + 1);
0061     headerCellAreas.resize(headerRows);
0062     for (int row = 0; row < headerRows; ++row) {
0063         headerCellAreas[row].resize(table->columns());
0064         for (int col = 0; col < table->columns(); ++col) {
0065             headerCellAreas[row][col] = other->headerCellAreas[row][col];
0066         }
0067         headerRowPositions[row] = other->headerRowPositions[row];
0068     }
0069     headerRowPositions[headerRows] = other->headerRowPositions[headerRows];
0070 }
0071 
0072 
0073 TableIterator::~TableIterator()
0074 {
0075     for (int col = 0; col < frameIterators.size(); ++col) {
0076         delete frameIterators[col];
0077     }
0078 }
0079 
0080 bool TableIterator::operator ==(const TableIterator &other) const
0081 {
0082     if (table != other.table)
0083         return false;
0084 
0085     if (row != other.row)
0086         return false;
0087 
0088     if (headerRows != other.headerRows)
0089         return false;
0090 
0091     for (int row = 0; row < headerRows; ++row) {
0092         for (int col = 0; col < table->columns(); ++col) {
0093             if (headerCellAreas[row][col] != other.headerCellAreas[row][col])
0094                 return false;
0095         }
0096     }
0097 
0098     for (int col = 0; col < table->columns(); ++col) {
0099         if (frameIterators[col] && other.frameIterators[col]) {
0100             if (!(*frameIterators[col] ==
0101                             *(other.frameIterators[col])))
0102                 return false;
0103         }
0104     }
0105 
0106     return true;
0107 }
0108 
0109 FrameIterator *TableIterator::frameIterator(int column)
0110 {
0111     FrameIterator *it = 0;
0112     if (row == table->rows()) {
0113         delete frameIterators[column];
0114         frameIterators[column] = it;
0115     } else if (frameIterators[column] == 0) {
0116         it = new FrameIterator(table->cellAt(row, column));
0117         it->masterPageName = masterPageName;
0118         frameIterators[column] = it;
0119     } else {
0120         it = frameIterators[column];
0121     }
0122     return it;
0123 }