46 std::vector<std::shared_ptr<Item>>
items;
52 std::map<int32_t, std::shared_ptr<Item>>
item_map;
92 item->checked = !item->checked;
148 void add_item(std::shared_ptr<Item> item, std::shared_ptr<Category> category =
nullptr);
192 const std::string& name) {
194 if (category && category->name != name) {
195 category->name = name;
213 const std::string& name) {
215 if (item && item->name != name) {
236 if (item && item->checked != state) {
237 item->checked = state;
250 bool save(
const std::string& filename);
284 std::vector<std::shared_ptr<Item>>::size_type c = 0;
286 for (
const auto& item : cat_items)
388 const std::shared_ptr<Item>
get_item(int32_t
id)
const;
398 const std::shared_ptr<Category>
get_category(int32_t
id)
const;
435 const std::vector<std::shared_ptr<Item>>
448 const std::vector<std::shared_ptr<Item>>
486 std::vector<std::shared_ptr<Item>>&
items,
487 std::vector<std::shared_ptr<Category>>&
categories);
std::vector< std::shared_ptr< Item > >::size_type get_current_checked_item_count() const
void remove_items(const std::vector< std::shared_ptr< Item > > &items)
Removes references to each of the Item instances in the list from the currently selected Category.
const std::shared_ptr< Item > get_item(int32_t id) const
Gets an Item by ID.
void validate() const
Validates the model ensuring all the maps are consistent with each of the corresponding lists.
bool save(const std::string &filename)
saves the Model to a file.
void change_all_current_items_checked_states(check_action action)
Switches the checked state of all items in the currently selected Category.
void renumber()
Re-assigns IDs to all of the categories and items.
void add_category(std::shared_ptr< Category > category)
Adds the passed category to the model.
std::shared_ptr< Item > set_item_name(const int32_t id, const std::string &name)
Updates the name of the passed Item.
void sort()
Sorts everything within the model.
const std::vector< std::shared_ptr< Item > > get_all_items_for_current_selected_category() const
Returns all items for the currently selected Category.
bool is_dirty() const
Whether the model has been modified since it was last saved.
auto get_item_count() const
The count of items in the model.
void remove_all_current_checked_items()
Removes all checked items from the current category.
int32_t max_item_id
The highest item ID in use.
void set_filter(state_filter state)
Sets filtering of checked items.
void set_dirty(bool dirty=true)
Sets dirty flag.
state_filter filter
Indicates filtering state of checked items.
const std::shared_ptr< Category > get_category(int32_t id) const
Gets a Category by ID.
void remove_item(int32_t id)
Removes references to the item from the currently selected Category.
void sort_item_categories()
Sorts all the categories assicated with each item.
std::shared_ptr< Category > set_category_name(const int32_t id, const std::string &name)
Updates the name of passed Category.
void renumber_categories()
Re-assigns IDs to all the categories.
state_filter get_filter() const
The current state_filter.
auto count_filter_items_for_current_selected_category() const
Returns a count of the filtered items in the currently selected category.
const std::vector< std::shared_ptr< Category > > get_categories() const
The list of categories.
void copy_items_to_categories(std::vector< std::shared_ptr< Item > > &items, std::vector< std::shared_ptr< Category > > &categories)
Copies all of the passed items to each of the passed categories, updating the model relationships.
std::shared_ptr< Category > get_current_category()
Returns the current Category or nullptr if not found.
void show_model() const
Dumps details of the entire model for debugging.
void copy_item_to_categories(int32_t item_id, std::vector< int32_t > cids)
Copies the specified item to the list of categories.
const std::vector< std::shared_ptr< Item > > get_all_items() const
Gets all items, without filtering.
void delete_category(int32_t id)
Deletes the Category having the passed ID.
int32_t get_selected_category() const
The ID of the currently selected Category.
int32_t selected_category
The currently selected category.
int32_t max_category_id
The highest category ID in use.
const std::shared_ptr< Item > change_checked_state(int32_t id, check_action action)
Switches the checked state of the Item referenced by the specified ID according to the specified acti...
const std::vector< std::shared_ptr< Item > > filter_items_for_current_selected_category() const
Filters the list of Item instances based on the currently selected category (selected_category) and c...
void sort_category_items()
Sorts all the items associated with each category.
void sort_items()
Sorts all the model's items.
bool dirty
Indicates that the Model has been modified since it was last saved.
check_action
Specifies what state Item checkmarks must be changed to.
void add_item(std::shared_ptr< Item > item, std::shared_ptr< Category > category=nullptr)
Adds the passed Item to the model, updating item and category maps appropriately of both the Item and...
void delete_item(int32_t id)
Deletes the Item having the passed ID.
auto get_category_count() const
The count of categories in the model.
std::vector< std::shared_ptr< Item > > items
The list of items.
std::vector< std::shared_ptr< Category > > categories
The list of categories.
static const int32_t no_category
Indicates no filtering by category.
int32_t new_item(const std::string &name, bool checked=false)
Creates a new Item in the model using the passed parameters, incrementing max_item_id and assigning i...
std::shared_ptr< Item > set_item_checked(const int32_t id, const bool state)
Updates the checked state of the passed Item.
std::map< int32_t, std::shared_ptr< Category > > category_map
A map of all categories keyed by ID.
std::shared_ptr< Item > toggle_item_checked(const int32_t id)
Toggles the checked state of the passed Item.
void copy_checked_items_to_categories(std::vector< int32_t > cids)
Copies all currently checked items for the currently selected Category to the list of categories.
std::map< int32_t, std::shared_ptr< Item > > item_map
A map of all items keyed by ID.
void delete_all_current_checked_items()
Deletes all checked items.
void associate_item_with_category(int32_t item_id, std::shared_ptr< Category > category)
Updates the relationships between an Item and a Category that are already in the model,...
Model()
Default constructor.
void select_category(int32_t id)
Sets the selected Category to that of the passed ID.
int32_t new_category(const std::string &name)
Creates a new Category in the model using the passed parameters, incrementing max_category_id and ass...
virtual ~Model()
Destructor.
state_filter
Constants for filtering items depending on their checked state.
@ unchecked
Show only unchecked items.
@ all
Show all items, i.e. no filtering.
@ checked
Show only checked items.
void sort_categories()
Sorts all the model's categories.
void renumber_items()
Re-assigns IDs to all the items.