From d6ccac1d85efa15d7e69e474ec1dc90044d82785 Mon Sep 17 00:00:00 2001 From: "PANIK\\chris" Date: Thu, 4 Sep 2025 18:10:14 +0200 Subject: [PATCH] Fixed ::setData, part I --- src/items/xqitem.cpp | 15 ++++---- src/model/xqviewmodel.cpp | 5 +-- src/nodes/znode.h | 75 +++++---------------------------------- xml/saved_testfile.xtr | 1 - 4 files changed, 18 insertions(+), 78 deletions(-) diff --git a/src/items/xqitem.cpp b/src/items/xqitem.cpp index e91cde8..6642c3f 100644 --- a/src/items/xqitem.cpp +++ b/src/items/xqitem.cpp @@ -613,18 +613,21 @@ void XQItem::setData(const QVariant& value, int role ) case Qt::EditRole: case XQItem::ContentRole: { - QVariant plainText; + QVariant newValue; if( itemType().renderStyle() == XQItem::FormattedStyle) - plainText = XQItemType::unFormatFromSI( value.toString() ); + newValue = XQItemType::unFormatFromSI( value.toString() ); else - plainText = value; + newValue = value; // fallback: wenns keinen content node gibt, dann nehmen wir // das standardverfahren. - int role = XQItem::ContentRole; if( !hasContentPtr() ) - role = Qt::DisplayRole; - QStandardItem::setData( plainText, role ); + return QStandardItem::setData( newValue, XQItem::ContentRole ); + + // wir nehmen den string pointer + const QString* contentPtr = QStandardItem::data( XQItem::ContentRole ).value(); + //Q_ASSERT(contentPtr); + *contentPtr = newValue.toString(); return; } diff --git a/src/model/xqviewmodel.cpp b/src/model/xqviewmodel.cpp index 0eaf106..abea403 100644 --- a/src/model/xqviewmodel.cpp +++ b/src/model/xqviewmodel.cpp @@ -465,10 +465,7 @@ void XQViewModel::cmdNew( const XQCommand& command ) XQItem& target = xqItemFromIndex( origin ); // current data node XQNodePtr node = target.contentNode(); - - qDebug() << " --- node own pos: " << node->own_pos(); - - // we create a new data node + // we create a new data node XQNodePtr newNode = XQNode::make_node( node->tag_name(), node->tag_value() ); // store node in node->parent() newNode->add_me_at( node->own_pos(), node->parent() ); diff --git a/src/nodes/znode.h b/src/nodes/znode.h index 7aeb6d0..bbc5226 100644 --- a/src/nodes/znode.h +++ b/src/nodes/znode.h @@ -241,7 +241,6 @@ namespace znode int add_child_at( int idx, const zshared_node& node ) { // _fixme! was ist, wenn da schon ein elternknoten ist? - _children.insert(children().begin() + idx, node ); node->_parent = this->shared_from_this(); return int(children().size() - 1); @@ -254,10 +253,9 @@ namespace znode parent()->add_child_at( offset, this->shared_from_this() ); else throw std::runtime_error("add_me_at(offset): no parent node"); - } - //! fügt einen shard_ptr von 'mir' in die kinderliste des übergebenen knotens ein + //! fügt einen shared_ptr von 'mir' in die kinderliste des übergebenen knotens ein //! und macht diesen zu meinem elternknoten. void add_me_at( int offset, const zshared_node& parent_node ) { @@ -270,18 +268,17 @@ namespace znode { throw std::runtime_error("add_me_at(offset,parent): no parent node"); } - - } + + //! findet die eigene position im eltern-knoten int own_pos() { if( parent()) return parent()->child_pos( this->shared_from_this() ); return -1; - } - //int child_pos(zbasic_node* child) + //! findet die postion eines kind-knotens int child_pos(const zshared_node& child) { //auto pos = std::find_if(children().begin(), children().end(), match_node(child) ); @@ -291,7 +288,7 @@ namespace znode return -1; } - //zshared_node unlink_child( zbasic_node* node ) + //! findet die postion eines kind-knotens zshared_node unlink_child( const zshared_node& node ) { auto it = std::find(_children.begin(), _children.end(), node); @@ -319,11 +316,10 @@ namespace znode { for( auto child : _children ) { - qDebug() << " --#- " << child->name() << " : " << child->has_attribute( attrkey, attrvalue ); if( child->has_attribute( attrkey, attrvalue )) return child; } - return zshared_node(); + return nullptr; } // @@ -334,7 +330,7 @@ namespace znode if( child->tag_name() == tagname ) return child; } - return zshared_node(); + return nullptr; } zshared_node find_child_by_id( int id ) @@ -344,46 +340,7 @@ namespace znode if (child->_id == id) return child; } - return zshared_node(); - } - - - - void dump(int indent = 0) const - { - - // fix_me! - qDebug() << std::string(indent * 2, ' ').c_str() << this->to_string(); - //qDebug() << to_string(); - //qDebug() << '\n';// std::endl; - - if (!children().empty()) - { - for (auto child : _children) - { - //qDebug() << " --- type: " << typeid(child).name(); - child.get()->dump( indent + 1 ); - } - } - - } - - template - bool for_each_x( T func, int depth = 0 ) - //bool for_each( auto func ) const - { - if( !apply( func, depth ) ) - return false; - - if( !children().empty() ) - { - for( auto child : _children ) - { - if( !child->for_each( func, depth+1 ) ) - return false; - } - } - return true; + return nullptr; } // find ... @@ -396,22 +353,6 @@ namespace znode }; - - class zbasic_node_walker - { - public: - - virtual void begin() - {} - - template - void for_each_node( zbasic_node* node ); - - virtual void end() - {} - - }; - } //namespace znode diff --git a/xml/saved_testfile.xtr b/xml/saved_testfile.xtr index 01a0f34..ac8e3ef 100644 --- a/xml/saved_testfile.xtr +++ b/xml/saved_testfile.xtr @@ -2,7 +2,6 @@ -