From 769ad2b00268c8011c25b92941b7bafdaf10e383 Mon Sep 17 00:00:00 2001 From: "PANIK\\chris" Date: Fri, 22 Aug 2025 23:07:56 +0200 Subject: [PATCH] refurbished old style item creation. --- src/application/xqchildmodel.cpp | 5 +-- src/application/xqmainmodel.cpp | 4 +- src/items/xqitemfactory.cpp | 67 +++++--------------------------- src/items/xqitemfactory.h | 7 +--- src/model/xqviewmodel.cpp | 7 ++-- 5 files changed, 20 insertions(+), 70 deletions(-) diff --git a/src/application/xqchildmodel.cpp b/src/application/xqchildmodel.cpp index a5354da..e97bf05 100644 --- a/src/application/xqchildmodel.cpp +++ b/src/application/xqchildmodel.cpp @@ -62,9 +62,8 @@ void XQChildModel::setContent( const XQNodePtr& contentRoot ) section.setContentRootNode( contentEntry->parent() ); int newRow = _sections.lastRow(section); - XQNodePtr node = section.sheetRootNode(); - XQItemList list = _itemFactory.makeContentRow( node, contentEntry ); - //XQItemList list = _itemFactory.makeContentRow( section.sheetRootNode, contentEntry ); + XQNodePtr sheetNode = section.sheetRootNode(); + XQItemList list = _itemFactory.makeRow( sheetNode, contentEntry ); // als Baum? //section.headerItem().appendRow( list ); diff --git a/src/application/xqmainmodel.cpp b/src/application/xqmainmodel.cpp index 64f807e..ef90247 100644 --- a/src/application/xqmainmodel.cpp +++ b/src/application/xqmainmodel.cpp @@ -48,6 +48,7 @@ XQItem* XQMainModel::addProjectItem( XQNodePtr contentNode ) // wir durchsuchen alle unsere section nach dem passenden content-type, // hier: content-type beschreibt die + /* for(const auto& section : _sections ) { @@ -76,7 +77,8 @@ XQItem* XQMainModel::addProjectItem( XQNodePtr contentNode ) } } -. + */ + throw XQException( "addProjectItem: main model should not be empty!" ); } diff --git a/src/items/xqitemfactory.cpp b/src/items/xqitemfactory.cpp index 754b391..8956c0d 100644 --- a/src/items/xqitemfactory.cpp +++ b/src/items/xqitemfactory.cpp @@ -303,28 +303,9 @@ XQItemList XQItemFactory::createGenericRow( const XQNodePtr& contentNode, const */ - -//! erzeugt eine header-item row. - -XQItemList XQItemFactory::makeHeaderRow( const XQNodePtr& sheetNode, const QString& caption ) -{ - - XQItemList list; - - for( const auto& sheetEntry : sheetNode->children() ) - { - list.append( makeHeaderItem( sheetEntry, caption ) ); - } - - Q_ASSERT(!list.empty()); - - return list; -} - - //! erzeugt eine item-row. -XQItemList XQItemFactory::makeContentRow( const XQNodePtr& sheetNode, const XQNodePtr& contentNode ) +XQItemList XQItemFactory::makeRow( const XQNodePtr& sheetNode, const XQNodePtr& contentNode ) { XQItemList list; @@ -340,65 +321,38 @@ XQItemList XQItemFactory::makeContentRow( const XQNodePtr& sheetNode, const XQNo // for( const auto& sheetEntry : sheetNode->children() ) - { - list.append( makeContentItem( sheetEntry, contentNode ) ); - } + list.append( makeItem( sheetEntry, contentNode ) ); Q_ASSERT(!list.empty()); - // wir merken uns den original content node auch, aber + // wir merken uns den original content node auch, aber // im ersten Item. - dynamic_cast(list[0])->setContentNode(contentNode); + dynamic_cast(list[0])->setContentNode(contentNode); return list; } -XQItem* XQItemFactory::makeHeaderItem( const XQNodePtr& sheetNode, const QString& caption ) -{ - // den itemtype des neuen items rausfinden - XQItemType* itemType = makeItemType(sheetNode); // throws - - // das ist Unterschied zum normalen Item: Der Titel kommt aus der Modelbeschreibung - // der content wird indirect über den tag-name des sheetnode geholt - - XQItem* newItem = new XQItem( itemType, sheetNode->attribute_ptr(caption) ); - - // __fixme! - if( newItem->isCheckable() ) - newItem->setCheckState( Qt::Checked ); - - return newItem; -} - //! fixme! unsinn! //! erzeugt ein XQItem aus einer typ-beschreibung ('sheetNode') und einem daten-knoten ('contentNode'). //! wenn der content node nicht gesetzt ist, wird stattdess das attribut 'Caption' aus der typ-beschreibung //! verwendet: es handelt sich dann um ein header item, das erzeugt wurde. -XQItem* XQItemFactory::makeContentItem( const XQNodePtr& sheetNode, const XQNodePtr& contentNode ) +XQItem* XQItemFactory::makeItem( const XQNodePtr& sheetNode, const XQNodePtr& contentNode ) { // den itemtype des neuen items rausfinden XQItemType* itemType = makeItemType(sheetNode); // throws - // das ist Unterschied zum normalen Item: Der Titel kommt aus der Modelbeschreibung - // der content wird indirect über den tag-name des sheetnode geholt + const QString* contentPtr{}; // das ist Unterschied vom HeaderItem zum normalen Item: Der Titel kommt aus der Modelbeschreibung if(!contentNode) - return makeItem( sheetNode, sheetNode->attribute_ptr(c_Caption) ); - + contentPtr = sheetNode->attribute_ptr(c_Caption); + else // der content wird indirect über den tag-name des sheetnode geholt - const QString* contentPtr = contentNode->attribute_ptr( sheetNode->tag_name() ); - return makeItem( sheetNode, contentPtr ); -} + contentPtr = contentNode->attribute_ptr( sheetNode->tag_name() ); - -XQItem* XQItemFactory::makeItem( const XQNodePtr& sheetNode, const QString* contentPtr ) -{ - // den itemtype des neuen items rausfinden - XQItemType* itemType = makeItemType(sheetNode); // throws - XQItem* newItem = new XQItem( itemType, contentPtr ); + XQItem* newItem = new XQItem( itemType, contentPtr); // __fixme! if( newItem->isCheckable() ) @@ -408,4 +362,3 @@ XQItem* XQItemFactory::makeItem( const XQNodePtr& sheetNode, const QString* cont return newItem; } - diff --git a/src/items/xqitemfactory.h b/src/items/xqitemfactory.h index 99bf8e4..ae5cbea 100644 --- a/src/items/xqitemfactory.h +++ b/src/items/xqitemfactory.h @@ -34,8 +34,7 @@ public: //XQItemList makeEmptyRow( const XQNodePtr& contentNode, const XQNodePtr& sheetNode ); - XQItemList makeHeaderRow( const XQNodePtr& sheetNode, const QString& caption = c_Caption ); - XQItemList makeContentRow( const XQNodePtr& sheetNode, const XQNodePtr& contentNode ); + XQItemList makeRow( const XQNodePtr& sheetNode, const XQNodePtr& contentNode ); // wozu ist das gut? //XQItemList createGenericRow( const XQNodePtr& contentNode, const XQNodePtr& sheetNode ); @@ -50,11 +49,7 @@ protected: bool isValid(); - XQItem* makeHeaderItem( const XQNodePtr& sheetNode, const QString& caption ); - XQItem* makeContentItem( const XQNodePtr& sheetNode, const XQNodePtr& contentNode ); - XQItem* makeItem( const XQNodePtr& sheetNode, const XQNodePtr& contentNode ); - XQItem* makeItem( const XQNodePtr& sheetNode, const QString* contentPtr ); // shortcuts using ItemConfigFunc = std::function; diff --git a/src/model/xqviewmodel.cpp b/src/model/xqviewmodel.cpp index e188895..2677d05 100644 --- a/src/model/xqviewmodel.cpp +++ b/src/model/xqviewmodel.cpp @@ -108,7 +108,8 @@ void XQViewModel::initModel(const QString& modelName) const XQNodePtr header = sectionNode->find_child_by_tag_name( c_Header ); if( header ) { - XQItemList list = _itemFactory.makeHeaderRow( header ); + + XQItemList list = _itemFactory.makeRow( header, nullptr ); addSection(list, sectionNode ); } @@ -353,7 +354,7 @@ void XQViewModel::cmdCutUndo( XQCommand& command ) const XQNodePtr& savedNode = entry.contentNode; // __fix! should not be _contentRoot! savedNode->add_me_at( entry.nodePos, _contentRoot ); - XQItemList list = _itemFactory.makeContentRow( section.sheetRootNode(), savedNode ); + XQItemList list = _itemFactory.makeRow( section.sheetRootNode(), savedNode ); XQItem& firstItem = *((XQItem*)list[0]); qDebug() << " --- Cut Undo: " << firstItem.text() << " " << firstItem.row() << " id#" << entry.contentNode->_id << " count: " << entry.contentNode.use_count(); @@ -388,7 +389,7 @@ void XQViewModel::cmdPaste( XQCommand& command ) XQNodePtr newNode = entry.contentNode->clone(section.contentRootNode() ); newNode->clone(section.contentRootNode() )->add_me_at( nodePos ); // ... und damit eine frische item-row erzeugen - XQItemList list = _itemFactory.makeContentRow( section.sheetRootNode(), newNode ); + XQItemList list = _itemFactory.makeRow( section.sheetRootNode(), newNode ); insertRow( insRow, list ); // die neue item-row selektieren const QModelIndex& selIdx = list[0]->index();