GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/models/iconsmodel.h Lines: 16 24 66.7 %
Date: 2018-07-14 Branches: 7 28 25.0 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2009  The Mana World Development Team
4
 *  Copyright (C) 2009-2010  Andrei Karas
5
 *  Copyright (C) 2011-2018  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_ICONSMODEL_H
24
#define GUI_MODELS_ICONSMODEL_H
25
26
#include "gui/models/listmodel.h"
27
28
#include "utils/foreach.h"
29
30
#include "resources/iteminfo.h"
31
32
#include "resources/db/itemdb.h"
33
34
#include <list>
35
36
#include "localconsts.h"
37
38
1
class IconsModel final : public ListModel
39
{
40
    public:
41
1
        IconsModel() :
42
3
            mStrings()
43
        {
44
1
            const std::map<int, ItemInfo*> &items = ItemDB::getItemInfos();
45
2
            std::list<std::string> tempStrings;
46
47
1
            for (std::map<int, ItemInfo*>::const_iterator
48
2
                 i = items.begin(), i_end = items.end();
49
                 i != i_end; ++i)
50
            {
51
                if (i->first < 0)
52
                    continue;
53
54
                const ItemInfo &info = (*i->second);
55
                const std::string &name = info.getName();
56
                if (name != "unnamed" && !info.getName().empty()
57
                    && info.getName() != "unnamed")
58
                {
59
                    tempStrings.push_back(name);
60
                }
61
            }
62
1
            tempStrings.sort();
63
5
            mStrings.push_back("");
64
5
            FOR_EACH (std::list<std::string>::const_iterator, i, tempStrings)
65
                mStrings.push_back(*i);
66
1
        }
67
68
        A_DELETE_COPY(IconsModel)
69
70
8
        int getNumberOfElements() override final
71
        {
72
20
            return CAST_S32(mStrings.size());
73
        }
74
75
2
        std::string getElementAt(int i) override final
76
        {
77

4
            if (i < 0 || i >= getNumberOfElements())
78
                return "???";
79
4
            return mStrings.at(i);
80
        }
81
    private:
82
        StringVect mStrings;
83
};
84
85
#endif  // GUI_MODELS_ICONSMODEL_H