forked from amazingfate/loongoffice
This is a squashed commit of the pivot chart implementation.
Some of the changes:
- Add pivot chart specific (pivot table) data provider which
provides the data from a pivot table to the associated chart.
- When inserting a chart and the cursor is in a pivot table,
in that case insert a pivot chart
- Modify the pivot chart when the pivot table changes
- Collect and set the number format for the values
- isDataFromSpreadsheet check for the creation wizard
- In ChartView (and VLegend) check if the data provider is a
pivot chart data provider and get the pivot table field names
to create the buttons on the UI.
- Adds the functionallity to show a filter pop-up (from calc)
when clicking on row / column / page field buttons.
- Remove (X)PopupRequest as we won't need it.
- Add ODF import/export for pivot charts:
+ Added loext:data-pilot-source attribute on chart:chart
which is the internal name of the pivot table with which the
pivot chart is associated with. If the element is present, then
the it means the chart is a pivot chart, else it is a normal
chart
+ Added service to create pivot chart data provider through UNO
+ Add new methods to XPivotChartDataProvider to create value and
label data sequences separately from the data source, which is
needed for pivot chart import
+ When importing defer setting the data provider until a later
time when we know if we are creating a chart od a pivot chart
- Pivot chart ODF round-trip test
- Add table pivot chart supplier API:
This adds the XTablePivotChartSupplier and related interfaces so
we can access, create, delete pivot charts from UNO in a sheet
document. With this we now distinguish between normal charts
and pivot charts. This was mainly needed because we can't extend
the "published" interfaces of TableChartSupplier.
- Added an extensive test, which uses the API to create a new
pivot chart when there was none, and checks that the pivot chart
updates when the pivot table updates.
Change-Id: Ia9ed96fd6b1d342e61c2f7f9fa33a5e03dda21af
Reviewed-on: https://gerrit.libreoffice.org/36023
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Tested-by: Tomaž Vajngerl <quikee@gmail.com>
279 lines
7.8 KiB
C++
279 lines
7.8 KiB
C++
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
/*
|
|
* This file is part of the LibreOffice project.
|
|
*
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
*/
|
|
|
|
#include "PivotTableDataSequence.hxx"
|
|
|
|
#include <sal/config.h>
|
|
|
|
#include "miscuno.hxx"
|
|
#include "document.hxx"
|
|
#include "docsh.hxx"
|
|
#include "hints.hxx"
|
|
|
|
#include <com/sun/star/chart/ChartDataChangeEvent.hpp>
|
|
|
|
using namespace css;
|
|
|
|
namespace sc
|
|
{
|
|
|
|
SC_SIMPLE_SERVICE_INFO( PivotTableDataSequence, "PivotTableDataSequence", "com.sun.star.chart2.data.DataSequence")
|
|
|
|
const SfxItemPropertyMapEntry* lcl_GetDataSequencePropertyMap()
|
|
{
|
|
static const SfxItemPropertyMapEntry aDataSequencePropertyMap_Impl[] =
|
|
{
|
|
{ OUString(SC_UNONAME_HIDDENVALUES), 0, cppu::UnoType<uno::Sequence<sal_Int32>>::get(), 0, 0 },
|
|
{ OUString(SC_UNONAME_ROLE), 0, cppu::UnoType<css::chart2::data::DataSequenceRole>::get(), 0, 0 },
|
|
{ OUString(SC_UNONAME_INCLUDEHIDDENCELLS), 0, cppu::UnoType<bool>::get(), 0, 0 },
|
|
{ OUString(), 0, css::uno::Type(), 0, 0 }
|
|
};
|
|
return aDataSequencePropertyMap_Impl;
|
|
}
|
|
|
|
PivotTableDataSequence::PivotTableDataSequence(ScDocument* pDocument, OUString const & sPivotTableName, OUString const & sID,
|
|
std::vector<ValueAndFormat> const & rData)
|
|
: m_pDocument(pDocument)
|
|
, m_sPivotTableName(sPivotTableName)
|
|
, m_aID(sID)
|
|
, m_aData(rData)
|
|
, m_aPropSet(lcl_GetDataSequencePropertyMap())
|
|
{
|
|
if (m_pDocument)
|
|
m_pDocument->AddUnoObject(*this);
|
|
}
|
|
|
|
PivotTableDataSequence::~PivotTableDataSequence()
|
|
{
|
|
SolarMutexGuard g;
|
|
|
|
if (m_pDocument)
|
|
m_pDocument->RemoveUnoObject(*this);
|
|
}
|
|
|
|
void PivotTableDataSequence::Notify(SfxBroadcaster& /*rBC*/, const SfxHint& rHint)
|
|
{
|
|
if (rHint.GetId() == SfxHintId::Dying)
|
|
{
|
|
m_pDocument = nullptr;
|
|
}
|
|
}
|
|
|
|
uno::Sequence<uno::Any> SAL_CALL PivotTableDataSequence::getData()
|
|
{
|
|
SolarMutexGuard aGuard;
|
|
|
|
if (!m_pDocument)
|
|
throw uno::RuntimeException();
|
|
|
|
uno::Sequence<uno::Any> aSeq(m_aData.size());
|
|
|
|
size_t i = 0;
|
|
for (ValueAndFormat const & rItem : m_aData)
|
|
{
|
|
if (rItem.m_bIsValue)
|
|
aSeq[i] <<= double(rItem.m_fValue);
|
|
else
|
|
aSeq[i] <<= OUString(rItem.m_aString);
|
|
i++;
|
|
}
|
|
return aSeq;
|
|
}
|
|
|
|
// XNumericalDataSequence --------------------------------------------------
|
|
|
|
uno::Sequence<double> SAL_CALL PivotTableDataSequence::getNumericalData()
|
|
{
|
|
SolarMutexGuard aGuard;
|
|
if (!m_pDocument)
|
|
throw uno::RuntimeException();
|
|
|
|
uno::Sequence<double> aSeq(m_aData.size());
|
|
|
|
size_t i = 0;
|
|
for (ValueAndFormat const & rItem : m_aData)
|
|
{
|
|
aSeq[i] = rItem.m_fValue;
|
|
i++;
|
|
}
|
|
return aSeq;
|
|
}
|
|
|
|
// XTextualDataSequence --------------------------------------------------
|
|
|
|
uno::Sequence<OUString> SAL_CALL PivotTableDataSequence::getTextualData()
|
|
{
|
|
SolarMutexGuard aGuard;
|
|
if (!m_pDocument)
|
|
throw uno::RuntimeException();
|
|
|
|
uno::Sequence<OUString> aSeq(m_aData.size());
|
|
|
|
size_t i = 0;
|
|
for (ValueAndFormat const & rItem : m_aData)
|
|
{
|
|
if (!rItem.m_bIsValue)
|
|
aSeq[i] = rItem.m_aString;
|
|
i++;
|
|
}
|
|
return aSeq;
|
|
}
|
|
|
|
OUString SAL_CALL PivotTableDataSequence::getSourceRangeRepresentation()
|
|
{
|
|
SolarMutexGuard aGuard;
|
|
|
|
return m_aID;
|
|
}
|
|
|
|
uno::Sequence<OUString> SAL_CALL PivotTableDataSequence::generateLabel(chart2::data::LabelOrigin /*eOrigin*/)
|
|
{
|
|
SolarMutexGuard aGuard;
|
|
if (!m_pDocument)
|
|
throw uno::RuntimeException();
|
|
|
|
uno::Sequence<OUString> aSeq;
|
|
return aSeq;
|
|
}
|
|
|
|
sal_Int32 SAL_CALL PivotTableDataSequence::getNumberFormatKeyByIndex(sal_Int32 nIndex)
|
|
{
|
|
SolarMutexGuard aGuard;
|
|
if (nIndex == -1 && !m_aData.empty())
|
|
{
|
|
return m_aData[0].m_nNumberFormat;
|
|
}
|
|
else if (nIndex < 0 && size_t(nIndex) >= m_aData.size())
|
|
{
|
|
SAL_WARN("sc.ui", "Passed invalid index to getNumberFormatKeyByIndex(). Will return default value '0'.");
|
|
return 0;
|
|
}
|
|
return m_aData[size_t(nIndex)].m_nNumberFormat;
|
|
}
|
|
|
|
// XCloneable ================================================================
|
|
|
|
uno::Reference<util::XCloneable> SAL_CALL PivotTableDataSequence::createClone()
|
|
{
|
|
SolarMutexGuard aGuard;
|
|
|
|
std::unique_ptr<PivotTableDataSequence> pClone;
|
|
pClone.reset(new PivotTableDataSequence(m_pDocument, m_sPivotTableName, m_aID, m_aData));
|
|
pClone->setRole(m_aRole);
|
|
|
|
uno::Reference<util::XCloneable> xClone(pClone.release());
|
|
|
|
return xClone;
|
|
}
|
|
|
|
// XModifyBroadcaster ========================================================
|
|
|
|
void SAL_CALL PivotTableDataSequence::addModifyListener(const uno::Reference<util::XModifyListener>& aListener)
|
|
{
|
|
SolarMutexGuard aGuard;
|
|
m_aValueListeners.push_back(uno::Reference<util::XModifyListener>(aListener));
|
|
}
|
|
|
|
void SAL_CALL PivotTableDataSequence::removeModifyListener(const uno::Reference<util::XModifyListener>& aListener)
|
|
{
|
|
SolarMutexGuard aGuard;
|
|
|
|
sal_uInt16 nCount = m_aValueListeners.size();
|
|
for (sal_uInt16 n = nCount; n--; )
|
|
{
|
|
uno::Reference<util::XModifyListener>& rObj = m_aValueListeners[n];
|
|
if (rObj == aListener)
|
|
{
|
|
m_aValueListeners.erase(m_aValueListeners.begin() + n);
|
|
}
|
|
}
|
|
}
|
|
|
|
// DataSequence XPropertySet -------------------------------------------------
|
|
|
|
uno::Reference< beans::XPropertySetInfo> SAL_CALL PivotTableDataSequence::getPropertySetInfo()
|
|
{
|
|
SolarMutexGuard aGuard;
|
|
static uno::Reference<beans::XPropertySetInfo> aRef = new SfxItemPropertySetInfo(m_aPropSet.getPropertyMap());
|
|
return aRef;
|
|
}
|
|
|
|
void SAL_CALL PivotTableDataSequence::setPropertyValue(const OUString& rPropertyName, const uno::Any& rValue)
|
|
{
|
|
if (rPropertyName == SC_UNONAME_ROLE)
|
|
{
|
|
if (!(rValue >>= m_aRole))
|
|
throw lang::IllegalArgumentException();
|
|
}
|
|
else if (rPropertyName == SC_UNONAME_INCLUDEHIDDENCELLS
|
|
|| rPropertyName == SC_UNONAME_HIDDENVALUES
|
|
|| rPropertyName == SC_UNONAME_TIME_BASED
|
|
|| rPropertyName == SC_UNONAME_HAS_STRING_LABEL)
|
|
{}
|
|
else
|
|
throw beans::UnknownPropertyException();
|
|
}
|
|
|
|
uno::Any SAL_CALL PivotTableDataSequence::getPropertyValue(const OUString& rPropertyName)
|
|
{
|
|
uno::Any aReturn;
|
|
if (rPropertyName == SC_UNONAME_ROLE)
|
|
aReturn <<= m_aRole;
|
|
else if (rPropertyName == SC_UNONAME_INCLUDEHIDDENCELLS)
|
|
aReturn <<= false;
|
|
else if (rPropertyName == SC_UNONAME_HIDDENVALUES)
|
|
{
|
|
css::uno::Sequence<sal_Int32> aHiddenValues;
|
|
aReturn <<= aHiddenValues;
|
|
}
|
|
else if (rPropertyName == SC_UNONAME_TIME_BASED)
|
|
{
|
|
aReturn <<= false;
|
|
}
|
|
else if (rPropertyName == SC_UNONAME_HAS_STRING_LABEL)
|
|
{
|
|
aReturn <<= false;
|
|
}
|
|
else
|
|
throw beans::UnknownPropertyException();
|
|
return aReturn;
|
|
}
|
|
|
|
void SAL_CALL PivotTableDataSequence::addPropertyChangeListener(
|
|
const OUString& /*rPropertyName*/,
|
|
const uno::Reference< beans::XPropertyChangeListener>& /*xListener*/)
|
|
{
|
|
OSL_FAIL("Not yet implemented");
|
|
}
|
|
|
|
void SAL_CALL PivotTableDataSequence::removePropertyChangeListener(
|
|
const OUString& /*rPropertyName*/,
|
|
const uno::Reference< beans::XPropertyChangeListener>& /*rListener*/)
|
|
{
|
|
OSL_FAIL("Not yet implemented");
|
|
}
|
|
|
|
void SAL_CALL PivotTableDataSequence::addVetoableChangeListener(
|
|
const OUString& /*rPropertyName*/,
|
|
const uno::Reference< beans::XVetoableChangeListener>& /*rListener*/)
|
|
{
|
|
OSL_FAIL("Not yet implemented");
|
|
}
|
|
|
|
void SAL_CALL PivotTableDataSequence::removeVetoableChangeListener(
|
|
const OUString& /*rPropertyName*/,
|
|
const uno::Reference< beans::XVetoableChangeListener>& /*rListener*/)
|
|
{
|
|
OSL_FAIL("Not yet implemented");
|
|
}
|
|
|
|
} // end sc namespace
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|