diff --git a/src/application/xqchildmodel.cpp b/src/application/xqchildmodel.cpp index 0157aa2..2a4aaff 100644 --- a/src/application/xqchildmodel.cpp +++ b/src/application/xqchildmodel.cpp @@ -31,6 +31,22 @@ XQChildModel::XQChildModel( QObject *parent ) } + +//! Erzeugt eine model-section und fügt den zugehörigen header ein. + +void XQChildModel::addSectionEntry( const QString& key, const XQNodePtr& contentEntry ) +{ + const XQModelSection& section = _sections.sectionByKey( key ); + if(section.isValid() ) + { + section.setContentRootNode( contentEntry->parent() ); + int newRow =_sections.lastRow(section); + XQNodePtr sheetNode = section.sheetRootNode(); + XQItemList list = _itemFactory.makeRow( sheetNode, nullptr ); + insertRow( newRow, list); + } +} + //! erzegt den sichtbaren inhalt des models aus einem root-datenknoten. void XQChildModel::addModelData( const XQNodePtr& contentRoot ) @@ -46,7 +62,6 @@ void XQChildModel::addModelData( const XQNodePtr& contentRoot ) // Das ist hier der Typ des Eintrags: Panel, Battery ... QString key = contentEntry->tag_name(); - // 'silent failure' hier der Datenbaum kann auch Knoten enthalten // die nicht für uns gedacht sind. if (!_sections.hasValidSection(key)) @@ -69,28 +84,28 @@ void XQChildModel::addModelData( const XQNodePtr& contentRoot ) { qDebug() << " --- AddModelData: CHILD Found for: :" << contentEntry->tag_name() << " sheet parent: " << sheetNode->tag_name(); if( !sheetNode->has_children() ) - qDebug() << " --- AUA"; - //else + { + qDebug() << " --- no sheet node for children"; + continue; + }Sehr geehrte Frau Hollerbaum, + + Derzeit in Festanstellung, kann mir aber bin aber offen + + Mein Fachgebiet ist Qt ma + addSectionChildren( list.front(), sheetNode, contentEntry ); } } // for } - -//! Erzeugt eine model-section und fügt den zugehörigen header ein. - -void XQChildModel::addSectionEntry( const QString& key, const XQNodePtr& contentEntry ) +void XQChildModel::addSectionChildren( QStandardItem* parent, const XQNodePtr& sheetEntry, const XQNodePtr& contentRoot ) { - const XQModelSection& section = _sections.sectionByKey( key ); - if(section.isValid() ) + for (const auto& contentEntry : contentRoot->children()) { - section.setContentRootNode( contentEntry->parent() ); - int newRow =_sections.lastRow(section); - XQNodePtr sheetNode = section.sheetRootNode(); - XQItemList list = _itemFactory.makeRow( sheetNode, nullptr ); - insertRow( newRow, list); + } + } diff --git a/src/application/xqchildmodel.h b/src/application/xqchildmodel.h index d98d88e..c02f3ea 100644 --- a/src/application/xqchildmodel.h +++ b/src/application/xqchildmodel.h @@ -30,7 +30,8 @@ public: virtual ~XQChildModel() = default; void addModelData(const XQNodePtr& contentRoot ); - void addSectionEntry(const QString& key, const XQNodePtr& contentEntry ); + void addSectionEntry( const QString& key, const XQNodePtr& contentEntry ); + void addSectionChildren( QStandardItem* parent, const XQNodePtr& sheetEntry, const XQNodePtr& contentEntry ); protected: diff --git a/src/application/xqmainmodel.cpp b/src/application/xqmainmodel.cpp index 479e5d8..b554425 100644 --- a/src/application/xqmainmodel.cpp +++ b/src/application/xqmainmodel.cpp @@ -71,7 +71,7 @@ XQItem* XQMainModel::addProjectItem( XQNodePtr contentNode ) void XQMainModel::addSectionItem( const XQModelSection& section, XQItem* projectItem ) { - XQNodePtr sheetNode = projectItem->sheetNode()->find_child_by_tag_name("CurrentSection"); + XQNodePtr sheetNode = projectItem->sheetNode()->child("CurrentSection"); XQItem* newItem = _itemFactory.makeSingleItem( sheetNode, section.contentType() ); projectItem->appendRow( newItem ); expandNewItem(projectItem->index() ); diff --git a/src/items/xqitemfactory.cpp b/src/items/xqitemfactory.cpp index 0135389..acdf223 100644 --- a/src/items/xqitemfactory.cpp +++ b/src/items/xqitemfactory.cpp @@ -42,7 +42,7 @@ void XQItemFactory::initItemFactory( const QString& modelSheetFileName ) throw XQException("modelSheet load failed. ", modelSheetFileName); // schritt #3: itemtype beschreibungen laden ... - _typesSheet = _modelSheet->find_child_by_tag_name( "ItemTypes" ); + _typesSheet = _modelSheet->child( "ItemTypes" ); // ... und testen if( !_typesSheet ) throw XQException( "initItemFactory is null" ); @@ -114,7 +114,7 @@ XQItemType* XQItemFactory::findItemTypeTemplate(const QString& key ) const XQNodePtr XQItemFactory::findModelSheet( const QString& modelName ) const { - XQNodePtr modelSheet = _modelSheet->find_child_by_tag_name( modelName ); + XQNodePtr modelSheet = _modelSheet->child( modelName ); if( !modelSheet ) throw XQException( "model sheet not found: ", modelName ); diff --git a/src/model/xqsectionmanager.cpp b/src/model/xqsectionmanager.cpp index b0c0ad9..304d7d7 100644 --- a/src/model/xqsectionmanager.cpp +++ b/src/model/xqsectionmanager.cpp @@ -60,7 +60,7 @@ XQNodePtr XQModelSection::sectionRootNode() const XQNodePtr XQModelSection::sheetRootNode() const { - return _sectionSheetRootNode->find_child_by_tag_name( c_ModelSheet ); + return _sectionSheetRootNode->child( c_ModelSheet ); } diff --git a/src/model/xqviewmodel.cpp b/src/model/xqviewmodel.cpp index 8c5a2ad..99262aa 100644 --- a/src/model/xqviewmodel.cpp +++ b/src/model/xqviewmodel.cpp @@ -139,7 +139,7 @@ void XQViewModel::initModel(const QString& modelName) for( auto& sectionNode : modelSheet->children() ) { // #2: (optionalen?) header erzeugen - const XQNodePtr header = sectionNode->find_child_by_tag_name( c_Header ); + const XQNodePtr header = sectionNode->child( c_Header ); if( header ) { XQItemList list = _itemFactory.makeRow( header, nullptr ); diff --git a/src/nodes/znode.h b/src/nodes/znode.h index 6ada81a..98e1fe1 100644 --- a/src/nodes/znode.h +++ b/src/nodes/znode.h @@ -206,6 +206,12 @@ namespace znode return !children().empty(); } + //! testet, ob kinder vorhanden sind. + bool has_child(str_cref tagname ) const + { + return child(tagname ) != nullptr; + } + //! gibt das erste kind zurück zshared_node first_child() { @@ -229,6 +235,17 @@ namespace znode return nullptr; } + // + zshared_node child(str_cref tagname ) const + { + for( auto child : _children ) + { + if( child->tag_name() == tagname ) + return child; + } + return nullptr; + } + //! hängt einen knoten an meine kinderliste an. int add_child( const zshared_node& node ) { @@ -313,7 +330,7 @@ namespace znode //! findet den ersten kind-knoten mit dem attribut 'attrkey' welches den //! wert 'attrvalue' hat. - zshared_node find_child_by_attribute(str_cref attrkey, str_cref attrvalue ) + zshared_node find_child_by_attribute(str_cref attrkey, str_cref attrvalue ) const { for( auto child : _children ) { @@ -323,18 +340,9 @@ namespace znode return nullptr; } - // - zshared_node find_child_by_tag_name(str_cref tagname ) - { - for( auto child : _children ) - { - if( child->tag_name() == tagname ) - return child; - } - return nullptr; - } - zshared_node find_child_by_id( int id ) + + zshared_node find_child_by_id( int id ) const { for (auto child : _children ) { diff --git a/src/pugixml/pugixml.hpp b/src/pugixml/pugixml.hpp index 954851b..2dee653 100644 --- a/src/pugixml/pugixml.hpp +++ b/src/pugixml/pugixml.hpp @@ -630,7 +630,7 @@ namespace pugi } // Find child node using predicate. Returns first child for which predicate returned true. - template xml_node find_child_by_tag_name(Predicate pred) const + template xml_node child(Predicate pred) const { if (!_root) return xml_node(); diff --git a/xml/modeldata1.xtr b/xml/modeldata1.xtr index 4a15fda..4788f91 100644 --- a/xml/modeldata1.xtr +++ b/xml/modeldata1.xtr @@ -16,7 +16,8 @@ - + + diff --git a/xml/modelsheets.xml b/xml/modelsheets.xml index 62de50f..6e95e94 100644 --- a/xml/modelsheets.xml +++ b/xml/modelsheets.xml @@ -119,23 +119,28 @@ - + + + + + + + + + + + + + + + - - - + - - - - - - - - +