tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / chart2 / source / controller / dialogs / dlg_DataSource.cxx
blobc00698fef60d13d9b3cb19a4fed3d45689f66778
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <com/sun/star/chart2/XChartDocument.hpp>
22 #include <dlg_DataSource.hxx>
23 #include <ChartTypeTemplateProvider.hxx>
24 #include <ChartTypeTemplate.hxx>
25 #include <Diagram.hxx>
26 #include "DialogModel.hxx"
27 #include <ChartModel.hxx>
29 #include "tp_RangeChooser.hxx"
30 #include "tp_DataSource.hxx"
32 using namespace ::com::sun::star;
33 using namespace ::chart;
35 namespace chart
38 namespace {
40 class DocumentChartTypeTemplateProvider : public ChartTypeTemplateProvider
42 public:
43 explicit DocumentChartTypeTemplateProvider(
44 const rtl::Reference<::chart::ChartModel> & xDoc );
46 // ____ ChartTypeTemplateProvider ____
47 virtual rtl::Reference< ::chart::ChartTypeTemplate > getCurrentTemplate() const override;
49 private:
50 rtl::Reference< ::chart::ChartTypeTemplate > m_xTemplate;
55 DocumentChartTypeTemplateProvider::DocumentChartTypeTemplateProvider(
56 const rtl::Reference<::chart::ChartModel> & xDoc )
58 if( !xDoc.is())
59 return;
61 rtl::Reference< Diagram > xDia( xDoc->getFirstChartDiagram());
62 if( xDia.is())
64 Diagram::tTemplateWithServiceName aResult(
65 xDia->getTemplate( xDoc->getTypeManager() ));
66 m_xTemplate = aResult.xChartTypeTemplate;
70 rtl::Reference< ::chart::ChartTypeTemplate > DocumentChartTypeTemplateProvider::getCurrentTemplate() const
72 return m_xTemplate;
75 sal_uInt16 DataSourceDialog::m_nLastPageId = 0;
77 DataSourceDialog::DataSourceDialog(weld::Window * pParent,
78 const rtl::Reference<::chart::ChartModel> & xChartDocument)
79 : GenericDialogController(pParent, u"modules/schart/ui/datarangedialog.ui"_ustr,
80 u"DataRangeDialog"_ustr)
81 , m_apDocTemplateProvider(new DocumentChartTypeTemplateProvider(xChartDocument))
82 , m_apDialogModel(new DialogModel(xChartDocument))
83 , m_bRangeChooserTabIsValid(true)
84 , m_bDataSourceTabIsValid(true)
85 , m_bTogglingEnabled(true)
86 , m_xTabControl(m_xBuilder->weld_notebook(u"tabcontrol"_ustr))
87 , m_xBtnOK(m_xBuilder->weld_button(u"ok"_ustr))
89 m_xRangeChooserTabPage = std::make_unique<RangeChooserTabPage>(m_xTabControl->get_page(u"range"_ustr), this,
90 *m_apDialogModel,
91 m_apDocTemplateProvider.get(), true /* bHideDescription */ );
92 m_xDataSourceTabPage = std::make_unique<DataSourceTabPage>(m_xTabControl->get_page(u"series"_ustr), this,
93 *m_apDialogModel,
94 m_apDocTemplateProvider.get(), true /* bHideDescription */ );
95 m_xTabControl->connect_enter_page(LINK(this, DataSourceDialog, ActivatePageHdl));
96 m_xTabControl->connect_leave_page(LINK(this, DataSourceDialog, DeactivatePageHdl));
97 m_xBtnOK->connect_clicked(LINK(this, DataSourceDialog, OkHdl));
98 ActivatePageHdl(m_xTabControl->get_current_page_ident());
99 if (m_nLastPageId != 0)
101 m_xTabControl->set_current_page(m_nLastPageId);
102 ActivatePageHdl(m_xTabControl->get_current_page_ident());
106 DataSourceDialog::~DataSourceDialog()
108 m_xRangeChooserTabPage.reset();
109 m_xDataSourceTabPage.reset();
110 m_nLastPageId = m_xTabControl->get_current_page();
113 void DataSourceDialog::commitPages()
115 if (m_xRangeChooserTabPage)
116 m_xRangeChooserTabPage->commitPage();
117 if (m_xDataSourceTabPage)
118 m_xDataSourceTabPage->commitPage();
121 IMPL_LINK_NOARG(DataSourceDialog, OkHdl, weld::Button&, void)
123 commitPages();
124 m_xDialog->response(RET_OK);
127 IMPL_LINK(DataSourceDialog, ActivatePageHdl, const OUString&, rPage, void)
129 if (rPage == "range")
130 m_xRangeChooserTabPage->Activate();
131 else if (rPage == "series")
132 m_xDataSourceTabPage->Activate();
135 // allow/disallow user to leave page
136 IMPL_LINK_NOARG(DataSourceDialog, DeactivatePageHdl, const OUString&, bool)
138 return m_bTogglingEnabled;
141 void DataSourceDialog::setInvalidPage(BuilderPage* pTabPage)
143 if (pTabPage == m_xRangeChooserTabPage.get())
144 m_bRangeChooserTabIsValid = false;
145 else if (pTabPage == m_xDataSourceTabPage.get())
146 m_bDataSourceTabIsValid = false;
148 if (!(m_bRangeChooserTabIsValid && m_bDataSourceTabIsValid))
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
154 if( m_bRangeChooserTabIsValid )
155 m_xTabControl->set_current_page(1);
156 else if( m_bDataSourceTabIsValid )
157 m_xTabControl->set_current_page(0);
158 m_bTogglingEnabled = false;
162 void DataSourceDialog::setValidPage(BuilderPage* pTabPage)
164 if( pTabPage == m_xRangeChooserTabPage.get() )
165 m_bRangeChooserTabIsValid = true;
166 else if( pTabPage == m_xDataSourceTabPage.get() )
167 m_bDataSourceTabIsValid = true;
169 if (m_bRangeChooserTabIsValid && m_bDataSourceTabIsValid)
171 m_xBtnOK->set_sensitive(true);
172 m_bTogglingEnabled = true;
176 } // namespace chart
178 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */