KoShape* StencilShapeFactory:: createFromOdf(KoStore* store, KoDocumentResourceManager* documentRes) const { KoOdfReadStore odfStore(store); QString errorMessage; if (! odfStore.loadAndParse(errorMessage)) { kError() << "loading and parsing failed:" << errorMessage << endl; return 0; } KoXmlElement content = odfStore.contentDoc().documentElement(); KoXmlElement realBody(KoXml::namedItemNS(content, KoXmlNS::office, "body")); if (realBody.isNull()) { kError() << "No body tag found!" << endl; return 0; } KoXmlElement body = KoXml::namedItemNS(realBody, KoXmlNS::office, "drawing"); if (body.isNull()) { kError() << "No office:drawing tag found!" << endl; return 0; } KoXmlElement page = KoXml::namedItemNS(body, KoXmlNS::draw, "page"); if (page.isNull()) { kError() << "No page found!" << endl; return 0; } KoXmlElement shapeElement = KoXml::namedItemNS(page, KoXmlNS::draw, "g"); if (shapeElement.isNull()) { shapeElement = KoXml::namedItemNS(page, KoXmlNS::draw, "custom-shape"); if (shapeElement.isNull()) { kError() << "draw:g or draw:custom-shape element not found!" << endl; return 0; } } KoOdfLoadingContext loadingContext(odfStore.styles(), odfStore.store()); KoShapeLoadingContext context(loadingContext, documentRes); KoShapeRegistry* registry = KoShapeRegistry::instance(); foreach (const QString & id, registry->keys()) { KoShapeFactoryBase* shapeFactory = registry->value(id); shapeFactory->newDocumentResourceManager(documentRes); } return KoShapeRegistry::instance()->createShapeFromOdf(shapeElement, context); }
DocBase::DocBase(QWidget *parentWidget, QObject* parent, bool singleViewMode) : KoDocument(parentWidget, parent, singleViewMode) , d(new Private) { d->resourceManager = new KoResourceManager(); d->map = new Map(this, CURRENT_SYNTAX_VERSION); // Document Url for FILENAME function and page header/footer. d->map->calculationSettings()->setFileName(url().prettyUrl()); KoShapeRegistry *registry = KoShapeRegistry::instance(); foreach (const QString &id, registry->keys()) { KoShapeFactoryBase *shapeFactory = registry->value(id); shapeFactory->newDocumentResourceManager(d->resourceManager); } d->configLoadFromFile = false; documents().append(this); d->sheetAccessModel = new SheetAccessModel(d->map); }