2015-07-16 18:44:01 +02:00
|
|
|
/* -*- 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/.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following license notice:
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sfx2/sidebar/ResourceDefinitions.hrc>
|
|
|
|
#include <sfx2/sidebar/Theme.hxx>
|
|
|
|
#include <sfx2/sidebar/ControlFactory.hxx>
|
|
|
|
|
2015-07-16 20:17:37 +02:00
|
|
|
#include <com/sun/star/chart2/DataPointLabel.hpp>
|
2015-07-16 22:12:03 +02:00
|
|
|
#include <com/sun/star/chart/ErrorBarStyle.hpp>
|
2015-07-16 20:17:37 +02:00
|
|
|
|
2015-07-16 18:44:01 +02:00
|
|
|
#include "ChartSeriesPanel.hxx"
|
|
|
|
#include "ChartController.hxx"
|
|
|
|
#include <sfx2/bindings.hxx>
|
|
|
|
#include <sfx2/dispatch.hxx>
|
|
|
|
#include <sfx2/imagemgr.hxx>
|
|
|
|
#include <vcl/fixed.hxx>
|
|
|
|
#include <vcl/lstbox.hxx>
|
|
|
|
#include <vcl/field.hxx>
|
|
|
|
#include <vcl/toolbox.hxx>
|
|
|
|
#include <svl/intitem.hxx>
|
|
|
|
#include <svl/stritem.hxx>
|
|
|
|
#include <comphelper/processfactory.hxx>
|
|
|
|
|
|
|
|
#include "ChartModel.hxx"
|
2015-07-16 20:17:37 +02:00
|
|
|
#include "DataSeriesHelper.hxx"
|
2015-07-16 21:15:31 +02:00
|
|
|
#include "RegressionCurveHelper.hxx"
|
2015-07-16 22:12:03 +02:00
|
|
|
#include "StatisticsHelper.hxx"
|
2015-07-16 18:44:01 +02:00
|
|
|
|
|
|
|
using namespace css;
|
|
|
|
using namespace css::uno;
|
|
|
|
using ::sfx2::sidebar::Theme;
|
|
|
|
|
|
|
|
namespace chart { namespace sidebar {
|
|
|
|
|
2015-07-16 20:17:37 +02:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
bool isDataLabelVisible(css::uno::Reference<css::frame::XModel> xModel, const OUString& rCID)
|
|
|
|
{
|
|
|
|
css::uno::Reference< css::chart2::XDataSeries > xSeries(
|
|
|
|
ObjectIdentifier::getDataSeriesForCID(rCID, xModel), uno::UNO_QUERY );
|
|
|
|
|
|
|
|
if (!xSeries.is())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return DataSeriesHelper::hasDataLabelsAtSeries(xSeries);
|
|
|
|
}
|
|
|
|
|
|
|
|
void setDataLabelVisible(css::uno::Reference<css::frame::XModel> xModel, const OUString& rCID, bool bVisible)
|
|
|
|
{
|
|
|
|
css::uno::Reference< css::chart2::XDataSeries > xSeries(
|
|
|
|
ObjectIdentifier::getDataSeriesForCID(rCID, xModel), uno::UNO_QUERY );
|
|
|
|
|
|
|
|
if (!xSeries.is())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (bVisible)
|
|
|
|
DataSeriesHelper::insertDataLabelsToSeriesAndAllPoints(xSeries);
|
|
|
|
else
|
|
|
|
DataSeriesHelper::deleteDataLabelsFromSeriesAndAllPoints(xSeries);
|
|
|
|
}
|
|
|
|
|
2015-07-16 21:15:31 +02:00
|
|
|
bool isTrendlineVisible(css::uno::Reference<css::frame::XModel> xModel,
|
|
|
|
const OUString& rCID)
|
|
|
|
{
|
|
|
|
css::uno::Reference< css::chart2::XRegressionCurveContainer > xRegressionCurveContainer(
|
|
|
|
ObjectIdentifier::getDataSeriesForCID(rCID, xModel), uno::UNO_QUERY );
|
|
|
|
|
|
|
|
if (!xRegressionCurveContainer.is())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return xRegressionCurveContainer->getRegressionCurves().getLength() != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setTrendlineVisible(css::uno::Reference<css::frame::XModel>
|
|
|
|
xModel, const OUString& rCID, bool bVisible)
|
|
|
|
{
|
|
|
|
css::uno::Reference< css::chart2::XRegressionCurveContainer > xRegressionCurveContainer(
|
|
|
|
ObjectIdentifier::getDataSeriesForCID(rCID, xModel), uno::UNO_QUERY );
|
|
|
|
|
|
|
|
if (!xRegressionCurveContainer.is())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (bVisible)
|
|
|
|
{
|
|
|
|
/* code */
|
|
|
|
uno::Reference< chart2::XRegressionCurve > xCurve =
|
|
|
|
RegressionCurveHelper::addRegressionCurve(
|
|
|
|
CHREGRESS_LINEAR,
|
|
|
|
xRegressionCurveContainer,
|
|
|
|
comphelper::getProcessComponentContext());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
RegressionCurveHelper::removeAllExceptMeanValueLine(
|
|
|
|
xRegressionCurveContainer );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-07-16 22:12:03 +02:00
|
|
|
bool isErrorBarVisible(css::uno::Reference<css::frame::XModel>
|
|
|
|
xModel, const OUString& rCID, bool bYError)
|
|
|
|
{
|
|
|
|
css::uno::Reference< css::chart2::XDataSeries > xSeries(
|
|
|
|
ObjectIdentifier::getDataSeriesForCID(rCID, xModel), uno::UNO_QUERY );
|
|
|
|
|
|
|
|
if (!xSeries.is())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return StatisticsHelper::hasErrorBars(xSeries, bYError);
|
|
|
|
}
|
|
|
|
|
|
|
|
void setErrorBarVisible(css::uno::Reference<css::frame::XModel>
|
|
|
|
xModel, const OUString& rCID, bool bYError, bool bVisible)
|
|
|
|
{
|
|
|
|
css::uno::Reference< css::chart2::XDataSeries > xSeries(
|
|
|
|
ObjectIdentifier::getDataSeriesForCID(rCID, xModel), uno::UNO_QUERY );
|
|
|
|
|
|
|
|
if (!xSeries.is())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (bVisible)
|
|
|
|
{
|
|
|
|
StatisticsHelper::addErrorBars( xSeries, comphelper::getProcessComponentContext(),
|
|
|
|
css::chart::ErrorBarStyle::STANDARD_DEVIATION,
|
|
|
|
bYError);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
StatisticsHelper::removeErrorBars( xSeries, bYError );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-16 20:17:37 +02:00
|
|
|
}
|
|
|
|
|
2015-07-16 18:44:01 +02:00
|
|
|
ChartSeriesPanel::ChartSeriesPanel(
|
|
|
|
vcl::Window* pParent,
|
|
|
|
const css::uno::Reference<css::frame::XFrame>& rxFrame,
|
|
|
|
SfxBindings* pBindings,
|
|
|
|
ChartController* pController)
|
|
|
|
: PanelLayout(pParent, "ChartSeriesPanel", "modules/schart/ui/sidebarseries.ui", rxFrame),
|
|
|
|
mxFrame(rxFrame),
|
|
|
|
maContext(),
|
|
|
|
mpBindings(pBindings),
|
2015-07-16 22:00:26 +02:00
|
|
|
mxModel(pController->getModel()),
|
|
|
|
mxListener(new ChartSidebarModifyListener(this))
|
2015-07-16 18:44:01 +02:00
|
|
|
{
|
2015-07-16 20:17:37 +02:00
|
|
|
get(mpCBLabel, "checkbutton_label");
|
|
|
|
get(mpCBTrendline, "checkbutton_trendline");
|
|
|
|
get(mpCBXError, "checkbutton_x_error");
|
|
|
|
get(mpCBYError, "checkbutton_y_error");
|
|
|
|
|
2015-07-16 18:44:01 +02:00
|
|
|
Initialize();
|
|
|
|
}
|
|
|
|
|
|
|
|
ChartSeriesPanel::~ChartSeriesPanel()
|
|
|
|
{
|
|
|
|
disposeOnce();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChartSeriesPanel::dispose()
|
|
|
|
{
|
2015-07-16 22:00:26 +02:00
|
|
|
css::uno::Reference<css::util::XModifyBroadcaster> xBroadcaster(mxModel, css::uno::UNO_QUERY_THROW);
|
|
|
|
xBroadcaster->removeModifyListener(mxListener);
|
2015-07-16 18:44:01 +02:00
|
|
|
|
2015-07-16 22:01:57 +02:00
|
|
|
mpCBLabel.clear();
|
|
|
|
mpCBTrendline.clear();
|
|
|
|
mpCBXError.clear();
|
|
|
|
mpCBYError.clear();
|
|
|
|
|
2015-07-16 18:44:01 +02:00
|
|
|
PanelLayout::dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChartSeriesPanel::Initialize()
|
|
|
|
{
|
2015-07-16 22:00:26 +02:00
|
|
|
css::uno::Reference<css::util::XModifyBroadcaster> xBroadcaster(mxModel, css::uno::UNO_QUERY_THROW);
|
|
|
|
xBroadcaster->addModifyListener(mxListener);
|
|
|
|
|
2015-07-16 20:17:37 +02:00
|
|
|
updateData();
|
|
|
|
|
|
|
|
Link<> aLink = LINK(this, ChartSeriesPanel, CheckBoxHdl);
|
|
|
|
mpCBLabel->SetClickHdl(aLink);
|
|
|
|
mpCBTrendline->SetClickHdl(aLink);
|
|
|
|
mpCBXError->SetClickHdl(aLink);
|
|
|
|
mpCBYError->SetClickHdl(aLink);
|
2015-07-16 18:44:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ChartSeriesPanel::updateData()
|
|
|
|
{
|
2015-07-16 20:17:37 +02:00
|
|
|
css::uno::Reference<css::frame::XController> xController(mxModel->getCurrentController());
|
|
|
|
css::uno::Reference<css::view::XSelectionSupplier> xSelectionSupplier(xController, css::uno::UNO_QUERY);
|
|
|
|
if (!xSelectionSupplier.is())
|
|
|
|
return;
|
|
|
|
|
|
|
|
uno::Any aAny = xSelectionSupplier->getSelection();
|
|
|
|
assert(aAny.hasValue());
|
|
|
|
OUString aCID;
|
|
|
|
aAny >>= aCID;
|
|
|
|
#ifdef DBG_UTIL
|
|
|
|
ObjectType eType = ObjectIdentifier::getObjectType(aCID);
|
|
|
|
assert(eType == OBJECTTYPE_DATA_SERIES);
|
|
|
|
#endif
|
2015-07-16 18:44:01 +02:00
|
|
|
SolarMutexGuard aGuard;
|
2015-07-16 20:17:37 +02:00
|
|
|
mpCBLabel->Check(isDataLabelVisible(mxModel, aCID));
|
2015-07-16 21:15:31 +02:00
|
|
|
mpCBTrendline->Check(isTrendlineVisible(mxModel, aCID));
|
2015-07-16 22:12:03 +02:00
|
|
|
mpCBXError->Check(isErrorBarVisible(mxModel, aCID, false));
|
|
|
|
mpCBYError->Check(isErrorBarVisible(mxModel, aCID, true));
|
2015-07-16 18:44:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
VclPtr<vcl::Window> ChartSeriesPanel::Create (
|
|
|
|
vcl::Window* pParent,
|
|
|
|
const css::uno::Reference<css::frame::XFrame>& rxFrame,
|
|
|
|
SfxBindings* pBindings, ChartController* pController)
|
|
|
|
{
|
|
|
|
if (pParent == NULL)
|
|
|
|
throw lang::IllegalArgumentException("no parent Window given to ChartSeriesPanel::Create", NULL, 0);
|
|
|
|
if ( ! rxFrame.is())
|
|
|
|
throw lang::IllegalArgumentException("no XFrame given to ChartSeriesPanel::Create", NULL, 1);
|
|
|
|
if (pBindings == NULL)
|
|
|
|
throw lang::IllegalArgumentException("no SfxBindings given to ChartSeriesPanel::Create", NULL, 2);
|
|
|
|
|
|
|
|
return VclPtr<ChartSeriesPanel>::Create(
|
|
|
|
pParent, rxFrame, pBindings, pController);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChartSeriesPanel::DataChanged(
|
|
|
|
const DataChangedEvent& )
|
|
|
|
{
|
|
|
|
updateData();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChartSeriesPanel::HandleContextChange(
|
|
|
|
const ::sfx2::sidebar::EnumContext& rContext)
|
|
|
|
{
|
|
|
|
maContext = rContext;
|
|
|
|
updateData();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChartSeriesPanel::NotifyItemUpdate(
|
|
|
|
sal_uInt16 /*nSID*/,
|
|
|
|
SfxItemState /*eState*/,
|
|
|
|
const SfxPoolItem* /*pState*/,
|
|
|
|
const bool )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChartSeriesPanel::modelInvalid()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-07-16 20:17:37 +02:00
|
|
|
IMPL_LINK(ChartSeriesPanel, CheckBoxHdl, CheckBox*, pCheckBox)
|
|
|
|
{
|
|
|
|
bool bChecked = pCheckBox->IsChecked();
|
|
|
|
css::uno::Reference<css::frame::XController> xController(mxModel->getCurrentController());
|
|
|
|
css::uno::Reference<css::view::XSelectionSupplier> xSelectionSupplier(xController, css::uno::UNO_QUERY);
|
|
|
|
if (!xSelectionSupplier.is())
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
uno::Any aAny = xSelectionSupplier->getSelection();
|
|
|
|
assert(aAny.hasValue());
|
|
|
|
OUString aCID;
|
|
|
|
aAny >>= aCID;
|
|
|
|
#ifdef DBG_UTIL
|
|
|
|
ObjectType eType = ObjectIdentifier::getObjectType(aCID);
|
|
|
|
assert(eType == OBJECTTYPE_DATA_SERIES);
|
|
|
|
#endif
|
|
|
|
if (pCheckBox == mpCBLabel.get())
|
|
|
|
setDataLabelVisible(mxModel, aCID, bChecked);
|
2015-07-16 21:15:31 +02:00
|
|
|
else if (pCheckBox == mpCBTrendline.get())
|
|
|
|
setTrendlineVisible(mxModel, aCID, bChecked);
|
2015-07-16 22:12:03 +02:00
|
|
|
else if (pCheckBox == mpCBXError.get())
|
|
|
|
setErrorBarVisible(mxModel, aCID, false, bChecked);
|
|
|
|
else if (pCheckBox == mpCBYError.get())
|
|
|
|
setErrorBarVisible(mxModel, aCID, true, bChecked);
|
2015-07-16 20:17:37 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-07-16 18:44:01 +02:00
|
|
|
}} // end of namespace ::chart::sidebar
|
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|