File: kis_wrapped_line_iterator_base.h

package info (click to toggle)
calligra 1%3A2.8.5%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 397,516 kB
  • ctags: 185,064
  • sloc: cpp: 1,505,875; python: 45,987; ansic: 28,421; xml: 26,472; sh: 23,986; java: 18,214; objc: 3,965; makefile: 2,816; perl: 2,792; yacc: 2,601; lex: 1,410; sql: 903; ruby: 737; asm: 236; lisp: 121
file content (157 lines) | stat: -rw-r--r-- 4,671 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/*
 *  Copyright (c) 2013 Dmitry Kazakov <dimula73@gmail.com>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

#ifndef __KIS_WRAPPED_LINE_ITERATOR_BASE_H
#define __KIS_WRAPPED_LINE_ITERATOR_BASE_H


template <class IteratorStrategy, class BaseClass>
    class KisWrappedLineIteratorBase : public BaseClass
{
public:
    KisWrappedLineIteratorBase(KisDataManager *dataManager,
                               const KisWrappedRect &splitRect,
                               qint32 offsetX, qint32 offsetY,
                               bool writable)
        : m_splitRect(splitRect)
    {
        Q_ASSERT(m_splitRect.isSplit());

        m_iterators.resize(4);
        for (int i = 0; i < 4; i++) {
            QRect rc = m_splitRect[i];
            if (rc.isEmpty()) continue;

            m_iterators[i] = m_strategy.createIterator(dataManager,
                                                       rc,
                                                       offsetX, offsetY,
                                                       writable);
        }
        m_strategy.completeInitialization(&m_iterators, &m_splitRect);
        m_iterationAreaSize =
            m_strategy.originalRectToColumnsRows(m_splitRect.originalRect());

        m_currentIterator = m_strategy.leftColumnIterator();
    }

    bool nextPixel() {
        int result = m_currentIterator->nextPixel();
        if (!result) {
            result = trySwitchColumn();
        }

        m_currentPos.rx()++;
        return m_currentPos.rx() < m_iterationAreaSize.width();
    }

    bool nextPixels(qint32 n) {
        int result = m_currentIterator->nextPixels(n);
        if (!result) {
            result = trySwitchColumn();
        }

        m_currentPos.rx() += n;
        return m_currentPos.rx() < m_iterationAreaSize.width();
    }

    void nextRow() {
        if (!m_strategy.trySwitchIteratorStripe()) {
            m_strategy.iteratorsToNextRow();
        }

        m_currentIterator = m_strategy.leftColumnIterator();
        m_currentPos.rx() = 0;
        m_currentPos.ry()++;
    }

    void nextColumn() {
        nextRow();
    }

    const quint8* oldRawData() const {
        return m_currentIterator->oldRawData();
    }

    const quint8* rawDataConst() const {
        return m_currentIterator->rawDataConst();
    }

    quint8* rawData() {
        return m_currentIterator->rawData();
    }

    qint32 nConseqPixels() const {
        qint32 iteratorChunk =
            m_currentIterator->nConseqPixels();
        return qMin(iteratorChunk,
                    m_iterationAreaSize.width() - m_currentPos.x());
    }

    qint32 x() const {
        return (m_splitRect.originalRect().topLeft() +
                m_strategy.columnRowToXY(m_currentPos)).x();
    }

    qint32 y() const {
        return (m_splitRect.originalRect().topLeft() +
                m_strategy.columnRowToXY(m_currentPos)).y();
    }

    void resetPixelPos() {
        qCritical() << "CRITICAL: resetPixelPos() is not implemented";
    }

    void resetRowPos() {
        qCritical() << "CRITICAL: resetRowPos() is not implemented";
    }

    void resetColumnPos() {
        resetRowPos();
    }

private:
    bool trySwitchColumn() {
        int result = true;

        if (m_currentIterator == m_strategy.leftColumnIterator() &&
            m_strategy.rightColumnIterator()) {

            m_currentIterator = m_strategy.rightColumnIterator();

        } else if (m_strategy.trySwitchColumnForced()) {

            m_currentIterator = m_strategy.leftColumnIterator();

        } else {
            result = false;
        }

        return result;
    }

private:

    KisWrappedRect m_splitRect;
    QSize m_iterationAreaSize; // columns x rows
    QPoint m_currentPos; // column, row
    QVector<typename IteratorStrategy::IteratorTypeSP> m_iterators;
    typename IteratorStrategy::IteratorTypeSP m_currentIterator;
    IteratorStrategy m_strategy;
};

#endif /* __KIS_WRAPPED_LINE_ITERATOR_BASE_H */