LibreOffice Module chart2 (master) 1
ChartTypePanel.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#include "ChartTypePanel.hxx"
22
23#include <ChartController.hxx>
24#include <ChartModelHelper.hxx>
25#include <ChartModel.hxx>
28#include <ChartTypeManager.hxx>
29#include <ChartTypeTemplate.hxx>
30#include <DiagramHelper.hxx>
31#include <Diagram.hxx>
32#include <unonames.hxx>
33
34#include <svtools/valueset.hxx>
36
37using namespace css;
38using namespace css::uno;
39
40namespace chart::sidebar
41{
43 : PanelLayout(pParent, "ChartTypePanel", "modules/schart/ui/sidebartype.ui")
45 , mbModelValid(true)
46 , m_pDim3DLookResourceGroup(new Dim3DLookResourceGroup(m_xBuilder.get()))
47 , m_pStackingResourceGroup(new StackingResourceGroup(m_xBuilder.get()))
48 , m_pSplineResourceGroup(
49 new SplineResourceGroup(m_xBuilder.get(), pController->GetChartFrame()))
50 , m_pGeometryResourceGroup(new GeometryResourceGroup(m_xBuilder.get()))
51 , m_pSortByXValuesResourceGroup(new SortByXValuesResourceGroup(m_xBuilder.get()))
52 , m_xChartModel(pController->getChartModel())
53 , m_aChartTypeDialogControllerList(0)
54 , m_pCurrentMainType(nullptr)
55 , m_nChangingCalls(0)
56 , m_aTimerTriggeredControllerLock(m_xChartModel)
57 , m_xMainTypeList(m_xBuilder->weld_combo_box("cmb_chartType"))
58 , m_xSubTypeList(new ValueSet(m_xBuilder->weld_scrolled_window("subtypewin", true)))
59 , m_xSubTypeListWin(new weld::CustomWeld(*m_xBuilder, "subtype", *m_xSubTypeList))
60{
61 Size aSize(m_xSubTypeList->GetDrawingArea()->get_ref_device().LogicToPixel(
62 Size(120, 40), MapMode(MapUnit::MapAppFont)));
63 m_xSubTypeListWin->set_size_request(aSize.Width(), aSize.Height());
64
65 m_xMainTypeList->connect_changed(LINK(this, ChartTypePanel, SelectMainTypeHdl));
66 m_xSubTypeList->SetSelectHdl(LINK(this, ChartTypePanel, SelectSubTypeHdl));
67
70 m_xSubTypeList->SetColCount(4);
71 m_xSubTypeList->SetLineCount(1);
72
73 bool bEnableComplexChartTypes = true;
75 uno::UNO_QUERY);
76 if (xProps.is())
77 {
78 try
79 {
80 xProps->getPropertyValue("EnableComplexChartTypes") >>= bEnableComplexChartTypes;
81 }
82 catch (const uno::Exception&)
83 {
84 TOOLS_WARN_EXCEPTION("chart2", "");
85 }
86 }
87
88 m_aChartTypeDialogControllerList.push_back(std::make_unique<ColumnChartDialogController>());
89 m_aChartTypeDialogControllerList.push_back(std::make_unique<BarChartDialogController>());
90 m_aChartTypeDialogControllerList.push_back(std::make_unique<PieChartDialogController>());
91 m_aChartTypeDialogControllerList.push_back(std::make_unique<AreaChartDialogController>());
92 m_aChartTypeDialogControllerList.push_back(std::make_unique<LineChartDialogController>());
93 if (bEnableComplexChartTypes)
94 {
95 m_aChartTypeDialogControllerList.push_back(std::make_unique<XYChartDialogController>());
96 m_aChartTypeDialogControllerList.push_back(std::make_unique<BubbleChartDialogController>());
97 }
98 m_aChartTypeDialogControllerList.push_back(std::make_unique<NetChartDialogController>());
99 if (bEnableComplexChartTypes)
100 {
101 m_aChartTypeDialogControllerList.push_back(std::make_unique<StockChartDialogController>());
102 }
104 std::make_unique<CombiColumnLineChartDialogController>());
105
106 for (auto const& elem : m_aChartTypeDialogControllerList)
107 {
108 m_xMainTypeList->append("", elem->getName(), elem->getImage());
109 elem->setChangeListener(this);
110 }
111
112 m_pDim3DLookResourceGroup->setChangeListener(this);
113 m_pStackingResourceGroup->setChangeListener(this);
114 m_pSplineResourceGroup->setChangeListener(this);
115 m_pGeometryResourceGroup->setChangeListener(this);
116 m_pSortByXValuesResourceGroup->setChangeListener(this);
117
118 Initialize();
119}
120
122{
123 doUpdateModel(nullptr);
124
125 //delete all dialog controller
127
128 //delete all resource helpers
134 m_xSubTypeListWin.reset();
135 m_xSubTypeList.reset();
136
137 m_xSubTypeListWin.reset();
138 m_xSubTypeList.reset();
139 m_xMainTypeList.reset();
140}
141
142IMPL_LINK_NOARG(ChartTypePanel, SelectMainTypeHdl, weld::ComboBox&, void) { selectMainType(); }
143
144IMPL_LINK_NOARG(ChartTypePanel, SelectSubTypeHdl, ValueSet*, void)
145{
146 if (m_pCurrentMainType)
147 {
148 ChartTypeParameter aParameter(getCurrentParameter());
149 m_pCurrentMainType->adjustParameterToSubType(aParameter);
150 fillAllControls(aParameter, false);
151 commitToModel(aParameter);
152 }
153}
154
156{
157 if (!m_xChartModel.is())
158 return;
159 rtl::Reference<::chart::ChartTypeManager> xChartTypeManager = m_xChartModel->getTypeManager();
160 rtl::Reference<Diagram> xDiagram = m_xChartModel->getFirstChartDiagram();
162 if (xDiagram)
163 aTemplate = xDiagram->getTemplate(xChartTypeManager);
164 OUString aServiceName(aTemplate.sServiceName);
165
166 bool bFound = false;
167
168 sal_uInt16 nM = 0;
169 for (auto const& elem : m_aChartTypeDialogControllerList)
170 {
171 if (elem->isSubType(aServiceName))
172 {
173 bFound = true;
174
175 m_xMainTypeList->set_active(nM);
176 showAllControls(*elem);
178 static_cast<cppu::OWeakObject*>(aTemplate.xChartTypeTemplate.get()),
179 uno::UNO_QUERY);
180 ChartTypeParameter aParameter
181 = elem->getChartTypeParameterForService(aServiceName, xTemplateProps);
183
184 //set ThreeDLookScheme
185 aParameter.eThreeDLookScheme = xDiagram->detectScheme();
186 if (!aParameter.b3DLook
189
190 try
191 {
192 xDiagram->getPropertyValue(CHART_UNONAME_SORT_BY_XVALUES)
193 >>= aParameter.bSortByXValues;
194 }
195 catch (const uno::Exception&)
196 {
197 DBG_UNHANDLED_EXCEPTION("chart2");
198 }
199
200 fillAllControls(aParameter);
203 break;
204 }
205 ++nM;
206 }
207
208 if (!bFound)
209 {
210 m_xSubTypeList->Hide();
211 m_pDim3DLookResourceGroup->showControls(false);
212 m_pStackingResourceGroup->showControls(false);
213 m_pSplineResourceGroup->showControls(false);
214 m_pGeometryResourceGroup->showControls(false);
215 m_pSortByXValuesResourceGroup->showControls(false);
216 }
217}
218
220{
221 // Chart Type related
222 if (!m_xChartModel.is())
223 return;
224 rtl::Reference<::chart::ChartTypeManager> xChartTypeManager = m_xChartModel->getTypeManager();
225 rtl::Reference<Diagram> xDiagram = m_xChartModel->getFirstChartDiagram();
227 if (xDiagram)
228 aTemplate = xDiagram->getTemplate(xChartTypeManager);
229 OUString aServiceName(aTemplate.sServiceName);
230
231 //sal_uInt16 nM = 0;
232 for (auto const& elem : m_aChartTypeDialogControllerList)
233 {
234 if (elem->isSubType(aServiceName))
235 {
236 //m_pMainTypeList->SelectEntryPos(nM);
237 //m_pMainTypeList->select_entry_region(nM, nM);
238 break;
239 }
240 //++nM;
241 }
242}
243
245{
247 updateData();
248}
249
251{
252 if (maContext == rContext)
253 {
254 // Nothing to do.
255 return;
256 }
257
258 maContext = rContext;
259 updateData();
260}
261
263
265{
266 if (mbModelValid)
267 {
268 m_xChartModel->removeModifyListener(mxListener);
269 }
270
273
274 if (!mbModelValid)
275 return;
276
277 m_xChartModel->addModifyListener(mxListener);
278}
279
280void ChartTypePanel::updateModel(css::uno::Reference<css::frame::XModel> xModel)
281{
282 ::chart::ChartModel* pModel = dynamic_cast<::chart::ChartModel*>(xModel.get());
283 assert(!xModel || pModel);
284 doUpdateModel(pModel);
285}
286
288{
290 {
294 = m_xChartModel->getTypeManager();
295 return m_pCurrentMainType->getCurrentTemplate(aParameter, xChartTypeManager);
296 }
297 return nullptr;
298}
299
301{
302 ChartTypeDialogController* pTypeController = nullptr;
303 auto nM = static_cast<std::vector<ChartTypeDialogController*>::size_type>(
304 m_xMainTypeList->get_active());
305 if (nM < m_aChartTypeDialogControllerList.size())
306 pTypeController = m_aChartTypeDialogControllerList[nM].get();
307 return pTypeController;
308}
309
311{
312 m_xMainTypeList->show();
313 m_xSubTypeList->Show();
314
315 bool bShow = rTypeController.shouldShow_3DLookControl();
316 m_pDim3DLookResourceGroup->showControls(bShow);
317 bShow = rTypeController.shouldShow_StackingControl();
318 m_pStackingResourceGroup->showControls(bShow);
319 bShow = rTypeController.shouldShow_SplineControl();
320 m_pSplineResourceGroup->showControls(bShow);
321 bShow = rTypeController.shouldShow_GeometryControl();
322 m_pGeometryResourceGroup->showControls(bShow);
323 bShow = rTypeController.shouldShow_SortByXValuesResourceGroup();
324 m_pSortByXValuesResourceGroup->showControls(bShow);
325 rTypeController.showExtraControls(m_xBuilder.get());
326}
327
329 bool bAlsoResetSubTypeList)
330{
332 if (m_pCurrentMainType && bAlsoResetSubTypeList)
333 {
335 }
336 m_xSubTypeList->SelectItem(static_cast<sal_uInt16>(rParameter.nSubTypeIndex));
337 m_pDim3DLookResourceGroup->fillControls(rParameter);
338 m_pStackingResourceGroup->fillControls(rParameter);
339 m_pSplineResourceGroup->fillControls(rParameter);
340 m_pGeometryResourceGroup->fillControls(rParameter);
341 m_pSortByXValuesResourceGroup->fillControls(rParameter);
343}
344
346{
347 ChartTypeParameter aParameter;
348 aParameter.nSubTypeIndex = static_cast<sal_Int32>(m_xSubTypeList->GetSelectedItemId());
349 m_pDim3DLookResourceGroup->fillParameter(aParameter);
350 m_pStackingResourceGroup->fillParameter(aParameter);
351 m_pSplineResourceGroup->fillParameter(aParameter);
352 m_pGeometryResourceGroup->fillParameter(aParameter);
353 m_pSortByXValuesResourceGroup->fillParameter(aParameter);
354 return aParameter;
355}
356
358{
360 return;
362
365 {
368 }
369 commitToModel(aParameter);
370
371 //detect the new ThreeDLookScheme
372 rtl::Reference<Diagram> xDiagram = m_xChartModel->getFirstChartDiagram();
373 aParameter.eThreeDLookScheme = xDiagram->detectScheme();
374 try
375 {
376 xDiagram->getPropertyValue(CHART_UNONAME_SORT_BY_XVALUES) >>= aParameter.bSortByXValues;
377 }
378 catch (const uno::Exception&)
379 {
380 DBG_UNHANDLED_EXCEPTION("chart2");
381 }
382 //the controls have to be enabled/disabled accordingly
383 fillAllControls(aParameter);
384
386}
387
389{
391 return;
392
395}
396
398{
400
402 {
405 }
406
409 return;
410
412
414 commitToModel(aParameter);
415 //detect the new ThreeDLookScheme
416 aParameter.eThreeDLookScheme = m_xChartModel->getFirstChartDiagram()->detectScheme();
417 if (!aParameter.b3DLook
420
421 rtl::Reference<Diagram> xDiagram = m_xChartModel->getFirstChartDiagram();
422 try
423 {
424 xDiagram->getPropertyValue(CHART_UNONAME_SORT_BY_XVALUES) >>= aParameter.bSortByXValues;
425 }
426 catch (const uno::Exception&)
427 {
428 DBG_UNHANDLED_EXCEPTION("chart2");
429 }
430
431 fillAllControls(aParameter);
433 static_cast<cppu::OWeakObject*>(getCurrentTemplate().get()), uno::UNO_QUERY);
435}
436} // end of namespace ::chart::sidebar
437
438/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::unique_ptr< weld::Builder > m_xBuilder
virtual void DataChanged(const DataChangedEvent &rEvent)
constexpr tools::Long Height() const
constexpr tools::Long Width() const
virtual void fillExtraControls(const rtl::Reference<::chart::ChartModel > &xChartModel, const css::uno::Reference< css::beans::XPropertySet > &xTemplateProps) const
virtual void fillSubTypeList(ValueSet &rSubTypeList, const ChartTypeParameter &rParameter)
void commitToModel(const ChartTypeParameter &rParameter, const rtl::Reference<::chart::ChartModel > &xChartModel)
virtual bool shouldShow_SortByXValuesResourceGroup() const
rtl::Reference<::chart::ChartTypeTemplate > getCurrentTemplate(const ChartTypeParameter &rParameter, const rtl::Reference<::chart::ChartTypeManager > &xTemplateManager) const
virtual void showExtraControls(weld::Builder *pBuilder)
virtual void adjustParameterToSubType(ChartTypeParameter &rParameter)
virtual void adjustSubTypeAndEnableControls(ChartTypeParameter &rParameter)
virtual void adjustParameterToMainType(ChartTypeParameter &rParameter)
void commitToModel(const ChartTypeParameter &rParameter)
virtual ~ChartTypePanel() override
void showAllControls(ChartTypeDialogController &rTypeController)
TimerTriggeredControllerLock m_aTimerTriggeredControllerLock
virtual void stateChanged() override
ChartTypeDialogController * m_pCurrentMainType
ChartTypePanel(weld::Widget *pParent, ::chart::ChartController *pController)
ChartTypeParameter getCurrentParameter() const
std::unique_ptr< ValueSet > m_xSubTypeList
virtual void updateData() override
std::unique_ptr< weld::ComboBox > m_xMainTypeList
virtual void HandleContextChange(const vcl::EnumContext &rContext) override
void fillAllControls(const ChartTypeParameter &rParameter, bool bAlsoResetSubTypeList=true)
std::unique_ptr< SplineResourceGroup > m_pSplineResourceGroup
virtual void DataChanged(const DataChangedEvent &rEvent) override
ChartTypeDialogController * getSelectedMainType()
std::vector< std::unique_ptr< ChartTypeDialogController > > m_aChartTypeDialogControllerList
virtual rtl::Reference<::chart::ChartTypeTemplate > getCurrentTemplate() const override
std::unique_ptr< weld::CustomWeld > m_xSubTypeListWin
rtl::Reference<::chart::ChartModel > m_xChartModel
std::unique_ptr< SortByXValuesResourceGroup > m_pSortByXValuesResourceGroup
css::uno::Reference< css::util::XModifyListener > mxListener
std::unique_ptr< GeometryResourceGroup > m_pGeometryResourceGroup
virtual void updateModel(css::uno::Reference< css::frame::XModel > xModel) override
void doUpdateModel(rtl::Reference<::chart::ChartModel > xModel)
std::unique_ptr< Dim3DLookResourceGroup > m_pDim3DLookResourceGroup
virtual void modelInvalid() override
std::unique_ptr< StackingResourceGroup > m_pStackingResourceGroup
#define TOOLS_WARN_EXCEPTION(area, stream)
#define DBG_UNHANDLED_EXCEPTION(...)
Reference< script::XScriptListener > mxListener
IMPL_LINK_NOARG(ChartAxisPanel, ListBoxHdl, weld::ComboBox &, void)
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
rtl::Reference< ::chart::ChartTypeTemplate > xChartTypeTemplate
Definition: Diagram.hxx:314
Reference< XModel > xModel
constexpr OUStringLiteral CHART_UNONAME_SORT_BY_XVALUES
Definition: unonames.hxx:14
#define WB_FLATVALUESET
#define WB_ITEMBORDER
#define WB_DOUBLEBORDER
#define WB_NAMEFIELD
WinBits const WB_3DLOOK