invented creation-mode for items
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
@@ -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<XQItem*>(list[0]);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
throw XQException( "addProjectItem: main model should not be empty!" );
|
||||
}
|
||||
|
@@ -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:";
|
||||
|
@@ -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);
|
||||
|
||||
|
@@ -28,13 +28,20 @@ class XQItemFactory : public xsingleton<XQItemFactory>
|
||||
|
||||
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<void( XQItem* item, const QString& attrValue, XQNodePtr contentNode, XQNodePtr sheetNode )>;
|
||||
|
@@ -65,10 +65,6 @@ class XQModelSectionList : public XQMaptor<XQModelSection>
|
||||
{
|
||||
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;
|
||||
|
@@ -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();
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -59,7 +59,7 @@
|
||||
|
||||
<DocumentDetailsModel>
|
||||
|
||||
<Section ContentType="Panel" >
|
||||
<Section ContentType="Panel" CatchBlock="TagName=Panel">
|
||||
<Header>
|
||||
<PanelID Caption="Panel" ItemType="HeaderType" />
|
||||
<PanelName Caption="Name" ItemType="HeaderType" Icon="BrowserStop" />
|
||||
|
Reference in New Issue
Block a user