本文整理汇总了C++中DomItem::parent方法的典型用法代码示例。如果您正苦于以下问题:C++ DomItem::parent方法的具体用法?C++ DomItem::parent怎么用?C++ DomItem::parent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DomItem
的用法示例。
在下文中一共展示了DomItem::parent方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: data
QVariant DomModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
return QVariant();
//role to get full xml path of index
if(role == XPathRole)
{
QString wholeXmlPath;
DomItem *item = static_cast<DomItem*>(index.internalPointer());
if (item==NULL)
qFatal("can't convert domitem from datamodel");
for(;item->parent()!=NULL;item=item->parent())
{
wholeXmlPath=item->node().nodeName()+"/"+wholeXmlPath;
}
wholeXmlPath="/"+wholeXmlPath;
return wholeXmlPath;
}
else if (role == Qt::DisplayRole)
{
DomItem *item = static_cast<DomItem*>(index.internalPointer());
QDomNode node = item->node();
QStringList attributes;
QDomNamedNodeMap attributeMap = node.attributes();
switch (index.column())
{
//name
case 0:
return node.nodeName();
//attributes
case 1:
for (int i = 0; i < attributeMap.count(); ++i)
{
QDomNode attribute = attributeMap.item(i);
attributes << attribute.nodeName() + "=\"" +attribute.nodeValue() + "\"";
}
return attributes.join(" ");
//value
case 2:
return node.nodeValue().split("\n").join(" ");
default:
return QVariant();
}
}
else
return QVariant();
}
示例2: parent
//! [9]
QModelIndex DomModel::parent(const QModelIndex &child) const
{
if (!child.isValid())
return QModelIndex();
DomItem *childItem = static_cast<DomItem*>(child.internalPointer());
DomItem *parentItem = childItem->parent();
if (!parentItem || parentItem == rootItem)
return QModelIndex();
return createIndex(parentItem->row(), 0, parentItem);
}
示例3: SaveToFile
// save to file
void MetricDomModel::SaveToFile(const QModelIndex& selectedItem, const QString& fileName) {
QFile file( fileName );
if( !file.open( QIODevice::WriteOnly ) ) {
printf("ERROR writing to file %s\n", fileName.toStdString().c_str());
return ;
}
DomItem *item = static_cast<DomItem*>(selectedItem.internalPointer());
vector<QDomNode> nodes;
while(item) {
nodes.push_back(item->node());
item = item->parent();
}
SmartPtr<Named_interface> ni =
Root::instance()->interface( metricData_manager + "/metricRegistrar");
MetricDataManager* mDataRegistrar = (MetricDataManager*)(ni.raw_ptr());
// create QDom
QDomDocument doc("save");
QDomElement root = doc.createElement( "MetricDataCollection" );
doc.appendChild( root );
if (nodes.size() == 4) {
// save one property
string metric_name = nodes[2].nodeName().toStdString();
string grid_name = nodes[1].nodeName().toStdString();
string property_name = nodes[0].nodeName().toStdString();
AddQDomForProperty(mDataRegistrar, doc, root, metric_name,grid_name,property_name);
} else if (nodes.size() == 3) {
// save all properties in the grid
string metric_name = nodes[1].nodeName().toStdString();
string grid_name = nodes[0].nodeName().toStdString();
string property_name;
item = static_cast<DomItem*>(selectedItem.internalPointer());
QHash<int,DomItem*>::iterator it;
for (it = item->begin(); it != item->end(); ++it) {
property_name = it.value()->node().nodeName().toStdString();
AddQDomForProperty(mDataRegistrar, doc, root, metric_name,grid_name,property_name);
}
} else if (nodes.size() == 2) {
// save all grids with these metric
string metric_name = nodes[0].nodeName().toStdString();
string grid_name;
string property_name;
DomItem* item1;
item = static_cast<DomItem*>(selectedItem.internalPointer());
QHash<int,DomItem*>::iterator it;
QHash<int,DomItem*>::iterator it1;
for (it = item->begin(); it != item->end(); ++it) {
grid_name = it.value()->node().nodeName().toStdString();
item1 = it.value();
for (it1 = item1->begin(); it1 != item1->end(); ++it1) {
property_name = it1.value()->node().nodeName().toStdString();
AddQDomForProperty(mDataRegistrar, doc, root, metric_name,grid_name,property_name);
}
}
}
QTextStream ts( &file );
ts << doc.toString();
file.close();
}