added access on tag_name and tag_value

This commit is contained in:
2025-08-23 14:37:36 +02:00
parent 769ad2b002
commit 3a5fbad33e
14 changed files with 89 additions and 32 deletions

View File

@@ -33,7 +33,7 @@ XQChildModel::XQChildModel( QObject *parent )
//! erzegt 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 ) void XQChildModel::addModelData( const XQNodePtr& contentRoot )
{ {
// __fix: set object name ?? // __fix: set object name ??
@@ -59,6 +59,9 @@ void XQChildModel::setContent( const XQNodePtr& contentRoot )
// wir speichern das parent des datenknoten auch in der // wir speichern das parent des datenknoten auch in der
// section. // section.
// contentEntry->parent == _contentRoot, aber halt nur weil das model flach ist // contentEntry->parent == _contentRoot, aber halt nur weil das model flach ist
qDebug() << " --- add section ENTRY: " << key << " TagName: " << contentEntry->attribute("TagName");
section.setContentRootNode( contentEntry->parent() ); section.setContentRootNode( contentEntry->parent() );
int newRow = _sections.lastRow(section); int newRow = _sections.lastRow(section);
@@ -73,6 +76,18 @@ void XQChildModel::setContent( const XQNodePtr& contentRoot )
} }
void XQChildModel::addSectionEntry( const QString& key, const XQNodePtr& contentEntry )
{
XQModelSection& section = _sections.at( key );
if(section.isValid() )
{
section.setContentRootNode( contentEntry->parent() );
int newRow = _sections.lastRow(section);
XQNodePtr sheetNode = section.sheetRootNode();
XQItemList list = _itemFactory.makeRow( sheetNode, contentEntry );
insertRow( newRow, list);
}
}
//! erzeugt ein adhoc-contextmenu, je nachdem welche aktionen gerade möflich sind. //! erzeugt ein adhoc-contextmenu, je nachdem welche aktionen gerade möflich sind.

View File

@@ -29,7 +29,8 @@ public:
explicit XQChildModel(QObject *parent = nullptr); explicit XQChildModel(QObject *parent = nullptr);
virtual ~XQChildModel() = default; virtual ~XQChildModel() = default;
void setContent(const XQNodePtr& contentRoot ); void addModelData(const XQNodePtr& contentRoot );
void addSectionEntry(const QString& key, const XQNodePtr& contentEntry );
protected: protected:

View File

@@ -355,7 +355,7 @@ void XQMainWindow::loadDocument( const QString& fileName )
childModel->initModel( c_ChildModelName ); childModel->initModel( c_ChildModelName );
// model inhalte laden // model inhalte laden
childModel->setContent( contentRoot->first_child() ); childModel->addModelData( contentRoot->first_child() );
} }

View File

