Changed XML style, made znode attritbutes a template parameter

This commit is contained in:
2025-10-05 10:45:28 +02:00
parent b3b37d1ca4
commit f70e67e6ed
9 changed files with 41 additions and 143 deletions

View File

@@ -242,7 +242,6 @@ void XQItemDelegate::drawSpinBoxStyle(QPainter* painter, const QStyleOptionViewI
spinBoxOption.frame = true; spinBoxOption.frame = true;
_commonStyle.drawComplexControl(QStyle::CC_SpinBox, &spinBoxOption, painter, nullptr); _commonStyle.drawComplexControl(QStyle::CC_SpinBox, &spinBoxOption, painter, nullptr);
QRect editRect =_commonStyle.subControlRect(QStyle::CC_SpinBox, &spinBoxOption, QStyle::SC_SpinBoxEditField, nullptr);
painter->drawText(spinBoxOption.rect, Qt::AlignCenter, item.text()); painter->drawText(spinBoxOption.rect, Qt::AlignCenter, item.text());
} }

View File

@@ -15,6 +15,7 @@
#ifndef XQITEMFACTORY_H #ifndef XQITEMFACTORY_H
#define XQITEMFACTORY_H #define XQITEMFACTORY_H
#include <xsingleton.h>
#include <xqitem.h> #include <xqitem.h>
#include <xqitemtype.h> #include <xqitemtype.h>
#include <functional> #include <functional>

View File

