Completed cmdNew implementation.

This commit is contained in:
2025-09-04 14:56:18 +02:00
parent f8bd0886d3
commit 89c5fd21f1
5 changed files with 45 additions and 42 deletions

View File

@@ -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 );
}

View File

@@ -69,7 +69,14 @@ const XQItem& XQViewModel::xqRootItem()
// dynamisch über den ItemData Mechanismus wie in QStandardItem
return *static_cast<XQItem*>(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 );

View File

@@ -60,6 +60,7 @@ public:
//little helpers
const XQItem& xqRootItem();
XQNodePtr contentRootNode();
XQItem& xqItemFromIndex(const QModelIndex& index) const;
XQItem& xqFirstItem(int row) const;

View File

@@ -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();
}