Mana
Loading...
Searching...
No Matches
tablemodel.cpp
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
23
24#include "utils/dtor.h"
25
26#include <guichan/widget.hpp>
27
29{
30 listeners.insert(listener);
31}
32
34{
35 listeners.erase(listener);
36}
37
39{
40 for (auto listener : listeners)
41 listener->modelUpdated(false);
42}
43
45{
46 for (auto listener : listeners)
47 listener->modelUpdated(true);
48}
49
50
51#define WIDGET_AT(row, column) (((row) * mColumns) + (column))
52#define DYN_SIZE(h) ((h) >= 0) // determines whether this size is tagged for auto-detection
53
55 mRows(row),
56 mColumns(column),
57 mHeight(1)
58{
59 mTableModel.resize(row * column);
60 mWidths.resize(column, 1);
61}
62
67
74
75void StaticTableModel::set(int row, int column, gcn::Widget *widget)
76{
77 if (row >= mRows || row < 0
78 || column >= mColumns || column < 0)
79 // raise exn?
80 return;
81
82 if (DYN_SIZE(mHeight)
83 && widget->getHeight() > mHeight)
84 mHeight = widget->getHeight();
85
87 && widget->getWidth() > mWidths[column])
88 mWidths[column] = widget->getWidth();
89
91
94
96
98}
99
100gcn::Widget *StaticTableModel::getElementAt(int row, int column) const
101{
103}
104
105void StaticTableModel::fixColumnWidth(int column, int width)
106{
107 if (width < 0
109 return;
110
111 mWidths[column] = -width; // Negate to tag as fixed
112}
113
115{
116 if (height < 0)
117 return;
118
119 mHeight = -height;
120}
121
123{
124 return abs(mHeight);
125}
126
128{
130 return 0;
131
132 return abs(mWidths[column]);
133}
134
136{
137 return mRows;
138}
139
141{
142 return mColumns;
143}
144
146{
147 int width = 0;
148
149 for (int w : mWidths)
150 {
151 width += w;
152 }
153
154 return width;
155}
156
158{
159 return mColumns * mHeight;
160}
161
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.
StaticTableModel(int width, int height)
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
void signalAfterUpdate()
Tells all listeners that the table has seen an update.
std::set< TableModelListener * > listeners
Definition tablemodel.h:94
void removeListener(TableModelListener *listener)
void installListener(TableModelListener *listener)
void signalBeforeUpdate()
Tells all listeners that the table is about to see an update.
void delete_all(Container &c)
Definition dtor.h:46
#define WIDGET_AT(row, column)
#define DYN_SIZE(h)