35#include <com/sun/star/chart/XChartDocument.hpp>
36#include <com/sun/star/container/XChild.hpp>
37#include <com/sun/star/lang/XMultiServiceFactory.hpp>
38#include <com/sun/star/uno/XComponentContext.hpp>
39#include <com/sun/star/chart2/data/XDataReceiver.hpp>
40#include <com/sun/star/chart2/XChartDocument.hpp>
41#include <com/sun/star/chart2/XCoordinateSystemContainer.hpp>
42#include <com/sun/star/chart2/XChartTypeContainer.hpp>
43#include <com/sun/star/chart2/XDataSeriesContainer.hpp>
45#include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
52using ::com::sun::star::uno::Reference;
53using ::com::sun::star::uno::Sequence;
57class lcl_MatchesChartType
60 explicit lcl_MatchesChartType( OUString aChartTypeName ) :
61 m_aChartTypeName(
std::move( aChartTypeName ))
64 bool operator () (
const Reference< chart2::XChartType > & xChartType )
const
66 return (xChartType.is() &&
67 xChartType->getChartType() == m_aChartTypeName );
71 OUString m_aChartTypeName;
83 mpAutoStyles( nullptr )
89 const Reference< frame::XModel >& rChartModel )
93 Reference< chart::XChartDocument > xDoc( rChartModel, uno::UNO_QUERY );
101 SAL_WARN(
"xmloff.chart",
"No valid XChartDocument given as XModel" );
118 pPropStyle->FillPropertySet(rProp);
127 const Reference< chart2::XDataSeries > & xSeries,
128 const Reference< chart2::XChartDocument > & xDoc )
134 Reference< chart2::XCoordinateSystemContainer > xCooSysCnt(
135 xDoc->getFirstDiagram(), uno::UNO_QUERY_THROW );
136 const Sequence< Reference< chart2::XCoordinateSystem > > aCooSysSeq(
137 xCooSysCnt->getCoordinateSystems());
139 for(
const auto& rCooSys : aCooSysSeq )
141 Reference< chart2::XChartTypeContainer > xCTCnt( rCooSys, uno::UNO_QUERY_THROW );
142 const Sequence< Reference< chart2::XChartType > > aChartTypes( xCTCnt->getChartTypes());
144 for(
const auto& rChartType : aChartTypes )
146 Reference< chart2::XDataSeriesContainer > xSeriesCnt( rChartType, uno::UNO_QUERY_THROW );
147 const Sequence< Reference< chart2::XDataSeries > > aSeriesSeq( xSeriesCnt->getDataSeries());
149 if (std::find(aSeriesSeq.begin(), aSeriesSeq.end(), xSeries) != aSeriesSeq.end())
151 xSeriesCnt->removeDataSeries(xSeries);
157 catch(
const uno::Exception &)
165 const Reference< chart2::XChartDocument > & xDoc,
166 sal_Int32 nCoordinateSystemIndex,
167 const OUString & rChartTypeName,
168 bool bPushLastChartType )
170 Reference< chart2::XDataSeries > xResult;
176 Reference< chart2::XCoordinateSystemContainer > xCooSysCnt(
177 xDoc->getFirstDiagram(), uno::UNO_QUERY_THROW );
178 Sequence< Reference< chart2::XCoordinateSystem > > aCooSysSeq(
179 xCooSysCnt->getCoordinateSystems());
180 Reference< uno::XComponentContext > xContext(
183 if( nCoordinateSystemIndex < aCooSysSeq.getLength())
185 Reference< chart2::XChartType > xCurrentType;
187 Reference< chart2::XChartTypeContainer > xCTCnt( aCooSysSeq[ nCoordinateSystemIndex ], uno::UNO_QUERY_THROW );
188 Sequence< Reference< chart2::XChartType > > aChartTypes( xCTCnt->getChartTypes());
190 const Reference< chart2::XChartType > * pBegin = aChartTypes.getConstArray();
191 const Reference< chart2::XChartType > * pEnd = pBegin + aChartTypes.getLength();
192 const Reference< chart2::XChartType > * pIt =
193 ::std::find_if( pBegin, pEnd, lcl_MatchesChartType( rChartTypeName ));
195 xCurrentType.set( *pIt );
198 if( !xCurrentType.is())
201 xContext->getServiceManager()->createInstanceWithContext( rChartTypeName, xContext ),
203 if( xCurrentType.is())
205 if( bPushLastChartType && aChartTypes.hasElements())
207 sal_Int32
nIndex( aChartTypes.getLength() - 1 );
208 aChartTypes.realloc( aChartTypes.getLength() + 1 );
209 auto pChartTypes = aChartTypes.getArray();
211 pChartTypes[
nIndex ] = xCurrentType;
212 xCTCnt->setChartTypes( aChartTypes );
215 xCTCnt->addChartType( xCurrentType );
220 if( xCurrentType.is())
222 Reference< chart2::XDataSeriesContainer > xSeriesCnt( xCurrentType, uno::UNO_QUERY_THROW );
227 xContext->getServiceManager()->createInstanceWithContext(
228 "com.sun.star.chart2.DataSeries",
229 xContext ), uno::UNO_QUERY_THROW );
232 xSeriesCnt->addDataSeries( xResult );
236 catch(
const uno::Exception & )
244 const Reference< uno::XComponentContext >& xContext,
255 uno::Reference< chart2::XChartDocument > xChartDoc( GetModel(), uno::UNO_QUERY );
256 if( xChartDoc.is() && xChartDoc->hasControllersLocked() )
257 xChartDoc->unlockControllers();
263 const uno::Reference< xml::sax::XFastAttributeList >& )
272 uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
273 GetModel(), uno::UNO_QUERY);
280 xDPS->getDocumentProperties());
301 SetAutoStyles( pStylesCtxt );
309 uno::Reference<chart2::XChartDocument> xOldDoc(GetModel(), uno::UNO_QUERY);
310 if (xOldDoc.is() && xOldDoc->hasControllersLocked())
311 xOldDoc->unlockControllers();
313 SvXMLImport::setTargetDocument(xDoc);
315 uno::Reference<chart2::XChartDocument> xChartDoc(GetModel(), uno::UNO_QUERY);
323 xChartDoc->lockControllers();
325 uno::Reference<container::XChild> xChild(xChartDoc, uno::UNO_QUERY);
326 uno::Reference<chart2::data::XDataReceiver> xDataReceiver(xChartDoc, uno::UNO_QUERY);
327 if (xChild.is() && xDataReceiver.is())
329 Reference<lang::XMultiServiceFactory> xFact(xChild->getParent(), uno::UNO_QUERY);
333 Reference<util::XNumberFormatsSupplier> xNumberFormatsSupplier(xFact, uno::UNO_QUERY);
334 xDataReceiver->attachNumberFormatsSupplier(xNumberFormatsSupplier);
338 catch (
const uno::Exception &)
346extern "C" SAL_DLLPUBLIC_EXPORT uno::XInterface*
348 uno::Sequence<uno::Any>
const& )
355extern "C" SAL_DLLPUBLIC_EXPORT uno::XInterface*
357 uno::XComponentContext* pCtx, uno::Sequence<uno::Any>
const& )
362extern "C" SAL_DLLPUBLIC_EXPORT uno::XInterface*
364 uno::XComponentContext* pCtx, uno::Sequence<uno::Any>
const& )
369extern "C" SAL_DLLPUBLIC_EXPORT uno::XInterface*
371 uno::XComponentContext* pCtx, uno::Sequence<uno::Any>
const& )
373 return cppu::acquire(
new SchXMLImport(pCtx,
"SchXMLImport.Content",
SAL_DLLPUBLIC_EXPORT uno::XInterface * com_sun_star_comp_Chart_XMLOasisContentImporter_get_implementation(uno::XComponentContext *pCtx, uno::Sequence< uno::Any > const &)
SAL_DLLPUBLIC_EXPORT uno::XInterface * com_sun_star_comp_Chart_XMLOasisMetaImporter_get_implementation(uno::XComponentContext *pCtx, uno::Sequence< uno::Any > const &)
SAL_DLLPUBLIC_EXPORT uno::XInterface * com_sun_star_comp_Chart_XMLOasisImporter_get_implementation(uno::XComponentContext *pCtx, uno::Sequence< uno::Any > const &)
SAL_DLLPUBLIC_EXPORT uno::XInterface * com_sun_star_comp_Chart_XMLOasisStylesImporter_get_implementation(uno::XComponentContext *pCtx, uno::Sequence< uno::Any > const &)
With this class you can import a <chart:chart> element containing its data as <table:table> element o...
static void DeleteDataSeries(const css::uno::Reference< css::chart2::XDataSeries > &xSeries, const css::uno::Reference< css::chart2::XChartDocument > &xDoc)
css::uno::Reference< css::chart::XChartDocument > mxChartDoc
SvXMLStylesContext * GetAutoStylesContext() const
SvXMLImportContext * CreateChartContext(SvXMLImport &rImport, const css::uno::Reference< css::frame::XModel > &rChartModel)
get the context for reading the <chart:chart> element with subelements.
void FillAutoStyle(const OUString &rAutoStyleName, const css::uno::Reference< css::beans::XPropertySet > &rProp)
Fill in the autostyle.
static css::uno::Reference< css::chart2::XDataSeries > GetNewDataSeries(const css::uno::Reference< css::chart2::XChartDocument > &xDoc, sal_Int32 nCoordinateSystemIndex, const OUString &rChartTypeName, bool bPushLastChartType)
static XmlStyleFamily GetChartFamilyID()
virtual ~SchXMLImport() noexcept override
virtual void SAL_CALL setTargetDocument(const css::uno::Reference< css::lang::XComponent > &xDoc) override
rtl::Reference< SchXMLImportHelper > maImportHelper
virtual SvXMLImportContext * CreateFastContext(sal_Int32 nElement, const ::css::uno::Reference<::css::xml::sax::XFastAttributeList > &xAttrList) override
SvXMLImportContext * CreateStylesContext()
SchXMLImport(const css::uno::Reference< css::uno::XComponentContext > &xContext, OUString const &implementationName, SvXMLImportFlags nImportFlags)
This class deliberately does not support XWeak, to improve performance when loading large documents.
handles the top-level office:document-meta element of meta.xml documents
const SvXMLStyleContext * FindStyleChildContext(XmlStyleFamily nFamily, const OUString &rName, bool bCreateIndex=false) const
#define TOOLS_INFO_EXCEPTION(area, stream)
#define DBG_UNHANDLED_EXCEPTION(...)
#define SAL_WARN(area, stream)
Reference< XComponentContext > getProcessComponentContext()
constexpr OUStringLiteral implementationName
Handling of tokens in XML:
const OUString & GetXMLToken(enum XMLTokenEnum eToken)
return the OUString representation for eToken
#define XML_ELEMENT(prefix, name)
constexpr sal_uInt16 XML_NAMESPACE_XLINK
constexpr sal_uInt16 XML_NAMESPACE_CHART_EXT