Fixed ::setData, part I
This commit is contained in:
@@ -613,18 +613,21 @@ void XQItem::setData(const QVariant& value, int role )
|
|||||||
case Qt::EditRole:
|
case Qt::EditRole:
|
||||||
case XQItem::ContentRole:
|
case XQItem::ContentRole:
|
||||||
{
|
{
|
||||||
QVariant plainText;
|
QVariant newValue;
|
||||||
if( itemType().renderStyle() == XQItem::FormattedStyle)
|
if( itemType().renderStyle() == XQItem::FormattedStyle)
|
||||||
plainText = XQItemType::unFormatFromSI( value.toString() );
|
newValue = XQItemType::unFormatFromSI( value.toString() );
|
||||||
else
|
else
|
||||||
plainText = value;
|
newValue = value;
|
||||||
|
|
||||||
// fallback: wenns keinen content node gibt, dann nehmen wir
|
// fallback: wenns keinen content node gibt, dann nehmen wir
|
||||||
// das standardverfahren.
|
// das standardverfahren.
|
||||||
int role = XQItem::ContentRole;
|
|
||||||
if( !hasContentPtr() )
|
if( !hasContentPtr() )
|
||||||
role = Qt::DisplayRole;
|
return QStandardItem::setData( newValue, XQItem::ContentRole );
|
||||||
QStandardItem::setData( plainText, role );
|
|
||||||
|
// wir nehmen den string pointer
|
||||||
|
const QString* contentPtr = QStandardItem::data( XQItem::ContentRole ).value<const QString*>();
|
||||||
|
//Q_ASSERT(contentPtr);
|
||||||
|
*contentPtr = newValue.toString();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -465,10 +465,7 @@ void XQViewModel::cmdNew( const XQCommand& command )
|
|||||||
XQItem& target = xqItemFromIndex( origin );
|
XQItem& target = xqItemFromIndex( origin );
|
||||||
// current data node
|
// current data node
|
||||||
XQNodePtr node = target.contentNode();
|
XQNodePtr node = target.contentNode();
|
||||||
|
// we create a new data node
|
||||||
qDebug() << " --- node own pos: " << node->own_pos();
|
|
||||||
|
|
||||||
// we create a new data node
|
|
||||||
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() );
|
||||||
|
@@ -241,7 +241,6 @@ namespace znode
|
|||||||
int add_child_at( int idx, const zshared_node& node )
|
int add_child_at( int idx, const zshared_node& node )
|
||||||
{
|
{
|
||||||
// _fixme! was ist, wenn da schon ein elternknoten ist?
|
// _fixme! was ist, wenn da schon ein elternknoten ist?
|
||||||
|
|
||||||
_children.insert(children().begin() + idx, node );
|
_children.insert(children().begin() + idx, node );
|
||||||
node->_parent = this->shared_from_this();
|
node->_parent = this->shared_from_this();
|
||||||
return int(children().size() - 1);
|
return int(children().size() - 1);
|
||||||
@@ -254,10 +253,9 @@ namespace znode
|
|||||||
parent()->add_child_at( offset, this->shared_from_this() );
|
parent()->add_child_at( offset, this->shared_from_this() );
|
||||||
else
|
else
|
||||||
throw std::runtime_error("add_me_at(offset): no parent node");
|
throw std::runtime_error("add_me_at(offset): no parent node");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//! fügt einen shard_ptr von 'mir' in die kinderliste des übergebenen knotens ein
|
//! fügt einen shared_ptr von 'mir' in die kinderliste des übergebenen knotens ein
|
||||||
//! und macht diesen zu meinem elternknoten.
|
//! und macht diesen zu meinem elternknoten.
|
||||||
void add_me_at( int offset, const zshared_node& parent_node )
|
void add_me_at( int offset, const zshared_node& parent_node )
|
||||||
{
|
{
|
||||||
@@ -270,18 +268,17 @@ namespace znode
|
|||||||
{
|
{
|
||||||
throw std::runtime_error("add_me_at(offset,parent): no parent node");
|
throw std::runtime_error("add_me_at(offset,parent): no parent node");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! findet die eigene position im eltern-knoten
|
||||||
int own_pos()
|
int own_pos()
|
||||||
{
|
{
|
||||||
if( parent())
|
if( parent())
|
||||||
return parent()->child_pos( this->shared_from_this() );
|
return parent()->child_pos( this->shared_from_this() );
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//int child_pos(zbasic_node* child)
|
//! findet die postion eines kind-knotens
|
||||||
int child_pos(const zshared_node& child)
|
int child_pos(const zshared_node& child)
|
||||||
{
|
{
|
||||||
//auto pos = std::find_if(children().begin(), children().end(), match_node(child) );
|
//auto pos = std::find_if(children().begin(), children().end(), match_node(child) );
|
||||||
@@ -291,7 +288,7 @@ namespace znode
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
//zshared_node unlink_child( zbasic_node* node )
|
//! findet die postion eines kind-knotens
|
||||||
zshared_node unlink_child( const zshared_node& node )
|
zshared_node unlink_child( const zshared_node& node )
|
||||||
{
|
{
|
||||||
auto it = std::find(_children.begin(), _children.end(), node);
|
auto it = std::find(_children.begin(), _children.end(), node);
|
||||||
@@ -319,11 +316,10 @@ namespace znode
|
|||||||
{
|
{
|
||||||
for( auto child : _children )
|
for( auto child : _children )
|
||||||
{
|
{
|
||||||
qDebug() << " --#- " << child->name() << " : " << child->has_attribute( attrkey, attrvalue );
|
|
||||||
if( child->has_attribute( attrkey, attrvalue ))
|
if( child->has_attribute( attrkey, attrvalue ))
|
||||||
return child;
|
return child;
|
||||||
}
|
}
|
||||||
return zshared_node();
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -334,7 +330,7 @@ namespace znode
|
|||||||
if( child->tag_name() == tagname )
|
if( child->tag_name() == tagname )
|
||||||
return child;
|
return child;
|
||||||
}
|
}
|
||||||
return zshared_node();
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
zshared_node find_child_by_id( int id )
|
zshared_node find_child_by_id( int id )
|
||||||
@@ -344,46 +340,7 @@ namespace znode
|
|||||||
if (child->_id == id)
|
if (child->_id == id)
|
||||||
return child;
|
return child;
|
||||||
}
|
}
|
||||||
return zshared_node();
|
return nullptr;
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void dump(int indent = 0) const
|
|
||||||
{
|
|
||||||
|
|
||||||
// fix_me!
|
|
||||||
qDebug() << std::string(indent * 2, ' ').c_str() << this->to_string();
|
|
||||||
//qDebug() << to_string();
|
|
||||||
//qDebug() << '\n';// std::endl;
|
|
||||||
|
|
||||||
if (!children().empty())
|
|
||||||
{
|
|
||||||
for (auto child : _children)
|
|
||||||
{
|
|
||||||
//qDebug() << " --- type: " << typeid(child).name();
|
|
||||||
child.get()->dump( indent + 1 );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
bool for_each_x( T func, int depth = 0 )
|
|
||||||
//bool for_each( auto func ) const
|
|
||||||
{
|
|
||||||
if( !apply( func, depth ) )
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if( !children().empty() )
|
|
||||||
{
|
|
||||||
for( auto child : _children )
|
|
||||||
{
|
|
||||||
if( !child->for_each( func, depth+1 ) )
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// find ...
|
// find ...
|
||||||
@@ -396,22 +353,6 @@ namespace znode
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class zbasic_node_walker
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
virtual void begin()
|
|
||||||
{}
|
|
||||||
|
|
||||||
template<typename str_t>
|
|
||||||
void for_each_node( zbasic_node<str_t>* node );
|
|
||||||
|
|
||||||
virtual void end()
|
|
||||||
{}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
} //namespace znode
|
} //namespace znode
|
||||||
|
|
||||||
|
|
||||||
|
@@ -2,7 +2,6 @@
|
|||||||
<Components>
|
<Components>
|
||||||
<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"/>
|
<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"/>
|
||||||
<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"/>
|
<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"/>
|
||||||
<Panel/>
|
|
||||||
<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"/>
|
<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"/>
|
||||||
<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 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 FriendlyName="@PanelName" Height="1,70" Manufacturer="JA Solar 5" MaxAmpere="11" MaxVolt="42" PanelID="#5 JA 05" PanelName="JA 05 Solar X58C" WattPeak="440" Weight="12" Width="1,10"/>
|
<Panel FriendlyName="@PanelName" Height="1,70" Manufacturer="JA Solar 5" MaxAmpere="11" MaxVolt="42" PanelID="#5 JA 05" PanelName="JA 05 Solar X58C" WattPeak="440" Weight="12" Width="1,10"/>
|
||||||
|
Reference in New Issue
Block a user