Warning, file /include/QtWidgets/qtablewidget.h was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004 #ifndef QTABLEWIDGET_H
0005 #define QTABLEWIDGET_H
0006
0007 #include <QtWidgets/qtableview.h>
0008 #include <QtWidgets/qtwidgetsglobal.h>
0009 #include <QtCore/qlist.h>
0010 #include <QtCore/qvariant.h>
0011
0012 QT_REQUIRE_CONFIG(tablewidget);
0013
0014 QT_BEGIN_NAMESPACE
0015
0016 class QTableWidgetSelectionRange
0017 {
0018 public:
0019 QTableWidgetSelectionRange() = default;
0020 QTableWidgetSelectionRange(int top, int left, int bottom, int right)
0021 : m_top(top), m_left(left), m_bottom(bottom), m_right(right)
0022 {}
0023
0024 friend bool operator==(const QTableWidgetSelectionRange &lhs,
0025 const QTableWidgetSelectionRange &rhs) noexcept
0026 {
0027 return lhs.m_top == rhs.m_top && lhs.m_left == rhs.m_left && lhs.m_bottom == rhs.m_bottom
0028 && lhs.m_right == rhs.m_right;
0029 }
0030 friend bool operator!=(const QTableWidgetSelectionRange &lhs,
0031 const QTableWidgetSelectionRange &rhs) noexcept
0032 { return !(lhs == rhs); }
0033
0034 inline int topRow() const { return m_top; }
0035 inline int bottomRow() const { return m_bottom; }
0036 inline int leftColumn() const { return m_left; }
0037 inline int rightColumn() const { return m_right; }
0038 inline int rowCount() const { return m_bottom - m_top + 1; }
0039 inline int columnCount() const { return m_right - m_left + 1; }
0040 private:
0041 int m_top = -1, m_left = -1, m_bottom = -2, m_right = -2;
0042 };
0043
0044 class QTableWidget;
0045 class QTableModel;
0046 class QWidgetItemData;
0047 class QTableWidgetItemPrivate;
0048
0049 class Q_WIDGETS_EXPORT QTableWidgetItem
0050 {
0051 friend class QTableWidget;
0052 friend class QTableModel;
0053 public:
0054 enum ItemType { Type = 0, UserType = 1000 };
0055 explicit QTableWidgetItem(int type = Type);
0056 explicit QTableWidgetItem(const QString &text, int type = Type);
0057 explicit QTableWidgetItem(const QIcon &icon, const QString &text, int type = Type);
0058 QTableWidgetItem(const QTableWidgetItem &other);
0059 virtual ~QTableWidgetItem();
0060
0061 virtual QTableWidgetItem *clone() const;
0062
0063 inline QTableWidget *tableWidget() const { return view; }
0064
0065 inline int row() const;
0066 inline int column() const;
0067
0068 void setSelected(bool select);
0069 bool isSelected() const;
0070
0071 inline Qt::ItemFlags flags() const { return itemFlags; }
0072 void setFlags(Qt::ItemFlags flags);
0073
0074 inline QString text() const
0075 { return data(Qt::DisplayRole).toString(); }
0076 inline void setText(const QString &text);
0077
0078 inline QIcon icon() const
0079 { return qvariant_cast<QIcon>(data(Qt::DecorationRole)); }
0080 inline void setIcon(const QIcon &icon);
0081
0082 inline QString statusTip() const
0083 { return data(Qt::StatusTipRole).toString(); }
0084 inline void setStatusTip(const QString &statusTip);
0085
0086 #if QT_CONFIG(tooltip)
0087 inline QString toolTip() const
0088 { return data(Qt::ToolTipRole).toString(); }
0089 inline void setToolTip(const QString &toolTip);
0090 #endif
0091
0092 #if QT_CONFIG(whatsthis)
0093 inline QString whatsThis() const
0094 { return data(Qt::WhatsThisRole).toString(); }
0095 inline void setWhatsThis(const QString &whatsThis);
0096 #endif
0097
0098 inline QFont font() const
0099 { return qvariant_cast<QFont>(data(Qt::FontRole)); }
0100 inline void setFont(const QFont &font);
0101
0102 #if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
0103 inline int textAlignment() const
0104 { return data(Qt::TextAlignmentRole).toInt(); }
0105 #else
0106 inline Qt::Alignment textAlignment() const
0107 { return qvariant_cast<Qt::Alignment>(data(Qt::TextAlignmentRole)); }
0108 #endif
0109 #if QT_DEPRECATED_SINCE(6, 4)
0110 QT_DEPRECATED_VERSION_X_6_4("Use the overload taking Qt::Alignment")
0111 inline void setTextAlignment(int alignment)
0112 { setData(Qt::TextAlignmentRole, alignment); }
0113 inline void setTextAlignment(Qt::AlignmentFlag alignment)
0114 { setData(Qt::TextAlignmentRole, QVariant::fromValue(Qt::Alignment(alignment))); }
0115 #endif
0116 inline void setTextAlignment(Qt::Alignment alignment)
0117 { setData(Qt::TextAlignmentRole, QVariant::fromValue(alignment)); }
0118
0119 inline QBrush background() const
0120 { return qvariant_cast<QBrush>(data(Qt::BackgroundRole)); }
0121 inline void setBackground(const QBrush &brush)
0122 { setData(Qt::BackgroundRole, brush.style() != Qt::NoBrush ? QVariant(brush) : QVariant()); }
0123
0124 inline QBrush foreground() const
0125 { return qvariant_cast<QBrush>(data(Qt::ForegroundRole)); }
0126 inline void setForeground(const QBrush &brush)
0127 { setData(Qt::ForegroundRole, brush.style() != Qt::NoBrush ? QVariant(brush) : QVariant()); }
0128
0129 inline Qt::CheckState checkState() const
0130 { return qvariant_cast<Qt::CheckState>(data(Qt::CheckStateRole)); }
0131 inline void setCheckState(Qt::CheckState state)
0132 { setData(Qt::CheckStateRole, state); }
0133
0134 inline QSize sizeHint() const
0135 { return qvariant_cast<QSize>(data(Qt::SizeHintRole)); }
0136 inline void setSizeHint(const QSize &size)
0137 { setData(Qt::SizeHintRole, size.isValid() ? QVariant(size) : QVariant()); }
0138
0139 virtual QVariant data(int role) const;
0140 virtual void setData(int role, const QVariant &value);
0141
0142 virtual bool operator<(const QTableWidgetItem &other) const;
0143
0144 #ifndef QT_NO_DATASTREAM
0145 virtual void read(QDataStream &in);
0146 virtual void write(QDataStream &out) const;
0147 #endif
0148 QTableWidgetItem &operator=(const QTableWidgetItem &other);
0149
0150 inline int type() const { return rtti; }
0151
0152 private:
0153 QTableModel *tableModel() const;
0154
0155 private:
0156 int rtti;
0157 QList<QWidgetItemData> values;
0158 QTableWidget *view;
0159 QTableWidgetItemPrivate *d;
0160 Qt::ItemFlags itemFlags;
0161 };
0162
0163 inline void QTableWidgetItem::setText(const QString &atext)
0164 { setData(Qt::DisplayRole, atext); }
0165
0166 inline void QTableWidgetItem::setIcon(const QIcon &aicon)
0167 { setData(Qt::DecorationRole, aicon); }
0168
0169 inline void QTableWidgetItem::setStatusTip(const QString &astatusTip)
0170 { setData(Qt::StatusTipRole, astatusTip); }
0171
0172 #if QT_CONFIG(tooltip)
0173 inline void QTableWidgetItem::setToolTip(const QString &atoolTip)
0174 { setData(Qt::ToolTipRole, atoolTip); }
0175 #endif
0176
0177 #if QT_CONFIG(whatsthis)
0178 inline void QTableWidgetItem::setWhatsThis(const QString &awhatsThis)
0179 { setData(Qt::WhatsThisRole, awhatsThis); }
0180 #endif
0181
0182 inline void QTableWidgetItem::setFont(const QFont &afont)
0183 { setData(Qt::FontRole, afont); }
0184
0185 #ifndef QT_NO_DATASTREAM
0186 Q_WIDGETS_EXPORT QDataStream &operator>>(QDataStream &in, QTableWidgetItem &item);
0187 Q_WIDGETS_EXPORT QDataStream &operator<<(QDataStream &out, const QTableWidgetItem &item);
0188 #endif
0189
0190 class QTableWidgetPrivate;
0191
0192 class Q_WIDGETS_EXPORT QTableWidget : public QTableView
0193 {
0194 Q_OBJECT
0195 Q_PROPERTY(int rowCount READ rowCount WRITE setRowCount)
0196 Q_PROPERTY(int columnCount READ columnCount WRITE setColumnCount)
0197
0198 friend class QTableModel;
0199 public:
0200 explicit QTableWidget(QWidget *parent = nullptr);
0201 QTableWidget(int rows, int columns, QWidget *parent = nullptr);
0202 ~QTableWidget();
0203
0204 void setRowCount(int rows);
0205 int rowCount() const;
0206
0207 void setColumnCount(int columns);
0208 int columnCount() const;
0209
0210 int row(const QTableWidgetItem *item) const;
0211 int column(const QTableWidgetItem *item) const;
0212
0213 QTableWidgetItem *item(int row, int column) const;
0214 void setItem(int row, int column, QTableWidgetItem *item);
0215 QTableWidgetItem *takeItem(int row, int column);
0216 QList<QTableWidgetItem*> items(const QMimeData *data) const;
0217 QModelIndex indexFromItem(const QTableWidgetItem *item) const;
0218 QTableWidgetItem *itemFromIndex(const QModelIndex &index) const;
0219
0220 QTableWidgetItem *verticalHeaderItem(int row) const;
0221 void setVerticalHeaderItem(int row, QTableWidgetItem *item);
0222 QTableWidgetItem *takeVerticalHeaderItem(int row);
0223
0224 QTableWidgetItem *horizontalHeaderItem(int column) const;
0225 void setHorizontalHeaderItem(int column, QTableWidgetItem *item);
0226 QTableWidgetItem *takeHorizontalHeaderItem(int column);
0227 void setVerticalHeaderLabels(const QStringList &labels);
0228 void setHorizontalHeaderLabels(const QStringList &labels);
0229
0230 int currentRow() const;
0231 int currentColumn() const;
0232 QTableWidgetItem *currentItem() const;
0233 void setCurrentItem(QTableWidgetItem *item);
0234 void setCurrentItem(QTableWidgetItem *item, QItemSelectionModel::SelectionFlags command);
0235 void setCurrentCell(int row, int column);
0236 void setCurrentCell(int row, int column, QItemSelectionModel::SelectionFlags command);
0237
0238 void sortItems(int column, Qt::SortOrder order = Qt::AscendingOrder);
0239 void setSortingEnabled(bool enable);
0240 bool isSortingEnabled() const;
0241
0242 void editItem(QTableWidgetItem *item);
0243 void openPersistentEditor(QTableWidgetItem *item);
0244 void closePersistentEditor(QTableWidgetItem *item);
0245 using QAbstractItemView::isPersistentEditorOpen;
0246 bool isPersistentEditorOpen(QTableWidgetItem *item) const;
0247
0248 QWidget *cellWidget(int row, int column) const;
0249 void setCellWidget(int row, int column, QWidget *widget);
0250 inline void removeCellWidget(int row, int column);
0251
0252 void setRangeSelected(const QTableWidgetSelectionRange &range, bool select);
0253
0254 QList<QTableWidgetSelectionRange> selectedRanges() const;
0255 QList<QTableWidgetItem*> selectedItems() const;
0256 QList<QTableWidgetItem*> findItems(const QString &text, Qt::MatchFlags flags) const;
0257
0258 int visualRow(int logicalRow) const;
0259 int visualColumn(int logicalColumn) const;
0260
0261 QTableWidgetItem *itemAt(const QPoint &p) const;
0262 inline QTableWidgetItem *itemAt(int x, int y) const;
0263 QRect visualItemRect(const QTableWidgetItem *item) const;
0264
0265 const QTableWidgetItem *itemPrototype() const;
0266 void setItemPrototype(const QTableWidgetItem *item);
0267
0268 public Q_SLOTS:
0269 void scrollToItem(const QTableWidgetItem *item, QAbstractItemView::ScrollHint hint = EnsureVisible);
0270 void insertRow(int row);
0271 void insertColumn(int column);
0272 void removeRow(int row);
0273 void removeColumn(int column);
0274 void clear();
0275 void clearContents();
0276
0277 Q_SIGNALS:
0278 void itemPressed(QTableWidgetItem *item);
0279 void itemClicked(QTableWidgetItem *item);
0280 void itemDoubleClicked(QTableWidgetItem *item);
0281
0282 void itemActivated(QTableWidgetItem *item);
0283 void itemEntered(QTableWidgetItem *item);
0284 void itemChanged(QTableWidgetItem *item);
0285
0286 void currentItemChanged(QTableWidgetItem *current, QTableWidgetItem *previous);
0287 void itemSelectionChanged();
0288
0289 void cellPressed(int row, int column);
0290 void cellClicked(int row, int column);
0291 void cellDoubleClicked(int row, int column);
0292
0293 void cellActivated(int row, int column);
0294 void cellEntered(int row, int column);
0295 void cellChanged(int row, int column);
0296
0297 void currentCellChanged(int currentRow, int currentColumn, int previousRow, int previousColumn);
0298
0299 protected:
0300 bool event(QEvent *e) override;
0301 virtual QStringList mimeTypes() const;
0302 virtual QMimeData *mimeData(const QList<QTableWidgetItem *> &items) const;
0303 virtual bool dropMimeData(int row, int column, const QMimeData *data, Qt::DropAction action);
0304 virtual Qt::DropActions supportedDropActions() const;
0305
0306 protected:
0307 #if QT_CONFIG(draganddrop)
0308 void dropEvent(QDropEvent *event) override;
0309 #endif
0310 private:
0311 void setModel(QAbstractItemModel *model) override;
0312
0313 Q_DECLARE_PRIVATE(QTableWidget)
0314 Q_DISABLE_COPY(QTableWidget)
0315 };
0316
0317 inline void QTableWidget::removeCellWidget(int arow, int acolumn)
0318 { setCellWidget(arow, acolumn, nullptr); }
0319
0320 inline QTableWidgetItem *QTableWidget::itemAt(int ax, int ay) const
0321 { return itemAt(QPoint(ax, ay)); }
0322
0323 inline int QTableWidgetItem::row() const
0324 { return (view ? view->row(this) : -1); }
0325
0326 inline int QTableWidgetItem::column() const
0327 { return (view ? view->column(this) : -1); }
0328
0329 QT_END_NAMESPACE
0330
0331 #endif