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

Business/service layer implementation. More...

#include <service.hpp>

Public Member Functions

 Service (KitListDao &dao)
 Loads the data model from the persistence store. More...
 
 ~Service ()
 
ModelItemfind_item (long id)
 
ModelCategoryfind_category (long cat_id)
 
void copy_items (const ModelItemContainer &items, long cat_id)
 Copies items to the specified category. More...
 
Itemcreate_item (long cat_id)
 Creates a new ModelItem and associates it with the specified category. More...
 
bool delete_item (long id)
 Flags an item as deleted. More...
 
bool delete_category (long cat_id)
 Flags a category as deleted. More...
 
Categorycreate_category ()
 Creates a new category. More...
 
bool is_model_dirty ()
 
void set_model_dirty (bool flag=true)
 
virtual bool filter (bool checked)
 Applies the current filter. More...
 
void create_default_model ()
 Creates a default model. More...
 
void open_as_xml (const Glib::ustring &filename)
 Loads a new data model from the named XML document. More...
 
void save ()
 
void save_as_xml (const Glib::ustring &filename)
 Saves the model's state to an XML document. More...
 
bool update_item (long id, const std::string description, bool checked)
 Updates the attributes of an item. More...
 
ItemContainerget_items (long cat_id=-1)
 Returns a list of items. More...
 
ItemContainerget_filtered_items (long cat_id=-1)
 Returns a list of items, applying the current filter. More...
 
CategoryContainerget_categories ()
 Returns a list of all categories. More...
 
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 select_items (ModelItemContainer *items, bool checked=true)
 Checks or unchecks all the passed items. More...
 
virtual void toggle_selected_items (ModelItemContainer *items)
 Toggles the checked state of all the passed items. More...
 
virtual bool require_filename ()
 

Protected Member Functions

KitModelload_model ()
 Loads the data model from the persistence store. More...
 
long get_next_item_id ()
 
long get_next_category_id ()
 

Protected Attributes

KitListDaom_dao
 Reference to the perisitence data access object. More...
 
KitModelm_model
 The application's data model. More...
 

Detailed Description

Business/service layer implementation.

Implements the service layer of the application, such that a different front-end can re-use the provided business methods.

Definition at line 38 of file service.hpp.

Constructor & Destructor Documentation

◆ Service()

Service::Service ( KitListDao dao)

Loads the data model from the persistence store.

Definition at line 44 of file service.cpp.

References load_model(), and m_model.

◆ ~Service()

Service::~Service ( )

Definition at line 49 of file service.cpp.

References m_model.

Member Function Documentation

◆ copy_items()

void Service::copy_items ( const ModelItemContainer items,
long  cat_id 
)

Copies items to the specified category.

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

Definition at line 144 of file service.cpp.

References KitModel::copy_items(), m_model, and KitModel::set_dirty().

Referenced by KitListGui::add_items().

◆ create_category()

Category * Service::create_category ( )

Creates a new category.

A new ModelCategory is created, assigned a new unique ID and added to the model.

Definition at line 220 of file service.cpp.

References KitModel::add_category(), get_next_category_id(), m_model, GuiState::set_dirty(), KitModel::set_dirty(), Category::set_id(), and GuiState::set_new_flag().

Referenced by KitListGui::close_add_category_window().

◆ create_default_model()

void Service::create_default_model ( )

Creates a default model.

By default, a new empty XmlDao data model is created.

Definition at line 83 of file service.cpp.

References KitListDao::get_model(), m_dao, m_model, and KitModel::reset().

Referenced by filter(), and KitListGui::on_menu_file_new().

◆ create_item()

Item * Service::create_item ( long  cat_id)

Creates a new ModelItem and associates it with the specified category.

A new item is created and assigned a new unique Id. The item is added to the data model and associated with a category if the cat_id is greater than or equal to zero. Otherwise the item is added to the model without being associated with a category.

Definition at line 159 of file service.cpp.

References KitModel::add_item(), get_next_item_id(), m_model, GuiState::set_dirty(), KitModel::set_dirty(), Item::set_id(), and GuiState::set_new_flag().

