From 89c5fd21f109099a1683d22299b30515b1dd3e85 Mon Sep 17 00:00:00 2001 From: "PANIK\\chris" Date: Thu, 4 Sep 2025 14:56:18 +0200 Subject: [PATCH] Completed cmdNew implementation. --- src/application/xqmainwindow.cpp | 5 ++-- src/model/xqviewmodel.cpp | 15 ++++++---- src/model/xqviewmodel.h | 1 + src/nodes/znode.h | 16 +++++----- xml/saved_testfile.xtr | 50 +++++++++++++++----------------- 5 files changed, 45 insertions(+), 42 deletions(-) diff --git a/src/application/xqmainwindow.cpp b/src/application/xqmainwindow.cpp index cd36d4d..ade4203 100644 --- a/src/application/xqmainwindow.cpp +++ b/src/application/xqmainwindow.cpp @@ -404,7 +404,6 @@ void XQMainWindow::loadDocument( const QString& fileName ) connect( childModel, SIGNAL(sectionCreated(XQModelSection)), this, SLOT(onSectionCreated(XQModelSection)) ); connect( childModel, SIGNAL(sectionToggled(XQModelSection)), this, SLOT(onSectionToggled(XQModelSection)) ); - //connect( childModel, &QStandardItemModel::itemChanged, this, &XQMainWindow::onTreeItemChanged); // Den globalen undo-stack ... childModel->setUndoStack(&_undoStack); @@ -432,7 +431,9 @@ void XQMainWindow::saveDocument( const QString& fileName ) { XQNodeWriter nodeWriter; int curIdx = _tabWidget->currentIndex(); - XQNodePtr rootNode = _documentStore[curIdx].treeItem->contentNode(); + //XQNodePtr rootNode = _documentStore[curIdx].treeItem->contentNode(); + XQNodePtr rootNode = _documentStore[curIdx].modelView->contentRootNode(); + Q_ASSERT(rootNode); nodeWriter.dumpTree( rootNode, fileName ); } diff --git a/src/model/xqviewmodel.cpp b/src/model/xqviewmodel.cpp index 7cac038..4c94393 100644 --- a/src/model/xqviewmodel.cpp +++ b/src/model/xqviewmodel.cpp @@ -69,7 +69,14 @@ const XQItem& XQViewModel::xqRootItem() // dynamisch über den ItemData Mechanismus wie in QStandardItem return *static_cast(invisibleRootItem()); +} + +//! Gibt den daten root node des models zurück. + +XQNodePtr XQViewModel::contentRootNode() +{ + return _contentRoot; } @@ -431,20 +438,18 @@ void XQViewModel::cmdDeleteUndo( const XQCommand& command ) void XQViewModel::cmdNew( const XQCommand& command ) { - - - const QModelIndex& origin = command.originIndex(); - XQItem& target = xqItemFromIndex( origin ); // current data node XQNodePtr node = target.contentNode(); + qDebug() << " --- node own pos: " << node->own_pos(); + // we create a new data node XQNodePtr newNode = XQNode::make_node( node->tag_name(), node->tag_value(), node->parent() ); // store node in node->parent() - //node->add_before_me( newNode ); + newNode->add_me_at( node->own_pos(), node->parent() ); // store node also in 'command' to enable undo const XQModelSection& section = _sections.sectionFromIndex( origin ); diff --git a/src/model/xqviewmodel.h b/src/model/xqviewmodel.h index 3f2cc19..0c1d384 100644 --- a/src/model/xqviewmodel.h +++ b/src/model/xqviewmodel.h @@ -60,6 +60,7 @@ public: //little helpers const XQItem& xqRootItem(); + XQNodePtr contentRootNode(); XQItem& xqItemFromIndex(const QModelIndex& index) const; XQItem& xqFirstItem(int row) const; diff --git a/src/nodes/znode.h b/src/nodes/znode.h index 06d4403..3ed2d68 100644 --- a/src/nodes/znode.h +++ b/src/nodes/znode.h @@ -180,16 +180,14 @@ namespace znode zshared_node sibling() { - if( !parent() ) - //return zshared_node( make_node("WTF1") ); - return zshared_node(); + if( parent() ) + { + znode_list& childs = _parent->_children; + auto it = std::find( childs.begin(), childs.end(), this->shared_from_this() ); + if( ++it != childs.end()) + return *(it); + } - znode_list& childs = _parent->_children; - auto it = std::find( childs.begin(), childs.end(), this->shared_from_this() ); - if( ++it != childs.end()) - return *(it); - - //return zshared_node( make_node("WTF?") ); return zshared_node(); } diff --git a/xml/saved_testfile.xtr b/xml/saved_testfile.xtr index c06133d..01a0f34 100644 --- a/xml/saved_testfile.xtr +++ b/xml/saved_testfile.xtr @@ -1,27 +1,25 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + +