Avoid potential negative array index access to cached text.
[LibreOffice.git] / chart2 / source / controller / dialogs / DialogModel.hxx
blob325cffe0677324df87563cc6197f7955f105cffd
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #pragma once
21 #include <TimerTriggeredControllerLock.hxx>
22 #include <rtl/ustring.hxx>
23 #include <rtl/ref.hxx>
25 #include <map>
26 #include <memory>
27 #include <vector>
29 namespace chart { class ChartModel; }
30 namespace com::sun::star::beans { struct PropertyValue; }
31 namespace com::sun::star::chart2 { class XChartDocument; }
32 namespace com::sun::star::frame { class XModel; }
33 namespace com::sun::star::uno { class XComponentContext; }
34 namespace com::sun::star::uno { template <class E> class Sequence; }
36 namespace com::sun::star::chart2 {
37 class XDataSeriesContainer;
38 class XDataSeries;
39 class XChartType;
40 namespace data {
41 class XDataProvider;
42 class XLabeledDataSequence;
46 namespace chart
48 class ChartType;
49 class ChartTypeTemplate;
50 class DataSeries;
51 struct InterpretedData;
52 class LabeledDataSequence;
53 class RangeSelectionHelper;
55 struct DialogModelTimeBasedInfo
57 DialogModelTimeBasedInfo();
59 bool bTimeBased;
60 sal_Int32 nStart;
61 sal_Int32 nEnd;
64 class DialogModel
66 public:
67 explicit DialogModel( rtl::Reference<::chart::ChartModel> xChartDocument );
68 ~DialogModel();
70 typedef std::pair<
71 OUString,
72 std::pair< rtl::Reference< ::chart::DataSeries >,
73 rtl::Reference< ::chart::ChartType > > >
74 tSeriesWithChartTypeByName;
76 typedef std::map< OUString, OUString >
77 tRolesWithRanges;
79 void setTemplate(
80 const rtl::Reference< ::chart::ChartTypeTemplate > & xTemplate );
82 std::shared_ptr< RangeSelectionHelper > const &
83 getRangeSelectionHelper() const;
85 const rtl::Reference<::chart::ChartModel> &
86 getChartModel() const;
88 css::uno::Reference< css::chart2::data::XDataProvider >
89 getDataProvider() const;
91 std::vector< rtl::Reference< ::chart::ChartType > >
92 getAllDataSeriesContainers() const;
94 std::vector< tSeriesWithChartTypeByName >
95 getAllDataSeriesWithLabel() const;
97 static tRolesWithRanges getRolesWithRanges(
98 const css::uno::Reference< css::chart2::XDataSeries > & xSeries,
99 const OUString & aRoleOfSequenceForLabel,
100 const rtl::Reference< ::chart::ChartType > & xChartType );
102 enum class MoveDirection
104 Down, Up
107 void moveSeries( const rtl::Reference< DataSeries > & xSeries,
108 MoveDirection eDirection );
110 /// @return the newly inserted series
111 rtl::Reference<
112 ::chart::DataSeries > insertSeriesAfter(
113 const css::uno::Reference< css::chart2::XDataSeries > & xSeries,
114 const rtl::Reference< ::chart::ChartType > & xChartType,
115 bool bCreateDataCachedSequences = false );
117 void deleteSeries(
118 const rtl::Reference< ::chart::DataSeries > & xSeries,
119 const rtl::Reference< ::chart::ChartType > & xChartType );
121 css::uno::Reference< css::chart2::data::XLabeledDataSequence >
122 getCategories() const;
124 void setCategories( const css::uno::Reference< css::chart2::data::XLabeledDataSequence > & xCategories );
126 OUString getCategoriesRange() const;
128 bool isCategoryDiagram() const;
130 void detectArguments(
131 OUString & rOutRangeString,
132 bool & rOutUseColumns, bool & rOutFirstCellAsLabel, bool & rOutHasCategories ) const;
134 bool allArgumentsForRectRangeDetected() const;
136 void setData( const css::uno::Sequence< css::beans::PropertyValue > & rArguments );
138 void setTimeBasedRange( bool bTimeBased, sal_Int32 nStart, sal_Int32 nEnd) const;
140 const DialogModelTimeBasedInfo& getTimeBasedInfo() const { return maTimeBasedInfo; }
142 void startControllerLockTimer();
144 static OUString ConvertRoleFromInternalToUI( const OUString & rRoleString );
145 static OUString GetRoleDataLabel();
147 // pass a role string (not translated) and get an index that serves for
148 // relative ordering, to get e.g. x-values and y-values in the right order
149 static sal_Int32 GetRoleIndexForSorting( const OUString & rInternalRoleString );
151 ChartModel& getModel() const;
153 private:
154 rtl::Reference<::chart::ChartModel>
155 m_xChartDocument;
157 rtl::Reference< ::chart::ChartTypeTemplate > m_xTemplate;
159 mutable std::shared_ptr< RangeSelectionHelper >
160 m_spRangeSelectionHelper;
162 TimerTriggeredControllerLock m_aTimerTriggeredControllerLock;
164 private:
165 void applyInterpretedData(
166 const InterpretedData & rNewData,
167 const std::vector< rtl::Reference< ::chart::DataSeries > > & rSeriesToReUse );
169 sal_Int32 countSeries() const;
171 mutable DialogModelTimeBasedInfo maTimeBasedInfo;
174 } // namespace chart
176 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */