Mana
Loading...
Searching...
No Matches
tablemodel.h
Go to the documentation of this file.
1/*
2 * The Mana Client
3 * Copyright (C) 2008-2009 The Mana World Development Team
4 * Copyright (C) 2009-2012 The Mana Developers
5 *
6 * This file is part of The Mana Client.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#pragma once
23
24#include <guichanfwd.h>
25
26#include <set>
27#include <vector>
28
30{
31public:
41 virtual void modelUpdated(bool completed) = 0;
42
44};
45
50{
51public:
52 virtual ~TableModel() { }
53
57 virtual int getRows() const = 0;
58
62 virtual int getColumns() const = 0;
63
67 virtual int getRowHeight() const = 0;
68
72 virtual int getColumnWidth(int index) const = 0;
73
77 virtual gcn::Widget *getElementAt(int row, int column) const = 0;
78
79 void installListener(TableModelListener *listener);
80 void removeListener(TableModelListener *listener);
81
82protected:
86 void signalBeforeUpdate();
87
91 void signalAfterUpdate();
92
93private:
94 std::set<TableModelListener *> listeners;
95};
96
97
99{
100public:
101 StaticTableModel(int width, int height);
102 ~StaticTableModel() override;
103
109 virtual void set(int row, int column, gcn::Widget *widget);
110
117 virtual void fixColumnWidth(int column, int width);
118
124 virtual void fixRowHeight(int height);
125
129 virtual void resize();
130
131 int getRows() const override;
132 int getColumns() const override;
133 int getRowHeight() const override;
134 virtual int getWidth() const;
135 virtual int getHeight() const;
136 int getColumnWidth(int index) const override;
137 gcn::Widget *getElementAt(int row, int column) const override;
138
139protected:
142 std::vector<gcn::Widget *> mTableModel;
143 std::vector<int> mWidths;
144};
virtual void set(int row, int column, gcn::Widget *widget)
Inserts a widget into the table model.
int getRowHeight() const override
Determines the height for each row.
std::vector< int > mWidths
Definition tablemodel.h:143
gcn::Widget * getElementAt(int row, int column) const override
Retrieves the widget stored at the specified location within the table.
~StaticTableModel() override
int getRows() const override
Determines the number of rows (lines) in the table.
virtual void resize()
Resizes the table model.
int getColumnWidth(int index) const override
Determines the width of each individual column.
virtual int getWidth() const
virtual int getHeight() const
virtual void fixRowHeight(int height)
Fixes the row height; this overrides dynamic height inference.
int getColumns() const override
Determines the number of columns in each row.
virtual void fixColumnWidth(int column, int width)
Fixes the column width for a given column; this overrides dynamic width inference.
std::vector< gcn::Widget * > mTableModel
Definition tablemodel.h:142
virtual void modelUpdated(bool completed)=0
Must be invoked by the TableModel whenever a global change is about to occur or has occurred (e....
virtual ~TableModelListener()
Definition tablemodel.h:43
A model for a regular table of widgets.
Definition tablemodel.h:50
virtual ~TableModel()
Definition tablemodel.h:52
virtual int getRows() const =0
Determines the number of rows (lines) in the table.
void signalAfterUpdate()
Tells all listeners that the table has seen an update.
std::set< TableModelListener * > listeners
Definition tablemodel.h:94
virtual int getRowHeight() const =0
Determines the height for each row.
void removeListener(TableModelListener *listener)
virtual int getColumns() const =0
Determines the number of columns in each row.
virtual gcn::Widget * getElementAt(int row, int column) const =0
Retrieves the widget stored at the specified location within the table.
virtual int getColumnWidth(int index) const =0
Determines the width of each individual column.
void installListener(TableModelListener *listener)
void signalBeforeUpdate()
Tells all listeners that the table is about to see an update.