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