本文整理汇总了C++中KoXmlNode::toElement方法的典型用法代码示例。如果您正苦于以下问题:C++ KoXmlNode::toElement方法的具体用法?C++ KoXmlNode::toElement怎么用?C++ KoXmlNode::toElement使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类KoXmlNode
的用法示例。
在下文中一共展示了KoXmlNode::toElement方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: loadNodes
KisNodeSP KisKraLoader::loadNodes(const KoXmlElement& element, KisImageWSP image, KisNodeSP parent)
{
KoXmlNode node = element.firstChild();
KoXmlNode child;
if (!node.isNull()) {
if (node.isElement()) {
if (node.nodeName().toUpper() == LAYERS.toUpper() || node.nodeName().toUpper() == MASKS.toUpper()) {
for (child = node.lastChild(); !child.isNull(); child = child.previousSibling()) {
KisNodeSP node = loadNode(child.toElement(), image, parent);
if (node) {
image->nextLayerName(); // Make sure the nameserver is current with the number of nodes.
image->addNode(node, parent);
if (node->inherits("KisLayer") && child.childNodesCount() > 0) {
loadNodes(child.toElement(), image, node);
}
}
}
}
}
}
return parent;
}
示例2: loadCompositions
void KisKraLoader::loadCompositions(const KoXmlElement& elem, KisImageWSP image)
{
KoXmlNode child;
for (child = elem.firstChild(); !child.isNull(); child = child.nextSibling()) {
KoXmlElement e = child.toElement();
QString name = e.attribute("name");
bool exportEnabled = e.attribute("exportEnabled", "1") == "0" ? false : true;
KisLayerComposition* composition = new KisLayerComposition(image, name);
composition->setExportEnabled(exportEnabled);
KoXmlNode value;
for (value = child.lastChild(); !value.isNull(); value = value.previousSibling()) {
KoXmlElement e = value.toElement();
QUuid uuid(e.attribute("uuid"));
bool visible = e.attribute("visible", "1") == "0" ? false : true;
composition->setVisible(uuid, visible);
bool collapsed = e.attribute("collapsed", "1") == "0" ? false : true;
composition->setCollapsed(uuid, collapsed);
}
image->addComposition(composition);
}
}
示例3: context
KoFilterEffectStack * FilterEffectResource::toFilterStack() const
{
KoFilterEffectStack * filterStack = new KoFilterEffectStack();
if (!filterStack)
return 0;
QByteArray data = m_data.toByteArray();
KoXmlDocument doc;
doc.setContent(data);
KoXmlElement e = doc.documentElement();
// only allow obect bounding box units
if (e.hasAttribute("filterUnits") && e.attribute("filterUnits") != "objectBoundingBox")
return 0;
if (e.attribute("primitiveUnits") != "objectBoundingBox")
return 0;
// parse filter region rectangle
QRectF filterRegion;
filterRegion.setX(fromPercentage(e.attribute("x", "-0.1")));
filterRegion.setY(fromPercentage(e.attribute("y", "-0.1")));
filterRegion.setWidth(fromPercentage(e.attribute("width", "1.2")));
filterRegion.setHeight(fromPercentage(e.attribute("height", "1.2")));
filterStack->setClipRect(filterRegion);
KoFilterEffectLoadingContext context(QString(""));
KoFilterEffectRegistry * registry = KoFilterEffectRegistry::instance();
// create the filter effects and add them to the shape
for (KoXmlNode n = e.firstChild(); !n.isNull(); n = n.nextSibling()) {
KoXmlElement primitive = n.toElement();
KoFilterEffect * filterEffect = registry->createFilterEffectFromXml(primitive, context);
if (!filterEffect) {
qWarning() << "filter effect" << primitive.tagName() << "is not implemented yet";
continue;
}
// parse subregion
qreal x = fromPercentage(primitive.attribute("x", "0"));
qreal y = fromPercentage(primitive.attribute("y", "0"));
qreal w = fromPercentage(primitive.attribute("width", "1"));
qreal h = fromPercentage(primitive.attribute("height", "1"));
QRectF subRegion(QPointF(x, y), QSizeF(w, h));
if (primitive.hasAttribute("in"))
filterEffect->setInput(0, primitive.attribute("in"));
if (primitive.hasAttribute("result"))
filterEffect->setOutput(primitive.attribute("result"));
filterEffect->setFilterRect(subRegion);
filterStack->appendFilterEffect(filterEffect);
}
return filterStack;
}
示例4: loadOdf
bool KoInlineNote::loadOdf(const KoXmlElement & element, KoShapeLoadingContext &context, KoStyleManager *styleManager, KoChangeTracker *changeTracker)
{
QTextDocument *document = new QTextDocument();
QTextCursor cursor(document);
KoTextDocument textDocument(document);
textDocument.setStyleManager(styleManager);
d->styleManager = styleManager;
textDocument.setChangeTracker(changeTracker);
KoTextLoader loader(context);
if (element.namespaceURI() == KoXmlNS::text && element.localName() == "note") {
QString className = element.attributeNS(KoXmlNS::text, "note-class");
if (className == "footnote") {
d->type = Footnote;
}
else if (className == "endnote") {
d->type = Endnote;
}
else {
delete document;
return false;
}
d->id = element.attributeNS(KoXmlNS::text, "id");
for (KoXmlNode node = element.firstChild(); !node.isNull(); node = node.nextSibling()) {
setAutoNumbering(false);
KoXmlElement ts = node.toElement();
if (ts.namespaceURI() != KoXmlNS::text)
continue;
if (ts.localName() == "note-body") {
loader.loadBody(ts, cursor);
} else if (ts.localName() == "note-citation") {
d->label = ts.attributeNS(KoXmlNS::text, "label");
if (d->label.isEmpty()) {
setAutoNumbering(true);
d->label = ts.text();
}
}
}
}
else if (element.namespaceURI() == KoXmlNS::office && element.localName() == "annotation") {
d->author = element.attributeNS(KoXmlNS::text, "dc-creator");
d->date = QDateTime::fromString(element.attributeNS(KoXmlNS::text, "dc-date"), Qt::ISODate);
loader.loadBody(element, cursor); // would skip author and date, and do just the <text-p> and <text-list> elements
}
else {
delete document;
return false;
}
d->text = QTextDocumentFragment(document);
delete document;
return true;
}
示例5: load
bool KPlatoXmlLoader::load( const KoXmlElement& plan )
{
kDebug(kplatoXmlDebugArea())<<"plan";
QString syntaxVersion = plan.attribute( "version" );
m_loader.setVersion( syntaxVersion );
if ( syntaxVersion.isEmpty() ) {
int ret = KMessageBox::warningContinueCancel(
0, i18n( "This document has no syntax version.\n"
"Opening it in Plan may lose information." ),
i18n( "File-Format Error" ), KGuiItem( i18n( "Continue" ) ) );
if ( ret == KMessageBox::Cancel ) {
m_message = "USER_CANCELED";
return false;
}
// set to max version and hope for the best
m_loader.setVersion( KPLATO_MAX_FILE_SYNTAX_VERSION );
} else if ( syntaxVersion > KPLATO_MAX_FILE_SYNTAX_VERSION ) {
int ret = KMessageBox::warningContinueCancel(
0, i18n( "This document was created with a newer version of KPlato than Plan can load.\n"
"Syntax version: %1\n"
"Opening it in this version of Plan may lose some information.", syntaxVersion ),
i18n( "File-Format Mismatch" ), KGuiItem( i18n( "Continue" ) ) );
if ( ret == KMessageBox::Cancel ) {
m_message = "USER_CANCELED";
return false;
}
}
m_loader.startLoad();
bool result = false;
KoXmlNode n = plan.firstChild();
for ( ; ! n.isNull(); n = n.nextSibling() ) {
if ( ! n.isElement() ) {
continue;
}
KoXmlElement e = n.toElement();
if ( e.tagName() == "project" ) {
m_loader.setProject( m_project );
result = load( m_project, e, m_loader );
if ( result ) {
if ( m_project->id().isEmpty() ) {
m_project->setId( m_project->uniqueNodeId() );
m_project->registerNodeId( m_project );
}
} else {
m_loader.addMsg( XMLLoaderObject::Errors, "Loading of project failed" );
kError()<<"Loading of project failed";
//TODO add some ui here
}
}
}
m_loader.stopLoad();
return result;
}
示例6: loadAssistantsList
void KisKraLoader::loadAssistantsList(const KoXmlElement &elem)
{
KoXmlNode child;
int count = 0;
for (child = elem.firstChild(); !child.isNull(); child = child.nextSibling()) {
KoXmlElement e = child.toElement();
QString type = e.attribute("type");
QString file_name = e.attribute("filename");
m_d->assistantsFilenames.insert(file_name,type);
count++;
}
}
示例7: parseManifest
bool KoOdfLoadingContext::parseManifest(const KoXmlDocument &manifestDocument)
{
// First find the manifest:manifest node.
KoXmlNode n = manifestDocument.firstChild();
kDebug(30006) << "Searching for manifest:manifest " << n.toElement().nodeName();
for (; !n.isNull(); n = n.nextSibling()) {
if (!n.isElement()) {
kDebug(30006) << "NOT element";
continue;
} else {
kDebug(30006) << "element";
}
kDebug(30006) << "name:" << n.toElement().localName()
<< "namespace:" << n.toElement().namespaceURI();
if (n.toElement().localName() == "manifest"
&& n.toElement().namespaceURI() == KoXmlNS::manifest)
{
kDebug(30006) << "found manifest:manifest";
break;
}
}
if (n.isNull()) {
kDebug(30006) << "Could not find manifest:manifest";
return false;
}
// Now loop through the children of the manifest:manifest and
// store all the manifest:file-entry elements.
const KoXmlElement manifestElement = n.toElement();
for (n = manifestElement.firstChild(); !n.isNull(); n = n.nextSibling()) {
if (!n.isElement())
continue;
KoXmlElement el = n.toElement();
if (!(el.localName() == "file-entry" && el.namespaceURI() == KoXmlNS::manifest))
continue;
QString fullPath = el.attributeNS(KoXmlNS::manifest, "full-path", QString());
QString mediaType = el.attributeNS(KoXmlNS::manifest, "media-type", QString(""));
QString version = el.attributeNS(KoXmlNS::manifest, "version", QString());
// Only if fullPath is valid, should we store this entry.
// If not, we don't bother to find out exactly what is wrong, we just skip it.
if (!fullPath.isNull()) {
d->manifestEntries.insert(fullPath,
new KoOdfManifestEntry(fullPath, mediaType, version));
}
}
return true;
}
示例8: loadXML
bool KraConverter::loadXML(const KoXmlDocument &doc, KoStore *store)
{
Q_UNUSED(store);
KoXmlElement root;
KoXmlNode node;
if (doc.doctype().name() != "DOC") {
m_doc->setErrorMessage(i18n("The format is not supported or the file is corrupted"));
return false;
}
root = doc.documentElement();
int syntaxVersion = root.attribute("syntaxVersion", "3").toInt();
if (syntaxVersion > 2) {
m_doc->setErrorMessage(i18n("The file is too new for this version of Krita (%1).", syntaxVersion));
return false;
}
if (!root.hasChildNodes()) {
m_doc->setErrorMessage(i18n("The file has no layers."));
return false;
}
m_kraLoader = new KisKraLoader(m_doc, syntaxVersion);
// Legacy from the multi-image .kra file period.
for (node = root.firstChild(); !node.isNull(); node = node.nextSibling()) {
if (node.isElement()) {
if (node.nodeName() == "IMAGE") {
KoXmlElement elem = node.toElement();
if (!(m_image = m_kraLoader->loadXML(elem))) {
if (m_kraLoader->errorMessages().isEmpty()) {
m_doc->setErrorMessage(i18n("Unknown error."));
}
else {
m_doc->setErrorMessage(m_kraLoader->errorMessages().join(".\n"));
}
return false;
}
return true;
}
else {
if (m_kraLoader->errorMessages().isEmpty()) {
m_doc->setErrorMessage(i18n("The file does not contain an image."));
}
return false;
}
}
}
return false;
}
示例9: parseColorStops
void SvgStyleParser::parseColorStops(QGradient *gradient, const KoXmlElement &e)
{
QGradientStops stops;
QColor c;
for (KoXmlNode n = e.firstChild(); !n.isNull(); n = n.nextSibling()) {
KoXmlElement stop = n.toElement();
if (stop.tagName() == "stop") {
float offset;
QString temp = stop.attribute("offset");
if (temp.contains('%')) {
temp = temp.left(temp.length() - 1);
offset = temp.toFloat() / 100.0;
} else
offset = temp.toFloat();
QString stopColorStr = stop.attribute("stop-color");
if (!stopColorStr.isEmpty()) {
if (stopColorStr == "inherit") {
stopColorStr = inheritedAttribute("stop-color", stop);
}
parseColor(c, stopColorStr);
}
else {
// try style attr
QString style = stop.attribute("style").simplified();
QStringList substyles = style.split(';', QString::SkipEmptyParts);
for (QStringList::Iterator it = substyles.begin(); it != substyles.end(); ++it) {
QStringList substyle = it->split(':');
QString command = substyle[0].trimmed();
QString params = substyle[1].trimmed();
if (command == "stop-color")
parseColor(c, params);
if (command == "stop-opacity")
c.setAlphaF(params.toDouble());
}
}
QString opacityStr = stop.attribute("stop-opacity");
if (!opacityStr.isEmpty()) {
if (opacityStr == "inherit") {
opacityStr = inheritedAttribute("stop-opacity", stop);
}
c.setAlphaF(opacityStr.toDouble());
}
stops.append(QPair<qreal, QColor>(offset, c));
}
}
if (stops.count())
gradient->setStops(stops);
}
示例10: load
bool Context::load( const KoXmlDocument &document ) {
m_document = document; // create a copy, document is deleted under our feet
// Check if this is the right app
KoXmlElement elm = m_document.documentElement();
QString value = elm.attribute( "mime", QString() );
if ( value.isEmpty() ) {
errorPlan << "No mime type specified!";
// setErrorMessage( i18n( "Invalid document. No mimetype specified." ) );
return false;
} else if ( value != "application/x-vnd.kde.plan" ) {
if ( value == "application/x-vnd.kde.kplato" ) {
// accept, since we forgot to change kplato to plan for so long...
} else {
errorPlan << "Unknown mime type " << value;
// setErrorMessage( i18n( "Invalid document. Expected mimetype application/x-vnd.kde.kplato, got %1", value ) );
return false;
}
}
/* QString m_syntaxVersion = elm.attribute( "version", "0.0" );
if ( m_syntaxVersion > "0.0" ) {
int ret = KMessageBox::warningContinueCancel(
0, i18n( "This document was created with a newer version of Plan (syntax version: %1)\n"
"Opening it in this version of Plan will lose some information.", m_syntaxVersion ),
i18n( "File-Format Mismatch" ), KGuiItem( i18n( "Continue" ) ) );
if ( ret == KMessageBox::Cancel ) {
setErrorMessage( "USER_CANCELED" );
return false;
}
}
*/
/*
#ifdef KOXML_USE_QDOM
int numNodes = elm.childNodes().count();
#else
int numNodes = elm.childNodesCount();
#endif
*/
KoXmlNode n = elm.firstChild();
for ( ; ! n.isNull(); n = n.nextSibling() ) {
if ( ! n.isElement() ) {
continue;
}
KoXmlElement element = n.toElement();
if ( element.tagName() == "context" ) {
m_context = element;
m_contextLoaded = true;
}
}
return true;
}
示例11: loadAuthorInfo
bool KoDocumentInfo::loadAuthorInfo(const KoXmlElement &e)
{
KoXmlNode n = e.namedItem("author").firstChild();
for (; !n.isNull(); n = n.nextSibling()) {
KoXmlElement e = n.toElement();
if (e.isNull())
continue;
if (e.tagName() == "full-name")
setActiveAuthorInfo("creator", e.text().trimmed());
else
setActiveAuthorInfo(e.tagName(), e.text().trimmed());
}
return true;
}
示例12: loadWorkpackage
bool KPlatoXmlLoader::loadWorkpackage( const KoXmlElement& plan )
{
kDebug(kplatoXmlDebugArea());
bool ok = false;
if ( m_loader.workVersion() > KPLATOWORK_MAX_FILE_SYNTAX_VERSION ) {
int ret = KMessageBox::warningContinueCancel(
0, i18n( "This document was created with a newer version of KPlatoWork (syntax version: %1)\n"
"Opening it in this version of PlanWork will lose some information.", m_loader.workVersion() ),
i18n( "File-Format Mismatch" ), KGuiItem( i18n( "Continue" ) ) );
if ( ret == KMessageBox::Cancel ) {
m_message = "USER_CANCELED";
return false;
}
}
m_loader.startLoad();
Project *proj = new Project();
Package *package = new Package();
package->project = proj;
KoXmlNode n = plan.firstChild();
for ( ; ! n.isNull(); n = n.nextSibling() ) {
if ( ! n.isElement() ) {
continue;
}
KoXmlElement e = n.toElement();
if ( e.tagName() == "project" ) {
m_loader.setProject( proj );
ok = load( proj, e, m_loader );
if ( ! ok ) {
m_loader.addMsg( XMLLoaderObject::Errors, "Loading of work package failed" );
//TODO add some ui here
}
} else if ( e.tagName() == "workpackage" ) {
m_timeTag = e.attribute( "time-tag" );
package->ownerId = e.attribute( "owner-id" );
package->ownerName = e.attribute( "owner" );
KoXmlElement elem;
forEachElement( elem, e ) {
if ( elem.tagName() != "settings" ) {
continue;
}
package->settings.usedEffort = (bool)elem.attribute( "used-effort" ).toInt();
package->settings.progress = (bool)elem.attribute( "progress" ).toInt();
package->settings.documents = (bool)elem.attribute( "documents" ).toInt();
}
}
}
示例13: supports
bool KPrPlaceholderShapeFactory::supports(const KoXmlElement & e, KoShapeLoadingContext &context) const
{
Q_UNUSED(context);
// check parent if placeholder is set to true
KoXmlNode parent = e.parentNode();
if ( !parent.isNull() ) {
KoXmlElement element = parent.toElement();
if ( !element.isNull() ) {
bool supported = element.attributeNS( KoXmlNS::presentation, "placeholder", "false" ) == "true";
kDebug(33001) << "placeholder:" << supported;
#ifndef NWORKAROUND_ODF_BUGS
if (!supported && KoOdfWorkaround::fixPresentationPlaceholder() && element.hasAttributeNS(KoXmlNS::presentation, "class")) {
supported = true;
kDebug(33001) << "workaround OO placeholder bug" << supported;
}
#endif
return supported;
}
}
return false;
}
示例14: loadOasisAuthorInfo
bool KoDocumentInfo::loadOasisAuthorInfo(const KoXmlNode &metaDoc)
{
KoXmlElement e = KoXml::namedItemNS(metaDoc, KoXmlNS::dc, "creator");
if (!e.isNull() && !e.text().isEmpty())
setActiveAuthorInfo("creator", e.text());
KoXmlNode n = metaDoc.firstChild();
for (; !n.isNull(); n = n.nextSibling()) {
if (!n.isElement())
continue;
KoXmlElement e = n.toElement();
if (!(e.namespaceURI() == KoXmlNS::meta &&
e.localName() == "user-defined" && !e.text().isEmpty()))
continue;
QString name = e.attributeNS(KoXmlNS::meta, "name", QString());
setActiveAuthorInfo(name, e.text());
}
return true;
}
示例15: loadXML
KisImageWSP KisKraLoader::loadXML(const KoXmlElement& element)
{
QString attr;
KisImageWSP image = 0;
QString name;
qint32 width;
qint32 height;
QString profileProductName;
double xres;
double yres;
QString colorspacename;
const KoColorSpace * cs;
if ((attr = element.attribute(MIME)) == NATIVE_MIMETYPE) {
if ((m_d->imageName = element.attribute(NAME)).isNull()) {
m_d->errorMessages << i18n("Image does not have a name.");
return KisImageWSP(0);
}
if ((attr = element.attribute(WIDTH)).isNull()) {
m_d->errorMessages << i18n("Image does not specify a width.");
return KisImageWSP(0);
}
width = attr.toInt();
if ((attr = element.attribute(HEIGHT)).isNull()) {
m_d->errorMessages << i18n("Image does not specify a height.");
return KisImageWSP(0);
}
height = attr.toInt();
m_d->imageComment = element.attribute(DESCRIPTION);
xres = 100.0 / 72.0;
if (!(attr = element.attribute(X_RESOLUTION)).isNull()) {
if (attr.toDouble() > 1.0) {
xres = attr.toDouble() / 72.0;
}
}
yres = 100.0 / 72.0;
if (!(attr = element.attribute(Y_RESOLUTION)).isNull()) {
if (attr.toDouble() > 1.0) {
yres = attr.toDouble() / 72.0;
}
}
if ((colorspacename = element.attribute(COLORSPACE_NAME)).isNull()) {
// An old file: take a reasonable default.
// Krita didn't support anything else in those
// days anyway.
colorspacename = "RGBA";
}
profileProductName = element.attribute(PROFILE);
// A hack for an old colorspacename
convertColorSpaceNames(colorspacename, profileProductName);
QString colorspaceModel = KoColorSpaceRegistry::instance()->colorSpaceColorModelId(colorspacename).id();
QString colorspaceDepth = KoColorSpaceRegistry::instance()->colorSpaceColorDepthId(colorspacename).id();
if (profileProductName.isNull()) {
// no mention of profile so get default profile";
cs = KoColorSpaceRegistry::instance()->colorSpace(colorspaceModel, colorspaceDepth, "");
} else {
cs = KoColorSpaceRegistry::instance()->colorSpace(colorspaceModel, colorspaceDepth, profileProductName);
}
if (cs == 0) {
// try once more without the profile
cs = KoColorSpaceRegistry::instance()->colorSpace(colorspaceModel, colorspaceDepth, "");
if (cs == 0) {
m_d->errorMessages << i18n("Image specifies an unsupported color model: %1.", colorspacename);
return KisImageWSP(0);
}
}
if (m_d->document) {
image = new KisImage(m_d->document->createUndoStore(), width, height, cs, name);
}
else {
image = new KisImage(0, width, height, cs, name);
}
image->setResolution(xres, yres);
loadNodes(element, image, const_cast<KisGroupLayer*>(image->rootLayer().data()));
KoXmlNode child;
for (child = element.lastChild(); !child.isNull(); child = child.previousSibling()) {
KoXmlElement e = child.toElement();
if(e.tagName() == "ProjectionBackgroundColor") {
if (e.hasAttribute("ColorData")) {
QByteArray colorData = QByteArray::fromBase64(e.attribute("ColorData").toLatin1());
KoColor color((const quint8*)colorData.data(), image->colorSpace());
image->setDefaultProjectionColor(color);
}
}
if (e.tagName().toLower() == "animation") {
//.........这里部分代码省略.........