|
Kitlist
A list manager for maintaining kit lists
|
Maintains the data model. More...
#include "model.hpp"
Public Types | |
| enum | state_filter { all , checked , unchecked } |
| Constants for filtering items depending on their checked state. More... | |
| enum | check_action { toggle , check , uncheck } |
| Specifies what state Item checkmarks must be changed to. More... | |
Public Member Functions | |
| Model () | |
| Default constructor. | |
| virtual | ~Model () |
| Destructor. | |
| 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, but using only the item's ID as a reference. | |
| std::shared_ptr< Category > | set_category_name (const int32_t id, const std::string &name) |
| Updates the name of passed Category. | |
| std::shared_ptr< Item > | set_item_name (const int32_t id, const std::string &name) |
| Updates the name of the passed Item. | |
| std::shared_ptr< Item > | set_item_checked (const int32_t id, const bool state) |
| Updates the checked state of the passed Item. | |
| bool | save (const std::string &filename) |
| saves the Model to a file. | |
| void | set_dirty (bool dirty=true) |
| Sets dirty flag. | |
| 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. | |
| std::vector< std::shared_ptr< Item > >::size_type | get_current_checked_item_count () const |
| auto | get_category_count () const |
| The count of categories in the model. | |
| 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 it to the Item. | |
| void | delete_category (int32_t id) |
| Deletes the Category having the passed ID. | |
| void | delete_item (int32_t id) |
| Deletes the Item having the passed ID. | |
| 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. | |
| void | remove_item (int32_t id) |
| Removes references to the item from the currently selected Category. | |
| int32_t | new_category (const std::string &name) |
| Creates a new Category in the model using the passed parameters, incrementing max_category_id and assigning it to the Category. | |
| void | add_category (std::shared_ptr< Category > category) |
| Adds the passed category to the model. | |
| const std::shared_ptr< Item > | get_item (int32_t id) const |
| Gets an Item by ID. | |
| const std::shared_ptr< Category > | get_category (int32_t id) const |
| Gets a Category by ID. | |
| std::shared_ptr< Category > | get_current_category () |
| Returns the current Category or nullptr if not found. | |
| 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 action. | |
| void | change_all_current_items_checked_states (check_action action) |
| Switches the checked state of all items in the currently selected Category. | |
| const std::vector< std::shared_ptr< Item > > | get_all_items_for_current_selected_category () const |
| Returns all items for the currently selected Category. | |
| 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 checked status (filter). | |
| auto | count_filter_items_for_current_selected_category () const |
| Returns a count of the filtered items in the currently selected category. | |
| void | remove_all_current_checked_items () |
| Removes all checked items from the current category. | |
| void | delete_all_current_checked_items () |
| Deletes all checked items. | |
| 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. | |
| 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. | |
| void | copy_item_to_categories (int32_t item_id, std::vector< int32_t > cids) |
| Copies the specified item to the list of categories. | |
| void | select_category (int32_t id) |
| Sets the selected Category to that of the passed ID. | |
| int32_t | get_selected_category () const |
| The ID of the currently selected Category. | |
| const std::vector< std::shared_ptr< Category > > | get_categories () const |
| The list of categories. | |
| const std::vector< std::shared_ptr< Item > > | get_all_items () const |
| Gets all items, without filtering. | |
| void | set_filter (state_filter state) |
| Sets filtering of checked items. | |
| state_filter | get_filter () const |
| The current state_filter. | |
| void | sort_items () |
| Sorts all the model's items. | |
| void | sort_categories () |
| Sorts all the model's categories. | |
| void | sort_category_items () |
| Sorts all the items associated with each category. | |
| void | sort_item_categories () |
| Sorts all the categories assicated with each item. | |
| void | sort () |
| Sorts everything within the model. | |
| void | show_model () const |
| Dumps details of the entire model for debugging. | |
| void | validate () const |
| Validates the model ensuring all the maps are consistent with each of the corresponding lists. | |
| void | renumber_items () |
| Re-assigns IDs to all the items. | |
| void | renumber_categories () |
| Re-assigns IDs to all the categories. | |
| void | renumber () |
| Re-assigns IDs to all of the categories and items. | |
Static Public Attributes | |
| static const int32_t | no_category = -1 |
| Indicates no filtering by category. | |
Protected Member Functions | |
| 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 the Category. | |
Private Member Functions | |
| std::shared_ptr< Item > | toggle_item_checked (const int32_t id) |
| Toggles the checked state of the passed Item. | |
Private Attributes | |
| bool | dirty |
| Indicates that the Model has been modified since it was last saved. | |
| std::vector< std::shared_ptr< Item > > | items |
| The list of items. | |
| std::vector< std::shared_ptr< Category > > | categories |
| The list of categories. | |
| std::map< int32_t, std::shared_ptr< Item > > | item_map |
| A map of all items keyed by ID. | |
| std::map< int32_t, std::shared_ptr< Category > > | category_map |
| A map of all categories keyed by ID. | |
| int32_t | max_item_id |
| The highest item ID in use. | |
| int32_t | max_category_id |
| The highest category ID in use. | |
| int32_t | selected_category |
| The currently selected category. | |
| state_filter | filter |
| Indicates filtering state of checked items. | |
Friends | |
| class | KitParser |
Maintains the data model.
Manages the category and item lists and their relationships.
| enum Model::check_action |
| enum Model::state_filter |
| void Model::add_category | ( | std::shared_ptr< Category > | category | ) |
|
protected |
Adds the passed Item to the model, updating item and category maps appropriately of both the Item and the Category.
| item | A std::shared_ptr to the Item to add to the model. |
| category | An optional std::shared_ptr to an existing Category in the model. |
| void Model::associate_item_with_category | ( | int32_t | item_id, |
| std::shared_ptr< Category > | category ) |
| void Model::change_all_current_items_checked_states | ( | check_action | action | ) |
Switches the checked state of all items in the currently selected Category.
All items are processed without any filtering by their checked state.
| action | The type of check_action to take. |
| const std::shared_ptr< Item > Model::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 action.
| id | The ID of the Item to be updated. |
| action | The type of check_action to take. |
| void Model::copy_checked_items_to_categories | ( | std::vector< int32_t > | cids | ) |
| void Model::copy_item_to_categories | ( | int32_t | item_id, |
| std::vector< int32_t > | cids ) |
| void Model::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.
Only the items complying with the specified filter are copied to categories. The default of Model::all copies all items, otherwise only items matching the specified filter are copied.
|
inline |
Returns a count of the filtered items in the currently selected category.
If selected_category is no_category then all items are returned subject to the filter state.
| void Model::delete_all_current_checked_items | ( | ) |
| void Model::delete_category | ( | int32_t | id | ) |
| void Model::delete_item | ( | int32_t | id | ) |
| const vector< shared_ptr< Item > > Model::filter_items_for_current_selected_category | ( | ) | const |
Filters the list of Item instances based on the currently selected category (selected_category) and checked status (filter).
If selected_category is no_category then all items are returned subject to the filter state.
|
inline |
| const vector< shared_ptr< Item > > Model::get_all_items_for_current_selected_category | ( | ) | const |
Returns all items for the currently selected Category.
All items are returned without any filtering by their checked state.
|
inline |
| const std::shared_ptr< Category > Model::get_category | ( | int32_t | id | ) | const |
|
inline |
|
inline |
|
inline |
|
inline |
The current state_filter.
| const std::shared_ptr< Item > Model::get_item | ( | int32_t | id | ) | const |
|
inline |
|
inline |
|
inline |
| int32_t Model::new_category | ( | const std::string & | name | ) |
Creates a new Category in the model using the passed parameters, incrementing max_category_id and assigning it to the Category.
| name | The category's name. |
| int32_t Model::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 it to the Item.
| name | The item's name. |
| checked | An optional boolean, true indicating it is checked. Defaults to false. |
| void Model::remove_all_current_checked_items | ( | ) |
| void Model::remove_item | ( | int32_t | id | ) |
Removes references to the item from the currently selected Category.
The model relationships are updated appropriately.
| void Model::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.
All the model relationships are updated appropriately.
| items | A list of shared_ptr to the Item instances being removed from the currently selected Category. |
| void Model::renumber | ( | ) |
| void Model::renumber_categories | ( | ) |
| void Model::renumber_items | ( | ) |
| bool Model::save | ( | const std::string & | filename | ) |
|
inline |
|
inline |
Updates the name of passed Category.
Implemented such that only calls from an implementation of KitListBaseApp can modify the model and therefore have an opportunity to be aware of the change, updating the user interface appropriately.
| void Model::set_dirty | ( | bool | dirty = true | ) |
Sets dirty flag.
Also calls KitListBaseApp::model_state_changed() notifying the change of state.
| dirty | true if the model has been altered. |
|
inline |
|
inline |
Updates the checked state of the passed Item.
Implemented such that only calls from an implementation of KitListBaseApp can modify the model and therefore have an opportunity to be aware of the change, updating the user interface appropriately.
|
inline |
Updates the name of the passed Item.
Implemented such that only calls from an implementation of KitListBaseApp can modify the model and therefore have an opportunity to be aware of the change, updating the user interface appropriately.
| void Model::show_model | ( | ) | const |
| void Model::sort_categories | ( | ) |
| void Model::sort_category_items | ( | ) |
| void Model::sort_item_categories | ( | ) |
|
inlineprivate |
Toggles the checked state of the passed Item.
Implemented such that only calls from an implementation of KitListBaseApp can modify the model and therefore have an opportunity to be aware of the change, updating the user interface appropriately.
| id | The ID of the Item to be updated. |
| void Model::validate | ( | ) | const |
|
private |
|
private |
|
private |
|
private |
Indicates filtering state of checked items.
|
private |
|
private |
|
private |
|
private |
|
static |
|
private |
The currently selected category.
A value of no_category indicates that no category is selected, so all items will be shown.