ManaPlus
Public Member Functions | Protected Attributes
PlayerTableModel Class Reference

#include <playertablemodel.h>

Inheritance diagram for PlayerTableModel:
Widget2 TableModel

Public Member Functions

 PlayerTableModel (const Widget2 *const widget)
 
 ~PlayerTableModel ()
 
int getRows () const
 
int getColumns () const A_CONST
 
int getRowHeight () const A_CONST
 
int getColumnWidth (const int index) const A_CONST
 
void playerRelationsUpdated ()
 
void updateModelInRow (const int row) const
 
WidgetgetElementAt (int row, int column) const
 
void freeWidgets ()
 
std::string getPlayerAt (const int index) const
 
- Public Member Functions inherited from Widget2
virtual ~Widget2 ()
 
const ColorgetThemeColor (const ThemeColorIdT type, const unsigned int alpha) const A_INLINE
 
const ColorgetThemeCharColor (const signed char c, bool &valid) const A_INLINE
 
virtual void setWidget2 (const Widget2 *const widget)
 
void setPalette (int palette)
 
void checkPalette ()
 
void setForegroundColor2 (const Color &color)
 
WidgetgetWindow () const
 
virtual void setWindow (Widget *const window)
 
- Public Member Functions inherited from TableModel
virtual ~TableModel ()
 
virtual void installListener (TableModelListener *const listener)
 
virtual void removeListener (TableModelListener *const listener)
 

Protected Attributes

StringVectmPlayers
 
std::vector< Widget * > mWidgets
 
PlayerRelationListModelmListModel
 
- Protected Attributes inherited from Widget2
int mPaletteOffset
 
WidgetmWindow
 
Color mForegroundColor2
 

Additional Inherited Members

- Protected Member Functions inherited from Widget2
 Widget2 (const Widget2 *const widget)
 
- Protected Member Functions inherited from TableModel
 TableModel ()
 
virtual void signalBeforeUpdate ()
 
virtual void signalAfterUpdate ()
 

Detailed Description

Definition at line 35 of file playertablemodel.h.

Constructor & Destructor Documentation

◆ PlayerTableModel()

PlayerTableModel::PlayerTableModel ( const Widget2 *const  widget)
explicit

Definition at line 51 of file playertablemodel.cpp.

51  :
52  Widget2(widget),
53  TableModel(),
54  mPlayers(nullptr),
55  mWidgets(),
57 {
59 }
std::vector< Widget * > mWidgets
StringVect * mPlayers
PlayerRelationListModel * mListModel
Widget2(const Widget2 *const widget)
Definition: widget2.h:103

References playerRelationsUpdated().

◆ ~PlayerTableModel()

PlayerTableModel::~PlayerTableModel ( )

Definition at line 61 of file playertablemodel.cpp.

62 {
63  freeWidgets();
66 }
#define delete2(var)
Definition: delete2.h:25

References delete2, freeWidgets(), mListModel, and mPlayers.

Member Function Documentation

◆ freeWidgets()

void PlayerTableModel::freeWidgets ( )

Definition at line 139 of file playertablemodel.cpp.

140 {
143  mWidgets.clear();
144 }
void delete_all(Container &c)
Definition: dtor.h:56

References delete2, delete_all(), mPlayers, and mWidgets.

Referenced by playerRelationsUpdated(), and ~PlayerTableModel().

◆ getColumns()

int PlayerTableModel::getColumns ( ) const
virtual

Determines the number of columns in each row

Implements TableModel.

Definition at line 75 of file playertablemodel.cpp.

76 {
77  return COLUMNS_NR;
78 }
static const int COLUMNS_NR

References COLUMNS_NR.

◆ getColumnWidth()

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

Determines the width of each individual column

Implements TableModel.

Definition at line 85 of file playertablemodel.cpp.

86 {
87  if (index == NAME_COLUMN)
88  return NAME_COLUMN_WIDTH;
90 }
static const unsigned int NAME_COLUMN_WIDTH
static const unsigned int RELATION_CHOICE_COLUMN_WIDTH
static const int NAME_COLUMN

References NAME_COLUMN, NAME_COLUMN_WIDTH, and RELATION_CHOICE_COLUMN_WIDTH.

◆ getElementAt()

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

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

Implements TableModel.

Definition at line 134 of file playertablemodel.cpp.

135 {
136  return mWidgets[WIDGET_AT(row, column)];
137 }
#define WIDGET_AT(row, column)

References mWidgets, and WIDGET_AT.

Referenced by updateModelInRow().

