added access on tag_name and tag_value
This commit is contained in:
@@ -33,7 +33,7 @@ XQChildModel::XQChildModel( QObject *parent )
|
||||
|
||||
//! 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 ??
|
||||
@@ -59,6 +59,9 @@ void XQChildModel::setContent( const XQNodePtr& contentRoot )
|
||||
// wir speichern das parent des datenknoten auch in der
|
||||
// section.
|
||||
// contentEntry->parent == _contentRoot, aber halt nur weil das model flach ist
|
||||
|
||||
qDebug() << " --- add section ENTRY: " << key << " TagName: " << contentEntry->attribute("TagName");
|
||||
|
||||
section.setContentRootNode( contentEntry->parent() );
|
||||
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.
|
||||
|
||||
|
@@ -29,7 +29,8 @@ public:
|
||||
explicit XQChildModel(QObject *parent = nullptr);
|
||||
virtual ~XQChildModel() = default;
|
||||
|
||||
void setContent(const XQNodePtr& contentRoot );
|
||||
void addModelData(const XQNodePtr& contentRoot );
|
||||
void addSectionEntry(const QString& key, const XQNodePtr& contentEntry );
|
||||
|
||||
protected:
|
||||
|
||||
|
@@ -355,7 +355,7 @@ void XQMainWindow::loadDocument( const QString& fileName )
|
||||
childModel->initModel( c_ChildModelName );
|
||||
|
||||
// model inhalte laden
|
||||
childModel->setContent( contentRoot->first_child() );
|
||||
childModel->addModelData( contentRoot->first_child() );
|
||||
|
||||
|
||||
}
|
||||
|
@@ -201,13 +201,13 @@ public:
|
||||
void setData(const QVariant &value, int role ) override;
|
||||
|
||||
/*
|
||||
template<class T>
|
||||
template<typename T>
|
||||
void setToVariant(T entry, QtExtUserRoles::NTDataRoles role)
|
||||
{
|
||||
setData(QVariant::fromValue<T>(entry), role);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
template<typename T>
|
||||
T getFromVariant(QtExtUserRoles::NTDataRoles role)
|
||||
{
|
||||
return data(role).value<T>();
|
||||
|
@@ -79,6 +79,9 @@ bool znode::zpayload<QString>::xstr_is_empty(const QString& entry ) const
|
||||
|
||||
//! 'QString' varianten der keystrings.
|
||||
|
||||
template<>
|
||||
const QString znode::zpayload<QString>::cTagName = "TagName";
|
||||
|
||||
template<>
|
||||
const QString znode::zpayload<QString>::cType = "Type";
|
||||
|
||||
|
@@ -98,6 +98,9 @@ void XQViewModel::initModel(const QString& modelName)
|
||||
...
|
||||
|
||||
*/
|
||||
setObjectName( modelName );
|
||||
qDebug() << " --- initModel: " << objectName();
|
||||
|
||||
// model rootnode finden -> <DocumentTreeModel>
|
||||
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 );
|
||||
if( header )
|
||||
{
|
||||
|
||||
XQItemList list = _itemFactory.makeRow( header, nullptr );
|
||||
addSection(list, sectionNode );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -385,6 +386,9 @@ void XQViewModel::cmdPaste( XQCommand& command )
|
||||
// wir pasten das clipboard
|
||||
for (auto& entry : _clipBoard )
|
||||
{
|
||||
|
||||
// WARUM zwei mal klonen ?
|
||||
|
||||
// noch ein clone vom clone erzeugen ...
|
||||
XQNodePtr newNode = entry.contentNode->clone(section.contentRootNode() );
|
||||
newNode->clone(section.contentRootNode() )->add_me_at( nodePos );
|
||||
|
@@ -43,16 +43,16 @@ namespace znode
|
||||
|
||||
|
||||
// forward declaration of base class zbasic_node ...
|
||||
//template<class str_t>
|
||||
//template<typename str_t>
|
||||
//class zbasic_node;
|
||||
|
||||
// ... used here for conveniance typedef
|
||||
//template<class str_t>
|
||||
//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<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>>
|
||||
{
|
||||
|
||||
@@ -400,7 +400,7 @@ namespace znode
|
||||
virtual void begin()
|
||||
{}
|
||||
|
||||
template<class str_t>
|
||||
template<typename str_t>
|
||||
void for_each_node( zbasic_node<str_t>* node );
|
||||
|
||||
virtual void end()
|
||||
|
@@ -40,7 +40,7 @@ model: muss ich wirklich jeden attibute node einzeln angeben?
|
||||
*/
|
||||
namespace znode
|
||||
{
|
||||
template<class str_t>
|
||||
template<typename str_t>
|
||||
class znode_factory
|
||||
{
|
||||
|
||||
|
@@ -21,7 +21,7 @@
|
||||
|
||||
namespace znode
|
||||
{
|
||||
template<class T>
|
||||
template<typename T>
|
||||
struct znode_iterator
|
||||
{
|
||||
using iterator_category = std::forward_iterator_tag;
|
||||
|
@@ -9,7 +9,7 @@
|
||||
|
||||
namespace znode
|
||||
{
|
||||
template<class str_t>
|
||||
template<typename 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
|
||||
{
|
||||
|
||||
@@ -52,7 +52,10 @@ namespace znode
|
||||
// __fixme: should this be a vector? or a maptor?
|
||||
//using zattributes = std::map<str_t, zvalue>;
|
||||
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 cName;// = "Name";
|
||||
static const str_t cValue;// = "Value";
|
||||
@@ -188,6 +191,22 @@ namespace znode
|
||||
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
|
||||
{
|
||||
if( !xstr_is_empty( key ) )
|
||||
@@ -201,7 +220,24 @@ namespace znode
|
||||
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
|
||||
@@ -217,6 +253,7 @@ namespace znode
|
||||
return &result;
|
||||
}
|
||||
}
|
||||
//return fixed_attribute_ptr( key );
|
||||
return &s_dummy_value;
|
||||
}
|
||||
|
||||
@@ -259,7 +296,7 @@ namespace znode
|
||||
};
|
||||
|
||||
// init statics
|
||||
template<class str_t>
|
||||
template<typename str_t>
|
||||
str_t zpayload<str_t>::s_dummy_value;
|
||||
|
||||
}
|
||||
|
@@ -6,7 +6,7 @@
|
||||
|
||||
|
||||
//using znode_vector = std::vector<zplain_node*>;
|
||||
template<class T>
|
||||
template<typename T>
|
||||
class znode_vector : public std::vector<T*>
|
||||
{
|
||||
|
||||
|
@@ -24,7 +24,7 @@
|
||||
* items can be accessed via string keys and int indices.
|
||||
*/
|
||||
|
||||
template<class T>
|
||||
template<typename T>
|
||||
class XQMaptor
|
||||
{
|
||||
|
||||
|
@@ -21,7 +21,7 @@
|
||||
* @brief A XQMaptor implementation for pointers to to data entries.
|
||||
*/
|
||||
|
||||
template<class T>
|
||||
template<typename T>
|
||||
class XQPtrMaptor : public XQMaptor<T*>
|
||||
{
|
||||
|
||||
|
@@ -59,8 +59,8 @@
|
||||
|
||||
<DocumentDetailsModel>
|
||||
|
||||
<Section ContentType="Panel" firz="farz">
|
||||
<Header Marker="Panel">
|
||||
<Section ContentType="Panel" >
|
||||
<Header>
|
||||
<PanelID Caption="Panel" ItemType="HeaderType" />
|
||||
<PanelName Caption="Name" ItemType="HeaderType" Icon="BrowserStop" />
|
||||
<Manufacturer Caption="Manufacturer" ItemType="HeaderType" />
|
||||
@@ -71,7 +71,7 @@
|
||||
<MaxVolt Caption="max. Volt" ItemType="HeaderType" />
|
||||
<MaxAmpere Caption="max. Ampere" ItemType="HeaderType" />
|
||||
</Header>
|
||||
<ModelSheet Marker="Panel">
|
||||
<ModelSheet>
|
||||
<!-- 'Icon' überschreibt den default wert im ItemType und erzeugt damit einen neuen ItemType-->
|
||||
<PanelID ItemType="PlainType" Icon="DesktopIcon"/>
|
||||
<PanelName ItemType="PlainType" Icon="BrowserStop"/>
|
||||
@@ -87,8 +87,8 @@
|
||||
</Section>
|
||||
|
||||
|
||||
<Section ContentType="Inverter" firz="farz">
|
||||
<Header Marker="Inverter">
|
||||
<Section ContentType="Inverter" >
|
||||
<Header >
|
||||
<InverterID Caption="Inverter" ItemType="HeaderType" />
|
||||
<InverterName Caption="Name" ItemType="HeaderType" />
|
||||
<Manufacturer Caption="Manufacturer" ItemType="HeaderType" />
|
||||
@@ -97,7 +97,7 @@
|
||||
<NumStrings Caption="Strings" ItemType="HeaderType" />
|
||||
<Weight Caption="Weight" ItemType="HeaderType" />
|
||||
</Header>
|
||||
<ModelSheet Marker="Inverter">
|
||||
<ModelSheet>
|
||||
<InverterID Caption="Inverter" ItemType="ValueType" />
|
||||
<InverterName Caption="Name" ItemType="ValueType" />
|
||||
<Manufacturer Caption="Manufacturer" ItemType="ValueType" />
|
||||
@@ -108,8 +108,8 @@
|
||||
</ModelSheet>
|
||||
</Section>
|
||||
|
||||
<Section ContentType="Battery" firz="farz">
|
||||
<Header Marker="Battery">
|
||||
<Section ContentType="Battery" >
|
||||
<Header>
|
||||
<BatteryID Caption="Name" ItemType="HeaderType" />
|
||||
<BatteryName Caption="Battery" ItemType="HeaderType" />
|
||||
<Manufacturer Caption="Manufacturer" ItemType="HeaderType" />
|
||||
@@ -118,7 +118,7 @@
|
||||
<MaxCurrent Caption="max. Current" ItemType="HeaderType" />
|
||||
<MaxVolt Caption="max. Volt" ItemType="HeaderType" />
|
||||
</Header>
|
||||
<ModelSheet Marker="Bettery">
|
||||
<ModelSheet>
|
||||
<BatteryID Caption="Battery" ItemType="ValueType" />
|
||||
<BatteryName Caption="Name" ItemType="ValueType" />
|
||||
<Manufacturer Caption="Manufacturer" ItemType="ValueType" />
|
||||
@@ -129,7 +129,4 @@
|
||||
</ModelSheet>
|
||||
</Section>
|
||||
|
||||
|
||||
|
||||
|
||||
</DocumentDetailsModel>
|
Reference in New Issue
Block a user