GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/models/namesmodel.cpp Lines: 20 21 95.2 %
Date: 2019-08-19 Branches: 10 16 62.5 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2012-2019  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/models/namesmodel.h"
22
23
#include "utils/cast.h"
24
#include "utils/foreach.h"
25
#include "utils/gettext.h"
26
27
#include "debug.h"
28
29
45
NamesModel::NamesModel() :
30
    ListModel(),
31
135
    mNames()
32
{
33
45
}
34
35
45
NamesModel::~NamesModel()
36
{
37
45
}
38
39
1130
int NamesModel::getNumberOfElements()
40
{
41
4296
    return CAST_S32(mNames.size());
42
}
43
44
1018
std::string NamesModel::getElementAt(int i)
45
{
46

1018
    if (i >= getNumberOfElements() || i < 0)
47
        return "???";
48
2036
    return mNames[CAST_SIZE(i)];
49
}
50
51
29
void NamesModel::fillFromArray(const char *const *const arr,
52
                               const std::size_t sz)
53
{
54
29
    if (arr == nullptr)
55
        return;
56
281
    for (size_t f = 0; f < sz; f ++)
57
630
        mNames.push_back(gettext(arr[f]));
58
}
59
60
2
void NamesModel::fillFromVector(const StringVect &vect)
61
{
62
16
    FOR_EACH(StringVectCIter, it, vect)
63
    {
64
24
        const std::string str = *it;
65
8
        if (!str.empty())
66
8
            mNames.push_back(str);
67
    }
68
2
}