◆ getPlayerAt()

std::string PlayerTableModel::getPlayerAt ( const int  index) const

Definition at line 146 of file playertablemodel.cpp.

147 {
148  if ((mPlayers == nullptr) || index < 0
149  || index >= CAST_S32(mPlayers->size()))
150  {
151  return std::string();
152  }
153  return (*mPlayers)[index];
154 }
#define CAST_S32
Definition: cast.h:30

References CAST_S32, and mPlayers.

Referenced by Setup_Relations::action(), and updateModelInRow().

◆ getRowHeight()

int PlayerTableModel::getRowHeight ( ) const
virtual

Determines the height for each row

Implements TableModel.

Definition at line 80 of file playertablemodel.cpp.

81 {
82  return ROW_HEIGHT;
83 }
static const unsigned int ROW_HEIGHT

References ROW_HEIGHT.

◆ getRows()

int PlayerTableModel::getRows ( ) const
virtual

Determines the number of rows (lines) in the table

Implements TableModel.

Definition at line 68 of file playertablemodel.cpp.

69 {
70  if (mPlayers != nullptr)
71  return CAST_S32(mPlayers->size());
72  return 0;
73 }

References CAST_S32, and mPlayers.

◆ playerRelationsUpdated()

void PlayerTableModel::playerRelationsUpdated ( )

Definition at line 92 of file playertablemodel.cpp.

93 {
95 
96  freeWidgets();
97  StringVect *const player_names = playerRelations.getPlayers();
98  delete mPlayers;
99  mPlayers = player_names;
100 
101  // set up widgets
102  for (unsigned int r = 0, fsz = CAST_U32(
103  player_names->size()); r < fsz; ++r)
104  {
105  const std::string name = (*player_names)[r];
106  Widget *const widget = new Label(this, name);
107  mWidgets.push_back(widget);
108 
109  DropDown *const choicebox = new DropDown(this,
110  mListModel,
111  false,
112  Modal_false,
113  nullptr,
114  std::string());
115  choicebox->setSelected(CAST_S32(
117  mWidgets.push_back(choicebox);
118  }
119 
121 }
#define CAST_U32
Definition: cast.h:31
void setSelected(int selected)
Definition: dropdown.cpp:514
Definition: label.h:91
StringVect * getPlayers() const
RelationT getRelation(const std::string &name) const
virtual void signalAfterUpdate()
Definition: tablemodel.cpp:55
virtual void signalBeforeUpdate()
Definition: tablemodel.cpp:46
Definition: widget.h:99
const bool Modal_false
Definition: modal.h:30
PlayerRelationsManager playerRelations
std::vector< std::string > StringVect
Definition: stringvector.h:29

References CAST_S32, CAST_U32, freeWidgets(), PlayerRelationsManager::getPlayers(), PlayerRelationsManager::getRelation(), mListModel, Modal_false, mPlayers, mWidgets, playerRelations, DropDown::setSelected(), TableModel::signalAfterUpdate(), and TableModel::signalBeforeUpdate().

Referenced by PlayerTableModel(), and Setup_Relations::updatedPlayer().

◆ updateModelInRow()

void PlayerTableModel::updateModelInRow ( const int  row) const

Definition at line 123 of file playertablemodel.cpp.

124 {
125  const DropDown *const choicebox = static_cast<DropDown *>(
127  if (choicebox == nullptr)
128  return;
130  static_cast<RelationT>(
131  choicebox->getSelected()));
132 }
int getSelected() const
Definition: dropdown.cpp:509
void setRelation(const std::string &name, const RelationT relation)
Widget * getElementAt(int row, int column) const
std::string getPlayerAt(const int index) const
static const unsigned int RELATION_CHOICE_COLUMN
Relation ::T RelationT
Definition: relation.h:39

References getElementAt(), getPlayerAt(), DropDown::getSelected(), playerRelations, RELATION_CHOICE_COLUMN, and PlayerRelationsManager::setRelation().

Referenced by Setup_Relations::action().

Field Documentation

◆ mListModel

PlayerRelationListModel* PlayerTableModel::mListModel
protected

Definition at line 66 of file playertablemodel.h.

Referenced by playerRelationsUpdated(), and ~PlayerTableModel().

◆ mPlayers

StringVect* PlayerTableModel::mPlayers
protected

◆ mWidgets

std::vector<Widget *> PlayerTableModel::mWidgets
protected

Definition at line 65 of file playertablemodel.h.

Referenced by freeWidgets(), getElementAt(), and playerRelationsUpdated().


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