GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/models/iconsmodel.h Lines: 16 26 61.5 %
Date: 2017-11-29 Branches: 6 22 27.3 %

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-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_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
class IconsModel final : public ListModel
39
{
40
    public:
41
2
        IconsModel() :
42
6
            mStrings()
43
        {
44
2
            const std::map<int, ItemInfo*> &items = ItemDB::getItemInfos();
45
4
            std::list<std::string> tempStrings;
46
47
            for (std::map<int, ItemInfo*>::const_iterator
48
4
                 i = items.begin(), i_end = items.end();
49
2
                 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
2
            tempStrings.sort();
63
10
            mStrings.push_back("");
64
10
            FOR_EACH (std::list<std::string>::const_iterator, i, tempStrings)
65
                mStrings.push_back(*i);
66
2
        }
67
68
        A_DELETE_COPY(IconsModel)
69
70
        ~IconsModel()
71
2
        { }
72
73
16
        int getNumberOfElements() override final
74
        {
75
40
            return CAST_S32(mStrings.size());
76
        }
77
78
4
        std::string getElementAt(int i) override final
79
        {
80

8
            if (i < 0 || i >= getNumberOfElements())
81
                return "???";
82
8
            return mStrings.at(i);
83
        }
84
    private:
85
        StringVect mStrings;
86
};
87
88
#endif  // GUI_MODELS_ICONSMODEL_H