24 #include <QAbstractItemModel> 27 #include <QItemSelection> 28 #include <QStyledItemDelegate> 29 #include <QTableWidget> 31 #include "ginteractor.h" 38 class _Internal_QTableWidget;
79 QWidget* parent =
nullptr);
98 virtual void clearCell(
int row,
int column);
119 virtual void fill(
const string& text);
125 virtual string
get(
int row,
int column)
const;
182 string
getType()
const override;
196 virtual int height()
const;
252 virtual void select(
int row,
int column);
258 virtual void set(
int row,
int column,
const string& text);
301 virtual void setCellFont(
int row,
int column,
const string& font);
331 void setColor(
const string& color)
override;
405 virtual void setEditorValue(
int row,
int column,
const string& text);
410 void setFont(
const QFont& font)
override;
416 void setFont(
const string& font)
override;
467 virtual void setRowFont(
int row,
const string& font);
520 virtual int width()
const;
541 return background >= 0
547 void mergeWith(
const TableStyle& other) {
548 if (other.background >= 0) {
549 background = other.background;
551 if (other.foreground >= 0) {
552 foreground = other.foreground;
554 if (!other.font.empty()) {
557 if (other.alignment >= 0) {
558 alignment = other.alignment;
562 TableStyle mergedWith(
const TableStyle& other) {
563 TableStyle copy = *
this;
564 copy.mergeWith(other);
568 static TableStyle unset() {
570 style.background = -1;
571 style.foreground = -1;
582 static TableStyle _defaultCellStyle;
585 _Internal_QTableWidget* _iqtableview;
589 std::map<int, TableStyle> _rowStyles;
590 std::map<int, TableStyle> _columnStyles;
591 TableStyle _globalCellStyle;
593 void applyStyleToCell(
int row,
int column,
const TableStyle& style);
598 void checkColumn(
const string& member,
int column)
const;
599 void checkIndex(
const string& member,
int row,
int column)
const;
600 void checkRow(
const string& member,
int row)
const;
602 void ensureColumnStyle(
int column);
603 void ensureDefaultFormatting()
const;
604 void ensureGlobalCellStyle();
605 void ensureRowStyle(
int row);
606 TableStyle getMergedStyleForCell(
int row,
int column);
610 virtual void setCellBackgroundInternal(
int row,
int column,
int color);
611 virtual void setCellFontInternal(
int row,
int column,
const string& font);
612 virtual void setCellForegroundInternal(
int row,
int column,
int color);
614 static string toExcelColumnName(
int col);
616 void updateColumnHeaders();
618 friend class _Internal_QTableWidget;
625 class _Internal_QItemDelegate :
public QStyledItemDelegate {
629 _Internal_QItemDelegate(QObject* parent =
nullptr);
630 virtual QWidget* createEditor(QWidget* parent,
const QStyleOptionViewItem& option,
const QModelIndex& index)
const;
631 virtual void destroyEditor(QWidget* editor,
const QModelIndex& index)
const;
632 virtual QWidget* getEditor()
const;
643 class _Internal_QTableWidget :
public QTableWidget,
public _Internal_QWidget {
647 _Internal_QTableWidget(GTable* gtable,
int rows,
int columns, QWidget* parent =
nullptr);
648 void detach()
override;
649 bool edit(
const QModelIndex& index, QAbstractItemView::EditTrigger trigger, QEvent* event)
override;
650 virtual QWidget* getEditor()
const;
651 virtual _Internal_QItemDelegate* getItemDelegate()
const;
652 virtual bool isEditing()
const;
653 void closeEditor(QWidget* editor, QAbstractItemDelegate::EndEditHint hint)
override;
654 void keyPressEvent(QKeyEvent* event)
override;
655 QSize sizeHint()
const override;
658 void handleCellChange(
int row,
int column);
659 void handleCellDoubleClick(
int row,
int column);
660 void handleSelectionChange(
const QItemSelection& selected,
const QItemSelection& deselected);
664 _Internal_QItemDelegate* _delegate;
667 void fireTableEvent(
EventType eventType,
const string& eventName,
int row = -1,
int col = -1);
This is a small structure representing a row and column in a table.
Definition: gtable.h:684
virtual void setCellAlignment(int row, int column, HorizontalAlignment alignment)
Sets the horizontal alignment of the given cell.
Definition: gtable.cpp:400
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:258
virtual void setColumnFont(int column, string font)
Sets the text font of the given column to the given RGB color.
Definition: gtable.cpp:498
HorizontalAlignment
The supported kinds of horizontal alignment of a widget or onscreen object.
Definition: gtypes.h:136
void setFont(const QFont &font) override
Sets the font used to display each cell's text.
Definition: gtable.cpp:585
virtual void setCellBackground(int row, int column, int color)
Sets the background color of the given cell to the given color.
Definition: gtable.cpp:413
bool operator>=(const GTableIndex &loc1, const GTableIndex &loc2)
Definition: gtable.cpp:1089
virtual int height() const
Returns the number of rows in the table.
Definition: gtable.cpp:275
ColumnHeaderStyle
Styles of column header labels that can be shown.
Definition: gtable.h:65
void setColor(int rgb) override
Sets the color used for the text of each cell.
Definition: gtable.cpp:456
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:49
virtual int numCols() const
Returns the number of columns in the table.
Definition: gtable.cpp:287
virtual GTableIndex getSelectedCell() const
Returns the row and column of the cell that is currently selected.
Definition: gtable.cpp:229
std::ostream & operator<<(std::ostream &out, const GEvent &event)
Writes the given event to the given output stream.
Definition: gevent.cpp:494
virtual void autofitColumnWidths()
Changes widths of all columns to be perfectly large enough to fit their contents. ...
Definition: gtable.cpp:76
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:572
virtual void removeTableListener()
Removes the table listener from this button so that it will no longer call it when events occur...
Definition: gtable.cpp:295
bool operator>(const GTableIndex &loc1, const GTableIndex &loc2)
Definition: gtable.cpp:1085
virtual void setColumnForeground(int column, int color)
Sets the foreground/text color of the given column to the given color.
Definition: gtable.cpp:513
void requestFocus() override
Transfers keyboard focus to this interactor.
Definition: gtable.cpp:306
virtual void setRowForeground(int row, int rgb)
Sets the foreground/text color of the given row to the given color.
Definition: gtable.cpp:723
virtual void fill(string text)
Sets every cell in the table to have the given value.
Definition: gtable.cpp:180
GTableIndex()
Constructs a default location 0, 0.
Definition: gtable.cpp:1056
virtual int numRows() const
Returns the number of rows in the table.
Definition: gtable.cpp:291
virtual string getSelectedCellValue() const
Returns the text in the cell that is currently selected.
Definition: gtable.cpp:245
virtual void setEditable(bool editable)
Sets whether cells of the table can be edited.
Definition: gtable.cpp:558
virtual void setHorizontalAlignment(HorizontalAlignment alignment)
Sets the horizontal alignment of the text in all cells in the table.
Definition: gtable.cpp:648
std::function< void(GEvent)> GEventListener
Types for the event listener functions to be passed to various interactors.
Definition: gevent.h:38
bool operator==(const GTableIndex &loc1, const GTableIndex &loc2)
Definition: gtable.cpp:1077
This abstract class is the superclass for all graphical interactors.
Definition: ginteractor.h:52
virtual void setTableListener(GEventListener func)
Sets the given function to be called when events occur in this table.
Definition: gtable.cpp:767
string getType() const override
Returns a string representing the class name of this interactor, such as "GButton" or "GCheckBox"...
Definition: gtable.cpp:262
void setBackground(int rgb) override
Sets the background color that appears behind each cell.
Definition: gtable.cpp:368
virtual double getRowHeight(int row) const
Returns the height of the given row index in pixels.
Definition: gtable.cpp:224
virtual bool hasSelectedCell() const
Returns true if a cell is currently selected.
Definition: gtable.cpp:270
virtual void clearFormatting()
Removes any per-cell/column/row formatting that has been applied to the table.
Definition: gtable.cpp:113
virtual bool isEditable() const
Returns whether cells of the table can be edited.
Definition: gtable.cpp:283
A GTable represents a graphical editable 2D table, like a mediocre facsimile of an Excel spreadsheet...
Definition: gtable.h:56
void setForeground(int rgb) override
Sets the color used for the text of each cell.
Definition: gtable.cpp:616
virtual void clearCellFormatting(int row, int column)
Removes any formatting that has been applied to the given cell.
Definition: gtable.cpp:129
virtual bool rowColumnHeadersVisible() const
Returns whether row and column headers are shown in the table.
Definition: gtable.cpp:347
bool operator<=(const GTableIndex &loc1, const GTableIndex &loc2)
Definition: gtable.cpp:1073
virtual void setColumnBackground(int column, int color)
Sets the background color of the given column to the given color.
Definition: gtable.cpp:479
virtual void setColumnAlignment(int column, HorizontalAlignment alignment)
Sets the horizontal alignment of the given column.
Definition: gtable.cpp:464
std::function< void()> GEventListenerVoid
Types for the event listener functions to be passed to various interactors.
Definition: gevent.h:44
virtual void clearSelection()
Deselects any currently selected cell.
Definition: gtable.cpp:149
virtual void setColumnHeaderStyle(ColumnHeaderStyle style)
Sets the column headers to use the given style.
Definition: gtable.cpp:532
virtual double getColumnWidth(int column) const
Returns the width of the given column index in pixels.
Definition: gtable.cpp:201
virtual void setRowHeight(int row, double width)
Sets the given row index to have the given height in pixels.
Definition: gtable.cpp:750
bool operator<(const GTableIndex &loc1, const GTableIndex &loc2)
Relational operators for comparing table locations.
Definition: gtable.cpp:1068
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:279
virtual void clearCell(int row, int column)
Sets the given cell to store an empty string value.
Definition: gtable.cpp:108
string to_string(const GTableIndex &value)
Returns a string representation of this location, such as "r2c17".
Definition: gtable.cpp:1064
QWidget* getWidget() const override
Returns a direct pointer to the internal Qt widget being wrapped by this interactor.
Definition: gtable.cpp:266
virtual void setColumnWidth(int column, double width)
Sets the given column index to have the given width in pixels.
Definition: gtable.cpp:548
EventType
Defines the event subtypes for all events.
Definition: gevent.h:74
int col
Definition: gtable.h:705
virtual void setSelectedCellValue(string text)
Sets the text in the cell that is currently selected.
Definition: gtable.cpp:760
virtual void setRowFont(int row, string font)
Sets the text font of the given row to the given font.
Definition: gtable.cpp:708
virtual void setRowColumnHeadersVisible(bool visible)
Sets whether row and column headers should be shown in the table.
Definition: gtable.cpp:743
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:254
virtual void setRowAlignment(int row, HorizontalAlignment alignment)
Sets the horizontal alignment of the given row.
Definition: gtable.cpp:674
virtual void resize(int numRows, int numCols)
Modifies the table to have the given number of rows and columns.
Definition: gtable.cpp:317
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:428
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:439
virtual void clear()
Sets all cells in the table to store an empty string value.
Definition: gtable.cpp:100
std::istream & operator>>(std::istream &input, GTableIndex &loc)
Definition: gtable.cpp:1097
virtual void setRowBackground(int row, int rgb)
Sets the background color of the given row to the given RGB color.
Definition: gtable.cpp:689
virtual void select(int row, int column)
Sets the given cell to become currently selected, replacing any previous selection.
Definition: gtable.cpp:352
int row
Definition: gtable.h:704
bool operator!=(const GTableIndex &loc1, const GTableIndex &loc2)
Definition: gtable.cpp:1081
string toString() const
Returns a string representation of this location, such as "r2c17".
Definition: gtable.cpp:1058
virtual ColumnHeaderStyle getColumnHeaderStyle() const
Returns the column headers to use the given style.
Definition: gtable.cpp:197
virtual int width() const
Returns the number of columns in the table.
Definition: gtable.cpp:822
~GTable() override
Definition: gtable.cpp:63
_Internal_QWidget* getInternalWidget() const override
Returns a direct pointer to the internal Qt widget being wrapped by this interactor.
Definition: gtable.cpp:206