summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2017-05-01 20:28:59 +0200
committerTomaž Vajngerl <quikee@gmail.com>2017-05-01 22:25:32 +0200
commitd02d52887678cd3d518c19a235bc443c292b3041 (patch)
tree3fdee17138c0e0d944e4681ab13af1b0e49b9fbb /sc
parenta33201662c7b7b7350d23eb07f5a3d76fd67e8e1 (diff)
tdf#107145 display applied filters for page field in pivot chart
Add field output description which shows the description of the filtered output, which can be either "- all -" when nothing is filtered, "- multiple -" when multiple values are outputted or the specific value - the only value remaining. Change-Id: I8fca6050dabba9878e9f3a31e4be7a03e3b87467 Reviewed-on: https://gerrit.libreoffice.org/37125 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'sc')
-rw-r--r--sc/inc/PivotTableDataProvider.hxx4
-rw-r--r--sc/source/ui/unoobj/PivotTableDataProvider.cxx61
2 files changed, 65 insertions, 0 deletions
diff --git a/sc/inc/PivotTableDataProvider.hxx b/sc/inc/PivotTableDataProvider.hxx
index 67a65f37b07d..f572cbdf797d 100644
--- a/sc/inc/PivotTableDataProvider.hxx
+++ b/sc/inc/PivotTableDataProvider.hxx
@@ -97,6 +97,8 @@ public:
virtual css::uno::Reference<css::chart2::data::XDataSequence> SAL_CALL
createDataSequenceOfCategories() override;
+ virtual OUString SAL_CALL getFieldOutputDescription(sal_Int32 nPageFieldIndex) override;
+
// XPropertySet
virtual css::uno::Reference<css::beans::XPropertySetInfo> SAL_CALL getPropertySetInfo() override;
@@ -170,6 +172,8 @@ private:
std::vector<css::chart2::data::PivotTableFieldEntry> m_aPageFields;
std::vector<css::chart2::data::PivotTableFieldEntry> m_aDataFields;
+ std::unordered_map<sal_Int32, OUString> m_aFieldOutputDescriptionMap;
+
bool m_bNeedsUpdate;
css::uno::Reference<css::uno::XComponentContext> m_xContext;
diff --git a/sc/source/ui/unoobj/PivotTableDataProvider.cxx b/sc/source/ui/unoobj/PivotTableDataProvider.cxx
index 112acbe96a48..fee34e6f9cc8 100644
--- a/sc/source/ui/unoobj/PivotTableDataProvider.cxx
+++ b/sc/source/ui/unoobj/PivotTableDataProvider.cxx
@@ -18,7 +18,9 @@
#include "document.hxx"
#include "unonames.hxx"
#include "docsh.hxx"
+#include "scresid.hxx"
#include "globstr.hrc"
+#include "scres.hrc"
#include "dpobject.hxx"
#include "hints.hxx"
@@ -36,6 +38,7 @@
#include <com/sun/star/sheet/XLevelsSupplier.hpp>
#include <com/sun/star/sheet/XDataPilotMemberResults.hpp>
#include <com/sun/star/sheet/MemberResultFlags.hpp>
+#include <com/sun/star/sheet/XMembersSupplier.hpp>
#include <com/sun/star/chart/ChartDataChangeEvent.hpp>
@@ -86,6 +89,39 @@ OUString lcl_identifierForCategories()
return "PT@" + constIdCategories;
}
+std::vector<OUString> lcl_getVisiblePageMembers(const uno::Reference<uno::XInterface> & xLevel)
+{
+ std::vector<OUString> aResult;
+ if (!xLevel.is())
+ return aResult;
+
+ uno::Reference<sheet::XMembersSupplier> xMembersSupplier(xLevel, uno::UNO_QUERY);
+ if (!xMembersSupplier.is())
+ return aResult;
+
+ uno::Reference<sheet::XMembersAccess> xMembersAccess = xMembersSupplier->getMembers();
+ if (!xMembersAccess.is())
+ return aResult;
+
+ for (OUString const & rMemberNames : xMembersAccess->getElementNames())
+ {
+ uno::Reference<beans::XPropertySet> xProperties(xMembersAccess->getByName(rMemberNames), uno::UNO_QUERY);
+ if (!xProperties.is())
+ continue;
+
+ OUString aCaption = ScUnoHelpFunctions::GetStringProperty(xProperties, SC_UNO_DP_LAYOUTNAME, OUString());
+ if (aCaption.isEmpty())
+ aCaption = rMemberNames;
+
+ bool bVisible = ScUnoHelpFunctions::GetBoolProperty(xProperties, SC_UNO_DP_ISVISIBLE);
+
+ if (bVisible)
+ aResult.push_back(aCaption);
+ }
+
+ return aResult;
+}
+
} // end anonymous namespace
SC_SIMPLE_SERVICE_INFO(PivotTableDataProvider, "PivotTableDataProvider", SC_SERVICENAME_CHART_PIVOTTABLE_DATAPROVIDER)
@@ -261,6 +297,7 @@ void PivotTableDataProvider::collectPivotTableData()
m_aRowFields.clear();
m_aPageFields.clear();
m_aDataFields.clear();
+ m_aFieldOutputDescriptionMap.clear();
uno::Reference<sheet::XDataPilotResults> xDPResults(pDPObject->GetSource(), uno::UNO_QUERY);
uno::Sequence<uno::Sequence<sheet::DataResult>> xDataResultsSequence = xDPResults->getResults();
@@ -447,6 +484,23 @@ void PivotTableDataProvider::collectPivotTableData()
case sheet::DataPilotFieldOrientation_PAGE:
{
m_aPageFields.push_back(chart2::data::PivotTableFieldEntry{xLevelName->getName(), nDim, nDimPos, bHasHiddenMember});
+
+ // Resolve filtering
+ OUString aFieldOutputDescription;
+ if (bHasHiddenMember)
+ {
+ std::vector<OUString> aMembers = lcl_getVisiblePageMembers(xLevel);
+
+ if (aMembers.size() == 1)
+ aFieldOutputDescription = aMembers[0];
+ else
+ aFieldOutputDescription = ScResId(SCSTR_MULTIPLE).toString();
+ }
+ else
+ {
+ aFieldOutputDescription = ScResId(SCSTR_ALL).toString();
+ }
+ m_aFieldOutputDescriptionMap[nDim] = aFieldOutputDescription;
}
break;
@@ -763,6 +817,13 @@ uno::Reference<css::chart2::data::XDataSequence>
return xDataSequence;
}
+OUString PivotTableDataProvider::getFieldOutputDescription(sal_Int32 nDimensionIndex)
+{
+ if (nDimensionIndex < 0)
+ return OUString();
+ return m_aFieldOutputDescriptionMap[size_t(nDimensionIndex)];
+}
+
// XModifyBroadcaster ========================================================
void SAL_CALL PivotTableDataProvider::addModifyListener(const uno::Reference< util::XModifyListener>& aListener)