ManaPlus
Public Member Functions | Protected Attributes
StaticTableModel Class Reference

#include <tablemodel.h>

Inheritance diagram for StaticTableModel:
TableModel

Public Member Functions

 StaticTableModel (const int width, const int height)
 
 ~StaticTableModel ()
 
void set (const int row, const int column, Widget *const widget)
 
void fixColumnWidth (const int column, const int width)
 
void fixRowHeight (const int height)
 
void resize ()
 
int getRows () const
 
int getColumns () const
 
int getRowHeight () const
 
int getWidth () const
 
int getHeight () const
 
int getColumnWidth (const int index) const
 
WidgetgetElementAt (const int row, const int column) const
 
- Public Member Functions inherited from TableModel
virtual ~TableModel ()
 
virtual void installListener (TableModelListener *const listener)
 
virtual void removeListener (TableModelListener *const listener)
 

Protected Attributes

int mRows
 
int mColumns
 
int mHeight
 
std::vector< Widget * > mTableModel
 
std::vector< int > mWidths
 

Additional Inherited Members

- Protected Member Functions inherited from TableModel
 TableModel ()
 
virtual void signalBeforeUpdate ()
 
virtual void signalAfterUpdate ()
 

Detailed Description

Definition at line 100 of file tablemodel.h.

Constructor & Destructor Documentation

◆ StaticTableModel()

StaticTableModel::StaticTableModel ( const int  width,
const int  height 
)

Definition at line 69 of file tablemodel.cpp.

69  :
70  TableModel(),
71  mRows(row),
72  mColumns(column),
73  mHeight(1),
74  mTableModel(),
75  mWidths()
76 {
77  mTableModel.resize(row * column, nullptr);
78  mWidths.resize(column, 1);
79 }
std::vector< int > mWidths
Definition: tablemodel.h:151
std::vector< Widget * > mTableModel
Definition: tablemodel.h:150

References mTableModel, and mWidths.

◆ ~StaticTableModel()

StaticTableModel::~StaticTableModel ( )

Definition at line 81 of file tablemodel.cpp.

82 {
84  mTableModel.clear();
85 }
void delete_all(Container &c)
Definition: dtor.h:56

References delete_all(), and mTableModel.

Member Function Documentation

◆ fixColumnWidth()

void StaticTableModel::fixColumnWidth ( const int  column,
const int  width 
)

Fixes the column width for a given column; this overrides dynamic width inference.

Semantics are undefined for width 0.

Definition at line 131 of file tablemodel.cpp.

132 {
133  if (width < 0 || column < 0 || column >= mColumns)
134  return;
135 
136  mWidths[column] = -width; // Negate to tag as fixed
137 }

References mColumns, and mWidths.

Referenced by Setup_Relations::Setup_Relations().

◆ fixRowHeight()

void StaticTableModel::fixRowHeight ( const int  height)

Fixes the row height; this overrides dynamic height inference.

Semantics are undefined for width 0.

Definition at line 139 of file tablemodel.cpp.

140 {
141  if (height < 0)
142  return;
143 
144  mHeight = -height;
145 }

References mHeight.

◆ getColumns()

int StaticTableModel::getColumns ( ) const
virtual

Determines the number of columns in each row

Implements TableModel.

Definition at line 165 of file tablemodel.cpp.

166 {
167  return mColumns;
168 }

References mColumns.

Referenced by resize().

◆ getColumnWidth()

int StaticTableModel::getColumnWidth ( const int  index) const
virtual

Determines the width of each individual column

Implements TableModel.

Definition at line 152 of file tablemodel.cpp.

153 {
154  if (column < 0 || column >= mColumns)
155  return 0;
156 
157  return abs(mWidths[column]);
158 }

References mColumns, and mWidths.

◆ getElementAt()

Widget * StaticTableModel::getElementAt ( const int  row,
const int  column 
) const
virtual

Retrieves the widget stored at the specified location within the table.

Implements TableModel.

Definition at line 125 of file tablemodel.cpp.

127 {
128  return mTableModel[WIDGET_AT(row, column)];
129 }
#define WIDGET_AT(row, column)
Definition: tablemodel.cpp:66

References mTableModel, and WIDGET_AT.

◆ getHeight()

int StaticTableModel::getHeight ( ) const

Definition at line 180 of file tablemodel.cpp.

