Coverage Report

Created: 2026-03-31 11:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/chart2/source/controller/sidebar/ChartElementsPanel.cxx
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
20
#include <com/sun/star/chart2/LegendPosition.hpp>
21
#include <com/sun/star/chart/ChartLegendExpansion.hpp>
22
23
#include <vcl/svapp.hxx>
24
#include <vcl/weld/Builder.hxx>
25
26
#include "ChartElementsPanel.hxx"
27
#include <ChartController.hxx>
28
#include <comphelper/processfactory.hxx>
29
30
#include <Legend.hxx>
31
#include <LegendHelper.hxx>
32
#include <AxisHelper.hxx>
33
#include <Diagram.hxx>
34
#include <ChartType.hxx>
35
#include <ChartModel.hxx>
36
#include <BaseCoordinateSystem.hxx>
37
38
39
using namespace css;
40
using namespace css::uno;
41
42
namespace chart::sidebar {
43
44
namespace {
45
46
enum class GridType
47
{
48
    VERT_MAJOR,
49
    VERT_MINOR,
50
    HOR_MAJOR,
51
    HOR_MINOR
52
};
53
54
enum class AxisType
55
{
56
    X_MAIN,
57
    Y_MAIN,
58
    Z_MAIN,
59
    X_SECOND,
60
    Y_SECOND
61
};
62
63
ChartModel* getChartModel(const css::uno::Reference<css::frame::XModel>& xModel)
64
0
{
65
0
    ChartModel* pModel = dynamic_cast<ChartModel*>(xModel.get());
66
67
0
    return pModel;
68
0
}
69
70
bool isLegendVisible(const css::uno::Reference<css::frame::XModel>& xModel)
71
0
{
72
0
    ChartModel* pModel = getChartModel(xModel);
73
0
    if (!pModel)
74
0
        return false;
75
76
0
    rtl::Reference< Legend > xLegendProp = LegendHelper::getLegend(*pModel);
77
0
    if( xLegendProp.is())
78
0
    {
79
0
        try
80
0
        {
81
0
            bool bShow = false;
82
0
            if( xLegendProp->getPropertyValue( u"Show"_ustr) >>= bShow )
83
0
            {
84
0
                return bShow;
85
0
            }
86
0
        }
87
0
        catch(const uno::Exception &)
88
0
        {
89
0
        }
90
0
    }
91
92
0
    return false;
93
0
}
94
95
void setLegendVisible(const css::uno::Reference<css::frame::XModel>& xModel, bool bVisible)
96
0
{
97
0
    ChartModel* pModel = getChartModel(xModel);
98
0
    if (!pModel)
99
0
        return;
100
101
0
    if (bVisible)
102
0
        LegendHelper::showLegend(*pModel, comphelper::getProcessComponentContext());
103
0
    else
104
0
        LegendHelper::hideLegend(*pModel);
105
0
}
106
107
bool isLegendOverlay(const css::uno::Reference<css::frame::XModel>& xModel)
108
0
{
109
0
    ChartModel* pModel = getChartModel(xModel);
110
0
    if (!pModel)
111
0
        return false;
112
113
0
    rtl::Reference< Legend > xLegendProp = LegendHelper::getLegend(*pModel);
114
0
    if( xLegendProp.is())
115
0
    {
116
0
        try
117
0
        {
118
0
            bool bOverlay = false;
119
0
            if(xLegendProp->getPropertyValue(u"Overlay"_ustr) >>= bOverlay)
120
0
            {
121
0
                return bOverlay;
122
0
            }
123
0
        }
124
0
        catch(const uno::Exception &)
125
0
        {
126
0
        }
127
0
    }
128
129
0
    return false;
130
0
}
131
132
void setLegendOverlay(const css::uno::Reference<css::frame::XModel>& xModel, bool bOverlay)
133
0
{
134
0
    ChartModel* pModel = getChartModel(xModel);
135
0
    if (!pModel)
136
0
        return;
137
138
0
    rtl::Reference<Legend> xLegendProp = LegendHelper::getLegend(*pModel);
139
0
    if (!xLegendProp.is())
140
0
        return;
141
142
0
    xLegendProp->setPropertyValue(u"Overlay"_ustr, css::uno::Any(bOverlay));
143
0
}
144
145
bool isTitleVisible(const rtl::Reference<::chart::ChartModel>& xModel, TitleHelper::eTitleType eTitle)
146
0
{
147
0
    rtl::Reference<Title> xTitle = TitleHelper::getTitle(eTitle, xModel);
148
0
    if (!xTitle.is())
149
0
        return false;
150
151
0
    css::uno::Any aAny = xTitle->getPropertyValue(u"Visible"_ustr);
152
0
    bool bVisible = aAny.get<bool>();
153
0
    return bVisible;
154
0
}
155
156
bool isGridVisible(const rtl::Reference<::chart::ChartModel>& xModel, GridType eType)
157
0
{
158
0
    rtl::Reference< Diagram > xDiagram(xModel->getFirstChartDiagram());
159
0
    if(xDiagram.is())
160
0
    {
161
0
        sal_Int32 nDimensionIndex = 0;
162
0
        if (eType == GridType::HOR_MAJOR || eType == GridType::HOR_MINOR)
163
0
            nDimensionIndex = 1;
164
165
0
        bool bMajor = (eType == GridType::HOR_MAJOR || eType == GridType::VERT_MAJOR);
166
167
0
        bool bHasGrid = AxisHelper::isGridShown(nDimensionIndex, 0, bMajor, xDiagram);
168
0
        return bHasGrid;
169
0
    }
170
0
    return false;
171
0
}
172
173
void setGridVisible(const rtl::Reference<::chart::ChartModel>& xModel, GridType eType, bool bVisible)
174
0
{
175
0
    rtl::Reference< Diagram > xDiagram(xModel->getFirstChartDiagram());
176
0
    if(!xDiagram.is())
177
0
        return;
178
179
0
    sal_Int32 nDimensionIndex = 0;
180
0
    if (eType == GridType::HOR_MAJOR || eType == GridType::HOR_MINOR)
181
0
        nDimensionIndex = 1;
182
0
    sal_Int32 nCooSysIndex = 0;
183
184
0
    bool bMajor = (eType == GridType::HOR_MAJOR || eType == GridType::VERT_MAJOR);
185
186
0
    if (bVisible)
187
0
        AxisHelper::showGrid(nDimensionIndex, nCooSysIndex, bMajor,
188
0
                xDiagram);
189
0
    else
190
0
        AxisHelper::hideGrid(nDimensionIndex, nCooSysIndex, bMajor, xDiagram);
191
0
}
192
193
bool isAxisVisible(const rtl::Reference<::chart::ChartModel>& xModel, AxisType eType)
194
0
{
195
0
    rtl::Reference< Diagram > xDiagram(xModel->getFirstChartDiagram());
196
0
    if(xDiagram.is())
197
0
    {
198
0
        sal_Int32 nDimensionIndex = 0;
199
0
        if (eType == AxisType::Y_MAIN || eType == AxisType::Y_SECOND)
200
0
            nDimensionIndex = 1;
201
0
        else if (eType == AxisType::Z_MAIN)
202
0
            nDimensionIndex = 2;
203
204
0
        bool bMajor = (eType != AxisType::X_SECOND && eType != AxisType::Y_SECOND);
205
206
0
        bool bHasAxis = AxisHelper::isAxisShown(nDimensionIndex, bMajor, xDiagram);
207
0
        return bHasAxis;
208
0
    }
209
0
    return false;
210
0
}
211
212
void setAxisVisible(const rtl::Reference<::chart::ChartModel>& xModel, AxisType eType, bool bVisible)
213
0
{
214
0
    rtl::Reference< Diagram > xDiagram(xModel->getFirstChartDiagram());
215
0
    if(!xDiagram.is())
216
0
        return;
217
218
0
    sal_Int32 nDimensionIndex = 0;
219
0
    if (eType == AxisType::Y_MAIN || eType == AxisType::Y_SECOND)
220
0
        nDimensionIndex = 1;
221
0
    else if (eType == AxisType::Z_MAIN)
222
0
        nDimensionIndex = 2;
223
224
0
    bool bMajor = (eType != AxisType::X_SECOND && eType != AxisType::Y_SECOND);
225
226
0
    if (bVisible)
227
0
        AxisHelper::showAxis(nDimensionIndex, bMajor, xDiagram, comphelper::getProcessComponentContext());
228
0
    else
229
0
        AxisHelper::hideAxis(nDimensionIndex, bMajor, xDiagram);
230
0
}
231
232
sal_Int32 getLegendPos(const css::uno::Reference<css::frame::XModel>& xModel)
233
0
{
234
0
    ChartModel* pModel = getChartModel(xModel);
235
0
    if (!pModel)
236
0
        return -1;
237
238
0
    rtl::Reference< Legend > xLegendProp = LegendHelper::getLegend(*pModel);
239
0
    if (!xLegendProp.is())
240
0
        return -1;
241
242
0
    chart2::LegendPosition eLegendPos = chart2::LegendPosition_LINE_END;
243
0
    xLegendProp->getPropertyValue(u"AnchorPosition"_ustr) >>= eLegendPos;
244
0
    switch(eLegendPos)
245
0
    {
246
0
        case chart2::LegendPosition_LINE_START:
247
0
            return 3;
248
0
        case chart2::LegendPosition_LINE_END:
249
0
            return 0;
250
0
        case chart2::LegendPosition_PAGE_START:
251
0
            return 1;
252
0
        case chart2::LegendPosition_PAGE_END:
253
0
            return 2;
254
0
        default:
255
0
            return -1;
256
0
    }
257
0
}
258
259
void setLegendPos(const css::uno::Reference<css::frame::XModel>& xModel, sal_Int32 nPos)
260
0
{
261
0
    ChartModel* pModel = getChartModel(xModel);
262
0
    if (!pModel)
263
0
        return;
264
265
0
    rtl::Reference< Legend > xLegendProp = LegendHelper::getLegend(*pModel);
266
0
    if (!xLegendProp.is())
267
0
        return;
268
269
0
    chart2::LegendPosition eLegendPos = chart2::LegendPosition_LINE_END;
270
0
    css::chart::ChartLegendExpansion eExpansion = css::chart::ChartLegendExpansion_HIGH;
271
0
    switch(nPos)
272
0
    {
273
0
        case 1:
274
0
            eLegendPos = chart2::LegendPosition_PAGE_START;
275
0
            eExpansion = css::chart::ChartLegendExpansion_WIDE;
276
0
            break;
277
0
        case 3:
278
0
            eLegendPos = chart2::LegendPosition_LINE_START;
279
0
            break;
280
0
        case 0:
281
0
            eLegendPos = chart2::LegendPosition_LINE_END;
282
0
            break;
283
0
        case 2:
284
0
            eLegendPos = chart2::LegendPosition_PAGE_END;
285
0
            eExpansion = css::chart::ChartLegendExpansion_WIDE;
286
0
            break;
287
0
        default:
288
0
            assert(false);
289
0
    }
290
291
0
    xLegendProp->setPropertyValue(u"AnchorPosition"_ustr, css::uno::Any(eLegendPos));
292
0
    xLegendProp->setPropertyValue(u"Expansion"_ustr, css::uno::Any(eExpansion));
293
0
    xLegendProp->setPropertyValue(u"RelativePosition"_ustr, uno::Any());
294
0
}
295
296
}
297
298
ChartElementsPanel::ChartElementsPanel(
299
    weld::Widget* pParent, ChartController* pController)
300
0
    : PanelLayout(pParent, u"ChartElementsPanel"_ustr, u"modules/schart/ui/sidebarelements.ui"_ustr)
301
0
    , mxCBTitle(m_xBuilder->weld_check_button(u"checkbutton_title"_ustr))
302
0
    , mxEditTitle(m_xBuilder->weld_entry(u"edit_title"_ustr))
303
0
    , mxCBSubtitle(m_xBuilder->weld_check_button(u"checkbutton_subtitle"_ustr))
304
0
    , mxEditSubtitle(m_xBuilder->weld_entry(u"edit_subtitle"_ustr))
305
0
    , mxCBXAxis(m_xBuilder->weld_check_button(u"checkbutton_x_axis"_ustr))
306
0
    , mxCBXAxisTitle(m_xBuilder->weld_check_button(u"checkbutton_x_axis_title"_ustr))
307
0
    , mxCBYAxis(m_xBuilder->weld_check_button(u"checkbutton_y_axis"_ustr))
308
0
    , mxCBYAxisTitle(m_xBuilder->weld_check_button(u"checkbutton_y_axis_title"_ustr))
309
0
    , mxCBZAxis(m_xBuilder->weld_check_button(u"checkbutton_z_axis"_ustr))
310
0
    , mxCBZAxisTitle(m_xBuilder->weld_check_button(u"checkbutton_z_axis_title"_ustr))
311
0
    , mxCB2ndXAxis(m_xBuilder->weld_check_button(u"checkbutton_2nd_x_axis"_ustr))
312
0
    , mxCB2ndXAxisTitle(m_xBuilder->weld_check_button(u"checkbutton_2nd_x_axis_title"_ustr))
313
0
    , mxCB2ndYAxis(m_xBuilder->weld_check_button(u"checkbutton_2nd_y_axis"_ustr))
314
0
    , mxCB2ndYAxisTitle(m_xBuilder->weld_check_button(u"checkbutton_2nd_y_axis_title"_ustr))
315
0
    , mxCBLegend(m_xBuilder->weld_check_button(u"checkbutton_legend"_ustr))
316
0
    , mxCBLegendNoOverlay(m_xBuilder->weld_check_button(u"checkbutton_no_overlay"_ustr))
317
0
    , mxCBGridVerticalMajor(m_xBuilder->weld_check_button(u"checkbutton_gridline_vertical_major"_ustr))
318
0
    , mxCBGridHorizontalMajor(m_xBuilder->weld_check_button(u"checkbutton_gridline_horizontal_major"_ustr))
319
0
    , mxCBGridVerticalMinor(m_xBuilder->weld_check_button(u"checkbutton_gridline_vertical_minor"_ustr))
320
0
    , mxCBGridHorizontalMinor(m_xBuilder->weld_check_button(u"checkbutton_gridline_horizontal_minor"_ustr))
321
0
    , mxTextTitle(m_xBuilder->weld_label(u"text_title"_ustr))
322
0
    , mxTextSubTitle(m_xBuilder->weld_label(u"text_subtitle"_ustr))
323
0
    , mxLBAxis(m_xBuilder->weld_label(u"label_axes"_ustr))
324
0
    , mxLBGrid(m_xBuilder->weld_label(u"label_gri"_ustr))
325
0
    , mxLBLegendPosition(m_xBuilder->weld_combo_box(u"comboboxtext_legend"_ustr))
326
0
    , mxBoxLegend(m_xBuilder->weld_widget(u"box_legend"_ustr))
327
0
    , mxModel(pController->getChartModel())
328
0
    , mxListener(new ChartSidebarModifyListener(this))
329
0
    , mbModelValid(true)
330
0
{
331
0
    maTextTitle = mxTextTitle->get_label();
332
0
    maTextSubTitle = mxTextSubTitle->get_label();
333
334
0
    Initialize();
335
0
}
336
337
ChartElementsPanel::~ChartElementsPanel()
338
0
{
339
0
    doUpdateModel(nullptr);
340
341
0
    mxCBTitle.reset();
342
0
    mxEditTitle.reset();
343
0
    mxCBSubtitle.reset();
344
0
    mxEditSubtitle.reset();
345
0
    mxCBXAxis.reset();
346
0
    mxCBXAxisTitle.reset();
347
0
    mxCBYAxis.reset();
348
0
    mxCBYAxisTitle.reset();
349
0
    mxCBZAxis.reset();
350
0
    mxCBZAxisTitle.reset();
351
0
    mxCB2ndXAxis.reset();
352
0
    mxCB2ndXAxisTitle.reset();
353
0
    mxCB2ndYAxis.reset();
354
0
    mxCB2ndYAxisTitle.reset();
355
0
    mxCBLegend.reset();
356
0
    mxCBLegendNoOverlay.reset();
357
0
    mxCBGridVerticalMajor.reset();
358
0
    mxCBGridHorizontalMajor.reset();
359
0
    mxCBGridVerticalMinor.reset();
360
0
    mxCBGridHorizontalMinor.reset();
361
362
0
    mxLBLegendPosition.reset();
363
0
    mxBoxLegend.reset();
364
365
0
    mxLBAxis.reset();
366
0
    mxLBGrid.reset();
367
368
0
    mxTextTitle.reset();
369
0
    mxTextSubTitle.reset();
370
0
}
371
372
void ChartElementsPanel::Initialize()
373
0
{
374
0
    mxModel->addModifyListener(mxListener);
375
0
    updateData();
376
377
0
    Link<weld::Toggleable&,void> aLink = LINK(this, ChartElementsPanel, CheckBoxHdl);
378
0
    mxCBTitle->connect_toggled(aLink);
379
0
    mxCBSubtitle->connect_toggled(aLink);
380
0
    mxCBXAxis->connect_toggled(aLink);
381
0
    mxCBXAxisTitle->connect_toggled(aLink);
382
0
    mxCBYAxis->connect_toggled(aLink);
383
0
    mxCBYAxisTitle->connect_toggled(aLink);
384
0
    mxCBZAxis->connect_toggled(aLink);
385
0
    mxCBZAxisTitle->connect_toggled(aLink);
386
0
    mxCB2ndXAxis->connect_toggled(aLink);
387
0
    mxCB2ndXAxisTitle->connect_toggled(aLink);
388
0
    mxCB2ndYAxis->connect_toggled(aLink);
389
0
    mxCB2ndYAxisTitle->connect_toggled(aLink);
390
0
    mxCBLegend->connect_toggled(aLink);
391
0
    mxCBLegendNoOverlay->connect_toggled(aLink);
392
0
    mxCBGridVerticalMajor->connect_toggled(aLink);
393
0
    mxCBGridHorizontalMajor->connect_toggled(aLink);
394
0
    mxCBGridVerticalMinor->connect_toggled(aLink);
395
0
    mxCBGridHorizontalMinor->connect_toggled(aLink);
396
397
0
    mxLBLegendPosition->connect_changed(LINK(this, ChartElementsPanel, LegendPosHdl));
398
399
0
    Link<weld::Entry&, void> aEditLink = LINK(this, ChartElementsPanel, EditHdl);
400
0
    mxEditTitle->connect_changed(aEditLink);
401
0
    mxEditSubtitle->connect_changed(aEditLink);
402
0
}
403
404
namespace {
405
406
rtl::Reference<ChartType> getChartType(const rtl::Reference<ChartModel>& xModel)
407
0
{
408
0
    rtl::Reference<Diagram > xDiagram = xModel->getFirstChartDiagram();
409
0
    if (!xDiagram.is())
410
0
        return nullptr;
411
412
0
    const std::vector<rtl::Reference<BaseCoordinateSystem>> xCooSysSequence(xDiagram->getBaseCoordinateSystems());
413
414
0
    if (xCooSysSequence.empty())
415
0
        return nullptr;
416
417
0
    const std::vector<rtl::Reference<ChartType>> & xChartTypeSequence(xCooSysSequence[0]->getChartTypes2());
418
419
0
    if (xChartTypeSequence.empty())
420
0
        return nullptr;
421
422
0
    return xChartTypeSequence[0];
423
0
}
424
425
}
426
427
void ChartElementsPanel::updateData()
428
0
{
429
0
    if (!mbModelValid)
430
0
        return;
431
432
0
    rtl::Reference< Diagram > xDiagram(mxModel->getFirstChartDiagram());
433
0
    sal_Int32 nDimension = 0;
434
0
    if (xDiagram)
435
0
        nDimension = xDiagram->getDimension();
436
0
    SolarMutexGuard aGuard;
437
438
0
    mxCBLegend->set_active(isLegendVisible(mxModel));
439
0
    mxCBLegendNoOverlay->set_sensitive(isLegendVisible(mxModel));
440
0
    mxCBLegendNoOverlay->set_active(!isLegendOverlay(mxModel));
441
0
    mxBoxLegend->set_sensitive(isLegendVisible(mxModel));
442
443
0
    bool hasTitle = isTitleVisible(mxModel, TitleHelper::MAIN_TITLE);
444
0
    mxCBTitle->set_active(hasTitle);
445
446
0
    OUString title = mxEditTitle->get_text();
447
0
    OUString newTitle = TitleHelper::getCompleteString(TitleHelper::getTitle(TitleHelper::MAIN_TITLE, mxModel));
448
0
    if (title != newTitle)
449
0
        mxEditTitle->set_text(newTitle);
450
0
    if (mxEditTitle->get_sensitive() != hasTitle)
451
0
         mxEditTitle->set_sensitive(hasTitle);
452
453
0
    bool hasSubtitle = isTitleVisible(mxModel, TitleHelper::SUB_TITLE);
454
0
    mxCBSubtitle->set_active(hasSubtitle);
455
456
0
    OUString subtitle = mxEditSubtitle->get_text();
457
0
    OUString newSubtitle = TitleHelper::getCompleteString(TitleHelper::getTitle(TitleHelper::SUB_TITLE, mxModel));
458
0
    if (subtitle != newSubtitle)
459
0
        mxEditSubtitle->set_text(newSubtitle);
460
0
    if (mxEditSubtitle->get_sensitive() != hasSubtitle)
461
0
         mxEditSubtitle->set_sensitive(hasSubtitle);
462
463
0
    mxCBXAxisTitle->set_active(isTitleVisible(mxModel, TitleHelper::X_AXIS_TITLE));
464
0
    mxCBYAxisTitle->set_active(isTitleVisible(mxModel, TitleHelper::Y_AXIS_TITLE));
465
0
    mxCBZAxisTitle->set_active(isTitleVisible(mxModel, TitleHelper::Z_AXIS_TITLE));
466
0
    mxCB2ndXAxisTitle->set_active(isTitleVisible(mxModel, TitleHelper::SECONDARY_X_AXIS_TITLE));
467
0
    mxCB2ndYAxisTitle->set_active(isTitleVisible(mxModel, TitleHelper::SECONDARY_Y_AXIS_TITLE));
468
0
    mxCBGridVerticalMajor->set_active(isGridVisible(mxModel, GridType::VERT_MAJOR));
469
0
    mxCBGridHorizontalMajor->set_active(isGridVisible(mxModel, GridType::HOR_MAJOR));
470
0
    mxCBGridVerticalMinor->set_active(isGridVisible(mxModel, GridType::VERT_MINOR));
471
0
    mxCBGridHorizontalMinor->set_active(isGridVisible(mxModel, GridType::HOR_MINOR));
472
0
    mxCBXAxis->set_active(isAxisVisible(mxModel, AxisType::X_MAIN));
473
0
    mxCBYAxis->set_active(isAxisVisible(mxModel, AxisType::Y_MAIN));
474
0
    mxCBZAxis->set_active(isAxisVisible(mxModel, AxisType::Z_MAIN));
475
0
    mxCB2ndXAxis->set_active(isAxisVisible(mxModel, AxisType::X_SECOND));
476
0
    mxCB2ndYAxis->set_active(isAxisVisible(mxModel, AxisType::Y_SECOND));
477
478
0
    auto xChartType = getChartType(mxModel);
479
0
    bool bSupportsMainAxis = xChartType.is() ? xChartType->isSupportingMainAxis(0, 0) : true;
480
0
    if (bSupportsMainAxis)
481
0
    {
482
0
        mxCBXAxis->show();
483
0
        mxCBYAxis->show();
484
0
        mxCBZAxis->show();
485
0
        mxCBXAxisTitle->show();
486
0
        mxCBYAxisTitle->show();
487
0
        mxCBZAxisTitle->show();
488
0
        mxCBGridVerticalMajor->show();
489
0
        mxCBGridVerticalMinor->show();
490
0
        mxCBGridHorizontalMajor->show();
491
0
        mxCBGridHorizontalMinor->show();
492
0
        mxLBAxis->show();
493
0
        mxLBGrid->show();
494
0
    }
495
0
    else
496
0
    {
497
0
        mxCBXAxis->hide();
498
0
        mxCBYAxis->hide();
499
0
        mxCBZAxis->hide();
500
0
        mxCBXAxisTitle->hide();
501
0
        mxCBYAxisTitle->hide();
502
0
        mxCBZAxisTitle->hide();
503
0
        mxCBGridVerticalMajor->hide();
504
0
        mxCBGridVerticalMinor->hide();
505
0
        mxCBGridHorizontalMajor->hide();
506
0
        mxCBGridHorizontalMinor->hide();
507
0
        mxLBAxis->hide();
508
0
        mxLBGrid->hide();
509
0
    }
510
511
0
    if (nDimension == 3)
512
0
    {
513
0
        mxCBZAxis->set_sensitive(true);
514
0
        mxCBZAxisTitle->set_sensitive(true);
515
0
    }
516
0
    else
517
0
    {
518
0
        mxCBZAxis->set_sensitive(false);
519
0
        mxCBZAxisTitle->set_sensitive(false);
520
0
    }
521
522
0
    mxLBLegendPosition->set_active(getLegendPos(mxModel));
523
0
}
524
525
std::unique_ptr<PanelLayout> ChartElementsPanel::Create (
526
    weld::Widget* pParent,
527
    ChartController* pController)
528
0
{
529
0
    if (pParent == nullptr)
530
0
        throw lang::IllegalArgumentException(u"no parent Window given to ChartElementsPanel::Create"_ustr, nullptr, 0);
531
0
    return std::make_unique<ChartElementsPanel>(pParent, pController);
532
0
}
533
534
void ChartElementsPanel::DataChanged(const DataChangedEvent& rEvent)
535
0
{
536
0
    PanelLayout::DataChanged(rEvent);
537
0
    updateData();
538
0
}
539
540
void ChartElementsPanel::HandleContextChange(
541
    const vcl::EnumContext& rContext)
542
0
{
543
0
    if(maContext == rContext)
544
0
    {
545
        // Nothing to do.
546
0
        return;
547
0
    }
548
549
0
    maContext = rContext;
550
0
    updateData();
551
0
}
552
553
void ChartElementsPanel::modelInvalid()
554
0
{
555
0
    mbModelValid = false;
556
0
}
557
558
void ChartElementsPanel::doUpdateModel(const rtl::Reference<::chart::ChartModel>& xModel)
559
0
{
560
0
    if (mbModelValid)
561
0
    {
562
0
        mxModel->removeModifyListener(mxListener);
563
0
    }
564
565
0
    mxModel = xModel;
566
0
    mbModelValid = mxModel.is();
567
568
0
    if (!mbModelValid)
569
0
        return;
570
571
0
    mxModel->addModifyListener(mxListener);
572
0
}
573
574
void ChartElementsPanel::updateModel(css::uno::Reference<css::frame::XModel> xModel)
575
0
{
576
0
    ::chart::ChartModel* pModel = dynamic_cast<::chart::ChartModel*>(xModel.get());
577
0
    assert(!xModel || pModel);
578
0
    doUpdateModel(pModel);
579
0
}
580
581
IMPL_LINK(ChartElementsPanel, CheckBoxHdl, weld::Toggleable&, rCheckBox, void)
582
0
{
583
0
    bool bChecked = rCheckBox.get_active();
584
0
    if (&rCheckBox == mxCBTitle.get())
585
0
        setTitleVisible(TitleHelper::MAIN_TITLE, bChecked);
586
0
    else if (&rCheckBox == mxCBSubtitle.get())
587
0
        setTitleVisible(TitleHelper::SUB_TITLE, bChecked);
588
0
    else if (&rCheckBox == mxCBXAxis.get())
589
0
        setAxisVisible(mxModel, AxisType::X_MAIN, bChecked);
590
0
    else if (&rCheckBox == mxCBXAxisTitle.get())
591
0
        setTitleVisible(TitleHelper::X_AXIS_TITLE, bChecked);
592
0
    else if (&rCheckBox == mxCBYAxis.get())
593
0
        setAxisVisible(mxModel, AxisType::Y_MAIN, bChecked);
594
0
    else if (&rCheckBox == mxCBYAxisTitle.get())
595
0
        setTitleVisible(TitleHelper::Y_AXIS_TITLE, bChecked);
596
0
    else if (&rCheckBox == mxCBZAxis.get())
597
0
        setAxisVisible(mxModel, AxisType::Z_MAIN, bChecked);
598
0
    else if (&rCheckBox == mxCBZAxisTitle.get())
599
0
        setTitleVisible(TitleHelper::Z_AXIS_TITLE, bChecked);
600
0
    else if (&rCheckBox == mxCB2ndXAxis.get())
601
0
        setAxisVisible(mxModel, AxisType::X_SECOND, bChecked);
602
0
    else if (&rCheckBox == mxCB2ndXAxisTitle.get())
603
0
        setTitleVisible(TitleHelper::SECONDARY_X_AXIS_TITLE, bChecked);
604
0
    else if (&rCheckBox == mxCB2ndYAxis.get())
605
0
        setAxisVisible(mxModel, AxisType::Y_SECOND, bChecked);
606
0
    else if (&rCheckBox == mxCB2ndYAxisTitle.get())
607
0
        setTitleVisible(TitleHelper::SECONDARY_Y_AXIS_TITLE, bChecked);
608
0
    else if (&rCheckBox == mxCBLegend.get())
609
0
    {
610
0
        mxBoxLegend->set_sensitive(bChecked);
611
0
        mxCBLegendNoOverlay->set_sensitive(bChecked);
612
0
        setLegendVisible(mxModel, bChecked);
613
0
    }
614
0
    else if (&rCheckBox == mxCBLegendNoOverlay.get())
615
0
        setLegendOverlay(mxModel, !bChecked);
616
0
    else if (&rCheckBox == mxCBGridVerticalMajor.get())
617
0
        setGridVisible(mxModel, GridType::VERT_MAJOR, bChecked);
618
0
    else if (&rCheckBox == mxCBGridHorizontalMajor.get())
619
0
        setGridVisible(mxModel, GridType::HOR_MAJOR, bChecked);
620
0
    else if (&rCheckBox == mxCBGridVerticalMinor.get())
621
0
        setGridVisible(mxModel, GridType::VERT_MINOR, bChecked);
622
0
    else if (&rCheckBox == mxCBGridHorizontalMinor.get())
623
0
        setGridVisible(mxModel, GridType::HOR_MINOR, bChecked);
624
625
0
    updateData();
626
0
}
627
628
IMPL_LINK(ChartElementsPanel, EditHdl, weld::Entry&, rEdit, void)
629
0
{
630
    // title or subtitle?
631
0
    TitleHelper::eTitleType aTitleType = TitleHelper::MAIN_TITLE;
632
0
    if (&rEdit == mxEditSubtitle.get())
633
0
        aTitleType = TitleHelper::SUB_TITLE;
634
635
    // set it
636
0
    OUString aText(rEdit.get_text());
637
0
    TitleHelper::setCompleteString(aText, TitleHelper::getTitle(aTitleType, mxModel),
638
0
        comphelper::getProcessComponentContext(), nullptr, true);
639
0
}
640
641
IMPL_LINK_NOARG(ChartElementsPanel, LegendPosHdl, weld::ComboBox&, void)
642
0
{
643
0
    sal_Int32 nPos = mxLBLegendPosition->get_active();
644
0
    setLegendPos(mxModel, nPos);
645
0
}
646
647
void ChartElementsPanel::setTitleVisible(TitleHelper::eTitleType eTitle, bool bVisible)
648
0
{
649
0
    if (bVisible)
650
0
    {
651
0
        OUString aText = eTitle == TitleHelper::SUB_TITLE ? maTextSubTitle : maTextTitle;
652
0
        TitleHelper::createOrShowTitle(eTitle, aText, mxModel, comphelper::getProcessComponentContext());
653
0
    }
654
0
    else
655
0
    {
656
0
        TitleHelper::hideTitle(eTitle, mxModel);
657
0
    }
658
0
}
659
660
} // end of namespace ::chart::sidebar
661
662
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */