GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/widgets/statspage.cpp Lines: 0 29 0.0 %
Date: 2017-11-29 Branches: 0 44 0.0 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2011-2017  The ManaPlus Developers
4
 *
5
 *  This file is part of The ManaPlus Client.
6
 *
7
 *  This program is free software; you can redistribute it and/or modify
8
 *  it under the terms of the GNU General Public License as published by
9
 *  the Free Software Foundation; either version 2 of the License, or
10
 *  any later version.
11
 *
12
 *  This program is distributed in the hope that it will be useful,
13
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 *  GNU General Public License for more details.
16
 *
17
 *  You should have received a copy of the GNU General Public License
18
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
 */
20
21
#include "gui/widgets/statspage.h"
22
23
#include "gui/widgets/scrollarea.h"
24
#include "gui/widgets/vertcontainer.h"
25
26
#include "gui/widgets/attrs/derdisplay.h"
27
28
#include "utils/foreach.h"
29
30
#include "resources/db/statdb.h"
31
32
#include "debug.h"
33
34
StatsPage::StatsPage(const Widget2 *const widget,
35
                     const std::string &page) :
36
    Container(widget),
37
    WidgetListener(),
38
    AttributeListener(),
39
    StatListener(),
40
    mAttrs(),
41
    mAttrCont(new VertContainer(this, 32)),
42
    mAttrScroll(new ScrollArea(this, mAttrCont, Opaque_false))
43
{
44
    addWidgetListener(this);
45
    setSelectable(false);
46
47
    mAttrScroll->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER);
48
    mAttrScroll->setVerticalScrollPolicy(ScrollArea::SHOW_AUTO);
49
    mAttrScroll->setSelectable(false);
50
    mAttrCont->setSelectable(false);
51
52
    add(mAttrScroll);
53
    const STD_VECTOR<BasicStat> &basicStats = StatDb::getStats(page);
54
    FOR_EACH (STD_VECTOR<BasicStat>::const_iterator, it, basicStats)
55
    {
56
        const BasicStat &stat = *it;
57
        AttrDisplay *disp = new DerDisplay(this,
58
            stat.attr,
59
            stat.name,
60
            stat.tag);
61
        disp->update();
62
        mAttrCont->add2(disp, true);
63
        mAttrs[stat.attr] = disp;
64
    }
65
}
66
67
void StatsPage::widgetResized(const Event &event A_UNUSED)
68
{
69
    mAttrScroll->setSize(getWidth(), getHeight());
70
}
71
72
void StatsPage::attributeChanged(const AttributesT id,
73
                                 const int64_t oldVal A_UNUSED,
74
                                 const int64_t newVal A_UNUSED)
75
{
76
    const Attrs::const_iterator it = mAttrs.find(id);
77
    if (it != mAttrs.end() && (it->second != nullptr))
78
        it->second->update();
79
}
80
81
void StatsPage::statChanged(const AttributesT id,
82
                            const int oldVal1 A_UNUSED,
83
                            const int oldVal2 A_UNUSED)
84
{
85
    const Attrs::const_iterator it = mAttrs.find(id);
86
    if (it != mAttrs.end() && (it->second != nullptr))
87
        it->second->update();
88
}