Kitlist
A list manager for maintaining kit lists
Loading...
Searching...
No Matches
KitListBaseApp Class Reference

A pure virtual class acting as an interface for front-end implementations. More...

#include "kitlist_base_app.hpp"

Inheritance diagram for KitListBaseApp:
KitListGui fdsd::fc::KitListFinalcut fdsd::ftxui::KitListFtxui

Classes

class  file_not_found
 Exception throw when a file is not found. More...

Public Member Functions

 KitListBaseApp ()
 Default constructor.
virtual ~KitListBaseApp ()
 Destructor.
bool is_dirty () const
void set_dirty (bool dirty=true) const
auto get_current_checked_item_count () const
void new_file ()
 Create a new Model and sets the associated filename to be empty.
virtual void load_file (const std::string &filename)
 Loads the specified file.
virtual bool save ()
 Saves the current Model using the current filename.
virtual bool save (std::string filename)
const std::shared_ptr< Categoryset_category_name (const int32_t id, const std::string &name)
 Updates the name of passed Category.
const std::shared_ptr< Itemset_item_name (const int32_t id, const std::string &name)
 Updates the name of the passed Item.
const std::shared_ptr< Itemset_item_checked (const int32_t id, const bool state)
 Updates the checked state of the passed Item.
virtual const std::shared_ptr< Itemchange_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 action.
void change_all_current_items_checked_states (Model::check_action action) const
 Switches the checked state of all items in the currently selected Category.
void set_filename (const std::string &filename)
 Sets a new filename to associate with the Model.
const std::string get_filename () const
virtual void initialization_complete ()
 Sets initialized to true.
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 assigning it to the Item.
void delete_category (int32_t id) const
 Deletes the Category having the passed ID.
void delete_item (int32_t id) const
 Deletes the Item having the passed ID.
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.
void remove_item (int32_t id) const
 Removes references to the item from the currently selected Category.
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 and assigning it to the Category.
const std::shared_ptr< Itemget_item (int32_t id) const
 Gets an Item by ID.
