Service Class Reference

Business/service layer implementation. More...

#include <service.hpp>

List of all members.

Public Member Functions

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

Protected Member Functions

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

Protected Attributes

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


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 ( 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 (  ) 

Definition at line 49 of file service.cpp.

References m_model.


Member Function Documentation

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().

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().

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().

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().

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().

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().

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(), and KitListGui::on_menu_add().

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().

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().

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(), and KitListGui::on_menu_create_category().

bool Service::is_model_dirty (  )  [inline]

void Service::set_model_dirty ( bool  flag = true  ) 

virtual bool Service::filter ( bool  checked  )  [inline, virtual]

Applies the current filter.

Parameters:
checked The 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 KitModel::filter(), and m_model.

Referenced by KitListGui::refresh_item_list().

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 KitListGui::on_menu_file_new().

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 KitListGui::init(), KitListGui::on_menu_recent_file(), and KitListGui::open_file().

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(), and KitListGui::on_menu_save().

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:
filename The 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(), KitListGui::on_menu_save(), KitListGui::on_menu_save_as(), and KitListGui::run().

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:
id The unique ID of the item to update.
description The item's descriptive text.
checked The 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 KitListGui::on_row_changed().

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_id the 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 KitListGui::init(), and KitListGui::refresh_item_list().

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_id the 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 KitListGui::on_menu_export_to_pdf(), and KitListGui::on_menu_print().

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 KitListGui::refresh_category_list().

virtual void Service::show_all (  )  [inline, virtual]

Removes filter. All items are shown.

Definition at line 73 of file service.hpp.

References m_model, and KitModel::show_all().

Referenced by KitListGui::on_menu_show_all().

virtual void Service::show_checked_only (  )  [inline, virtual]

Sets the filter to show only checked items.

Definition at line 75 of file service.hpp.

References m_model, and KitModel::show_checked_only().

Referenced by KitListGui::on_menu_show_checked().

virtual void Service::show_unchecked_only (  )  [inline, virtual]

Sets the filter to show only unchecked items.

Definition at line 77 of file service.hpp.

References m_model, and KitModel::show_unchecked_only().

Referenced by KitListGui::on_menu_show_unchecked().

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

Checks or unchecks all the passed items.

Parameters:
items The 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().

void Service::toggle_selected_items ( ModelItemContainer items  )  [virtual]

Toggles the checked state of all the passed items.

Parameters:
items The items to change.

Definition at line 252 of file service.cpp.

References m_model, and KitModel::set_dirty().

Referenced by KitListGui::toggle_selected().

virtual bool Service::require_filename (  )  [inline, virtual]


Member Data Documentation

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(), require_filename(), save(), and save_as_xml().

KitModel* Service::m_model [protected]


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

Copyright 2008-2010 Frank Dean