22 #include <QAbstractItemModel> 25 #include <QItemSelection> 26 #include <QStyledItemDelegate> 27 #include <QTableWidget> 30 #include "ginteractor.h" 34 class _Internal_QTableWidget;
75 QWidget* parent =
nullptr);
94 virtual void clearCell(
int row,
int column);
115 virtual void fill(
const string& text);
121 virtual string
get(
int row,
int column)
const;
178 string
getType()
const override;
192 virtual int height()
const;
248 virtual void select(
int row,
int column);
254 virtual void set(
int row,
int column,
const string& text);
273 virtual void setCellAlignment(
int row,
int column, HorizontalAlignment alignment);
297 virtual void setCellFont(
int row,
int column,
const string& font);
327 void setColor(
const string& color)
override;
401 virtual void setEditorValue(
int row,
int column,
const string& text);
406 void setFont(
const QFont& font)
override;
412 void setFont(
const string& font)
override;
463 virtual void setRowFont(
int row,
const string& font);
516 virtual int width()
const;
526 HorizontalAlignment alignment;
533 alignment = ALIGN_LEFT;
537 return background >= 0
543 void mergeWith(
const TableStyle& other) {
544 if (other.background >= 0) {
545 background = other.background;
547 if (other.foreground >= 0) {
548 foreground = other.foreground;
550 if (!other.font.empty()) {
553 if (other.alignment >= 0) {
554 alignment = other.alignment;
558 TableStyle mergedWith(
const TableStyle& other) {
559 TableStyle copy = *
this;
560 copy.mergeWith(other);
564 static TableStyle unset() {
566 style.background = -1;
567 style.foreground = -1;
569 style.alignment = (HorizontalAlignment) -1;
578 static TableStyle _defaultCellStyle;
581 _Internal_QTableWidget* _iqtableview;
585 std::map<int, TableStyle> _rowStyles;
586 std::map<int, TableStyle> _columnStyles;
587 TableStyle _globalCellStyle;
589 void applyStyleToCell(
int row,
int column,
const TableStyle& style);
594 void checkColumn(
const string& member,
int column)
const;
595 void checkIndex(
const string& member,
int row,
int column)
const;
596 void checkRow(
const string& member,
int row)
const;
598 void ensureColumnStyle(
int column);
599 void ensureDefaultFormatting()
const;
600 void ensureGlobalCellStyle();
601 void ensureRowStyle(
int row);
602 TableStyle getMergedStyleForCell(
int row,
int column);
605 virtual void setCellAlignmentInternal(
int row,
int column, HorizontalAlignment alignment);
606 virtual void setCellBackgroundInternal(
int row,
int column,
int color);
607 virtual void setCellFontInternal(
int row,
int column,
const string& font);
608 virtual void setCellForegroundInternal(
int row,
int column,
int color);
610 static string toExcelColumnName(
int col);
613 void updateColumnHeaders();
615 friend class _Internal_QTableWidget;
622 class _Internal_QItemDelegate :
public QStyledItemDelegate {
626 _Internal_QItemDelegate(QObject* parent =
nullptr);
627 virtual QWidget* createEditor(QWidget* parent,
const QStyleOptionViewItem& option,
const QModelIndex& index)
const;
628 virtual void destroyEditor(QWidget* editor,
const QModelIndex& index)
const;
629 virtual QWidget* getEditor()
const;
640 class _Internal_QTableWidget :
public QTableWidget,
public _Internal_QWidget {
644 _Internal_QTableWidget(
GTable* gtable,
int rows,
int columns, QWidget* parent =
nullptr);
645 void detach()
override;
646 bool edit(
const QModelIndex& index, QAbstractItemView::EditTrigger trigger, QEvent* event)
override;
647 virtual QWidget* getEditor()
const;
648 virtual _Internal_QItemDelegate* getItemDelegate()
const;
649 virtual bool isEditing()
const;
650 void closeEditor(QWidget* editor, QAbstractItemDelegate::EndEditHint hint)
override;
651 void keyPressEvent(QKeyEvent* event)
override;
652 QSize sizeHint()
const override;
655 void handleCellChange(
int row,
int column);
656 void handleCellDoubleClick(
int row,
int column);
657 void handleSelectionChange(
const QItemSelection& selected,
const QItemSelection& deselected);
661 _Internal_QItemDelegate* _delegate;
664 void fireTableEvent(EventType eventType,
const string& eventName,
int row = -1,
int col = -1);
void setFont(const QFont &font) override
Sets the font used to display each cell's text.
Definition: gtable.cpp:579
virtual void clearFormatting()
Removes any per-cell/column/row formatting that has been applied to the table.
Definition: gtable.cpp:107
virtual double getRowHeight(int row) const
Returns the height of the given row index in pixels.
Definition: gtable.cpp:218
virtual void setEditorValue(int row, int column, string text)
Modifies the value in the cell that is currently being edited to store the given text.
Definition: gtable.cpp:566
virtual void setRowFont(int row, string font)
Sets the text font of the given row to the given font.
Definition: gtable.cpp:702
A GTable represents a graphical editable 2D table, like a mediocre facsimile of an Excel spreadsheet...
Definition: gtable.h:52
virtual int getSelectedColumn() const
Returns the column of the cell that is currently selected, or -1 if no cell is currently selected...
Definition: gtable.cpp:248
virtual void setCellFont(int row, int column, string font)
Sets the text font of the given cell to the given RGB color.
Definition: gtable.cpp:422
virtual void fill(string text)
Sets every cell in the table to have the given value.
Definition: gtable.cpp:174
virtual void setHorizontalAlignment(HorizontalAlignment alignment)
Sets the horizontal alignment of the text in all cells in the table.
Definition: gtable.cpp:642
virtual void setColumnWidth(int column, double width)
Sets the given column index to have the given width in pixels.
Definition: gtable.cpp:542
virtual bool hasSelectedCell() const
Returns true if a cell is currently selected.
Definition: gtable.cpp:264
virtual void setColumnAlignment(int column, HorizontalAlignment alignment)
Sets the horizontal alignment of the given column.
Definition: gtable.cpp:458
void setForeground(int rgb) override
Sets the color used for the text of each cell.
Definition: gtable.cpp:610
virtual void removeTableListener()
Removes the table listener from this button so that it will no longer call it when events occur...
Definition: gtable.cpp:289
virtual void setCellAlignment(int row, int column, HorizontalAlignment alignment)
Sets the horizontal alignment of the given cell.
Definition: gtable.cpp:394
virtual void setCellForeground(int row, int column, int color)
Sets the foreground/text color of the given cell to the given color.
Definition: gtable.cpp:433
virtual int numRows() const
Returns the number of rows in the table.
Definition: gtable.cpp:285
void requestFocus() override
Transfers keyboard focus to this interactor.
Definition: gtable.cpp:300
virtual bool rowColumnHeadersVisible() const
Returns whether row and column headers are shown in the table.
Definition: gtable.cpp:341
virtual int numCols() const
Returns the number of columns in the table.
Definition: gtable.cpp:281
virtual void autofitColumnWidths()
Changes widths of all columns to be perfectly large enough to fit their contents. ...
Definition: gtable.cpp:70
string getType() const override
Returns a string representing the class name of this interactor, such as "GButton" or "GCheckBox"...
Definition: gtable.cpp:256
virtual double getColumnWidth(int column) const
Returns the width of the given column index in pixels.
Definition: gtable.cpp:195
virtual void setRowHeight(int row, double width)
Sets the given row index to have the given height in pixels.
Definition: gtable.cpp:744
This abstract class is the superclass for all graphical interactors.
Definition: ginteractor.h:48
virtual void setColumnForeground(int column, int color)
Sets the foreground/text color of the given column to the given color.
Definition: gtable.cpp:507
GTable(int rows=0, int columns=0, double width=0, double height=0, QWidget* parent=nullptr)
Constructs a new table with the given dimensions and (optional) size.
Definition: gtable.cpp:43
virtual void setCellBackground(int row, int column, int color)
Sets the background color of the given cell to the given color.
Definition: gtable.cpp:407
virtual void setTableListener(GEventListener func)
Sets the given function to be called when events occur in this table.
Definition: gtable.cpp:761
virtual void setSelectedCellValue(string text)
Sets the text in the cell that is currently selected.
Definition: gtable.cpp:754
virtual void setColumnBackground(int column, int color)
Sets the background color of the given column to the given color.
Definition: gtable.cpp:473
virtual void clearCellFormatting(int row, int column)
Removes any formatting that has been applied to the given cell.
Definition: gtable.cpp:123
ColumnHeaderStyle
Styles of column header labels that can be shown.
Definition: gtable.h:61
virtual string getSelectedCellValue() const
Returns the text in the cell that is currently selected.
Definition: gtable.cpp:239
virtual void clearCell(int row, int column)
Sets the given cell to store an empty string value.
Definition: gtable.cpp:102
virtual void clear()
Sets all cells in the table to store an empty string value.
Definition: gtable.cpp:94
virtual int height() const
Returns the number of rows in the table.
Definition: gtable.cpp:269
virtual int getSelectedRow() const
Returns the row of the cell that is currently selected, or -1 if no cell is currently selected...
Definition: gtable.cpp:252
virtual int width() const
Returns the number of columns in the table.
Definition: gtable.cpp:816
virtual void setRowBackground(int row, int rgb)
Sets the background color of the given row to the given RGB color.
Definition: gtable.cpp:683
virtual void resize(int numRows, int numCols)
Modifies the table to have the given number of rows and columns.
Definition: gtable.cpp:311
virtual void setColumnHeaderStyle(ColumnHeaderStyle style)
Sets the column headers to use the given style.
Definition: gtable.cpp:526
virtual ColumnHeaderStyle getColumnHeaderStyle() const
Returns the column headers to use the given style.
Definition: gtable.cpp:191
void setBackground(int rgb) override
Sets the background color that appears behind each cell.
Definition: gtable.cpp:362
virtual bool isEditable() const
Returns whether cells of the table can be edited.
Definition: gtable.cpp:277
QWidget* getWidget() const override
Returns a direct pointer to the internal Qt widget being wrapped by this interactor.
Definition: gtable.cpp:260
virtual void setEditable(bool editable)
Sets whether cells of the table can be edited.
Definition: gtable.cpp:552
virtual void setRowAlignment(int row, HorizontalAlignment alignment)
Sets the horizontal alignment of the given row.
Definition: gtable.cpp:668
virtual bool inTableBounds(int row, int column) const
Returns true if the given 0-based row/column index is within the bounds of the table.
Definition: gtable.cpp:273
_Internal_QWidget* getInternalWidget() const override
Returns a direct pointer to the internal Qt widget being wrapped by this interactor.
Definition: gtable.cpp:200
void setColor(int rgb) override
Sets the color used for the text of each cell.
Definition: gtable.cpp:450
virtual void setColumnFont(int column, string font)
Sets the text font of the given column to the given RGB color.
Definition: gtable.cpp:492
virtual void setRowColumnHeadersVisible(bool visible)
Sets whether row and column headers should be shown in the table.
Definition: gtable.cpp:737
virtual void clearSelection()
Deselects any currently selected cell.
Definition: gtable.cpp:143
virtual void setRowForeground(int row, int rgb)
Sets the foreground/text color of the given row to the given color.
Definition: gtable.cpp:717
~GTable() override
Definition: gtable.cpp:57
virtual GridLocation getSelectedCell() const
Returns the row and column of the cell that is currently selected.
Definition: gtable.cpp:223
virtual void select(int row, int column)
Sets the given cell to become currently selected, replacing any previous selection.
Definition: gtable.cpp:346