/src/libreoffice/sc/source/ui/dbgui/PivotLayoutDialog.cxx
Line | Count | Source |
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 | | |
12 | | #include <PivotLayoutTreeList.hxx> |
13 | | #include <PivotLayoutDialog.hxx> |
14 | | #include <reffact.hxx> |
15 | | |
16 | | #include <rangeutl.hxx> |
17 | | #include <uiitems.hxx> |
18 | | #include <dputil.hxx> |
19 | | #include <dbdocfun.hxx> |
20 | | #include <dpsave.hxx> |
21 | | #include <dpshttab.hxx> |
22 | | #include <scmod.hxx> |
23 | | |
24 | | #include <memory> |
25 | | #include <utility> |
26 | | #include <vector> |
27 | | |
28 | | #include <com/sun/star/sheet/DataPilotFieldOrientation.hpp> |
29 | | #include <com/sun/star/sheet/DataPilotFieldSortMode.hpp> |
30 | | #include <vcl/weld/Dialog.hxx> |
31 | | #include <vcl/weld/Expander.hxx> |
32 | | |
33 | | using namespace css::uno; |
34 | | using namespace css::sheet; |
35 | | |
36 | | ScItemValue::ScItemValue(OUString aName, SCCOL nColumn, PivotFunc nFunctionMask) : |
37 | 0 | maName(std::move(aName)), |
38 | 0 | maFunctionData(nColumn, nFunctionMask), |
39 | 0 | mpOriginalItemValue(this) |
40 | 0 | {} |
41 | | |
42 | | ScItemValue::ScItemValue(const ScItemValue* pInputItemValue) : |
43 | 0 | maName(pInputItemValue->maName), |
44 | 0 | maFunctionData(pInputItemValue->maFunctionData), |
45 | 0 | mpOriginalItemValue(this) |
46 | 0 | {} |
47 | | |
48 | | ScItemValue::~ScItemValue() |
49 | 0 | {} |
50 | | |
51 | | namespace |
52 | | { |
53 | | |
54 | | ScRange lclGetRangeForNamedRange(OUString const & aName, const ScDocument& rDocument) |
55 | 0 | { |
56 | 0 | ScRange aInvalidRange(ScAddress::INITIALIZE_INVALID); |
57 | 0 | ScRangeName& rRangeName = rDocument.GetRangeName(); |
58 | |
|
59 | 0 | const ScRangeData* pData = rRangeName.findByUpperName(aName.toAsciiUpperCase()); |
60 | 0 | if (pData == nullptr) |
61 | 0 | return aInvalidRange; |
62 | | |
63 | 0 | ScRange aRange; |
64 | 0 | if (pData->IsReference(aRange)) |
65 | 0 | return aRange; |
66 | | |
67 | 0 | return aInvalidRange; |
68 | 0 | } |
69 | | |
70 | | } |
71 | | |
72 | | ScPivotLayoutDialog::ScPivotLayoutDialog( |
73 | | SfxBindings* pSfxBindings, SfxChildWindow* pChildWindow, weld::Window* pParent, |
74 | | ScViewData& rViewData, const ScDPObject* pPivotTableObject, bool bNewPivotTable) |
75 | 0 | : ScAnyRefDlgController(pSfxBindings, pChildWindow, pParent, u"modules/scalc/ui/pivottablelayoutdialog.ui"_ustr, u"PivotTableLayout"_ustr) |
76 | 0 | , maPivotTableObject(*pPivotTableObject) |
77 | 0 | , mpPreviouslyFocusedListBox(nullptr) |
78 | 0 | , mrViewData(rViewData) |
79 | 0 | , mrDocument(rViewData.GetDocument()) |
80 | 0 | , mbNewPivotTable(bNewPivotTable) |
81 | 0 | , maAddressDetails(mrDocument.GetAddressConvention(), 0, 0) |
82 | 0 | , mbDialogLostFocus(false) |
83 | 0 | , mpActiveEdit(nullptr) |
84 | 0 | , mxListBoxField(new ScPivotLayoutTreeListLabel(m_xBuilder->weld_tree_view(u"listbox-fields"_ustr))) |
85 | 0 | , mxListBoxPage(new ScPivotLayoutTreeList(m_xBuilder->weld_tree_view(u"listbox-page"_ustr))) |
86 | 0 | , mxListBoxColumn(new ScPivotLayoutTreeList(m_xBuilder->weld_tree_view(u"listbox-column"_ustr))) |
87 | 0 | , mxListBoxRow(new ScPivotLayoutTreeList(m_xBuilder->weld_tree_view(u"listbox-row"_ustr))) |
88 | 0 | , mxListBoxData(new ScPivotLayoutTreeListData(m_xBuilder->weld_tree_view(u"listbox-data"_ustr))) |
89 | 0 | , mxCheckIgnoreEmptyRows(m_xBuilder->weld_check_button(u"check-ignore-empty-rows"_ustr)) |
90 | 0 | , mxCheckTotalColumns(m_xBuilder->weld_check_button(u"check-total-columns"_ustr)) |
91 | 0 | , mxCheckAddFilter(m_xBuilder->weld_check_button(u"check-add-filter"_ustr)) |
92 | 0 | , mxCheckIdentifyCategories(m_xBuilder->weld_check_button(u"check-identify-categories"_ustr)) |
93 | 0 | , mxCheckTotalRows(m_xBuilder->weld_check_button(u"check-total-rows"_ustr)) |
94 | 0 | , mxCheckDrillToDetail(m_xBuilder->weld_check_button(u"check-drill-to-details"_ustr)) |
95 | 0 | , mxCheckExpandCollapse(m_xBuilder->weld_check_button(u"check-show-expand-collapse"_ustr)) |
96 | 0 | , mxSourceRadioNamedRange(m_xBuilder->weld_radio_button(u"source-radio-named-range"_ustr)) |
97 | 0 | , mxSourceRadioSelection(m_xBuilder->weld_radio_button(u"source-radio-selection"_ustr)) |
98 | 0 | , mxSourceListBox(m_xBuilder->weld_combo_box(u"source-list"_ustr)) |
99 | 0 | , mxSourceEdit(new formula::RefEdit(m_xBuilder->weld_entry(u"source-edit"_ustr))) |
100 | 0 | , mxSourceButton(new formula::RefButton(m_xBuilder->weld_button(u"source-button"_ustr))) |
101 | 0 | , mxDestinationRadioNewSheet(m_xBuilder->weld_radio_button(u"destination-radio-new-sheet"_ustr)) |
102 | 0 | , mxDestinationRadioNamedRange(m_xBuilder->weld_radio_button(u"destination-radio-named-range"_ustr)) |
103 | 0 | , mxDestinationRadioSelection(m_xBuilder->weld_radio_button(u"destination-radio-selection"_ustr)) |
104 | 0 | , mxDestinationListBox(m_xBuilder->weld_combo_box(u"destination-list"_ustr)) |
105 | 0 | , mxDestinationEdit(new formula::RefEdit(m_xBuilder->weld_entry(u"destination-edit"_ustr))) |
106 | 0 | , mxDestinationButton(new formula::RefButton(m_xBuilder->weld_button(u"destination-button"_ustr))) |
107 | 0 | , mxBtnOK(m_xBuilder->weld_button(u"ok"_ustr)) |
108 | 0 | , mxBtnCancel(m_xBuilder->weld_button(u"cancel"_ustr)) |
109 | 0 | , mxSourceFrame(m_xBuilder->weld_frame(u"frame2"_ustr)) |
110 | 0 | , mxDestFrame(m_xBuilder->weld_frame(u"frame1"_ustr)) |
111 | 0 | , mxOptions(m_xBuilder->weld_expander(u"options"_ustr)) |
112 | 0 | , mxMore(m_xBuilder->weld_expander(u"more"_ustr)) |
113 | 0 | { |
114 | | // Source UI |
115 | 0 | Link<weld::Toggleable&,void> aLink2 = LINK(this, ScPivotLayoutDialog, ToggleSource); |
116 | 0 | mxSourceRadioNamedRange->connect_toggled(aLink2); |
117 | 0 | mxSourceRadioSelection->connect_toggled(aLink2); |
118 | |
|
119 | 0 | mxCheckDrillToDetail->connect_toggled(LINK(this, ScPivotLayoutDialog, UpdateCheckExpandCollapse)); |
120 | |
|
121 | 0 | mxSourceEdit->SetReferences(this, mxSourceFrame.get()); |
122 | 0 | mxSourceButton->SetReferences(this, mxSourceEdit.get()); |
123 | |
|
124 | 0 | Link<formula::RefEdit&,void> aEditLink = LINK(this, ScPivotLayoutDialog, GetEditFocusHandler); |
125 | 0 | mxDestinationEdit->SetGetFocusHdl(aEditLink); |
126 | 0 | mxSourceEdit->SetGetFocusHdl(aEditLink); |
127 | |
|
128 | 0 | aEditLink = LINK(this, ScPivotLayoutDialog, LoseEditFocusHandler); |
129 | 0 | mxDestinationEdit->SetLoseFocusHdl(aEditLink); |
130 | 0 | mxSourceEdit->SetLoseFocusHdl(aEditLink); |
131 | |
|
132 | 0 | mxSourceEdit->SetModifyHdl(LINK(this, ScPivotLayoutDialog, SourceEditModified)); |
133 | 0 | mxSourceListBox->connect_changed(LINK(this, ScPivotLayoutDialog, SourceListSelected)); |
134 | | |
135 | | // Destination UI |
136 | 0 | aLink2 = LINK(this, ScPivotLayoutDialog, ToggleDestination); |
137 | 0 | mxDestinationRadioNewSheet->connect_toggled(aLink2); |
138 | 0 | mxDestinationRadioNamedRange->connect_toggled(aLink2); |
139 | 0 | mxDestinationRadioSelection->connect_toggled(aLink2); |
140 | |
|
141 | 0 | mxDestinationEdit->SetReferences(this, mxDestFrame.get()); |
142 | 0 | mxDestinationButton->SetReferences(this, mxDestinationEdit.get()); |
143 | |
|
144 | 0 | Link<formula::RefButton&,void> aButtonLink = LINK(this, ScPivotLayoutDialog, GetButtonFocusHandler); |
145 | 0 | mxSourceButton->SetGetFocusHdl(aButtonLink); |
146 | 0 | mxDestinationButton->SetGetFocusHdl(aButtonLink); |
147 | |
|
148 | 0 | aButtonLink = LINK(this, ScPivotLayoutDialog, LoseButtonFocusHandler); |
149 | 0 | mxSourceButton->SetLoseFocusHdl(aButtonLink); |
150 | 0 | mxDestinationButton->SetLoseFocusHdl(aButtonLink); |
151 | | |
152 | | // Buttons |
153 | 0 | mxBtnCancel->connect_clicked(LINK(this, ScPivotLayoutDialog, CancelClicked)); |
154 | 0 | mxBtnOK->connect_clicked(LINK(this, ScPivotLayoutDialog, OKClicked)); |
155 | | |
156 | | // Initialize Data |
157 | 0 | maPivotTableObject.FillOldParam(maPivotParameters); |
158 | 0 | maPivotTableObject.FillLabelData(maPivotParameters); |
159 | |
|
160 | 0 | mxListBoxField->Setup (this); |
161 | 0 | mxListBoxPage->Setup (this, ScPivotLayoutTreeList::PAGE_LIST); |
162 | 0 | mxListBoxColumn->Setup(this, ScPivotLayoutTreeList::COLUMN_LIST); |
163 | 0 | mxListBoxRow->Setup (this, ScPivotLayoutTreeList::ROW_LIST); |
164 | 0 | mxListBoxData->Setup (this); |
165 | |
|
166 | 0 | FillValuesToListBoxes(); |
167 | | |
168 | | // Initialize Options |
169 | 0 | const ScDPSaveData* pSaveData = maPivotTableObject.GetSaveData(); |
170 | 0 | if (pSaveData == nullptr) |
171 | 0 | { |
172 | 0 | mxCheckAddFilter->set_active(false); |
173 | 0 | mxCheckDrillToDetail->set_active(false); |
174 | 0 | mxCheckExpandCollapse->set_active(false); |
175 | 0 | } |
176 | 0 | else |
177 | 0 | { |
178 | 0 | mxCheckAddFilter->set_active(pSaveData->GetFilterButton()); |
179 | 0 | mxCheckDrillToDetail->set_active(pSaveData->GetDrillDown()); |
180 | 0 | mxCheckExpandCollapse->set_active(pSaveData->GetExpandCollapse()); |
181 | 0 | } |
182 | |
|
183 | 0 | mxCheckIgnoreEmptyRows->set_active(maPivotParameters.bIgnoreEmptyRows); |
184 | 0 | mxCheckIdentifyCategories->set_active(maPivotParameters.bDetectCategories); |
185 | 0 | mxCheckTotalColumns->set_active(maPivotParameters.bMakeTotalCol); |
186 | 0 | mxCheckTotalRows->set_active(maPivotParameters.bMakeTotalRow); |
187 | |
|
188 | 0 | UpdateCheckExpandCollapse(*mxCheckDrillToDetail); |
189 | |
|
190 | 0 | SetupSource(); |
191 | 0 | SetupDestination(); |
192 | 0 | } |
193 | | |
194 | | ScPivotLayoutDialog::~ScPivotLayoutDialog() |
195 | 0 | { |
196 | 0 | } |
197 | | |
198 | | void ScPivotLayoutDialog::SetupSource() |
199 | 0 | { |
200 | 0 | mxSourceListBox->clear(); |
201 | |
|
202 | 0 | ScRange aSourceRange; |
203 | 0 | OUString sSourceNamedRangeName; |
204 | |
|
205 | 0 | if (maPivotTableObject.GetSheetDesc()) |
206 | 0 | { |
207 | 0 | const ScSheetSourceDesc* pSheetSourceDesc = maPivotTableObject.GetSheetDesc(); |
208 | 0 | aSourceRange = pSheetSourceDesc->GetSourceRange(); |
209 | |
|
210 | 0 | if(!aSourceRange.IsValid()) |
211 | 0 | { |
212 | | // Source is probably a DB Range |
213 | 0 | mxSourceRadioNamedRange->set_sensitive(false); |
214 | 0 | mxSourceRadioSelection->set_sensitive(false); |
215 | 0 | ToggleSource(); |
216 | 0 | return; |
217 | 0 | } |
218 | 0 | else |
219 | 0 | { |
220 | 0 | OUString aSourceRangeName = aSourceRange.Format(mrDocument, ScRefFlags::RANGE_ABS_3D, maAddressDetails); |
221 | 0 | mxSourceEdit->SetText(aSourceRangeName); |
222 | 0 | } |
223 | 0 | } |
224 | 0 | else |
225 | 0 | { |
226 | 0 | mxSourceRadioNamedRange->set_sensitive(false); |
227 | 0 | mxSourceRadioSelection->set_sensitive(false); |
228 | 0 | ToggleSource(); |
229 | 0 | return; |
230 | 0 | } |
231 | | |
232 | | // Setup Named Ranges |
233 | 0 | bool bIsNamedRange = false; |
234 | |
|
235 | 0 | ScAreaNameIterator aIterator(mrDocument); |
236 | 0 | OUString aEachName; |
237 | 0 | ScRange aEachRange; |
238 | |
|
239 | 0 | while (aIterator.Next(aEachName, aEachRange)) |
240 | 0 | { |
241 | 0 | if (!aIterator.WasDBName()) |
242 | 0 | { |
243 | 0 | mxSourceListBox->append_text(aEachName); |
244 | 0 | if (aEachRange == aSourceRange) |
245 | 0 | { |
246 | 0 | sSourceNamedRangeName = aEachName; |
247 | 0 | bIsNamedRange = true; |
248 | 0 | } |
249 | 0 | } |
250 | 0 | } |
251 | |
|
252 | 0 | bool bSourceBoxHasEntries = mxSourceListBox->get_count() > 0; |
253 | |
|
254 | 0 | if (bIsNamedRange) |
255 | 0 | { |
256 | 0 | mxSourceListBox->set_active_text(sSourceNamedRangeName); |
257 | 0 | mxSourceRadioNamedRange->set_active(true); |
258 | 0 | } |
259 | 0 | else |
260 | 0 | { |
261 | | // If entries - select first entry |
262 | 0 | mxSourceListBox->set_active(bSourceBoxHasEntries ? 0 : -1); |
263 | 0 | mxSourceRadioSelection->set_active(true); |
264 | 0 | } |
265 | | |
266 | | // If no entries disable the radio button. |
267 | 0 | if (!bSourceBoxHasEntries) |
268 | 0 | mxSourceRadioNamedRange->set_sensitive(false); |
269 | |
|
270 | 0 | ToggleSource(); |
271 | 0 | } |
272 | | |
273 | | void ScPivotLayoutDialog::SetupDestination() |
274 | 0 | { |
275 | 0 | mxDestinationListBox->clear(); |
276 | | |
277 | | // Fill up named ranges |
278 | 0 | ScAreaNameIterator aIterator(mrDocument); |
279 | 0 | OUString aName; |
280 | 0 | ScRange aRange; |
281 | |
|
282 | 0 | while (aIterator.Next(aName, aRange)) |
283 | 0 | { |
284 | 0 | if (!aIterator.WasDBName()) |
285 | 0 | { |
286 | 0 | mxDestinationListBox->append_text(aName); |
287 | 0 | } |
288 | 0 | } |
289 | | |
290 | | // If entries - select first entry, otherwise disable the radio button. |
291 | 0 | if (mxDestinationListBox->get_count() > 0) |
292 | 0 | mxDestinationListBox->set_active(0); |
293 | 0 | else |
294 | 0 | mxDestinationRadioNamedRange->set_sensitive(false); |
295 | | |
296 | | // |
297 | 0 | if (mbNewPivotTable) |
298 | 0 | { |
299 | 0 | mxDestinationRadioNewSheet->set_active(true); |
300 | 0 | } |
301 | 0 | else |
302 | 0 | { |
303 | 0 | if (maPivotParameters.nTab != MAXTAB + 1) |
304 | 0 | { |
305 | 0 | ScAddress aAddress(maPivotParameters.nCol, maPivotParameters.nRow, maPivotParameters.nTab); |
306 | 0 | OUString aAddressString = aAddress.Format(ScRefFlags::ADDR_ABS_3D, &mrDocument, maAddressDetails); |
307 | 0 | mxDestinationEdit->SetText(aAddressString); |
308 | 0 | mxDestinationRadioSelection->set_active(true); |
309 | 0 | } |
310 | 0 | } |
311 | |
|
312 | 0 | ToggleDestination(); |
313 | 0 | } |
314 | | |
315 | | void ScPivotLayoutDialog::FillValuesToListBoxes() |
316 | 0 | { |
317 | 0 | mxListBoxField->FillLabelFields(maPivotParameters.maLabelArray); |
318 | 0 | mxListBoxData->FillDataField(maPivotParameters.maDataFields); |
319 | 0 | mxListBoxColumn->FillFields(maPivotParameters.maColFields); |
320 | 0 | mxListBoxRow->FillFields(maPivotParameters.maRowFields); |
321 | 0 | mxListBoxPage->FillFields(maPivotParameters.maPageFields); |
322 | 0 | } |
323 | | |
324 | | void ScPivotLayoutDialog::SetActive() |
325 | 0 | { |
326 | 0 | if (mbDialogLostFocus) |
327 | 0 | { |
328 | 0 | mbDialogLostFocus = false; |
329 | 0 | if(mpActiveEdit != nullptr) |
330 | 0 | { |
331 | 0 | mpActiveEdit->GrabFocus(); |
332 | 0 | if (mpActiveEdit == mxSourceEdit.get()) |
333 | 0 | UpdateSourceRange(); |
334 | 0 | } |
335 | 0 | } |
336 | 0 | else |
337 | 0 | { |
338 | 0 | m_xDialog->grab_focus(); |
339 | 0 | } |
340 | |
|
341 | 0 | RefInputDone(); |
342 | 0 | } |
343 | | |
344 | | void ScPivotLayoutDialog::SetReference(const ScRange& rReferenceRange, ScDocument& rDocument) |
345 | 0 | { |
346 | 0 | if (!mbDialogLostFocus) |
347 | 0 | return; |
348 | | |
349 | 0 | if (mpActiveEdit == nullptr) |
350 | 0 | return; |
351 | | |
352 | 0 | if (rReferenceRange.aStart != rReferenceRange.aEnd) |
353 | 0 | RefInputStart(mpActiveEdit); |
354 | |
|
355 | 0 | OUString aReferenceString = rReferenceRange.Format(rDocument, ScRefFlags::RANGE_ABS_3D, maAddressDetails); |
356 | |
|
357 | 0 | if (mpActiveEdit == mxSourceEdit.get()) |
358 | 0 | { |
359 | 0 | mxSourceEdit->SetRefString(aReferenceString); |
360 | 0 | } |
361 | 0 | else if (mpActiveEdit == mxDestinationEdit.get()) |
362 | 0 | { |
363 | 0 | mxDestinationEdit->SetRefString(aReferenceString); |
364 | 0 | } |
365 | 0 | } |
366 | | |
367 | | bool ScPivotLayoutDialog::IsRefInputMode() const |
368 | 0 | { |
369 | 0 | return mbDialogLostFocus; |
370 | 0 | } |
371 | | |
372 | | void ScPivotLayoutDialog::ItemInserted(const ScItemValue* pItemValue, ScPivotLayoutTreeList::SvPivotTreeListType eType) |
373 | 0 | { |
374 | 0 | if (pItemValue == nullptr) |
375 | 0 | return; |
376 | | |
377 | 0 | switch (eType) |
378 | 0 | { |
379 | 0 | case ScPivotLayoutTreeList::ROW_LIST: |
380 | 0 | case ScPivotLayoutTreeList::COLUMN_LIST: |
381 | 0 | case ScPivotLayoutTreeList::PAGE_LIST: |
382 | 0 | { |
383 | 0 | mxListBoxRow->RemoveEntryForItem(pItemValue); |
384 | 0 | mxListBoxColumn->RemoveEntryForItem(pItemValue); |
385 | 0 | mxListBoxPage->RemoveEntryForItem(pItemValue); |
386 | 0 | } |
387 | 0 | break; |
388 | 0 | case ScPivotLayoutTreeList::LABEL_LIST: |
389 | 0 | { |
390 | 0 | mxListBoxRow->RemoveEntryForItem(pItemValue); |
391 | 0 | mxListBoxColumn->RemoveEntryForItem(pItemValue); |
392 | 0 | mxListBoxPage->RemoveEntryForItem(pItemValue); |
393 | 0 | mxListBoxData->RemoveEntryForItem(pItemValue); |
394 | 0 | } |
395 | 0 | break; |
396 | 0 | default: |
397 | 0 | break; |
398 | 0 | } |
399 | 0 | } |
400 | | |
401 | | void ScPivotLayoutDialog::UpdateSourceRange() |
402 | 0 | { |
403 | 0 | if (!maPivotTableObject.GetSheetDesc()) |
404 | 0 | return; |
405 | | |
406 | 0 | ScSheetSourceDesc aSourceSheet = *maPivotTableObject.GetSheetDesc(); |
407 | |
|
408 | 0 | if (mxSourceRadioNamedRange->get_active()) |
409 | 0 | { |
410 | 0 | OUString aEntryString = mxSourceListBox->get_active_text(); |
411 | 0 | ScRange aSourceRange = lclGetRangeForNamedRange(aEntryString, mrDocument); |
412 | 0 | if (!aSourceRange.IsValid() || aSourceSheet.GetSourceRange() == aSourceRange) |
413 | 0 | return; |
414 | 0 | aSourceSheet.SetRangeName(aEntryString); |
415 | 0 | } |
416 | 0 | else if (mxSourceRadioSelection->get_active()) |
417 | 0 | { |
418 | 0 | OUString aSourceString = mxSourceEdit->GetText(); |
419 | 0 | ScRange aSourceRange; |
420 | 0 | ScRefFlags nResult = aSourceRange.Parse(aSourceString, mrDocument, maAddressDetails); |
421 | |
|
422 | 0 | bool bIsValid = (nResult & ScRefFlags::VALID) == ScRefFlags::VALID; // aSourceString is valid |
423 | |
|
424 | 0 | mxSourceEdit->SetRefValid(true); |
425 | |
|
426 | 0 | if (bIsValid) |
427 | 0 | { |
428 | 0 | ScRefAddress aStart; |
429 | 0 | ScRefAddress aEnd; |
430 | |
|
431 | 0 | ConvertDoubleRef(mrDocument, aSourceString, 1, aStart, aEnd, maAddressDetails); |
432 | 0 | aSourceRange.aStart = aStart.GetAddress(); |
433 | 0 | aSourceRange.aEnd = aEnd.GetAddress(); |
434 | 0 | } |
435 | 0 | else |
436 | 0 | { |
437 | 0 | aSourceRange = lclGetRangeForNamedRange(aSourceString, mrDocument); |
438 | 0 | } |
439 | |
|
440 | 0 | if (!aSourceRange.IsValid()) |
441 | 0 | { |
442 | 0 | mxSourceEdit->SetRefValid(false); |
443 | 0 | return; |
444 | 0 | } |
445 | | |
446 | 0 | if (aSourceSheet.GetSourceRange() == aSourceRange) |
447 | 0 | return; |
448 | | |
449 | 0 | aSourceSheet.SetSourceRange(aSourceRange); |
450 | 0 | if (aSourceSheet.CheckSourceRange()) |
451 | 0 | { |
452 | 0 | mxSourceEdit->SetRefValid(false); |
453 | 0 | return; |
454 | 0 | } |
455 | 0 | } |
456 | 0 | else |
457 | 0 | { |
458 | 0 | return; |
459 | 0 | } |
460 | | |
461 | 0 | maPivotTableObject.SetSheetDesc(aSourceSheet); |
462 | 0 | maPivotTableObject.FillOldParam(maPivotParameters); |
463 | 0 | maPivotTableObject.FillLabelData(maPivotParameters); |
464 | |
|
465 | 0 | FillValuesToListBoxes(); |
466 | 0 | } |
467 | | |
468 | | void ScPivotLayoutDialog::ApplyChanges() |
469 | 0 | { |
470 | 0 | ScDPSaveData aSaveData; |
471 | 0 | ApplySaveData(aSaveData); |
472 | 0 | ApplyLabelData(aSaveData); |
473 | |
|
474 | 0 | ScDPObject *pOldDPObj = mrDocument.GetDPAtCursor( maPivotParameters.nCol, maPivotParameters.nRow, maPivotParameters.nTab); |
475 | 0 | ScRange aDestinationRange; |
476 | 0 | bool bToNewSheet = false; |
477 | |
|
478 | 0 | if (!GetDestination(aDestinationRange, bToNewSheet)) |
479 | 0 | return; |
480 | | |
481 | 0 | SetDispatcherLock(false); |
482 | 0 | SwitchToDocument(); |
483 | |
|
484 | 0 | sal_uInt16 nWhichPivot = ScModule::get()->GetPool().GetWhichIDFromSlotID(SID_PIVOT_TABLE); |
485 | 0 | ScPivotItem aPivotItem(nWhichPivot, &aSaveData, &aDestinationRange, bToNewSheet); |
486 | 0 | mrViewData.GetViewShell()->SetDialogDPObject(std::make_unique<ScDPObject>(maPivotTableObject)); |
487 | | |
488 | |
|
489 | 0 | SfxDispatcher* pDispatcher = GetBindings().GetDispatcher(); |
490 | 0 | SfxCallMode const nCallMode = SfxCallMode::SLOT | SfxCallMode::RECORD; |
491 | 0 | const SfxPoolItemHolder aResult(pDispatcher->ExecuteList(SID_PIVOT_TABLE, |
492 | 0 | nCallMode, { &aPivotItem })); |
493 | |
|
494 | 0 | if (aResult) |
495 | 0 | { |
496 | | // existing pivot table might have moved to a new range or a new sheet |
497 | 0 | if ( pOldDPObj != nullptr ) |
498 | 0 | { |
499 | 0 | const ScRange& rOldRange = pOldDPObj->GetOutRange(); |
500 | |
|
501 | 0 | ScDPObject *pDPObj = nullptr; |
502 | | // FIXME: if the new range overlaps with the old one, the table actually doesn't move |
503 | | // and shouldn't therefore be deleted |
504 | 0 | if ( ( ( rOldRange != aDestinationRange ) && !rOldRange.Contains( aDestinationRange ) ) |
505 | 0 | || bToNewSheet ) |
506 | 0 | { |
507 | 0 | pDPObj = mrDocument.GetDPAtCursor( maPivotParameters.nCol, maPivotParameters.nRow, maPivotParameters.nTab); |
508 | 0 | } |
509 | 0 | if (pDPObj) |
510 | 0 | { |
511 | 0 | ScDBDocFunc aFunc( *mrViewData.GetDocShell() ); |
512 | 0 | aFunc.RemovePivotTable( *pDPObj, true, false); |
513 | 0 | mrViewData.GetView()->CursorPosChanged(); |
514 | 0 | } |
515 | 0 | } |
516 | 0 | return; |
517 | 0 | } |
518 | | |
519 | 0 | SetDispatcherLock(true); |
520 | 0 | } |
521 | | |
522 | | void ScPivotLayoutDialog::ApplySaveData(ScDPSaveData& rSaveData) |
523 | 0 | { |
524 | 0 | rSaveData.SetIgnoreEmptyRows(mxCheckIgnoreEmptyRows->get_active()); |
525 | 0 | rSaveData.SetRepeatIfEmpty(mxCheckIdentifyCategories->get_active()); |
526 | 0 | rSaveData.SetColumnGrand(mxCheckTotalColumns->get_active()); |
527 | 0 | rSaveData.SetRowGrand(mxCheckTotalRows->get_active()); |
528 | 0 | rSaveData.SetFilterButton(mxCheckAddFilter->get_active()); |
529 | 0 | rSaveData.SetDrillDown(mxCheckDrillToDetail->get_active()); |
530 | 0 | rSaveData.SetExpandCollapse(mxCheckExpandCollapse->get_active()); |
531 | |
|
532 | 0 | Reference<XDimensionsSupplier> xSource = maPivotTableObject.GetSource(); |
533 | |
|
534 | 0 | ScPivotFieldVector aPageFieldVector; |
535 | 0 | mxListBoxPage->PushEntriesToPivotFieldVector(aPageFieldVector); |
536 | 0 | ScDPObject::ConvertOrientation(rSaveData, aPageFieldVector, DataPilotFieldOrientation_PAGE, |
537 | 0 | xSource, maPivotParameters.maLabelArray); |
538 | |
|
539 | 0 | ScPivotFieldVector aColFieldVector; |
540 | 0 | mxListBoxColumn->PushEntriesToPivotFieldVector(aColFieldVector); |
541 | 0 | ScDPObject::ConvertOrientation(rSaveData, aColFieldVector, DataPilotFieldOrientation_COLUMN, |
542 | 0 | xSource, maPivotParameters.maLabelArray); |
543 | |
|
544 | 0 | ScPivotFieldVector aRowFieldVector; |
545 | 0 | mxListBoxRow->PushEntriesToPivotFieldVector(aRowFieldVector); |
546 | 0 | ScDPObject::ConvertOrientation(rSaveData, aRowFieldVector, DataPilotFieldOrientation_ROW, |
547 | 0 | xSource, maPivotParameters.maLabelArray); |
548 | |
|
549 | 0 | ScPivotFieldVector aDataFieldVector; |
550 | 0 | mxListBoxData->PushEntriesToPivotFieldVector(aDataFieldVector); |
551 | 0 | ScDPObject::ConvertOrientation(rSaveData, aDataFieldVector, DataPilotFieldOrientation_DATA, |
552 | 0 | xSource, maPivotParameters.maLabelArray, |
553 | 0 | &aColFieldVector, &aRowFieldVector, &aPageFieldVector); |
554 | 0 | } |
555 | | |
556 | | void ScPivotLayoutDialog::ApplyLabelData(const ScDPSaveData& rSaveData) |
557 | 0 | { |
558 | 0 | ScDPLabelDataVector& rLabelDataVector = GetLabelDataVector(); |
559 | |
|
560 | 0 | for (std::unique_ptr<ScDPLabelData> const & pLabelData : rLabelDataVector) |
561 | 0 | { |
562 | 0 | OUString aUnoName = ScDPUtil::createDuplicateDimensionName(pLabelData->maName, pLabelData->mnDupCount); |
563 | 0 | ScDPSaveDimension* pSaveDimensions = rSaveData.GetExistingDimensionByName(aUnoName); |
564 | |
|
565 | 0 | if (pSaveDimensions == nullptr) |
566 | 0 | continue; |
567 | | |
568 | 0 | pSaveDimensions->SetUsedHierarchy(pLabelData->mnUsedHier); |
569 | 0 | pSaveDimensions->SetShowEmpty(pLabelData->mbShowAll); |
570 | 0 | pSaveDimensions->SetRepeatItemLabels(pLabelData->mbRepeatItemLabels); |
571 | 0 | pSaveDimensions->SetSortInfo(&pLabelData->maSortInfo); |
572 | 0 | pSaveDimensions->SetLayoutInfo(&pLabelData->maLayoutInfo); |
573 | 0 | pSaveDimensions->SetAutoShowInfo(&pLabelData->maShowInfo); |
574 | |
|
575 | 0 | bool bManualSort = (pLabelData->maSortInfo.Mode == DataPilotFieldSortMode::MANUAL); |
576 | |
|
577 | 0 | for (ScDPLabelData::Member const & rLabelMember : pLabelData->maMembers) |
578 | 0 | { |
579 | 0 | ScDPSaveMember* pMember = pSaveDimensions->GetMemberByName(rLabelMember.maName); |
580 | |
|
581 | 0 | if (bManualSort || !rLabelMember.mbVisible || !rLabelMember.mbShowDetails) |
582 | 0 | { |
583 | 0 | pMember->SetIsVisible(rLabelMember.mbVisible); |
584 | 0 | pMember->SetShowDetails(rLabelMember.mbShowDetails); |
585 | 0 | } |
586 | 0 | } |
587 | 0 | } |
588 | 0 | } |
589 | | |
590 | | bool ScPivotLayoutDialog::GetDestination(ScRange& aDestinationRange, bool& bToNewSheet) |
591 | 0 | { |
592 | 0 | bToNewSheet = false; |
593 | |
|
594 | 0 | if (mxDestinationRadioNamedRange->get_active()) |
595 | 0 | { |
596 | 0 | OUString aName = mxDestinationListBox->get_active_text(); |
597 | 0 | aDestinationRange = lclGetRangeForNamedRange(aName, mrDocument); |
598 | 0 | if (!aDestinationRange.IsValid()) |
599 | 0 | return false; |
600 | 0 | } |
601 | 0 | else if (mxDestinationRadioSelection->get_active()) |
602 | 0 | { |
603 | 0 | ScAddress aAddress; |
604 | 0 | aAddress.Parse(mxDestinationEdit->GetText(), mrDocument, maAddressDetails); |
605 | 0 | aDestinationRange = ScRange(aAddress); |
606 | 0 | } |
607 | 0 | else |
608 | 0 | { |
609 | 0 | bToNewSheet = true; |
610 | 0 | aDestinationRange = ScRange(maPivotParameters.nCol, maPivotParameters.nRow, maPivotParameters.nTab); |
611 | 0 | } |
612 | 0 | return true; |
613 | 0 | } |
614 | | |
615 | | ScItemValue* ScPivotLayoutDialog::GetItem(SCCOL nColumn) |
616 | 0 | { |
617 | 0 | return mxListBoxField->GetItem(nColumn); |
618 | 0 | } |
619 | | |
620 | | bool ScPivotLayoutDialog::IsDataElement(SCCOL nColumn) |
621 | 0 | { |
622 | 0 | return mxListBoxField->IsDataElement(nColumn); |
623 | 0 | } |
624 | | |
625 | | bool ScPivotLayoutDialog::IsCalculatedElement(SCCOL nColumn) |
626 | 0 | { |
627 | 0 | return maPivotParameters.maLabelArray[nColumn]->mbCalculatedField; |
628 | 0 | } |
629 | | |
630 | | ScDPLabelData& ScPivotLayoutDialog::GetLabelData(SCCOL nColumn) |
631 | 0 | { |
632 | 0 | return *maPivotParameters.maLabelArray[nColumn]; |
633 | 0 | } |
634 | | |
635 | | void ScPivotLayoutDialog::PushDataFieldNames(std::vector<ScDPName>& rDataFieldNames) |
636 | 0 | { |
637 | 0 | mxListBoxData->PushDataFieldNames(rDataFieldNames); |
638 | 0 | } |
639 | | |
640 | | void ScPivotLayoutDialog::Close() |
641 | 0 | { |
642 | 0 | DoClose(ScPivotLayoutWrapper::GetChildWindowId()); |
643 | 0 | SfxDialogController::Close(); |
644 | 0 | } |
645 | | |
646 | | IMPL_LINK_NOARG( ScPivotLayoutDialog, OKClicked, weld::Button&, void ) |
647 | 0 | { |
648 | | /* tdf#137726 hide so it's not a candidate to be parent of any error |
649 | | messages that may appear because this dialog is going to disappear on |
650 | | response(RET_OK) and the error dialog is not run in its own event loop |
651 | | but instead async */ |
652 | 0 | m_xDialog->hide(); |
653 | |
|
654 | 0 | ApplyChanges(); |
655 | 0 | m_xDialog->response(RET_OK); |
656 | 0 | } |
657 | | |
658 | | IMPL_LINK_NOARG( ScPivotLayoutDialog, CancelClicked, weld::Button&, void ) |
659 | 0 | { |
660 | 0 | m_xDialog->response(RET_CANCEL); |
661 | 0 | } |
662 | | |
663 | | IMPL_LINK(ScPivotLayoutDialog, GetEditFocusHandler, formula::RefEdit&, rCtrl, void) |
664 | 0 | { |
665 | 0 | mpActiveEdit = &rCtrl; |
666 | 0 | mpActiveEdit->SelectAll(); |
667 | 0 | } |
668 | | |
669 | | IMPL_LINK(ScPivotLayoutDialog, GetButtonFocusHandler, formula::RefButton&, rCtrl, void) |
670 | 0 | { |
671 | 0 | mpActiveEdit = nullptr; |
672 | |
|
673 | 0 | if (&rCtrl == mxSourceButton.get()) |
674 | 0 | mpActiveEdit = mxSourceEdit.get(); |
675 | 0 | else if (&rCtrl == mxDestinationButton.get()) |
676 | 0 | mpActiveEdit = mxDestinationEdit.get(); |
677 | |
|
678 | 0 | if (mpActiveEdit) |
679 | 0 | mpActiveEdit->SelectAll(); |
680 | 0 | } |
681 | | |
682 | | IMPL_LINK_NOARG(ScPivotLayoutDialog, LoseEditFocusHandler, formula::RefEdit&, void) |
683 | 0 | { |
684 | 0 | mbDialogLostFocus = !m_xDialog->has_toplevel_focus(); |
685 | 0 | } |
686 | | |
687 | | IMPL_LINK_NOARG(ScPivotLayoutDialog, LoseButtonFocusHandler, formula::RefButton&, void) |
688 | 0 | { |
689 | 0 | mbDialogLostFocus = !m_xDialog->has_toplevel_focus(); |
690 | 0 | } |
691 | | |
692 | | IMPL_LINK_NOARG(ScPivotLayoutDialog, SourceListSelected, weld::ComboBox&, void) |
693 | 0 | { |
694 | 0 | UpdateSourceRange(); |
695 | 0 | } |
696 | | |
697 | | IMPL_LINK_NOARG(ScPivotLayoutDialog, SourceEditModified, formula::RefEdit&, void) |
698 | 0 | { |
699 | 0 | UpdateSourceRange(); |
700 | 0 | } |
701 | | |
702 | | IMPL_LINK_NOARG(ScPivotLayoutDialog, ToggleSource, weld::Toggleable&, void) |
703 | 0 | { |
704 | 0 | ToggleSource(); |
705 | 0 | } |
706 | | |
707 | | void ScPivotLayoutDialog::ToggleSource() |
708 | 0 | { |
709 | 0 | bool bNamedRange = mxSourceRadioNamedRange->get_active(); |
710 | 0 | bool bSelection = mxSourceRadioSelection->get_active(); |
711 | 0 | mxSourceListBox->set_sensitive(bNamedRange); |
712 | 0 | mxSourceButton->GetWidget()->set_sensitive(bSelection); |
713 | 0 | mxSourceEdit->GetWidget()->set_sensitive(bSelection); |
714 | 0 | UpdateSourceRange(); |
715 | 0 | } |
716 | | |
717 | | IMPL_LINK_NOARG(ScPivotLayoutDialog, ToggleDestination, weld::Toggleable&, void) |
718 | 0 | { |
719 | 0 | ToggleDestination(); |
720 | 0 | } |
721 | | |
722 | | void ScPivotLayoutDialog::ToggleDestination() |
723 | 0 | { |
724 | 0 | bool bNamedRange = mxDestinationRadioNamedRange->get_active(); |
725 | 0 | bool bSelection = mxDestinationRadioSelection->get_active(); |
726 | 0 | mxDestinationListBox->set_sensitive(bNamedRange); |
727 | 0 | mxDestinationButton->GetWidget()->set_sensitive(bSelection); |
728 | 0 | mxDestinationEdit->GetWidget()->set_sensitive(bSelection); |
729 | 0 | } |
730 | | |
731 | | IMPL_LINK_NOARG(ScPivotLayoutDialog, UpdateCheckExpandCollapse, weld::Toggleable&, void) |
732 | 0 | { |
733 | 0 | bool bChecked = mxCheckDrillToDetail->get_active(); |
734 | 0 | if (!bChecked) |
735 | 0 | mxCheckExpandCollapse->set_active(false); |
736 | 0 | mxCheckExpandCollapse->set_sensitive(bChecked); |
737 | 0 | } |
738 | | |
739 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |