1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation ([email protected])
|
---|
6 | **
|
---|
7 | ** This file is part of the QtGui module of the Qt Toolkit.
|
---|
8 | **
|
---|
9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
10 | ** Commercial Usage
|
---|
11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
14 | ** a written agreement between you and Nokia.
|
---|
15 | **
|
---|
16 | ** GNU Lesser General Public License Usage
|
---|
17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
18 | ** General Public License version 2.1 as published by the Free Software
|
---|
19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
20 | ** packaging of this file. Please review the following information to
|
---|
21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
23 | **
|
---|
24 | ** In addition, as a special exception, Nokia gives you certain additional
|
---|
25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
---|
26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you have questions regarding the use of this file, please contact
|
---|
37 | ** Nokia at [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | #ifndef QTABLEVIEW_P_H
|
---|
43 | #define QTABLEVIEW_P_H
|
---|
44 |
|
---|
45 | //
|
---|
46 | // W A R N I N G
|
---|
47 | // -------------
|
---|
48 | //
|
---|
49 | // This file is not part of the Qt API. It exists purely as an
|
---|
50 | // implementation detail. This header file may change from version to
|
---|
51 | // version without notice, or even be removed.
|
---|
52 | //
|
---|
53 | // We mean it.
|
---|
54 | //
|
---|
55 |
|
---|
56 | #include <QtCore/QList>
|
---|
57 | #include <QtCore/QLinkedList>
|
---|
58 | #include <QtCore/QMap>
|
---|
59 | #include <QtCore/QSet>
|
---|
60 | #include <QtCore/QDebug>
|
---|
61 | #include "private/qabstractitemview_p.h"
|
---|
62 |
|
---|
63 | #ifndef QT_NO_TABLEVIEW
|
---|
64 |
|
---|
65 | QT_BEGIN_NAMESPACE
|
---|
66 |
|
---|
67 | /** \internal
|
---|
68 | *
|
---|
69 | * This is a list of span with a binary index to look up quickly a span at a certain index.
|
---|
70 | *
|
---|
71 | * The index is a map of map.
|
---|
72 | * spans are mentaly divided into sub spans so that the start of any subspans doesn't overlap
|
---|
73 | * with any other subspans. There is no real representation of the subspans.
|
---|
74 | * The key of the first map is the row where the subspan starts, the value of the first map is
|
---|
75 | * a list (map) of all subspans that starts at the same row. It is indexed with its row
|
---|
76 | */
|
---|
77 | class Q_AUTOTEST_EXPORT QSpanCollection
|
---|
78 | {
|
---|
79 | public:
|
---|
80 | struct Span
|
---|
81 | {
|
---|
82 | int m_top;
|
---|
83 | int m_left;
|
---|
84 | int m_bottom;
|
---|
85 | int m_right;
|
---|
86 | bool will_be_deleted;
|
---|
87 | Span()
|
---|
88 | : m_top(-1), m_left(-1), m_bottom(-1), m_right(-1), will_be_deleted(false) { }
|
---|
89 | Span(int row, int column, int rowCount, int columnCount)
|
---|
90 | : m_top(row), m_left(column), m_bottom(row+rowCount-1), m_right(column+columnCount-1), will_be_deleted(false) { }
|
---|
91 | inline int top() const { return m_top; }
|
---|
92 | inline int left() const { return m_left; }
|
---|
93 | inline int bottom() const { return m_bottom; }
|
---|
94 | inline int right() const { return m_right; }
|
---|
95 | inline int height() const { return m_bottom - m_top + 1; }
|
---|
96 | inline int width() const { return m_right - m_left + 1; }
|
---|
97 | };
|
---|
98 |
|
---|
99 | ~QSpanCollection()
|
---|
100 | {
|
---|
101 | qDeleteAll(spans);
|
---|
102 | }
|
---|
103 |
|
---|
104 | void addSpan(Span *span);
|
---|
105 | void updateSpan(Span *span, int old_height);
|
---|
106 | Span *spanAt(int x, int y) const;
|
---|
107 | void clear();
|
---|
108 | QList<Span *> spansInRect(int x, int y, int w, int h) const;
|
---|
109 |
|
---|
110 | void updateInsertedRows(int start, int end);
|
---|
111 | void updateInsertedColumns(int start, int end);
|
---|
112 | void updateRemovedRows(int start, int end);
|
---|
113 | void updateRemovedColumns(int start, int end);
|
---|
114 |
|
---|
115 | #ifdef QT_BUILD_INTERNAL
|
---|
116 | bool checkConsistency() const;
|
---|
117 | #endif
|
---|
118 |
|
---|
119 | typedef QLinkedList<Span *> SpanList;
|
---|
120 | SpanList spans; //lists of all spans
|
---|
121 | private:
|
---|
122 | //the indexes are negative so the QMap::lowerBound do what i need.
|
---|
123 | typedef QMap<int, Span *> SubIndex;
|
---|
124 | typedef QMap<int, SubIndex> Index;
|
---|
125 | Index index;
|
---|
126 |
|
---|
127 | bool cleanSpanSubIndex(SubIndex &subindex, int end, bool update = false);
|
---|
128 | };
|
---|
129 |
|
---|
130 | Q_DECLARE_TYPEINFO ( QSpanCollection::Span, Q_MOVABLE_TYPE);
|
---|
131 |
|
---|
132 |
|
---|
133 | class QTableViewPrivate : public QAbstractItemViewPrivate
|
---|
134 | {
|
---|
135 | Q_DECLARE_PUBLIC(QTableView)
|
---|
136 | public:
|
---|
137 | QTableViewPrivate()
|
---|
138 | : showGrid(true), gridStyle(Qt::SolidLine),
|
---|
139 | rowSectionAnchor(-1), columnSectionAnchor(-1),
|
---|
140 | columnResizeTimerID(0), rowResizeTimerID(0),
|
---|
141 | horizontalHeader(0), verticalHeader(0),
|
---|
142 | sortingEnabled(false), geometryRecursionBlock(false),
|
---|
143 | visualCursor(QPoint())
|
---|
144 | {
|
---|
145 | wrapItemText = true;
|
---|
146 | #ifndef QT_NO_DRAGANDDROP
|
---|
147 | overwrite = true;
|
---|
148 | #endif
|
---|
149 | }
|
---|
150 | void init();
|
---|
151 | void trimHiddenSelections(QItemSelectionRange *range) const;
|
---|
152 |
|
---|
153 | inline bool isHidden(int row, int col) const {
|
---|
154 | return verticalHeader->isSectionHidden(row)
|
---|
155 | || horizontalHeader->isSectionHidden(col);
|
---|
156 | }
|
---|
157 | inline int visualRow(int logicalRow) const {
|
---|
158 | return verticalHeader->visualIndex(logicalRow);
|
---|
159 | }
|
---|
160 | inline int visualColumn(int logicalCol) const {
|
---|
161 | return horizontalHeader->visualIndex(logicalCol);
|
---|
162 | }
|
---|
163 | inline int logicalRow(int visualRow) const {
|
---|
164 | return verticalHeader->logicalIndex(visualRow);
|
---|
165 | }
|
---|
166 | inline int logicalColumn(int visualCol) const {
|
---|
167 | return horizontalHeader->logicalIndex(visualCol);
|
---|
168 | }
|
---|
169 |
|
---|
170 | int sectionSpanEndLogical(const QHeaderView *header, int logical, int span) const;
|
---|
171 | int sectionSpanSize(const QHeaderView *header, int logical, int span) const;
|
---|
172 | bool spanContainsSection(const QHeaderView *header, int logical, int spanLogical, int span) const;
|
---|
173 | void drawAndClipSpans(const QRegion &area, QPainter *painter,
|
---|
174 | const QStyleOptionViewItemV4 &option, QBitArray *drawn,
|
---|
175 | int firstVisualRow, int lastVisualRow, int firstVisualColumn, int lastVisualColumn);
|
---|
176 | void drawCell(QPainter *painter, const QStyleOptionViewItemV4 &option, const QModelIndex &index);
|
---|
177 |
|
---|
178 | bool showGrid;
|
---|
179 | Qt::PenStyle gridStyle;
|
---|
180 | int rowSectionAnchor;
|
---|
181 | int columnSectionAnchor;
|
---|
182 | int columnResizeTimerID;
|
---|
183 | int rowResizeTimerID;
|
---|
184 | QList<int> columnsToUpdate;
|
---|
185 | QList<int> rowsToUpdate;
|
---|
186 | QHeaderView *horizontalHeader;
|
---|
187 | QHeaderView *verticalHeader;
|
---|
188 | QWidget *cornerWidget;
|
---|
189 | bool sortingEnabled;
|
---|
190 | bool geometryRecursionBlock;
|
---|
191 | QPoint visualCursor; // (Row,column) cell coordinates to track through span navigation.
|
---|
192 |
|
---|
193 | QSpanCollection spans;
|
---|
194 |
|
---|
195 | void setSpan(int row, int column, int rowSpan, int columnSpan);
|
---|
196 | QSpanCollection::Span span(int row, int column) const;
|
---|
197 | inline int rowSpan(int row, int column) const {
|
---|
198 | return span(row, column).height();
|
---|
199 | }
|
---|
200 | inline int columnSpan(int row, int column) const {
|
---|
201 | return span(row, column).width();
|
---|
202 | }
|
---|
203 | inline bool hasSpans() const {
|
---|
204 | return !spans.spans.isEmpty();
|
---|
205 | }
|
---|
206 | inline int rowSpanHeight(int row, int span) const {
|
---|
207 | return sectionSpanSize(verticalHeader, row, span);
|
---|
208 | }
|
---|
209 | inline int columnSpanWidth(int column, int span) const {
|
---|
210 | return sectionSpanSize(horizontalHeader, column, span);
|
---|
211 | }
|
---|
212 | inline int rowSpanEndLogical(int row, int span) const {
|
---|
213 | return sectionSpanEndLogical(verticalHeader, row, span);
|
---|
214 | }
|
---|
215 | inline int columnSpanEndLogical(int column, int span) const {
|
---|
216 | return sectionSpanEndLogical(horizontalHeader, column, span);
|
---|
217 | }
|
---|
218 |
|
---|
219 | inline bool isRowHidden(int row) const {
|
---|
220 | return verticalHeader->isSectionHidden(row);
|
---|
221 | }
|
---|
222 | inline bool isColumnHidden(int column) const {
|
---|
223 | return horizontalHeader->isSectionHidden(column);
|
---|
224 | }
|
---|
225 | inline bool isCellEnabled(int row, int column) const {
|
---|
226 | return isIndexEnabled(model->index(row, column, root));
|
---|
227 | }
|
---|
228 | inline bool isVisualRowHiddenOrDisabled(int row, int column) const {
|
---|
229 | int r = logicalRow(row);
|
---|
230 | int c = logicalColumn(column);
|
---|
231 | return isRowHidden(r) || !isCellEnabled(r, c);
|
---|
232 | }
|
---|
233 | inline bool isVisualColumnHiddenOrDisabled(int row, int column) const {
|
---|
234 | int r = logicalRow(row);
|
---|
235 | int c = logicalColumn(column);
|
---|
236 | return isColumnHidden(c) || !isCellEnabled(r, c);
|
---|
237 | }
|
---|
238 |
|
---|
239 | QRect visualSpanRect(const QSpanCollection::Span &span) const;
|
---|
240 |
|
---|
241 | void _q_selectRow(int row);
|
---|
242 | void _q_selectColumn(int column);
|
---|
243 |
|
---|
244 | void selectRow(int row, bool anchor);
|
---|
245 | void selectColumn(int column, bool anchor);
|
---|
246 |
|
---|
247 | void _q_updateSpanInsertedRows(const QModelIndex &parent, int start, int end);
|
---|
248 | void _q_updateSpanInsertedColumns(const QModelIndex &parent, int start, int end);
|
---|
249 | void _q_updateSpanRemovedRows(const QModelIndex &parent, int start, int end);
|
---|
250 | void _q_updateSpanRemovedColumns(const QModelIndex &parent, int start, int end);
|
---|
251 | };
|
---|
252 |
|
---|
253 | QT_END_NAMESPACE
|
---|
254 |
|
---|
255 | #endif // QT_NO_TABLEVIEW
|
---|
256 |
|
---|
257 | #endif // QTABLEVIEW_P_H
|
---|