diff --git a/src/application/xqchildmodel.cpp b/src/application/xqchildmodel.cpp index afd6e07..6a6b841 100644 --- a/src/application/xqchildmodel.cpp +++ b/src/application/xqchildmodel.cpp @@ -60,13 +60,13 @@ void XQChildModel::addModelData( const XQNodePtr& contentRoot ) // section. // contentEntry->parent == _contentRoot, aber halt nur weil das model flach ist - qDebug() << " --- add section ENTRY: " << key << " TagName: " << contentEntry->attribute("TagName"); + //qDebug() << " --- add section ENTRY: " << key << " TagName: " << contentEntry->attribute("TagName"); section.setContentRootNode( contentEntry->parent() ); int newRow = _sections.lastRow(section); XQNodePtr sheetNode = section.sheetRootNode(); - XQItemList list = _itemFactory.makeRow( sheetNode, contentEntry ); + XQItemList list = _itemFactory.makeRow( XQItemFactory::mData, sheetNode, contentEntry ); // als Baum? //section.headerItem().appendRow( list ); @@ -84,7 +84,7 @@ void XQChildModel::addSectionEntry( const QString& key, const XQNodePtr& content section.setContentRootNode( contentEntry->parent() ); int newRow = _sections.lastRow(section); XQNodePtr sheetNode = section.sheetRootNode(); - XQItemList list = _itemFactory.makeRow( sheetNode, contentEntry ); + XQItemList list = _itemFactory.makeRow( XQItemFactory::mHeader, sheetNode, contentEntry ); insertRow( newRow, list); } } diff --git a/src/application/xqmainmodel.cpp b/src/application/xqmainmodel.cpp index ef90247..e3bd90e 100644 --- a/src/application/xqmainmodel.cpp +++ b/src/application/xqmainmodel.cpp @@ -48,16 +48,18 @@ 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 ) { if( contentNode->attribute( c_ContentType) == section.contentType() ) { - const QString* contentPtr = contentNode->attribute_ptr( "ProjectName" ); + + qDebug() << " --- add PROJECT: contentNode: " << contentNode->to_string(); + // __fixme! das ist mist! const XQNodePtr sheetNode = section.sheetRootNode()->first_child(); - XQItemList list = _itemFactory.makeHeaderRow( sheetNode, contentPtr ); + XQItemList list = _itemFactory.makeRow( XQItemFactory::mSingle, sheetNode, contentNode, "ProjectName"); // erzeuger sheet node speichern //newItem->setSheetNode( sheetNode ); @@ -72,12 +74,12 @@ XQItem* XQMainModel::addProjectItem( XQNodePtr contentNode ) //newItem->setContentNode( contentNode ); //emit itemCreated( newItem ); - return list[0]; + return dynamic_cast(list[0]); } } - */ + throw XQException( "addProjectItem: main model should not be empty!" ); } diff --git a/src/application/xqmainwindow.cpp b/src/application/xqmainwindow.cpp index 381530c..e03ce2b 100644 --- a/src/application/xqmainwindow.cpp +++ b/src/application/xqmainwindow.cpp @@ -346,7 +346,7 @@ void XQMainWindow::loadDocument( const QString& fileName ) childModel->setTreeTable(childTreeView); // neuen eintrag im übsichts-baum erzeugen - //_currentProjectItem = _mainModelView.addProjectItem( contentRoot ); + _currentProjectItem = _mainModelView.addProjectItem( contentRoot ); //_documentStore.addDocument( fileName, pTitle, _currentProjectItem, childModel ); qDebug() << " --- ZZZ und jetzt:"; diff --git a/src/items/xqitemfactory.cpp b/src/items/xqitemfactory.cpp index 8956c0d..11f7c31 100644 --- a/src/items/xqitemfactory.cpp +++ b/src/items/xqitemfactory.cpp @@ -305,7 +305,7 @@ XQItemList XQItemFactory::createGenericRow( const XQNodePtr& contentNode, const //! erzeugt eine item-row. -XQItemList XQItemFactory::makeRow( const XQNodePtr& sheetNode, const XQNodePtr& contentNode ) +XQItemList XQItemFactory::makeRow(CreationMode mode, const XQNodePtr& sheetNode, const XQNodePtr& contentNode, const QString& captionKey ) { XQItemList list; @@ -321,7 +321,7 @@ XQItemList XQItemFactory::makeRow( const XQNodePtr& sheetNode, const XQNodePtr& // for( const auto& sheetEntry : sheetNode->children() ) - list.append( makeItem( sheetEntry, contentNode ) ); + list.append( makeItem( mode, sheetEntry, contentNode, captionKey ) ); Q_ASSERT(!list.empty()); @@ -338,19 +338,29 @@ XQItemList XQItemFactory::makeRow( const XQNodePtr& sheetNode, const XQNodePtr& //! 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::makeItem( const XQNodePtr& sheetNode, const XQNodePtr& contentNode ) +XQItem* XQItemFactory::makeItem(CreationMode mode, const XQNodePtr& sheetNode, const XQNodePtr& contentNode, const QString& captionKey ) { // den itemtype des neuen items rausfinden XQItemType* itemType = makeItemType(sheetNode); // throws const QString* contentPtr{}; - // das ist Unterschied vom HeaderItem 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() ); + // das ist Unterschied vom HeaderItem zum normalen Item: Der Titel kommt aus der Modelbeschreibung, + // sonst wird der content indirekt über den tag-name des sheetnode geholt + + switch( mode ) + { + case mHeader: + contentPtr = sheetNode->attribute_ptr(captionKey); + break; + + case mData: + contentPtr = contentNode->attribute_ptr( sheetNode->tag_name() ); + break; + + case mSingle: + contentPtr = contentNode->attribute_ptr( captionKey ); + } XQItem* newItem = new XQItem( itemType, contentPtr); diff --git a/src/items/xqitemfactory.h b/src/items/xqitemfactory.h index ae5cbea..abe4f30 100644 --- a/src/items/xqitemfactory.h +++ b/src/items/xqitemfactory.h @@ -28,13 +28,20 @@ class XQItemFactory : public xsingleton public: + enum CreationMode + { + mHeader, + mData, + mSingle + }; + void initItemFactory(const QString& modelSheetFileName ); XQNodePtr findModelSheet( const QString& modelName ) const; //XQItemList makeEmptyRow( const XQNodePtr& contentNode, const XQNodePtr& sheetNode ); - XQItemList makeRow( const XQNodePtr& sheetNode, const XQNodePtr& contentNode ); + XQItemList makeRow( CreationMode mode, const XQNodePtr& sheetNode, const XQNodePtr& contentNode, const QString& captionKey=c_Caption ); // wozu ist das gut? //XQItemList createGenericRow( const XQNodePtr& contentNode, const XQNodePtr& sheetNode ); @@ -49,7 +56,7 @@ protected: bool isValid(); - XQItem* makeItem( const XQNodePtr& sheetNode, const XQNodePtr& contentNode ); + XQItem* makeItem( CreationMode mode, const XQNodePtr& sheetNode, const XQNodePtr& contentNode, const QString& captionKey ); // shortcuts using ItemConfigFunc = std::function; diff --git a/src/model/xqmodelsectionlist.h b/src/model/xqmodelsectionlist.h index a18be65..3cff156 100644 --- a/src/model/xqmodelsectionlist.h +++ b/src/model/xqmodelsectionlist.h @@ -65,10 +65,6 @@ class XQModelSectionList : public XQMaptor { public: - XQModelSectionList() = default; - virtual ~XQModelSectionList() = default; - - void createSectionEntry(const XQItemList& list, const XQNodePtr& sheetNode ); bool hasValidSection(const QString& sectionKey) const; const XQModelSection& sectionFromRow( int row ) const; diff --git a/src/model/xqviewmodel.cpp b/src/model/xqviewmodel.cpp index 04cff4b..d68ef69 100644 --- a/src/model/xqviewmodel.cpp +++ b/src/model/xqviewmodel.cpp @@ -111,7 +111,7 @@ void XQViewModel::initModel(const QString& modelName) const XQNodePtr header = sectionNode->find_child_by_tag_name( c_Header ); if( header ) { - XQItemList list = _itemFactory.makeRow( header, nullptr ); + XQItemList list = _itemFactory.makeRow( XQItemFactory::mHeader, header, nullptr ); addSection(list, sectionNode ); } } @@ -138,9 +138,6 @@ void XQViewModel::addSection(const XQItemList& list, const XQNodePtr& sectionNod // 5. das erzeugt dann auch valide indices appendRow(list); - // 6. die beschreibung der daten liegt im unterknoten 'Data' - - // 6. jetzt können wir auch die sction erzeugen XQModelSection section(list[0]->index(), sectionNode ); _sections.addAtKey(sectionNode->attribute( c_ContentType), section); @@ -355,7 +352,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.makeRow( section.sheetRootNode(), savedNode ); + XQItemList list = _itemFactory.makeRow( XQItemFactory::mData, section.sheetRootNode(), savedNode ); XQItem& firstItem = *((XQItem*)list[0]); qDebug() << " --- Cut Undo: " << firstItem.text() << " " << firstItem.row() << " id#" << entry.contentNode->_id << " count: " << entry.contentNode.use_count(); @@ -393,7 +390,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.makeRow( section.sheetRootNode(), newNode ); + XQItemList list = _itemFactory.makeRow( XQItemFactory::mData, section.sheetRootNode(), newNode ); insertRow( insRow, list ); // die neue item-row selektieren const QModelIndex& selIdx = list[0]->index(); diff --git a/src/nodes/znode_payload.h b/src/nodes/znode_payload.h index 2e1f87b..a3f878f 100644 --- a/src/nodes/znode_payload.h +++ b/src/nodes/znode_payload.h @@ -235,7 +235,7 @@ namespace znode auto it = s_fixed_attributes_ptr.find(key); if (it != s_fixed_attributes_ptr.end() ) - (this->*(it->second))(); + return (this->*(it->second))(); return &s_dummy_value; } diff --git a/xml/modelsheets.xml b/xml/modelsheets.xml index 1c5dbf5..f22ff6e 100644 --- a/xml/modelsheets.xml +++ b/xml/modelsheets.xml @@ -59,7 +59,7 @@ -
+