@@ -17,6 +17,7 @@
#include <QMetaType> #include <QMetaType>
#include <QGuiApplication> #include <QGuiApplication>
#include <QQmlApplicationEngine> #include <QQmlApplicationEngine>
#include <QQuickStyle>
#include <QUrl> #include <QUrl>
#include <QQmlContext> #include <QQmlContext>
#include <QStyleFactory> #include <QStyleFactory>
@@ -27,53 +28,6 @@
#include <xqmainwindow.h> #include <xqmainwindow.h>
/*
TODO:
- kann ich die Enums auto generieren?
- entries einfach abzählen,
- einen enum als type
- auf diesen type drauf-casten, siehe qtglobal.h
- FIX! in reality, we have nested types, also.
- done: reference style
- done: shared_ptr
- try QML
- try 'model->readMore'
doc:
- vorhandenes xnode konzept soll am qt angebunden werden
- datensparsam: flyweight pattern & pointer auf orig
who is who:
- item
-itemtype
- factory
- model
- section
*/
XQChildModel* createChildModel()
{
XQChildModel* myModel = new XQChildModel();
myModel->initModel( c_ChildModelName );
XQNodeFactory treeLoader;
// xml daten laden
XQNodePtr rawTree = treeLoader.load_tree( qPrintable(c_DocumentFileName1) );
// versteckten root node ignorieren
XQNodePtr contentRoot = rawTree->first_child();
myModel->addModelData( contentRoot->first_child() );
return myModel;
}
/* /*
@@ -124,10 +78,10 @@ int main(int argc, char *argv[])
{ {
QApplication app(argc, argv); QApplication app(argc, argv);
//qDebug() << QStyleFactory::keys();
//QApplication::setStyle("fusion"); // hat am wenigsten darstellungfehler (alternative: fusion)
//QApplication::setStyle("windowsvista"); QQuickStyle::setStyle("Imagine");
//QApplication::setStyle("windows");
XQMainWindow window; XQMainWindow window;
window.show(); window.show();

View File

@@ -16,8 +16,6 @@
#define XQNODE_H #define XQNODE_H
#include <iostream> #include <iostream>
#include <memory>
#include <QDebug> #include <QDebug>
#include <QModelIndex> #include <QModelIndex>
@@ -29,12 +27,12 @@
std::ostream& operator<<(std::ostream& os, const QString& obj); std::ostream& operator<<(std::ostream& os, const QString& obj);
//! raw node //! raw node
using XQNode = znode::zbasic_node<QString>; using XQNode = znode::zbasic_node<QString,znode::zpayload<QString>>;
//! default shared node //! default shared node
using XQNodePtr = std::shared_ptr<znode::zbasic_node<QString>>; using XQNodePtr = std::shared_ptr<znode::zbasic_node<QString,znode::zpayload<QString>>>;
//! die node factory //! die node factory
using XQNodeFactory = znode::znode_factory<QString>; using XQNodeFactory = znode::znode_factory<QString,znode::zpayload<QString>>;

View File

@@ -327,25 +327,12 @@ void XQViewModel::onCommandUndo( const XQCommand& command )
void XQViewModel::cmdCut( const XQCommand& command ) void XQViewModel::cmdCut( const XQCommand& command )
{ {
int itmPos = command.first().itemPos;
const XQModelSection& section = _sections.sectionByRow( itmPos );
qDebug() << " --- HEADSHOT I: " << itmPos << "->" << section.contentType();
// wir gehen rückwärts über alle gemerkten knoten ... // wir gehen rückwärts über alle gemerkten knoten ...
for (auto it = command.rbegin(); it != command.rend(); ++it) for (auto it = command.rbegin(); it != command.rend(); ++it)
{ {
// ... holen das erste item, das auch den content node enthält
// ... holen das erste item, das auch den content node enthält
//const XQNodeBackup& entry = *it;
// jetzt löschen, dabei wird die parent-verbindung entfernt // jetzt löschen, dabei wird die parent-verbindung entfernt
const XQNodeBackup& entry = *it; const XQNodeBackup& entry = *it;
XQItem& firstItem = xqFirstItem( (*it).itemPos );
//qDebug() << " --- Cut: " << firstItem.text() << " " << firstItem.row() << " id#" << entry.contentNode->_id;
qDebug() << " ---- command CUT: itemPos: " << entry.itemPos << " nodePos: "<< entry.nodePos << " is " << entry.contentNode->friendly_name();
entry.contentNode->unlink_self(); entry.contentNode->unlink_self();
removeRow(entry.itemPos ); removeRow(entry.itemPos );
} }
@@ -356,14 +343,11 @@ void XQViewModel::cmdCut( const XQCommand& command )
void XQViewModel::cmdCutUndo( const XQCommand& command ) void XQViewModel::cmdCutUndo( const XQCommand& command )
{ {
// die anfangsposition // die anfangsposition
int itmPos = command.first().itemPos; int itmPos = command.first().itemPos;
// die 'zuständige' section rausfinden // die 'zuständige' section rausfinden
const XQModelSection& section = _sections.sectionByRow( itmPos ); const XQModelSection& section = _sections.sectionByRow( itmPos );
qDebug() << " --- HEADSHOT II: " << itmPos << "->" << section.contentType();
// über alle einträge ... // über alle einträge ...
for (auto& entry : command ) for (auto& entry : command )
{ {
@@ -372,12 +356,6 @@ void XQViewModel::cmdCutUndo( const XQCommand& command )
savedNode->add_me_at( entry.nodePos, _contentRoot ); savedNode->add_me_at( entry.nodePos, _contentRoot );
XQItemList list = _itemFactory.makeRow( section.sheetRootNode(), savedNode ); XQItemList list = _itemFactory.makeRow( section.sheetRootNode(), savedNode );
insertRow( entry.itemPos, list ); insertRow( entry.itemPos, list );
XQItem& firstItem = *((XQItem*)list[0]);
qDebug() << " ---- command cut UNDO2: itemPos: " << entry.itemPos << " nodePos: "<< entry.nodePos << " is " << entry.contentNode->friendly_name();
qDebug() << " --- Cut Undo: " << firstItem.text() << " " << firstItem.row() << " id#" << entry.contentNode->_id << " count: " << entry.contentNode.use_count();
} }
} }
@@ -419,8 +397,6 @@ void XQViewModel::cmdPaste( const XQCommand& command )
} }
// unsere änderungen merken fürs 'undo' // unsere änderungen merken fürs 'undo'
/// fix_xx
const_cast<XQCommand&>(command).saveNodes( selectionModel->selectedRows() ); const_cast<XQCommand&>(command).saveNodes( selectionModel->selectedRows() );
} }
@@ -430,14 +406,11 @@ void XQViewModel::cmdPaste( const XQCommand& command )
void XQViewModel::cmdPasteUndo( const XQCommand& command ) void XQViewModel::cmdPasteUndo( const XQCommand& command )
{ {
command.dumpList("Paste UNDO");
// wir gehen rückwärts über alle markieren knoten ... // wir gehen rückwärts über alle markieren knoten ...
for (auto it = command.rbegin(); it != command.rend(); ++it) for (auto it = command.rbegin(); it != command.rend(); ++it)
{ {
// ... holen das erste item, das auch den content node enthält // ... holen das erste item, das auch den content node enthält
const XQNodeBackup& entry = *it; const XQNodeBackup& entry = *it;
XQItem& firstItem = xqFirstItem( (*it).itemPos );
qDebug() << " --- Cut: " << firstItem.text() << " " << firstItem.row();
// jetzt löschen // jetzt löschen
entry.contentNode->unlink_self(); entry.contentNode->unlink_self();
removeRow(entry.itemPos ); removeRow(entry.itemPos );
@@ -456,8 +429,6 @@ void XQViewModel::cmdDelete( const XQCommand& command )
{ {
// ... holen das erste item, das auch den content node enthält // ... holen das erste item, das auch den content node enthält
const XQNodeBackup& entry = *it; const XQNodeBackup& entry = *it;
XQItem& firstItem = xqFirstItem( (*it).itemPos );
qDebug() << " --- delete: " << firstItem.text() << " " << firstItem.row();
// jetzt löschen // jetzt löschen
entry.contentNode->unlink_self(); entry.contentNode->unlink_self();
removeRow(entry.itemPos ); removeRow(entry.itemPos );
@@ -468,10 +439,6 @@ void XQViewModel::cmdDelete( const XQCommand& command )
void XQViewModel::cmdDeleteUndo( const XQCommand& command ) void XQViewModel::cmdDeleteUndo( const XQCommand& command )
{ {
for (const auto& entry : command)
{
qDebug() << " --- delete UNDo: " << entry.contentNode->friendly_name();
}
cmdCutUndo(command); cmdCutUndo(command);
} }
@@ -489,8 +456,6 @@ void XQViewModel::cmdNew( const XQCommand& command )
XQNodePtr newNode = XQNode::make_node( node->tag_name(), node->tag_value() ); XQNodePtr newNode = XQNode::make_node( node->tag_name(), node->tag_value() );
// store node in node->parent() // store node in node->parent()
newNode->add_me_at( node->own_pos(), node->parent() ); newNode->add_me_at( node->own_pos(), node->parent() );
//... //...
const XQModelSection& section = _sections.sectionByRow( origin.row() ); const XQModelSection& section = _sections.sectionByRow( origin.row() );
@@ -529,7 +494,6 @@ void XQViewModel::cmdToggleSection( const XQCommand& command )
// einen doppelten Aufruf und wir sind dann wieder im Anfangszustand. // einen doppelten Aufruf und wir sind dann wieder im Anfangszustand.
//toggleSection( section ); //toggleSection( section );
emit sectionToggled(section); emit sectionToggled(section);
} }

View File

@@ -17,14 +17,11 @@
#include <vector> #include <vector>
#include <string>
#include <memory> #include <memory>
//#include <typeinfo>
#include <QString> #include <QString>
#include <QDebug> #include <QDebug>
#include <xqmaptor.h> #include <xqmaptor.h>
#include <xsingleton.h>
#include <znode_iterator.h> #include <znode_iterator.h>
//#include <znode_vector.h> //#include <znode_vector.h>
@@ -41,20 +38,9 @@ namespace znode
*/ */
//! tree-klasse, besonderheit: der nutzlast-string-type ist templated.
// forward declaration of base class zbasic_node ... template<typename str_t, typename payload_t>
//template<typename str_t> class zbasic_node : public zid, public payload_t, public std::enable_shared_from_this<zbasic_node<str_t,payload_t>>
//class zbasic_node;
// ... used here for conveniance typedef
//template<typename str_t>
//using zshared_node = std::shared_ptr<zbasic_node<str_t>>;
//! einfache tree-klasse, besonderheit: der nutzlast-string-type ist templated.
template<typename str_t>
//class zbasic_node : public zid, public zpayload<str_t>, public std::enable_shared_from_this<zbasic_node<str_t>>
class zbasic_node : public zid, public zpayload<str_t>, public std::enable_shared_from_this<zbasic_node<str_t>>
{ {
public: public:
@@ -62,11 +48,6 @@ namespace znode
using str_cref = const str_t&; using str_cref = const str_t&;
using str_list = std::vector<str_t>; using str_list = std::vector<str_t>;
//using zshared_node = std::shared_ptr<zbasic_node>;
//using znode_list = znode_vector<zbasic_node>;
//using znode_list = znode_vector<zshared_node<str_t>>;
//using znode_list = std::vector<zshared_node<str_t>>;
using zweak_node = std::weak_ptr<zbasic_node>; using zweak_node = std::weak_ptr<zbasic_node>;
using zshared_node = std::shared_ptr<zbasic_node>; using zshared_node = std::shared_ptr<zbasic_node>;
using znode_list = std::vector<zshared_node>; using znode_list = std::vector<zshared_node>;
@@ -109,14 +90,14 @@ namespace znode
//! konstruktor mit tag_name und optionalem elternknoten //! konstruktor mit tag_name und optionalem elternknoten
zbasic_node( str_cref tag_name, zshared_cref parent = nullptr ) zbasic_node( str_cref tag_name, zshared_cref parent = nullptr )
: zpayload<str_t>{tag_name}, _parent{parent} : payload_t{tag_name}, _parent{parent}
{ {
} }
//! konstruktor mit tag_name, value und optionalem elternknoten //! konstruktor mit tag_name, value und optionalem elternknoten
zbasic_node( str_cref tag_name, str_cref value, zshared_cref parent = nullptr ) zbasic_node( str_cref tag_name, str_cref value, zshared_cref parent = nullptr )
: zpayload<str_t>{tag_name,value}, _parent{parent} : payload_t{tag_name,value}, _parent{parent}
{ {
} }

View File

@@ -40,15 +40,14 @@ model: muss ich wirklich jeden attibute node einzeln angeben?
*/ */
namespace znode namespace znode
{ {
template<typename str_t> template<typename str_t,typename payload_t>
class znode_factory class znode_factory
{ {
public: public:
using str_cref = const str_t&; using str_cref = const str_t&;
using zshared_node = std::shared_ptr< zbasic_node<str_t,payload_t> >;
using zshared_node = std::shared_ptr<zbasic_node<str_t>>;
znode_factory() = default; znode_factory() = default;
virtual ~znode_factory() = default; virtual ~znode_factory() = default;
@@ -70,7 +69,7 @@ namespace znode
//tree_document.traverse(parser); //tree_document.traverse(parser);
//zbasic_node<str_t>* root_node = new zbasic_node<str_t>*("root!"); //zbasic_node<str_t>* root_node = new zbasic_node<str_t>*("root!");
zshared_node root_node = zbasic_node<str_t>::make_node("root!"); zshared_node root_node = zbasic_node<str_t, payload_t>::make_node("root!");
//T root_node = T::make_node( "root!" ); //T root_node = T::make_node( "root!" );
// prepare root == model !? // prepare root == model !?
@@ -100,7 +99,7 @@ namespace znode
//parent->add_child( new_node ); //parent->add_child( new_node );
//zbasic_node<str_t>* new_node = new zbasic_node<str_t>( node.name(), node.child_value(), parent ); //zbasic_node<str_t>* new_node = new zbasic_node<str_t>( node.name(), node.child_value(), parent );
zshared_node new_node = zbasic_node<str_t>::make_node( xml_node.name(), xml_node.child_value() ); zshared_node new_node = zbasic_node<str_t, payload_t>::make_node( xml_node.name(), xml_node.child_value() );
parent->add_child( new_node ); parent->add_child( new_node );
if( !xml_node.attributes().empty() ) if( !xml_node.attributes().empty() )

View File

@@ -1,4 +1,4 @@
QT += core gui widgets quick quickwidgets QT += core gui widgets quick quickwidgets quickcontrols2
# widgets-private # widgets-private
CONFIG += c++20 qmltypes CONFIG += c++20 qmltypes

View File

@@ -1,22 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<Components> <Components>
<Panel FriendlyName="@PanelName" Height="2,70" Manufacturer="Jingli Solar" MaxAmpere="11" MaxVolt="67" PanelID="Jingli 01" PanelName="Jingli 01 Solar T62B" WattPeak="620" Weight="12" Width="1,10"> <Panel FriendlyName="@PanelName" Height="2,70" Manufacturer="JA Solar 1 XX" MaxAmpere="11" MaxVolt="67" PanelID="#1 JA 01" PanelName="JA 01 Solar T62B" WattPeak="620" Weight="12" Width="1,10"/>
<AdditionalData DataItem="Image" DataValue="image.png"/> <Panel FriendlyName="@PanelName" Height="1,70" Manufacturer="JA Solar 2" MaxAmpere="11" MaxVolt="42" PanelID="#2 JA 02" PanelName="JA 02 Solar X58C" WattPeak="440" Weight="12" Width="1,10"/>
<AdditionalData DataItem="Manual" DataValue="manual.docx"/> <Panel FriendlyName="@PanelName" Height="2,70" Manufacturer="JA Solar 3" MaxAmpere="11" MaxVolt="67" PanelID="#3 JA 03" PanelName="JA 03 Solar T62B" WattPeak="620" Weight="12" Width="1,10"/>
<AdditionalData DataItem="Certificate" DataValue="certificate.pdf"/> <Panel FriendlyName="@PanelName" Height="1,70" Manufacturer="JA Solar 4" MaxAmpere="11" MaxVolt="42" PanelID="#4 JA 04" PanelName="JA 04 Solar X58C" WattPeak="440" Weight="12" Width="1,10"/>
</Panel> <Panel FriendlyName="@PanelName" Height="1,70" Manufacturer="JA Solar 5" MaxAmpere="11" MaxVolt="42" PanelID="#5 JA 05" PanelName="moo" WattPeak="440" Weight="12" Width="1,10"/>
<Panel FriendlyName="@PanelName" Height="1,70" Manufacturer="Jingli Solar" MaxAmpere="11" MaxVolt="42" PanelID="Jingli 02" PanelName="Jingli 02 Solar X58C" WattPeak="440" Weight="12" Width="1,10"/> <Panel FriendlyName="@PanelName" Height="1,70" Manufacturer="JA Solar 6" MaxAmpere="11" MaxVolt="42" PanelID="#6 JA 06" PanelName="JA 06 Solar X58C" WattPeak="440" Weight="12" Width="1,10"/>
<Panel FriendlyName="@PanelName" Height="2,70" Manufacturer="Jingli Solar" MaxAmpere="11" MaxVolt="67" PanelID="Jingli 03" PanelName="Jingli 03 Solar T62B" WattPeak="620" Weight="12" Width="1,10"/> <Inverter FriendlyName="@InverterName" InverterID="#1 HM600 01" InverterName="01 HM600 S2 TMax" Manufacturer="HoyMiles" MaxPowerInput="3000,00" MaxPowerInputChoice="2000;4000;6000" MaxPowerOutput="600" NumStrings="2" Weight="28"/>
<Inverter FriendlyName="@InverterName" InverterID="HM600 01" InverterName="01 HM600 S2 TMax" Manufacturer="HoyMiles" MaxPowerInput="4000" MaxPowerInputChoice="2000;4000;6000" MaxPowerOutput="600" NumStrings="2" Weight="28"/> <Inverter FriendlyName="@InverterName" InverterID="#2 HM800 02" InverterName="02 HM800 S2 TMax" Manufacturer="HoyMiles" MaxPowerInput="4000" MaxPowerInputChoice="4000;6000;8000" MaxPowerOutput="800" NumStrings="2" Weight="29"/>
<Inverter FriendlyName="@InverterName" InverterID="HM800 02" InverterName="02 HM800 S2 TMax" Manufacturer="HoyMiles" MaxPowerInput="4000" MaxPowerInputChoice="2000;4000;6000" MaxPowerOutput="800" NumStrings="2" Weight="29"/> <Inverter FriendlyName="@InverterName" InverterID="#3 HM1600 03" InverterName="03 HM1600 S4 TMax" Manufacturer="HoyMiles" MaxPowerInput="9000,00" MaxPowerInputChoice="6000;8000;10000" MaxPowerOutput="1600" NumStrings="4" Weight="32"/>
<Inverter FriendlyName="@InverterName" InverterID="HM1600 03" InverterName="03 HM1600 S4 TMax" Manufacturer="HoyMiles" MaxPowerInput="4000" MaxPowerInputChoice="2000;4000;6000" MaxPowerOutput="1600" NumStrings="4" Weight="32"/> <Inverter FriendlyName="@InverterName" InverterID="#4 D12K 04" InverterName="04 HM600 S2 TMax" Manufacturer="Deye" MaxPowerInput="8000" MaxPowerInputChoice="6000;8000;12000" MaxPowerOutput="600" NumStrings="2" Weight="28"/>
<Inverter FriendlyName="@InverterName" InverterID="D12K 04" InverterName="04 HM600 S2 TMax" Manufacturer="Deye" MaxPowerInput="4000" MaxPowerInputChoice="2000;4000;6000" MaxPowerOutput="600" NumStrings="2" Weight="28"/> <Battery BatteryID="#1 BYD 01" BatteryName="01 BYD T01 Stackable" Capacity="4500" FriendlyName="@BatteryName" Manufacturer="BYD" MaxCurrent="120" MaxVolt="48" Yield="90">
<Battery BatteryID="BYD 01" BatteryName="01 BYD T01 Stackable" Capacity="4500" FriendlyName="@BatteryName" Manufacturer="BYD" MaxCurrent="120" MaxVolt="48" Yield="88"> <Images FrontView="image.png" InstalledView="installed.png" PackageView="package.png"/>
<AdditionalData DataItem="Image" DataValue="image.png"/> <Documents Installation="installation.pdf" Manual="manual.docx"/>
<AdditionalData DataItem="Manual" DataValue="manual.docx"/> <Certificates Certificate="certificate.pdf" Conformity="conformity.pdf"/>
<AdditionalData DataItem="Certificate" DataValue="certificate.pdf"/>
</Battery> </Battery>
<Battery BatteryID="BYD 04" BatteryName="04 BYD T02 Stackable" Capacity="9000" FriendlyName="@BatteryName" Manufacturer="BYD" MaxCurrent="120" MaxVolt="48" Yield="32"/> <Battery BatteryID="#2 BYD 02" BatteryName="02 BYD T02 Stackable" Capacity="9000" FriendlyName="@BatteryName" Manufacturer="BYD" MaxCurrent="120" MaxVolt="48" Yield="94"/>
<Battery BatteryID="GroWatt 05 G2K" BatteryName="05 BYD T01 Stackable" Capacity="4500" FriendlyName="@BatteryName" Manufacturer="PylonTech" MaxCurrent="120" MaxVolt="48" Yield="46"/> <Battery BatteryID="#3 BYD 03" BatteryName="03 BYD T01 Stackable" Capacity="4500" FriendlyName="@BatteryName" Manufacturer="BYD" MaxCurrent="120" MaxVolt="48" Yield="86"/>
<Battery BatteryID="GroWatt 06 G4K" BatteryName="06 BYD T02 Stackable" Capacity="9000" FriendlyName="@BatteryName" Manufacturer="PylonTech" MaxCurrent="120" MaxVolt="48" Yield="94"/> <Battery BatteryID="#4 BYD 04" BatteryName="04 BYD T02 Stackable" Capacity="9000" FriendlyName="@BatteryName" Manufacturer="BYD" MaxCurrent="120" MaxVolt="48" Yield="91"/>
<Battery BatteryID="#5 GroWatt 05 G2K" BatteryName="05 BYD T01 Stackable" Capacity="4500" FriendlyName="@BatteryName" Manufacturer="GroWatt" MaxCurrent="120" MaxVolt="48" Yield="94"/>
<Battery BatteryID="#6 GroWatt 06 G4K" BatteryName="06 BYD T02 Stackable" Capacity="9000" FriendlyName="@BatteryName" Manufacturer="GroWatt" MaxCurrent="120" MaxVolt="48" Yield="49"/>
<Battery BatteryID="#7 Pyne 07 G4K" BatteryName="07 Pyne K7 Stackable" Capacity="9000" FriendlyName="@BatteryName" Manufacturer="PyNe" MaxCurrent="120" MaxVolt="48" Yield="68"/>
</Components> </Components>