diff --git a/src/application/xqchildmodel.cpp b/src/application/xqchildmodel.cpp index e97bf05..afd6e07 100644 --- a/src/application/xqchildmodel.cpp +++ b/src/application/xqchildmodel.cpp @@ -33,7 +33,7 @@ XQChildModel::XQChildModel( QObject *parent ) //! erzegt den sichtbaren inhalt des models aus einem root-datenknoten. -void XQChildModel::setContent( const XQNodePtr& contentRoot ) +void XQChildModel::addModelData( const XQNodePtr& contentRoot ) { // __fix: set object name ?? @@ -59,6 +59,9 @@ void XQChildModel::setContent( const XQNodePtr& contentRoot ) // wir speichern das parent des datenknoten auch in der // section. // contentEntry->parent == _contentRoot, aber halt nur weil das model flach ist + + qDebug() << " --- add section ENTRY: " << key << " TagName: " << contentEntry->attribute("TagName"); + section.setContentRootNode( contentEntry->parent() ); int newRow = _sections.lastRow(section); @@ -73,6 +76,18 @@ void XQChildModel::setContent( const XQNodePtr& contentRoot ) } +void XQChildModel::addSectionEntry( const QString& key, const XQNodePtr& contentEntry ) +{ + XQModelSection& section = _sections.at( key ); + if(section.isValid() ) + { + section.setContentRootNode( contentEntry->parent() ); + int newRow = _sections.lastRow(section); + XQNodePtr sheetNode = section.sheetRootNode(); + XQItemList list = _itemFactory.makeRow( sheetNode, contentEntry ); + insertRow( newRow, list); + } +} //! erzeugt ein adhoc-contextmenu, je nachdem welche aktionen gerade möflich sind. diff --git a/src/application/xqchildmodel.h b/src/application/xqchildmodel.h index 2e0681c..d98d88e 100644 --- a/src/application/xqchildmodel.h +++ b/src/application/xqchildmodel.h @@ -29,7 +29,8 @@ public: explicit XQChildModel(QObject *parent = nullptr); virtual ~XQChildModel() = default; - void setContent(const XQNodePtr& contentRoot ); + void addModelData(const XQNodePtr& contentRoot ); + void addSectionEntry(const QString& key, const XQNodePtr& contentEntry ); protected: diff --git a/src/application/xqmainwindow.cpp b/src/application/xqmainwindow.cpp index bb28680..381530c 100644 --- a/src/application/xqmainwindow.cpp +++ b/src/application/xqmainwindow.cpp @@ -355,7 +355,7 @@ void XQMainWindow::loadDocument( const QString& fileName ) childModel->initModel( c_ChildModelName ); // model inhalte laden - childModel->setContent( contentRoot->first_child() ); + childModel->addModelData( contentRoot->first_child() ); } diff --git a/src/items/xqitem.h b/src/items/xqitem.h index c7dfb91..3ae92cb 100644 --- a/src/items/xqitem.h +++ b/src/items/xqitem.h @@ -201,13 +201,13 @@ public: void setData(const QVariant &value, int role ) override; /* - template + template void setToVariant(T entry, QtExtUserRoles::NTDataRoles role) { setData(QVariant::fromValue(entry), role); } - template + template T getFromVariant(QtExtUserRoles::NTDataRoles role) { return data(role).value(); diff --git a/src/model/xqnode.cpp b/src/model/xqnode.cpp index 3700eb1..2a87506 100644 --- a/src/model/xqnode.cpp +++ b/src/model/xqnode.cpp @@ -79,6 +79,9 @@ bool znode::zpayload::xstr_is_empty(const QString& entry ) const //! 'QString' varianten der keystrings. +template<> +const QString znode::zpayload::cTagName = "TagName"; + template<> const QString znode::zpayload::cType = "Type"; diff --git a/src/model/xqviewmodel.cpp b/src/model/xqviewmodel.cpp index 2677d05..04cff4b 100644 --- a/src/model/xqviewmodel.cpp +++ b/src/model/xqviewmodel.cpp @@ -98,6 +98,9 @@ void XQViewModel::initModel(const QString& modelName) ... */ + setObjectName( modelName ); + qDebug() << " --- initModel: " << objectName(); + // model rootnode finden -> XQNodePtr modelSheet = _itemFactory.findModelSheet( modelName ); // throws @@ -108,11 +111,9 @@ void XQViewModel::initModel(const QString& modelName) const XQNodePtr header = sectionNode->find_child_by_tag_name( c_Header ); if( header ) { - XQItemList list = _itemFactory.makeRow( header, nullptr ); addSection(list, sectionNode ); } - } } @@ -385,6 +386,9 @@ void XQViewModel::cmdPaste( XQCommand& command ) // wir pasten das clipboard for (auto& entry : _clipBoard ) { + + // WARUM zwei mal klonen ? + // noch ein clone vom clone erzeugen ... XQNodePtr newNode = entry.contentNode->clone(section.contentRootNode() ); newNode->clone(section.contentRootNode() )->add_me_at( nodePos ); diff --git a/src/nodes/znode.h b/src/nodes/znode.h index 199034f..06d4403 100644 --- a/src/nodes/znode.h +++ b/src/nodes/znode.h @@ -43,16 +43,16 @@ namespace znode // forward declaration of base class zbasic_node ... - //template + //template //class zbasic_node; // ... used here for conveniance typedef - //template + //template //using zshared_node = std::shared_ptr>; //! einfache tree-klasse, besonderheit: der nutzlast-string-type ist templated. - template + template class zbasic_node : public zid, public zpayload, public std::enable_shared_from_this> { @@ -400,7 +400,7 @@ namespace znode virtual void begin() {} - template + template void for_each_node( zbasic_node* node ); virtual void end() diff --git a/src/nodes/znode_factory.h b/src/nodes/znode_factory.h index aa98748..9c1cb2f 100644 --- a/src/nodes/znode_factory.h +++ b/src/nodes/znode_factory.h @@ -40,7 +40,7 @@ model: muss ich wirklich jeden attibute node einzeln angeben? */ namespace znode { - template + template class znode_factory { diff --git a/src/nodes/znode_iterator.h b/src/nodes/znode_iterator.h index 314f642..a13e1ad 100644 --- a/src/nodes/znode_iterator.h +++ b/src/nodes/znode_iterator.h @@ -21,7 +21,7 @@ namespace znode { - template + template struct znode_iterator { using iterator_category = std::forward_iterator_tag; diff --git a/src/nodes/znode_payload.h b/src/nodes/znode_payload.h index 2253d23..2e1f87b 100644 --- a/src/nodes/znode_payload.h +++ b/src/nodes/znode_payload.h @@ -9,7 +9,7 @@ namespace znode { - template + template class zstringmap : public std::map { @@ -38,7 +38,7 @@ namespace znode }; - template + template class zpayload { @@ -52,7 +52,10 @@ namespace znode // __fixme: should this be a vector? or a maptor? //using zattributes = std::map; using zattributes = zstringmap; + using callmap_ref = std::map::*)() const>; + using callmap_ptr = std::map::*)() const>; + static const str_t cTagName; // = "TagName"; static const str_t cType;// = "Type"; static const str_t cName;// = "Name"; static const str_t cValue;// = "Value"; @@ -188,6 +191,22 @@ namespace znode return true; } + const zvalue& fixed_attribute(str_cref key ) const + { + + static callmap_ref s_fixed_attributes + { + { cTagName, &zpayload::tag_name }, + { cValue, &zpayload::tag_value } + }; + + auto it = s_fixed_attributes.find(key); + if (it != s_fixed_attributes.end()) + return (this->*(it->second))(); + + return s_dummy_value; + } + const zvalue& attribute(str_cref key ) const { if( !xstr_is_empty( key ) ) @@ -201,7 +220,24 @@ namespace znode return result; } } - return s_dummy_value; + //return s_dummy_value; + return fixed_attribute( key ); + } + + + const zvalue& fixed_attribute_ptr(str_cref key ) const + { + static callmap_ptr s_fixed_attributes_ptr + { + { cTagName, &zpayload::tag_name_ptr }, + { cValue, &zpayload::tag_value_ptr } + }; + + auto it = s_fixed_attributes_ptr.find(key); + if (it != s_fixed_attributes_ptr.end() ) + (this->*(it->second))(); + + return &s_dummy_value; } const zvalue* attribute_ptr(str_cref key ) const @@ -217,6 +253,7 @@ namespace znode return &result; } } + //return fixed_attribute_ptr( key ); return &s_dummy_value; } @@ -259,7 +296,7 @@ namespace znode }; // init statics - template + template str_t zpayload::s_dummy_value; } diff --git a/src/nodes/znode_vector.h b/src/nodes/znode_vector.h index c6179b6..34ab96f 100644 --- a/src/nodes/znode_vector.h +++ b/src/nodes/znode_vector.h @@ -6,7 +6,7 @@ //using znode_vector = std::vector; -template +template class znode_vector : public std::vector { diff --git a/src/util/xqmaptor.h b/src/util/xqmaptor.h index 41569b4..5435868 100644 --- a/src/util/xqmaptor.h +++ b/src/util/xqmaptor.h @@ -24,7 +24,7 @@ * items can be accessed via string keys and int indices. */ -template +template class XQMaptor { diff --git a/src/util/xqptrmaptor.h b/src/util/xqptrmaptor.h index d35a139..e8ee872 100644 --- a/src/util/xqptrmaptor.h +++ b/src/util/xqptrmaptor.h @@ -21,7 +21,7 @@ * @brief A XQMaptor implementation for pointers to to data entries. */ -template +template class XQPtrMaptor : public XQMaptor { diff --git a/xml/modelsheets.xml b/xml/modelsheets.xml index f92974c..1c5dbf5 100644 --- a/xml/modelsheets.xml +++ b/xml/modelsheets.xml @@ -59,8 +59,8 @@ -
-
+
+
@@ -71,7 +71,7 @@
- + @@ -87,8 +87,8 @@
-
-
+
+
@@ -97,7 +97,7 @@
- + @@ -108,8 +108,8 @@
-
-
+
+
@@ -118,7 +118,7 @@
- + @@ -129,7 +129,4 @@
- - - \ No newline at end of file