1 /**************************************************************************** 2 ** 3 ** DQt - D bindings for the Qt Toolkit 4 ** 5 ** GNU Lesser General Public License Usage 6 ** This file may be used under the terms of the GNU Lesser 7 ** General Public License version 3 as published by the Free Software 8 ** Foundation and appearing in the file LICENSE.LGPL3 included in the 9 ** packaging of this file. Please review the following information to 10 ** ensure the GNU Lesser General Public License version 3 requirements 11 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. 12 ** 13 ****************************************************************************/ 14 module qt.widgets.tablewidget; 15 extern(C++): 16 17 import qt.config; 18 import qt.core.abstractitemmodel; 19 import qt.core.coreevent; 20 import qt.core.itemselectionmodel; 21 import qt.core.list; 22 import qt.core.mimedata; 23 import qt.core.namespace; 24 import qt.core.point; 25 import qt.core.rect; 26 import qt.core.size; 27 import qt.core.string; 28 import qt.core.stringlist; 29 import qt.core.variant; 30 import qt.core.vector; 31 import qt.gui.brush; 32 import qt.gui.color; 33 import qt.gui.event; 34 import qt.gui.font; 35 import qt.gui.icon; 36 import qt.helpers; 37 import qt.widgets.abstractitemview; 38 import qt.widgets.tableview; 39 import qt.widgets.widget; 40 import qt.widgets.widgetitemdata; 41 version(QT_NO_DATASTREAM){}else 42 import qt.core.datastream; 43 44 /+ QT_REQUIRE_CONFIG(tablewidget); +/ 45 46 47 // ### Qt6 unexport the class, remove the user-defined special 3 and make it a literal type. 48 extern(C++, class) struct /+ Q_WIDGETS_EXPORT +/ QTableWidgetSelectionRange 49 { 50 public: 51 @disable this(); 52 pragma(mangle, defaultConstructorMangling(__traits(identifier, typeof(this)))) 53 ref typeof(this) rawConstructor(); 54 static typeof(this) create() 55 { 56 typeof(this) r = typeof(this).init; 57 r.rawConstructor(); 58 return r; 59 } 60 61 this(int top, int left, int bottom, int right); 62 ~this(); 63 64 @disable this(this); 65 this(ref const(QTableWidgetSelectionRange) other); 66 /+ref QTableWidgetSelectionRange operator =(ref const(QTableWidgetSelectionRange) other);+/ 67 68 pragma(inline, true) int topRow() const { return top; } 69 pragma(inline, true) int bottomRow() const { return bottom; } 70 pragma(inline, true) int leftColumn() const { return left; } 71 pragma(inline, true) int rightColumn() const { return right; } 72 pragma(inline, true) int rowCount() const { return bottom - top + 1; } 73 pragma(inline, true) int columnCount() const { return right - left + 1; } 74 75 private: 76 int top; int left; int bottom; int right; 77 } 78 79 /+ class QTableWidget; +/ 80 extern(C++, class) struct QTableModel; 81 extern(C++, class) struct QTableWidgetItemPrivate; 82 83 class /+ Q_WIDGETS_EXPORT +/ QTableWidgetItem 84 { 85 private: 86 /+ friend class QTableWidget; +/ 87 /+ friend class QTableModel; +/ 88 public: 89 enum ItemType { Type = 0, UserType = 1000 } 90 /+ explicit +/this(int type = ItemType.Type); 91 /+ explicit +/this(ref const(QString) text, int type = ItemType.Type); 92 /+ explicit +/this(ref const(QIcon) icon, ref const(QString) text, int type = ItemType.Type); 93 /+ QTableWidgetItem(const QTableWidgetItem &other); +/ 94 /+ virtual +/~this(); 95 96 /+ virtual +/ QTableWidgetItem clone() const; 97 98 pragma(inline, true) final QTableWidget tableWidget() const { return cast(QTableWidget)view; } 99 100 pragma(inline, true) final int row() const 101 { return (view ? view.row(this) : -1); } 102 pragma(inline, true) final int column() const 103 { return (view ? view.column(this) : -1); } 104 105 final void setSelected(bool select); 106 final bool isSelected() const; 107 108 pragma(inline, true) final /+ Qt:: +/qt.core.namespace.ItemFlags flags() const { return itemFlags; } 109 final void setFlags(/+ Qt:: +/qt.core.namespace.ItemFlags flags); 110 111 pragma(inline, true) final QString text() const 112 { return data(/+ Qt:: +/qt.core.namespace.ItemDataRole.DisplayRole).toString(); } 113 pragma(inline, true) final void setText(ref const(QString) atext) 114 { setData(/+ Qt:: +/qt.core.namespace.ItemDataRole.DisplayRole, atext); } 115 final void setText(const(QString) atext) { setText(atext); } 116 117 pragma(inline, true) final QIcon icon() const 118 { return qvariant_cast!(QIcon)(data(/+ Qt:: +/qt.core.namespace.ItemDataRole.DecorationRole)); } 119 pragma(inline, true) final void setIcon(ref const(QIcon) aicon) 120 { setData(/+ Qt:: +/qt.core.namespace.ItemDataRole.DecorationRole, aicon); } 121 122 pragma(inline, true) final QString statusTip() const 123 { return data(/+ Qt:: +/qt.core.namespace.ItemDataRole.StatusTipRole).toString(); } 124 pragma(inline, true) final void setStatusTip(ref const(QString) astatusTip) 125 { setData(/+ Qt:: +/qt.core.namespace.ItemDataRole.StatusTipRole, astatusTip); } 126 127 /+ #ifndef QT_NO_TOOLTIP +/ 128 version(QT_NO_TOOLTIP){}else 129 { 130 pragma(inline, true) final QString toolTip() const 131 { return data(/+ Qt:: +/qt.core.namespace.ItemDataRole.ToolTipRole).toString(); } 132 pragma(inline, true) final void setToolTip(ref const(QString) atoolTip) 133 { setData(/+ Qt:: +/qt.core.namespace.ItemDataRole.ToolTipRole, atoolTip); } 134 } 135 /+ #endif 136 137 #if QT_CONFIG(whatsthis) +/ 138 pragma(inline, true) final QString whatsThis() const 139 { return data(/+ Qt:: +/qt.core.namespace.ItemDataRole.WhatsThisRole).toString(); } 140 pragma(inline, true) final void setWhatsThis(ref const(QString) awhatsThis) 141 { setData(/+ Qt:: +/qt.core.namespace.ItemDataRole.WhatsThisRole, awhatsThis); } 142 /+ #endif +/ 143 144 pragma(inline, true) final QFont font() const 145 { return qvariant_cast!(QFont)(data(/+ Qt:: +/qt.core.namespace.ItemDataRole.FontRole)); } 146 pragma(inline, true) final void setFont(ref const(QFont) afont) 147 { setData(/+ Qt:: +/qt.core.namespace.ItemDataRole.FontRole, afont); } 148 149 pragma(inline, true) final int textAlignment() const 150 { return data(/+ Qt:: +/qt.core.namespace.ItemDataRole.TextAlignmentRole).toInt(); } 151 pragma(inline, true) final void setTextAlignment(int alignment) 152 { setData(/+ Qt:: +/qt.core.namespace.ItemDataRole.TextAlignmentRole, alignment); } 153 154 /+ #if QT_DEPRECATED_SINCE(5, 13) +/ 155 /+ QT_DEPRECATED_X ("Use QTableWidgetItem::background() instead") +/ 156 pragma(inline, true) final QColor backgroundColor() const 157 { return qvariant_cast!(QColor)(data(/+ Qt:: +/qt.core.namespace.ItemDataRole.BackgroundRole)); } 158 /+ QT_DEPRECATED_X ("Use QTableWidgetItem::setBackground() instead") +/ 159 pragma(inline, true) final void setBackgroundColor(ref const(QColor) color) 160 { setData(/+ Qt:: +/qt.core.namespace.ItemDataRole.BackgroundRole, color); } 161 /+ #endif +/ 162 163 pragma(inline, true) final QBrush background() const 164 { return qvariant_cast!(QBrush)(data(/+ Qt:: +/qt.core.namespace.ItemDataRole.BackgroundRole)); } 165 pragma(inline, true) final void setBackground(ref const(QBrush) brush) 166 { setData(/+ Qt:: +/qt.core.namespace.ItemDataRole.BackgroundRole, brush.style() != /+ Qt:: +/qt.core.namespace.BrushStyle.NoBrush ? QVariant.fromValue(brush) : QVariant()); } 167 168 /+ #if QT_DEPRECATED_SINCE(5, 13) +/ 169 /+ QT_DEPRECATED_X ("Use QTableWidgetItem::foreground() instead") +/ 170 pragma(inline, true) final QColor textColor() const 171 { return qvariant_cast!(QColor)(data(/+ Qt:: +/qt.core.namespace.ItemDataRole.ForegroundRole)); } 172 /+ QT_DEPRECATED_X ("Use QTableWidgetItem::setForeground() instead") +/ 173 pragma(inline, true) final void setTextColor(ref const(QColor) color) 174 { setData(/+ Qt:: +/qt.core.namespace.ItemDataRole.ForegroundRole, color); } 175 /+ #endif +/ 176 177 pragma(inline, true) final QBrush foreground() const 178 { return qvariant_cast!(QBrush)(data(/+ Qt:: +/qt.core.namespace.ItemDataRole.ForegroundRole)); } 179 pragma(inline, true) final void setForeground(ref const(QBrush) brush) 180 { setData(/+ Qt:: +/qt.core.namespace.ItemDataRole.ForegroundRole, brush.style() != /+ Qt:: +/qt.core.namespace.BrushStyle.NoBrush ? QVariant.fromValue(brush) : QVariant()); } 181 182 pragma(inline, true) final /+ Qt:: +/qt.core.namespace.CheckState checkState() const 183 { return static_cast!(/+ Qt:: +/qt.core.namespace.CheckState)(data(/+ Qt:: +/qt.core.namespace.ItemDataRole.CheckStateRole).toInt()); } 184 pragma(inline, true) final void setCheckState(/+ Qt:: +/qt.core.namespace.CheckState state) 185 { setData(/+ Qt:: +/qt.core.namespace.ItemDataRole.CheckStateRole, cast(int)state); } 186 187 pragma(inline, true) final QSize sizeHint() const 188 { return qvariant_cast!(QSize)(data(/+ Qt:: +/qt.core.namespace.ItemDataRole.SizeHintRole)); } 189 pragma(inline, true) final void setSizeHint(ref const(QSize) size) 190 { setData(/+ Qt:: +/qt.core.namespace.ItemDataRole.SizeHintRole, size.isValid() ? QVariant(size) : QVariant()); } 191 192 /+ virtual +/ QVariant data(int role) const; 193 /+ virtual +/ void setData(int role, ref const(QVariant) value); 194 final void setData(T)(int role, T value) 195 { 196 static if(is(const(T) == const(QVariant))) 197 QVariant v = value; 198 else 199 QVariant v = QVariant.fromValue(value); 200 setData(role, v); 201 } 202 203 pragma(mangle, mangleOpLess("QTableWidgetItem")) 204 bool opLess(const QTableWidgetItem other) const; 205 206 version(QT_NO_DATASTREAM){}else 207 { 208 /+ virtual +/ void read(ref QDataStream in_); 209 /+ virtual +/ void write(ref QDataStream out_) const; 210 } 211 /+ QTableWidgetItem &operator=(const QTableWidgetItem &other); +/ 212 213 pragma(inline, true) final int type() const { return rtti; } 214 215 private: 216 final QTableModel* tableModel() const; 217 218 private: 219 int rtti; 220 QVector!(QWidgetItemData) values; 221 QTableWidget view; 222 QTableWidgetItemPrivate* d; 223 /+ Qt:: +/qt.core.namespace.ItemFlags itemFlags; 224 } 225 226 /+ #ifndef QT_NO_TOOLTIP 227 #endif 228 229 #if QT_CONFIG(whatsthis) 230 #endif 231 232 #ifndef QT_NO_DATASTREAM 233 Q_WIDGETS_EXPORT QDataStream &operator>>(QDataStream &in, QTableWidgetItem &item); 234 Q_WIDGETS_EXPORT QDataStream &operator<<(QDataStream &out, const QTableWidgetItem &item); 235 #endif +/ 236 237 extern(C++, class) struct QTableWidgetPrivate; 238 239 class /+ Q_WIDGETS_EXPORT +/ QTableWidget : QTableView 240 { 241 mixin(Q_OBJECT); 242 /+ Q_PROPERTY(int rowCount READ rowCount WRITE setRowCount) 243 Q_PROPERTY(int columnCount READ columnCount WRITE setColumnCount) +/ 244 245 /+ friend class QTableModel; +/ 246 public: 247 /+ explicit +/this(QWidget parent = null); 248 this(int rows, int columns, QWidget parent = null); 249 ~this(); 250 251 final void setRowCount(int rows); 252 final int rowCount() const; 253 254 final void setColumnCount(int columns); 255 final int columnCount() const; 256 257 mixin(mangleWindows("?row@QTableWidget@@QEBAHPEBVQTableWidgetItem@@@Z", q{ 258 final int row(const(QTableWidgetItem) item) const; 259 })); 260 mixin(mangleWindows("?column@QTableWidget@@QEBAHPEBVQTableWidgetItem@@@Z", q{ 261 final int column(const(QTableWidgetItem) item) const; 262 })); 263 264 final QTableWidgetItem item(int row, int column) const; 265 final void setItem(int row, int column, QTableWidgetItem item); 266 final QTableWidgetItem takeItem(int row, int column); 267 268 final QTableWidgetItem verticalHeaderItem(int row) const; 269 final void setVerticalHeaderItem(int row, QTableWidgetItem item); 270 final QTableWidgetItem takeVerticalHeaderItem(int row); 271 272 final QTableWidgetItem horizontalHeaderItem(int column) const; 273 final void setHorizontalHeaderItem(int column, QTableWidgetItem item); 274 final QTableWidgetItem takeHorizontalHeaderItem(int column); 275 final void setVerticalHeaderLabels(ref const(QStringList) labels); 276 final void setHorizontalHeaderLabels(ref const(QStringList) labels); 277 278 final int currentRow() const; 279 final int currentColumn() const; 280 final QTableWidgetItem currentItem() const; 281 final void setCurrentItem(QTableWidgetItem item); 282 final void setCurrentItem(QTableWidgetItem item, QItemSelectionModel.SelectionFlags command); 283 final void setCurrentCell(int row, int column); 284 final void setCurrentCell(int row, int column, QItemSelectionModel.SelectionFlags command); 285 286 final void sortItems(int column, /+ Qt:: +/qt.core.namespace.SortOrder order = /+ Qt:: +/qt.core.namespace.SortOrder.AscendingOrder); 287 // final void setSortingEnabled(bool enable); 288 // final bool isSortingEnabled() const; 289 290 final void editItem(QTableWidgetItem item); 291 final void openPersistentEditor(QTableWidgetItem item); 292 final void closePersistentEditor(QTableWidgetItem item); 293 /+ using QAbstractItemView::isPersistentEditorOpen; +/ 294 final bool isPersistentEditorOpen(QTableWidgetItem item) const; 295 296 final QWidget cellWidget(int row, int column) const; 297 final void setCellWidget(int row, int column, QWidget widget); 298 pragma(inline, true) final void removeCellWidget(int arow, int acolumn) 299 { setCellWidget(arow, acolumn, null); } 300 301 /+ #if QT_DEPRECATED_SINCE(5, 13) +/ 302 /+ QT_DEPRECATED_X ("Use QTableWidgetItem::isSelected() instead") +/ 303 final bool isItemSelected(const(QTableWidgetItem) item) const; 304 /+ QT_DEPRECATED_X ("Use QTableWidgetItem::setSelected() instead") +/ 305 final void setItemSelected(const(QTableWidgetItem) item, bool select); 306 /+ #endif +/ 307 final void setRangeSelected(ref const(QTableWidgetSelectionRange) range, bool select); 308 309 final QList!(QTableWidgetSelectionRange) selectedRanges() const; 310 final QList!(QTableWidgetItem) selectedItems() const; 311 final QList!(QTableWidgetItem) findItems(ref const(QString) text, /+ Qt:: +/qt.core.namespace.MatchFlags flags) const; 312 313 final int visualRow(int logicalRow) const; 314 final int visualColumn(int logicalColumn) const; 315 316 final QTableWidgetItem itemAt(ref const(QPoint) p) const; 317 pragma(inline, true) final QTableWidgetItem itemAt(int ax, int ay) const 318 { auto tmp = QPoint(ax, ay); return itemAt(tmp); } 319 final QRect visualItemRect(const(QTableWidgetItem) item) const; 320 321 final const(QTableWidgetItem) itemPrototype() const; 322 final void setItemPrototype(const(QTableWidgetItem) item); 323 324 public /+ Q_SLOTS +/: 325 @QSlot final void scrollToItem(const(QTableWidgetItem) item, QAbstractItemView.ScrollHint hint = ScrollHint.EnsureVisible); 326 @QSlot final void insertRow(int row); 327 @QSlot final void insertColumn(int column); 328 @QSlot final void removeRow(int row); 329 @QSlot final void removeColumn(int column); 330 @QSlot final void clear(); 331 @QSlot final void clearContents(); 332 333 /+ Q_SIGNALS +/public: 334 @QSignal final void itemPressed(QTableWidgetItem item); 335 @QSignal final void itemClicked(QTableWidgetItem item); 336 @QSignal final void itemDoubleClicked(QTableWidgetItem item); 337 338 @QSignal final void itemActivated(QTableWidgetItem item); 339 @QSignal final void itemEntered(QTableWidgetItem item); 340 // ### Qt 6: add changed roles 341 @QSignal final void itemChanged(QTableWidgetItem item); 342 343 @QSignal final void currentItemChanged(QTableWidgetItem current, QTableWidgetItem previous); 344 @QSignal final void itemSelectionChanged(); 345 346 @QSignal final void cellPressed(int row, int column); 347 @QSignal final void cellClicked(int row, int column); 348 @QSignal final void cellDoubleClicked(int row, int column); 349 350 @QSignal final void cellActivated(int row, int column); 351 @QSignal final void cellEntered(int row, int column); 352 @QSignal final void cellChanged(int row, int column); 353 354 @QSignal final void currentCellChanged(int currentRow, int currentColumn, int previousRow, int previousColumn); 355 356 protected: 357 override bool event(QEvent e); 358 /+ virtual +/ QStringList mimeTypes() const; 359 /+ #if QT_VERSION >= QT_VERSION_CHECK(6,0,0) 360 virtual QMimeData *mimeData(const QList<QTableWidgetItem *> &items) const; 361 #else +/ 362 /+ virtual +/ QMimeData mimeData(const(QList!(QTableWidgetItem)) items) const; 363 /+ #endif +/ 364 mixin(mangleWindows("?dropMimeData@QTableWidget@@MEAA_NHHPEBVQMimeData@@W4DropAction@Qt@@@Z", q{ 365 /+ virtual +/ bool dropMimeData(int row, int column, const(QMimeData) data, qt.core.namespace.DropAction action); 366 })); 367 /+ virtual +/ /+ Qt:: +/qt.core.namespace.DropActions supportedDropActions() const; 368 369 /+ #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) 370 public: 371 #else +/ 372 protected: 373 /+ #endif +/ 374 final QList!(QTableWidgetItem) items(const(QMimeData) data) const; 375 376 final QModelIndex indexFromItem(const(QTableWidgetItem) item) const; 377 /+ #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) +/ 378 final QModelIndex indexFromItem(QTableWidgetItem item) const; // ### Qt 6: remove 379 /+ #endif +/ 380 final QTableWidgetItem itemFromIndex(ref const(QModelIndex) index) const; 381 382 protected: 383 /+ #if QT_CONFIG(draganddrop) +/ 384 override void dropEvent(QDropEvent event); 385 /+ #endif +/ 386 private: 387 mixin(mangleWindows("?setModel@QTableView@@UEAAXPEAVQAbstractItemModel@@@Z", q{ 388 protected override void setModel(QAbstractItemModel model); 389 })); 390 391 /+ Q_DECLARE_PRIVATE(QTableWidget) +/ 392 /+ Q_DISABLE_COPY(QTableWidget) +/ 393 394 /+ Q_PRIVATE_SLOT(d_func(), void _q_emitItemPressed(const QModelIndex &index)) 395 Q_PRIVATE_SLOT(d_func(), void _q_emitItemClicked(const QModelIndex &index)) 396 Q_PRIVATE_SLOT(d_func(), void _q_emitItemDoubleClicked(const QModelIndex &index)) 397 Q_PRIVATE_SLOT(d_func(), void _q_emitItemActivated(const QModelIndex &index)) 398 Q_PRIVATE_SLOT(d_func(), void _q_emitItemEntered(const QModelIndex &index)) 399 Q_PRIVATE_SLOT(d_func(), void _q_emitItemChanged(const QModelIndex &index)) 400 Q_PRIVATE_SLOT(d_func(), void _q_emitCurrentItemChanged(const QModelIndex &previous, const QModelIndex ¤t)) 401 Q_PRIVATE_SLOT(d_func(), void _q_sort()) 402 Q_PRIVATE_SLOT(d_func(), void _q_dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)) +/ 403 } 404