Referenced by KitListGui::close_add_item_window().

◆ delete_category()

bool Service::delete_category ( long  cat_id)

Flags a category as deleted.

Finds the category with the specified ID and flags it as deleted.

Returns
false if the category does not exist.

Definition at line 200 of file service.cpp.

References KitModel::find_category(), m_model, GuiState::set_deleted(), GuiState::set_dirty(), and KitModel::set_dirty().

Referenced by KitListGui::on_menu_delete_category().

◆ delete_item()

bool Service::delete_item ( long  id)

Flags an item as deleted.

Finds the item with the specified ID and flags it as deleted.

Returns
false if the item does not exist.

Definition at line 180 of file service.cpp.

References KitModel::find_item(), m_model, GuiState::set_deleted(), GuiState::set_dirty(), and KitModel::set_dirty().

Referenced by KitListGui::delete_selected_items(), and KitListGui::selected_row_callback().

◆ filter()

virtual bool Service::filter ( bool  checked)
inlinevirtual

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 63 of file service.hpp.

References create_default_model(), KitModel::filter(), get_categories(), get_filtered_items(), get_items(), open_as_xml(), save(), save_as_xml(), and update_item().

Referenced by KitListGui::refresh_item_list().

◆ find_category()

ModelCategory * Service::find_category ( long  cat_id)

Returns the category with the specified unique ID.

Definition at line 133 of file service.cpp.

References KitModel::find_category(), and m_model.

Referenced by KitListGui::close_add_category_window(), KitListGui::on_menu_cut(), and KitListGui::on_menu_rename_category().

◆ find_item()

ModelItem * Service::find_item ( long  id)

Returns the item with the specified unique ID.

Definition at line 125 of file service.cpp.

References KitModel::find_item(), and m_model.

Referenced by KitListGui::get_selected_items(), and KitListGui::paste_from_xml().

◆ get_categories()

CategoryContainer * Service::get_categories ( )

Returns a list of all categories.

Categories flagged as deleted are excluded.

Definition at line 354 of file service.cpp.

References KitModel::get_categories(), and m_model.

Referenced by filter(), and KitListGui::refresh_category_list().

◆ get_filtered_items()

ItemContainer * Service::get_filtered_items ( long  cat_id = -1)

Returns a list of items, applying the current filter.

The returned list is also sorted by item name.

If cat_id is less than zero, returns all items, otherwise only those items associated with the specified category ID.

Parameters
cat_idthe unique ID of a category or '-1' to indicate all items are to be retrieved.

Definition at line 331 of file service.cpp.

References KitModel::find_category(), KitModel::get_all_items(), ModelCategory::get_items(), and m_model.

Referenced by filter(), KitListGui::on_menu_export_to_pdf(), and KitListGui::on_menu_print().

◆ get_items()

ItemContainer * Service::get_items ( long  cat_id = -1)

Returns a list of items.

If cat_id is less than zero, returns all items, otherwise only those items associated with the specified category ID.

Parameters
cat_idthe unique ID of a category or '-1' to indicate all items are to be retrieved.

Definition at line 305 of file service.cpp.

References KitModel::find_category(), KitModel::get_all_items(), ModelCategory::get_items(), and m_model.

Referenced by filter(), KitListGui::init(), and KitListGui::refresh_item_list().

◆ get_next_category_id()

long Service::get_next_category_id ( )
protected

Returns an unused unique id for a Category.

Definition at line 372 of file service.cpp.

References KitListDao::get_next_category_id(), and m_dao.

Referenced by create_category().

◆ get_next_item_id()

long Service::get_next_item_id ( )
protected

Returns an unused unique id for an Item.

Definition at line 364 of file service.cpp.

References KitListDao::get_next_item_id(), and m_dao.

Referenced by create_item().

◆ is_model_dirty()

bool Service::is_model_dirty ( )
inline

◆ load_model()

KitModel * Service::load_model ( )
protected

Loads the data model from the persistence store.

