本文整理汇总了C++中QDomDocument::createCDATASection方法的典型用法代码示例。如果您正苦于以下问题:C++ QDomDocument::createCDATASection方法的具体用法?C++ QDomDocument::createCDATASection怎么用?C++ QDomDocument::createCDATASection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QDomDocument
的用法示例。
在下文中一共展示了QDomDocument::createCDATASection方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: writeFile
bool EBTextEdit::writeFile(QString sFileName )
{
Q_ASSERT(m_FullFileName.size());
//save or save as?
if (sFileName.isEmpty())
sFileName = m_FullFileName;
QDomDocument xmlDocument; //has to be first because of EditorView::OnlyPlainData reads it
QFile fileWrite(sFileName);
QIODevice::OpenMode flags = QFile::WriteOnly | QFile::Text;
if (m_ViewType == EditorView::OnlyPlainData) {
QFile fileRead(m_FullFileName); //read always from source/can be the same as fileWrite
if (!fileRead.open(QFile::ReadOnly| QFile::Text))
return false;
QString errotMsg("");
int iErrorLine(0), iErrorCol(0);
if ( !xmlDocument.setContent( &fileRead,false, &errotMsg, &iErrorLine, &iErrorCol))
{
fileRead.close();
qCritical()<< "QDomDocument::setContent: " << errotMsg << " Line " << iErrorLine << " column: " << iErrorCol;
return false;
}
fileRead.close();
}
if (!fileWrite.open(flags))
return false;
QTextStream out(&fileWrite);
QApplication::setOverrideCursor(Qt::WaitCursor);
if (m_ViewType == EditorView::XmlSource) {
qDebug() << "file.write(SOURCE): "<< sFileName;
out << toPlainText();
} else if (m_ViewType == EditorView::Text) {
qDebug() << "file.write(DOM): "<< sFileName;
QDomElement root = xmlDocument.createElement(DataOwnerSingl::XmlKeywords::KEYWORD_ITEM );
xmlDocument.appendChild( root );
//actual reading TXT format and saving to QDomDocument
//1.we divide it to 2 parts - tags and data
//than we red keyword one by one and if some is missing we use default
//than we take the data as a rest
QDomElement tag;
QTextCursor cursor(document());
int iDataCursorPosition = document()->end().position(); //default is end of document
if (!document()->find(DataOwnerSingl::TxtKeywords::KEYWORD_DATA).isNull()) {
cursor.movePosition(QTextCursor::EndOfWord, QTextCursor::MoveAnchor); //remove txt keyword from selection
iDataCursorPosition = document()->find(DataOwnerSingl::TxtKeywords::KEYWORD_DATA).position();
//qDebug() << "First data char:" << document()->characterAt(iDataCursorPosition) << "Next data char:" << document()->characterAt(iDataCursorPosition+1);
//\n should be part of TxtKeywords::KEYWORD_DATA but it can be deleted..
if(document()->characterAt(iDataCursorPosition) == QChar('\r'))
++iDataCursorPosition;
if(document()->characterAt(iDataCursorPosition) == QChar('\n'))
++iDataCursorPosition;
}
//key = xml, value = txt
QList< QPair<QString, QString> >::const_iterator i = DataOwnerSingl::XmlKeywords::Keywords.constBegin();
while (i != DataOwnerSingl::XmlKeywords::Keywords.constEnd()) {
if ((*i).first != DataOwnerSingl::XmlKeywords::KEYWORD_DATA) {
//tag
tag = xmlDocument.createElement((*i).first);
root.appendChild(tag);
//content (before data)
QString sText("");
cursor = document()->find((*i).second);
if (cursor.position() < iDataCursorPosition ) {
//valid record
const QTextBlock block = cursor.block();
if (block.isValid())
sText = block.text();
sText.remove(QRegExp("^"+ (*i).second));
//qDebug() << "writeFile sText:" << sText;
}
//missing or invalid = empty
QDomText text = xmlDocument.createTextNode(sText);
tag.appendChild(text);
}
++i;
}
tag = xmlDocument.createElement(DataOwnerSingl::XmlKeywords::KEYWORD_DATA);
root.appendChild(tag);
//select from iDataCursorPosition till end - if tag is missing it is empty, with \n correction
cursor.setPosition(iDataCursorPosition, QTextCursor::MoveAnchor);
cursor.movePosition(QTextCursor::End, QTextCursor::KeepAnchor);
QDomCDATASection data = xmlDocument.createCDATASection(cursor.selectedText().replace(QChar(0x2029), QChar('\n')));
tag.appendChild(data);
//qDebug()<< "save XML:" << xmlDocument.toString();
out << xmlDocument.toString();
} else if (m_ViewType == EditorView::OnlyPlainData) {
QDomNodeList nodeList = xmlDocument.elementsByTagName(DataOwnerSingl::XmlKeywords::KEYWORD_DATA);
QDomElement data;
if (nodeList.isEmpty()) {
data = xmlDocument.createElement(DataOwnerSingl::XmlKeywords::KEYWORD_DATA);
xmlDocument.documentElement().appendChild(data);
//.........这里部分代码省略.........
示例2: saveSettings
void MainWindow::saveSettings() {
QFile file("settings.xml");
file.open(QIODevice::WriteOnly | QIODevice::Text);
QDomDocument doc ("StreamControl");
QDomElement settingsXML = doc.createElement("settings");
doc.appendChild(settingsXML);
QDomElement xsplitPathE = doc.createElement("xsplitPath");
settingsXML.appendChild(xsplitPathE);
QDomCDATASection xsplitPathT = doc.createCDATASection(settings["xsplitPath"]);
xsplitPathE.appendChild(xsplitPathT);
QDomElement useCDATAE = doc.createElement("useCDATA");
settingsXML.appendChild(useCDATAE);
QDomText useCDATAT = doc.createTextNode(settings["useCDATA"]);
useCDATAE.appendChild(useCDATAT);
QDomElement gamesE = doc.createElement("games");
settingsXML.appendChild(gamesE);
for (int i = 0; i < gameComboBox->count(); ++i) {
QDomElement gameE = doc.createElement("game");
gamesE.appendChild(gameE);
QDomCDATASection gameText = doc.createCDATASection(gameComboBox->itemText(i));
gameE.appendChild(gameText);
}
QDomElement p1E = doc.createElement("player1");
settingsXML.appendChild(p1E);
for (int i = 0; i < ui->p1Color->count(); ++i) {
QDomElement p1colorE = doc.createElement("color");
p1E.appendChild(p1colorE);
QDomCDATASection p1CText = doc.createCDATASection(ui->p1Color->itemText(i));
p1colorE.appendChild(p1CText);
}
QDomElement p2E = doc.createElement("player2");
settingsXML.appendChild(p2E);
for (int i = 0; i < ui->p2Color->count(); ++i) {
QDomElement p2colorE = doc.createElement("color");
p2E.appendChild(p2colorE);
QDomCDATASection p2CText = doc.createCDATASection(ui->p2Color->itemText(i));
p2colorE.appendChild(p2CText);
}
QTextStream out(&file);
out.setCodec("UTF-8");
out << doc.toString();
file.close();
}
示例3: saveToDevice
bool KisWorkspaceResource::saveToDevice(QIODevice *dev) const
{
QDomDocument doc;
QDomElement root = doc.createElement("Workspace");
root.setAttribute("name", name() );
root.setAttribute("version", WORKSPACE_VERSION);
QDomElement state = doc.createElement("state");
state.appendChild(doc.createCDATASection(m_dockerState.toBase64()));
root.appendChild(state);
// Save KisPropertiesConfiguration settings
QDomElement settings = doc.createElement("settings");
KisPropertiesConfiguration::toXML(doc, settings);
root.appendChild(settings);
doc.appendChild(root);
QTextStream textStream(dev);
textStream.setCodec("UTF-8");
doc.save(textStream, 4);
KoResource::saveToDevice(dev);
return true;
}
示例4: toXML
// <param name="brush_definition">
// <![CDATA[
// <Brush type="auto_brush" spacing="0.1" angle="0">
// <MaskGenerator radius="5" ratio="1" type="circle" vfade="0.5" spikes="2" hfade="0.5"/>
// </Brush> ]]>
// </param>
void AbrBrushProperties::toXML(QDomDocument& doc, QDomElement& root) const
{
if (m_brushType != BRUSH_TYPE_COMPUTED){
qDebug() << m_brushType << "saved as computed brush...";
}
QDomDocument d;
QDomElement e = d.createElement( "Brush" );
QDomElement shapeElement = d.createElement("MaskGenerator");
shapeElement.setAttribute("radius", (m_diameter * 0.5)); // radius == diameter / 2
shapeElement.setAttribute("ratio", m_roundness / 100.0); // roundness in (0..100) to ratio in (0.0..1.0)
shapeElement.setAttribute("hfade", m_hardness / 100.0); // same here
shapeElement.setAttribute("vfade", m_hardness / 100.0); // and here too
shapeElement.setAttribute("spikes", 2); // just circle so far
shapeElement.setAttribute("type", "circle");
e.appendChild(shapeElement);
e.setAttribute("type", "auto_brush");
e.setAttribute("spacing", m_spacing / 100.0); // spacing from 0..1000 to
e.setAttribute("angle", m_angle < 0 ? m_angle + 360.0 : m_angle); // angle from -180..180 to 0..360
e.setAttribute("randomness", 0); // default here
d.appendChild(e);
QDomElement elementParam = doc.createElement("param");
elementParam.setAttribute("name","brush_definition");
QDomText text = doc.createCDATASection(d.toString());
elementParam.appendChild(text);
root.appendChild(elementParam);
}
示例5: createCDATASection
QDomCDATASection QDomDocumentProto::createCDATASection(const QString& data)
{
QDomDocument *item = qscriptvalue_cast<QDomDocument*>(thisObject());
if (item)
return item->createCDATASection(data);
return QDomCDATASection();
}
示例6: toXml
QDomElement State::toXml(QDomDocument doc) const
{
QDomElement node = doc.createElement("state");
node.setAttribute("name", name());
node.appendChild(doc.createCDATASection(mCode));
return node;
}
示例7: appendData
void TupRequestBuilder::appendData(QDomDocument &doc, QDomElement &element, const QByteArray &data)
{
if (!data.isNull() && !data.isEmpty()) {
QDomElement edata = doc.createElement("data");
QDomCDATASection cdata = doc.createCDATASection(QString(data.toBase64()));
edata.appendChild(cdata);
element.appendChild(edata);
}
}
示例8: writeShaderXml
// FIXME no error handling.
QDomDocument writeShaderXml(const Shader & shader) {
QDomDocument result;
QDomElement root = result.createElement(XML_ROOT_NAME);
result.appendChild(root);
for (int i = 0; i < MAX_CHANNELS; ++i) {
if (!shader.channelTextures[i].isEmpty()) {
QDomElement channelElement = result.createElement(XML_CHANNEL);
channelElement.setAttribute(XML_CHANNEL_ATTR_ID, i);
channelElement.setAttribute(XML_CHANNEL_ATTR_TYPE, shader.channelTypes[i] == ChannelInputType::CUBEMAP ? "cube" : "tex");
channelElement.appendChild(result.createTextNode(shader.channelTextures[i]));
root.appendChild(channelElement);
}
}
root.appendChild(result.createElement(XML_FRAGMENT_SOURCE)).
appendChild(result.createCDATASection(shader.fragmentSource));
if (!shader.name.isEmpty()) {
root.appendChild(result.createElement(XML_NAME)).
appendChild(result.createCDATASection(shader.name));
}
return result;
}
示例9: if
ContactListModelSelection::ContactListModelSelection(QList<ContactListItemProxy*> items)
: QMimeData()
, mimeData_(0)
{
QDomDocument doc;
QDomElement root = doc.createElement("items");
root.setAttribute("version", "2.0");
doc.appendChild(root);
// TODO: maybe also embed a random instance-specific token to
// prevent drag'n'drop with other running Psi instances?
QStringList jids;
foreach(ContactListItemProxy* itemProxy, items) {
Q_ASSERT(itemProxy);
PsiContact* contact = 0;
ContactListNestedGroup* group = 0;
ContactListAccountGroup* account = 0;
if ((contact = dynamic_cast<PsiContact*>(itemProxy->item()))) {
QDomElement tag = textTag(&doc, "contact", contact->jid().full());
tag.setAttribute("account", contact->account()->id());
tag.setAttribute("group", itemProxy->parent() ? itemProxy->parent()->fullName() : "");
root.appendChild(tag);
jids << contact->jid().full();
}
else if ((account = dynamic_cast<ContactListAccountGroup*>(itemProxy->item()))) {
QDomElement tag = doc.createElement("account");
tag.setAttribute("id", account->account()->id());
root.appendChild(tag);
jids << account->displayName();
}
else if ((group = dynamic_cast<ContactListNestedGroup*>(itemProxy->item()))) {
// if group->fullName() consists only of whitespace when we'll try
// to read it back we'll get an empty string, so we're using CDATA
// QDomElement tag = textTag(&doc, "group", group->fullName());
QDomElement tag = doc.createElement("group");
QDomText text = doc.createCDATASection(TextUtil::escape(group->fullName()));
tag.appendChild(text);
root.appendChild(tag);
jids << group->fullName();
}
else {
qWarning("ContactListModelSelection::ContactListModelSelection(): Unable to serialize %d, unsupported type", itemProxy->item()->type());
}
}
示例10: save
void KoProperties::save(QDomElement &root) const
{
QDomDocument doc = root.ownerDocument();
QMap<QString, QVariant>::Iterator it;
for (it = d->properties.begin(); it != d->properties.end(); ++it) {
QDomElement e = doc.createElement("property");
e.setAttribute("name", QString(it.key().toLatin1()));
QVariant v = it.value();
e.setAttribute("type", v.typeName());
QByteArray bytes;
QDataStream out(&bytes, QIODevice::WriteOnly);
out << v;
QDomText text = doc.createCDATASection(QString::fromLatin1(bytes, bytes.size()));
e.appendChild(text);
root.appendChild(e);
}
}
示例11: saveNotes
int XmlNotes::saveNotes()
{
//DEBUG_FUNC_NAME
QDomDocument sdoc;
QDomElement root = sdoc.createElement("notes");
root.setAttribute("version", m_version);
sdoc.appendChild(root);
QMapIterator<QString, QString> i(notesType);
while(i.hasNext()) {
i.next();
const QString id = i.key();
if(id.isEmpty())
continue;
QDomElement tag = sdoc.createElement("note");
tag.setAttribute("title", notesTitle.value(id));
tag.setAttribute("type", notesType.value(id));
tag.setAttribute("id", id);
root.appendChild(tag);
QDomElement data = sdoc.createElement("data");
QDomCDATASection text = sdoc.createCDATASection(notesData.value(id));
data.appendChild(text);
tag.appendChild(data);
QDomElement ref = sdoc.createElement("ref");
QMap<QString, QString> map = notesRef.value(id);
QMapIterator<QString, QString> i(map);
while(i.hasNext()) {
i.next();
QDomElement e = sdoc.createElement(i.key());
QDomText t = doc.createTextNode(i.value());
e.appendChild(t);
ref.appendChild(e);
}
tag.appendChild(ref);
}
QFile file(m_fileName);
if(!file.open(QIODevice::WriteOnly | QIODevice::Text))
return 1;
const int IndentSize = 4;
QTextStream out(&file);
sdoc.save(out, IndentSize);
file.close();
doc = sdoc;
return 0;
}
示例12: save
QDomDocument FolderShape::save() const
{
QDomDocument doc;
QDomElement element = doc.createElement("book");
doc.appendChild(element);
foreach (KShape *child, shapes()) {
IconShape *ic = dynamic_cast<IconShape*>(child);
if (ic) {
ic->save(element);
continue;
}
ClipboardProxyShape *proxy = dynamic_cast<ClipboardProxyShape*>(child);
if (proxy) {
QDomElement clipboard = doc.createElement("clipboard");
element.appendChild(clipboard);
QDomText text = doc.createCDATASection( QString::fromAscii( proxy->clipboardData(), proxy->clipboardData().size() ) );
clipboard.appendChild(text);
continue;
}
}
示例13: save
// KOffice-1.3 format
QDomElement KoDocumentInfoAbout::save( QDomDocument& doc )
{
saveParameters();
QDomElement e = doc.createElement( "about" );
QDomElement t = doc.createElement( "abstract" );
e.appendChild( t );
t.appendChild( doc.createCDATASection( m_abstract ) );
t = doc.createElement( "title" );
e.appendChild( t );
t.appendChild( doc.createTextNode( m_title ) );
t = doc.createElement( "keyword" );
e.appendChild( t );
t.appendChild( doc.createTextNode( m_keywords ) );
t = doc.createElement( "subject" );
e.appendChild( t );
t.appendChild( doc.createTextNode( m_subject ) );
t = doc.createElement( "initial-creator" );
e.appendChild( t );
t.appendChild( doc.createTextNode( m_initialCreator ) );
t = doc.createElement( "editing-cycles" );
e.appendChild( t );
t.appendChild( doc.createTextNode( QString::number( m_editingCycles ) ) );
t = doc.createElement( "creation-date" );
e.appendChild( t );
t.appendChild( doc.createTextNode( m_creationDate.toString( Qt::ISODate ) ) );
t = doc.createElement( "date" );
e.appendChild( t );
t.appendChild( doc.createTextNode( m_modificationDate.toString( Qt::ISODate ) ) );
return e;
}
示例14: toXML
/**
* Creates an XML representation of the view, which can be used for storing the
* model's data in a file.
* The representation is rooted at a <QueryView> element, which holds a <Query>
* element for the query information, a <Columns> element with a list of
* columns, and a <LocationList> element that describes the list or tree of
* locations.
* @param doc The XML document object to use
* @return The root element of the view's representation
*/
QDomElement QueryView::toXML(QDomDocument& doc) const
{
// Create an element for storing the view.
QDomElement viewElem = doc.createElement("QueryView");
viewElem.setAttribute("name", windowTitle());
viewElem.setAttribute("type", QString::number(type_));
// Store query information.
QDomElement queryElem = doc.createElement("Query");
queryElem.setAttribute("type", QString::number(query_.type_));
queryElem.setAttribute("flags", QString::number(query_.flags_));
queryElem.appendChild(doc.createCDATASection(query_.pattern_));
viewElem.appendChild(queryElem);
// Create a "Columns" element.
QDomElement colsElem = doc.createElement("Columns");
viewElem.appendChild(colsElem);
// Add an element for each column.
foreach (Location::Fields field, model()->columns()) {
QDomElement colElem = doc.createElement("Column");
colElem.setAttribute("field", QString::number(field));
colsElem.appendChild(colElem);
}
示例15: saveData
void MainWindow::saveData()
{
QFile file(settings["xsplitPath"] + "streamcontrol.xml");
file.open(QIODevice::WriteOnly | QIODevice::Text);
QDomDocument doc ("StreamControl");
QDomElement items = doc.createElement("items");
doc.appendChild(items);
QDateTime current = QDateTime::currentDateTime();
uint timestamp_t = current.toTime_t();
QDomElement timestamp = doc.createElement("timestamp");
items.appendChild(timestamp);
QDomText timestampt = doc.createTextNode(QString::number(timestamp_t));;
timestamp.appendChild(timestampt);
QDomElement pName1 = doc.createElement("pName1");
items.appendChild(pName1);
if (useCDATA) {
QDomCDATASection pName1t = doc.createCDATASection(ui->pName1->text());
pName1.appendChild(pName1t);
} else {
QDomText pName1t = doc.createTextNode(ui->pName1->text());
pName1.appendChild(pName1t);
}
QDomElement pScore1 = doc.createElement("pScore1");
items.appendChild(pScore1);
QDomText pScore1t = doc.createTextNode(ui->pScore1->text());
pScore1.appendChild(pScore1t);
QDomElement pName2 = doc.createElement("pName2");
items.appendChild(pName2);
if (useCDATA) {
QDomCDATASection pName2t = doc.createCDATASection(ui->pName2->text());
pName2.appendChild(pName2t);
} else {
QDomText pName2t = doc.createTextNode(ui->pName2->text());
pName2.appendChild(pName2t);
}
QDomElement pScore2 = doc.createElement("pScore2");
items.appendChild(pScore2);
QDomText pScore2t = doc.createTextNode(ui->pScore2->text());
pScore2.appendChild(pScore2t);
QDomElement rounds = doc.createElement("rounds");
items.appendChild(rounds);
QDomText roundst = doc.createTextNode(ui->rounds->text());
rounds.appendChild(roundst);
QDomElement srText = doc.createElement("srText");
items.appendChild(srText);
if (useCDATA) {
QDomCDATASection srTextt = doc.createCDATASection(ui->srText->text());
srText.appendChild(srTextt);
} else {
QDomText srTextt = doc.createTextNode(ui->srText->text());
srText.appendChild(srTextt);
}
QDomElement cTitle1 = doc.createElement("cTitle1");
items.appendChild(cTitle1);
if (useCDATA) {
QDomCDATASection cTitle1t = doc.createCDATASection(ui->cTitle1->text());
cTitle1.appendChild(cTitle1t);
} else {
QDomText cTitle1t = doc.createTextNode(ui->cTitle1->text());
cTitle1.appendChild(cTitle1t);
}
QDomElement cTitle2 = doc.createElement("cTitle2");
items.appendChild(cTitle2);
if (useCDATA) {
QDomCDATASection cTitle2t = doc.createCDATASection(ui->cTitle2->text());
cTitle2.appendChild(cTitle2t);
} else {
QDomText cTitle2t = doc.createTextNode(ui->cTitle2->text());
cTitle2.appendChild(cTitle2t);
}
//.........这里部分代码省略.........