Kitlist  1.1.0
Public Member Functions | Protected Attributes | List of all members
KitModel Class Reference

Holds a rich graph of objects representing the application's data model. More...

#include <kitmodel.hpp>

Public Member Functions

 KitModel ()
 Creates an empty data model. More...
 
 ~KitModel ()
 Destructor. More...
 
void foreach_item_iter (const SlotForeachModelItemIter &slot)
 Calls the provided slot for each item in the map. More...
 
void foreach_item (const SlotForeachModelItem &slot)
 Calls the provided slot for each item in the map. More...
 
void foreach_category_iter (const SlotForeachCategoryIter &slot)
 Calls the provided slot for each category in the map. More...
 
void foreach_category (const SlotForeachCategory &slot)
 Calls the provided slot for each category in the map. More...
 
virtual ModelCategoryfind_category (long id)
 Finds a Category by it's unique ID. More...
 
virtual ModelItemfind_item (long id)
 Finds an item by it's unique ID. More...
 
virtual CategoryContainerget_categories ()
 Returns a list of all categories. More...
 
virtual ItemContainerget_all_items ()
 Returns a list of all items. More...
 
virtual ItemContainerget_all_items (ItemFunctor &functor)
 Returns a list of all items, filtered by the passed functor. More...
 
virtual void add_category (ModelCategory *category)
 Add a category to the model. More...
 
virtual void add_item (ModelItem *item)
 Adds an item to the model. More...
 
virtual void add_item (ModelItem *item, long cat_id)
 Adds an item to the model and associates it with the specified category. More...
 
virtual void copy_items (const ModelItemContainer &items, long cat_id=-1)
 Copies items to the specified category. More...
 
virtual bool filter (bool checked)
 Applies the current filter. More...
 
virtual void set_dirty (bool dirty=true)
 
virtual bool is_dirty ()
 
virtual void show_all ()
 Removes filter. All items are shown. More...
 
virtual void show_checked_only ()
 Sets the filter to show only checked items. More...
 
virtual void show_unchecked_only ()
 Sets the filter to show only unchecked items. More...
 
virtual void reset ()
 Resets all contained objects to their default states. More...
 
virtual void purge ()
 Purges deleted categories and items from the model. More...
 

Protected Attributes

bool m_dirty
 Indicates whether the model needs saving. I.e it's state has changed. More...
 
CategoryMapm_category_map
 Map allowing categories to be located by ID. More...
 
ItemMapm_item_map
 Map allowing items to be located by ID. More...
 
enum item_filter_types m_item_filter
 Indicates whether and how items are currently filtered. More...
 

Detailed Description

Holds a rich graph of objects representing the application's data model.

Definition at line 135 of file kitmodel.hpp.

Constructor & Destructor Documentation

◆ KitModel()

KitModel::KitModel ( )

Creates an empty data model.

Definition at line 187 of file kitmodel.cpp.

References m_category_map, and m_item_map.

◆ ~KitModel()

KitModel::~KitModel ( )

Destructor.

Deletes all items and categories belonging to the model.

Definition at line 198 of file kitmodel.cpp.

References m_category_map, and m_item_map.

Member Function Documentation

◆ add_category()

void KitModel::add_category ( ModelCategory category)
virtual

Add a category to the model.

The category is included in the model's map.

Definition at line 361 of file kitmodel.cpp.

References Category::get_id(), and m_category_map.

Referenced by Service::create_category(), and KitParser::process_category().

◆ add_item() [1/2]

void KitModel::add_item ( ModelItem item)
virtual

Adds an item to the model.

The item is included in the model's map.

Definition at line 371 of file kitmodel.cpp.

References Item::get_id(), and m_item_map.

Referenced by Service::create_item(), and KitParser::process_item().

◆ add_item() [2/2]

void KitModel::add_item ( ModelItem item,
long  cat_id 
)
virtual

Adds an item to the model and associates it with the specified category.

The category must have already been added to the model's map.

Definition at line 382 of file kitmodel.cpp.

References ModelCategory::add_item(), find_category(), Item::get_id(), and m_item_map.

◆ copy_items()

void KitModel::copy_items ( const ModelItemContainer items,
long  cat_id = -1 
)
virtual

Copies items to the specified category.

Only copies those items that do not already exist in the target category.

Definition at line 399 of file kitmodel.cpp.

References ModelCategory::add_item(), find_category(), Category::m_items, and GuiState::set_dirty().

Referenced by Service::copy_items().

◆ filter()

bool KitModel::filter ( bool  checked)
virtual

Applies the current filter.

Parameters
checkedThe checked/ticked state of the item being filtered.
Returns
true if the item should be included.

Definition at line 446 of file kitmodel.cpp.

References ALL, CHECKED, m_item_filter, and UNCHECKED.

Referenced by Service::filter(), and FilterItem::operator()().

◆ find_category()

ModelCategory * KitModel::find_category ( long  id)
virtual

◆ find_item()

ModelItem * KitModel::find_item ( long  id)
virtual

Finds an item by it's unique ID.

Definition at line 278 of file kitmodel.cpp.

References m_item_map.

Referenced by Service::delete_item(), Service::find_item(), KitParser::process_category_item(), and Service::update_item().

◆ foreach_category()

