LibreOffice Module chart2 (master) 1
dlg_DataSource.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 <com/sun/star/chart2/XChartDocument.hpp>
21
22#include <dlg_DataSource.hxx>
24#include <ChartTypeTemplate.hxx>
25#include <Diagram.hxx>
26#include <DiagramHelper.hxx>
27#include "DialogModel.hxx"
28#include <ChartModel.hxx>
29
30#include "tp_RangeChooser.hxx"
31#include "tp_DataSource.hxx"
32
33using namespace ::com::sun::star;
34using namespace ::com::sun::star::chart2;
35using namespace ::chart;
36
37namespace chart
38{
39
40namespace {
41
42class DocumentChartTypeTemplateProvider : public ChartTypeTemplateProvider
43{
44public:
45 explicit DocumentChartTypeTemplateProvider(
47
48 // ____ ChartTypeTemplateProvider ____
49 virtual rtl::Reference< ::chart::ChartTypeTemplate > getCurrentTemplate() const override;
50
51private:
53};
54
55}
56
57DocumentChartTypeTemplateProvider::DocumentChartTypeTemplateProvider(
59{
60 if( !xDoc.is())
61 return;
62
63 rtl::Reference< Diagram > xDia( xDoc->getFirstChartDiagram());
64 if( xDia.is())
65 {
66 Diagram::tTemplateWithServiceName aResult(
67 xDia->getTemplate( xDoc->getTypeManager() ));
68 m_xTemplate = aResult.xChartTypeTemplate;
69 }
70}
71
72rtl::Reference< ::chart::ChartTypeTemplate > DocumentChartTypeTemplateProvider::getCurrentTemplate() const
73{
74 return m_xTemplate;
75}
76
78
80 const rtl::Reference<::chart::ChartModel> & xChartDocument)
81 : GenericDialogController(pParent, "modules/schart/ui/datarangedialog.ui",
82 "DataRangeDialog")
83 , m_apDocTemplateProvider(new DocumentChartTypeTemplateProvider(xChartDocument))
84 , m_apDialogModel(new DialogModel(xChartDocument))
85 , m_bRangeChooserTabIsValid(true)
86 , m_bDataSourceTabIsValid(true)
87 , m_bTogglingEnabled(true)
88 , m_xTabControl(m_xBuilder->weld_notebook("tabcontrol"))
89 , m_xBtnOK(m_xBuilder->weld_button("ok"))
90{
91 m_xRangeChooserTabPage = std::make_unique<RangeChooserTabPage>(m_xTabControl->get_page("range"), this,
93 m_apDocTemplateProvider.get(), true /* bHideDescription */ );
94 m_xDataSourceTabPage = std::make_unique<DataSourceTabPage>(m_xTabControl->get_page("series"), this,
96 m_apDocTemplateProvider.get(), true /* bHideDescription */ );
97 m_xTabControl->connect_enter_page(LINK(this, DataSourceDialog, ActivatePageHdl));
98 m_xTabControl->connect_leave_page(LINK(this, DataSourceDialog, DeactivatePageHdl));
99 ActivatePageHdl(m_xTabControl->get_current_page_ident());
100 if (m_nLastPageId != 0)
101 {
102 m_xTabControl->set_current_page(m_nLastPageId);
103 ActivatePageHdl(m_xTabControl->get_current_page_ident());
104 }
105}
106
108{
110 m_xDataSourceTabPage.reset();
111 m_nLastPageId = m_xTabControl->get_current_page();
112}
113
115{
116 short nResult = GenericDialogController::run();
117 if( nResult == RET_OK )
118 {
120 m_xRangeChooserTabPage->commitPage();
122 m_xDataSourceTabPage->commitPage();
123 }
124 return nResult;
125}
126
127IMPL_LINK(DataSourceDialog, ActivatePageHdl, const OUString&, rPage, void)
128{
129 if (rPage == "range")
130 m_xRangeChooserTabPage->Activate();
131 else if (rPage == "series")
132 m_xDataSourceTabPage->Activate();
133}
134
135// allow/disallow user to leave page
136IMPL_LINK_NOARG(DataSourceDialog, DeactivatePageHdl, const OUString&, bool)
137{
138 return m_bTogglingEnabled;
139}
140
142{
143 if (pTabPage == m_xRangeChooserTabPage.get())
145 else if (pTabPage == m_xDataSourceTabPage.get())
147
149 {
150 m_xBtnOK->set_sensitive(false);
151 // note: there seems to be no suitable mechanism to address pages by
152 // identifier, at least it is unclear what the page identifiers are.
153 // @todo: change the fixed numbers to identifiers
155 m_xTabControl->set_current_page(1);
156 else if( m_bDataSourceTabIsValid )
157 m_xTabControl->set_current_page(0);
158 m_bTogglingEnabled = false;
159 }
160}
161
163{
164 if( pTabPage == m_xRangeChooserTabPage.get() )
166 else if( pTabPage == m_xDataSourceTabPage.get() )
168
170 {
171 m_xBtnOK->set_sensitive(true);
172 m_bTogglingEnabled = true;
173 }
174}
175
176} // namespace chart
177
178/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual short run() override
std::unique_ptr< weld::Button > m_xBtnOK
std::unique_ptr< weld::Notebook > m_xTabControl
virtual void setInvalidPage(BuilderPage *pTabPage) override
std::unique_ptr< DataSourceTabPage > m_xDataSourceTabPage
std::unique_ptr< ChartTypeTemplateProvider > m_apDocTemplateProvider
static sal_uInt16 m_nLastPageId
std::unique_ptr< DialogModel > m_apDialogModel
virtual ~DataSourceDialog() override
DataSourceDialog(weld::Window *pParent, const rtl::Reference<::chart::ChartModel > &xChartDocument)
std::unique_ptr< RangeChooserTabPage > m_xRangeChooserTabPage
virtual void setValidPage(BuilderPage *pTabPage) override
rtl::Reference< ::chart::ChartTypeTemplate > m_xTemplate
IMPL_LINK(StackingResourceGroup, StackingChangeHdl, weld::Toggleable &, rRadio, void)
IMPL_LINK_NOARG(SplinePropertiesDialog, SplineTypeListBoxHdl, weld::ComboBox &, void)
RET_OK