summaryrefslogtreecommitdiff
path: root/sc/source/ui/xmlsource
diff options
context:
space:
mode:
authorKohei Yoshida <kohei@libreoffice.org>2019-08-20 22:11:03 -0400
committerKohei Yoshida <kohei@libreoffice.org>2019-08-22 01:55:00 +0200
commit52cff86bc74cec1a6755809c6b5434afa32a274c (patch)
treeda8faf59a50da500a25e82deff3928510129a482 /sc/source/ui/xmlsource
parent86d55aaad49a3f83b61894afd81f195b37a142af (diff)
Fully support importing of XML with nested repeat elements.
With this change, Calc's XML Source will allow importing XML that contains nested repeat elements. It is something the old implementation did not support. Change-Id: I73fa1087ccd727390a47007bcfabd411cf007621 Reviewed-on: https://gerrit.libreoffice.org/77941 Tested-by: Jenkins Reviewed-by: Kohei Yoshida <kohei@libreoffice.org>
Diffstat (limited to 'sc/source/ui/xmlsource')
-rw-r--r--sc/source/ui/xmlsource/xmlsourcedlg.cxx43
1 files changed, 15 insertions, 28 deletions
diff --git a/sc/source/ui/xmlsource/xmlsourcedlg.cxx b/sc/source/ui/xmlsource/xmlsourcedlg.cxx
index dd78ab5e18b9..0cd202c8dec6 100644
--- a/sc/source/ui/xmlsource/xmlsourcedlg.cxx
+++ b/sc/source/ui/xmlsource/xmlsourcedlg.cxx
@@ -205,10 +205,10 @@ void ScXMLSourceDlg::LoadSourceFileStructure(const OUString& rPath)
namespace {
/**
- * When the current entry is a direct or indirect child of a mappable
- * repeat element entry, that entry becomes the reference entry.
- * Otherwise the reference entry equals the current entry. A reference
- * entry is the entry that stores mapped cell position.
+ * The current entry is the reference entry for a cell link. For a range
+ * link, the reference entry is the shallowest repeat element entry up from
+ * the current entry position. The mapped cell position for a range link is
+ * stored with the reference entry.
*/
std::unique_ptr<weld::TreeIter> getReferenceEntry(const weld::TreeView& rTree, weld::TreeIter& rCurEntry)
{
@@ -221,14 +221,7 @@ std::unique_ptr<weld::TreeIter> getReferenceEntry(const weld::TreeView& rTree, w
OSL_ASSERT(pUserData);
if (pUserData->meType == ScOrcusXMLTreeParam::ElementRepeat)
{
- // This is a repeat element.
- if (xRefEntry)
- {
- // Second repeat element encountered. Not good.
- std::unique_ptr<weld::TreeIter> xCurEntry(rTree.make_iterator(&rCurEntry));
- return xCurEntry;
- }
-
+ // This is a repeat element - a potential reference entry.
xRefEntry = rTree.make_iterator(xParent.get());
}
bParent = rTree.iter_parent(*xParent);
@@ -332,9 +325,7 @@ void ScXMLSourceDlg::RepeatElementSelected(weld::TreeIter& rEntry)
}
// Check all its child elements / attributes and make sure non of them are
- // linked or repeat elements. In the future we will support range linking
- // of repeat element who has another repeat elements. But first I need to
- // support that scenario in orcus.
+ // linked.
if (IsChildrenDirty(&rEntry))
{
@@ -420,11 +411,6 @@ bool ScXMLSourceDlg::IsParentDirty(weld::TreeIter* pEntry) const
// This parent is already linked.
return true;
}
- if (pUserData->meType == ScOrcusXMLTreeParam::ElementRepeat)
- {
- // This is a repeat element.
- return true;
- }
}
while (mxLbTree->iter_parent(*xParent));
return false;
@@ -444,10 +430,6 @@ bool ScXMLSourceDlg::IsChildrenDirty(weld::TreeIter* pEntry) const
// Already linked.
return true;
- if (pUserData->meType == ScOrcusXMLTreeParam::ElementRepeat)
- // We don't support linking of nested repeat elements (yet).
- return true;
-
if (pUserData->meType == ScOrcusXMLTreeParam::ElementDefault)
{
// Check recursively.
@@ -478,9 +460,14 @@ void getFieldLinks(
OUString aPath = getXPath(rTree, *xChild, rNamespaces);
const ScOrcusXMLTreeParam::EntryData* pUserData = ScOrcusXMLTreeParam::getUserData(rTree, *xChild);
- if (pUserData && pUserData->mbLeafNode)
+ if (pUserData)
{
- if (!aPath.isEmpty())
+ if (pUserData->meType == ScOrcusXMLTreeParam::ElementRepeat)
+ // nested repeat element automatically becomes a row-group node.
+ rRangeLink.maRowGroups.push_back(
+ OUStringToOString(aPath, RTL_TEXTENCODING_UTF8));
+
+ if (pUserData->mbLeafNode && !aPath.isEmpty())
// XPath should never be empty anyway, but it won't hurt to check...
rRangeLink.maFieldPaths.push_back(OUStringToOString(aPath, RTL_TEXTENCODING_UTF8));
}
@@ -533,8 +520,8 @@ void ScXMLSourceDlg::OkPressed()
// Go through all its child elements.
getFieldLinks(aRangeLink, aParam.maNamespaces, *mxLbTree, *rEntry);
- // Add the anchor node as a grouping node, which will be used as a
- // row position increment point.
+ // Add the reference entry as a row-group node, which will be used
+ // as a row position increment point.
OUString aThisEntry = getXPath(*mxLbTree, *rEntry, aParam.maNamespaces);
aRangeLink.maRowGroups.push_back(
OUStringToOString(aThisEntry, RTL_TEXTENCODING_UTF8));