void KitModel::foreach_category ( const SlotForeachCategory slot)

Calls the provided slot for each category in the map.

Definition at line 254 of file kitmodel.cpp.

References m_category_map.

Referenced by XmlDao::save_model().

◆ foreach_category_iter()

void KitModel::foreach_category_iter ( const SlotForeachCategoryIter slot)

Calls the provided slot for each category in the map.

Definition at line 242 of file kitmodel.cpp.

References m_category_map.

◆ foreach_item()

void KitModel::foreach_item ( const SlotForeachModelItem slot)

Calls the provided slot for each item in the map.

Definition at line 230 of file kitmodel.cpp.

References m_item_map.

Referenced by XmlDao::save_model().

◆ foreach_item_iter()

void KitModel::foreach_item_iter ( const SlotForeachModelItemIter slot)

Calls the provided slot for each item in the map.

Definition at line 218 of file kitmodel.cpp.

References m_item_map.

◆ get_all_items() [1/2]

ItemContainer * KitModel::get_all_items ( )
virtual

Returns a list of all items.

Excluded items are excluded from the list. The caller is responsible for deleting the returned item list.

Definition at line 327 of file kitmodel.cpp.

References m_item_map.

Referenced by Service::get_filtered_items(), Service::get_items(), and XmlDao::get_model().

◆ get_all_items() [2/2]

ItemContainer * KitModel::get_all_items ( ItemFunctor functor)
virtual

Returns a list of all items, filtered by the passed functor.

Excluded items are excluded from the list. The caller is responsible for deleting the returned item list.

Definition at line 345 of file kitmodel.cpp.

References m_item_map.

◆ get_categories()

CategoryContainer * KitModel::get_categories ( )
virtual

Returns a list of all categories.

Definition at line 300 of file kitmodel.cpp.

References GuiState::is_deleted(), and m_category_map.

Referenced by Service::get_categories(), and XmlDao::get_model().

◆ is_dirty()

virtual bool KitModel::is_dirty ( )
inlinevirtual

Definition at line 177 of file kitmodel.hpp.

References GuiState::m_dirty.

Referenced by Service::is_model_dirty().

◆ purge()

void KitModel::purge ( )
virtual

Purges deleted categories and items from the model.

Typically, this method is called after a save operation, but before calling KitModel::reset()

Definition at line 486 of file kitmodel.cpp.

References GuiState::is_deleted(), m_category_map, m_item_map, and ModelCategory::purge().

Referenced by XmlDao::save_model().

◆ reset()

void KitModel::reset ( )
virtual

Resets all contained objects to their default states.

This method needs to be called after load or save operations to ensure all the dirty, deleted and new flags of each object are reset.

After a save operation, KitModel::purge() should be called before this method.

Definition at line 466 of file kitmodel.cpp.

References GuiState::is_deleted(), m_category_map, m_dirty, m_item_map, GuiState::reset(), and ModelCategory::reset().

Referenced by Service::create_default_model(), XmlDao::get_model(), and XmlDao::save_model().

◆ set_dirty()

virtual void KitModel::set_dirty ( bool  dirty = true)
inlinevirtual

◆ show_all()

virtual void KitModel::show_all ( )
inlinevirtual

Removes filter. All items are shown.

Definition at line 179 of file kitmodel.hpp.

References ALL.

Referenced by Service::show_all().

◆ show_checked_only()

virtual void KitModel::show_checked_only ( )
inlinevirtual

Sets the filter to show only checked items.

Definition at line 181 of file kitmodel.hpp.

References CHECKED.

Referenced by Service::show_checked_only().

◆ show_unchecked_only()

virtual void KitModel::show_unchecked_only ( )
inlinevirtual

Sets the filter to show only unchecked items.

Definition at line 183 of file kitmodel.hpp.

References GuiState::reset(), and UNCHECKED.

Referenced by Service::show_unchecked_only().

Member Data Documentation

◆ m_category_map

CategoryMap* KitModel::m_category_map
protected

Map allowing categories to be located by ID.

The map's key is the category ID, with the second field of the pair containing a pointer to the ModelCategory instance.

Definition at line 145 of file kitmodel.hpp.

Referenced by add_category(), find_category(), foreach_category(), foreach_category_iter(), get_categories(), KitModel(), purge(), reset(), and ~KitModel().

◆ m_dirty

bool KitModel::m_dirty
protected

Indicates whether the model needs saving. I.e it's state has changed.

Definition at line 138 of file kitmodel.hpp.

Referenced by reset().

◆ m_item_filter

enum item_filter_types KitModel::m_item_filter
protected

Indicates whether and how items are currently filtered.

One of ALL, CHECKED or UNCHECKED.

Definition at line 158 of file kitmodel.hpp.

Referenced by filter().

◆ m_item_map

ItemMap* KitModel::m_item_map
protected

Map allowing items to be located by ID.

The map's key is the item ID, with the second field of the pair containing a pointer to the ModelItem instance.

Definition at line 152 of file kitmodel.hpp.

Referenced by add_item(), find_item(), foreach_item(), foreach_item_iter(), get_all_items(), KitModel(), purge(), reset(), and ~KitModel().


The documentation for this class was generated from the following files:

Copyright 2008-2021 Frank Dean