GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/models/tablemodel.h Lines: 3 3 100.0 %
Date: 2017-11-29 Branches: 0 0 0.0 %

Line Branch Exec Source
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-2017  The ManaPlus Developers
6
 *
7
 *  This file is part of The ManaPlus Client.
8
 *
9
 *  This program is free software; you can redistribute it and/or modify
10
 *  it under the terms of the GNU General Public License as published by
11
 *  the Free Software Foundation; either version 2 of the License, or
12
 *  any later version.
13
 *
14
 *  This program is distributed in the hope that it will be useful,
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 *  GNU General Public License for more details.
18
 *
19
 *  You should have received a copy of the GNU General Public License
20
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
 */
22
23
#ifndef GUI_MODELS_TABLEMODEL_H
24
#define GUI_MODELS_TABLEMODEL_H
25
26
#include "utils/vector.h"
27
28
#include <set>
29
30
#include "localconsts.h"
31
32
class Widget;
33
34
class TableModelListener;
35
36
/**
37
 * A model for a regular table of widgets.
38
 */
39
class TableModel notfinal
40
{
41
    public:
42
        A_DELETE_COPY(TableModel)
43
44
        virtual ~TableModel()
45
16
        { }
46
47
        /**
48
         * Determines the number of rows (lines) in the table
49
         */
50
        virtual int getRows() const A_WARN_UNUSED = 0;
51
52
        /**
53
         * Determines the number of columns in each row
54
         */
55
        virtual int getColumns() const A_WARN_UNUSED = 0;
56
57
        /**
58
         * Determines the height for each row
59
         */
60
        virtual int getRowHeight() const A_WARN_UNUSED = 0;
61
62
        /**
63
         * Determines the width of each individual column
64
         */
65
        virtual int getColumnWidth(const int index) const A_WARN_UNUSED = 0;
66
67
        /**
68
         * Retrieves the widget stored at the specified location
69
         *  within the table.
70
         */
71
        virtual Widget *getElementAt(const int row, const int column)
72
                                     const A_WARN_UNUSED = 0;
73
74
        virtual void installListener(TableModelListener *const listener);
75
76
        virtual void removeListener(TableModelListener *const listener);
77
78
    protected:
79
8
        TableModel() :
80
16
            listeners()
81
        {
82
        }
83
84
        /**
85
         * Tells all listeners that the table is about to see an update
86
         */
87
        virtual void signalBeforeUpdate();
88
89
        /**
90
         * Tells all listeners that the table has seen an update
91
         */
92
        virtual void signalAfterUpdate();
93
94
    private:
95
        std::set<TableModelListener *> listeners;
96
};
97
98
99
class StaticTableModel final : public TableModel
100
{
101
    public:
102
        StaticTableModel(const int width, const int height);
103
104
        A_DELETE_COPY(StaticTableModel)
105
106
        ~StaticTableModel();
107
108
        /**
109
         * Inserts a widget into the table model.
110
         * The model is resized to accomodate the widget's width and height,
111
         * unless column width / row height have been fixed.
112
         */
113
        void set(const int row, const int column, Widget *const widget);
114
115
        /**
116
         * Fixes the column width for a given column; this overrides dynamic
117
         * width inference.
118
         *
119
         * Semantics are undefined for width 0.
120
         */
121
        void fixColumnWidth(const int column, const int width);
122
123
        /**
124
         * Fixes the row height; this overrides dynamic height inference.
125
         *
126
         * Semantics are undefined for width 0.
127
         */
128
        void fixRowHeight(const int height);
129
130
        /**
131
         * Resizes the table model
132
         */
133
        void resize();
134
135
        int getRows() const override final A_WARN_UNUSED;
136
        int getColumns() const override final A_WARN_UNUSED;
137
        int getRowHeight() const override final A_WARN_UNUSED;
138
        int getWidth() const A_WARN_UNUSED;
139
        int getHeight() const A_WARN_UNUSED;
140
        int getColumnWidth(const int index) const override final A_WARN_UNUSED;
141
        Widget *getElementAt(const int row,
142
                             const int column) const override final
143
                             A_WARN_UNUSED;
144
145
    protected:
146
        int mRows;
147
        int mColumns;
148
        int mHeight;
149
        STD_VECTOR<Widget *> mTableModel;
150
        STD_VECTOR<int> mWidths;
151
};
152
153
#endif  // GUI_MODELS_TABLEMODEL_H