0
|
1 |
/****************************************************************************
|
|
2 |
**
|
|
3 |
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
4 |
** All rights reserved.
|
|
5 |
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
6 |
**
|
|
7 |
** This file is part of the QtGui module of the Qt Toolkit.
|
|
8 |
**
|
|
9 |
** $QT_BEGIN_LICENSE:LGPL$
|
|
10 |
** No Commercial Usage
|
|
11 |
** This file contains pre-release code and may not be distributed.
|
|
12 |
** You may use this file in accordance with the terms and conditions
|
|
13 |
** contained in the Technology Preview License Agreement accompanying
|
|
14 |
** this package.
|
|
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 |
** If you have questions regarding the use of this file, please contact
|
|
29 |
** Nokia at qt-info@nokia.com.
|
|
30 |
**
|
|
31 |
**
|
|
32 |
**
|
|
33 |
**
|
|
34 |
**
|
|
35 |
**
|
|
36 |
**
|
|
37 |
**
|
|
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 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 |
typedef QLinkedList<Span *> SpanList;
|
|
116 |
SpanList spans; //lists of all spans
|
|
117 |
private:
|
|
118 |
//the indexes are negative so the QMap::lowerBound do what i need.
|
|
119 |
typedef QMap<int, Span *> SubIndex;
|
|
120 |
typedef QMap<int, SubIndex> Index;
|
|
121 |
Index index;
|
|
122 |
|
|
123 |
bool cleanSpanSubIndex(SubIndex &subindex, int end, bool update = false);
|
|
124 |
};
|
|
125 |
|
|
126 |
Q_DECLARE_TYPEINFO ( QSpanCollection::Span, Q_MOVABLE_TYPE);
|
|
127 |
|
|
128 |
|
|
129 |
class QTableViewPrivate : public QAbstractItemViewPrivate
|
|
130 |
{
|
|
131 |
Q_DECLARE_PUBLIC(QTableView)
|
|
132 |
public:
|
|
133 |
QTableViewPrivate()
|
|
134 |
: showGrid(true), gridStyle(Qt::SolidLine),
|
|
135 |
rowSectionAnchor(-1), columnSectionAnchor(-1),
|
|
136 |
columnResizeTimerID(0), rowResizeTimerID(0),
|
|
137 |
horizontalHeader(0), verticalHeader(0),
|
|
138 |
sortingEnabled(false), geometryRecursionBlock(false),
|
|
139 |
visualCursor(QPoint())
|
|
140 |
{
|
|
141 |
wrapItemText = true;
|
|
142 |
#ifndef QT_NO_DRAGANDDROP
|
|
143 |
overwrite = true;
|
|
144 |
#endif
|
|
145 |
}
|
|
146 |
void init();
|
|
147 |
void trimHiddenSelections(QItemSelectionRange *range) const;
|
|
148 |
|
|
149 |
inline bool isHidden(int row, int col) const {
|
|
150 |
return verticalHeader->isSectionHidden(row)
|
|
151 |
|| horizontalHeader->isSectionHidden(col);
|
|
152 |
}
|
|
153 |
inline int visualRow(int logicalRow) const {
|
|
154 |
return verticalHeader->visualIndex(logicalRow);
|
|
155 |
}
|
|
156 |
inline int visualColumn(int logicalCol) const {
|
|
157 |
return horizontalHeader->visualIndex(logicalCol);
|
|
158 |
}
|
|
159 |
inline int logicalRow(int visualRow) const {
|
|
160 |
return verticalHeader->logicalIndex(visualRow);
|
|
161 |
}
|
|
162 |
inline int logicalColumn(int visualCol) const {
|
|
163 |
return horizontalHeader->logicalIndex(visualCol);
|
|
164 |
}
|
|
165 |
|
|
166 |
int sectionSpanEndLogical(const QHeaderView *header, int logical, int span) const;
|
|
167 |
int sectionSpanSize(const QHeaderView *header, int logical, int span) const;
|
|
168 |
bool spanContainsSection(const QHeaderView *header, int logical, int spanLogical, int span) const;
|
|
169 |
void drawAndClipSpans(const QRegion &area, QPainter *painter,
|
|
170 |
const QStyleOptionViewItemV4 &option, QBitArray *drawn,
|
|
171 |
int firstVisualRow, int lastVisualRow, int firstVisualColumn, int lastVisualColumn);
|
|
172 |
void drawCell(QPainter *painter, const QStyleOptionViewItemV4 &option, const QModelIndex &index);
|
|
173 |
|
|
174 |
bool showGrid;
|
|
175 |
Qt::PenStyle gridStyle;
|
|
176 |
int rowSectionAnchor;
|
|
177 |
int columnSectionAnchor;
|
|
178 |
int columnResizeTimerID;
|
|
179 |
int rowResizeTimerID;
|
|
180 |
QList<int> columnsToUpdate;
|
|
181 |
QList<int> rowsToUpdate;
|
|
182 |
QHeaderView *horizontalHeader;
|
|
183 |
QHeaderView *verticalHeader;
|
|
184 |
QWidget *cornerWidget;
|
|
185 |
bool sortingEnabled;
|
|
186 |
bool geometryRecursionBlock;
|
|
187 |
QPoint visualCursor; // (Row,column) cell coordinates to track through span navigation.
|
|
188 |
|
|
189 |
QSpanCollection spans;
|
|
190 |
|
|
191 |
void setSpan(int row, int column, int rowSpan, int columnSpan);
|
|
192 |
QSpanCollection::Span span(int row, int column) const;
|
|
193 |
inline int rowSpan(int row, int column) const {
|
|
194 |
return span(row, column).height();
|
|
195 |
}
|
|
196 |
inline int columnSpan(int row, int column) const {
|
|
197 |
return span(row, column).width();
|
|
198 |
}
|
|
199 |
inline bool hasSpans() const {
|
|
200 |
return !spans.spans.isEmpty();
|
|
201 |
}
|
|
202 |
inline int rowSpanHeight(int row, int span) const {
|
|
203 |
return sectionSpanSize(verticalHeader, row, span);
|
|
204 |
}
|
|
205 |
inline int columnSpanWidth(int column, int span) const {
|
|
206 |
return sectionSpanSize(horizontalHeader, column, span);
|
|
207 |
}
|
|
208 |
inline int rowSpanEndLogical(int row, int span) const {
|
|
209 |
return sectionSpanEndLogical(verticalHeader, row, span);
|
|
210 |
}
|
|
211 |
inline int columnSpanEndLogical(int column, int span) const {
|
|
212 |
return sectionSpanEndLogical(horizontalHeader, column, span);
|
|
213 |
}
|
|
214 |
|
|
215 |
inline bool isRowHidden(int row) const {
|
|
216 |
return verticalHeader->isSectionHidden(row);
|
|
217 |
}
|
|
218 |
inline bool isColumnHidden(int column) const {
|
|
219 |
return horizontalHeader->isSectionHidden(column);
|
|
220 |
}
|
|
221 |
inline bool isCellEnabled(int row, int column) const {
|
|
222 |
return isIndexEnabled(model->index(row, column, root));
|
|
223 |
}
|
|
224 |
inline bool isVisualRowHiddenOrDisabled(int row, int column) const {
|
|
225 |
int r = logicalRow(row);
|
|
226 |
int c = logicalColumn(column);
|
|
227 |
return isRowHidden(r) || !isCellEnabled(r, c);
|
|
228 |
}
|
|
229 |
inline bool isVisualColumnHiddenOrDisabled(int row, int column) const {
|
|
230 |
int r = logicalRow(row);
|
|
231 |
int c = logicalColumn(column);
|
|
232 |
return isColumnHidden(c) || !isCellEnabled(r, c);
|
|
233 |
}
|
|
234 |
|
|
235 |
QRect visualSpanRect(const QSpanCollection::Span &span) const;
|
|
236 |
|
|
237 |
void _q_selectRow(int row);
|
|
238 |
void _q_selectColumn(int column);
|
|
239 |
|
|
240 |
void selectRow(int row, bool anchor);
|
|
241 |
void selectColumn(int column, bool anchor);
|
|
242 |
|
|
243 |
void _q_updateSpanInsertedRows(const QModelIndex &parent, int start, int end);
|
|
244 |
void _q_updateSpanInsertedColumns(const QModelIndex &parent, int start, int end);
|
|
245 |
void _q_updateSpanRemovedRows(const QModelIndex &parent, int start, int end);
|
|
246 |
void _q_updateSpanRemovedColumns(const QModelIndex &parent, int start, int end);
|
|
247 |
};
|
|
248 |
|
|
249 |
QT_END_NAMESPACE
|
|
250 |
|
|
251 |
#endif // QT_NO_TABLEVIEW
|
|
252 |
|
|
253 |
#endif // QTABLEVIEW_P_H
|