本文整理汇总了C++中KoXmlDocument::documentElement方法的典型用法代码示例。如果您正苦于以下问题:C++ KoXmlDocument::documentElement方法的具体用法?C++ KoXmlDocument::documentElement怎么用?C++ KoXmlDocument::documentElement使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类KoXmlDocument
的用法示例。
在下文中一共展示了KoXmlDocument::documentElement方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: d
KoOasisSettings::KoOasisSettings(const KoXmlDocument& doc)
: m_settingsElement(KoXml::namedItemNS(doc.documentElement(), KoXmlNS::office, "settings")),
m_configNsUri(KoXmlNS::config)
, d(0)
{
const KoXmlElement contents = doc.documentElement();
if (m_settingsElement.isNull())
kDebug(30003) << " document doesn't have tag 'office:settings'";
}
示例2: dev
KoShape *SvgShapeFactory::createShapeFromOdf(const KoXmlElement &element, KoShapeLoadingContext &context)
{
const KoXmlElement & imageElement(KoXml::namedItemNS(element, KoXmlNS::draw, "image"));
if (imageElement.isNull()) {
kError(30006) << "svg image element not found";
return 0;
}
if (imageElement.tagName() == "image") {
kDebug(30006) << "trying to create shapes form svg image";
QString href = imageElement.attribute("href");
if (href.isEmpty())
return 0;
// check the mimetype
if (href.startsWith("./")) {
href.remove(0,2);
}
QString mimetype = context.odfLoadingContext().mimeTypeForPath(href);
kDebug(30006) << mimetype;
if (mimetype != "image/svg+xml")
return 0;
if (!context.odfLoadingContext().store()->open(href))
return 0;
KoStoreDevice dev(context.odfLoadingContext().store());
KoXmlDocument xmlDoc;
int line, col;
QString errormessage;
const bool parsed = xmlDoc.setContent(&dev, &errormessage, &line, &col);
context.odfLoadingContext().store()->close();
if (! parsed) {
kError(30006) << "Error while parsing file: "
<< "at line " << line << " column: " << col
<< " message: " << errormessage << endl;
return 0;
}
SvgParser parser(context.documentResourceManager());
QList<KoShape*> shapes = parser.parseSvg(xmlDoc.documentElement());
if (shapes.isEmpty())
return 0;
if (shapes.count() == 1)
return shapes.first();
KoShapeGroup *svgGroup = new KoShapeGroup;
KoShapeGroupCommand cmd(svgGroup, shapes);
cmd.redo();
return svgGroup;
}
return 0;
}
示例3: testOdfElement
void TestKoShapeFactory::testOdfElement()
{
KoShapeFactoryBase * factory = new KoPathShapeFactory(QStringList());
QVERIFY(factory->odfElements().front().second.contains("path"));
QVERIFY(factory->odfElements().front().second.contains("line"));
QVERIFY(factory->odfElements().front().second.contains("polyline"));
QVERIFY(factory->odfElements().front().second.contains("polygon"));
QVERIFY(factory->odfElements().front().first == KoXmlNS::draw);
QBuffer xmldevice;
xmldevice.open(QIODevice::WriteOnly);
QTextStream xmlstream(&xmldevice);
xmlstream << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
xmlstream << "<office:document-content xmlns:office=\"urn:oasis:names:tc:opendocument:xmlns:office:1.0\" xmlns:meta=\"urn:oasis:names:tc:opendocument:xmlns:meta:1.0\" xmlns:config=\"urn:oasis:names:tc:opendocument:xmlns:config:1.0\" xmlns:text=\"urn:oasis:names:tc:opendocument:xmlns:text:1.0\" xmlns:table=\"urn:oasis:names:tc:opendocument:xmlns:table:1.0\" xmlns:draw=\"urn:oasis:names:tc:opendocument:xmlns:drawing:1.0\" xmlns:presentation=\"urn:oasis:names:tc:opendocument:xmlns:presentation:1.0\" xmlns:dr3d=\"urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0\" xmlns:chart=\"urn:oasis:names:tc:opendocument:xmlns:chart:1.0\" xmlns:form=\"urn:oasis:names:tc:opendocument:xmlns:form:1.0\" xmlns:script=\"urn:oasis:names:tc:opendocument:xmlns:script:1.0\" xmlns:style=\"urn:oasis:names:tc:opendocument:xmlns:style:1.0\" xmlns:number=\"urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0\" xmlns:math=\"http://www.w3.org/1998/Math/MathML\" xmlns:svg=\"urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0\" xmlns:fo=\"urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0\" xmlns:koffice=\"http://www.koffice.org/2005/\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">";
xmlstream << "<office:body>";
xmlstream << "<office:text>";
xmlstream << "<text:p text:style-name=\"P1\"><?opendocument cursor-position?></text:p>";
xmlstream << "<draw:path svg:d=\"M10,10L100,100\"></draw:path>";
xmlstream << "</office:text>";
xmlstream << "</office:body>";
xmlstream << "</office:document-content>";
xmldevice.close();
KoXmlDocument doc;
QString errorMsg;
int errorLine = 0;
int errorColumn = 0;
QCOMPARE(doc.setContent(&xmldevice, true, &errorMsg, &errorLine, &errorColumn), true);
QCOMPARE(errorMsg.isEmpty(), true);
QCOMPARE(errorLine, 0);
QCOMPARE(errorColumn, 0);
KoXmlElement contentElement = doc.documentElement();
KoXmlElement bodyElement = contentElement.firstChild().toElement();
// XXX: When loading is implemented, these no doubt have to be
// sensibly filled.
KoOdfStylesReader stylesReader;
KoOdfLoadingContext odfContext(stylesReader, 0);
KoShapeLoadingContext shapeContext(odfContext, 0);
KoXmlElement textElement = bodyElement.firstChild().firstChild().toElement();
QVERIFY(textElement.tagName() == "p");
QCOMPARE(factory->supports(textElement, shapeContext), false);
KoXmlElement pathElement = bodyElement.firstChild().lastChild().toElement();
QVERIFY(pathElement.tagName() == "path");
QCOMPARE(factory->supports(pathElement, shapeContext), true);
KoShape *shape = factory->createDefaultShape();
QVERIFY(shape);
QVERIFY(shape->loadOdf(pathElement, shapeContext));
delete shape;
delete factory;
}
示例4: 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;
}
示例5: layout
static QRectF layout(BasicElement* element, const QString& input)
{
KoXmlDocument doc;
doc.setContent( input );
element->readMathML(doc.documentElement());
AttributeManager am;
element->layout( &am );
return element->boundingRect();
}
示例6: 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;
}
示例7: testCreateFramedShapes
void TestKoShapeRegistry::testCreateFramedShapes()
{
QBuffer xmldevice;
xmldevice.open(QIODevice::WriteOnly);
QTextStream xmlstream(&xmldevice);
xmlstream << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
xmlstream << "<office:document-content xmlns:office=\"urn:oasis:names:tc:opendocument:xmlns:office:1.0\" xmlns:meta=\"urn:oasis:names:tc:opendocument:xmlns:meta:1.0\" xmlns:config=\"urn:oasis:names:tc:opendocument:xmlns:config:1.0\" xmlns:text=\"urn:oasis:names:tc:opendocument:xmlns:text:1.0\" xmlns:table=\"urn:oasis:names:tc:opendocument:xmlns:table:1.0\" xmlns:draw=\"urn:oasis:names:tc:opendocument:xmlns:drawing:1.0\" xmlns:presentation=\"urn:oasis:names:tc:opendocument:xmlns:presentation:1.0\" xmlns:dr3d=\"urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0\" xmlns:chart=\"urn:oasis:names:tc:opendocument:xmlns:chart:1.0\" xmlns:form=\"urn:oasis:names:tc:opendocument:xmlns:form:1.0\" xmlns:script=\"urn:oasis:names:tc:opendocument:xmlns:script:1.0\" xmlns:style=\"urn:oasis:names:tc:opendocument:xmlns:style:1.0\" xmlns:number=\"urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0\" xmlns:math=\"http://www.w3.org/1998/Math/MathML\" xmlns:svg=\"urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0\" xmlns:fo=\"urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0\" xmlns:calligra=\"http://www.calligra.org/2005/\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">";
xmlstream << "<office:body>";
xmlstream << "<office:text>";
xmlstream << "<draw:path svg:d=\"M0,0L100,100\"></draw:path>";
xmlstream << "</office:text>";
xmlstream << "</office:body>";
xmlstream << "</office:document-content>";
xmldevice.close();
KoXmlDocument doc;
QString errorMsg;
int errorLine = 0;
int errorColumn = 0;
QCOMPARE(doc.setContent(&xmldevice, true, &errorMsg, &errorLine, &errorColumn), true);
QCOMPARE(errorMsg.isEmpty(), true);
QCOMPARE(errorLine, 0);
QCOMPARE(errorColumn, 0);
KoXmlElement contentElement = doc.documentElement();
KoXmlElement bodyElement = contentElement.firstChild().toElement();
KoShapeRegistry * registry = KoShapeRegistry::instance();
// XXX: When loading is implemented, these no doubt have to be
// sensibly filled.
KoOdfStylesReader stylesReader;
KoOdfLoadingContext odfContext(stylesReader, 0);
KoShapeLoadingContext shapeContext(odfContext, 0);
KoShape * shape = registry->createShapeFromOdf(bodyElement, shapeContext);
QVERIFY(shape == 0);
KoXmlElement pathElement = bodyElement.firstChild().firstChild().toElement();
shape = registry->createShapeFromOdf(pathElement, shapeContext);
QVERIFY(shape != 0);
QVERIFY(shape->shapeId() == KoPathShapeId);
}
示例8: loadNodeKeyframes
void KisKraLoadVisitor::loadNodeKeyframes(KisNode *node)
{
if (!m_keyframeFilenames.contains(node)) return;
node->enableAnimation();
const QString &location = getLocation(m_keyframeFilenames[node]);
if (!m_store->open(location)) {
m_errorMessages << i18n("Could not load keyframes from %1.", location);
return;
}
QString errorMsg;
int errorLine;
int errorColumn;
KoXmlDocument doc = KoXmlDocument(true);
bool ok = doc.setContent(m_store->device(), &errorMsg, &errorLine, &errorColumn);
m_store->close();
if (!ok) {
m_errorMessages << i18n("parsing error in the keyframe file %1 at line %2, column %3\nError message: %4", location, errorLine, errorColumn, i18n(errorMsg.toUtf8()));
return;
}
QDomDocument dom;
KoXml::asQDomElement(dom, doc.documentElement());
QDomElement root = dom.firstChildElement();
for (QDomElement child = root.firstChildElement(); !child.isNull(); child = child.nextSiblingElement()) {
if (child.nodeName().toUpper() == "CHANNEL") {
QString id = child.attribute("name");
KisKeyframeChannel *channel = node->getKeyframeChannel(id, true);
if (!channel) {
m_errorMessages << i18n("unknown keyframe channel type: %1 in %2", id, location);
continue;
}
channel->loadXML(child);
}
}
}
示例9: unknownShiftDirection
// static
bool PasteCommand::unknownShiftDirection(const QMimeData *mimeData)
{
if (!mimeData) {
return false;
}
QByteArray byteArray;
if (mimeData->hasFormat("application/x-kspread-snippet")) {
byteArray = mimeData->data("application/x-kspread-snippet");
} else {
return false;
}
QString errorMsg;
int errorLine;
int errorColumn;
KoXmlDocument d;
if (!d.setContent(byteArray, false, &errorMsg, &errorLine, &errorColumn)) {
// an error occurred
kDebug() << "An error occurred."
<< "line:" << errorLine << "col:" << errorColumn << errorMsg;
return false;
}
KoXmlElement e = d.documentElement();
if (!e.namedItem("columns").toElement().isNull()) {
return false;
}
if (!e.namedItem("rows").toElement().isNull()) {
return false;
}
KoXmlElement c = e.firstChild().toElement();
for (; !c.isNull(); c = c.nextSibling().toElement()) {
if (c.tagName() == "cell") {
return true;
}
}
return false;
}
示例10: loadXML
bool Doc::loadXML(const KoXmlDocument& doc, KoStore*)
{
QPointer<KoUpdater> updater;
if (progressUpdater()) {
updater = progressUpdater()->startSubtask(1, "KSpread::Doc::loadXML");
updater->setProgress(0);
}
d->spellListIgnoreAll.clear();
// <spreadsheet>
KoXmlElement spread = doc.documentElement();
if (spread.attribute("mime") != "application/x-kspread" && spread.attribute("mime") != "application/vnd.kde.kspread") {
setErrorMessage(i18n("Invalid document. Expected mimetype application/x-kspread or application/vnd.kde.kspread, got %1" , spread.attribute("mime")));
return false;
}
bool ok = false;
int version = spread.attribute("syntaxVersion").toInt(&ok);
map()->setSyntaxVersion(ok ? version : 0);
if (map()->syntaxVersion() > CURRENT_SYNTAX_VERSION) {
int ret = KMessageBox::warningContinueCancel(
0, i18n("This document was created with a newer version of Calligra Sheets (syntax version: %1)\n"
"When you open it with this version of Calligra Sheets, some information may be lost.", map()->syntaxVersion()),
i18n("File Format Mismatch"), KStandardGuiItem::cont());
if (ret == KMessageBox::Cancel) {
setErrorMessage("USER_CANCELED");
return false;
}
}
// <locale>
KoXmlElement loc = spread.namedItem("locale").toElement();
if (!loc.isNull())
static_cast<Localization*>(map()->calculationSettings()->locale())->load(loc);
if (updater) updater->setProgress(5);
KoXmlElement defaults = spread.namedItem("defaults").toElement();
if (!defaults.isNull()) {
double dim = defaults.attribute("row-height").toDouble(&ok);
if (!ok)
return false;
map()->setDefaultRowHeight(dim);
dim = defaults.attribute("col-width").toDouble(&ok);
if (!ok)
return false;
map()->setDefaultColumnWidth(dim);
}
KoXmlElement ignoreAll = spread.namedItem("SPELLCHECKIGNORELIST").toElement();
if (!ignoreAll.isNull()) {
KoXmlElement spellWord = spread.namedItem("SPELLCHECKIGNORELIST").toElement();
spellWord = spellWord.firstChild().toElement();
while (!spellWord.isNull()) {
if (spellWord.tagName() == "SPELLCHECKIGNOREWORD") {
d->spellListIgnoreAll.append(spellWord.attribute("word"));
}
spellWord = spellWord.nextSibling().toElement();
}
}
if (updater) updater->setProgress(40);
// In case of reload (e.g. from konqueror)
qDeleteAll(map()->sheetList());
map()->sheetList().clear();
KoXmlElement styles = spread.namedItem("styles").toElement();
if (!styles.isNull()) {
if (!map()->styleManager()->loadXML(styles)) {
setErrorMessage(i18n("Styles cannot be loaded."));
return false;
}
}
// <map>
KoXmlElement mymap = spread.namedItem("map").toElement();
if (mymap.isNull()) {
setErrorMessage(i18n("Invalid document. No map tag."));
return false;
}
if (!map()->loadXML(mymap)) {
return false;
}
// named areas
const KoXmlElement areaname = spread.namedItem("areaname").toElement();
if (!areaname.isNull())
map()->namedAreaManager()->loadXML(areaname);
//Backwards compatibility with older versions for paper layout
if (map()->syntaxVersion() < 1) {
KoXmlElement paper = spread.namedItem("paper").toElement();
if (!paper.isNull()) {
loadPaper(paper);
}
//.........这里部分代码省略.........
示例11: testRichText
void CellTest::testRichText()
{
KoOdfStylesReader stylesReader;
QBuffer buffer;
buffer.open(QIODevice::ReadOnly);
KoStore *store = KoStore::createStore(&buffer, KoStore::Read);
KoOdfLoadingContext odfContext(stylesReader, store);
OdfLoadingContext context(odfContext);
KoDocumentResourceManager documentResources;
KoShapeLoadingContext shapeContext(odfContext, &documentResources);
context.shapeContext = &shapeContext;
Styles autoStyles;
QString cellStyleName;
Map map;
Sheet* sheet = map.addNewSheet();
CellStorage* storage = sheet->cellStorage();
storage->setValue(1, 1, Value(1));
Cell cell = storage->firstInRow(1);
QVERIFY(!cell.isNull());
{ // Test the simple case. Only one paragraph with some simple text.
KoXmlDocument doc = xmlDocument("<text:p>Some text</text:p>");
KoXmlElement e = doc.documentElement();
QVERIFY(!e.isNull());
cell.loadOdfCellText(e, context, autoStyles, cellStyleName);
QVERIFY(!cell.isNull());
QVERIFY(!cell.richText());
QVERIFY(cell.userInput().split('\n').count() == 1);
}
{ // Text in the paragraph and in a child text:span means rich-text.
KoXmlDocument doc = xmlDocument("<text:p>First<text:span>Second<text:span>Theird</text:span></text:span></text:p>");
KoXmlElement e = doc.documentElement();
QVERIFY(!e.isNull());
cell.loadOdfCellText(e, context, autoStyles, cellStyleName);
QVERIFY(!cell.isNull());
QVERIFY(cell.richText());
QVERIFY(cell.userInput().split('\n').count() == 1);
}
{ // The text:line-break should be translated into a \n newline and since there is no other rich-text it should not be detected as such.
KoXmlDocument doc = xmlDocument("<text:p>First<text:line-break/>Second</text:p>");
KoXmlElement e = doc.documentElement();
QVERIFY(!e.isNull());
cell.loadOdfCellText(e, context, autoStyles, cellStyleName);
QVERIFY(!cell.isNull());
QVERIFY(!cell.richText());
QVERIFY(cell.userInput().split('\n').count() == 2);
}
{ // The text:s and text:tab should be translated into space and tabulator. No rich-text else.
KoXmlDocument doc = xmlDocument("<text:p>First<text:s/>Second<text:tab/>Theird</text:p>");
KoXmlElement e = doc.documentElement();
QVERIFY(!e.isNull());
cell.loadOdfCellText(e, context, autoStyles, cellStyleName);
QVERIFY(!cell.isNull());
QVERIFY(!cell.richText());
QVERIFY(cell.userInput().split('\n').count() == 1);
}
}
示例12: load
static void load(BasicElement* element, const QString& input)
{
KoXmlDocument doc;
doc.setContent( input );
element->readMathML(doc.documentElement());
}