22#ifndef KITLIST_BASE_APP_HPP
23#define KITLIST_BASE_APP_HPP
163 return model->is_dirty();
167 model->set_dirty(dirty);
176 return model->get_current_checked_item_count();
205 if (!
model->is_dirty())
227 const std::string& name) {
228 auto category =
model->set_category_name(
id, name);
245 const std::string& name) {
246 auto item =
model->set_item_name(
id, name);
265 auto item =
model->set_item_checked(
id, state);
285 return model->change_checked_state(
id, action);
299 model->change_all_current_items_checked_states(action);
342 int32_t
new_item(
const std::string& name,
bool checked)
const {
343 return model->new_item(name, checked);
355 model->delete_category(
id);
367 model->delete_item(
id);
383 void remove_items(
const std::vector<std::shared_ptr<Item>>& items)
const {
384 model->remove_items(items);
397 model->remove_item(
id);
411 return model->new_category(name);
422 const std::shared_ptr<Item>
get_item(int32_t
id)
const {
423 return model->get_item(
id);
434 return model->get_category(
id);
444 const std::vector<std::shared_ptr<Item>>
447 return model->get_all_items_for_current_selected_category();
461 const std::vector<std::shared_ptr<Item>>
464 return model->filter_items_for_current_selected_category();
474 return model->count_filter_items_for_current_selected_category();
481 model->remove_all_current_checked_items();
491 model->delete_all_current_checked_items();
506 model->associate_item_with_category(item_id, category);
517 std::vector<std::shared_ptr<Item>>& items,
518 std::vector<std::shared_ptr<Category>>& categories)
const {
520 model->copy_items_to_categories(items, categories);
530 model->copy_checked_items_to_categories(cids);
540 model->copy_item_to_categories(item_id, cids);
550 model->select_category(
id);
560 return model->get_selected_category();
569 return model->get_categories();
579 return model->get_all_items();
584 model->set_filter(state);
592 return model->get_filter();
599 model->sort_categories();
617 virtual const char*
what()
const throw()
override {
virtual const char * what() const override
Describes the exeption.
file_not_found(std::string message)
Constructor taking a message.
std::string message
The exception's message.
void set_dirty(bool dirty=true) const
auto count_filter_items_for_current_selected_category() const
Returns a count of the filtered items in the currently selected category.
void remove_items(const std::vector< std::shared_ptr< Item > > &items) const
Removes references to each of the Item instances in the list from 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 (Model::selected_category...
void copy_item_to_categories(int32_t item_id, std::vector< int32_t > cids)
Copies the specified item to the list of categories.
void delete_all_current_checked_items()
Deletes all checked items.
void sort() const
Sorts everything within the model.
virtual const std::shared_ptr< Item > change_checked_state(int32_t id, Model::check_action action)
Switches the checked state of the Item referenced by the specified ID according to the specified acti...
void new_file()
Create a new Model and sets the associated filename to be empty.
virtual void update_menu_state(bool is_dirty)
Called whenever there is a change to the Model state.
const std::shared_ptr< Category > set_category_name(const int32_t id, const std::string &name)
Updates the name of passed Category.
KitListBaseApp()
Default constructor.
void sort_categories() const
Sorts all the model's categories.
void copy_checked_items_to_categories(std::vector< int32_t > cids) const
Copies all currently checked items for the currently selected Category to the list of categories.
virtual void item_checked_changed(const std::shared_ptr< Item > item)
void set_filter(Model::state_filter state) const
Sets filtering of checked items.
void remove_item(int32_t id) const
Removes references to the item from the currently selected Category.
int32_t get_selected_category() const
Gets the ID of the currently selected Category.
const std::shared_ptr< Item > set_item_name(const int32_t id, const std::string &name)
Updates the name of the passed Item.
const std::string get_filename() const
virtual void category_name_changed(const std::shared_ptr< Category > category)
std::string filename
The current filename the Model was loaded from.
void copy_items_to_categories(std::vector< std::shared_ptr< Item > > &items, std::vector< std::shared_ptr< Category > > &categories) const
Copies all of the passed items to each of the passed categories, updating the model relationships.
virtual void item_entry_changed(const std::shared_ptr< Item > item)
Called when a Item instance's state has changed.
const std::shared_ptr< Item > set_item_checked(const int32_t id, const bool state)
Updates the checked state of the passed Item.
virtual void category_entry_changed(const std::shared_ptr< Category > category)
Called when a Category name has changed.
void delete_category(int32_t id) const
Deletes the Category having the passed ID.
int32_t new_item(const std::string &name, bool checked) const
creates a new Item in the model using the passed parameters, incrementing Model::max_item_id and assi...
virtual void load_file(const std::string &filename)
Loads the specified file.
const std::vector< std::shared_ptr< Item > > get_all_items() const
Gets all items, without filtering.
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,...
virtual void initialization_complete()
Sets initialized to true.
void select_category(int32_t id)
Sets the selected Category to that of the passed ID.
virtual void item_name_changed(const std::shared_ptr< Item > item)
bool initialized
Indicates that the application has finished it's initialization stage.
void set_filename(const std::string &filename)
Sets a new filename to associate with the Model.
void remove_all_current_checked_items()
Removes all checked items from the current category.
std::unique_ptr< Model > model
The application's data model.
virtual bool save(std::string filename)
static const std::string DEFAULT_FILE_EXTENSION
The application's default filename extension. .kit.
const std::vector< std::shared_ptr< Item > > get_all_items_for_current_selected_category() const
Returns all items for the currently selected Category.
virtual ~KitListBaseApp()
Destructor.
void delete_item(int32_t id) const
Deletes the Item having the passed ID.
auto get_current_checked_item_count() const
const std::shared_ptr< Category > get_category(int32_t id) const
Gets a Category by ID.
const std::string all_items_text
Constant string indicating the option to select no category and therefor display all items.
const std::vector< std::shared_ptr< Category > > get_categories() const
Gets the list of categories.
int32_t new_category(const std::string &name) const
Creates a new Category in the Model using the passed parameters, incrementing Model::max_category_id ...
const std::shared_ptr< Item > get_item(int32_t id) const
Gets an Item by ID.
virtual bool save()
Saves the current Model using the current filename.
void change_all_current_items_checked_states(Model::check_action action) const
Switches the checked state of all items in the currently selected Category.
virtual void model_state_changed(bool is_dirty)
Called whenever the Model state is changed.
Model::state_filter get_filter() const
The current filter.
check_action
Specifies what state Item checkmarks must be changed to.
state_filter
Constants for filtering items depending on their checked state.
@ all
Show all items, i.e. no filtering.