Definition at line 58 of file service.cpp.

References KitListDao::get_model(), and m_dao.

Referenced by Service().

◆ open_as_xml()

void Service::open_as_xml ( const Glib::ustring &  filename)

Loads a new data model from the named XML document.

Creates a new data model based on the passed filename. The existing data model is destroyed after successfully loading the new one.

Definition at line 70 of file service.cpp.

References m_dao, and m_model.

Referenced by filter(), KitListGui::init(), KitListGui::on_menu_recent_file(), and KitListGui::open_file().

◆ require_filename()

virtual bool Service::require_filename ( )
inlinevirtual

◆ save()

void Service::save ( )

Saves the model's state to the persistence store.

Definition at line 98 of file service.cpp.

References m_dao, m_model, and KitListDao::save_model().

Referenced by KitListGui::confirm_lose_changes(), filter(), and KitListGui::on_menu_save().

◆ save_as_xml()

void Service::save_as_xml ( const Glib::ustring &  filename)

Saves the model's state to an XML document.

This is primarily intended to support switching from one dao implementation to the XmlDao implemenation.

Parameters
filenameThe full pathname and filename to save the file to.

Definition at line 111 of file service.cpp.

References m_dao, m_model, and XmlDao::save_model().

Referenced by KitListGui::confirm_lose_changes(), filter(), KitListGui::on_menu_save(), and KitListGui::on_menu_save_as().

◆ select_items()

void Service::select_items ( ModelItemContainer items,
bool  checked = true 
)
virtual

Checks or unchecks all the passed items.

Parameters
itemsThe items to change. the state to change the to.

Definition at line 238 of file service.cpp.

References m_model, and KitModel::set_dirty().

Referenced by KitListGui::set_selected(), and show_unchecked_only().

◆ set_model_dirty()

void Service::set_model_dirty ( bool  flag = true)

◆ show_all()

virtual void Service::show_all ( )
inlinevirtual

Removes filter. All items are shown.

Definition at line 73 of file service.hpp.

References KitModel::show_all().

Referenced by KitListGui::on_menu_show_all().

◆ show_checked_only()

virtual void Service::show_checked_only ( )
inlinevirtual

Sets the filter to show only checked items.

Definition at line 75 of file service.hpp.

References KitModel::show_checked_only().

Referenced by KitListGui::on_menu_show_checked().

◆ show_unchecked_only()

virtual void Service::show_unchecked_only ( )
inlinevirtual

Sets the filter to show only unchecked items.

Definition at line 77 of file service.hpp.

References select_items(), KitModel::show_unchecked_only(), and toggle_selected_items().

Referenced by KitListGui::on_menu_show_unchecked().

◆ toggle_selected_items()

void Service::toggle_selected_items ( ModelItemContainer items)
virtual

Toggles the checked state of all the passed items.

Parameters
itemsThe items to change.

Definition at line 252 of file service.cpp.

References m_model, and KitModel::set_dirty().

Referenced by show_unchecked_only(), and KitListGui::toggle_selected().

◆ update_item()

bool Service::update_item ( long  id,
const std::string  description,
bool  checked 
)

Updates the attributes of an item.

Locates the item using the supplied unique ID, then assigns the passed values.

Parameters
idThe unique ID of the item to update.
descriptionThe item's descriptive text.
checkedThe checked/ticked state of the item.
Returns
Returns true if the item exists, false otherwise.

Definition at line 282 of file service.cpp.

References KitModel::find_item(), m_model, ModelItem::set_checked(), Item::set_description(), and GuiState::set_dirty().

Referenced by filter(), and KitListGui::on_row_changed().

Member Data Documentation

◆ m_dao

KitListDao& Service::m_dao
protected

Reference to the perisitence data access object.

Definition at line 40 of file service.hpp.

Referenced by create_default_model(), get_next_category_id(), get_next_item_id(), load_model(), open_as_xml(), save(), and save_as_xml().

◆ m_model

KitModel* Service::m_model
protected

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

Copyright 2008-2021 Frank Dean