summaryrefslogtreecommitdiff
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
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>
-rw-r--r--chart2/source/view/main/ChartView.cxx11
-rw-r--r--offapi/com/sun/star/chart2/data/XPivotTableDataProvider.idl7
-rw-r--r--sc/inc/PivotTableDataProvider.hxx4
-rw-r--r--sc/source/ui/unoobj/PivotTableDataProvider.cxx61
4 files changed, 80 insertions, 3 deletions
diff --git a/chart2/source/view/main/ChartView.cxx b/chart2/source/view/main/ChartView.cxx
index b0f99831c090..ccaa3f868444 100644
--- a/chart2/source/view/main/ChartView.cxx
+++ b/chart2/source/view/main/ChartView.cxx
@@ -2498,7 +2498,8 @@ void lcl_createButtons(const uno::Reference<drawing::XShapes>& xPageShapes,
return;
uno::Reference<beans::XPropertySet> xModelPage(rModel.getPageBackground());
- awt::Size aSize(3000, 700); // size of the button
+
+ awt::Size aSize(4000, 700); // size of the button
long x = 0;
@@ -2511,8 +2512,10 @@ void lcl_createButtons(const uno::Reference<drawing::XShapes>& xPageShapes,
std::unique_ptr<VButton> pButton(new VButton);
pButton->init(xPageShapes, xShapeFactory);
awt::Point aNewPosition = awt::Point(rRemainingSpace.X + x + 100, rRemainingSpace.Y + 100);
- pButton->setLabel(rPageFieldEntry.Name);
- pButton->setCID("FieldButton.Page." + OUString::number(rPageFieldEntry.DimensionIndex));
+ sal_Int32 nDimensionIndex = rPageFieldEntry.DimensionIndex;
+ OUString aFieldOutputDescription = xPivotTableDataProvider->getFieldOutputDescription(nDimensionIndex);
+ pButton->setLabel(rPageFieldEntry.Name + " | " + aFieldOutputDescription);
+ pButton->setCID("FieldButton.Page." + OUString::number(nDimensionIndex));
pButton->setPosition(aNewPosition);
pButton->setSize(aSize);
if (rPageFieldEntry.HasHiddenMembers)
@@ -2525,6 +2528,8 @@ void lcl_createButtons(const uno::Reference<drawing::XShapes>& xPageShapes,
rRemainingSpace.Height -= (aSize.Height + 100 + 100);
}
+ aSize = awt::Size(3000, 700); // size of the button
+
if (xPivotTableDataProvider->getRowFields().hasElements())
{
x = 200;
diff --git a/offapi/com/sun/star/chart2/data/XPivotTableDataProvider.idl b/offapi/com/sun/star/chart2/data/XPivotTableDataProvider.idl
index 540304113b89..78f285ffaf89 100644
--- a/offapi/com/sun/star/chart2/data/XPivotTableDataProvider.idl
+++ b/offapi/com/sun/star/chart2/data/XPivotTableDataProvider.idl
@@ -85,6 +85,13 @@ interface XPivotTableDataProvider : com::sun::star::uno::XInterface
* @since LibreOffice 5.4
*/
XDataSequence createDataSequenceOfCategories();
+
+ /** field output description: either "- all -", "- multiple -", or specific value
+ *
+ * @param nDimensionIndex
+ * dimension index of the field
+ */
+ string getFieldOutputDescription([in] long nDimensionIndex);
};
};};};};};
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)