49 if (m_filename.size() > 0) {
51 parser.set_validate();
52 parser.set_substitute_entities();
53 parser.parse_file(m_filename);
58 if (i != items->end()) {
59 Item* max_item = (*i);
60 m_max_item_id = max_item->
get_id();
67 if (cat != categories->end()) {
69 m_max_category_id = max_category->
get_id();
71 m_max_category_id = -1;
75 }
catch (
const xmlpp::exception& ex) {
76 std::cout <<
"libxml++ exception: " << ex.what() << std::endl;
88 assert(m_items_node != NULL);
90 xmlpp::Element* itemNode = m_items_node->add_child(
"item");
93 itemNode->set_attribute(
"id", os.str());
94 itemNode->set_attribute(
"checked", item.
get_checked() ?
"true" :
"false");
107 assert(m_cat_items_node != NULL);
109 xmlpp::Element* itemNode = m_cat_items_node->add_child(
"category-item");
112 itemNode->set_attribute(
"id", os.str());
124 assert(m_categories_node != NULL);
126 xmlpp::Element* catNode = m_categories_node->add_child(
"category");
129 catNode->set_attribute(
"id", os.str());
130 xmlpp::Element* catNameNode = catNode->add_child(
"category-name");
131 catNameNode->set_child_text(category.
get_name());
132 m_cat_items_node = catNode->add_child(
"category-items");
143 return ++m_max_item_id;
151 return ++m_max_category_id;
164 xmlpp::Document document;
165 xmlpp::Element* rootNode = document.create_root_node(
"kitlist");
166 m_items_node = rootNode->add_child(
"items");
168 m_categories_node = rootNode->add_child(
"categories");
170 document.write_to_file_formatted(m_filename);
long get_next_category_id()
Represents a Category combined with GuiState attributes.
SaxParser implementation for reading the KitModel from an XML document.
ItemContainer::iterator ItemIter
bool add_category_item_to_dom(Item &item)
Adds the passed item to the current category's node.
CategoryContainer::iterator CategoryIter
void foreach_category(const SlotForeachCategory &slot)
Calls the provided slot for each category in the map.
Comparator used for comparing Items by id.
std::vector< Item * > ItemContainer
void foreach_item(const SlotForeachItem &slot)
Executes a callback function for each associated item.
void save_model(KitModel *model)
Saves the model as an XML document.
KitModel * get_model()
Loads the data model from the previously set filename.
bool add_item_to_dom(ModelItem &item)
Adds the passed item to the current items' node.
virtual ItemContainer * get_all_items()
Returns a list of all items.
bool add_category_to_dom(ModelCategory &item)
Adds the passed item to the current categories' node.
std::string get_description()
Represents an Item combined with GuiState attributes.
Holds a rich graph of objects representing the application's data model.
virtual CategoryContainer * get_categories()
Returns a list of all categories.
void foreach_item(const SlotForeachModelItem &slot)
Calls the provided slot for each item in the map.
std::vector< Category * > CategoryContainer
virtual void purge()
Purges deleted categories and items from the model.
virtual void reset()
Resets all contained objects to their default states.
long get_next_item_id()
Returns the next unused unique id for items.
Comparator used for comparing Categories by id.