diff --git a/src/application/xqappdata.h b/src/application/xqappdata.h index 7237337..e4b288a 100644 --- a/src/application/xqappdata.h +++ b/src/application/xqappdata.h @@ -27,6 +27,7 @@ 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_ContentType = "ContentType"; const QString c_MainModelName = "DocumentTreeModel"; const QString c_ChildModelName = "DocumentDetailsModel"; diff --git a/src/application/xqchildmodel.cpp b/src/application/xqchildmodel.cpp index 74f9404..d509d8c 100644 --- a/src/application/xqchildmodel.cpp +++ b/src/application/xqchildmodel.cpp @@ -31,73 +31,7 @@ XQChildModel::XQChildModel( QObject *parent ) } -//! erzeugt die basisstruktur des models. -/* -void XQChildModel::initModel(const QString& modelName) -{ - - auto extendItemType = [=,this](const XQNodePtr& entry) - { - const QString& typeName = entry->attribute("ItemType"); - XQItemType* itemType = _itemFactory.findItemTypeTemplate( typeName); // throws - // über alle attribute - for (const auto& attr : entry->attributes()) - { - // prüfen, ob der itemType des attribute schon hat - int role = itemType->hasAttribute( attr.first); - // wenn ja, überschreiben - if( role != XQItem::NoRole ) - { - QVariant newValue = _itemFactory.makeVariant(role,attr.second); - itemType->replaceAttribute( newValue, role ); - } - - } - - }; - - // #0: Wir suchen die Model-Beschreibung - XQNodePtr modelSheet = _itemFactory.findModelSheet( modelName ); // throws - - // #1: Wir erzeugen die Model-Struktur: Jedes Kind beschreibt einen - // XML-Datentyp, z.B. , - // Jeder XML-Knoten entspricht einer Zeile im späteren Model, jedes - // Attribut wird einem eigenen Feld (XQItem) abgebildet. - - for( const auto& sheetNode : modelSheet->children() ) - { - - - XQItemList list = _itemFactory.makeHeaderRow( sheetNode ); - - // für jeden XML-Knotentyp in der Modelbeschreibung erzeugen wir eine section - addSection(list, sheetNode ); - - // jedes kind kann enthält einen itemType und einen headerItemType. Für - // diese sind eventuell weitere attribute vorhanden, die die im type - // enthaltenen defualt-werte überschreiben. - - for( const auto& sheetChild : sheetNode->children() ) - { - //qDebug() << "---- kloppo: " << sheetChild->tag_name() << ": " << sheetChild->to_string(); - extendItemType( sheetChild ); - } - - - - // empty row: - // XQNodePtr contentNode = XQNode::make_node( sheetNode->tag_name() ); - // XQItemList emptyRow = _itemFactory.makeEmptyRow( contentNode, sheetNode ); - // appendRow( emptyRow ); - - - } // for - -} -*/ - - -//! erzegut den sichtbaren inhalt des models aus einem root-datenknoten. +//! erzegt den sichtbaren inhalt des models aus einem root-datenknoten. void XQChildModel::setContent( const XQNodePtr& contentRoot ) { @@ -113,14 +47,20 @@ void XQChildModel::setContent( const XQNodePtr& contentRoot ) // haben, hier: . ... for (const auto& contentEntry : _contentRoot->children()) { + + qDebug() << " --- GOGOGO: 00: " << contentEntry->to_string(); + // Das ist hier der Typ des Eintrags: Panel, Battery ... QString key = contentEntry->tag_name(); + qDebug() << " --- GOGOGO: " << key; // 'silent failure' hier der Datenbaum kann auch Knoten enthalten // die nicht für uns gedacht sind. if (!_sections.hasValidSection(key)) continue; + qDebug() << " --- GOGOGO: FOUND!" << key; + XQModelSection& section = _sections.at( key ); // wir speichern das parent des datenknoten auch in der // section. @@ -128,8 +68,10 @@ void XQChildModel::setContent( const XQNodePtr& contentRoot ) section.contentRootNode = contentEntry->parent(); int newRow = _sections.lastRow(section); - //qDebug() << " --- AHJA: " << key << " -- last Row dazu: " << newRow; - XQItemList list = _itemFactory.makeContentRow( contentEntry, section.sheetRootNode ); + XQItemList list = _itemFactory.makeContentRow( section.sheetRootNode, contentEntry ); + + qDebug() << " --- AHJA: " << key << " -- last Row dazu: " << newRow; + // als Baum? //section.headerItem().appendRow( list ); insertRow( newRow, list); diff --git a/src/application/xqmainmodel.cpp b/src/application/xqmainmodel.cpp index 018dbf7..ad087cd 100644 --- a/src/application/xqmainmodel.cpp +++ b/src/application/xqmainmodel.cpp @@ -39,6 +39,7 @@ XQMainModel::XQMainModel(QObject *parent ) XQItem* XQMainModel::createTreeEntry( XQNodePtr contentNode ) { + for(const auto& section : _sections ) { qDebug() << " --- wtf1: " << contentNode->to_string(); diff --git a/src/application/xqmainwindow.cpp b/src/application/xqmainwindow.cpp index 73f56b7..bf8d14a 100644 --- a/src/application/xqmainwindow.cpp +++ b/src/application/xqmainwindow.cpp @@ -34,12 +34,34 @@ XQMainWindow::XQMainWindow( QWidget* parent ) } +// setzt das working directory: dieses muss das 'xml' datenverzeichnis enthalten. + +void XQMainWindow::setupWorkingDir() +{ + QDir dir = QDir::current(); + + while (dir.exists()) + { + QString xmlPath = dir.absoluteFilePath("xml"); + if (QDir(xmlPath).exists()) + { + qDebug() << " --- CD TO: " << dir.absolutePath(); + QDir::setCurrent( dir.absolutePath() ); + } + if (!dir.cdUp()) + return; + } +} + + //! actions & document struktur einrichten. void XQMainWindow::initMainWindow() { qDebug() << " --- initMainWindow(): here we go!"; + // das working dir setzen: 'xml' muss als unterverzeichnis vorhanden sein. + setupWorkingDir(); // als allererstes laden wir die Modelschreibungen XQItemFactory::instance().initItemFactory( c_ModelSheetFileName ); @@ -295,11 +317,12 @@ void XQMainWindow::loadDocument( const QString& fileName ) // read the model data childModel->setContent( contentRoot->first_child() ); + /* // create new entry in the left side main tree view - XQItem* newEntry = _mainModelView.createTreeEntry( contentRoot ); _mainTreeView->setCurrentIndex( newEntry->index() ); _documentStore.addDocument( fileName, pTitle, newEntry, childModel ); + */ } diff --git a/src/application/xqmainwindow.h b/src/application/xqmainwindow.h index ee3478a..a0a167c 100644 --- a/src/application/xqmainwindow.h +++ b/src/application/xqmainwindow.h @@ -51,6 +51,8 @@ public slots: protected: + void setupWorkingDir(); + // fixme implement void showDocumnet( const QString& key ){} void loadDocument( const QString& fileName ); diff --git a/src/items/xqitemfactory.cpp b/src/items/xqitemfactory.cpp index bd522cc..8644a65 100644 --- a/src/items/xqitemfactory.cpp +++ b/src/items/xqitemfactory.cpp @@ -28,7 +28,7 @@ void XQItemFactory::initItemFactory( const QString& modelSheetFileName ) // über alle attribute for( const auto& [key,value] : sheetNode->attributes() ) { - qDebug() << " --- conf item Type: " << key << " : " << value; + //qDebug() << " --- conf item Type: " << key << " : " << value; setItemDataFromString( *itemType, key, value ); } }; @@ -97,6 +97,8 @@ XQItemType* XQItemFactory::makeItemType(const XQNodePtr& sheetEntry ) return itemType; } +//! firz! + XQItemType* XQItemFactory::findItemTypeTemplate(const QString& key ) const { if( !key.isEmpty() && s_ItemTypeTemplates.contains(key)) @@ -105,6 +107,8 @@ XQItemType* XQItemFactory::findItemTypeTemplate(const QString& key ) const } +//! firz! + XQNodePtr XQItemFactory::findModelSheet( const QString& modelName ) const { XQNodePtr modelSheet = _modelSheet->find_child_by_tag_name( modelName ); @@ -115,26 +119,7 @@ XQNodePtr XQItemFactory::findModelSheet( const QString& modelName ) const } - -XQItem* XQItemFactory::makeHeaderItem( const XQNodePtr& sheetEntry ) -{ - // header items are all non-data items: - // - section header row items - // - main tree header items - // - main tree child items - // - also: static items, hidden items - - // den itemtype des neuen items rausfinden - QString typeKey = sheetEntry->attribute("HeaderItemType"); - //XQItemType* itemType = makeItemType(sheetEntry); // throws - XQItemType* itemType = findItemTypeTemplate(typeKey); - // das ist Unterschied zum normalen Item: Der Titel kommt aus der Modelbeschreibung - const QString* contentPtr = sheetEntry->attribute_ptr("HeaderCaption"); - - return new XQItem( itemType, contentPtr ); - -} - +//! firz! XQItem* XQItemFactory::makeTreeChildItem( const XQNodePtr& contentNode, const XQNodePtr& sheetEntry ) { @@ -150,6 +135,9 @@ XQItem* XQItemFactory::makeTreeChildItem( const XQNodePtr& contentNode, const XQ return newItem; } + +//! firz! + void XQItemFactory::setItemDataFromString( XQItem& item, const QString& roleKey, const QString& source ) const { int dataRole = XQItem::fetchItemDataRole( roleKey ); @@ -162,6 +150,8 @@ void XQItemFactory::setItemDataFromString( XQItem& item, const QString& roleKey, } +//! firz! + QVariant XQItemFactory::makeVariant( int dataRole, const QString& source ) const { @@ -283,23 +273,15 @@ 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() ); +//! 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. - return new XQItem( itemType, contentPtr ); - -} - - XQItem* XQItemFactory::makeItem( const XQNodePtr& sheetNode, const XQNodePtr& contentNode ) +XQItem* XQItemFactory::makeItem( const XQNodePtr& sheetNode, const XQNodePtr& contentNode ) { // den itemtype des neuen items rausfinden QString typeKey = sheetNode->attribute(c_ItemType); + qDebug() << " --- makeItem: typeKey: " << typeKey << ": " << sheetNode->to_string(); //XQItemType* itemType = makeItemType(sheetEntry); // throws XQItemType* itemType = findItemTypeTemplate(typeKey); // fallunterscheidung beim inhalt: @@ -315,14 +297,14 @@ XQItem* XQItemFactory::makeContentItem( const XQNodePtr& contentNode, const XQNo } -XQItemList XQItemFactory::makeHeader( const XQNodePtr& headerNode ) +XQItemList XQItemFactory::makeHeaderRow( const XQNodePtr& headerNode ) { XQItemList list; // über alle kinder der
sektion for( const auto& headerEntry : headerNode->children() ) { - qDebug() << " --- headerEntry: " << headerEntry->tag_name() << ": " << headerEntry->attribute( "ItemType") << headerEntry->attribute( "Caption"); + //qDebug() << " --- headerEntry: " << headerEntry->tag_name() << ": " << headerEntry->attribute( "ItemType") << headerEntry->attribute( "Caption"); XQItem* headerItem = makeItem( headerEntry ); list.append( headerItem ); } @@ -332,36 +314,9 @@ XQItemList XQItemFactory::makeHeader( const XQNodePtr& headerNode ) } -XQItemList XQItemFactory::makeHeaderRow( const XQNodePtr& sheetNode ) -{ - XQItemList list; - // Die Kinder des Knotens beschreiben die einzelnen - // Attribute des XML-Datenknotens - for( const auto& attrNode : sheetNode->children() ) - { - // ?? - //if(attrNode->has_children() ) - // continue; +//! erzeugt eine header item row. - XQItem* headerItem = makeHeaderItem( attrNode ); - list.append( headerItem ); - } - - if( !list.empty() ) - { - // wir merken uns den original content node auch, aber - // im ersten Item. - dynamic_cast(list[0])->setContentNode(sheetNode); - // brauchen wir den noch? - dynamic_cast(list[0])->setSheetNode(sheetNode); - } - - return list; -} - - -// no clone here ! -XQItemList XQItemFactory::makeContentRow( const XQNodePtr& contentNode, const XQNodePtr& sheetNode ) +XQItemList XQItemFactory::makeContentRow( const XQNodePtr& sheetNode, const XQNodePtr& contentNode ) { XQItemList list; @@ -378,7 +333,7 @@ XQItemList XQItemFactory::makeContentRow( const XQNodePtr& contentNode, const XQ for( const auto& sheetEntry : sheetNode->children() ) { - list.append( makeContentItem( contentNode, sheetEntry ) ); + list.append( makeItem( sheetEntry, contentNode ) ); } if( !list.empty() ) @@ -392,6 +347,7 @@ XQItemList XQItemFactory::makeContentRow( const XQNodePtr& contentNode, const XQ } +/* XQItemList XQItemFactory::makeEmptyRow( const XQNodePtr& contentNode, const XQNodePtr& sheetNode ) { Q_UNUSED(contentNode) @@ -408,8 +364,9 @@ XQItemList XQItemFactory::makeEmptyRow( const XQNodePtr& contentNode, const XQNo return list; } +*/ - +/* XQItemList XQItemFactory::createGenericRow( const XQNodePtr& contentNode, const XQNodePtr& sheetNode ) { @@ -429,3 +386,4 @@ XQItemList XQItemFactory::createGenericRow( const XQNodePtr& contentNode, const return makeContentRow(contentNode, sheetNode ); } +*/ diff --git a/src/items/xqitemfactory.h b/src/items/xqitemfactory.h index db0b645..535d7bf 100644 --- a/src/items/xqitemfactory.h +++ b/src/items/xqitemfactory.h @@ -32,20 +32,17 @@ 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* 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 ); + XQItemList makeContentRow( const XQNodePtr& sheetNode, const XQNodePtr& contentNode ); + //XQItemList makeEmptyRow( const XQNodePtr& contentNode, const XQNodePtr& sheetNode ); + // wozu ist das gut? - 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/items/xqitemtype.cpp b/src/items/xqitemtype.cpp index 91aef3d..4a0e9bb 100644 --- a/src/items/xqitemtype.cpp +++ b/src/items/xqitemtype.cpp @@ -65,7 +65,7 @@ QVariant XQItemType::data( int role ) const void XQItemType::setData(const QVariant& value, int role ) { - qDebug() << " --- itemType set Data:" << role << " : " << value.toString(); + //qDebug() << " --- itemType set Data:" << role << " : " << value.toString(); return QStandardItem::setData(value,role); } diff --git a/src/model/xqmodelsectionlist.cpp b/src/model/xqmodelsectionlist.cpp index 74a69b6..ce3a9d8 100644 --- a/src/model/xqmodelsectionlist.cpp +++ b/src/model/xqmodelsectionlist.cpp @@ -61,8 +61,12 @@ XQItem& XQModelSection::XQModelSection::headerItem() const void XQModelSectionList::addSectionEntry(const QModelIndex& idx, XQNodePtr sheetNode) { - XQModelSection section(idx, sheetNode); - addAtKey(sheetNode->tag_name(), section); + if( !sheetNode->has_attribute( c_ContentType) ) + throw XQException( "section list: Section node needs attribute 'ContentType'!"); + + XQModelSection section(idx, sheetNode->find_child_by_tag_name("Data")); + qDebug() << " ---- ADD section: " << sheetNode->attribute( c_ContentType); + addAtKey(sheetNode->attribute( c_ContentType), section); } bool XQModelSectionList::hasValidSection(const QString& sectionKey) const diff --git a/src/model/xqviewmodel.cpp b/src/model/xqviewmodel.cpp index 56d3c10..258348e 100644 --- a/src/model/xqviewmodel.cpp +++ b/src/model/xqviewmodel.cpp @@ -108,7 +108,7 @@ void XQViewModel::initModel(const QString& modelName) const XQNodePtr header = section->find_child_by_tag_name( "Header"); if( header ) { - XQItemList list = _itemFactory.makeHeader( header ); + XQItemList list = _itemFactory.makeHeaderRow( header ); Q_ASSERT(!list.isEmpty()); addSection(list, section ); } diff --git a/src/nodes/znode_payload.h b/src/nodes/znode_payload.h index 2cbd940..2253d23 100644 --- a/src/nodes/znode_payload.h +++ b/src/nodes/znode_payload.h @@ -170,6 +170,9 @@ namespace znode typename zattributes::const_iterator pos = _attributes.find(key); if( pos == _attributes.end() ) return false; + // leer gilded nicht + if( xstr_is_empty( pos->second ) ) + return false; return true; } diff --git a/xml/modeldata1.xtr b/xml/modeldata1.xtr index 7b62e47..89253ec 100644 --- a/xml/modeldata1.xtr +++ b/xml/modeldata1.xtr @@ -1,6 +1,6 @@ - + diff --git a/xml/modeldata2.xtr b/xml/modeldata2.xtr index 8198148..b2fa088 100644 --- a/xml/modeldata2.xtr +++ b/xml/modeldata2.xtr @@ -1,7 +1,7 @@ - + diff --git a/xml/modeldata3.xtr b/xml/modeldata3.xtr index ae9d9fa..f7c783b 100644 --- a/xml/modeldata3.xtr +++ b/xml/modeldata3.xtr @@ -1,6 +1,6 @@ - + diff --git a/xml/modelsheets.xml b/xml/modelsheets.xml index 9b61535..83267c2 100644 --- a/xml/modelsheets.xml +++ b/xml/modelsheets.xml @@ -42,7 +42,7 @@ DocumentDetailsModel: --> -
+
@@ -50,7 +50,7 @@
-
+
@@ -58,7 +58,7 @@
-
+
@@ -74,8 +74,8 @@ -
-
+
+
@@ -101,8 +101,8 @@
-
-
+
+
@@ -122,8 +122,8 @@
-
-
+
+