| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2009 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 QTABLEWIDGET_P_H
|
|---|
| 43 | #define QTABLEWIDGET_P_H
|
|---|
| 44 |
|
|---|
| 45 | //
|
|---|
| 46 | // W A R N I N G
|
|---|
| 47 | // -------------
|
|---|
| 48 | //
|
|---|
| 49 | // This file is not part of the Qt API. This header file may change
|
|---|
| 50 | // from version to version without notice, or even be removed.
|
|---|
| 51 | //
|
|---|
| 52 | // We mean it.
|
|---|
| 53 | //
|
|---|
| 54 |
|
|---|
| 55 | #include <qheaderview.h>
|
|---|
| 56 | #include <qtablewidget.h>
|
|---|
| 57 | #include <qabstractitemmodel.h>
|
|---|
| 58 | #include <private/qabstractitemmodel_p.h>
|
|---|
| 59 | #include <private/qtableview_p.h>
|
|---|
| 60 | #include <private/qwidgetitemdata_p.h>
|
|---|
| 61 |
|
|---|
| 62 | #ifndef QT_NO_TABLEWIDGET
|
|---|
| 63 |
|
|---|
| 64 | QT_BEGIN_NAMESPACE
|
|---|
| 65 |
|
|---|
| 66 | // workaround for VC++ 6.0 linker bug
|
|---|
| 67 | typedef bool(*LessThan)(const QPair<QTableWidgetItem*,int>&,const QPair<QTableWidgetItem*,int>&);
|
|---|
| 68 |
|
|---|
| 69 | class QTableWidgetMimeData : public QMimeData
|
|---|
| 70 | {
|
|---|
| 71 | Q_OBJECT
|
|---|
| 72 | public:
|
|---|
| 73 | QList<QTableWidgetItem*> items;
|
|---|
| 74 | };
|
|---|
| 75 |
|
|---|
| 76 | class QTableModelLessThan
|
|---|
| 77 | {
|
|---|
| 78 | public:
|
|---|
| 79 | inline bool operator()(QTableWidgetItem *i1, QTableWidgetItem *i2) const
|
|---|
| 80 | { return (*i1 < *i2); }
|
|---|
| 81 | };
|
|---|
| 82 |
|
|---|
| 83 | class QTableModelGreaterThan
|
|---|
| 84 | {
|
|---|
| 85 | public:
|
|---|
| 86 | inline bool operator()(QTableWidgetItem *i1, QTableWidgetItem *i2) const
|
|---|
| 87 | { return (*i2 < *i1); }
|
|---|
| 88 | };
|
|---|
| 89 |
|
|---|
| 90 | class QTableModel : public QAbstractTableModel
|
|---|
| 91 | {
|
|---|
| 92 | Q_OBJECT
|
|---|
| 93 | public:
|
|---|
| 94 | enum ItemFlagsExtension {
|
|---|
| 95 | ItemIsHeaderItem = 128
|
|---|
| 96 | }; // we need this to separate header items from other items
|
|---|
| 97 |
|
|---|
| 98 | QTableModel(int rows, int columns, QTableWidget *parent);
|
|---|
| 99 | ~QTableModel();
|
|---|
| 100 |
|
|---|
| 101 | bool insertRows(int row, int count = 1, const QModelIndex &parent = QModelIndex());
|
|---|
| 102 | bool insertColumns(int column, int count = 1, const QModelIndex &parent = QModelIndex());
|
|---|
| 103 |
|
|---|
| 104 | bool removeRows(int row, int count = 1, const QModelIndex &parent = QModelIndex());
|
|---|
| 105 | bool removeColumns(int column, int count = 1, const QModelIndex &parent = QModelIndex());
|
|---|
| 106 |
|
|---|
| 107 | void setItem(int row, int column, QTableWidgetItem *item);
|
|---|
| 108 | QTableWidgetItem *takeItem(int row, int column);
|
|---|
| 109 | QTableWidgetItem *item(int row, int column) const;
|
|---|
| 110 | QTableWidgetItem *item(const QModelIndex &index) const;
|
|---|
| 111 | void removeItem(QTableWidgetItem *item);
|
|---|
| 112 |
|
|---|
| 113 | void setHorizontalHeaderItem(int section, QTableWidgetItem *item);
|
|---|
| 114 | void setVerticalHeaderItem(int section, QTableWidgetItem *item);
|
|---|
| 115 | QTableWidgetItem *takeHorizontalHeaderItem(int section);
|
|---|
| 116 | QTableWidgetItem *takeVerticalHeaderItem(int section);
|
|---|
| 117 | QTableWidgetItem *horizontalHeaderItem(int section);
|
|---|
| 118 | QTableWidgetItem *verticalHeaderItem(int section);
|
|---|
| 119 |
|
|---|
| 120 | QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const
|
|---|
| 121 | { return QAbstractTableModel::index(row, column, parent); }
|
|---|
| 122 |
|
|---|
| 123 | QModelIndex index(const QTableWidgetItem *item) const;
|
|---|
| 124 |
|
|---|
| 125 | void setRowCount(int rows);
|
|---|
| 126 | void setColumnCount(int columns);
|
|---|
| 127 |
|
|---|
| 128 | int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
|---|
| 129 | int columnCount(const QModelIndex &parent = QModelIndex()) const;
|
|---|
| 130 |
|
|---|
| 131 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
|
|---|
| 132 | bool setData(const QModelIndex &index, const QVariant &value, int role);
|
|---|
| 133 | bool setItemData(const QModelIndex &index, const QMap<int, QVariant> &roles);
|
|---|
| 134 |
|
|---|
| 135 | QMap<int, QVariant> itemData(const QModelIndex &index) const;
|
|---|
| 136 |
|
|---|
| 137 | QVariant headerData(int section, Qt::Orientation orientation, int role) const;
|
|---|
| 138 | bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role);
|
|---|
| 139 |
|
|---|
| 140 | Qt::ItemFlags flags(const QModelIndex &index) const;
|
|---|
| 141 |
|
|---|
| 142 | void sort(int column, Qt::SortOrder order);
|
|---|
| 143 | static bool itemLessThan(const QPair<QTableWidgetItem*,int> &left,
|
|---|
| 144 | const QPair<QTableWidgetItem*,int> &right);
|
|---|
| 145 | static bool itemGreaterThan(const QPair<QTableWidgetItem*,int> &left,
|
|---|
| 146 | const QPair<QTableWidgetItem*,int> &right);
|
|---|
| 147 |
|
|---|
| 148 | void ensureSorted(int column, Qt::SortOrder order, int start, int end);
|
|---|
| 149 | QVector<QTableWidgetItem*> columnItems(int column) const;
|
|---|
| 150 | void updateRowIndexes(QModelIndexList &indexes, int movedFromRow, int movedToRow);
|
|---|
| 151 | static QVector<QTableWidgetItem*>::iterator sortedInsertionIterator(
|
|---|
| 152 | const QVector<QTableWidgetItem*>::iterator &begin,
|
|---|
| 153 | const QVector<QTableWidgetItem*>::iterator &end,
|
|---|
| 154 | Qt::SortOrder order, QTableWidgetItem *item);
|
|---|
| 155 |
|
|---|
| 156 | bool isValid(const QModelIndex &index) const;
|
|---|
| 157 | inline long tableIndex(int row, int column) const
|
|---|
| 158 | { return (row * horizontalHeaderItems.count()) + column; }
|
|---|
| 159 |
|
|---|
| 160 | void clear();
|
|---|
| 161 | void clearContents();
|
|---|
| 162 | void itemChanged(QTableWidgetItem *item);
|
|---|
| 163 |
|
|---|
| 164 | QTableWidgetItem *createItem() const;
|
|---|
| 165 | const QTableWidgetItem *itemPrototype() const;
|
|---|
| 166 | void setItemPrototype(const QTableWidgetItem *item);
|
|---|
| 167 |
|
|---|
| 168 | // dnd
|
|---|
| 169 | QStringList mimeTypes() const;
|
|---|
| 170 | QMimeData *mimeData(const QModelIndexList &indexes) const;
|
|---|
| 171 | bool dropMimeData(const QMimeData *data, Qt::DropAction action,
|
|---|
| 172 | int row, int column, const QModelIndex &parent);
|
|---|
| 173 | Qt::DropActions supportedDropActions() const;
|
|---|
| 174 |
|
|---|
| 175 | QMimeData *internalMimeData() const;
|
|---|
| 176 |
|
|---|
| 177 | private:
|
|---|
| 178 | const QTableWidgetItem *prototype;
|
|---|
| 179 | QVector<QTableWidgetItem*> tableItems;
|
|---|
| 180 | QVector<QTableWidgetItem*> verticalHeaderItems;
|
|---|
| 181 | QVector<QTableWidgetItem*> horizontalHeaderItems;
|
|---|
| 182 |
|
|---|
| 183 | // A cache must be mutable if get-functions should have const modifiers
|
|---|
| 184 | mutable QModelIndexList cachedIndexes;
|
|---|
| 185 | };
|
|---|
| 186 |
|
|---|
| 187 | class QTableWidgetPrivate : public QTableViewPrivate
|
|---|
| 188 | {
|
|---|
| 189 | Q_DECLARE_PUBLIC(QTableWidget)
|
|---|
| 190 | public:
|
|---|
| 191 | QTableWidgetPrivate() : QTableViewPrivate() {}
|
|---|
| 192 | inline QTableModel *tableModel() const { return qobject_cast<QTableModel*>(model); }
|
|---|
| 193 | void setup();
|
|---|
| 194 |
|
|---|
| 195 | // view signals
|
|---|
| 196 | void _q_emitItemPressed(const QModelIndex &index);
|
|---|
| 197 | void _q_emitItemClicked(const QModelIndex &index);
|
|---|
| 198 | void _q_emitItemDoubleClicked(const QModelIndex &index);
|
|---|
| 199 | void _q_emitItemActivated(const QModelIndex &index);
|
|---|
| 200 | void _q_emitItemEntered(const QModelIndex &index);
|
|---|
| 201 | // model signals
|
|---|
| 202 | void _q_emitItemChanged(const QModelIndex &index);
|
|---|
| 203 | // selection signals
|
|---|
| 204 | void _q_emitCurrentItemChanged(const QModelIndex &previous, const QModelIndex ¤t);
|
|---|
| 205 | // sorting
|
|---|
| 206 | void _q_sort();
|
|---|
| 207 | void _q_dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
|
|---|
| 208 | };
|
|---|
| 209 |
|
|---|
| 210 | class QTableWidgetItemPrivate
|
|---|
| 211 | {
|
|---|
| 212 | public:
|
|---|
| 213 | QTableWidgetItemPrivate(QTableWidgetItem *item) : q(item), id(-1) {}
|
|---|
| 214 | QTableWidgetItem *q;
|
|---|
| 215 | int id;
|
|---|
| 216 | };
|
|---|
| 217 |
|
|---|
| 218 | QT_END_NAMESPACE
|
|---|
| 219 |
|
|---|
| 220 | #endif // QT_NO_TABLEWIDGET
|
|---|
| 221 |
|
|---|
| 222 | #endif // QTABLEWIDGET_P_H
|
|---|