Debian Codegraph @

chart2/source/controller/dialogs/dlg_DataSource.cxx

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