GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/shortcut/shortcutbase.h Lines: 0 7 0.0 %
Date: 2021-03-17 Branches: 0 0 0.0 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2009  The Mana World Development Team
4
 *  Copyright (C) 2011-2019  The ManaPlus Developers
5
 *  Copyright (C) 2009-2021  Andrei Karas
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_SHORTCUT_SHORTCUTBASE_H
24
#define GUI_SHORTCUT_SHORTCUTBASE_H
25
26
#include "enums/simpletypes/itemcolor.h"
27
28
#include "utils/cast.h"
29
30
#include <string>
31
32
#include "localconsts.h"
33
34
class Item;
35
36
/**
37
 * The class which keeps track of the item shortcuts.
38
 */
39
class ShortcutBase notfinal
40
{
41
    public:
42
        /**
43
         * Constructor.
44
         */
45
        ShortcutBase(const std::string &itemName,
46
                     const std::string &colorName,
47
                     const int maxSize);
48
49
        A_DELETE_COPY(ShortcutBase)
50
51
        /**
52
         * Destructor.
53
         */
54
        virtual ~ShortcutBase();
55
56
        /**
57
         * Load the configuration information.
58
         */
59
        void load();
60
61
        /**
62
         * Save the configuration information.
63
         */
64
        void save() const;
65
66
        /**
67
         * Returns the shortcut item ID specified by the index.
68
         *
69
         * @param index Index of the shortcut item.
70
         */
71
        int getItem(const size_t index) const A_WARN_UNUSED
72
        { return mItems[index]; }
73
74
        ItemColor getItemColor(const size_t index) const A_WARN_UNUSED
75
        { return mItemColors[index]; }
76
77
        /**
78
         * Returns the amount of shortcut items.
79
         */
80
        int getItemCount() const noexcept2 A_WARN_UNUSED
81
        { return CAST_S32(mMaxSize); }
82
83
        /**
84
         * Returns the item ID that is currently selected.
85
         */
86
        int getItemSelected() const noexcept2 A_WARN_UNUSED
87
        { return mItemSelected; }
88
89
        /**
90
         * Adds the selected item ID to the items specified by the index.
91
         *
92
         * @param index Index of the items.
93
         */
94
        void setItem(const size_t index);
95
96
        /**
97
         * Adds an item to the items store specified by the index.
98
         *
99
         * @param index Index of the item.
100
         * @param itemId ID of the item.
101
         */
102
        void setItems(const size_t index,
103
                      const int itemId,
104
                      const ItemColor color)
105
        { mItems[index] = itemId; mItemColors[index] = color; save(); }
106
107
        /**
108
         * Set the item that is selected.
109
         *
110
         * @param itemId The ID of the item that is to be assigned.
111
         */
112
        void setItemSelected(const int itemId)
113
        { mItemSelected = itemId; }
114
115
        void setItemSelected(const Item *const item);
116
117
        /**
118
         * A flag to check if the item is selected.
119
         */
120
        bool isItemSelected() const noexcept2 A_WARN_UNUSED
121
        { return mItemSelected > -1; }
122
123
        /**
124
         * Remove a item from the shortcut.
125
         */
126
        void removeItem(const size_t index)
127
        { mItems[index] = -1; save(); }
128
129
        void clear(const bool isSave);
130
131
    private:
132
        int *mItems A_NONNULLPOINTER;
133
        ItemColor *mItemColors A_NONNULLPOINTER;
134
        std::string mItemName;
135
        std::string mColorName;
136
        size_t mMaxSize;
137
        int mItemSelected;
138
        ItemColor mItemColorSelected;
139
};
140
141
#endif  // GUI_SHORTCUT_SHORTCUTBASE_H