Qt 4.8
qtableview_p.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
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 
66 
78 {
79 public:
80  struct Span
81  {
82  int m_top;
83  int m_left;
84  int m_bottom;
85  int m_right;
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 
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 
120  SpanList spans; //lists of all spans
121 private:
122  //the indexes are negative so the QMap::lowerBound do what i need.
125  Index index;
126 
127  bool cleanSpanSubIndex(SubIndex &subindex, int end, bool update = false);
128 };
129 
131 
132 
134 {
136 public:
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  inline int accessibleTable2Index(const QModelIndex &index) const {
171  return (index.row() + (horizontalHeader ? 1 : 0)) * (index.model()->columnCount() + (verticalHeader ? 1 : 0))
172  + index.column() + (verticalHeader ? 1 : 0) + 1;
173  }
174 
175  int sectionSpanEndLogical(const QHeaderView *header, int logical, int span) const;
176  int sectionSpanSize(const QHeaderView *header, int logical, int span) const;
177  bool spanContainsSection(const QHeaderView *header, int logical, int spanLogical, int span) const;
178  void drawAndClipSpans(const QRegion &area, QPainter *painter,
179  const QStyleOptionViewItemV4 &option, QBitArray *drawn,
180  int firstVisualRow, int lastVisualRow, int firstVisualColumn, int lastVisualColumn);
181  void drawCell(QPainter *painter, const QStyleOptionViewItemV4 &option, const QModelIndex &index);
182 
183  bool showGrid;
196  QPoint visualCursor; // (Row,column) cell coordinates to track through span navigation.
197 
199 
200  void setSpan(int row, int column, int rowSpan, int columnSpan);
201  QSpanCollection::Span span(int row, int column) const;
202  inline int rowSpan(int row, int column) const {
203  return span(row, column).height();
204  }
205  inline int columnSpan(int row, int column) const {
206  return span(row, column).width();
207  }
208  inline bool hasSpans() const {
209  return !spans.spans.isEmpty();
210  }
211  inline int rowSpanHeight(int row, int span) const {
212  return sectionSpanSize(verticalHeader, row, span);
213  }
214  inline int columnSpanWidth(int column, int span) const {
215  return sectionSpanSize(horizontalHeader, column, span);
216  }
217  inline int rowSpanEndLogical(int row, int span) const {
218  return sectionSpanEndLogical(verticalHeader, row, span);
219  }
220  inline int columnSpanEndLogical(int column, int span) const {
221  return sectionSpanEndLogical(horizontalHeader, column, span);
222  }
223 
224  inline bool isRowHidden(int row) const {
225  return verticalHeader->isSectionHidden(row);
226  }
227  inline bool isColumnHidden(int column) const {
228  return horizontalHeader->isSectionHidden(column);
229  }
230  inline bool isCellEnabled(int row, int column) const {
231  return isIndexEnabled(model->index(row, column, root));
232  }
233  inline bool isVisualRowHiddenOrDisabled(int row, int column) const {
234  int r = logicalRow(row);
235  int c = logicalColumn(column);
236  return isRowHidden(r) || !isCellEnabled(r, c);
237  }
238  inline bool isVisualColumnHiddenOrDisabled(int row, int column) const {
239  int r = logicalRow(row);
240  int c = logicalColumn(column);
241  return isColumnHidden(c) || !isCellEnabled(r, c);
242  }
243 
244  QRect visualSpanRect(const QSpanCollection::Span &span) const;
245 
246  void _q_selectRow(int row);
247  void _q_selectColumn(int column);
248 
249  void selectRow(int row, bool anchor);
250  void selectColumn(int column, bool anchor);
251 
252  void _q_updateSpanInsertedRows(const QModelIndex &parent, int start, int end);
253  void _q_updateSpanInsertedColumns(const QModelIndex &parent, int start, int end);
254  void _q_updateSpanRemovedRows(const QModelIndex &parent, int start, int end);
255  void _q_updateSpanRemovedColumns(const QModelIndex &parent, int start, int end);
256 };
257 
259 
260 #endif // QT_NO_TABLEVIEW
261 
262 #endif // QTABLEVIEW_P_H
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const =0
Returns the number of columns for the children of the given parent.
bool isCellEnabled(int row, int column) const
Definition: qtableview_p.h:230
unsigned char c[8]
Definition: qnumeric_p.h:62
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
bool isColumnHidden(int column) const
Definition: qtableview_p.h:227
int visualColumn(int logicalCol) const
Definition: qtableview_p.h:160
Span(int row, int column, int rowCount, int columnCount)
Definition: qtableview_p.h:89
QList< int > rowsToUpdate
Definition: qtableview_p.h:190
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
The QStyleOptionViewItemV4 class is used to describe the parameters necessary for drawing a frame in ...
Definition: qstyleoption.h:609
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlinkedlist.h:103
static void clear(QVariant::Private *d)
Definition: qvariant.cpp:197
The QItemSelectionRange class manages information about a range of selected items in a model...
int rowSpan(int row, int column) const
Definition: qtableview_p.h:202
QList< int > columnsToUpdate
Definition: qtableview_p.h:189
QHeaderView * horizontalHeader
Definition: qtableview_p.h:191
bool isSectionHidden(int logicalIndex) const
Returns true if the section specified by logicalIndex is explicitly hidden from the user; otherwise r...
QMap< int, SubIndex > Index
Definition: qtableview_p.h:124
PenStyle
Definition: qnamespace.h:1134
int columnSpanWidth(int column, int span) const
Definition: qtableview_p.h:214
QSpanCollection spans
Definition: qtableview_p.h:198
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
int rowSpanEndLogical(int row, int span) const
Definition: qtableview_p.h:217
bool hasSpans() const
Definition: qtableview_p.h:208
static bool init
QHeaderView * verticalHeader
Definition: qtableview_p.h:192
int row() const
Returns the row this model index refers to.
const QAbstractItemModel * model() const
Returns a pointer to the model containing the item that this index refers to.
int logicalRow(int visualRow) const
Definition: qtableview_p.h:163
int columnSpanEndLogical(int column, int span) const
Definition: qtableview_p.h:220
Q_DECLARE_TYPEINFO(QSpanCollection::Span, Q_MOVABLE_TYPE)
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
bool isVisualColumnHiddenOrDisabled(int row, int column) const
Definition: qtableview_p.h:238
The QTableView class provides a default model/view implementation of a table view.
Definition: qtableview.h:58
bool isVisualRowHiddenOrDisabled(int row, int column) const
Definition: qtableview_p.h:233
bool isRowHidden(int row) const
Definition: qtableview_p.h:224
int visualRow(int logicalRow) const
Definition: qtableview_p.h:157
The QBitArray class provides an array of bits.
Definition: qbitarray.h:54
#define Q_DECLARE_PUBLIC(Class)
Definition: qglobal.h:2477
QLinkedList< Span * > SpanList
Definition: qtableview_p.h:119
int logicalColumn(int visualCol) const
Definition: qtableview_p.h:166
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
The QModelIndex class is used to locate data in a data model.
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
Definition: qnamespace.h:54
#define Q_AUTOTEST_EXPORT
Definition: qglobal.h:1510
quint16 index
int accessibleTable2Index(const QModelIndex &index) const
Definition: qtableview_p.h:170
QMap< int, Span * > SubIndex
Definition: qtableview_p.h:123
bool isHidden(int row, int col) const
Definition: qtableview_p.h:153
int rowSpanHeight(int row, int span) const
Definition: qtableview_p.h:211
static const KeyPair *const end
Qt::PenStyle gridStyle
Definition: qtableview_p.h:184
Q_OUTOFLINE_TEMPLATE void qDeleteAll(ForwardIterator begin, ForwardIterator end)
Definition: qalgorithms.h:319
int columnSpan(int row, int column) const
Definition: qtableview_p.h:205
The QMap class is a template class that provides a skip-list-based dictionary.
Definition: qdatastream.h:67
QWidget * cornerWidget
Definition: qtableview_p.h:193
int column() const
Returns the column this model index refers to.
The QHeaderView class provides a header row or header column for item views.
Definition: qheaderview.h:58
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
static int area(const QSize &s)
Definition: qicon.cpp:155