@@ -201,13 +201,13 @@ public:
void setData(const QVariant &value, int role ) override; void setData(const QVariant &value, int role ) override;
/* /*
template<class T> template<typename T>
void setToVariant(T entry, QtExtUserRoles::NTDataRoles role) void setToVariant(T entry, QtExtUserRoles::NTDataRoles role)
{ {
setData(QVariant::fromValue<T>(entry), role); setData(QVariant::fromValue<T>(entry), role);
} }
template<class T> template<typename T>
T getFromVariant(QtExtUserRoles::NTDataRoles role) T getFromVariant(QtExtUserRoles::NTDataRoles role)
{ {
return data(role).value<T>(); return data(role).value<T>();

View File

@@ -79,6 +79,9 @@ bool znode::zpayload<QString>::xstr_is_empty(const QString& entry ) const
//! 'QString' varianten der keystrings. //! 'QString' varianten der keystrings.
template<>
const QString znode::zpayload<QString>::cTagName = "TagName";
template<> template<>
const QString znode::zpayload<QString>::cType = "Type"; const QString znode::zpayload<QString>::cType = "Type";

View File

@@ -98,6 +98,9 @@ void XQViewModel::initModel(const QString& modelName)
... ...
*/ */
setObjectName( modelName );
qDebug() << " --- initModel: " << objectName();
// model rootnode finden -> <DocumentTreeModel> // model rootnode finden -> <DocumentTreeModel>
XQNodePtr modelSheet = _itemFactory.findModelSheet( modelName ); // throws XQNodePtr modelSheet = _itemFactory.findModelSheet( modelName ); // throws
@@ -108,11 +111,9 @@ void XQViewModel::initModel(const QString& modelName)
const XQNodePtr header = sectionNode->find_child_by_tag_name( c_Header ); const XQNodePtr header = sectionNode->find_child_by_tag_name( c_Header );
if( header ) if( header )
{ {
XQItemList list = _itemFactory.makeRow( header, nullptr ); XQItemList list = _itemFactory.makeRow( header, nullptr );
addSection(list, sectionNode ); addSection(list, sectionNode );
} }
} }
} }
@@ -385,6 +386,9 @@ void XQViewModel::cmdPaste( XQCommand& command )
// wir pasten das clipboard // wir pasten das clipboard
for (auto& entry : _clipBoard ) for (auto& entry : _clipBoard )
{ {
// WARUM zwei mal klonen ?
// noch ein clone vom clone erzeugen ... // noch ein clone vom clone erzeugen ...
XQNodePtr newNode = entry.contentNode->clone(section.contentRootNode() ); XQNodePtr newNode = entry.contentNode->clone(section.contentRootNode() );
newNode->clone(section.contentRootNode() )->add_me_at( nodePos ); newNode->clone(section.contentRootNode() )->add_me_at( nodePos );

View File

@@ -43,16 +43,16 @@ namespace znode
// forward declaration of base class zbasic_node ... // forward declaration of base class zbasic_node ...
//template<class str_t> //template<typename str_t>
//class zbasic_node; //class zbasic_node;
// ... used here for conveniance typedef // ... used here for conveniance typedef
//template<class str_t> //template<typename str_t>
//using zshared_node = std::shared_ptr<zbasic_node<str_t>>; //using zshared_node = std::shared_ptr<zbasic_node<str_t>>;
//! einfache tree-klasse, besonderheit: der nutzlast-string-type ist templated. //! einfache tree-klasse, besonderheit: der nutzlast-string-type ist templated.
template<class str_t> 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>>
{ {
@@ -400,7 +400,7 @@ namespace znode
virtual void begin() virtual void begin()
{} {}
template<class str_t> template<typename str_t>
void for_each_node( zbasic_node<str_t>* node ); void for_each_node( zbasic_node<str_t>* node );
virtual void end() virtual void end()

View File

@@ -40,7 +40,7 @@ model: muss ich wirklich jeden attibute node einzeln angeben?
*/ */
namespace znode namespace znode
{ {
template<class str_t> template<typename str_t>
class znode_factory class znode_factory
{ {

View File

@@ -21,7 +21,7 @@
namespace znode namespace znode
{ {
template<class T> template<typename T>
struct znode_iterator struct znode_iterator
{ {
using iterator_category = std::forward_iterator_tag; using iterator_category = std::forward_iterator_tag;

View File

@@ -9,7 +9,7 @@
namespace znode namespace znode
{ {
template<class str_t> template<typename str_t>
class zstringmap : public std::map<str_t,str_t> class zstringmap : public std::map<str_t,str_t>
{ {
@@ -38,7 +38,7 @@ namespace znode
}; };
template<class str_t> template<typename str_t>
class zpayload class zpayload
{ {
@@ -52,7 +52,10 @@ namespace znode
// __fixme: should this be a vector? or a maptor? // __fixme: should this be a vector? or a maptor?
//using zattributes = std::map<str_t, zvalue>; //using zattributes = std::map<str_t, zvalue>;
using zattributes = zstringmap<str_t>; using zattributes = zstringmap<str_t>;
using callmap_ref = std::map<str_t, str_cref (zpayload<str_t>::*)() const>;
using callmap_ptr = std::map<str_t, str_ptr (zpayload<str_t>::*)() const>;
static const str_t cTagName; // = "TagName";
static const str_t cType;// = "Type"; static const str_t cType;// = "Type";
static const str_t cName;// = "Name"; static const str_t cName;// = "Name";
static const str_t cValue;// = "Value"; static const str_t cValue;// = "Value";
@@ -188,6 +191,22 @@ namespace znode
return true; return true;
} }
const zvalue& fixed_attribute(str_cref key ) const
{
static callmap_ref s_fixed_attributes
{
{ cTagName, &zpayload::tag_name },
{ cValue, &zpayload::tag_value }
};
auto it = s_fixed_attributes.find(key);
if (it != s_fixed_attributes.end())
return (this->*(it->second))();
return s_dummy_value;
}
const zvalue& attribute(str_cref key ) const const zvalue& attribute(str_cref key ) const
{ {
if( !xstr_is_empty( key ) ) if( !xstr_is_empty( key ) )
@@ -201,7 +220,24 @@ namespace znode
return result; return result;
} }
} }
return s_dummy_value; //return s_dummy_value;
return fixed_attribute( key );
}
const zvalue& fixed_attribute_ptr(str_cref key ) const
{
static callmap_ptr s_fixed_attributes_ptr
{
{ cTagName, &zpayload<str_t>::tag_name_ptr },
{ cValue, &zpayload<str_t>::tag_value_ptr }
};
auto it = s_fixed_attributes_ptr.find(key);
if (it != s_fixed_attributes_ptr.end() )
(this->*(it->second))();
return &s_dummy_value;
} }
const zvalue* attribute_ptr(str_cref key ) const const zvalue* attribute_ptr(str_cref key ) const
@@ -217,6 +253,7 @@ namespace znode
return &result; return &result;
} }
} }
//return fixed_attribute_ptr( key );
return &s_dummy_value; return &s_dummy_value;
} }
@@ -259,7 +296,7 @@ namespace znode
}; };
// init statics // init statics
template<class str_t> template<typename str_t>
str_t zpayload<str_t>::s_dummy_value; str_t zpayload<str_t>::s_dummy_value;
} }

