QString EBTextEdit::itemNameFromDocument() { QString sItemName(""); if (m_ViewType == EditorView::XmlSource) { //Is there any problem with QTextEdit::toPlainText and QDomDocument::setContent? QDomDocument xmlDocument(m_FullFileName); QString errotMsg(""); int iErrorLine(0), iErrorCol(0); if (!xmlDocument.setContent(toPlainText(),false, &errotMsg, &iErrorLine, &iErrorCol)) { qCritical()<< "QDomDocument::setContent: " << errotMsg << " Line " << iErrorLine << " column: " << iErrorCol; return sItemName; } QDomNodeList nodeList = xmlDocument.elementsByTagName(DataOwnerSingl::XmlKeywords::KEYWORD_NAME); if (nodeList.isEmpty()) return sItemName; sItemName = nodeList.at(0).toElement().text(); } else if (m_ViewType == EditorView::Text) { QTextCursor cursor = document()->find(DataOwnerSingl::TxtKeywords::KEYWORD_NAME); const QTextBlock block = cursor.block(); if (!block.isValid()) return QString(""); sItemName = block.text(); sItemName.remove(QRegExp("^"+ DataOwnerSingl::TxtKeywords::KEYWORD_NAME)); //qDebug() << "itemNameFromDocument:" << sItemName; } else if(m_ViewType == EditorView::OnlyPlainData) { //todo sItemName = DataOwnerSingl::XmlKeywords::itemNameFromFile(m_FullFileName); } else Q_ASSERT(0); return sItemName; }
//Returns files dependent on the directory vector<string> Repository::getDependentFiles(string dirctry) { FileManager fm; vector<string> patterns = { "*.h", "*.cpp" }; string file = dirctry + "\\" + "DependencyInfo.xml"; cout << "Checking file: " << file; XmlDocument xmlDocument(file, XmlDocument::file); vector<sPtr> packages = xmlDocument.element("Package").select(); vector<string> packageNames; if (packages.size() > 0) { for (auto pckg : packages) { string dir = pckg->getAttrib("Name"); if (dir != ""&&dir != " ") { cout << "\nChecking dir" << dir; packageNames.push_back(dir); } } } vector<string> dependentFiles; if (packageNames.size() > 0) { for (auto package : packageNames) { vector<string> dep = getFilesinVersion(package); dependentFiles.insert(dependentFiles.end(), dep.begin(), dep.end()); } } return dependentFiles; }
// ------------------------------------------------------------------------------- CInformationCollection* XMLPersister::createInformationCollection( QFile& xmlFile ) // ------------------------------------------------------------------------------- { QDomDocument xmlDocument( "tuxcards_data_file" ); bool bResult = createDomDocumentFromFile( xmlFile, xmlDocument ); if ( bResult ) { return createInformationCollection( xmlDocument ); } return NULLPTR; }
void addNPC(Application& app, const char* behaviorFile) { XmlDocument xmlDocument(behaviorFile); auto rootNode = xmlDocument.getDocument().first_node(); assert(rootNode != nullptr); if( rootNode ) { assert(0 == strcmp(rootNode->name(), "root")); app.getWorld().addEntity<AI::NPC>(*rootNode); } }
void ReplaceDialog::slotSaveList() { QTableWidget * table = m_widget.list; QString fileName = QFileDialog::getSaveFileName(this,tr("Save Find & Replace Settings as:"), QDir::currentPath(), tr("KRename Find & Replace Settings XML (*.xml)")); if (fileName.isEmpty()) return; QFile f(fileName); if (!f.open(QIODevice::WriteOnly | QIODevice::Text)) { QMessageBox::warning(this, tr("KRename Warning"), tr("Failed to save the Find & Replace Settings File."), QMessageBox::Cancel, QMessageBox::NoButton); return; } QTextStream data( &f ); QDomDocument xmlDocument("KRename"); QDomElement root = xmlDocument.createElement("KRename"); root.setAttribute("version","1.0"); QDomElement frElement = xmlDocument.createElement("FindReplaceList"); frElement.setAttribute("rows",table->rowCount()); root.appendChild(frElement); for( int r = 0; r < table->rowCount(); ++r ) { QDomElement RegExpElement = xmlDocument.createElement("RegularExpression"); QDomElement FindElement = xmlDocument.createElement("Find"); QDomElement ReplaceWithElement = xmlDocument.createElement("ReplaceWith"); QDomElement ProcessTokensElement = xmlDocument.createElement("ProcessTokens"); QDomElement RowElement = xmlDocument.createElement("Row"); RowElement.setAttribute("num",r); int RegExpCheck=static_cast<int>(table->item( r, 0)->checkState()); QString RegExpCheckStr=QString::number( RegExpCheck, 10 ); RegExpElement.appendChild( xmlDocument.createTextNode(RegExpCheckStr)); RowElement.appendChild(RegExpElement); FindElement.appendChild( xmlDocument.createTextNode(table->item( r, 1)->data(Qt::EditRole).toString() )); RowElement.appendChild(FindElement); ReplaceWithElement.appendChild( xmlDocument.createTextNode(table->item( r, 2)->data(Qt::EditRole).toString() )); RowElement.appendChild(ReplaceWithElement); int ProcessTokensCheck=static_cast<int>(table->item( r, 3)->checkState()); QString ProcessTokensCheckStr=QString::number( ProcessTokensCheck, 10 ); ProcessTokensElement.appendChild( xmlDocument.createTextNode(ProcessTokensCheckStr)); RowElement.appendChild(ProcessTokensElement); frElement.appendChild(RowElement); } xmlDocument.appendChild(root); data << xmlDocument.toString(-1); f.close(); }