ManaPlus
tablemodel.h
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2008-2009 The Mana World Development Team
4  * Copyright (C) 2009-2010 The Mana Developers
5  * Copyright (C) 2011-2019 The ManaPlus Developers
6  * Copyright (C) 2019-2021 Andrei Karas
7  *
8  * This file is part of The ManaPlus Client.
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22  */
23 
24 #ifndef GUI_MODELS_TABLEMODEL_H
25 #define GUI_MODELS_TABLEMODEL_H
26 
27 #include "utils/vector.h"
28 
29 #include <set>
30 
31 #include "localconsts.h"
32 
33 class Widget;
34 
35 class TableModelListener;
36 
41 {
42  public:
44 
45  virtual ~TableModel()
46  { }
47 
51  virtual int getRows() const A_WARN_UNUSED = 0;
52 
56  virtual int getColumns() const A_WARN_UNUSED = 0;
57 
61  virtual int getRowHeight() const A_WARN_UNUSED = 0;
62 
66  virtual int getColumnWidth(const int index) const A_WARN_UNUSED = 0;
67 
72  virtual Widget *getElementAt(const int row, const int column)
73  const A_WARN_UNUSED = 0;
74 
75  virtual void installListener(TableModelListener *const listener);
76 
77  virtual void removeListener(TableModelListener *const listener);
78 
79  protected:
81  listeners()
82  {
83  }
84 
88  virtual void signalBeforeUpdate();
89 
93  virtual void signalAfterUpdate();
94 
95  private:
96  std::set<TableModelListener *> listeners;
97 };
98 
99 
101 {
102  public:
103  StaticTableModel(const int width, const int height);
104 
106 
107  ~StaticTableModel() override final;
108 
114  void set(const int row, const int column, Widget *const widget);
115 
122  void fixColumnWidth(const int column, const int width);
123 
129  void fixRowHeight(const int height);
130 
134  void resize();
135 
136  int getRows() const override final A_WARN_UNUSED;
137  int getColumns() const override final A_WARN_UNUSED;
138  int getRowHeight() const override final A_WARN_UNUSED;
139  int getWidth() const A_WARN_UNUSED;
140  int getHeight() const A_WARN_UNUSED;
141  int getColumnWidth(const int index) const override final A_WARN_UNUSED;
142  Widget *getElementAt(const int row,
143  const int column) const override final
145 
146  protected:
147  int mRows;
148  int mColumns;
149  int mHeight;
150  STD_VECTOR<Widget *> mTableModel;
151  STD_VECTOR<int> mWidths;
152 };
153 
154 #endif // GUI_MODELS_TABLEMODEL_H
int getRows() const
Definition: tablemodel.cpp:160
void fixRowHeight(const int height)
Definition: tablemodel.cpp:139
StaticTableModel(const int width, const int height)
Definition: tablemodel.cpp:69
std::vector< int > mWidths
Definition: tablemodel.h:151
int getColumnWidth(const int index) const
Definition: tablemodel.cpp:152
std::vector< Widget * > mTableModel
Definition: tablemodel.h:150
int getWidth() const
Definition: tablemodel.cpp:170
void set(const int row, const int column, Widget *const widget)
Definition: tablemodel.cpp:94
int getHeight() const
Definition: tablemodel.cpp:180
Widget * getElementAt(const int row, const int column) const
Definition: tablemodel.cpp:125
void fixColumnWidth(const int column, const int width)
Definition: tablemodel.cpp:131
int getRowHeight() const
Definition: tablemodel.cpp:147
int getColumns() const
Definition: tablemodel.cpp:165
virtual void removeListener(TableModelListener *const listener)
Definition: tablemodel.cpp:40
virtual int getRows() const =0
virtual void signalAfterUpdate()
Definition: tablemodel.cpp:55
virtual int getColumnWidth(const int index) const =0
virtual Widget * getElementAt(const int row, const int column) const =0
std::set< TableModelListener * > listeners
Definition: tablemodel.h:96
virtual void installListener(TableModelListener *const listener)
Definition: tablemodel.cpp:34
virtual int getRowHeight() const =0
virtual int getColumns() const =0
virtual void signalBeforeUpdate()
Definition: tablemodel.cpp:46
Definition: widget.h:99
#define A_WARN_UNUSED
Definition: localconsts.h:161
#define notfinal
Definition: localconsts.h:261
#define final
Definition: localconsts.h:46
#define A_DELETE_COPY(func)
Definition: localconsts.h:53