summaryrefslogtreecommitdiff
path: root/chart2
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2022-12-10 12:34:50 +0100
committerStephan Bergmann <sbergman@redhat.com>2022-12-14 12:56:52 +0000
commit56e17186ffcda7e93530bef3a06120584bb7d579 (patch)
tree71f3de002cb1e822da6d7fc5d5241dd94f45d8f8 /chart2
parent8bdb85f8c7f31e51328afa51a584c3cfdea1c06f (diff)
[API CHANGE] Merge sfx2::XmlDump into css::qa::XDumper
Both sfx2::XmlDump and css::qa::XDumper were (only) used to dump various data from ChartModel and ChartView instances in debugging (e.g., F12 and Shift-F12 in an SW_DEBUG=1 Writer) and testing scenarios. The problem with XmlDump was that it was used as the target of a dynamic_cast from a UNO type, which is dangerous (see the upcoming commit introducing loplugin:unocast for details). One fix would have been to replace that dynamic_cast with a use of XUnoTunnel, and make ChartModel and ChartView implement that. But those classes already implement XDumper, so it looks more natural to use XDumper for that purpose too. However, the information that was obtained via XDumper was rather different from the information that was obtained via XmlDump. So make an incompatible change to the (unpublished) XDumper, adding a kind parameter distinguishing the original behavior of XDumper (kind == "shapes") from the original behavior of XmlDump (kind == ""). Change-Id: Ia7379bedfc45ab62a298fdc2f030cebaf21c4885 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/144145 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'chart2')
-rw-r--r--chart2/inc/ChartModel.hxx12
-rw-r--r--chart2/inc/ChartView.hxx7
-rw-r--r--chart2/qa/extras/xshape/chart2xshape.cxx14
-rw-r--r--chart2/source/controller/main/ChartController_Window.cxx2
-rw-r--r--chart2/source/inc/dumpxmltostring.hxx41
-rw-r--r--chart2/source/model/main/ChartModel.cxx10
-rw-r--r--chart2/source/view/main/ChartView.cxx8
7 files changed, 73 insertions, 21 deletions
diff --git a/chart2/inc/ChartModel.hxx b/chart2/inc/ChartModel.hxx
index b877e47db5e0..8c876d8b95e6 100644
--- a/chart2/inc/ChartModel.hxx
+++ b/chart2/inc/ChartModel.hxx
@@ -52,10 +52,11 @@
#include <cppuhelper/implbase.hxx>
#include <comphelper/interfacecontainer2.hxx>
#include <vcl/GraphicObject.hxx>
-#include <sfx2/xmldump.hxx>
#include <memory>
+typedef struct _xmlTextWriter* xmlTextWriterPtr;
+
namespace com::sun::star::awt { class XRequestCallback; }
namespace com::sun::star::chart2::data { class XDataProvider; }
namespace com::sun::star::document { class XFilter; }
@@ -113,7 +114,7 @@ class UndoManager;
class ChartView;
class OOO_DLLPUBLIC_CHARTTOOLS SAL_LOPLUGIN_ANNOTATE("crosscast") ChartModel final :
- public impl::ChartModel_Base, public sfx2::XmlDump
+ public impl::ChartModel_Base
{
private:
@@ -452,7 +453,7 @@ public:
virtual void SAL_CALL update() override;
// XDumper
- virtual OUString SAL_CALL dump() override;
+ virtual OUString SAL_CALL dump(OUString const & kind) override;
// normal methods
css::uno::Reference< css::util::XNumberFormatsSupplier > const &
@@ -474,10 +475,9 @@ public:
const rtl::Reference< ::chart::ChartTypeManager > & getTypeManager() const { return m_xChartTypeManager; }
- /// See sfx2::XmlDump::dumpAsXml().
- void dumpAsXml(xmlTextWriterPtr pWriter) const override;
-
private:
+ void dumpAsXml(xmlTextWriterPtr pWriter) const;
+
sal_Int32 mnStart;
sal_Int32 mnEnd;
};
diff --git a/chart2/inc/ChartView.hxx b/chart2/inc/ChartView.hxx
index 5c7e70e97900..5f0665877e3d 100644
--- a/chart2/inc/ChartView.hxx
+++ b/chart2/inc/ChartView.hxx
@@ -43,7 +43,6 @@
#include <memory>
#include <vcl/timer.hxx>
-#include <sfx2/xmldump.hxx>
namespace com::sun::star::drawing { class XDrawPage; }
namespace com::sun::star::drawing { class XShapes; }
@@ -97,7 +96,6 @@ class OOO_DLLPUBLIC_CHARTVIEW ChartView final : public ::cppu::WeakImplHelper<
>
, public ExplicitValueProvider
, private SfxListener
- , public sfx2::XmlDump
{
private:
void init();
@@ -180,14 +178,13 @@ public:
virtual ::sal_Int64 SAL_CALL getSomething( const css::uno::Sequence< ::sal_Int8 >& aIdentifier ) override;
// XDumper
- virtual OUString SAL_CALL dump() override;
+ virtual OUString SAL_CALL dump(OUString const & kind) override;
void setViewDirty();
css::uno::Reference<css::uno::XComponentContext> const& getComponentContext() { return m_xCC;}
- /// See sfx2::XmlDump::dumpAsXml().
- void dumpAsXml(xmlTextWriterPtr pWriter) const override;
+ void dumpAsXml(xmlTextWriterPtr pWriter) const;
private: //methods
void createShapes();
diff --git a/chart2/qa/extras/xshape/chart2xshape.cxx b/chart2/qa/extras/xshape/chart2xshape.cxx
index 23e3f93eaafa..92605a71199c 100644
--- a/chart2/qa/extras/xshape/chart2xshape.cxx
+++ b/chart2/qa/extras/xshape/chart2xshape.cxx
@@ -63,6 +63,11 @@ private:
namespace
{
+OUString getShapeDump(css::uno::Reference<css::chart::XChartDocument> const& doc)
+{
+ return css::uno::Reference<css::qa::XDumper>(doc, css::uno::UNO_QUERY_THROW)->dump("shapes");
+}
+
bool checkDumpAgainstFile(std::u16string_view rDump, std::u16string_view aFilePath,
char const* toleranceFile)
{
@@ -80,8 +85,7 @@ OUString Chart2XShapeTest::getXShapeDumpString()
{
uno::Reference<chart::XChartDocument> xChartDoc(getChartCompFromSheet(0, 0, mxComponent),
UNO_QUERY_THROW);
- uno::Reference<qa::XDumper> xDumper(xChartDoc, UNO_QUERY_THROW);
- return xDumper->dump();
+ return getShapeDump(xChartDoc);
}
xmlDocUniquePtr Chart2XShapeTest::getXShapeDumpXmlDoc()
@@ -132,8 +136,7 @@ void Chart2XShapeTest::testTdf149204()
// - Attr: sizeX
loadFromURL(u"pptx/tdf149204.pptx");
uno::Reference<chart::XChartDocument> xChartDoc = getChartDocFromDrawImpress(0, 0);
- uno::Reference<qa::XDumper> xDumper(xChartDoc, UNO_QUERY_THROW);
- compareAgainstReference(xDumper->dump(), u"tdf149204.xml");
+ compareAgainstReference(getShapeDump(xChartDoc), u"tdf149204.xml");
}
void Chart2XShapeTest::testTdf151424()
@@ -251,8 +254,7 @@ void Chart2XShapeTest::testTdf88154LabelRotatedLayout()
{
loadFromURL(u"pptx/tdf88154_LabelRotatedLayout.pptx");
uno::Reference<chart::XChartDocument> xChartDoc = getChartDocFromDrawImpress(0, 5);
- uno::Reference<qa::XDumper> xDumper(xChartDoc, UNO_QUERY_THROW);
- OUString rDump = xDumper->dump();
+ OUString rDump = getShapeDump(xChartDoc);
OString aXmlDump = OUStringToOString(rDump, RTL_TEXTENCODING_UTF8);
xmlDocUniquePtr pXmlDoc(xmlParseDoc(reinterpret_cast<const xmlChar*>(aXmlDump.getStr())));
diff --git a/chart2/source/controller/main/ChartController_Window.cxx b/chart2/source/controller/main/ChartController_Window.cxx
index 018419b0eacf..70ab5436e148 100644
--- a/chart2/source/controller/main/ChartController_Window.cxx
+++ b/chart2/source/controller/main/ChartController_Window.cxx
@@ -1563,7 +1563,7 @@ bool ChartController::execute_KeyInput( const KeyEvent& rKEvt )
rtl::Reference< ChartModel > xChartModel = getChartModel();
if(xChartModel.is())
{
- OUString aDump = xChartModel->dump();
+ OUString aDump = xChartModel->dump("shapes");
SAL_WARN("chart2", aDump);
}
}
diff --git a/chart2/source/inc/dumpxmltostring.hxx b/chart2/source/inc/dumpxmltostring.hxx
new file mode 100644
index 000000000000..d03f1cab9d45
--- /dev/null
+++ b/chart2/source/inc/dumpxmltostring.hxx
@@ -0,0 +1,41 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#pragma once
+
+#include <sal/config.h>
+
+#include <libxml/tree.h>
+#include <libxml/xmlwriter.h>
+
+#include <new>
+
+namespace chart
+{
+template <typename F> OUString dumpXmlToString(F f)
+{
+ auto const buf = xmlBufferCreate();
+ if (buf == nullptr)
+ {
+ throw std::bad_alloc();
+ }
+ auto const writer = xmlNewTextWriterMemory(buf, 0);
+ if (writer == nullptr)
+ {
+ throw std::bad_alloc();
+ }
+ f(writer);
+ xmlFreeTextWriter(writer);
+ OString s(reinterpret_cast<char const*>(xmlBufferContent(buf)), xmlBufferLength(buf));
+ xmlBufferFree(buf);
+ return OStringToOUString(s, RTL_TEXTENCODING_ISO_8859_1); //TODO
+}
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/chart2/source/model/main/ChartModel.cxx b/chart2/source/model/main/ChartModel.cxx
index 781fc7c8e08a..0564f83703b8 100644
--- a/chart2/source/model/main/ChartModel.cxx
+++ b/chart2/source/model/main/ChartModel.cxx
@@ -36,6 +36,7 @@
#include <PopupRequest.hxx>
#include <ModifyListenerHelper.hxx>
#include <Diagram.hxx>
+#include <dumpxmltostring.hxx>
#include <com/sun/star/chart/ChartDataRowSource.hpp>
#include <com/sun/star/chart2/data/XPivotTableDataProvider.hpp>
@@ -1257,12 +1258,17 @@ uno::Sequence< Reference< chart2::data::XLabeledDataSequence > > SAL_CALL ChartM
}
//XDumper
-OUString SAL_CALL ChartModel::dump()
+OUString SAL_CALL ChartModel::dump(OUString const & kind)
{
+ if (kind.isEmpty()) {
+ return dumpXmlToString([this](auto writer) { return dumpAsXml(writer); });
+ }
+
+ // kind == "shapes":
uno::Reference< qa::XDumper > xDumper(
createInstance( CHART_VIEW_SERVICE_NAME ), uno::UNO_QUERY );
if (xDumper.is())
- return xDumper->dump();
+ return xDumper->dump(kind);
return OUString();
}
diff --git a/chart2/source/view/main/ChartView.cxx b/chart2/source/view/main/ChartView.cxx
index 584dfdb5ea72..2de5611c5ed0 100644
--- a/chart2/source/view/main/ChartView.cxx
+++ b/chart2/source/view/main/ChartView.cxx
@@ -56,6 +56,7 @@
#include <DateHelper.hxx>
#include <ExplicitCategoriesProvider.hxx>
#include <defines.hxx>
+#include <dumpxmltostring.hxx>
#include <unonames.hxx>
#include <editeng/frmdiritem.hxx>
#include <editeng/eeitem.hxx>
@@ -1784,8 +1785,13 @@ uno::Sequence< OUString > ChartView::getAvailableServiceNames()
return aServiceNames;
}
-OUString ChartView::dump()
+OUString ChartView::dump(OUString const & kind)
{
+ if (kind.isEmpty()) {
+ return dumpXmlToString([this](auto writer) { return dumpAsXml(writer); });
+ }
+
+ // kind == "shapes":
#if HAVE_FEATURE_DESKTOP
// Used for unit tests and in chartcontroller only, no need to drag in this when cross-compiling
// for non-desktop