LibreOffice Module chart2 (master) 1
ChartModelHelper.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#include <ChartModelHelper.hxx>
21#include <DiagramHelper.hxx>
22#include <Diagram.hxx>
23#include <DataSource.hxx>
24#include <DataSourceHelper.hxx>
26#include <RangeHighlighter.hxx>
28#include <ChartModel.hxx>
30#include <ChartType.hxx>
31#include <DataSeries.hxx>
32
33#include <com/sun/star/chart/ChartDataRowSource.hpp>
34#include <com/sun/star/chart/XChartDocument.hpp>
35#include <com/sun/star/embed/Aspects.hpp>
36#include <com/sun/star/view/XSelectionChangeListener.hpp>
38
39namespace chart
40{
41using namespace ::com::sun::star;
42using namespace ::com::sun::star::chart2;
43
45 const rtl::Reference<::chart::ChartModel>& xChartDoc, bool bConnectToModel )
46{
47 bool bDefaultDataInColumns(true);
48
49 // #i120559# Try to access the current state of "DataRowSource" for the
50 // chart data and use it as default for creating a new InternalDataProvider
51 if(xChartDoc.is())
52 {
53 // old XChartDocument interface
54 css::uno::Reference< css::chart::XChartDocument > xDoc(static_cast<cppu::OWeakObject*>(xChartDoc.get()), uno::UNO_QUERY);
55
56 if(xDoc.is())
57 {
58 css::uno::Reference< css::chart::XDiagram > aDiagram = xDoc->getDiagram();
59
60 if(aDiagram.is())
61 {
62 css::uno::Reference< css::beans::XPropertySet > xProp(aDiagram, uno::UNO_QUERY);
63
64 if(xProp.is())
65 {
66 css::chart::ChartDataRowSource aDataRowSource(css::chart::ChartDataRowSource_COLUMNS);
67
68 xProp->getPropertyValue( "DataRowSource" ) >>= aDataRowSource;
69
70 bDefaultDataInColumns = (aDataRowSource == css::chart::ChartDataRowSource_COLUMNS);
71 }
72 }
73 }
74 }
75
76 return new InternalDataProvider( xChartDoc, bConnectToModel, bDefaultDataInColumns );
77}
78
80{
81 rtl::Reference< Diagram > xDiagram = xModel->getFirstChartDiagram();
82 if( xDiagram.is() )
83 {
84 auto aCooSysSeq( xDiagram->getBaseCoordinateSystems() );
85 if( !aCooSysSeq.empty() )
86 return aCooSysSeq[0];
87 }
88 return nullptr;
89}
90
91std::vector< rtl::Reference< DataSeries > > ChartModelHelper::getDataSeries(
92 const rtl::Reference<::chart::ChartModel> & xChartDoc )
93{
94 std::vector< rtl::Reference< DataSeries > > aResult;
95
96 rtl::Reference< Diagram > xDiagram = xChartDoc->getFirstChartDiagram();
97 if( xDiagram.is())
98 aResult = xDiagram->getDataSeries();
99
100 return aResult;
101}
102
105 , const rtl::Reference< DataSeries >& xGivenDataSeries )
106{
107 rtl::Reference<Diagram> xDiagram = xModel->getFirstChartDiagram();
108 return xDiagram ? xDiagram->getChartTypeOfSeries( xGivenDataSeries ) : nullptr;
109}
110
112{
113 return awt::Size( 16000, 9000 );
114}
115
117{
118 awt::Size aPageSize( ChartModelHelper::getDefaultPageSize() );
119 OSL_ENSURE(xModel.is(),"need xVisualObject for page size");
120 if( xModel.is() )
121 aPageSize = xModel->getVisualAreaSize( embed::Aspects::MSOLE_CONTENT );
122 return aPageSize;
123}
124
126{
127 if( xModel.is() )
128 {
129 uno::Reference< view::XSelectionChangeListener > xSelectionChangeListener( xModel->getRangeHighlighter(), uno::UNO_QUERY );
130 //trigger selection of cell range
131 if( xSelectionChangeListener.is() )
132 {
133 lang::EventObject aEvent( xSelectionChangeListener );
134 xSelectionChangeListener->selectionChanged( aEvent );
135 }
136 }
137}
138
140{
141 bool bIncluded = true; // hidden cells are included by default.
142
143 rtl::Reference< Diagram > xDiagram( xChartModel->getFirstChartDiagram() );
144 if (!xDiagram.is())
145 return bIncluded;
146
147 try
148 {
149 xDiagram->getPropertyValue("IncludeHiddenCells") >>= bIncluded;
150 }
151 catch( const beans::UnknownPropertyException& )
152 {
153 }
154
155 return bIncluded;
156}
157
158bool ChartModelHelper::setIncludeHiddenCells( bool bIncludeHiddenCells, ChartModel& rModel )
159{
160 bool bChanged = false;
161 try
162 {
163 ControllerLockGuard aLockedControllers( rModel );
164
165 uno::Reference< beans::XPropertySet > xDiagramProperties( rModel.getFirstDiagram(), uno::UNO_QUERY );
166 if (xDiagramProperties.is())
167 {
168 bool bOldValue = bIncludeHiddenCells;
169 xDiagramProperties->getPropertyValue( "IncludeHiddenCells" ) >>= bOldValue;
170 if( bOldValue == bIncludeHiddenCells )
171 bChanged = true;
172
173 //set the property on all instances in all cases to get the different objects in sync!
174
175 uno::Any aNewValue(bIncludeHiddenCells);
176
177 try
178 {
179 uno::Reference< beans::XPropertySet > xDataProviderProperties( rModel.getDataProvider(), uno::UNO_QUERY );
180 if( xDataProviderProperties.is() )
181 xDataProviderProperties->setPropertyValue("IncludeHiddenCells", aNewValue );
182 }
183 catch( const beans::UnknownPropertyException& )
184 {
185 //the property is optional!
186 }
187
188 try
189 {
191 if( xUsedData.is() )
192 {
196 {
197 xProp.set( uno::Reference< beans::XPropertySet >( labeledData->getValues(), uno::UNO_QUERY ) );
198 if(xProp.is())
199 xProp->setPropertyValue("IncludeHiddenCells", aNewValue );
200 xProp.set( uno::Reference< beans::XPropertySet >( labeledData->getLabel(), uno::UNO_QUERY ) );
201 if(xProp.is())
202 xProp->setPropertyValue("IncludeHiddenCells", aNewValue );
203 }
204 }
205 }
206 catch( const beans::UnknownPropertyException& )
207 {
208 //the property is optional!
209 }
210
211 xDiagramProperties->setPropertyValue( "IncludeHiddenCells", aNewValue);
212 }
213 }
214 catch (const uno::Exception&)
215 {
216 TOOLS_WARN_EXCEPTION("chart2", "" );
217 }
218 return bChanged;
219}
220
221} //namespace chart
222
223/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
AnyEventRef aEvent
static bool isIncludeHiddenCells(const rtl::Reference<::chart::ChartModel > &xChartModel)
static rtl::Reference< InternalDataProvider > createInternalDataProvider(const rtl::Reference<::chart::ChartModel > &xChartDoc, bool bConnectToModel)
static bool setIncludeHiddenCells(bool bIncludeHiddenCells, ChartModel &rModel)
static css::awt::Size getPageSize(const rtl::Reference<::chart::ChartModel > &xModel)
static void triggerRangeHighlighting(const rtl::Reference<::chart::ChartModel > &xModel)
static rtl::Reference< ChartType > getChartTypeOfSeries(const rtl::Reference<::chart::ChartModel > &xModel, const rtl::Reference< ::chart::DataSeries > &xGivenDataSeries)
static std::vector< rtl::Reference< ::chart::DataSeries > > getDataSeries(const rtl::Reference< ::chart::ChartModel > &xModel)
static css::awt::Size getDefaultPageSize()
static rtl::Reference< ::chart::BaseCoordinateSystem > getFirstCoordinateSystem(const rtl::Reference<::chart::ChartModel > &xModel)
static rtl::Reference< ::chart::DataSource > getUsedData(ChartModel &rModel)
Data provider that handles data internally.
#define TOOLS_WARN_EXCEPTION(area, stream)
constexpr OUStringLiteral aData
Reference< XModel > xModel