本文整理汇总了C++中DomItem::node方法的典型用法代码示例。如果您正苦于以下问题:C++ DomItem::node方法的具体用法?C++ DomItem::node怎么用?C++ DomItem::node使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DomItem
的用法示例。
在下文中一共展示了DomItem::node方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: removeSlot
void KUI_project::removeSlot()
{
QModelIndex current = usersList->selectionModel()->currentIndex();
DomItem *item = static_cast<DomItem*>( current.internalPointer() );
if ( current.isValid() && item->node().nodeName()=="user" ) {
qDebug() << "Removing: " << item->node().nodeName();
model->removeRows( current.row(), 1, current.parent() );
}
usersList->update();
}
示例3: data
//! [3]
QVariant DomModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
return QVariant();
if (role != Qt::DisplayRole)
return QVariant();
DomItem *item = static_cast<DomItem*>(index.internalPointer());
QDomNode node = item->node();
//! [3] //! [4]
QStringList attributes;
QDomNamedNodeMap attributeMap = node.attributes();
switch (index.column()) {
case 0:
return node.nodeName();
case 1:
for (int i = 0; i < attributeMap.count(); ++i) {
QDomNode attribute = attributeMap.item(i);
attributes << attribute.nodeName() + "=\""
+attribute.nodeValue() + "\"";
}
return attributes.join(" ");
case 2:
return node.nodeValue().split("\n").join(" ");
default:
return QVariant();
}
}
示例4: data
QVariant MetricDomModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
return QVariant();
if (role != Qt::DisplayRole)
return QVariant();
DomItem *item = static_cast<DomItem*>(index.internalPointer());
QDomNode node = item->node();
QStringList attributes;
QDomNamedNodeMap attributeMap = node.attributes();
switch (index.column()) {
case 0:
return node.nodeName();
case 1:
if( !attributeMap.contains("Type") ) {
return QVariant();
}
return attributeMap.namedItem("Type").nodeValue();
case 2:
if( !attributeMap.contains("Format") ) {
return QVariant();
}
return attributeMap.namedItem("Format").nodeValue();
default:
return QVariant();
}
}
示例5: addSlot
void KUI_project::addSlot()
{
QModelIndex sessionIndex = model->index(0, 0,QModelIndex());
DomItem *sessionItem = static_cast<DomItem*> ( sessionIndex.internalPointer() );
qDebug() << sessionItem->node().nodeName();
model->insertRows(0,1, sessionIndex);
usersList->update();
}
示例6: rowCount
int DomModel::rowCount(const QModelIndex &parent) const
{
DomItem *parentItem;
if (!parent.isValid())
parentItem = rootItem;
else
parentItem = static_cast<DomItem*>(parent.internalPointer());
return parentItem->node().childNodes().count();
}
示例7: rowCount
int QAbstractXmlTreeModel::rowCount(const QModelIndex &parent) const
{
DomItem *item = 0;
if (!parent.isValid())
item = dqaxtm->m_RootItem;
else
item = static_cast<DomItem*>(parent.internalPointer());
return item->node().childNodes().count();
}
示例8: node
QDomNode QAbstractXmlTreeModel::node(const QModelIndex &index) const
{
if (!index.isValid())
return dqaxtm->m_RootNode;
DomItem *domItem = static_cast<DomItem*>(index.internalPointer());
if (!domItem)
return dqaxtm->m_RootNode;
return domItem->node();
}
示例9: 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();
}