GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/widgets/statspage.cpp Lines: 0 29 0.0 %
Date: 2021-03-17 Branches: 0 46 0.0 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2011-2019  The ManaPlus Developers
4
 *  Copyright (C) 2019-2021  Andrei Karas
5
 *
6
 *  This file is part of The ManaPlus 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
#include "gui/widgets/statspage.h"
23
24
#include "gui/widgets/scrollarea.h"
25
#include "gui/widgets/vertcontainer.h"
26
27
#include "gui/widgets/attrs/derdisplay.h"
28
29
#include "utils/foreach.h"
30
31
#include "resources/db/statdb.h"
32
33
#include "debug.h"
34
35
StatsPage::StatsPage(const Widget2 *const widget,
36
                     const std::string &page) :
37
    Container(widget),
38
    WidgetListener(),
39
    AttributeListener(),
40
    StatListener(),
41
    mAttrs(),
42
    mAttrCont(new VertContainer(this, 32, true, 0)),
43
    mAttrScroll(new ScrollArea(this, mAttrCont, Opaque_false, std::string()))
44
{
45
    addWidgetListener(this);
46
    setSelectable(false);
47
48
    mAttrScroll->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER);
49
    mAttrScroll->setVerticalScrollPolicy(ScrollArea::SHOW_AUTO);
50
    mAttrScroll->setSelectable(false);
51
    mAttrCont->setSelectable(false);
52
53
    add(mAttrScroll);
54
    const STD_VECTOR<BasicStat> &basicStats = StatDb::getStats(page);
55
    FOR_EACH (STD_VECTOR<BasicStat>::const_iterator, it, basicStats)
56
    {
57
        const BasicStat &stat = *it;
58
        AttrDisplay *disp = new DerDisplay(this,
59
            stat.attr,
60
            stat.name,
61
            stat.tag);
62
        disp->update();
63
        mAttrCont->add2(disp, true, -1);
64
        mAttrs[stat.attr] = disp;
65
    }
66
}
67
68
void StatsPage::widgetResized(const Event &event A_UNUSED)
69
{
70
    mAttrScroll->setSize(getWidth(), getHeight());
71
}
72
73
void StatsPage::attributeChanged(const AttributesT id,
74
                                 const int64_t oldVal A_UNUSED,
75
                                 const int64_t newVal A_UNUSED)
76
{
77
    const Attrs::const_iterator it = mAttrs.find(id);
78
    if (it != mAttrs.end() && (it->second != nullptr))
79
        it->second->update();
80
}
81
82
void StatsPage::statChanged(const AttributesT id,
83
                            const int oldVal1 A_UNUSED,
84
                            const int oldVal2 A_UNUSED)
85
{
86
    const Attrs::const_iterator it = mAttrs.find(id);
87
    if (it != mAttrs.end() && (it->second != nullptr))
88
        it->second->update();
89
}