181 {
182  return mColumns * mHeight;
183 }

References mColumns, and mHeight.

◆ getRowHeight()

int StaticTableModel::getRowHeight ( ) const
virtual

Determines the height for each row

Implements TableModel.

Definition at line 147 of file tablemodel.cpp.

148 {
149  return abs(mHeight);
150 }

References mHeight.

◆ getRows()

int StaticTableModel::getRows ( ) const
virtual

Determines the number of rows (lines) in the table

Implements TableModel.

Definition at line 160 of file tablemodel.cpp.

161 {
162  return mRows;
163 }

References mRows.

Referenced by resize().

◆ getWidth()

int StaticTableModel::getWidth ( ) const

Definition at line 170 of file tablemodel.cpp.

171 {
172  size_t width = 0;
173 
174  for (size_t i = 0, sz = mWidths.size(); i < sz; i++)
175  width += CAST_SIZE(mWidths[i]);
176 
177  return CAST_S32(width);
178 }
#define CAST_S32
Definition: cast.h:30
#define CAST_SIZE
Definition: cast.h:34

References CAST_S32, CAST_SIZE, and mWidths.

◆ resize()

void StaticTableModel::resize ( )

Resizes the table model

Definition at line 87 of file tablemodel.cpp.

88 {
89  mRows = getRows();
90  mColumns = getColumns();
91  mTableModel.resize(mRows * mColumns, nullptr);
92 }
int getRows() const
Definition: tablemodel.cpp:160
int getColumns() const
Definition: tablemodel.cpp:165

References getColumns(), getRows(), mColumns, mRows, and mTableModel.

◆ set()

void StaticTableModel::set ( const int  row,
const int  column,
Widget *const  widget 
)

Inserts a widget into the table model. The model is resized to accomodate the widget's width and height, unless column width / row height have been fixed.

Definition at line 94 of file tablemodel.cpp.

96 {
97  if ((widget == nullptr) || row >= mRows || row < 0
98  || column >= mColumns || column < 0)
99  {
100  // raise exn?
101  return;
102  }
103 
104  if (DYN_SIZE(mHeight)
105  && widget->getHeight() > mHeight)
106  {
107  mHeight = widget->getHeight();
108  }
109 
110  if (DYN_SIZE(mWidths[column])
111  && widget->getWidth() > mWidths[column])
112  {
113  mWidths[column] = widget->getWidth();
114  }
115 
117 
118  delete mTableModel[WIDGET_AT(row, column)];
119 
120  mTableModel[WIDGET_AT(row, column)] = widget;
121 
123 }
virtual void signalAfterUpdate()
Definition: tablemodel.cpp:55
virtual void signalBeforeUpdate()
Definition: tablemodel.cpp:46
int getHeight() const
Definition: widget.h:240
int getWidth() const
Definition: widget.h:221
#define DYN_SIZE(h)
Definition: tablemodel.cpp:67

References DYN_SIZE, Widget::getHeight(), Widget::getWidth(), mColumns, mHeight, mRows, mTableModel, mWidths, TableModel::signalAfterUpdate(), TableModel::signalBeforeUpdate(), and WIDGET_AT.

Referenced by Setup_Relations::Setup_Relations().

Field Documentation

◆ mColumns

int StaticTableModel::mColumns
protected

Definition at line 148 of file tablemodel.h.

Referenced by fixColumnWidth(), getColumns(), getColumnWidth(), getHeight(), resize(), and set().

◆ mHeight

int StaticTableModel::mHeight
protected

Definition at line 149 of file tablemodel.h.

Referenced by fixRowHeight(), getHeight(), getRowHeight(), and set().

◆ mRows

int StaticTableModel::mRows
protected

Definition at line 147 of file tablemodel.h.

Referenced by getRows(), resize(), and set().

◆ mTableModel

std::vector<Widget *> StaticTableModel::mTableModel
protected

Definition at line 150 of file tablemodel.h.

Referenced by getElementAt(), resize(), set(), StaticTableModel(), and ~StaticTableModel().

◆ mWidths

std::vector<int> StaticTableModel::mWidths
protected

Definition at line 151 of file tablemodel.h.

Referenced by fixColumnWidth(), getColumnWidth(), getWidth(), set(), and StaticTableModel().


The documentation for this class was generated from the following files: