diff options
Diffstat (limited to '')
-rw-r--r-- | sc/source/ui/sparklines/SparklineAttributes.cxx | 277 | ||||
-rw-r--r-- | sc/source/ui/sparklines/SparklineData.cxx | 30 | ||||
-rw-r--r-- | sc/source/ui/sparklines/SparklineGroup.cxx | 34 | ||||
-rw-r--r-- | sc/source/ui/sparklines/SparklineList.cxx | 103 |
4 files changed, 444 insertions, 0 deletions
diff --git a/sc/source/ui/sparklines/SparklineAttributes.cxx b/sc/source/ui/sparklines/SparklineAttributes.cxx new file mode 100644 index 000000000..20b8bf6fe --- /dev/null +++ b/sc/source/ui/sparklines/SparklineAttributes.cxx @@ -0,0 +1,277 @@ +/* -*- 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 <SparklineAttributes.hxx> + +namespace sc +{ +/** Holder of sparkline attributes */ +class SparklineAttributes::Implementation +{ +public: + Color m_aColorSeries; + Color m_aColorNegative; + Color m_aColorAxis; + Color m_aColorMarkers; + Color m_aColorFirst; + Color m_aColorLast; + Color m_aColorHigh; + Color m_aColorLow; + + AxisType m_eMinAxisType; + AxisType m_eMaxAxisType; + + double m_fLineWeight; // In pt + + SparklineType m_eType; + + bool m_bDateAxis; + + DisplayEmptyCellsAs m_eDisplayEmptyCellsAs; // span, gap, zero + + bool m_bMarkers; + bool m_bHigh; + bool m_bLow; + bool m_bFirst; + bool m_bLast; + bool m_bNegative; + bool m_bDisplayXAxis; + bool m_bDisplayHidden; + bool m_bRightToLeft; + + std::optional<double> m_aManualMax; + std::optional<double> m_aManualMin; + + static constexpr ::Color COL_STANDARD_RED = 0xff0000; + static constexpr ::Color COL_STANDARD_BLUE = 0x2a6099; + + Implementation() + : m_aColorSeries(COL_STANDARD_BLUE) + , m_aColorNegative(COL_STANDARD_RED) + , m_aColorAxis(COL_STANDARD_RED) + , m_aColorMarkers(COL_STANDARD_RED) + , m_aColorFirst(COL_STANDARD_RED) + , m_aColorLast(COL_STANDARD_RED) + , m_aColorHigh(COL_STANDARD_RED) + , m_aColorLow(COL_STANDARD_RED) + , m_eMinAxisType(AxisType::Individual) + , m_eMaxAxisType(AxisType::Individual) + , m_fLineWeight(0.75) + , m_eType(SparklineType::Line) + , m_bDateAxis(false) + , m_eDisplayEmptyCellsAs(DisplayEmptyCellsAs::Zero) + , m_bMarkers(false) + , m_bHigh(false) + , m_bLow(false) + , m_bFirst(false) + , m_bLast(false) + , m_bNegative(false) + , m_bDisplayXAxis(false) + , m_bDisplayHidden(false) + , m_bRightToLeft(false) + { + } + + Implementation(Implementation const& pOther) + : m_aColorSeries(pOther.m_aColorSeries) + , m_aColorNegative(pOther.m_aColorNegative) + , m_aColorAxis(pOther.m_aColorAxis) + , m_aColorMarkers(pOther.m_aColorMarkers) + , m_aColorFirst(pOther.m_aColorFirst) + , m_aColorLast(pOther.m_aColorLast) + , m_aColorHigh(pOther.m_aColorHigh) + , m_aColorLow(pOther.m_aColorLow) + , m_eMinAxisType(pOther.m_eMinAxisType) + , m_eMaxAxisType(pOther.m_eMaxAxisType) + , m_fLineWeight(pOther.m_fLineWeight) + , m_eType(pOther.m_eType) + , m_bDateAxis(pOther.m_bDateAxis) + , m_eDisplayEmptyCellsAs(pOther.m_eDisplayEmptyCellsAs) + , m_bMarkers(pOther.m_bMarkers) + , m_bHigh(pOther.m_bHigh) + , m_bLow(pOther.m_bLow) + , m_bFirst(pOther.m_bFirst) + , m_bLast(pOther.m_bLast) + , m_bNegative(pOther.m_bNegative) + , m_bDisplayXAxis(pOther.m_bDisplayXAxis) + , m_bDisplayHidden(pOther.m_bDisplayHidden) + , m_bRightToLeft(pOther.m_bRightToLeft) + , m_aManualMax(pOther.m_aManualMax) + , m_aManualMin(pOther.m_aManualMin) + { + } + + bool operator==(const Implementation& rImpl) const + { + return (m_aColorSeries == rImpl.m_aColorSeries) + && (m_aColorNegative == rImpl.m_aColorNegative) + && (m_aColorAxis == rImpl.m_aColorAxis) && (m_aColorMarkers == rImpl.m_aColorMarkers) + && (m_aColorFirst == rImpl.m_aColorFirst) && (m_aColorLast == rImpl.m_aColorLast) + && (m_aColorHigh == rImpl.m_aColorHigh) && (m_aColorLow == rImpl.m_aColorLow) + && (m_eMinAxisType == rImpl.m_eMinAxisType) + && (m_eMaxAxisType == rImpl.m_eMaxAxisType) && (m_fLineWeight == rImpl.m_fLineWeight) + && (m_eType == rImpl.m_eType) && (m_bDateAxis == rImpl.m_bDateAxis) + && (m_eDisplayEmptyCellsAs == rImpl.m_eDisplayEmptyCellsAs) + && (m_bMarkers == rImpl.m_bMarkers) && (m_bHigh == rImpl.m_bHigh) + && (m_bLow == rImpl.m_bLow) && (m_bFirst == rImpl.m_bFirst) + && (m_bLast == rImpl.m_bLast) && (m_bNegative == rImpl.m_bNegative) + && (m_bDisplayXAxis == rImpl.m_bDisplayXAxis) + && (m_bDisplayHidden == rImpl.m_bDisplayHidden) + && (m_bRightToLeft == rImpl.m_bRightToLeft) && (m_aManualMax == rImpl.m_aManualMax) + && (m_aManualMin == rImpl.m_aManualMin); + } +}; + +SparklineAttributes::SparklineAttributes() = default; + +SparklineAttributes::~SparklineAttributes() = default; + +SparklineAttributes::SparklineAttributes(SparklineAttributes const&) = default; + +SparklineAttributes::SparklineAttributes(SparklineAttributes&&) = default; + +SparklineAttributes& SparklineAttributes::operator=(SparklineAttributes const&) = default; + +SparklineAttributes& SparklineAttributes::operator=(SparklineAttributes&&) = default; + +bool SparklineAttributes::operator==(SparklineAttributes const& rOther) const +{ + return m_aImplementation == rOther.m_aImplementation; +} + +Color SparklineAttributes::getColorSeries() const { return m_aImplementation->m_aColorSeries; } + +void SparklineAttributes::setColorSeries(Color aColor) +{ + m_aImplementation->m_aColorSeries = aColor; +} + +Color SparklineAttributes::getColorNegative() const { return m_aImplementation->m_aColorNegative; } + +void SparklineAttributes::setColorNegative(Color aColor) +{ + m_aImplementation->m_aColorNegative = aColor; +} + +Color SparklineAttributes::getColorAxis() const { return m_aImplementation->m_aColorAxis; } + +void SparklineAttributes::setColorAxis(Color aColor) { m_aImplementation->m_aColorAxis = aColor; } + +Color SparklineAttributes::getColorMarkers() const { return m_aImplementation->m_aColorMarkers; } +void SparklineAttributes::setColorMarkers(Color aColor) +{ + m_aImplementation->m_aColorMarkers = aColor; +} + +Color SparklineAttributes::getColorFirst() const { return m_aImplementation->m_aColorFirst; } +void SparklineAttributes::setColorFirst(Color aColor) { m_aImplementation->m_aColorFirst = aColor; } + +Color SparklineAttributes::getColorLast() const { return m_aImplementation->m_aColorLast; } +void SparklineAttributes::setColorLast(Color aColor) { m_aImplementation->m_aColorLast = aColor; } + +Color SparklineAttributes::getColorHigh() const { return m_aImplementation->m_aColorHigh; } +void SparklineAttributes::setColorHigh(Color aColor) { m_aImplementation->m_aColorHigh = aColor; } + +Color SparklineAttributes::getColorLow() const { return m_aImplementation->m_aColorLow; } +void SparklineAttributes::setColorLow(Color aColor) { m_aImplementation->m_aColorLow = aColor; } + +AxisType SparklineAttributes::getMinAxisType() const { return m_aImplementation->m_eMinAxisType; } +void SparklineAttributes::setMinAxisType(AxisType eAxisType) +{ + m_aImplementation->m_eMinAxisType = eAxisType; +} + +AxisType SparklineAttributes::getMaxAxisType() const { return m_aImplementation->m_eMaxAxisType; } +void SparklineAttributes::setMaxAxisType(AxisType eAxisType) +{ + m_aImplementation->m_eMaxAxisType = eAxisType; +} + +double SparklineAttributes::getLineWeight() const { return m_aImplementation->m_fLineWeight; } +void SparklineAttributes::setLineWeight(double nWeight) +{ + m_aImplementation->m_fLineWeight = nWeight; +} + +SparklineType SparklineAttributes::getType() const { return m_aImplementation->m_eType; } +void SparklineAttributes::setType(SparklineType eType) { m_aImplementation->m_eType = eType; } + +bool SparklineAttributes::isDateAxis() const { return m_aImplementation->m_bDateAxis; } +void SparklineAttributes::setDateAxis(bool bValue) { m_aImplementation->m_bDateAxis = bValue; } + +DisplayEmptyCellsAs SparklineAttributes::getDisplayEmptyCellsAs() const +{ + return m_aImplementation->m_eDisplayEmptyCellsAs; +} +void SparklineAttributes::setDisplayEmptyCellsAs(DisplayEmptyCellsAs eValue) +{ + m_aImplementation->m_eDisplayEmptyCellsAs = eValue; +} + +bool SparklineAttributes::isMarkers() const { return m_aImplementation->m_bMarkers; } +void SparklineAttributes::setMarkers(bool bValue) { m_aImplementation->m_bMarkers = bValue; } + +bool SparklineAttributes::isHigh() const { return m_aImplementation->m_bHigh; } +void SparklineAttributes::setHigh(bool bValue) { m_aImplementation->m_bHigh = bValue; } + +bool SparklineAttributes::isLow() const { return m_aImplementation->m_bLow; } +void SparklineAttributes::setLow(bool bValue) { m_aImplementation->m_bLow = bValue; } + +bool SparklineAttributes::isFirst() const { return m_aImplementation->m_bFirst; } +void SparklineAttributes::setFirst(bool bValue) { m_aImplementation->m_bFirst = bValue; } + +bool SparklineAttributes::isLast() const { return m_aImplementation->m_bLast; } +void SparklineAttributes::setLast(bool bValue) { m_aImplementation->m_bLast = bValue; } + +bool SparklineAttributes::isNegative() const { return m_aImplementation->m_bNegative; } +void SparklineAttributes::setNegative(bool bValue) { m_aImplementation->m_bNegative = bValue; } + +bool SparklineAttributes::shouldDisplayXAxis() const { return m_aImplementation->m_bDisplayXAxis; } +void SparklineAttributes::setDisplayXAxis(bool bValue) +{ + m_aImplementation->m_bDisplayXAxis = bValue; +} + +bool SparklineAttributes::shouldDisplayHidden() const +{ + return m_aImplementation->m_bDisplayHidden; +} +void SparklineAttributes::setDisplayHidden(bool bValue) +{ + m_aImplementation->m_bDisplayHidden = bValue; +} + +bool SparklineAttributes::isRightToLeft() const { return m_aImplementation->m_bRightToLeft; } +void SparklineAttributes::setRightToLeft(bool bValue) +{ + m_aImplementation->m_bRightToLeft = bValue; +} + +std::optional<double> SparklineAttributes::getManualMax() const +{ + return m_aImplementation->m_aManualMax; +} +void SparklineAttributes::setManualMax(std::optional<double> aValue) +{ + m_aImplementation->m_aManualMax = aValue; +} + +std::optional<double> SparklineAttributes::getManualMin() const +{ + return m_aImplementation->m_aManualMin; +} +void SparklineAttributes::setManualMin(std::optional<double> aValue) +{ + m_aImplementation->m_aManualMin = aValue; +} + +} // end sc + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/sparklines/SparklineData.cxx b/sc/source/ui/sparklines/SparklineData.cxx new file mode 100644 index 000000000..a126acc10 --- /dev/null +++ b/sc/source/ui/sparklines/SparklineData.cxx @@ -0,0 +1,30 @@ +/* -*- 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 <SparklineData.hxx> + +namespace sc +{ +RangeOrientation calculateOrientation(sal_Int32 nOutputSize, ScRange const& rInputRange) +{ + sal_Int32 nRowSize = rInputRange.aEnd.Row() - rInputRange.aStart.Row(); + sal_Int32 nColSize = rInputRange.aEnd.Col() - rInputRange.aStart.Col(); + + auto eInputOrientation = RangeOrientation::Unknown; + if (nOutputSize == nRowSize) + eInputOrientation = RangeOrientation::Row; + else if (nOutputSize == nColSize) + eInputOrientation = RangeOrientation::Col; + return eInputOrientation; +} + +} // end sc + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/sparklines/SparklineGroup.cxx b/sc/source/ui/sparklines/SparklineGroup.cxx new file mode 100644 index 000000000..1ba235e75 --- /dev/null +++ b/sc/source/ui/sparklines/SparklineGroup.cxx @@ -0,0 +1,34 @@ +/* -*- 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 <SparklineGroup.hxx> + +namespace sc +{ +SparklineGroup::SparklineGroup(SparklineAttributes const& rSparklineAttributes) + : m_aAttributes(rSparklineAttributes) + , m_aGUID(tools::Guid::Generate) +{ +} + +SparklineGroup::SparklineGroup() + : m_aGUID(tools::Guid::Generate) +{ +} + +SparklineGroup::SparklineGroup(SparklineGroup const& pOtherSparkline) + : m_aAttributes(pOtherSparkline.m_aAttributes) + , m_aGUID(pOtherSparkline.m_aGUID) +{ +} + +} // end sc + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/sparklines/SparklineList.cxx b/sc/source/ui/sparklines/SparklineList.cxx new file mode 100644 index 000000000..1cae30896 --- /dev/null +++ b/sc/source/ui/sparklines/SparklineList.cxx @@ -0,0 +1,103 @@ +/* -*- 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 <SparklineList.hxx> + +namespace sc +{ +SparklineList::SparklineList() = default; + +void SparklineList::addSparkline(std::shared_ptr<Sparkline> const& pSparkline) +{ + auto pWeakGroup = std::weak_ptr<SparklineGroup>(pSparkline->getSparklineGroup()); + + auto[iterator, bInserted] + = m_aSparklineGroupMap.try_emplace(pWeakGroup, std::vector<std::weak_ptr<Sparkline>>()); + iterator->second.push_back(std::weak_ptr<Sparkline>(pSparkline)); + if (bInserted) + m_aSparklineGroups.push_back(pWeakGroup); +} + +void SparklineList::removeSparkline(std::shared_ptr<Sparkline> const& pSparkline) +{ + auto pWeakGroup = std::weak_ptr<SparklineGroup>(pSparkline->getSparklineGroup()); + auto iteratorGroup = m_aSparklineGroupMap.find(pWeakGroup); + if (iteratorGroup != m_aSparklineGroupMap.end()) + { + auto& rWeakSparklines = iteratorGroup->second; + + for (auto iterator = rWeakSparklines.begin(); iterator != rWeakSparklines.end();) + { + auto pCurrentSparkline = iterator->lock(); + + if (pCurrentSparkline && pCurrentSparkline != pSparkline) + { + iterator++; + } + else + { + iterator = rWeakSparklines.erase(iterator); + } + } + } +} + +std::vector<std::shared_ptr<SparklineGroup>> SparklineList::getSparklineGroups() +{ + std::vector<std::shared_ptr<SparklineGroup>> toReturn; + + for (auto iterator = m_aSparklineGroups.begin(); iterator != m_aSparklineGroups.end();) + { + auto pWeakGroup = *iterator; + if (auto pSparklineGroup = pWeakGroup.lock()) + { + toReturn.push_back(pSparklineGroup); + iterator++; + } + else + { + iterator = m_aSparklineGroups.erase(iterator); + } + } + return toReturn; +} + +std::vector<std::shared_ptr<Sparkline>> +SparklineList::getSparklinesFor(std::shared_ptr<SparklineGroup> const& pSparklineGroup) +{ + std::vector<std::shared_ptr<Sparkline>> toReturn; + + std::weak_ptr<SparklineGroup> pWeakGroup(pSparklineGroup); + auto iteratorGroup = m_aSparklineGroupMap.find(pWeakGroup); + + if (iteratorGroup == m_aSparklineGroupMap.end()) + return toReturn; + + auto& rWeakSparklines = iteratorGroup->second; + + for (auto iterator = rWeakSparklines.begin(); iterator != rWeakSparklines.end();) + { + if (auto aSparkline = iterator->lock()) + { + toReturn.push_back(aSparkline); + iterator++; + } + else + { + iterator = rWeakSparklines.erase(iterator); + } + } + + return toReturn; +} + +} // end sc + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |