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 34 of file playertablemodel.h.

Constructor & Destructor Documentation

◆ PlayerTableModel()

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

Definition at line 50 of file playertablemodel.cpp.

References playerRelationsUpdated().

50  :
51  Widget2(widget),
52  TableModel(),
53  mPlayers(nullptr),
54  mWidgets(),
56 {
58 }
PlayerRelationListModel * mListModel
StringVect * mPlayers
std::vector< Widget * > mWidgets
Widget2(const Widget2 *const widget)
Definition: widget2.h:102

◆ ~PlayerTableModel()

PlayerTableModel::~PlayerTableModel ( )

Definition at line 60 of file playertablemodel.cpp.

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

61 {
62  freeWidgets();
65 }
PlayerRelationListModel * mListModel
#define delete2(var)
Definition: delete2.h:24
StringVect * mPlayers

Member Function Documentation

◆ freeWidgets()

void PlayerTableModel::freeWidgets ( )

Definition at line 138 of file playertablemodel.cpp.

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

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

139 {
142  mWidgets.clear();
143 }
#define delete2(var)
Definition: delete2.h:24
StringVect * mPlayers
void delete_all(Container &c)
Definition: dtor.h:55
std::vector< Widget * > mWidgets

◆ getColumns()

int PlayerTableModel::getColumns ( ) const
virtual

Determines the number of columns in each row

Implements TableModel.

Definition at line 74 of file playertablemodel.cpp.

References COLUMNS_NR.

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

◆ getColumnWidth()

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

Determines the width of each individual column

Implements TableModel.

Definition at line 84 of file playertablemodel.cpp.

References NAME_COLUMN, NAME_COLUMN_WIDTH, and RELATION_CHOICE_COLUMN_WIDTH.

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

◆ 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 133 of file playertablemodel.cpp.

References mWidgets, and WIDGET_AT.

Referenced by updateModelInRow().

134 {
135  return mWidgets[WIDGET_AT(row, column)];
136 }
std::vector< Widget * > mWidgets
#define WIDGET_AT(row, column)

◆ getPlayerAt()

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

Definition at line 145 of file playertablemodel.cpp.

References CAST_S32, and mPlayers.

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

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

◆ getRowHeight()

int PlayerTableModel::getRowHeight ( ) const
virtual

Determines the height for each row

Implements TableModel.

Definition at line 79 of file playertablemodel.cpp.

References ROW_HEIGHT.

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

◆ getRows()

int PlayerTableModel::getRows ( ) const
virtual

Determines the number of rows (lines) in the table

Implements TableModel.

Definition at line 67 of file playertablemodel.cpp.

References CAST_S32, and mPlayers.

68 {
69  if (mPlayers != nullptr)
70  return CAST_S32(mPlayers->size());
71  return 0;
72 }
StringVect * mPlayers
#define CAST_S32
Definition: cast.h:29

◆ playerRelationsUpdated()

void PlayerTableModel::playerRelationsUpdated ( )

Definition at line 91 of file playertablemodel.cpp.

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().

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

◆ updateModelInRow()

void PlayerTableModel::updateModelInRow ( const int  row) const

Definition at line 122 of file playertablemodel.cpp.

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

Referenced by Setup_Relations::action().

123 {
124  const DropDown *const choicebox = static_cast<DropDown *>(
126  if (choicebox == nullptr)
127  return;
129  static_cast<RelationT>(
130  choicebox->getSelected()));
131 }
Widget * getElementAt(int row, int column) const
std::string getPlayerAt(const int index) const
static const unsigned int RELATION_CHOICE_COLUMN
PlayerRelationsManager playerRelations
void setRelation(const std::string &name, const RelationT relation)
int getSelected() const
Definition: dropdown.cpp:509

Field Documentation

◆ mListModel

PlayerRelationListModel* PlayerTableModel::mListModel
protected

Definition at line 65 of file playertablemodel.h.

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

◆ mPlayers

StringVect* PlayerTableModel::mPlayers
protected

◆ mWidgets

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

Definition at line 64 of file playertablemodel.h.

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


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