Coverage Report

Created: 2026-11-06 11:29

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sc/source/ui/unoobj/TablePivotChart.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
10
#include <com/sun/star/chart2/XChartDocument.hpp>
11
#include <com/sun/star/embed/XEmbeddedObject.hpp>
12
#include <chart2/AbstractPivotTableDataProvider.hxx>
13
#include <svx/svdoole2.hxx>
14
#include <svtools/embedhlp.hxx>
15
#include <utility>
16
#include <vcl/svapp.hxx>
17
18
#include <miscuno.hxx>
19
#include <docsh.hxx>
20
21
#include <TablePivotChart.hxx>
22
#include <ChartTools.hxx>
23
24
using namespace css;
25
26
namespace sc
27
{
28
29
SC_SIMPLE_SERVICE_INFO(TablePivotChart, u"TablePivotChart"_ustr, u"com.sun.star.table.TablePivotChart"_ustr)
30
31
TablePivotChart::TablePivotChart(ScDocShell* pDocShell, SCTAB nTab, OUString aName)
32
0
    : m_pDocShell(pDocShell)
33
0
    , m_nTab(nTab)
34
0
    , m_aChartName(std::move(aName))
35
0
{
36
0
    if (m_pDocShell)
37
0
        m_pDocShell->GetDocument().AddUnoObject(*this);
38
0
}
Unexecuted instantiation: sc::TablePivotChart::TablePivotChart(ScDocShell*, short, rtl::OUString)
Unexecuted instantiation: sc::TablePivotChart::TablePivotChart(ScDocShell*, short, rtl::OUString)
39
40
TablePivotChart::~TablePivotChart()
41
0
{
42
0
    SolarMutexGuard aGuard;
43
44
0
    if (m_pDocShell)
45
0
        m_pDocShell->GetDocument().RemoveUnoObject(*this);
46
0
}
47
48
void TablePivotChart::Notify(SfxBroadcaster&, const SfxHint& rHint)
49
0
{
50
0
    if (rHint.GetId() == SfxHintId::Dying)
51
0
        m_pDocShell = nullptr;
52
0
}
53
54
// XEmbeddedObjectSupplier
55
56
uno::Reference<lang::XComponent> SAL_CALL TablePivotChart::getEmbeddedObject()
57
0
{
58
0
    SolarMutexGuard aGuard;
59
0
    SdrOle2Obj* pObject = sctools::findChartsByName(m_pDocShell, m_nTab, m_aChartName, sctools::ChartSourceType::PIVOT_TABLE);
60
0
    if (pObject && svt::EmbeddedObjectRef::TryRunningState(pObject->GetObjRef()))
61
0
        return uno::Reference<lang::XComponent>(pObject->GetObjRef()->getComponent(), uno::UNO_QUERY);
62
0
    return nullptr;
63
0
}
64
65
// XNamed
66
67
OUString SAL_CALL TablePivotChart::getName()
68
0
{
69
0
    return m_aChartName;
70
0
}
71
72
void SAL_CALL TablePivotChart::setName(OUString const & /* aName */)
73
0
{
74
0
    throw uno::RuntimeException(); // name cannot be changed
75
0
}
76
77
// XTablePivotChart
78
79
OUString SAL_CALL TablePivotChart::getPivotTableName()
80
0
{
81
0
    SolarMutexGuard aGuard;
82
83
0
    SdrOle2Obj* pObject = sctools::findChartsByName(m_pDocShell, m_nTab, m_aChartName, sctools::ChartSourceType::PIVOT_TABLE);
84
0
    if (!pObject)
85
0
        return OUString();
86
87
0
    uno::Reference<embed::XEmbeddedObject> xObject = pObject->GetObjRef();
88
0
    if (!xObject.is())
89
0
        return OUString();
90
91
0
    uno::Reference<chart2::XChartDocument> xChartDoc(xObject->getComponent(), uno::UNO_QUERY);
92
0
    if (!xChartDoc.is())
93
0
        return OUString();
94
95
0
    chart2api::AbstractPivotTableDataProvider* pPivotTableDataProvider =
96
0
        dynamic_cast<chart2api::AbstractPivotTableDataProvider*>(xChartDoc->getDataProvider().get());
97
0
    if (!pPivotTableDataProvider)
98
0
        return OUString();
99
100
0
    return pPivotTableDataProvider->getPivotTableName();
101
0
}
102
103
} // end sc namespace
104
105
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */