#include <service.hpp>
Public Member Functions | |
Service (KitListDao &dao) | |
Loads the data model from the persistence store. | |
~Service () | |
ModelItem * | find_item (long id) |
ModelCategory * | find_category (long cat_id) |
void | copy_items (const ModelItemContainer &items, long cat_id) |
Copies items to the specified category. | |
Item * | create_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. | |
Category * | create_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. | |
ItemContainer * | get_items (long cat_id=-1) |
Returns a list of items. | |
ItemContainer * | get_filtered_items (long cat_id=-1) |
Returns a list of items, applying the current filter. | |
CategoryContainer * | get_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 | |
KitModel * | load_model () |
Loads the data model from the persistence store. | |
long | get_next_item_id () |
long | get_next_category_id () |
Protected Attributes | |
KitListDao & | m_dao |
Reference to the perisitence data access object. | |
KitModel * | m_model |
The application's data model. |
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.
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 | ( | ) |
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.
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.
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] |
Definition at line 55 of file service.hpp.
References KitModel::is_dirty(), and m_model.
Referenced by KitListGui::on_delete_event(), KitListGui::on_menu_file_new(), KitListGui::on_menu_file_open(), KitListGui::on_menu_quit(), KitListGui::on_menu_recent_file(), KitListGui::on_menu_save(), KitListGui::run(), and KitListGui::safe_open_file().
void Service::set_model_dirty | ( | bool | flag = true |
) |
Flags the model as being dirty.
Definition at line 264 of file service.cpp.
References m_model, and KitModel::set_dirty().
Referenced by KitListGui::close_add_category_window(), KitListGui::confirm_lose_changes(), KitListGui::init(), KitListGui::on_cell_edit(), KitListGui::on_delete_event(), KitListGui::on_menu_create_category(), KitListGui::on_menu_cut(), KitListGui::on_menu_quit(), KitListGui::on_menu_rename_category(), and KitListGui::on_row_changed().
virtual bool Service::filter | ( | bool | checked | ) | [inline, virtual] |
Applies the current filter.
checked | The checked/ticked state of the item being filtered. |
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.
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.
id | The unique ID of the item to update. | |
description | The item's descriptive text. | |
checked | The checked/ticked state of the item. |
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.
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.
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.
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.
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] |
Definition at line 80 of file service.hpp.
References m_dao, and KitListDao::require_filename().
Referenced by KitListGui::init(), KitListGui::on_menu_file_new(), and KitListGui::on_menu_save().
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 application's data model.
Definition at line 41 of file service.hpp.
Referenced by copy_items(), create_category(), create_default_model(), create_item(), delete_category(), delete_item(), filter(), find_category(), find_item(), get_categories(), get_filtered_items(), get_items(), is_model_dirty(), open_as_xml(), save(), save_as_xml(), select_items(), Service(), set_model_dirty(), show_all(), show_checked_only(), show_unchecked_only(), toggle_selected_items(), update_item(), and ~Service().