View File

@@ -6,7 +6,7 @@
//using znode_vector = std::vector<zplain_node*>; //using znode_vector = std::vector<zplain_node*>;
template<class T> template<typename T>
class znode_vector : public std::vector<T*> class znode_vector : public std::vector<T*>
{ {

View File

@@ -24,7 +24,7 @@
* items can be accessed via string keys and int indices. * items can be accessed via string keys and int indices.
*/ */
template<class T> template<typename T>
class XQMaptor class XQMaptor
{ {

View File

@@ -21,7 +21,7 @@
* @brief A XQMaptor implementation for pointers to to data entries. * @brief A XQMaptor implementation for pointers to to data entries.
*/ */
template<class T> template<typename T>
class XQPtrMaptor : public XQMaptor<T*> class XQPtrMaptor : public XQMaptor<T*>
{ {

View File

@@ -59,8 +59,8 @@
<DocumentDetailsModel> <DocumentDetailsModel>
<Section ContentType="Panel" firz="farz"> <Section ContentType="Panel" >
<Header Marker="Panel"> <Header>
<PanelID Caption="Panel" ItemType="HeaderType" /> <PanelID Caption="Panel" ItemType="HeaderType" />
<PanelName Caption="Name" ItemType="HeaderType" Icon="BrowserStop" /> <PanelName Caption="Name" ItemType="HeaderType" Icon="BrowserStop" />
<Manufacturer Caption="Manufacturer" ItemType="HeaderType" /> <Manufacturer Caption="Manufacturer" ItemType="HeaderType" />
@@ -71,7 +71,7 @@
<MaxVolt Caption="max. Volt" ItemType="HeaderType" /> <MaxVolt Caption="max. Volt" ItemType="HeaderType" />
<MaxAmpere Caption="max. Ampere" ItemType="HeaderType" /> <MaxAmpere Caption="max. Ampere" ItemType="HeaderType" />
</Header> </Header>
<ModelSheet Marker="Panel"> <ModelSheet>
<!-- 'Icon' überschreibt den default wert im ItemType und erzeugt damit einen neuen ItemType--> <!-- 'Icon' überschreibt den default wert im ItemType und erzeugt damit einen neuen ItemType-->
<PanelID ItemType="PlainType" Icon="DesktopIcon"/> <PanelID ItemType="PlainType" Icon="DesktopIcon"/>
<PanelName ItemType="PlainType" Icon="BrowserStop"/> <PanelName ItemType="PlainType" Icon="BrowserStop"/>
@@ -87,8 +87,8 @@
</Section> </Section>
<Section ContentType="Inverter" firz="farz"> <Section ContentType="Inverter" >
<Header Marker="Inverter"> <Header >
<InverterID Caption="Inverter" ItemType="HeaderType" /> <InverterID Caption="Inverter" ItemType="HeaderType" />
<InverterName Caption="Name" ItemType="HeaderType" /> <InverterName Caption="Name" ItemType="HeaderType" />
<Manufacturer Caption="Manufacturer" ItemType="HeaderType" /> <Manufacturer Caption="Manufacturer" ItemType="HeaderType" />
@@ -97,7 +97,7 @@
<NumStrings Caption="Strings" ItemType="HeaderType" /> <NumStrings Caption="Strings" ItemType="HeaderType" />
<Weight Caption="Weight" ItemType="HeaderType" /> <Weight Caption="Weight" ItemType="HeaderType" />
</Header> </Header>
<ModelSheet Marker="Inverter"> <ModelSheet>
<InverterID Caption="Inverter" ItemType="ValueType" /> <InverterID Caption="Inverter" ItemType="ValueType" />
<InverterName Caption="Name" ItemType="ValueType" /> <InverterName Caption="Name" ItemType="ValueType" />
<Manufacturer Caption="Manufacturer" ItemType="ValueType" /> <Manufacturer Caption="Manufacturer" ItemType="ValueType" />
@@ -108,8 +108,8 @@
</ModelSheet> </ModelSheet>
</Section> </Section>
<Section ContentType="Battery" firz="farz"> <Section ContentType="Battery" >
<Header Marker="Battery"> <Header>
<BatteryID Caption="Name" ItemType="HeaderType" /> <BatteryID Caption="Name" ItemType="HeaderType" />
<BatteryName Caption="Battery" ItemType="HeaderType" /> <BatteryName Caption="Battery" ItemType="HeaderType" />
<Manufacturer Caption="Manufacturer" ItemType="HeaderType" /> <Manufacturer Caption="Manufacturer" ItemType="HeaderType" />
@@ -118,7 +118,7 @@
<MaxCurrent Caption="max. Current" ItemType="HeaderType" /> <MaxCurrent Caption="max. Current" ItemType="HeaderType" />
<MaxVolt Caption="max. Volt" ItemType="HeaderType" /> <MaxVolt Caption="max. Volt" ItemType="HeaderType" />
</Header> </Header>
<ModelSheet Marker="Bettery"> <ModelSheet>
<BatteryID Caption="Battery" ItemType="ValueType" /> <BatteryID Caption="Battery" ItemType="ValueType" />
<BatteryName Caption="Name" ItemType="ValueType" /> <BatteryName Caption="Name" ItemType="ValueType" />
<Manufacturer Caption="Manufacturer" ItemType="ValueType" /> <Manufacturer Caption="Manufacturer" ItemType="ValueType" />
@@ -129,7 +129,4 @@
</ModelSheet> </ModelSheet>
</Section> </Section>
</DocumentDetailsModel> </DocumentDetailsModel>