const std::shared_ptr< Categoryget_category (int32_t id) const
 Gets a Category by ID.
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 (Model::selected_category) and checked status (Model::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 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.
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.
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.
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
 Gets the ID of the currently selected Category.
const std::vector< std::shared_ptr< Category > > get_categories () const
 Gets the list of categories.
const std::vector< std::shared_ptr< Item > > get_all_items () const
 Gets all items, without filtering.
void set_filter (Model::state_filter state) const
 Sets filtering of checked items.
Model::state_filter get_filter () const
 The current filter.
void sort_categories () const
 Sorts all the model's categories.
void sort () const
 Sorts everything within the model.

Public Attributes

const std::string all_items_text = "-- Show all items --"
 Constant string indicating the option to select no category and therefor display all items.

Static Public Attributes

static const std::string DEFAULT_FILE_EXTENSION = ".kit"
 The application's default filename extension. .kit.

Protected Member Functions

virtual void update_menu_state (bool is_dirty)
 Called whenever there is a change to the Model state.
virtual void category_entry_changed (const std::shared_ptr< Category > category)
 Called when a Category name has changed.
virtual void item_entry_changed (const std::shared_ptr< Item > item)
 Called when a Item instance's state has changed.
virtual void category_name_changed (const std::shared_ptr< Category > category)
virtual void item_name_changed (const std::shared_ptr< Item > item)
virtual void item_checked_changed (const std::shared_ptr< Item > item)
virtual void model_state_changed (bool is_dirty)
 Called whenever the Model state is changed.

Private Attributes

std::unique_ptr< Modelmodel
 The application's data model.
std::string filename
 The current filename the Model was loaded from.
bool initialized
 Indicates that the application has finished it's initialization stage.

Friends

class Model

Detailed Description

A pure virtual class acting as an interface for front-end implementations.

An implementation may override the following methods:

Definition at line 42 of file kitlist_base_app.hpp.

Constructor & Destructor Documentation

◆ KitListBaseApp()

KitListBaseApp::KitListBaseApp ( )

Default constructor.

Definition at line 30 of file kitlist_base_app.cpp.

◆ ~KitListBaseApp()

KitListBaseApp::~KitListBaseApp ( )
virtual

Destructor.

Definition at line 37 of file kitlist_base_app.cpp.

Member Function Documentation

◆ associate_item_with_category()

void KitListBaseApp::associate_item_with_category ( int32_t item_id,
std::shared_ptr< Category > category )
inline

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.

Parameters
item_idThe ID of the Item within the model.
categoryA std::shared_ptr to the Category within the model.

Definition at line 505 of file kitlist_base_app.hpp.

◆ category_entry_changed()

virtual void KitListBaseApp::category_entry_changed ( const std::shared_ptr< Category > category)
inlineprotectedvirtual

Called when a Category name has changed.

This allows the front-end implementation to update the category list view. The value will be a nullptr if there is no selected Category.

Reimplemented in fdsd::ftxui::KitListFtxui, and KitListGui.

Definition at line 91 of file kitlist_base_app.hpp.

◆ category_name_changed()

virtual void KitListBaseApp::category_name_changed ( const std::shared_ptr< Category > category)
inlineprotectedvirtual

Called whenever a Category name changes.

Parameters
categoryThe Category.

Definition at line 106 of file kitlist_base_app.hpp.

◆ change_all_current_items_checked_states()

void KitListBaseApp::change_all_current_items_checked_states ( Model::check_action action) const
inline

Switches the checked state of all items in the currently selected Category.

All items are processed without any filtering by their checked state.

Parameters
actionThe type of Model::check_action to take.

Definition at line 296 of file kitlist_base_app.hpp.

◆ change_checked_state()

virtual const std::shared_ptr< Item > KitListBaseApp::change_checked_state ( int32_t id,
Model::check_action action )
inlinevirtual

Switches the checked state of the Item referenced by the specified ID according to the specified action.

Parameters
idThe ID of the Item to be updated.
actionThe type of Model::check_action to take.
Returns
A pointer to the updated Item or nullptr if the Item does not exist.

Definition at line 281 of file kitlist_base_app.hpp.

◆ copy_checked_items_to_categories()

void KitListBaseApp::copy_checked_items_to_categories ( std::vector< int32_t > cids) const
inline

Copies all currently checked items for the currently selected Category to the list of categories.

Parameters
cidsA list of category IDs to copy all the checked items to.

Definition at line 529 of file kitlist_base_app.hpp.

◆ copy_item_to_categories()

void KitListBaseApp::copy_item_to_categories ( int32_t item_id,
std::vector< int32_t > cids )
inline

Copies the specified item to the list of categories.

Parameters
item_idThe ID of the item to be copies.
cidsA list of category IDs to copy all the checked items to.

Definition at line 539 of file kitlist_base_app.hpp.

◆ copy_items_to_categories()

void KitListBaseApp::copy_items_to_categories ( std::vector< std::shared_ptr< Item > > & items,
std::vector< std::shared_ptr< Category > > & categories ) const
inline

Copies all of the passed items to each of the passed categories, updating the model relationships.

Parameters
itemsThe source list of Item instance to copy to categories.
categoriesThe target list of Category instances.

Definition at line 516 of file kitlist_base_app.hpp.

◆ count_filter_items_for_current_selected_category()

auto KitListBaseApp::count_filter_items_for_current_selected_category ( ) const
inline

Returns a count of the filtered items in the currently selected category.

If Model::selected_category is Model::no_category then all items are returned subject to the Model::filter state.

Definition at line 473 of file kitlist_base_app.hpp.

◆ delete_all_current_checked_items()

void KitListBaseApp::delete_all_current_checked_items ( )
inline

Deletes all checked items.

If there is a current category selected, then only those items in the current category are deleted.

Definition at line 490 of file kitlist_base_app.hpp.

◆ delete_category()

void KitListBaseApp::delete_category ( int32_t id) const
inline

Deletes the Category having the passed ID.

The model relationships are updated appropriately.

Parameters
idThe ID of the Category to delete.

Definition at line 354 of file kitlist_base_app.hpp.

◆ delete_item()

void KitListBaseApp::delete_item ( int32_t id) const
inline

Deletes the Item having the passed ID.

The model relationships are updated appropriately.

Parameters
idThe ID of the Item to delete.

Definition at line 366 of file kitlist_base_app.hpp.

◆ filter_items_for_current_selected_category()

const std::vector< std::shared_ptr< Item > > KitListBaseApp::filter_items_for_current_selected_category ( ) const
inline

Filters the list of Item instances based on the currently selected category (Model::selected_category) and checked status (Model::filter).

If Model::selected_category is Model::no_category then all items are returned subject to the Model::filter state.

Returns
a filtered list of Item instances.
See also
Model::get_items_for_current_selected_category()

Definition at line 462 of file kitlist_base_app.hpp.

◆ get_all_items()

const std::vector< std::shared_ptr< Item > > KitListBaseApp::get_all_items ( ) const
inline

Gets all items, without filtering.

Returns
all items, i.e. without any filtering by checked state or current Category.

Definition at line 578 of file kitlist_base_app.hpp.

◆ get_all_items_for_current_selected_category()

const std::vector< std::shared_ptr< Item > > KitListBaseApp::get_all_items_for_current_selected_category ( ) const
inline

Returns all items for the currently selected Category.

All items are returned without any filtering by their checked state.

See also
Model::selected_category

Definition at line 445 of file kitlist_base_app.hpp.

◆ get_categories()

const std::vector< std::shared_ptr< Category > > KitListBaseApp::get_categories ( ) const
inline

Gets the list of categories.

Returns
All categories.

Definition at line 568 of file kitlist_base_app.hpp.

◆ get_category()

const std::shared_ptr< Category > KitListBaseApp::get_category ( int32_t id) const
inline

Gets a Category by ID.

Parameters
idThe ID of the Category.
Returns
The Category with the passed ID, or nullptr if it does not exist in the model.

Definition at line 433 of file kitlist_base_app.hpp.

◆ get_current_checked_item_count()

auto KitListBaseApp::get_current_checked_item_count ( ) const
inline

Returns the count of items in the current Category.

The count disregards the current filter.

Definition at line 175 of file kitlist_base_app.hpp.

◆ get_filename()

const std::string KitListBaseApp::get_filename ( ) const
inline
Returns
the filename associated with the Model.

Definition at line 314 of file kitlist_base_app.hpp.

◆ get_filter()

Model::state_filter KitListBaseApp::get_filter ( ) const
inline

The current filter.

Returns
The current Model::state_filter.

Definition at line 591 of file kitlist_base_app.hpp.

◆ get_item()

const std::shared_ptr< Item > KitListBaseApp::get_item ( int32_t id) const
inline

Gets an Item by ID.

Parameters
idthe id of the Item.
Returns
the Item with the passed id, or nullptr if it does not exist in the model.

Definition at line 422 of file kitlist_base_app.hpp.

◆ get_selected_category()

int32_t KitListBaseApp::get_selected_category ( ) const
inline

Gets the ID of the currently selected Category.

Returns
The ID.

Definition at line 559 of file kitlist_base_app.hpp.

◆ initialization_complete()

virtual void KitListBaseApp::initialization_complete ( )
inlinevirtual

Sets initialized to true.

Indicates that the application has finished initializing. Thereafter, the app will be notified via calls to update_menu_state() when the Model state changes.

Definition at line 325 of file kitlist_base_app.hpp.

◆ is_dirty()

bool KitListBaseApp::is_dirty ( ) const
inline
Returns
true if the Model has been modified since it was last saved.

Definition at line 162 of file kitlist_base_app.hpp.

◆ item_checked_changed()

virtual void KitListBaseApp::item_checked_changed ( const std::shared_ptr< Item > item)
inlineprotectedvirtual

Called whenever a Item checked state changes.

Parameters
itemThe Item.

Definition at line 128 of file kitlist_base_app.hpp.

◆ item_entry_changed()

virtual void KitListBaseApp::item_entry_changed ( const std::shared_ptr< Item > item)
inlineprotectedvirtual

Called when a Item instance's state has changed.

This allows the front-end implementation to update the item list view. The value will be a nullptr if there is no selected Item.

Reimplemented in fdsd::ftxui::KitListFtxui, and KitListGui.

Definition at line 99 of file kitlist_base_app.hpp.

◆ item_name_changed()

virtual void KitListBaseApp::item_name_changed ( const std::shared_ptr< Item > item)
inlineprotectedvirtual

Called whenever a Item name changes.

Parameters
itemThe Item.

Definition at line 117 of file kitlist_base_app.hpp.

◆ load_file()

void KitListBaseApp::load_file ( const std::string & filename)
virtual

Loads the specified file.

Loads the Model from the specified filename.

Parameters
filenameThe name of the file to load.
Exceptions
KitParser::parse_exceptionThrown if there is an error parsing the file.
KitListBaseApp::file_not_foundif the file does not exist or cannot be read.

Reimplemented in KitListGui.

Definition at line 39 of file kitlist_base_app.cpp.

◆ model_state_changed()

virtual void KitListBaseApp::model_state_changed ( bool is_dirty)
inlineprotectedvirtual

Called whenever the Model state is changed.

In turn, calls model_state_changed() if initialized is true.

Parameters
is_dirtythe current Model state.

Definition at line 141 of file kitlist_base_app.hpp.

◆ new_category()

int32_t KitListBaseApp::new_category ( const std::string & name) const
inline

Creates a new Category in the Model using the passed parameters, incrementing Model::max_category_id and assigning it to the Category.

Parameters
nameThe category's name.
Returns
The ID of the newly created category.

Definition at line 410 of file kitlist_base_app.hpp.

◆ new_file()

void KitListBaseApp::new_file ( )
inline

Create a new Model and sets the associated filename to be empty.

Definition at line 180 of file kitlist_base_app.hpp.

◆ new_item()

int32_t KitListBaseApp::new_item ( const std::string & name,
bool checked ) const
inline

creates a new Item in the model using the passed parameters, incrementing Model::max_item_id and assigning it to the Item.

Parameters
namethe item's name.
checkedan optional boolean, true indicating it is checked. defaults to false.
Returns
the id of the newly created item.

Definition at line 342 of file kitlist_base_app.hpp.

◆ remove_all_current_checked_items()

void KitListBaseApp::remove_all_current_checked_items ( )
inline

Removes all checked items from the current category.

Definition at line 480 of file kitlist_base_app.hpp.

◆ remove_item()

void KitListBaseApp::remove_item ( int32_t id) const
inline

Removes references to the item from the currently selected Category.

The model relationships are updated appropriately.

Remarks
The item itself is not deleted from the model and therefore will still be returned by a call to get_all_items.

Definition at line 396 of file kitlist_base_app.hpp.

◆ remove_items()

void KitListBaseApp::remove_items ( const std::vector< std::shared_ptr< Item > > & items) const
inline

Removes references to each of the Item instances in the list from the currently selected Category.

All the model relationships are updated appropriately.

Parameters
itemsA list of shared_ptr to the Item instances being removed from the currently selected Category.
Remarks
The items themselves are not deleted from the model and therefore will still be returned by a call to get_all_items.

Definition at line 383 of file kitlist_base_app.hpp.

◆ save() [1/2]

virtual bool KitListBaseApp::save ( )
inlinevirtual

Saves the current Model using the current filename.

Definition at line 201 of file kitlist_base_app.hpp.

◆ save() [2/2]

virtual bool KitListBaseApp::save ( std::string filename)
inlinevirtual

Definition at line 210 of file kitlist_base_app.hpp.

◆ select_category()

void KitListBaseApp::select_category ( int32_t id)
inline

Sets the selected Category to that of the passed ID.

Parameters
idThe ID of the Category

Definition at line 549 of file kitlist_base_app.hpp.

◆ set_category_name()

const std::shared_ptr< Category > KitListBaseApp::set_category_name ( const int32_t id,
const std::string & name )
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.

Parameters
idThe ID of the Category to be updated.
nameThe new name of the Category.
Returns
A pointer to the Category or nullptr if it does not exist.

Definition at line 226 of file kitlist_base_app.hpp.

◆ set_dirty()

void KitListBaseApp::set_dirty ( bool dirty = true) const
inline

Definition at line 166 of file kitlist_base_app.hpp.

◆ set_filename()

void KitListBaseApp::set_filename ( const std::string & filename)
inline

Sets a new filename to associate with the Model.

Parameters
filenamethe new filename.

Definition at line 307 of file kitlist_base_app.hpp.

◆ set_filter()

void KitListBaseApp::set_filter ( Model::state_filter state) const
inline

Sets filtering of checked items.

See also
state_filter.

Definition at line 583 of file kitlist_base_app.hpp.

◆ set_item_checked()

const std::shared_ptr< Item > KitListBaseApp::set_item_checked ( const int32_t id,
const bool state )
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.

Parameters
idThe ID of the Item to be updated.
stateThe new state of the Item.
Returns
A pointer to the Item or nullptr if it does not exist.

Definition at line 263 of file kitlist_base_app.hpp.

◆ set_item_name()

const std::shared_ptr< Item > KitListBaseApp::set_item_name ( const int32_t id,
const std::string & name )
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.

Parameters
idThe ID of the Item to be updated.
nameThe new name of the Item.
Returns
A pointer to the Item or nullptr if it does not exist.

Definition at line 244 of file kitlist_base_app.hpp.

◆ sort()

void KitListBaseApp::sort ( ) const
inline

Sorts everything within the model.

Definition at line 605 of file kitlist_base_app.hpp.

◆ sort_categories()

void KitListBaseApp::sort_categories ( ) const
inline

Sorts all the model's categories.

Definition at line 598 of file kitlist_base_app.hpp.

◆ update_menu_state()

virtual void KitListBaseApp::update_menu_state ( bool is_dirty)
inlineprotectedvirtual

Called whenever there is a change to the Model state.

This allows the front-end implementation to enable or disabled menu items as appropriate to the new state.

This implementation does nothing, so there is no need for a sub-class to call it.

State changes to the model are ignored if initialized is false.

Reimplemented in KitListGui.

Definition at line 80 of file kitlist_base_app.hpp.

◆ Model

friend class Model
friend

Definition at line 44 of file kitlist_base_app.hpp.

Member Data Documentation

◆ all_items_text

const std::string KitListBaseApp::all_items_text = "-- Show all items --"

Constant string indicating the option to select no category and therefor display all items.

Definition at line 156 of file kitlist_base_app.hpp.

◆ DEFAULT_FILE_EXTENSION

const string KitListBaseApp::DEFAULT_FILE_EXTENSION = ".kit"
static

The application's default filename extension. .kit.

Definition at line 159 of file kitlist_base_app.hpp.

◆ filename

std::string KitListBaseApp::filename
private

The current filename the Model was loaded from.

An empty string indicates no file is currently associated with the Model.

Definition at line 55 of file kitlist_base_app.hpp.

◆ initialized

bool KitListBaseApp::initialized
private

Indicates that the application has finished it's initialization stage.

Before the application has fully initialised, it may not be safe to update it's state, e.g. calls to update_menu_state() are skipped until initialized is true.

Definition at line 65 of file kitlist_base_app.hpp.

◆ model

std::unique_ptr<Model> KitListBaseApp::model
private

The application's data model.

Definition at line 47 of file kitlist_base_app.hpp.


The documentation for this class was generated from the following files:
Copyright 2008-2025 Frank Dean