本文整理汇总了C++中QDomDocument::insertBefore方法的典型用法代码示例。如果您正苦于以下问题:C++ QDomDocument::insertBefore方法的具体用法?C++ QDomDocument::insertBefore怎么用?C++ QDomDocument::insertBefore使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QDomDocument
的用法示例。
在下文中一共展示了QDomDocument::insertBefore方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: insertBefore
QDomNode QDomDocumentProto::insertBefore(const QDomNode& newChild, const QDomNode& refChild)
{
QDomDocument *item = qscriptvalue_cast<QDomDocument*>(thisObject());
if (item)
return item->insertBefore(newChild, refChild);
return QDomNode();
}
示例2: save
void DataStorage::save(QFile &file)
{
QDomDocument doc;
QDomNode xmlNode = doc.createProcessingInstruction("xml","version=\"1.0\" encoding=\"UTF-8\"");
doc.insertBefore(xmlNode, doc.firstChild());
QDomElement opp = doc.createElement("opp");
opp.setAttribute("title", _projectTitle);
opp.setAttribute("notes", _projectNotes);
doc.appendChild(opp);
QDomElement medias = doc.createElement("medias");
QDomElement playlists = doc.createElement("playlists");
QDomElement schedules = doc.createElement("schedules");
opp.appendChild(medias);
opp.appendChild(playlists);
opp.appendChild(schedules);
/*List of medias*/
QDomElement media;
const QList<Media*>& mediaList = _mediaListModel->mediaList();
foreach(Media* mediaElement, mediaList)
{
media= doc.createElement("media");
media.setAttribute("id",mediaElement->id());
media.setAttribute("location",mediaElement->location());
medias.appendChild(media);
}
示例3: ecrire
void Dom::ecrire(QString fileName)
{
QFile file;
QDomDocument doc;
QDomElement sauvegarde;
QDomElement racine;
QTextStream out;
doc.clear();
racine=doc.createElement("sauvegardes");
doc.appendChild(racine); // filiation de la balise "sauvegarde"
file.setFileName(fileName);
if (!file.open(QIODevice::WriteOnly)) // ouverture du fichier de sauvegarde
return; // en écriture
out.setDevice(&file); // association du flux au fichier
for(int i=0; i<p.size(); i++){
sauvegarde=doc.createElement("sauvegarde");
sauvegarde.setAttribute("valeur", p.at(i)->toQString());
racine.appendChild(sauvegarde);
}
QDomNode noeud = doc.createProcessingInstruction("xml","version=\"1.0\"");
doc.insertBefore(noeud,doc.firstChild());
// sauvegarde dans le flux (deux espaces de décalage dans l'arborescence)
doc.save(out,2);
file.close();
}
示例4: creerXml
QDomDocument Manager::creerXml()
{
QDomDocument doc;
QDomNode xmlNode = doc.createProcessingInstruction("xml","version=\"1.0\" encoding=\"UTF-8\"");
doc.insertBefore(xmlNode, doc.firstChild());
return doc;
}
示例5: save
void save(const char* filename, const Grammar& grammar) {
QFile file(filename);
file.open(QFile::WriteOnly);
QDomDocument doc;
QDomElement root = doc.createElement("grammar");
root.setAttribute("version", "1.0");
root.setAttribute("author", "Gen Nishida");
doc.appendChild(root);
save(doc, root, grammar);
QTextStream out(&file);
QDomNode xmlNode = doc.createProcessingInstruction("xml", "version=\"1.0\" encoding=\"ISO-8859-1\"");
doc.insertBefore(xmlNode, doc.firstChild());
doc.save(out, 4);
}
示例6: save
void Qtfe::save()
{
QDomDocument doc;
QDomElement MultiEditor;
QFile file;
QTextStream out;
file.setFileName(filename);
if (!file.open(QIODevice::WriteOnly))
return;
out.setDevice(&file);
MultiEditor = doc.createElement("Qtfe");
doc.appendChild(MultiEditor);
for(int i=0 ; i<canals.size() ; ++i)
{
QDomElement func = doc.createElement("Function");
MultiEditor.appendChild(func);
for(int j=0 ; j<canals[i]->getPoints().size() ; ++j)
{
QDomElement point = doc.createElement("point");
func.appendChild(point);
point.setAttribute("x", QString::number(canals[i]->getPoints()[j]->x()));
point.setAttribute("y", QString::number(canals[i]->getPoints()[j]->y()));
}
}
for(int i=0 ; i<outputs.size() ; ++i)
{
QDomElement output = doc.createElement("Output");
MultiEditor.appendChild(output);
output.setAttribute("R", QString::number(outputs[i]->R));
output.setAttribute("G", QString::number(outputs[i]->G));
output.setAttribute("B", QString::number(outputs[i]->B));
output.setAttribute("A", QString::number(outputs[i]->A));
}
QDomNode noeud = doc.createProcessingInstruction("xml","version=\"1.0\"");
doc.insertBefore(noeud,doc.firstChild());
doc.save(out,2);
file.close();
}
示例7: main
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
// Prepare the XML file
QFile file("list.xml");
file.remove();
QDomDocument xml;
QDomNode declaration = xml.createProcessingInstruction("xml",QString("version=\"1.0\" encoding=\"UTF-8\""));
xml.insertBefore(declaration,xml.firstChild());
QDomComment comment = xml.createComment("Do not edit this file, it is regenerated automatically!");
xml.appendChild(comment);
QDomNode root = xml.createElement("files");
xml.appendChild(root);
// Liste tous les fichiers
QStringList liste;
QDirIterator it(".", QDir::Files, QDirIterator::Subdirectories);
while (it.hasNext()) {
if(QString(it.hasNext()).startsWith("./Assets/Modules/Custom_Civilizations_MCP/"))
{}
else{
// Add the file to the list
QDomElement entity = xml.createElement("file");
entity.appendChild(xml.createTextNode(it.next()));
entity.setAttribute("md5", checkMd5(it.next()));
root.appendChild(entity);
}
}
// Save the file
file.open(QIODevice::Truncate | QIODevice::WriteOnly);
QTextStream ts(&file);
xml.save(ts, 4);
file.close();
return a.exec();
}
示例8: enregistre
bool DDZ::enregistre(QString fichier, QString contenu, QString langue, QStringList annexes, QStringList ignore){
//Paramètres de fonction
ErrorManager instance_erreur;
QZipWriter ddz_global(fichier, QIODevice::WriteOnly);
//Création d'un XML global pour les préférences
QDomDocument preferences;
QDomElement xmlConfig = preferences.createElement("config");
QDomElement xmlLangue = preferences.createElement("langue");
QDomText xmlLangueTexte = preferences.createTextNode(langue);
xmlLangue.appendChild(xmlLangueTexte);
xmlConfig.appendChild(xmlLangue);
//On remplit le fichier avec le contenu
QString nom_fichier = fichier.split("/").last();
//Le nom du fichier est le même que le nom de l'archive globale si ce n'est que l'extention change
nom_fichier.remove(nom_fichier.size()-4, nom_fichier.size()).append(".ddw");
QByteArray array_contenu;
array_contenu.append(contenu);
ddz_global.addFile(nom_fichier, array_contenu);
//On regarde s'il y avait des images
int nb_images = contenu.count("<img src=");
//Il y a des images, on rentre dans la boucle
if(nb_images > 0){
//Définition de la RegExp
QRegExp regexp_images("<img[^>]*src=\"([^\"]*)");
//Récupération des images
int pos = 0; QStringList list;
while ((pos = regexp_images.indexIn(contenu, pos)) != -1){
list << regexp_images.cap(1);
pos += regexp_images.matchedLength();
}
if(nb_images != list.size()){
//On a pas trouvé toutes les images (ou on en a trouvé trop, ce qui est pire)
instance_erreur.Erreur_msg(QObject::tr("Problème lors de la détection d'images -> annulation de la sauvegarde"), QMessageBox::Ignore);
return false;
}
//Si on est ici, c'est que tout roule
//On ajoute les images détectées au zip
//ddz_global.addDirectory("images");
for(int i=0; i<list.size(); i++){
QString liste_temp = list.at(i);
QString nom_fichier = liste_temp.split("/").last();
//nom_fichier.prepend("images/");
//On récupère l'extention
QString extention = list.at(i).section('.', -1);
QImageReader image(list.at(i), extention.toUpper().toStdString().c_str());
ddz_global.addFile(nom_fichier, image.device());
}
}
//Traitement des annexes
if(annexes.size() > 0){
QDomNode xmlAnnexe = preferences.createElement("annexes");
for(int i=0; i<annexes.size(); i++){
QFile fichier(annexes.at(i));
fichier.open(QFile::ReadOnly);
ddz_global.addFile(annexes.at(i).split("/").last(), fichier.readAll());
fichier.close();
//Ajout des annexes au XML global
QDomElement thisAnnexe = preferences.createElement("annexe");
QDomText thisText = preferences.createTextNode(annexes.at(i).split("/").last());
thisAnnexe.appendChild(thisText);
xmlAnnexe.appendChild(thisAnnexe);
xmlConfig.appendChild(xmlAnnexe);
}
}
//Traitement des mots à ignorer définitivement (ajout dans le XML de config)
if(ignore.size() >= 1){
QDomNode xmlIgnore = preferences.createElement("orthographe");
for(int i=0; i<ignore.count(); i++){
QDomElement motIgnore = preferences.createElement("mot");
QDomText motTexte = preferences.createTextNode(ignore.at(i));
motIgnore.appendChild(motTexte);
xmlIgnore.appendChild(motIgnore);
xmlConfig.appendChild(xmlIgnore);
}
}
//Enregistrement des préférences
preferences.appendChild(xmlConfig);
QDomNode noeud = preferences.createProcessingInstruction("xml","version=\"1.0\"");
preferences.insertBefore(noeud, preferences.firstChild());
QByteArray array_prefs;
array_prefs.append(preferences.toString());
ddz_global.addFile("config.xml", array_prefs);
//On ferme tout
ddz_global.close();
//.........这里部分代码省略.........
示例9: write
bool VYVReader::write ( const QString& fileName,
bool inXML ) const
{
QFile OutFile(fileName);
QString Message;
int i;
int j;
if ( ! OutFile.open(QIODevice::WriteOnly) )
return false;
if ( inXML ) {
QTextStream stream( &OutFile );
QDomDocument doc;
QDomNode xmlInstr =
doc.createProcessingInstruction(
"xml", QString("version=\"1.0\" encoding=\"UTF-8\"") );
doc.insertBefore( xmlInstr, doc.firstChild() );
doc.appendChild( toXML(doc) );
doc.save( stream, 4 );
return true;
}
Message = "Чтение из файла : " + fileName + "\n";
OutFile.write(Message.toAscii().data(), Message.length());
Message = "Ферменная конструкция состоит из : " +
QString::number(Data.nodesNum) + " Узлов и " +
QString::number(Data.pivotsNum) + " Стержней\n\n";
OutFile.write(Message.toAscii().data(), Message.length());
Message = "Количество случаев нагружения : " +
QString::number(Data.loadsNum) + "\n\n";
OutFile.write(Message.toAscii().data(), Message.length());
Message = "Допускаемое Напряжение \n" +
QString::number(Data.stressLimit,'e',3) + "\n\n";
OutFile.write(Message.toAscii().data(), Message.length());
Message = "Топология стержней : \n";
OutFile.write(Message.toAscii().data(), Message.length());
for (i=0;i<Data.pivotsNum;i++) {
Message = QString::number(i+1) + " Стержень : " +
QString::number(Data.pivotsFirstNodes[i]) + " " +
QString::number(Data.pivotsLastNodes[i]) + "\n";
OutFile.write(Message.toAscii().data(), Message.length());
}
Message = "\nКоординаты Узлов : \n";
OutFile.write(Message.toAscii().data(), Message.length());
for (i = 0; i < Data.nodesNum; i++) {
Message = QString::number(i+1) + " Узел : [" +
QString::number(Data.x[i],'e',3) + "," +
QString::number(Data.y[i],'e',3) + "] \n";
OutFile.write(Message.toAscii().data(), Message.length());
}
Message = "\nПеремещения узлов :\n";
OutFile.write(Message.toAscii().data(), Message.length());
for (i = 0; i < Data.loadsNum; i++) {
Message = "Случай нагружения " + QString::number(i+1) + "\n";
OutFile.write(Message.toAscii().data(), Message.length());
for (j = 0; j < Data.nodesNum; j++) {
Message =
QString::number( j+1) + "Узел : [" +
QString::number(Data.xTrans[Data.nodesNum*i+j],'e',3) +
" , " +
QString::number(Data.yTrans[Data.nodesNum*i+j],'e',3) +
"] \n";
OutFile.write(Message.toAscii().data(), Message.length());
}
}
Message = "\nНапряжения в стержнях \n";
OutFile.write(Message.toAscii().data(), Message.length());
for (i = 0; i < Data.loadsNum; i++) {
Message = "Случай нагружения " + QString::number(i+1) + "\n";
OutFile.write(Message.toAscii().data(), Message.length());
for (j = 0; j < Data.pivotsNum; j++) {
Message =
QString::number( j+1) + " Стержень : " +
QString::number(Data.stress[Data.pivotsNum*i+j],'e',3) +
"\n";
OutFile.write(Message.toAscii().data(), Message.length());
}
}
Message = "\nЗапас прочности \n";
OutFile.write(Message.toAscii().data(), Message.length());
for (i = 0; i < Data.loadsNum; i++) {
Message = "Случай нагружения " + QString::number(i+1) + "\n";
OutFile.write(Message.toAscii().data(), Message.length());
for (j = 0; j < Data.pivotsNum; j++) {
Message =
QString::number( j+1) + " Стержень : " +
QString::number(
Data.safetyFactor[Data.pivotsNum*i+j],'e',3) + "\n";
OutFile.write(Message.toAscii().data(), Message.length());
}
}
Message = "\nНачальные площади\n";
OutFile.write(Message.toAscii().data(), Message.length());
for (i = 0; i < Data.pivotsNum; i++) {
Message = QString::number(i+1) + "Стержень : " +
QString::number(Data.pivotSquare[i],'e',3) + "\n";
OutFile.write(Message.toAscii().data(), Message.length());
//.........这里部分代码省略.........
示例10: onSaveButtonClicked
/******************************************************************************
* Slot called when the Save button has been clicked.
*
* Serialize the transfer funtion in file.
* Currently, format is XML document.
******************************************************************************/
void Qtfe::onSaveButtonClicked()
{
// If filename is empty, do "Save As"
if ( _filename.isEmpty() )
{
onSaveAsButtonClicked();
// Exit to avoid infinite loop
return;
}
QDomDocument doc;
QDomElement MultiEditor;
QFile file;
QTextStream out;
// Try to open/create file
file.setFileName( _filename );
if ( ! file.open( QIODevice::WriteOnly ) )
{
// TO DO
// Handle error
//...
return;
}
out.setDevice( &file );
MultiEditor = doc.createElement( "Qtfe" );
doc.appendChild( MultiEditor );
// Iterate through channels
for ( int i = 0; i < _channels.size(); ++i )
{
// Create a Function tag
QDomElement func = doc.createElement( "Function" );
MultiEditor.appendChild( func );
// Iterate through points
for ( int j = 0; j < _channels[ i ]->getPoints().size(); ++j )
{
// Create a point tag in Function tag
QDomElement point = doc.createElement( "point" );
func.appendChild( point );
// Write data
point.setAttribute( "x", QString::number( _channels[ i ]->getPoints()[ j ]->x() ) );
point.setAttribute( "y", QString::number( _channels[ i ]->getPoints()[ j ]->y() ) );
}
}
// Iterate through outputs
for ( int i = 0; i < _outputs.size(); ++i )
{
// Create an Output tag
QDomElement output = doc.createElement( "Output" );
MultiEditor.appendChild( output );
// Write data
output.setAttribute( "R", QString::number( _outputs[ i ]->_R ) );
output.setAttribute( "G", QString::number( _outputs[ i ]->_G ) );
output.setAttribute( "B", QString::number( _outputs[ i ]->_B ) );
output.setAttribute( "A", QString::number( _outputs[ i ]->_A ) );
}
// Add XML header at beginning of the file
QDomNode noeud = doc.createProcessingInstruction( "xml", "version=\"1.0\"" );
doc.insertBefore( noeud, doc.firstChild() );
// Write document in file
doc.save( out, 2 );
// Close file
file.close();
}