summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2017-03-07 16:53:27 +0100
committerTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2017-03-30 23:52:44 +0200
commit851287e8e5ef90b5c1a0996f77f3d596c14d3b40 (patch)
treec2693917eee74de3baa483a6333dd067deba91f4
parent82fd8daea70fc1b9b26848dc3081b22bd8c605ab (diff)
charts: add field buttons if we have the pivot table data
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. Change-Id: I08faaa17c953f0f40180e1ac1b0cb1dc6471607e
-rw-r--r--chart2/source/view/main/ChartView.cxx36
-rw-r--r--chart2/source/view/main/VLegend.cxx14
2 files changed, 23 insertions, 27 deletions
diff --git a/chart2/source/view/main/ChartView.cxx b/chart2/source/view/main/ChartView.cxx
index 1e0f0d48d437..25ea564dffb3 100644
--- a/chart2/source/view/main/ChartView.cxx
+++ b/chart2/source/view/main/ChartView.cxx
@@ -114,6 +114,8 @@
#include <comphelper/classids.hxx>
#include "servicenames_charttypes.hxx"
+#include <com/sun/star/chart2/data/XPivotChartDataProvider.hpp>
+
#include <rtl/strbuf.hxx>
#include <rtl/ustring.hxx>
@@ -2490,35 +2492,29 @@ void lcl_createButtons(const uno::Reference< drawing::XShapes>& xPageShapes,
ChartModel& rModel,
awt::Rectangle& rRemainingSpace)
{
- uno::Reference<beans::XPropertySet> xModelPage(rModel.getPageBackground());
+ uno::Reference<chart2::data::XPivotChartDataProvider> xPivotChartDataProvider(rModel.getDataProvider(), uno::UNO_QUERY);
-// TODO: Get this from the PivotTable
- std::vector<OUString> aPageFields {
-// "Subdivision", "Subdivision2"
- };
- std::vector<OUString> aDataFields {
-// "Sum - Revenue", "Sum - Expenses"
- };
- std::vector<OUString> aColumnFields {
-// "Group Segment", "Group Segment 2"
- };
+ uno::Sequence<OUString> aRowFields = xPivotChartDataProvider->getRowFields();
+ uno::Sequence<OUString> aPageFields = xPivotChartDataProvider->getPageFields();
+ uno::Sequence<OUString> aDataFields = xPivotChartDataProvider->getDataFields();
+ uno::Reference<beans::XPropertySet> xModelPage(rModel.getPageBackground());
awt::Size aSize(3000, 700); // size of the button
long x = 0;
int nCIDIndex = 0;
- if (!aPageFields.empty())
+ if (aPageFields.hasElements())
{
x = 0;
nCIDIndex = 0;
- for (OUString const & aPageField : aPageFields)
+ for (OUString const & rPageField : aPageFields)
{
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(aPageField);
+ pButton->setLabel(rPageField);
pButton->setCID("PageFieldButton." + OUString::number(nCIDIndex));
pButton->createShapes(aNewPosition, aSize, xModelPage);
x += aSize.Width + 100;
@@ -2528,16 +2524,16 @@ void lcl_createButtons(const uno::Reference< drawing::XShapes>& xPageShapes,
rRemainingSpace.Height -= (aSize.Height + 100 + 100);
}
- if (!aDataFields.empty())
+ if (aDataFields.hasElements())
{
x = 200;
nCIDIndex = 0;
- for (OUString const & aDataField : aDataFields)
+ for (OUString const & rDataField : aDataFields)
{
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(aDataField);
+ pButton->setLabel(rDataField);
pButton->setCID("DataFieldButton." + OUString::number(nCIDIndex));
pButton->createShapes(aNewPosition, aSize, xModelPage);
x += aSize.Width + 100;
@@ -2547,17 +2543,17 @@ void lcl_createButtons(const uno::Reference< drawing::XShapes>& xPageShapes,
rRemainingSpace.Height -= (aSize.Height + 100 + 100);
}
- if (!aColumnFields.empty())
+ if (aRowFields.hasElements())
{
x = 200;
nCIDIndex = 0;
- for (OUString const & aColumnField : aColumnFields)
+ for (OUString const & rRowField : aRowFields)
{
std::unique_ptr<VButton> pButton(new VButton);
pButton->init(xPageShapes, xShapeFactory);
awt::Point aNewPosition = awt::Point(rRemainingSpace.X + x + 100,
rRemainingSpace.Y + rRemainingSpace.Height - aSize.Height - 100);
- pButton->setLabel(aColumnField);
+ pButton->setLabel(rRowField);
pButton->setCID("ColumnFieldButton." + OUString::number(nCIDIndex));
pButton->createShapes(aNewPosition, aSize, xModelPage);
x += aSize.Width + 100;
diff --git a/chart2/source/view/main/VLegend.cxx b/chart2/source/view/main/VLegend.cxx
index 5cddb573af95..b79c95ac4e41 100644
--- a/chart2/source/view/main/VLegend.cxx
+++ b/chart2/source/view/main/VLegend.cxx
@@ -40,6 +40,8 @@
#include <rtl/ustrbuf.hxx>
#include <svl/languageoptions.hxx>
+#include <com/sun/star/chart2/data/XPivotChartDataProvider.hpp>
+
#include <vector>
#include <algorithm>
@@ -766,14 +768,12 @@ std::vector<std::shared_ptr<VButton>> lcl_createButtons(
const uno::Reference< lang::XMultiServiceFactory>& xShapeFactory,
ChartModel& rModel, long& nUsedHeight)
{
-// TODO: get this info from the Pivot Table
- std::vector<OUString> aRowFields {
-// "Service Months"
- };
+ uno::Reference<chart2::data::XPivotChartDataProvider> xPivotChartDataProvider(rModel.getDataProvider(), uno::UNO_QUERY);
+ uno::Sequence<OUString> aColumnFields = xPivotChartDataProvider->getColumnFields();
std::vector<std::shared_ptr<VButton>> aButtons;
- if (aRowFields.empty())
+ if (!aColumnFields.hasElements())
return aButtons;
uno::Reference<beans::XPropertySet> xModelPage(rModel.getPageBackground());
@@ -781,13 +781,13 @@ std::vector<std::shared_ptr<VButton>> lcl_createButtons(
int nCIDIndex = 0;
awt::Size aSize(2000, 700);
- for (OUString const & sRowField : aRowFields)
+ for (OUString const & sColumnField : aColumnFields)
{
std::shared_ptr<VButton> pButton(new VButton);
aButtons.push_back(pButton);
pButton->init(xLegendContainer, xShapeFactory);
awt::Point aNewPosition = awt::Point(100, 100);
- pButton->setLabel(sRowField);
+ pButton->setLabel(sColumnField);
pButton->setCID("RowFieldButton." + OUString::number(nCIDIndex));
pButton->createShapes(aNewPosition, aSize, xModelPage);
nCIDIndex += 1;