Help regarding correct way of accessing UI change in model for Histogram Calculation [PR - 170909]
Devansh Varshney
varshney.devansh614 at gmail.com
Sun Nov 3 14:51:49 UTC 2024
[Part of Adding Histogram support to LO GSoC-2024]
Hi,
I have been holding this mail for the past four days and am looking for the
correct way to access the UI input from the sidebar of the chart type
selection.
How do I approach accessing UI changes done by the user for the custom bin
in the model? *Related PR* - *https://gerrit.libreoffice.org/c/core/+/170909
<https://gerrit.libreoffice.org/c/core/+/170909>*
*(I am also following Kurt's PR closely* -
*https://gerrit.libreoffice.org/c/core/+/174301*
<https://gerrit.libreoffice.org/c/core/+/174301>*)*
>From the controller
*chart2/source/controller/dialogs/ChartTypeDialogController.cxx*
we are registering the changes from the UI to the model template via the
void HistogramChartDialogController::setTemplateProperties(const css::uno::
Reference<css::beans::XPropertySet>& xTemplateProps) const
In the *chart2/source/model/template/HistogramChartTypeTemplate.cxx*
I have added the -
void HistogramChartTypeTemplate::createChartTypes(
const std::vector<std::vector<rtl::Reference<DataSeries>>>& aSeriesSeq,
const std::vector<rtl::Reference<BaseCoordinateSystem>>& rCoordSys,
const std::vector<rtl::Reference<ChartType>>& /* aOldChartTypesSeq */)
{
if (rCoordSys.empty())
return;
try
{
// Step 1: Create and configure a new HistogramChartType instance
rtl::Reference<ChartType> xCT = new HistogramChartType();
xCT->setFastPropertyValue(PROP_HISTOGRAMCHARTTYPE_BINCOUNT,
getFastPropertyValue(PROP_HISTOGRAM_TEMPLATE_BINCOUNT));
xCT->setFastPropertyValue(PROP_HISTOGRAMCHARTTYPE_BINWIDTH,
getFastPropertyValue(PROP_HISTOGRAM_TEMPLATE_BINWIDTH));
xCT->setFastPropertyValue(PROP_HISTOGRAMCHARTTYPE_FREQUENCYTYPE,
getFastPropertyValue(PROP_HISTOGRAM_TEMPLATE_FREQUENCYTYPE));
xCT->setFastPropertyValue(PROP_HISTOGRAMCHARTTYPE_OVERFLOWBIN,
getFastPropertyValue(PROP_HISTOGRAM_TEMPLATE_OVERFLOWBIN));
xCT->setFastPropertyValue(PROP_HISTOGRAMCHARTTYPE_UNDERFLOWBIN,
getFastPropertyValue(PROP_HISTOGRAM_TEMPLATE_UNDERFLOWBIN));
xCT->setFastPropertyValue(PROP_HISTOGRAMCHARTTYPE_OVERFLOWBIN_VALUE,
getFastPropertyValue(PROP_HISTOGRAM_TEMPLATE_OVERFLOWBIN_VALUE));
xCT->setFastPropertyValue(PROP_HISTOGRAMCHARTTYPE_UNDERFLOWBIN_VALUE,
getFastPropertyValue(PROP_HISTOGRAM_TEMPLATE_UNDERFLOWBIN_VALUE));
// // Sync the properties to the internal variables in HistogramChartType
// rtl::Reference<css::beans::XPropertySet> xTemplateProps =
this->getPropertySetInfo();
// static_cast<HistogramChartType*>(xCT.get())->syncWithTemplate(this);
// Step 2: Add the configured HistogramChartType to the coordinate system
rCoordSys[0]->setChartTypes(std::vector{ xCT });
// Step 3: Set Data Series and Perform Calculations if Series is Available
if (!aSeriesSeq.empty())
{
// For histogram, we typically use only the first series
xCT->setDataSeries(aSeriesSeq[0]);
// Call createCalculatedDataSeries to process the data
static_cast<HistogramChartType*>(xCT.get())->createCalculatedDataSeries();
}
}
catch (const uno::Exception&)
{
DBG_UNHANDLED_EXCEPTION("chart2");
}
}
However, I am unsure if this is the correct way of calling the
*createCalculatedDataSeries()* in the model file -
*chart2/source/model/template/HistogramChartType.cxx*
So that, this will eventually call the
*chart2/source/model/template/HistogramCalculator.cxx* to calculate the
binning.
tho in the model *chart2/source/model/template/HistogramChartType.cxx*
I have also added the -
sal_Int8 getFrequencyType() const { return m_nFrequencyType; }
sal_Int32 getBinCount() const { return m_nBinCount; }
double getBinWidth() const { return m_fBinWidth; }
bool isOverflowBinActive() const { return m_bOverflowBinActive; }
bool isUnderflowBinActive() const { return m_bUnderflowBinActive; }
double getOverflowValue() const { return m_fOverflowValue; }
double getUnderflowValue() const { return m_fUnderflowValue; }
void setFrequencyType(sal_Int8 nFrequencyType);
void setBinCount(sal_Int32 nBinCount);
void setBinWidth(double fBinWidth);
void setOverflowBinActive(bool bActive);
void setUnderflowBinActive(bool bActive);
void setOverflowBinValue(double fValue);
void setUnderflowBinValue(double fValue);
void syncWithTemplate(const css::uno::Reference<css::beans::XPropertySet>&
xTemplateProps);
But I am not sure about these getter and setter functions.
I have not modified the
*chart2/source/model/template/HistogramCalculator.cxx* to use these new
parameters set in the UI
as I am unsure of what I have done to have access to the ui parameters.
I also tried to access them in the view too -
HistogramChart::HistogramChart(const rtl::Reference<ChartType>&
xChartTypeModel,
sal_Int32 nDimensionCount)
: BarChart(xChartTypeModel, nDimensionCount)
, m_nBinCount(1)
, m_fBinWidth(1.0)
, m_nFrequencyType(0)
, m_bOverflowBinActive(false)
, m_bUnderflowBinActive(false)
{
// We only support 2 dimensional histogram charts
assert(nDimensionCount == 2 && "HistogramChart only supports 2D charts");
// Runtime check for all builds
if (nDimensionCount != 2)
{
// Log a warning or throw an exception if appropriate
SAL_WARN("chart2", "HistogramChart created with invalid dimension count.
Forcing 2D.");
}
PlotterBase::m_pPosHelper = &m_aMainPosHelper;
VSeriesPlotter::m_pMainPosHelper = &m_aMainPosHelper;
try
{
if (m_xChartTypeModel.is())
m_xChartTypeModel->getPropertyValue(u"GapwidthSequence"_ustr) >>=
m_aGapwidthSequence;
}
catch (const uno::Exception&)
{
TOOLS_WARN_EXCEPTION("chart2", "");
}
try
{
if (m_xChartTypeModel.is())
m_xChartTypeModel->getPropertyValue(u"BinCount"_ustr) >>= m_nBinCount;
}
catch (const uno::Exception&)
{
TOOLS_WARN_EXCEPTION("chart2", "");
}
try
{
if (m_xChartTypeModel.is())
m_xChartTypeModel->getPropertyValue(u"BinWidth"_ustr) >>= m_fBinWidth;
}
catch (const uno::Exception&)
{
TOOLS_WARN_EXCEPTION("chart2", "");
}
try
{
if (m_xChartTypeModel.is())
m_xChartTypeModel->getPropertyValue(u"FrequencyType"_ustr) >>=
m_nFrequencyType;
}
catch (const uno::Exception&)
{
TOOLS_WARN_EXCEPTION("chart2", "");
}
try
{
if (m_xChartTypeModel.is())
m_xChartTypeModel->getPropertyValue(u"OverflowBin"_ustr) >>=
m_bOverflowBinActive;
}
catch (const uno::Exception&)
{
TOOLS_WARN_EXCEPTION("chart2", "");
}
try
{
if (m_xChartTypeModel.is())
m_xChartTypeModel->getPropertyValue(u"UnderflowBin"_ustr) >>=
m_bUnderflowBinActive;
}
catch (const uno::Exception&)
{
TOOLS_WARN_EXCEPTION("chart2", "");
}
}
*But we want to do it in the model as per the comment(commit message) made
by Tomaž in the PR - https://gerrit.libreoffice.org/c/core/+/171952
<https://gerrit.libreoffice.org/c/core/+/171952>*
--
*Regards,*
*Devansh*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/libreoffice/attachments/20241103/a5db3e0d/attachment.htm>
More information about the LibreOffice
mailing list