diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2022-05-16 15:27:46 +0900 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2022-07-17 18:09:06 +0200 |
commit | 212f03a3cd33a1c276e93ee693dc1173a5c1b051 (patch) | |
tree | ffbd455126efe5fbd318a299ca2f48f1e569f3f4 /chart2/source/model | |
parent | 8ab54ac42ca2516c333a49fb23f6d27196122c22 (diff) |
[API-CHANGE] chart data table implementation
Adds new service DataTable, which is reposible for the properties
of a data table for a chart. Also removes the existing properties
related to the data table from Diagram service, which were added
prematurely in the past, without a data table actually being
supported by the chart module.
Also adds an implementation of the DataTable service in chart2
module.
Change-Id: I0c6b32163745704c623d04baaf0ce0e208c107f5
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136789
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'chart2/source/model')
-rw-r--r-- | chart2/source/model/main/DataTable.cxx | 230 | ||||
-rw-r--r-- | chart2/source/model/main/Diagram.cxx | 49 |
2 files changed, 261 insertions, 18 deletions
diff --git a/chart2/source/model/main/DataTable.cxx b/chart2/source/model/main/DataTable.cxx new file mode 100644 index 000000000000..cfadc5fee0ae --- /dev/null +++ b/chart2/source/model/main/DataTable.cxx @@ -0,0 +1,230 @@ +/* -*- 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 <DataTable.hxx> + +#include <LinePropertiesHelper.hxx> +#include <FillProperties.hxx> +#include <CharacterProperties.hxx> +#include <ModifyListenerHelper.hxx> +#include <PropertyHelper.hxx> +#include <cppuhelper/supportsservice.hxx> + +#include <com/sun/star/beans/PropertyAttribute.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> + +#include <algorithm> + +using namespace css; + +namespace +{ +enum +{ + DataTableProperty_HorizontalBorder, + DataTableProperty_VerticalBorder, + DataTableProperty_Outilne, + DataTableProperty_Keys, +}; + +void lcl_AddPropertiesToVector(std::vector<beans::Property>& rOutProperties) +{ + rOutProperties.emplace_back( + "HBorder", DataTableProperty_HorizontalBorder, cppu::UnoType<bool>::get(), + beans::PropertyAttribute::BOUND | beans::PropertyAttribute::MAYBEDEFAULT); + rOutProperties.emplace_back( + "VBorder", DataTableProperty_VerticalBorder, cppu::UnoType<bool>::get(), + beans::PropertyAttribute::BOUND | beans::PropertyAttribute::MAYBEDEFAULT); + rOutProperties.emplace_back("Outline", DataTableProperty_Outilne, cppu::UnoType<bool>::get(), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT); + rOutProperties.emplace_back("Keys", DataTableProperty_Keys, cppu::UnoType<bool>::get(), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT); +} + +struct StaticDataTableDefaults_Initializer +{ + ::chart::tPropertyValueMap* operator()() + { + static ::chart::tPropertyValueMap aStaticDefaults; + lcl_AddDefaultsToMap(aStaticDefaults); + return &aStaticDefaults; + } + +private: + static void lcl_AddDefaultsToMap(::chart::tPropertyValueMap& aMap) + { + ::chart::LinePropertiesHelper::AddDefaultsToMap(aMap); + ::chart::FillProperties::AddDefaultsToMap(aMap); + ::chart::CharacterProperties::AddDefaultsToMap(aMap); + + ::chart::PropertyHelper::setPropertyValueDefault(aMap, DataTableProperty_HorizontalBorder, + true); + ::chart::PropertyHelper::setPropertyValueDefault(aMap, DataTableProperty_VerticalBorder, + true); + ::chart::PropertyHelper::setPropertyValueDefault(aMap, DataTableProperty_Outilne, true); + ::chart::PropertyHelper::setPropertyValueDefault(aMap, DataTableProperty_Keys, false); + } +}; + +struct StaticDataTableDefaults + : public rtl::StaticAggregate<::chart::tPropertyValueMap, StaticDataTableDefaults_Initializer> +{ +}; + +struct StaticDataTableInfoHelper_Initializer +{ + cppu::OPropertyArrayHelper* operator()() + { + static cppu::OPropertyArrayHelper aPropHelper(lcl_GetPropertySequence()); + return &aPropHelper; + } + +private: + static uno::Sequence<beans::Property> lcl_GetPropertySequence() + { + std::vector<beans::Property> aProperties; + lcl_AddPropertiesToVector(aProperties); + ::chart::LinePropertiesHelper::AddPropertiesToVector(aProperties); + ::chart::FillProperties::AddPropertiesToVector(aProperties); + std::sort(aProperties.begin(), aProperties.end(), ::chart::PropertyNameLess()); + + return comphelper::containerToSequence(aProperties); + } +}; + +struct StaticDataTableInfoHelper + : public rtl::StaticAggregate<::cppu::OPropertyArrayHelper, + StaticDataTableInfoHelper_Initializer> +{ +}; + +struct StaticDataTableInfo_Initializer +{ + uno::Reference<beans::XPropertySetInfo>* operator()() + { + static uno::Reference<beans::XPropertySetInfo> xPropertySetInfo( + ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticDataTableInfoHelper::get())); + return &xPropertySetInfo; + } +}; + +struct StaticDataTableInfo : public rtl::StaticAggregate<uno::Reference<beans::XPropertySetInfo>, + StaticDataTableInfo_Initializer> +{ +}; + +} // anonymous namespace + +namespace chart +{ +DataTable::DataTable() + : ::property::OPropertySet(m_aMutex) + , m_xModifyEventForwarder(new ModifyEventForwarder()) +{ +} + +DataTable::DataTable(const DataTable& rOther) + : DataTable_Base(rOther) + , ::property::OPropertySet(rOther, m_aMutex) + , m_xModifyEventForwarder(new ModifyEventForwarder()) +{ +} + +DataTable::~DataTable() = default; + +// ____ XCloneable ____ +uno::Reference<util::XCloneable> SAL_CALL DataTable::createClone() +{ + return uno::Reference<util::XCloneable>(new DataTable(*this)); +} + +// ____ XModifyBroadcaster ____ +void SAL_CALL DataTable::addModifyListener(const uno::Reference<util::XModifyListener>& aListener) +{ + m_xModifyEventForwarder->addModifyListener(aListener); +} + +void SAL_CALL +DataTable::removeModifyListener(const uno::Reference<util::XModifyListener>& aListener) +{ + m_xModifyEventForwarder->removeModifyListener(aListener); +} + +// ____ XModifyListener ____ +void SAL_CALL DataTable::modified(const lang::EventObject& aEvent) +{ + m_xModifyEventForwarder->modified(aEvent); +} + +// ____ XEventListener (base of XModifyListener) ____ +void SAL_CALL DataTable::disposing(const lang::EventObject& /* Source */) +{ + // nothing +} + +// ____ OPropertySet ____ +void DataTable::firePropertyChangeEvent() +{ + m_xModifyEventForwarder->modified(lang::EventObject(static_cast<uno::XWeak*>(this))); +} + +// ____ OPropertySet ____ +void DataTable::GetDefaultValue(sal_Int32 nHandle, uno::Any& rAny) const +{ + const tPropertyValueMap& rStaticDefaults = *StaticDataTableDefaults::get(); + auto aFound = rStaticDefaults.find(nHandle); + if (aFound == rStaticDefaults.end()) + rAny.clear(); + else + rAny = (*aFound).second; +} + +::cppu::IPropertyArrayHelper& SAL_CALL DataTable::getInfoHelper() +{ + return *StaticDataTableInfoHelper::get(); +} + +// ____ XPropertySet ____ +uno::Reference<beans::XPropertySetInfo> SAL_CALL DataTable::getPropertySetInfo() +{ + return *StaticDataTableInfo::get(); +} + +// implement XServiceInfo methods basing upon getSupportedServiceNames_Static +OUString SAL_CALL DataTable::getImplementationName() +{ + return "com.sun.star.comp.chart2.DataTable"; +} + +sal_Bool SAL_CALL DataTable::supportsService(const OUString& rServiceName) +{ + return cppu::supportsService(this, rServiceName); +} + +uno::Sequence<OUString> SAL_CALL DataTable::getSupportedServiceNames() +{ + return { "com.sun.star.chart2.DataTable", "com.sun.star.beans.PropertySet", + "com.sun.star.drawing.FillProperties", "com.sun.star.drawing.LineProperties" }; +} + +IMPLEMENT_FORWARD_XINTERFACE2(DataTable, DataTable_Base, ::property::OPropertySet) +IMPLEMENT_FORWARD_XTYPEPROVIDER2(DataTable, DataTable_Base, ::property::OPropertySet) + +} // namespace chart + +extern "C" SAL_DLLPUBLIC_EXPORT uno::XInterface* +com_sun_star_comp_chart2_DataTable_get_implementation( + css::uno::XComponentContext* /*pComponentContext*/, uno::Sequence<uno::Any> const& /*rAny*/) +{ + return cppu::acquire(new ::chart::DataTable); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/chart2/source/model/main/Diagram.cxx b/chart2/source/model/main/Diagram.cxx index f6d746ff8cbc..de8244136642 100644 --- a/chart2/source/model/main/Diagram.cxx +++ b/chart2/source/model/main/Diagram.cxx @@ -32,6 +32,7 @@ #include <unonames.hxx> #include <BaseCoordinateSystem.hxx> #include <Legend.hxx> +#include <DataTable.hxx> #include <basegfx/numeric/ftools.hxx> #include <com/sun/star/beans/PropertyAttribute.hpp> @@ -161,21 +162,6 @@ void lcl_AddPropertiesToVector( PROP_DIAGRAM_3DRELATIVEHEIGHT, cppu::UnoType<sal_Int32>::get(), beans::PropertyAttribute::MAYBEVOID ); - rOutProperties.emplace_back( "DataTableHBorder", - PROP_DIAGRAM_DATATABLEHBORDER, - cppu::UnoType<bool>::get(), - beans::PropertyAttribute::BOUND - | beans::PropertyAttribute::MAYBEDEFAULT ); - rOutProperties.emplace_back( "DataTableVBorder", - PROP_DIAGRAM_DATATABLEVBORDER, - cppu::UnoType<bool>::get(), - beans::PropertyAttribute::BOUND - | beans::PropertyAttribute::MAYBEDEFAULT ); - rOutProperties.emplace_back( "DataTableOutline", - PROP_DIAGRAM_DATATABLEOUTLINE, - cppu::UnoType<bool>::get(), - beans::PropertyAttribute::BOUND - | beans::PropertyAttribute::MAYBEDEFAULT ); rOutProperties.emplace_back( "ExternalData", PROP_DIAGRAM_EXTERNALDATA, cppu::UnoType<OUString>::get(), @@ -193,9 +179,6 @@ const ::chart::tPropertyValueMap& StaticDiagramDefaults() ::chart::PropertyHelper::setPropertyValueDefault( aMap, PROP_DIAGRAM_GROUP_BARS_PER_AXIS, true ); ::chart::PropertyHelper::setPropertyValueDefault( aMap, PROP_DIAGRAM_INCLUDE_HIDDEN_CELLS, true ); ::chart::PropertyHelper::setPropertyValueDefault( aMap, PROP_DIAGRAM_RIGHT_ANGLED_AXES, false ); - ::chart::PropertyHelper::setPropertyValueDefault( aMap, PROP_DIAGRAM_DATATABLEHBORDER, false ); - ::chart::PropertyHelper::setPropertyValueDefault( aMap, PROP_DIAGRAM_DATATABLEVBORDER, false ); - ::chart::PropertyHelper::setPropertyValueDefault( aMap, PROP_DIAGRAM_DATATABLEOUTLINE, false ); ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( aMap, PROP_DIAGRAM_STARTING_ANGLE, 90 ); ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( aMap, PROP_DIAGRAM_3DRELATIVEHEIGHT, 100 ); ::chart::SceneProperties::AddDefaultsToMap( aMap ); @@ -664,6 +647,36 @@ void SAL_CALL Diagram::getFastPropertyValue( Any& rValue, sal_Int32 nHandle ) co ::property::OPropertySet::getFastPropertyValue( rValue,nHandle ); } +uno::Reference<chart2::XDataTable> SAL_CALL Diagram::getDataTable() +{ + MutexGuard aGuard(m_aMutex); + return m_xDataTable; +} + +void SAL_CALL Diagram::setDataTable(const uno::Reference<chart2::XDataTable>& xDataTable) +{ + auto* pDataTable = dynamic_cast<DataTable*>(xDataTable.get()); + assert(!xDataTable || pDataTable); + setDataTable(rtl::Reference<DataTable>(pDataTable)); +} + +void Diagram::setDataTable(const rtl::Reference<DataTable>& xNewDataTable) +{ + rtl::Reference<DataTable> xOldDataTable; + { + MutexGuard aGuard(m_aMutex); + if (m_xDataTable == xNewDataTable) + return; + xOldDataTable = m_xDataTable; + m_xDataTable = xNewDataTable; + } + if (xOldDataTable.is()) + ModifyListenerHelper::removeListener(xOldDataTable, m_xModifyEventForwarder); + if (xNewDataTable.is()) + ModifyListenerHelper::addListener(xNewDataTable, m_xModifyEventForwarder); + fireModifyEvent(); +} + using impl::Diagram_Base; IMPLEMENT_FORWARD_XINTERFACE2( Diagram, Diagram_Base, ::property::OPropertySet ) |