From 7c267bcb3310aef3a1f71df3e4586d3b696b03f5 Mon Sep 17 00:00:00 2001 From: "PANIK\\chris" Date: Tue, 12 Aug 2025 23:41:36 +0200 Subject: [PATCH] mini sucess --- src/application/xqappdata.h | 4 ++ src/application/xqmainmodel.cpp | 21 +++++++---- src/application/xqmainwindow.cpp | 5 ++- src/items/xqitemfactory.cpp | 63 +++++++++++++++++++++++++------- src/items/xqitemfactory.h | 19 ++++++---- src/model/xqviewmodel.cpp | 2 +- src/model/xqviewmodel.h | 15 ++------ xml/modelsheets.xml | 28 +++++++++++--- 8 files changed, 109 insertions(+), 48 deletions(-) diff --git a/src/application/xqappdata.h b/src/application/xqappdata.h index eeacf2f..5970410 100644 --- a/src/application/xqappdata.h +++ b/src/application/xqappdata.h @@ -24,6 +24,10 @@ const QString c_Version = "0.1.1 04.09.2024"; +const QString c_ItemType = "ItemType"; +const QString c_Caption = "Caption"; +const QString c_Header = "Header"; + const QString c_MainModelName = "DocumentTreeModel"; const QString c_ChildModelName = "DocumentDetailsModel"; const QString c_ProjectID = "ProjectID"; diff --git a/src/application/xqmainmodel.cpp b/src/application/xqmainmodel.cpp index 0b22044..a3d96b6 100644 --- a/src/application/xqmainmodel.cpp +++ b/src/application/xqmainmodel.cpp @@ -38,17 +38,22 @@ XQMainModel::XQMainModel(QObject *parent ) void XQMainModel::initModel(const QString& modelName) { - XQNodePtr modelSheet = _itemFactory.findModelSheet( modelName ); - // #1: create structure: create static sections for this model - for( auto& sheetNode : modelSheet->children() ) + // model rootnode finden -> + XQNodePtr modelSheet = _itemFactory.findModelSheet( modelName ); // throws + + // #1: über alle sections + for( auto& section : modelSheet->children() ) { - qDebug() << " create main model: " << sheetNode->tag_name(); + // #2: (optionalen) header erzeugen + const XQNodePtr header = section->find_child_by_tag_name( "Header"); + if( header ) + { + XQItemList list = _itemFactory.makeHeader( header ); + Q_ASSERT(!list.isEmpty()); + addSection(list, section ); + } - XQItemList list = { _itemFactory.makeHeaderItem( sheetNode ) }; - Q_ASSERT(!list.isEmpty()); - addSection(list, sheetNode ); - //appendRow( list ); } } diff --git a/src/application/xqmainwindow.cpp b/src/application/xqmainwindow.cpp index 73f56b7..37f8297 100644 --- a/src/application/xqmainwindow.cpp +++ b/src/application/xqmainwindow.cpp @@ -85,10 +85,11 @@ void XQMainWindow::initMainWindow() // hand over left side navigation tree _mainModelView.setTreeTable(_mainTreeView); // #1. init the left side main tree view - _mainModelView.initModel( c_MainModelName ); + //_mainModelView.initModel( c_MainModelName ); + _mainModelView.initModel( "ModelX" ); // #2. load demo data - loadDocument( c_DocumentFileName1 ); + //loadDocument( c_DocumentFileName1 ); //loadDocument( c_DocumentFileName2 ); qDebug() << " --- all here: " << XQNode::s_Count; diff --git a/src/items/xqitemfactory.cpp b/src/items/xqitemfactory.cpp index 20c73ac..718097e 100644 --- a/src/items/xqitemfactory.cpp +++ b/src/items/xqitemfactory.cpp @@ -135,19 +135,6 @@ XQItem* XQItemFactory::makeHeaderItem( const XQNodePtr& sheetEntry ) } -XQItem* XQItemFactory::makeContentItem( const XQNodePtr& contentNode, const XQNodePtr& sheetEntry ) -{ - // den itemtype des neuen items rausfinden - QString typeKey = sheetEntry->attribute("ItemType"); - //XQItemType* itemType = findItemTypeTemplate(typeKey); // throws - XQItemType* itemType = makeItemType(sheetEntry); // throws - - const QString* contentPtr = contentNode->attribute_ptr( sheetEntry->tag_name() ); - - return new XQItem( itemType, contentPtr ); - -} - XQItem* XQItemFactory::makeTreeChildItem( const XQNodePtr& contentNode, const XQNodePtr& sheetEntry ) { @@ -295,6 +282,56 @@ QVariant XQItemFactory::makeVariant( int dataRole, const QString& source ) const /// ------------------------------------------------ /// + +XQItem* XQItemFactory::makeContentItem( const XQNodePtr& contentNode, const XQNodePtr& sheetEntry ) +{ + // den itemtype des neuen items rausfinden + QString typeKey = sheetEntry->attribute(c_ItemType); + //XQItemType* itemType = findItemTypeTemplate(typeKey); // throws + XQItemType* itemType = makeItemType(sheetEntry); // throws + // das ist Unterschied zum normalen Item: Der Titel kommt aus der Modelbeschreibung + const QString* contentPtr = contentNode->attribute_ptr( sheetEntry->tag_name() ); + + return new XQItem( itemType, contentPtr ); + +} + + XQItem* XQItemFactory::makeItem( const XQNodePtr& sheetNode, const XQNodePtr& contentNode ) +{ + // den itemtype des neuen items rausfinden + QString typeKey = sheetNode->attribute(c_ItemType); + //XQItemType* itemType = makeItemType(sheetEntry); // throws + XQItemType* itemType = findItemTypeTemplate(typeKey); + // fallunterscheidung beim inhalt: + const QString* contentPtr{}; + // das ist Unterschied zum normalen Item: Der Titel kommt aus der Modelbeschreibung + if(!contentNode) + contentPtr = sheetNode->attribute_ptr(c_Caption); + else + // der content wird indirect über den tag-name des sheetnode geholt + contentPtr = contentNode->attribute_ptr( sheetNode->tag_name() ); + + return new XQItem( itemType, contentPtr ); + +} + +XQItemList XQItemFactory::makeHeader( const XQNodePtr& headerNode ) +{ + + XQItemList list; + + for( const auto& headerEntry : headerNode->children() ) + { + qDebug() << " --- headerEntry: " << headerEntry->tag_name() << ": " << headerEntry->attribute( "ItemType") << headerEntry->attribute( "Caption"); + XQItem* headerItem = makeItem( headerEntry ); + list.append( headerItem ); + } + + return list; + +} + + XQItemList XQItemFactory::makeHeaderRow( const XQNodePtr& sheetNode ) { XQItemList list; diff --git a/src/items/xqitemfactory.h b/src/items/xqitemfactory.h index 8829d13..db0b645 100644 --- a/src/items/xqitemfactory.h +++ b/src/items/xqitemfactory.h @@ -32,15 +32,20 @@ public: XQNodePtr findModelSheet( const QString& modelName ) const; - XQItem* makeHeaderItem(const XQNodePtr& typeSheetNode ); - XQItem* makeContentItem( const XQNodePtr& contentNode, const XQNodePtr& sheetEntry ); - XQItem* makeTreeChildItem( const XQNodePtr& contentNode, const XQNodePtr& sheetEntry ); + XQItem* makeHeaderItem(const XQNodePtr& typeSheetNode ); + XQItem* makeContentItem( const XQNodePtr& contentNode, const XQNodePtr& sheetEntry ); + XQItem* makeTreeChildItem( const XQNodePtr& contentNode, const XQNodePtr& sheetEntry ); - virtual XQItemList makeHeaderRow( const XQNodePtr& sheetNode ); - virtual XQItemList makeContentRow( const XQNodePtr& contentNode, const XQNodePtr& sheetNode ); - virtual XQItemList makeEmptyRow( const XQNodePtr& contentNode, const XQNodePtr& sheetNode ); + XQItem* makeItem( const XQNodePtr& sheetNode, const XQNodePtr& contentNode=nullptr); + XQItemList makeHeader( const XQNodePtr& sheetNode ); + + + + XQItemList makeHeaderRow( const XQNodePtr& sheetNode ); + XQItemList makeContentRow( const XQNodePtr& contentNode, const XQNodePtr& sheetNode ); + XQItemList makeEmptyRow( const XQNodePtr& contentNode, const XQNodePtr& sheetNode ); // wozu ist das gut? - virtual XQItemList createGenericRow( const XQNodePtr& contentNode, const XQNodePtr& sheetNode ); + XQItemList createGenericRow( const XQNodePtr& contentNode, const XQNodePtr& sheetNode ); void setItemDataFromString( XQItem& item, const QString& roleKey, const QString& source ) const; diff --git a/src/model/xqviewmodel.cpp b/src/model/xqviewmodel.cpp index 61fbe3b..2fab942 100644 --- a/src/model/xqviewmodel.cpp +++ b/src/model/xqviewmodel.cpp @@ -91,7 +91,7 @@ void XQViewModel::initModel( const QString& modelName) section header section - + ... */ diff --git a/src/model/xqviewmodel.h b/src/model/xqviewmodel.h index 5a09049..585253f 100644 --- a/src/model/xqviewmodel.h +++ b/src/model/xqviewmodel.h @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -30,18 +31,7 @@ class XQItem; class XQCommand; -/** - * @brief Abstract baseclass of all modelviews: Extends QStandardItemModel with a treeview. - */ - -// might be own implementation of QAbstractItemModel, not done yet. -// using QStandardItemModel = XQSimpleItemModel; -using QStandardItemModel = QStandardItemModel; - -/** - * @brief The XQViewModel class: An extendend QStandardItem model - * containing its own view. - */ +//! ein erweitertes QStandardItemModel welches 'seine' view bereits enthält. class XQViewModel : public QStandardItemModel { @@ -131,6 +121,7 @@ protected: XQModelSectionList _sections; XQTreeTable* _treeTable{}; + //QAbstractItemView* _treeTable{}; QUndoStack* _undoStack{}; XQContextMenu* _contextMenu{}; diff --git a/xml/modelsheets.xml b/xml/modelsheets.xml index 2bf96a3..10aa97e 100644 --- a/xml/modelsheets.xml +++ b/xml/modelsheets.xml @@ -47,15 +47,33 @@ - -
+ +
+
- - + + + +
+
+
+ +
+ + + +
+
+
+ +
+ + +
- +