/*! Returns wheter object \a e defines attribute \a name or not. \sa readAttribute() */ bool DomTool::hasAttribute( const QDomElement& e, const QString& name ) { QDomElement n; for ( n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) { if ( n.tagName() == "attribute" ) { if ( n.attribute( "name" ) != name ) continue; return TRUE; } } return FALSE; }
/*! Returns the contents of attribute \a name of object \a e as variant or the variant passed as \a defValue if the attribute does not exist. \sa hasAttribute() */ QVariant DomTool::readAttribute( const QDomElement& e, const QString& name, const QVariant& defValue, QString& comment ) { QDomElement n; for ( n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) { if ( n.tagName() == "attribute" ) { if ( n.attribute( "name" ) != name ) continue; return elementToVariant( n.firstChild().toElement(), defValue, comment ); } } return defValue; }
/* Returns whether object \a e defines attribute \a name or not. \sa readAttribute() */ bool DomTool::hasAttribute(const QDomElement& e, const QString& name) { QDomElement n; for (n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement()) { if (n.tagName() == QLatin1String("attribute")) { if (n.attribute(QLatin1String("name")) != name) continue; return true; } } return false; }
/*! Creates a colorgroup with name \a name from the color group \a cg */ void Ui3Reader::createColorGroupImpl(const QString& name, const QDomElement& e) { int r = -1; QDomElement n = e.firstChild().toElement(); QString color; Color white; white.init(255, 255, 255); Color black; black.init(0, 0, 0); while (!n.isNull()) { if (n.tagName() == QLatin1String("color")) { r++; Color col = DomTool::readColor(n); color = QLatin1String("QColor(%1, %2, %3)"); color = color.arg(col.red).arg(col.green).arg(col.blue); if (col == white) color = QLatin1String("white"); else if (col == black) color = QLatin1String("black"); if (n.nextSibling().toElement().tagName() != QLatin1String("pixmap")) { out << indent << name << ".setColor(QColorGroup::" << ColorRole[r] << ", " << color << ");" << endl; } } else if (n.tagName() == QLatin1String("pixmap")) { QString pixmap = n.firstChild().toText().data(); if (!pixmapLoaderFunction.isEmpty()) { pixmap.prepend(pixmapLoaderFunction + QLatin1Char('(') + QLatin1String(externPixmaps ? "\"" : "")); pixmap.append(QLatin1String(externPixmaps ? "\"" : "") + QLatin1Char(')')); } out << indent << name << ".setBrush(QColorGroup::" << ColorRole[r] << ", QBrush(" << color << ", " << pixmap << "));" << endl; } n = n.nextSibling().toElement(); } }
void Uic::createActionImpl( const QDomElement &n, const QString &parent ) { for ( QDomElement ae = n; !ae.isNull(); ae = ae.nextSibling().toElement() ) { QString objName = registerObject( getObjectName( ae ) ); if ( ae.tagName() == "action" ) out << indent << objName << " = new QAction( " << parent << ", \"" << objName << "\" );" << endl; else if ( ae.tagName() == "actiongroup" ) out << indent << objName << " = new QActionGroup( " << parent << ", \"" << objName << "\" );" << endl; else continue; bool subActionsDone = FALSE; bool hasMenuText = FALSE; QString actionText; for ( QDomElement n2 = ae.firstChild().toElement(); !n2.isNull(); n2 = n2.nextSibling().toElement() ) { if ( n2.tagName() == "property" ) { bool stdset = stdsetdef; if ( n2.hasAttribute( "stdset" ) ) stdset = toBool( n2.attribute( "stdset" ) ); QString prop = n2.attribute( "name" ); if ( prop == "name" ) continue; QString value = setObjectProperty( "QAction", objName, prop, n2.firstChild().toElement(), stdset ); if ( value.isEmpty() ) continue; QString call = objName + "->"; if ( stdset ) { call += mkStdSet( prop ) + "( "; } else { call += "setProperty( \"" + prop + "\", "; } call += value + " );"; if ( prop == "menuText" ) hasMenuText = TRUE; else if ( prop == "text" ) actionText = value; if ( n2.firstChild().toElement().tagName() == "string" ) { trout << indent << call << endl; } else { out << indent << call << endl; } } else if ( !subActionsDone && ( n2.tagName() == "actiongroup" || n2.tagName() == "action" ) ) { createActionImpl( n2, objName ); subActionsDone = TRUE; } } // workaround for loading pre-3.3 files expecting bogus QAction behavior if ( !hasMenuText && !actionText.isEmpty() && uiFileVersion < "3.3" ) trout << indent << objName << "->setMenuText(" << actionText << ");" << endl; } }
void Uic::createActionDecl( const QDomElement& e ) { QString objClass = e.tagName() == "action" ? "QAction" : "QActionGroup"; QString objName = getObjectName( e ); if ( objName.isEmpty() ) return; out << " " << objClass << "* " << objName << ";" << endl; if ( e.tagName() == "actiongroup" ) { for ( QDomElement n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) { if ( n.tagName() == "action" || n.tagName() == "actiongroup" ) createActionDecl( n ); } } }
bool LinePath::loadFromXMI( QDomElement & qElement ) { QDomNode node = qElement.firstChild(); QDomElement startElement = node.toElement(); if( startElement.isNull() || startElement.tagName() != "startpoint" ) return false; QString x = startElement.attribute( "startx", "0" ); int nX = x.toInt(); QString y = startElement.attribute( "starty", "0" ); int nY = y.toInt(); QPoint startPoint( nX, nY ); node = startElement.nextSibling(); QDomElement endElement = node.toElement(); if( endElement.isNull() || endElement.tagName() != "endpoint" ) return false; x = endElement.attribute( "endx", "0" ); nX = x.toInt(); y = endElement.attribute( "endy", "0" ); nY = y.toInt(); QPoint endPoint( nX, nY ); setStartEndPoints( startPoint, endPoint ); QPoint point; node = endElement.nextSibling(); QDomElement element = node.toElement(); int i = 1; while( !element.isNull() ) { if( element.tagName() == "point" ) { x = element.attribute( "x", "0" ); y = element.attribute( "y", "0" ); point.setX( x.toInt() ); point.setY( y.toInt() ); insertPoint( i++, point ); } node = element.nextSibling(); element = node.toElement(); } return true; }
/* Returns a list of the names of the properties of the given \a type found in the element \a e. */ QStringList DomTool::propertiesOfType(const QDomElement& e, const QString& type) { QStringList result; QDomElement n; for (n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement()) { if (n.tagName() == QLatin1String("property")) { QDomElement n2 = n.firstChild().toElement(); if (n2.tagName() == type) result += n.attribute(QLatin1String("name")); } } return result; }
void KWDWriter::cleanUpParagraph(const QDomElement ¶graph) { QDomElement e = paragraph.elementsByTagName("FORMATS").item(0).toElement(); if (e.isNull()) { kWarning(30503) << "cleanup : no valid paragraph"; return; } for (QDomElement k = e.firstChild().toElement();!k.isNull();k = k.nextSibling().toElement()) { if (k.attribute("len", QString()).isNull()) { e.removeChild(k); cleanUpParagraph(paragraph); return; } } }
/*! Auxiliary function to load a color group. The colorgroup must not contain pixmaps. */ QColorGroup Uic::loadColorGroup( const QDomElement &e ) { QColorGroup cg; int r = -1; QDomElement n = e.firstChild().toElement(); QColor col; while ( !n.isNull() ) { if ( n.tagName() == "color" ) { r++; cg.setColor(( QColorGroup::ColorRole )r, ( col = DomTool::readColor( n ) ) ); } n = n.nextSibling().toElement(); } return cg; }
QStringList DomUtil::readListEntry(const QDomDocument &doc, const QString &path, const QString &tag) { QStringList list; QDomElement el = elementByPath(doc, path); QDomElement subEl = el.firstChild().toElement(); while (!subEl.isNull()) { if (subEl.tagName() == tag) list << subEl.firstChild().toText().data(); subEl = subEl.nextSibling().toElement(); } return list; }
/*! Extracts the forms class name from \a e */ QString Uic::getFormClassName( const QDomElement& e ) { QDomElement n; QString cn; for ( n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) { if ( n.tagName() == "class" ) { QString s = n.firstChild().toText().data(); int i; while (( i = s.find( ' ' ) ) != -1 ) s[i] = '_'; cn = s; } } return cn; }
/*! Returns the contents of property \a name of object \a e as variant or the variant passed as \a defValue if the property does not exist. \sa hasProperty() */ QVariant DomTool::readProperty( const QDomElement& e, const QString& name, const QVariant& defValue, QString* comment ) { QDomElement n; for ( n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) { if ( n.tagName() == "property" ) { QDomElement n2 = n.firstChild().toElement(); if ( n2.tagName() == "name" ) { QString prop = n2.firstChild().toText().data(); if ( prop == name ) return elementToVariant( n2.nextSibling().toElement(), defValue, comment ); } } } return defValue; }
void Uic::createPopupMenuImpl( const QDomElement &e, const QString &parentClass, const QString &parent ) { int i = 0; for ( QDomElement n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) { if ( n.tagName() == "action" || n.tagName() == "actiongroup" ) { QDomElement n2 = n.nextSibling().toElement(); if ( n2.tagName() == "item" ) { // the action has a sub menu QString itemName = n2.attribute( "name" ); QString itemText = n2.attribute( "text" ); out << indent << itemName << " = new QPopupMenu( this );" << endl; out << indent << parent << "->insertItem( " << n.attribute( "name" ) << "->iconSet(), "; out << trcall( itemText ) << ", " << itemName << " );" << endl; trout << indent << parent << "->changeItem( " << parent << "->idAt( " << i << " ), "; trout << trcall( itemText ) << " );" << endl; createPopupMenuImpl( n2, parentClass, itemName ); n = n2; } else { out << indent << n.attribute( "name" ) << "->addTo( " << parent << " );" << endl; } } else if ( n.tagName() == "separator" ) { out << indent << parent << "->insertSeparator();" << endl; } ++i; } }
/*! Returns wheter object \a e defines property \a name or not. \sa readProperty() */ bool DomTool::hasProperty( const QDomElement& e, const QString& name ) { QDomElement n; for ( n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) { if ( n.tagName() == "property" ) { QDomElement n2 = n.firstChild().toElement(); if ( n2.tagName() == "name" ) { QString prop = n2.firstChild().toText().data(); if ( prop == name ) return TRUE; } } } return FALSE; }
/*! Extracts the forms class name from \a e */ QString Ui3Reader::getFormClassName(const QDomElement& e) { QDomElement n; QString cn; for (n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement()) { if (n.tagName() == QLatin1String("class")) { QString s = n.firstChild().toText().data(); int i; while ((i = s.indexOf(QLatin1Char(' '))) != -1) s[i] = QLatin1Char('_'); cn = s; } } return cn; }
void Ui3Reader::createFormImpl(const QDomElement& e, const QString& form, const QString& connection, const QString& table) { if (e.tagName() == QLatin1String("widget") && e.attribute(QLatin1String("class")) != QLatin1String("QDataTable")) { QString field = getDatabaseInfo(e, QLatin1String("field")); if (!field.isEmpty()) { if (isWidgetInTable(e, connection, table)) out << indent << form << "Form->insert(" << getObjectName(e) << ", " << fixString(field) << ");" << endl; } } QDomElement n; for (n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement()) { createFormImpl(n, form, connection, table); } }
QT_BEGIN_NAMESPACE /*! Extracts a named object property from \a e. */ QDomElement Ui3Reader::getObjectProperty( const QDomElement& e, const QString& name ) { QDomElement n; for ( n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) { if ( n.tagName() == QLatin1String("property") && n.toElement().attribute(QLatin1String("name")) == name ) return n; } return n; }
/*! Auxiliary function to load a color group. The colorgroup must not contain pixmaps. */ ColorGroup Ui3Reader::loadColorGroup(const QDomElement &e) { ColorGroup cg; int r = -1; QDomElement n = e.firstChild().toElement(); Color col; while (!n.isNull()) { if (n.tagName() == QLatin1String("color")) { r++; col = DomTool::readColor(n); cg.append(qMakePair(r, col)); } n = n.nextSibling().toElement(); } return cg; }
QColor DomTool::readColor( const QDomElement &e ) { QDomElement n = e.firstChild().toElement(); int r= 0, g = 0, b = 0; while ( !n.isNull() ) { if ( n.tagName() == "red" ) r = n.firstChild().toText().data().toInt(); else if ( n.tagName() == "green" ) g = n.firstChild().toText().data().toInt(); else if ( n.tagName() == "blue" ) b = n.firstChild().toText().data().toInt(); n = n.nextSibling().toElement(); } return QColor( r, g, b ); }
TNeuron::TNeuron(const QDomElement &neuron) { QDomElement weight = neuron.firstChild().toElement(); while (!weight.isNull()) { if(weight.tagName() == "detectivity") { double newDetectivity = weight.attribute("value").toDouble(); mDetectivity = newDetectivity; } else if (weight.tagName() == "weight") { double newWeight = weight.attribute("value").toDouble(); mSynapticWeights << newWeight; } else Q_ASSERT(false); weight = weight.nextSibling().toElement(); } Q_ASSERT(mSynapticWeights.size() == neuron.attribute("countOfWeights").toDouble()); }
DomUtil::TupleList DomUtil::readTupleListEntry(const QDomDocument &doc, const QString &path, const QString &tag, const QStringList &attrList) { TupleList list; QDomElement el = elementByPath(doc, path); QDomElement subEl = el.firstChild().toElement(); while (!subEl.isNull()) { if (subEl.tagName() == tag) { QStringList l; for(QValueListConstIterator<QString> it = attrList.begin(); it != attrList.end(); ++it) l << subEl.attribute(*it); list << l; } subEl = subEl.nextSibling().toElement(); } return list; }
//--------------------------------------------------------------------------- // fromDomElement // //! Reset the object based on the contents of a DOM element representing a //! search spec. // //! @return true if successful, false otherwise //--------------------------------------------------------------------------- bool SearchSpec::fromDomElement(const QDomElement& element) { if (element.tagName() != XML_TOP_ELEMENT) return false; SearchSpec tmpSpec; if (element.hasAttribute(XML_VERSION_ATTR)) { bool ok; tmpSpec.version = element.attribute(XML_VERSION_ATTR).toInt(&ok); if (!ok) return false; } QDomElement elem = element.firstChild().toElement(); if (elem.isNull() || (elem.tagName() != XML_CONDITIONS_ELEMENT)) return false; elem = elem.firstChild().toElement(); if (elem.isNull() || ((elem.tagName() != XML_CONJUNCTION_ELEMENT) && (elem.tagName() != XML_DISJUNCTION_ELEMENT))) { return false; } tmpSpec.conjunction = (elem.tagName() == XML_CONJUNCTION_ELEMENT); for (elem = elem.firstChild().toElement(); !elem.isNull(); elem = elem.nextSibling().toElement()) { SearchCondition condition; if (!condition.fromDomElement(elem)) return false; tmpSpec.conditions.append(condition); } if (tmpSpec.conditions.empty()) return false; tmpSpec.update(); *this = tmpSpec; return true; }
Color DomTool::readColor(const QDomElement &e) { QDomElement n = e.firstChild().toElement(); int r= 0, g = 0, b = 0; while (!n.isNull()) { if (n.tagName() == QLatin1String("red")) r = n.firstChild().toText().data().toInt(); else if (n.tagName() == QLatin1String("green")) g = n.firstChild().toText().data().toInt(); else if (n.tagName() == QLatin1String("blue")) b = n.firstChild().toText().data().toInt(); n = n.nextSibling().toElement(); } Color c; c.init(r, g, b); return c; }
void WatchRoot::restorePartialProjectSession(const QDomElement* el) { QDomDocument domDoc = el->ownerDocument(); if (domDoc.isNull()) { return; } QDomElement watchEl = el->namedItem("watchExpressions").toElement(); QDomElement subEl = watchEl.firstChild().toElement(); while (!subEl.isNull()) { new WatchVarItem(this, subEl.firstChild().toText().data(), UNKNOWN_TYPE); subEl = subEl.nextSibling().toElement(); } return; }
DomUtil::PairList DomUtil::readPairListEntry(const QDomDocument &doc, const QString &path, const QString &tag, const QString &firstAttr, const QString &secondAttr) { PairList list; QDomElement el = elementByPath(doc, path); QDomElement subEl = el.firstChild().toElement(); while (!subEl.isNull()) { if (subEl.tagName() == tag) { QString first = subEl.attribute(firstAttr); QString second = subEl.attribute(secondAttr); list << Pair(first, second); } subEl = subEl.nextSibling().toElement(); } return list; }
/** * Helper function to loadModel * * @param anArea that will contain a waitingList with patients parsed in this step * * @param n is an xml node of the first patient in the waiting List * */ void StorageHandler::parseWaitingList(Area* anArea,QDomNode* n){ QDomElement e; QDomNode node; while(!n->isNull()) { e = n->toElement(); QString healthCardNumber = e.attribute( "healthCardNumber", "1111111111" ); QString firstName = e.attribute( "firstName", "FirstName" ); QString lastName = e.attribute( "lastName", "LastName" ); QDate dateAdded = Convenience::fromXML(e.attribute("dateAdded", "2000-02-02")); Logger::infoMessage("storageHandler","parseWaitingList", "Patient added to waiting list name= ", firstName); anArea->addPatientToWaitingList(healthCardNumber, firstName, lastName, dateAdded); node = e.nextSibling(); n = &(node); } }
QDomElement Ui3Reader::parse(const QDomDocument &doc) { root = doc.firstChild().toElement(); widget = QDomElement(); pixmapLoaderFunction = getPixmapLoaderFunction(doc.firstChild().toElement()); nameOfClass = getFormClassName(doc.firstChild().toElement()); uiFileVersion = doc.firstChild().toElement().attribute(QLatin1String("version")); stdsetdef = toBool(doc.firstChild().toElement().attribute(QLatin1String("stdsetdef"))); if (doc.firstChild().isNull() || doc.firstChild().firstChild().isNull()) return widget; QDomElement e = doc.firstChild().firstChild().toElement(); while (!e.isNull()) { if (e.tagName() == QLatin1String("widget")) { widget = e; } else if (e.tagName() == QLatin1String("pixmapinproject")) { externPixmaps = true; } else if (e.tagName() == QLatin1String("layoutdefaults")) { defSpacing = e.attribute(QLatin1String("spacing"), defSpacing.toString()); defMargin = e.attribute(QLatin1String("margin"), defMargin.toString()); } else if (e.tagName() == QLatin1String("layoutfunctions")) { defSpacing = e.attribute(QLatin1String("spacing"), defSpacing.toString()); bool ok; defSpacing.toInt(&ok); if (!ok) { QString buf = defSpacing.toString(); defSpacing = buf.append(QLatin1String("()")); } defMargin = e.attribute(QLatin1String("margin"), defMargin.toString()); defMargin.toInt(&ok); if (!ok) { QString buf = defMargin.toString(); defMargin = buf.append(QLatin1String("()")); } } e = e.nextSibling().toElement(); } return widget; }
QString Uic::createListViewColumnImpl( const QDomElement &e, const QString &parent, QString *value ) { QDomElement n = e.firstChild().toElement(); QString txt; QString com; QString pix; bool clickable = FALSE, resizable = FALSE; while ( !n.isNull() ) { if ( n.tagName() == "property" ) { QString attrib = n.attribute("name"); QVariant v = DomTool::elementToVariant( n.firstChild().toElement(), QVariant() ); if ( attrib == "text" ) { txt = v.toString(); com = getComment( n ); } else if ( attrib == "pixmap" ) { pix = v.toString(); if ( !pix.isEmpty() && !pixmapLoaderFunction.isEmpty() ) { pix.prepend( pixmapLoaderFunction + "( " + QString( externPixmaps ? "\"" : "" ) ); pix.append( QString( externPixmaps ? "\"" : "" ) + " )" ); } } else if ( attrib == "clickable" ) clickable = v.toBool(); else if ( attrib == "resizable" || attrib == "resizeable" ) resizable = v.toBool(); } n = n.nextSibling().toElement(); } if ( value ) *value = trcall( txt, com ); QString s; s = indent + parent + "->addColumn( " + trcall( txt, com ) + " );\n"; if ( !pix.isEmpty() ) s += indent + parent + "->header()->setLabel( " + parent + "->header()->count() - 1, " + pix + ", " + trcall( txt, com ) + " );\n"; if ( !clickable ) s += indent + parent + "->header()->setClickEnabled( FALSE, " + parent + "->header()->count() - 1 );\n"; if ( !resizable ) s += indent + parent + "->header()->setResizeEnabled( FALSE, " + parent + "->header()->count() - 1 );\n"; return s; }
void ParserAlbum::writeToAlbumByFile(const QString & _source) { m_pFile->close(); if(!m_pFile->open(QIODevice::WriteOnly)) { return; } QDomElement element = m_pDoc->documentElement(); QDomElement node = element.firstChild().toElement(); while(node.tagName() != "images") { node = node.nextSibling().toElement(); } node.appendChild(createElement("image",_source)); if(m_pFile->isOpen()) { QTextStream(m_pFile) << m_pDoc->toString(); m_pFile->close(); } }