LibreOffice Module chart2 (master) 1
tp_ChartType.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 "tp_ChartType.hxx"
22#include <ChartTypeManager.hxx>
23#include <strings.hrc>
24#include <ResId.hxx>
25#include <ChartModelHelper.hxx>
26#include <ChartModel.hxx>
27#include <ChartTypeTemplate.hxx>
28#include <DiagramHelper.hxx>
29#include <Diagram.hxx>
30#include <unonames.hxx>
31
32#include <svtools/valueset.hxx>
33
34#include <utility>
35#include <vcl/weld.hxx>
36#include <vcl/outdev.hxx>
38
39namespace chart
40{
41using namespace ::com::sun::star;
42using namespace ::com::sun::star::chart2;
43
45 bool bShowDescription)
46 : OWizardPage(pPage, pController, "modules/schart/ui/tp_ChartType.ui", "tp_ChartType")
47 , m_pDim3DLookResourceGroup( new Dim3DLookResourceGroup(m_xBuilder.get()) )
48 , m_pStackingResourceGroup( new StackingResourceGroup(m_xBuilder.get()) )
49 , m_pSplineResourceGroup( new SplineResourceGroup(m_xBuilder.get(), pController->getDialog()) )
50 , m_pGeometryResourceGroup( new GeometryResourceGroup(m_xBuilder.get()) )
51 , m_pSortByXValuesResourceGroup( new SortByXValuesResourceGroup(m_xBuilder.get()) )
52 , m_xChartModel(std::move( xChartModel ))
53 , m_aChartTypeDialogControllerList(0)
54 , m_pCurrentMainType(nullptr)
55 , m_nChangingCalls(0)
56 , m_aTimerTriggeredControllerLock( m_xChartModel )
57 , m_xFT_ChooseType(m_xBuilder->weld_label("FT_CAPTION_FOR_WIZARD"))
58 , m_xMainTypeList(m_xBuilder->weld_tree_view("charttype"))
59 , m_xSubTypeList(new ValueSet(m_xBuilder->weld_scrolled_window("subtypewin", true)))
60 , m_xSubTypeListWin(new weld::CustomWeld(*m_xBuilder, "subtype", *m_xSubTypeList))
61{
62 Size aSize(m_xSubTypeList->GetDrawingArea()->get_ref_device().LogicToPixel(Size(150, 50), MapMode(MapUnit::MapAppFont)));
63 m_xSubTypeListWin->set_size_request(aSize.Width(), aSize.Height());
64
65 if (bShowDescription)
66 {
67 m_xFT_ChooseType->show();
68 }
69 else
70 {
71 m_xFT_ChooseType->hide();
72 }
73
74 SetPageTitle(SchResId(STR_PAGE_CHARTTYPE));
75
76 m_xMainTypeList->connect_changed(LINK(this, ChartTypeTabPage, SelectMainTypeHdl));
77 m_xSubTypeList->SetSelectHdl( LINK( this, ChartTypeTabPage, SelectSubTypeHdl ) );
78
79 m_xSubTypeList->SetStyle(m_xSubTypeList->GetStyle() |
81 m_xSubTypeList->SetColCount(4);
82 m_xSubTypeList->SetLineCount(1);
83
84 bool bEnableComplexChartTypes = true;
85 uno::Reference< beans::XPropertySet > xProps( static_cast<cppu::OWeakObject*>(m_xChartModel.get()), uno::UNO_QUERY );
86 if ( xProps.is() )
87 {
88 try
89 {
90 xProps->getPropertyValue("EnableComplexChartTypes") >>= bEnableComplexChartTypes;
91 }
92 catch( const uno::Exception& )
93 {
94 TOOLS_WARN_EXCEPTION("chart2", "" );
95 }
96 }
97
98 m_aChartTypeDialogControllerList.push_back(std::make_unique<ColumnChartDialogController>());
99 m_aChartTypeDialogControllerList.push_back(std::make_unique<BarChartDialogController>());
100 m_aChartTypeDialogControllerList.push_back(std::make_unique<PieChartDialogController>());
101 m_aChartTypeDialogControllerList.push_back(std::make_unique<AreaChartDialogController>());
102 m_aChartTypeDialogControllerList.push_back(std::make_unique<LineChartDialogController>());
103 if (bEnableComplexChartTypes)
104 {
105 m_aChartTypeDialogControllerList.push_back(std::make_unique<XYChartDialogController>());
107 std::make_unique<BubbleChartDialogController>());
108 }
109 m_aChartTypeDialogControllerList.push_back(std::make_unique<NetChartDialogController>());
110 if (bEnableComplexChartTypes)
111 {
112 m_aChartTypeDialogControllerList.push_back(std::make_unique<StockChartDialogController>());
113 }
115 std::make_unique<CombiColumnLineChartDialogController>());
116
117 for (auto const& elem : m_aChartTypeDialogControllerList)
118 {
119 m_xMainTypeList->append("", elem->getName(), elem->getImage());
120 elem->setChangeListener( this );
121 }
122
123 m_xMainTypeList->set_size_request(m_xMainTypeList->get_preferred_size().Width(), -1);
124
125 m_pDim3DLookResourceGroup->setChangeListener( this );
126 m_pStackingResourceGroup->setChangeListener( this );
127 m_pSplineResourceGroup->setChangeListener( this );
128 m_pGeometryResourceGroup->setChangeListener( this );
129 m_pSortByXValuesResourceGroup->setChangeListener( this );
130}
131
133{
134 //delete all dialog controller
136
137 //delete all resource helper
143 m_xSubTypeListWin.reset();
144 m_xSubTypeList.reset();
145}
146
148{
149 ChartTypeParameter aParameter;
150 aParameter.nSubTypeIndex = static_cast<sal_Int32>(m_xSubTypeList->GetSelectedItemId());
151 m_pDim3DLookResourceGroup->fillParameter( aParameter );
152 m_pStackingResourceGroup->fillParameter( aParameter );
153 m_pSplineResourceGroup->fillParameter( aParameter );
154 m_pGeometryResourceGroup->fillParameter( aParameter );
155 m_pSortByXValuesResourceGroup->fillParameter( aParameter );
156 return aParameter;
157}
158
160{
161 if( !m_pCurrentMainType )
162 return;
163
166}
167
169{
171 return;
173
176 {
179 }
180 commitToModel( aParameter );
181
182 //detect the new ThreeDLookScheme
183 rtl::Reference< Diagram > xDiagram = m_xChartModel->getFirstChartDiagram();
184 // tdf#124295 - select always a 3D scheme
185 if (ThreeDLookScheme aThreeDLookScheme = xDiagram->detectScheme();
187 aParameter.eThreeDLookScheme = aThreeDLookScheme;
188
189 try
190 {
191 xDiagram->getPropertyValue(CHART_UNONAME_SORT_BY_XVALUES) >>= aParameter.bSortByXValues;
192 }
193 catch ( const uno::Exception& )
194 {
195 DBG_UNHANDLED_EXCEPTION("chart2");
196 }
197 //the controls have to be enabled/disabled accordingly
198 fillAllControls( aParameter );
199
201}
202
204{
205 ChartTypeDialogController* pTypeController = nullptr;
206 auto nM = static_cast< std::vector< ChartTypeDialogController* >::size_type >(
207 m_xMainTypeList->get_selected_index() );
209 pTypeController = m_aChartTypeDialogControllerList[nM].get();
210 return pTypeController;
211}
212
213IMPL_LINK_NOARG(ChartTypeTabPage, SelectSubTypeHdl, ValueSet*, void)
214{
215 if( m_pCurrentMainType )
216 {
217 ChartTypeParameter aParameter( getCurrentParamter() );
218 m_pCurrentMainType->adjustParameterToSubType( aParameter );
219 fillAllControls( aParameter, false );
220 commitToModel( aParameter );
221 }
222}
223
225{
226 selectMainType();
227}
228
230{
232
234 {
237 }
238
240 if( !m_pCurrentMainType )
241 return;
242
244
246 commitToModel( aParameter );
247 //detect the new ThreeDLookScheme
249 rtl::Reference< Diagram > xDiagram = m_xChartModel->getFirstChartDiagram();
250 if (xDiagram)
251 aParameter.eThreeDLookScheme = m_xChartModel->getFirstChartDiagram()->detectScheme();
252 if (!aParameter.b3DLook
255
256 try
257 {
258 if (xDiagram)
259 xDiagram->getPropertyValue(CHART_UNONAME_SORT_BY_XVALUES) >>= aParameter.bSortByXValues;
260 }
261 catch ( const uno::Exception& )
262 {
263 DBG_UNHANDLED_EXCEPTION("chart2");
264 }
265
266 fillAllControls( aParameter );
267 uno::Reference< beans::XPropertySet > xTemplateProps( static_cast<cppu::OWeakObject*>(getCurrentTemplate().get()), uno::UNO_QUERY );
269}
270
272{
273 m_xMainTypeList->show();
274 m_xSubTypeList->Show();
275
276 bool bShow = rTypeController.shouldShow_3DLookControl();
277 m_pDim3DLookResourceGroup->showControls( bShow );
278 bShow = rTypeController.shouldShow_StackingControl();
279 m_pStackingResourceGroup->showControls( bShow );
280 bShow = rTypeController.shouldShow_SplineControl();
281 m_pSplineResourceGroup->showControls( bShow );
282 bShow = rTypeController.shouldShow_GeometryControl();
283 m_pGeometryResourceGroup->showControls( bShow );
284 bShow = rTypeController.shouldShow_SortByXValuesResourceGroup();
285 m_pSortByXValuesResourceGroup->showControls( bShow );
286 rTypeController.showExtraControls(m_xBuilder.get());
287}
288
289void ChartTypeTabPage::fillAllControls( const ChartTypeParameter& rParameter, bool bAlsoResetSubTypeList )
290{
292 if( m_pCurrentMainType && bAlsoResetSubTypeList )
293 {
295 }
296 m_xSubTypeList->SelectItem( static_cast<sal_uInt16>( rParameter.nSubTypeIndex) );
297 m_pDim3DLookResourceGroup->fillControls( rParameter );
298 m_pStackingResourceGroup->fillControls( rParameter );
299 m_pSplineResourceGroup->fillControls( rParameter );
300 m_pGeometryResourceGroup->fillControls( rParameter );
301 m_pSortByXValuesResourceGroup->fillControls( rParameter );
303}
304
306{
307 if( !m_xChartModel.is() )
308 return;
309 rtl::Reference< ::chart::ChartTypeManager > xChartTypeManager = m_xChartModel->getTypeManager();
310 rtl::Reference< Diagram > xDiagram = m_xChartModel->getFirstChartDiagram();
312 if (xDiagram)
313 aTemplate = xDiagram->getTemplate( xChartTypeManager );
314 OUString aServiceName( aTemplate.sServiceName );
315
316 bool bFound = false;
317
318 sal_uInt16 nM=0;
319 for (auto const& elem : m_aChartTypeDialogControllerList)
320 {
321 if( elem->isSubType(aServiceName) )
322 {
323 bFound = true;
324
325 m_xMainTypeList->select(nM);
326 showAllControls(*elem);
327 uno::Reference< beans::XPropertySet > xTemplateProps( static_cast<cppu::OWeakObject*>(aTemplate.xChartTypeTemplate.get()), uno::UNO_QUERY );
328 ChartTypeParameter aParameter = elem->getChartTypeParameterForService( aServiceName, xTemplateProps );
330
331 //set ThreeDLookScheme
332 aParameter.eThreeDLookScheme = xDiagram->detectScheme();
333 if (!aParameter.b3DLook
336
337 try
338 {
339 xDiagram->getPropertyValue(CHART_UNONAME_SORT_BY_XVALUES) >>= aParameter.bSortByXValues;
340 }
341 catch (const uno::Exception&)
342 {
343 DBG_UNHANDLED_EXCEPTION("chart2");
344 }
345
346 fillAllControls( aParameter );
349 break;
350 }
351 ++nM;
352 }
353
354 if( !bFound )
355 {
356 m_xMainTypeList->show();
357 m_xSubTypeList->Show();
358 m_pDim3DLookResourceGroup->showControls( false );
359 m_pStackingResourceGroup->showControls( false );
360 m_pSplineResourceGroup->showControls( false );
361 m_pGeometryResourceGroup->showControls( false );
362 m_pSortByXValuesResourceGroup->showControls( false );
363 }
364}
365
367{
368 return true; // return false if this page should not be left
369}
370
372{
374 {
377 rtl::Reference< ::chart::ChartTypeManager > xChartTypeManager = m_xChartModel->getTypeManager();
378 return m_pCurrentMainType->getCurrentTemplate( aParameter, xChartTypeManager );
379 }
380 return nullptr;
381}
382
383} //namespace chart
384
385/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void SetPageTitle(const OUString &rPageTitle)
std::unique_ptr< weld::Builder > m_xBuilder
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)
std::unique_ptr< Dim3DLookResourceGroup > m_pDim3DLookResourceGroup
std::unique_ptr< GeometryResourceGroup > m_pGeometryResourceGroup
std::unique_ptr< weld::CustomWeld > m_xSubTypeListWin
virtual ~ChartTypeTabPage() override
rtl::Reference<::chart::ChartModel > m_xChartModel
void commitToModel(const ChartTypeParameter &rParameter)
void fillAllControls(const ChartTypeParameter &rParameter, bool bAlsoResetSubTypeList=true)
std::unique_ptr< SplineResourceGroup > m_pSplineResourceGroup
virtual void initializePage() override
std::unique_ptr< SortByXValuesResourceGroup > m_pSortByXValuesResourceGroup
std::unique_ptr< ValueSet > m_xSubTypeList
virtual void stateChanged() override
ChartTypeParameter getCurrentParamter() const
std::unique_ptr< weld::TreeView > m_xMainTypeList
virtual bool commitPage(::vcl::WizardTypes::CommitPageReason eReason) override
std::vector< std::unique_ptr< ChartTypeDialogController > > m_aChartTypeDialogControllerList
virtual rtl::Reference< ::chart::ChartTypeTemplate > getCurrentTemplate() const override
ChartTypeDialogController * m_pCurrentMainType
std::unique_ptr< StackingResourceGroup > m_pStackingResourceGroup
ChartTypeTabPage(weld::Container *pPage, weld::DialogController *pController, rtl::Reference<::chart::ChartModel > xChartModel, bool bShowDescription=true)
void showAllControls(ChartTypeDialogController &rTypeController)
TimerTriggeredControllerLock m_aTimerTriggeredControllerLock
ChartTypeDialogController * getSelectedMainType()
std::unique_ptr< weld::Label > m_xFT_ChooseType
#define TOOLS_WARN_EXCEPTION(area, stream)
#define DBG_UNHANDLED_EXCEPTION(...)
ThreeDLookScheme
OUString OOO_DLLPUBLIC_CHARTTOOLS SchResId(TranslateId aId)
Definition: ResId.cxx:24
IMPL_LINK_NOARG(SplinePropertiesDialog, SplineTypeListBoxHdl, 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
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