From f70e67e6eda88142bb021fb22e5f06bd16d10706 Mon Sep 17 00:00:00 2001 From: "PANIK\\chris" Date: Sun, 5 Oct 2025 10:45:28 +0200 Subject: [PATCH] Changed XML style, made znode attritbutes a template parameter --- src/items/xqitemdelegate.cpp | 1 - src/items/xqitemfactory.h | 1 + src/main.cpp | 56 ++++-------------------------------- src/model/xqnode.h | 8 ++---- src/model/xqviewmodel.cpp | 38 +----------------------- src/nodes/znode.h | 31 ++++---------------- src/nodes/znode_factory.h | 9 +++--- src/xtree.pro | 2 +- xml/saved_testfile.xtr | 38 ++++++++++++------------ 9 files changed, 41 insertions(+), 143 deletions(-) diff --git a/src/items/xqitemdelegate.cpp b/src/items/xqitemdelegate.cpp index c20161b..49680c4 100644 --- a/src/items/xqitemdelegate.cpp +++ b/src/items/xqitemdelegate.cpp @@ -242,7 +242,6 @@ void XQItemDelegate::drawSpinBoxStyle(QPainter* painter, const QStyleOptionViewI spinBoxOption.frame = true; _commonStyle.drawComplexControl(QStyle::CC_SpinBox, &spinBoxOption, painter, nullptr); - QRect editRect =_commonStyle.subControlRect(QStyle::CC_SpinBox, &spinBoxOption, QStyle::SC_SpinBoxEditField, nullptr); painter->drawText(spinBoxOption.rect, Qt::AlignCenter, item.text()); } diff --git a/src/items/xqitemfactory.h b/src/items/xqitemfactory.h index 6626da6..edb1894 100644 --- a/src/items/xqitemfactory.h +++ b/src/items/xqitemfactory.h @@ -15,6 +15,7 @@ #ifndef XQITEMFACTORY_H #define XQITEMFACTORY_H +#include #include #include #include diff --git a/src/main.cpp b/src/main.cpp index 4dbcf42..4a7a3d1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -27,53 +28,6 @@ #include -/* - - TODO: - - - kann ich die Enums auto generieren? - - entries einfach abzählen, - - einen enum als type - - auf diesen type drauf-casten, siehe qtglobal.h - - - FIX! in reality, we have nested types, also. - - done: reference style - - done: shared_ptr - - - try QML - - try 'model->readMore' - -doc: - - vorhandenes xnode konzept soll am qt angebunden werden - - datensparsam: flyweight pattern & pointer auf orig - -who is who: - -- item --itemtype - - factory - - model - - section - -*/ - -XQChildModel* createChildModel() -{ - XQChildModel* myModel = new XQChildModel(); - - myModel->initModel( c_ChildModelName ); - - XQNodeFactory treeLoader; - // xml daten laden - XQNodePtr rawTree = treeLoader.load_tree( qPrintable(c_DocumentFileName1) ); - // versteckten root node ignorieren - XQNodePtr contentRoot = rawTree->first_child(); - myModel->addModelData( contentRoot->first_child() ); - - return myModel; - -} - /* @@ -124,10 +78,10 @@ int main(int argc, char *argv[]) { QApplication app(argc, argv); - //qDebug() << QStyleFactory::keys(); - //QApplication::setStyle("fusion"); - //QApplication::setStyle("windowsvista"); - //QApplication::setStyle("windows"); + + // hat am wenigsten darstellungfehler (alternative: fusion) + QQuickStyle::setStyle("Imagine"); + XQMainWindow window; window.show(); diff --git a/src/model/xqnode.h b/src/model/xqnode.h index fd78935..e985bb5 100644 --- a/src/model/xqnode.h +++ b/src/model/xqnode.h @@ -16,8 +16,6 @@ #define XQNODE_H #include -#include - #include #include @@ -29,12 +27,12 @@ std::ostream& operator<<(std::ostream& os, const QString& obj); //! raw node -using XQNode = znode::zbasic_node; +using XQNode = znode::zbasic_node>; //! default shared node -using XQNodePtr = std::shared_ptr>; +using XQNodePtr = std::shared_ptr>>; //! die node factory -using XQNodeFactory = znode::znode_factory; +using XQNodeFactory = znode::znode_factory>; diff --git a/src/model/xqviewmodel.cpp b/src/model/xqviewmodel.cpp index c2af70b..7c640fb 100644 --- a/src/model/xqviewmodel.cpp +++ b/src/model/xqviewmodel.cpp @@ -327,25 +327,12 @@ void XQViewModel::onCommandUndo( const XQCommand& command ) void XQViewModel::cmdCut( const XQCommand& command ) { - - int itmPos = command.first().itemPos; - const XQModelSection& section = _sections.sectionByRow( itmPos ); - qDebug() << " --- HEADSHOT I: " << itmPos << "->" << section.contentType(); - // wir gehen rückwärts über alle gemerkten knoten ... for (auto it = command.rbegin(); it != command.rend(); ++it) { - - - // ... holen das erste item, das auch den content node enthält - //const XQNodeBackup& entry = *it; + // ... holen das erste item, das auch den content node enthält // jetzt löschen, dabei wird die parent-verbindung entfernt const XQNodeBackup& entry = *it; - - XQItem& firstItem = xqFirstItem( (*it).itemPos ); - //qDebug() << " --- Cut: " << firstItem.text() << " " << firstItem.row() << " id#" << entry.contentNode->_id; - qDebug() << " ---- command CUT: itemPos: " << entry.itemPos << " nodePos: "<< entry.nodePos << " is " << entry.contentNode->friendly_name(); - entry.contentNode->unlink_self(); removeRow(entry.itemPos ); } @@ -356,14 +343,11 @@ void XQViewModel::cmdCut( const XQCommand& command ) void XQViewModel::cmdCutUndo( const XQCommand& command ) { - // die anfangsposition int itmPos = command.first().itemPos; // die 'zuständige' section rausfinden const XQModelSection& section = _sections.sectionByRow( itmPos ); - qDebug() << " --- HEADSHOT II: " << itmPos << "->" << section.contentType(); - // über alle einträge ... for (auto& entry : command ) { @@ -372,12 +356,6 @@ void XQViewModel::cmdCutUndo( const XQCommand& command ) savedNode->add_me_at( entry.nodePos, _contentRoot ); XQItemList list = _itemFactory.makeRow( section.sheetRootNode(), savedNode ); insertRow( entry.itemPos, list ); - - XQItem& firstItem = *((XQItem*)list[0]); - - qDebug() << " ---- command cut UNDO2: itemPos: " << entry.itemPos << " nodePos: "<< entry.nodePos << " is " << entry.contentNode->friendly_name(); - qDebug() << " --- Cut Undo: " << firstItem.text() << " " << firstItem.row() << " id#" << entry.contentNode->_id << " count: " << entry.contentNode.use_count(); - } } @@ -419,8 +397,6 @@ void XQViewModel::cmdPaste( const XQCommand& command ) } // unsere änderungen merken fürs 'undo' - - /// fix_xx const_cast(command).saveNodes( selectionModel->selectedRows() ); } @@ -430,14 +406,11 @@ void XQViewModel::cmdPaste( const XQCommand& command ) void XQViewModel::cmdPasteUndo( const XQCommand& command ) { - command.dumpList("Paste UNDO"); // wir gehen rückwärts über alle markieren knoten ... for (auto it = command.rbegin(); it != command.rend(); ++it) { // ... holen das erste item, das auch den content node enthält const XQNodeBackup& entry = *it; - XQItem& firstItem = xqFirstItem( (*it).itemPos ); - qDebug() << " --- Cut: " << firstItem.text() << " " << firstItem.row(); // jetzt löschen entry.contentNode->unlink_self(); removeRow(entry.itemPos ); @@ -456,8 +429,6 @@ void XQViewModel::cmdDelete( const XQCommand& command ) { // ... holen das erste item, das auch den content node enthält const XQNodeBackup& entry = *it; - XQItem& firstItem = xqFirstItem( (*it).itemPos ); - qDebug() << " --- delete: " << firstItem.text() << " " << firstItem.row(); // jetzt löschen entry.contentNode->unlink_self(); removeRow(entry.itemPos ); @@ -468,10 +439,6 @@ void XQViewModel::cmdDelete( const XQCommand& command ) void XQViewModel::cmdDeleteUndo( const XQCommand& command ) { - for (const auto& entry : command) - { - qDebug() << " --- delete UNDo: " << entry.contentNode->friendly_name(); - } cmdCutUndo(command); } @@ -489,8 +456,6 @@ void XQViewModel::cmdNew( const XQCommand& command ) 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() ); - - //... const XQModelSection& section = _sections.sectionByRow( origin.row() ); @@ -529,7 +494,6 @@ void XQViewModel::cmdToggleSection( const XQCommand& command ) // einen doppelten Aufruf und wir sind dann wieder im Anfangszustand. //toggleSection( section ); - emit sectionToggled(section); } diff --git a/src/nodes/znode.h b/src/nodes/znode.h index 0d838a1..6365eda 100644 --- a/src/nodes/znode.h +++ b/src/nodes/znode.h @@ -17,14 +17,11 @@ #include -#include #include -//#include - #include #include #include -#include + #include //#include @@ -41,20 +38,9 @@ namespace znode */ - - // forward declaration of base class zbasic_node ... - //template - //class zbasic_node; - - // ... used here for conveniance typedef - //template - //using zshared_node = std::shared_ptr>; - - - //! einfache tree-klasse, besonderheit: der nutzlast-string-type ist templated. - template - //class zbasic_node : public zid, public zpayload, public std::enable_shared_from_this> - class zbasic_node : public zid, public zpayload, public std::enable_shared_from_this> + //! tree-klasse, besonderheit: der nutzlast-string-type ist templated. + template + class zbasic_node : public zid, public payload_t, public std::enable_shared_from_this> { public: @@ -62,11 +48,6 @@ namespace znode using str_cref = const str_t&; using str_list = std::vector; - //using zshared_node = std::shared_ptr; - //using znode_list = znode_vector; - //using znode_list = znode_vector>; - //using znode_list = std::vector>; - using zweak_node = std::weak_ptr; using zshared_node = std::shared_ptr; using znode_list = std::vector; @@ -109,14 +90,14 @@ namespace znode //! konstruktor mit tag_name und optionalem elternknoten zbasic_node( str_cref tag_name, zshared_cref parent = nullptr ) - : zpayload{tag_name}, _parent{parent} + : payload_t{tag_name}, _parent{parent} { } //! konstruktor mit tag_name, value und optionalem elternknoten zbasic_node( str_cref tag_name, str_cref value, zshared_cref parent = nullptr ) - : zpayload{tag_name,value}, _parent{parent} + : payload_t{tag_name,value}, _parent{parent} { } diff --git a/src/nodes/znode_factory.h b/src/nodes/znode_factory.h index 6640b05..d8dcdd4 100644 --- a/src/nodes/znode_factory.h +++ b/src/nodes/znode_factory.h @@ -40,15 +40,14 @@ model: muss ich wirklich jeden attibute node einzeln angeben? */ namespace znode { - template + template class znode_factory { public: using str_cref = const str_t&; - - using zshared_node = std::shared_ptr>; + using zshared_node = std::shared_ptr< zbasic_node >; znode_factory() = default; virtual ~znode_factory() = default; @@ -70,7 +69,7 @@ namespace znode //tree_document.traverse(parser); //zbasic_node* root_node = new zbasic_node*("root!"); - zshared_node root_node = zbasic_node::make_node("root!"); + zshared_node root_node = zbasic_node::make_node("root!"); //T root_node = T::make_node( "root!" ); // prepare root == model !? @@ -100,7 +99,7 @@ namespace znode //parent->add_child( new_node ); //zbasic_node* new_node = new zbasic_node( node.name(), node.child_value(), parent ); - zshared_node new_node = zbasic_node::make_node( xml_node.name(), xml_node.child_value() ); + zshared_node new_node = zbasic_node::make_node( xml_node.name(), xml_node.child_value() ); parent->add_child( new_node ); if( !xml_node.attributes().empty() ) diff --git a/src/xtree.pro b/src/xtree.pro index fa5a243..6ba0ddf 100644 --- a/src/xtree.pro +++ b/src/xtree.pro @@ -1,4 +1,4 @@ -QT += core gui widgets quick quickwidgets +QT += core gui widgets quick quickwidgets quickcontrols2 # widgets-private CONFIG += c++20 qmltypes diff --git a/xml/saved_testfile.xtr b/xml/saved_testfile.xtr index ec3e5d2..5e6d124 100644 --- a/xml/saved_testfile.xtr +++ b/xml/saved_testfile.xtr @@ -1,22 +1,24 @@ - - - - - - - - - - - - - - - + + + + + + + + + + + + + + - - - + + + + + +