Coverage Report

Created: 2026-04-09 11:41

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/chart2/source/inc/ObjectIdentifier.hxx
Line
Count
Source
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
#pragma once
20
21
#include <sal/config.h>
22
23
#include <string_view>
24
25
#include "TitleHelper.hxx"
26
27
#include <rtl/ustring.hxx>
28
#include <rtl/ref.hxx>
29
30
namespace chart { class ChartModel; }
31
namespace com::sun::star::awt { struct Point; }
32
namespace com::sun::star::beans { class XPropertySet; }
33
namespace com::sun::star::chart2 { class XAxis; }
34
namespace com::sun::star::drawing { class XShape; }
35
namespace com::sun::star::uno { class XInterface; }
36
37
namespace chart
38
{
39
class Axis;
40
class BaseCoordinateSystem;
41
class DataSeries;
42
class Diagram;
43
class Legend;
44
45
enum ObjectType
46
{
47
    OBJECTTYPE_PAGE,
48
    OBJECTTYPE_TITLE,
49
    OBJECTTYPE_LEGEND,
50
    OBJECTTYPE_LEGEND_ENTRY,
51
    OBJECTTYPE_DIAGRAM,
52
    OBJECTTYPE_DIAGRAM_WALL,
53
    OBJECTTYPE_DIAGRAM_FLOOR,
54
    OBJECTTYPE_AXIS,
55
    OBJECTTYPE_AXIS_UNITLABEL,
56
    OBJECTTYPE_GRID,
57
    OBJECTTYPE_SUBGRID,
58
    OBJECTTYPE_DATA_SERIES,
59
    OBJECTTYPE_DATA_POINT,
60
    OBJECTTYPE_DATA_LABELS,
61
    OBJECTTYPE_DATA_LABEL,
62
    OBJECTTYPE_DATA_ERRORS_X,
63
    OBJECTTYPE_DATA_ERRORS_Y,
64
    OBJECTTYPE_DATA_ERRORS_Z,
65
    OBJECTTYPE_DATA_CURVE,//e.g. a statistical method printed as line
66
    OBJECTTYPE_DATA_AVERAGE_LINE,
67
    OBJECTTYPE_DATA_CURVE_EQUATION,
68
    OBJECTTYPE_DATA_STOCK_RANGE,
69
    OBJECTTYPE_DATA_STOCK_LOSS,
70
    OBJECTTYPE_DATA_STOCK_GAIN,
71
    OBJECTTYPE_DATA_TABLE,
72
    OBJECTTYPE_SHAPE,
73
    OBJECTTYPE_UNKNOWN
74
};
75
76
class ObjectIdentifier
77
{
78
    //CID == ClassifiedIdentifier <--> name of shape
79
    //semicolon, colon, equal sign and slash have special meanings in a CID
80
    //and are therefore not allowed in its components
81
82
    //syntax of a CID:  CID:/classification/ObjectID
83
84
    //where classification: nothing or "MultiClick" or "DragMethod=DragMethodServiceName" and "DragParameter=DragParameterString"
85
    //                      or a combination of these separated with a colon
86
    //where DragMethodServiceName can be a selfdefined servicename for special actions //todo define standard service for this purpose
87
    //where DragParameterString is any string you like to transport information to your special drag service
88
    //                            only semicolon, colon, equal sign and slash are not allowed characters
89
    //                            also the keywords used in the ObjectIdentifiers are not allowed
90
91
    //where ObjectID: Parent-Particle:Particle //e.g. Series=2:Point=22
92
    //where Particle: Type=ParticleID //e.g. Point=22
93
    //where Type: getStringForType( ObjectType eType ) or other string
94
95
public:
96
    ObjectIdentifier();
97
    ObjectIdentifier( OUString aObjectCID );
98
    ObjectIdentifier( const css::uno::Reference< css::drawing::XShape >& rxShape );
99
    ObjectIdentifier( const css::uno::Any& rAny );
100
101
    bool operator==( const ObjectIdentifier& rOID ) const;
102
    bool operator<( const ObjectIdentifier& rOID ) const;
103
104
    static OUString createClassifiedIdentifierForObject(
105
          const css::uno::Reference< css::uno::XInterface >& xObject
106
        , const rtl::Reference<::chart::ChartModel>& xChartModel );
107
    static OUString createClassifiedIdentifierForObject(
108
          const rtl::Reference< ::chart::Title >& xObject
109
        , const rtl::Reference<::chart::ChartModel>& xChartModel );
110
    static OUString createClassifiedIdentifierForObject(
111
          const rtl::Reference< ::chart::Legend >& xObject
112
        , const rtl::Reference<::chart::ChartModel>& xChartModel );
113
    static OUString createClassifiedIdentifierForObject(
114
          const rtl::Reference< ::chart::Axis >& xObject
115
        , const rtl::Reference<::chart::ChartModel>& xChartModel );
116
117
    static OUString createClassifiedIdentifierForParticle(
118
        std::u16string_view rParticle );
119
120
    static OUString createClassifiedIdentifierForParticles(
121
            std::u16string_view rParentParticle
122
          , std::u16string_view rChildParticle
123
          , std::u16string_view rDragMethodServiceName = std::u16string_view()
124
          , std::u16string_view rDragParameterString = std::u16string_view() );
125
126
    static OUString createClassifiedIdentifierForGrid(
127
          const css::uno::Reference< css::chart2::XAxis >& xAxis
128
        , const rtl::Reference<::chart::ChartModel>& xChartModel
129
        , sal_Int32 nSubIndex = -1 );//-1: main grid, 0: first subgrid etc
130
131
    static OUString createParticleForDiagram();
132
133
    static OUString createParticleForCoordinateSystem(
134
          const rtl::Reference< ::chart::BaseCoordinateSystem >& xCooSys
135
        , const rtl::Reference<::chart::ChartModel>& xChartModel );
136
137
    static OUString createParticleForAxis(
138
                      sal_Int32 nDimensionIndex, sal_Int32 nAxisIndex );
139
140
    static OUString createParticleForGrid(
141
                      sal_Int32 nDimensionIndex, sal_Int32 nAxisIndex );
142
143
    static OUString createParticleForSeries( sal_Int32 nDiagramIndex, sal_Int32 nCooSysIndex
144
            , sal_Int32 nChartTypeIndex, sal_Int32 nSeriesIndex );
145
146
    static OUString createParticleForLegend(
147
        const rtl::Reference<::chart::ChartModel>& xChartModel );
148
149
    /** Creates an identifier for the data table */
150
    static OUString createParticleForDataTable(
151
        const rtl::Reference<::chart::ChartModel>& xChartModel );
152
153
    static OUString addChildParticle( std::u16string_view rParticle, std::u16string_view rChildParticle );
154
    static OUString createChildParticleWithIndex( ObjectType eObjectType, sal_Int32 nIndex );
155
    static sal_Int32 getIndexFromParticleOrCID( std::u16string_view rParticleOrCID );
156
157
    static OUString createClassifiedIdentifier(
158
        enum ObjectType eObjectType //e.g. OBJECTTYPE_DATA_SERIES
159
        , std::u16string_view rParticleID );//e.g. SeriesID
160
161
    static OUString createClassifiedIdentifierWithParent(
162
        enum ObjectType //e.g. OBJECTTYPE_DATA_POINT or OBJECTTYPE_GRID
163
        , std::u16string_view rParticleID //for points or subgrids this is an Index or otherwise an identifier from the model object
164
        , std::u16string_view rParentPartical //e.g. "Series=SeriesID" or "Grid=GridId"
165
        , std::u16string_view rDragMethodServiceName = std::u16string_view()
166
        , std::u16string_view rDragParameterString = std::u16string_view()
167
        );
168
169
    static bool isCID( std::u16string_view rName );
170
    static std::u16string_view getDragMethodServiceName( std::u16string_view rClassifiedIdentifier );
171
    static std::u16string_view getDragParameterString( std::u16string_view rCID );
172
    static bool isDragableObject( std::u16string_view rClassifiedIdentifier );
173
    bool isDragableObject() const;
174
    static bool isRotateableObject( std::u16string_view rClassifiedIdentifier );
175
    static bool isMultiClickObject( std::u16string_view rClassifiedIdentifier );
176
    static bool areSiblings( std::u16string_view rCID1, std::u16string_view rCID2 );//identical object is no sibling
177
    static bool areIdenticalObjects( std::u16string_view rCID1, std::u16string_view rCID2 );
178
179
    static OUString getStringForType( ObjectType eObjectType );
180
    static ObjectType getObjectType( std::u16string_view rCID );
181
    ObjectType getObjectType() const;
182
183
    static OUString createSeriesSubObjectStub( ObjectType eSubObjectType
184
                    , std::u16string_view rSeriesParticle
185
                    , std::u16string_view rDragMethodServiceName = std::u16string_view()
186
                    , std::u16string_view rDragParameterString = std::u16string_view() );
187
    static OUString createPointCID( std::u16string_view rPointCID_Stub, sal_Int32 nIndex  );
188
189
    static OUString createDataCurveCID( std::u16string_view rSeriesParticle, sal_Int32 nCurveIndex, bool bAverageLine );
190
    static OUString createDataCurveEquationCID( std::u16string_view rSeriesParticle, sal_Int32 nCurveIndex );
191
192
    static OUString getObjectID( std::u16string_view rCID );
193
    static std::u16string_view getParticleID( std::u16string_view rCID );
194
    static std::u16string_view getFullParentParticle( std::u16string_view rCID );
195
196
    //returns the series particle of a CID when the CID is a child of the series
197
    static OUString getSeriesParticleFromCID( std::u16string_view rCID );
198
199
    //return the model object that is indicated by rObjectCID
200
    static css::uno::Reference< css::beans::XPropertySet >
201
            getObjectPropertySet(
202
                  std::u16string_view rObjectCID
203
                , const rtl::Reference< ::chart::ChartModel >& xChartDocument );
204
205
    //return the axis object that belongs to rObjectCID if any
206
    static rtl::Reference< ::chart::Axis >
207
            getAxisForCID(
208
                  std::u16string_view rObjectCID
209
                , const rtl::Reference<::chart::ChartModel>& xChartModel );
210
211
    //return the series object that belongs to rObjectCID if any
212
    static rtl::Reference< ::chart::DataSeries >
213
            getDataSeriesForCID(
214
                  std::u16string_view rObjectCID
215
                , const rtl::Reference<::chart::ChartModel>& xChartModel );
216
217
    static rtl::Reference< ::chart::Diagram >
218
            getDiagramForCID(
219
                  std::u16string_view rObjectCID
220
                , const rtl::Reference<::chart::ChartModel>& xChartModel );
221
222
    static const OUString& getPieSegmentDragMethodServiceName();
223
    static OUString createPieSegmentDragParameterString(
224
          sal_Int32 nOffsetPercent
225
        , const css::awt::Point& rMinimumPosition
226
        , const css::awt::Point& rMaximumPosition );
227
    static bool parsePieSegmentDragParameterString( std::u16string_view rDragParameterString
228
        , sal_Int32& rOffsetPercent
229
        , css::awt::Point& rMinimumPosition
230
        , css::awt::Point& rMaximumPosition );
231
232
    static TitleHelper::eTitleType getTitleTypeForCID( std::u16string_view rCID );
233
234
    static OUString getMovedSeriesCID( std::u16string_view rObjectCID, bool bForward );
235
236
    bool isValid() const;
237
    bool isAutoGeneratedObject() const;
238
    bool isAdditionalShape() const;
239
0
    const OUString& getObjectCID() const { return m_aObjectCID;}
240
0
    const css::uno::Reference< css::drawing::XShape >& getAdditionalShape() const { return m_xAdditionalShape;}
241
    css::uno::Any getAny() const;
242
243
private:
244
    // #i12587# support for shapes in chart
245
    // For autogenerated chart objects a CID is specified in m_aObjectCID,
246
    // for all other objects m_xAdditionalShape is set.
247
    // Note, that if m_aObjectCID is set, m_xAdditionalShape must be empty
248
    // and vice versa.
249
    OUString m_aObjectCID;
250
    css::uno::Reference< css::drawing::XShape > m_xAdditionalShape;
251
};
252
253
} //namespace chart
254
255
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */