works again

This commit is contained in:
Christoph Holzheuer
2025-08-14 19:13:53 +02:00
parent d3f2cbeaec
commit a6fb7e82bd
15 changed files with 92 additions and 161 deletions

View File

@@ -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";

View File

@@ -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. <Panel atr1="..." />, <Battery .../>
// 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: <Panel>. <Battery> ...
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);

View File

@@ -39,6 +39,7 @@ XQMainModel::XQMainModel(QObject *parent )
XQItem* XQMainModel::createTreeEntry( XQNodePtr contentNode )
{
for(const auto& section : _sections )
{
qDebug() << " --- wtf1: " << contentNode->to_string();

View File

@@ -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 );
*/
}

View File

@@ -51,6 +51,8 @@ public slots:
protected:
void setupWorkingDir();
// fixme implement
void showDocumnet( const QString& key ){}
void loadDocument( const QString& fileName );

View File

@@ -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 <Header> 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<XQItem*>(list[0])->setContentNode(sheetNode);
// brauchen wir den noch?
dynamic_cast<XQItem*>(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 );
}
*/

View File

@@ -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;

View File

@@ -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);
}

View File

@@ -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

View File

@@ -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 );
}

View File

@@ -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;
}

View File

@@ -1,6 +1,6 @@
<?xml version='1.0' encoding='UTF-8'?>
<Project ProjectID="HA01" FriendlyName="@ProjectName" ProjectName="Wiebelbach West" Established="2006" WattPeak="84000" State="runnning" LastFileName="modelData1.xtr">
<Project ProjectID="HA01" FriendlyName="@ProjectName" ProjectName="Wiebelbach West" Established="2006" WattPeak="84000" ContentType="runnning" LastFileName="modelData1.xtr">
<Components>
<Panel PanelID="#1 JA 01" FriendlyName="@PanelName" PanelName="JA 01 Solar T62B" Manufacturer="JA Solar 1 XX" WattPeak="620" Height="2,70" Width="1,10" Weight="12" MaxVolt="67" MaxAmpere="11">

View File

@@ -1,7 +1,7 @@
<?xml version='1.0' encoding='UTF-8'?>
<Project ProjectID="HA02" FriendlyName="@ProjectName" ProjectName="Gerbrunn Ost" Established="2006" WattPeak="9840" State="planned">
<Project ProjectID="HA02" FriendlyName="@ProjectName" ProjectName="Gerbrunn Ost" Established="2006" WattPeak="9840" ContentType="planned">
<Components>
<Panel PanelID="Jingli 01" FriendlyName="@PanelName" PanelName="Jingli 01 Solar T62B" Manufacturer="Jingli Solar" WattPeak="620" Height="2,70" Width="1,10" Weight="12" MaxVolt="67" MaxAmpere="11">
<AdditionalData DataItem="Image" DataValue="image,png"/>

View File

@@ -1,6 +1,6 @@
<?xml version='1.0' encoding='UTF-8'?>
<Project ProjectID="HA03" FriendlyName="@ProjectName" ProjectName="Neubrunn Süd" Established="2006" WattPeak="9840" State="runnning">
<Project ProjectID="HA03" FriendlyName="@ProjectName" ProjectName="Neubrunn Süd" Established="2006" WattPeak="9840" ContentType="runnning">
<Components>
<Panel PanelID="AIKO 01" FriendlyName="@PanelName" PanelName="AIKO 01 Solar T62B" Manufacturer="AIKO Solar" WattPeak="620" Height="2,70" Width="1,10" Weight="12" MaxVolt="67" MaxAmpere="11">
<AdditionalData DataItem="Image" DataValue="image.png"/>

View File

@@ -42,7 +42,7 @@
DocumentDetailsModel:
-->
<DocumentTreeModel>
<Section State="runnning">
<Section ContentType="runnning">
<Header>
<Entry Caption="Active Projects" ItemType="TreeParentType"/>
</Header>
@@ -50,7 +50,7 @@
<Project Caption="@ProjectName" ItemType="TreeParentType"/>
</Data>
</Section>
<Section State="planned">
<Section ContentType="planned">
<Header>
<Entry Caption="Planned Projects" ItemType="TreeParentType"/>
</Header>
@@ -58,7 +58,7 @@
<Project Caption="@ProjectName" ItemType="TreeParentType"/>
</Data>
</Section>
<Section State="finished">
<Section ContentType="finished">
<Header>
<Entry Caption="Finished Projects" ItemType="TreeParentType"/>
</Header>
@@ -74,8 +74,8 @@
<DocumentDetailsModel>
<Section>
<Header>
<Section ContentType="Panel">
<Header Marker="Panel">
<PanelID Caption="Panel" ItemType="HeaderType" />
<PanelName Caption="Name" ItemType="HeaderType" Icon="BrowserStop" />
<Manufacturer Caption="Manufacturer" ItemType="HeaderType" />
@@ -101,8 +101,8 @@
</Data>
</Section>
<Section>
<Header>
<Section ContentType="Inverter">
<Header Marker="Inverter">
<InverterID Caption="Inverter" ItemType="HeaderType" />
<InverterName Caption="Name" ItemType="HeaderType" />
<Manufacturer Caption="Manufacturer" ItemType="HeaderType" />
@@ -122,8 +122,8 @@
</Data>
</Section>
<Section>
<Header>
<Section ContentType="Battery">
<Header Marker="Battery">
<BatteryID Caption="Name" ItemType="HeaderType" />
<BatteryName Caption="Battery" ItemType="HeaderType" />
<Manufacturer Caption="Manufacturer" ItemType="HeaderType" />