refurbished old style item creation.

This commit is contained in:
2025-08-22 23:07:56 +02:00
parent c8e59b10db
commit 769ad2b002
5 changed files with 20 additions and 70 deletions

View File

@@ -62,9 +62,8 @@ void XQChildModel::setContent( const XQNodePtr& contentRoot )
section.setContentRootNode( contentEntry->parent() ); section.setContentRootNode( contentEntry->parent() );
int newRow = _sections.lastRow(section); int newRow = _sections.lastRow(section);
XQNodePtr node = section.sheetRootNode(); XQNodePtr sheetNode = section.sheetRootNode();
XQItemList list = _itemFactory.makeContentRow( node, contentEntry ); XQItemList list = _itemFactory.makeRow( sheetNode, contentEntry );
//XQItemList list = _itemFactory.makeContentRow( section.sheetRootNode, contentEntry );
// als Baum? // als Baum?
//section.headerItem().appendRow( list ); //section.headerItem().appendRow( list );

View File

@@ -48,6 +48,7 @@ XQItem* XQMainModel::addProjectItem( XQNodePtr contentNode )
// wir durchsuchen alle unsere section nach dem passenden content-type, // wir durchsuchen alle unsere section nach dem passenden content-type,
// hier: content-type beschreibt die // hier: content-type beschreibt die
/*
for(const auto& section : _sections ) for(const auto& section : _sections )
{ {
@@ -76,7 +77,8 @@ XQItem* XQMainModel::addProjectItem( XQNodePtr contentNode )
} }
} }
. */
throw XQException( "addProjectItem: main model should not be empty!" ); throw XQException( "addProjectItem: main model should not be empty!" );
} }

View File

@@ -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. //! erzeugt eine item-row.
XQItemList XQItemFactory::makeContentRow( const XQNodePtr& sheetNode, const XQNodePtr& contentNode ) XQItemList XQItemFactory::makeRow( const XQNodePtr& sheetNode, const XQNodePtr& contentNode )
{ {
XQItemList list; XQItemList list;
@@ -340,65 +321,38 @@ XQItemList XQItemFactory::makeContentRow( const XQNodePtr& sheetNode, const XQNo
// //
for( const auto& sheetEntry : sheetNode->children() ) for( const auto& sheetEntry : sheetNode->children() )
{ list.append( makeItem( sheetEntry, contentNode ) );
list.append( makeContentItem( sheetEntry, contentNode ) );
}
Q_ASSERT(!list.empty()); 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. // im ersten Item.
dynamic_cast<XQItem*>(list[0])->setContentNode(contentNode); dynamic_cast<XQItem*>(list[0])->setContentNode(contentNode);
return list; 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! //! fixme! unsinn!
//! erzeugt ein XQItem aus einer typ-beschreibung ('sheetNode') und einem daten-knoten ('contentNode'). //! 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 //! 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. //! 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 // den itemtype des neuen items rausfinden
XQItemType* itemType = makeItemType(sheetNode); // throws XQItemType* itemType = makeItemType(sheetNode); // throws
// das ist Unterschied zum normalen Item: Der Titel kommt aus der Modelbeschreibung const QString* contentPtr{};
// der content wird indirect über den tag-name des sheetnode geholt
// das ist Unterschied vom HeaderItem zum normalen Item: Der Titel kommt aus der Modelbeschreibung // das ist Unterschied vom HeaderItem zum normalen Item: Der Titel kommt aus der Modelbeschreibung
if(!contentNode) 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 // der content wird indirect über den tag-name des sheetnode geholt
const QString* contentPtr = contentNode->attribute_ptr( sheetNode->tag_name() ); contentPtr = contentNode->attribute_ptr( sheetNode->tag_name() );
return makeItem( sheetNode, contentPtr );
}
XQItem* newItem = new XQItem( itemType, contentPtr);
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 );
// __fixme! // __fixme!
if( newItem->isCheckable() ) if( newItem->isCheckable() )
@@ -408,4 +362,3 @@ XQItem* XQItemFactory::makeItem( const XQNodePtr& sheetNode, const QString* cont
return newItem; return newItem;
} }

View File

@@ -34,8 +34,7 @@ public:
//XQItemList makeEmptyRow( const XQNodePtr& contentNode, const XQNodePtr& sheetNode ); //XQItemList makeEmptyRow( const XQNodePtr& contentNode, const XQNodePtr& sheetNode );
XQItemList makeHeaderRow( const XQNodePtr& sheetNode, const QString& caption = c_Caption ); XQItemList makeRow( const XQNodePtr& sheetNode, const XQNodePtr& contentNode );
XQItemList makeContentRow( const XQNodePtr& sheetNode, const XQNodePtr& contentNode );
// wozu ist das gut? // wozu ist das gut?
//XQItemList createGenericRow( const XQNodePtr& contentNode, const XQNodePtr& sheetNode ); //XQItemList createGenericRow( const XQNodePtr& contentNode, const XQNodePtr& sheetNode );
@@ -50,11 +49,7 @@ protected:
bool isValid(); 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 XQNodePtr& contentNode );
XQItem* makeItem( const XQNodePtr& sheetNode, const QString* contentPtr );
// shortcuts // shortcuts
using ItemConfigFunc = std::function<void( XQItem* item, const QString& attrValue, XQNodePtr contentNode, XQNodePtr sheetNode )>; using ItemConfigFunc = std::function<void( XQItem* item, const QString& attrValue, XQNodePtr contentNode, XQNodePtr sheetNode )>;

View File

@@ -108,7 +108,8 @@ void XQViewModel::initModel(const QString& modelName)
const XQNodePtr header = sectionNode->find_child_by_tag_name( c_Header ); const XQNodePtr header = sectionNode->find_child_by_tag_name( c_Header );
if( header ) if( header )
{ {
XQItemList list = _itemFactory.makeHeaderRow( header );
XQItemList list = _itemFactory.makeRow( header, nullptr );
addSection(list, sectionNode ); addSection(list, sectionNode );
} }
@@ -353,7 +354,7 @@ void XQViewModel::cmdCutUndo( XQCommand& command )
const XQNodePtr& savedNode = entry.contentNode; const XQNodePtr& savedNode = entry.contentNode;
// __fix! should not be _contentRoot! // __fix! should not be _contentRoot!
savedNode->add_me_at( entry.nodePos, _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]); XQItem& firstItem = *((XQItem*)list[0]);
qDebug() << " --- Cut Undo: " << firstItem.text() << " " << firstItem.row() << " id#" << entry.contentNode->_id << " count: " << entry.contentNode.use_count(); 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() ); XQNodePtr newNode = entry.contentNode->clone(section.contentRootNode() );
newNode->clone(section.contentRootNode() )->add_me_at( nodePos ); newNode->clone(section.contentRootNode() )->add_me_at( nodePos );
// ... und damit eine frische item-row erzeugen // ... und damit eine frische item-row erzeugen
XQItemList list = _itemFactory.makeContentRow( section.sheetRootNode(), newNode ); XQItemList list = _itemFactory.makeRow( section.sheetRootNode(), newNode );
insertRow( insRow, list ); insertRow( insRow, list );
// die neue item-row selektieren // die neue item-row selektieren
const QModelIndex& selIdx = list[0]->index(); const QModelIndex& selIdx = list[0]->index();