tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sc / source / ui / dbgui / PivotLayoutDialog.cxx
blob675eb9313c95a5dcb124fbb87de31aa3b32a762a
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:
12 #include <PivotLayoutTreeList.hxx>
13 #include <PivotLayoutDialog.hxx>
14 #include <reffact.hxx>
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>
24 #include <memory>
25 #include <utility>
26 #include <vector>
28 #include <com/sun/star/sheet/DataPilotFieldOrientation.hpp>
29 #include <com/sun/star/sheet/DataPilotFieldSortMode.hpp>
31 using namespace css::uno;
32 using namespace css::sheet;
34 ScItemValue::ScItemValue(OUString aName, SCCOL nColumn, PivotFunc nFunctionMask) :
35 maName(std::move(aName)),
36 maFunctionData(nColumn, nFunctionMask),
37 mpOriginalItemValue(this)
40 ScItemValue::ScItemValue(const ScItemValue* pInputItemValue) :
41 maName(pInputItemValue->maName),
42 maFunctionData(pInputItemValue->maFunctionData),
43 mpOriginalItemValue(this)
46 ScItemValue::~ScItemValue()
49 namespace
52 ScRange lclGetRangeForNamedRange(OUString const & aName, const ScDocument& rDocument)
54 ScRange aInvalidRange(ScAddress::INITIALIZE_INVALID);
55 ScRangeName* pRangeName = rDocument.GetRangeName();
56 if (pRangeName == nullptr)
57 return aInvalidRange;
59 const ScRangeData* pData = pRangeName->findByUpperName(aName.toAsciiUpperCase());
60 if (pData == nullptr)
61 return aInvalidRange;
63 ScRange aRange;
64 if (pData->IsReference(aRange))
65 return aRange;
67 return aInvalidRange;
72 ScPivotLayoutDialog::ScPivotLayoutDialog(
73 SfxBindings* pSfxBindings, SfxChildWindow* pChildWindow, weld::Window* pParent,
74 ScViewData* pViewData, const ScDPObject* pPivotTableObject, bool bNewPivotTable)
75 : ScAnyRefDlgController(pSfxBindings, pChildWindow, pParent, u"modules/scalc/ui/pivottablelayoutdialog.ui"_ustr, u"PivotTableLayout"_ustr)
76 , maPivotTableObject(*pPivotTableObject)
77 , mpPreviouslyFocusedListBox(nullptr)
78 , mpViewData(pViewData)
79 , mrDocument(pViewData->GetDocument())
80 , mbNewPivotTable(bNewPivotTable)
81 , maAddressDetails(mrDocument.GetAddressConvention(), 0, 0)
82 , mbDialogLostFocus(false)
83 , mpActiveEdit(nullptr)
84 , mxListBoxField(new ScPivotLayoutTreeListLabel(m_xBuilder->weld_tree_view(u"listbox-fields"_ustr)))
85 , mxListBoxPage(new ScPivotLayoutTreeList(m_xBuilder->weld_tree_view(u"listbox-page"_ustr)))
86 , mxListBoxColumn(new ScPivotLayoutTreeList(m_xBuilder->weld_tree_view(u"listbox-column"_ustr)))
87 , mxListBoxRow(new ScPivotLayoutTreeList(m_xBuilder->weld_tree_view(u"listbox-row"_ustr)))
88 , mxListBoxData(new ScPivotLayoutTreeListData(m_xBuilder->weld_tree_view(u"listbox-data"_ustr)))
89 , mxCheckIgnoreEmptyRows(m_xBuilder->weld_check_button(u"check-ignore-empty-rows"_ustr))
90 , mxCheckTotalColumns(m_xBuilder->weld_check_button(u"check-total-columns"_ustr))
91 , mxCheckAddFilter(m_xBuilder->weld_check_button(u"check-add-filter"_ustr))
92 , mxCheckIdentifyCategories(m_xBuilder->weld_check_button(u"check-identify-categories"_ustr))
93 , mxCheckTotalRows(m_xBuilder->weld_check_button(u"check-total-rows"_ustr))
94 , mxCheckDrillToDetail(m_xBuilder->weld_check_button(u"check-drill-to-details"_ustr))
95 , mxCheckExpandCollapse(m_xBuilder->weld_check_button(u"check-show-expand-collapse"_ustr))
96 , mxSourceRadioNamedRange(m_xBuilder->weld_radio_button(u"source-radio-named-range"_ustr))
97 , mxSourceRadioSelection(m_xBuilder->weld_radio_button(u"source-radio-selection"_ustr))
98 , mxSourceListBox(m_xBuilder->weld_combo_box(u"source-list"_ustr))
99 , mxSourceEdit(new formula::RefEdit(m_xBuilder->weld_entry(u"source-edit"_ustr)))
100 , mxSourceButton(new formula::RefButton(m_xBuilder->weld_button(u"source-button"_ustr)))
101 , mxDestinationRadioNewSheet(m_xBuilder->weld_radio_button(u"destination-radio-new-sheet"_ustr))
102 , mxDestinationRadioNamedRange(m_xBuilder->weld_radio_button(u"destination-radio-named-range"_ustr))
103 , mxDestinationRadioSelection(m_xBuilder->weld_radio_button(u"destination-radio-selection"_ustr))
104 , mxDestinationListBox(m_xBuilder->weld_combo_box(u"destination-list"_ustr))
105 , mxDestinationEdit(new formula::RefEdit(m_xBuilder->weld_entry(u"destination-edit"_ustr)))
106 , mxDestinationButton(new formula::RefButton(m_xBuilder->weld_button(u"destination-button"_ustr)))
107 , mxBtnOK(m_xBuilder->weld_button(u"ok"_ustr))
108 , mxBtnCancel(m_xBuilder->weld_button(u"cancel"_ustr))
109 , mxSourceFrame(m_xBuilder->weld_frame(u"frame2"_ustr))
110 , mxSourceLabel(mxSourceFrame->weld_label_widget())
111 , mxDestFrame(m_xBuilder->weld_frame(u"frame1"_ustr))
112 , mxDestLabel(mxDestFrame->weld_label_widget())
113 , mxOptions(m_xBuilder->weld_expander(u"options"_ustr))
114 , mxMore(m_xBuilder->weld_expander(u"more"_ustr))
116 // Source UI
117 Link<weld::Toggleable&,void> aLink2 = LINK(this, ScPivotLayoutDialog, ToggleSource);
118 mxSourceRadioNamedRange->connect_toggled(aLink2);
119 mxSourceRadioSelection->connect_toggled(aLink2);
121 mxSourceEdit->SetReferences(this, mxSourceLabel.get());
122 mxSourceButton->SetReferences(this, mxSourceEdit.get());
124 Link<formula::RefEdit&,void> aEditLink = LINK(this, ScPivotLayoutDialog, GetEditFocusHandler);
125 mxDestinationEdit->SetGetFocusHdl(aEditLink);
126 mxSourceEdit->SetGetFocusHdl(aEditLink);
128 aEditLink = LINK(this, ScPivotLayoutDialog, LoseEditFocusHandler);
129 mxDestinationEdit->SetLoseFocusHdl(aEditLink);
130 mxSourceEdit->SetLoseFocusHdl(aEditLink);
132 mxSourceEdit->SetModifyHdl(LINK(this, ScPivotLayoutDialog, SourceEditModified));
133 mxSourceListBox->connect_changed(LINK(this, ScPivotLayoutDialog, SourceListSelected));
135 // Destination UI
136 aLink2 = LINK(this, ScPivotLayoutDialog, ToggleDestination);
137 mxDestinationRadioNewSheet->connect_toggled(aLink2);
138 mxDestinationRadioNamedRange->connect_toggled(aLink2);
139 mxDestinationRadioSelection->connect_toggled(aLink2);
141 mxDestinationEdit->SetReferences(this, mxDestLabel.get());
142 mxDestinationButton->SetReferences(this, mxDestinationEdit.get());
144 Link<formula::RefButton&,void> aButtonLink = LINK(this, ScPivotLayoutDialog, GetButtonFocusHandler);
145 mxSourceButton->SetGetFocusHdl(aButtonLink);
146 mxDestinationButton->SetGetFocusHdl(aButtonLink);
148 aButtonLink = LINK(this, ScPivotLayoutDialog, LoseButtonFocusHandler);
149 mxSourceButton->SetLoseFocusHdl(aButtonLink);
150 mxDestinationButton->SetLoseFocusHdl(aButtonLink);
152 // Buttons
153 mxBtnCancel->connect_clicked(LINK(this, ScPivotLayoutDialog, CancelClicked));
154 mxBtnOK->connect_clicked(LINK(this, ScPivotLayoutDialog, OKClicked));
156 // Initialize Data
157 maPivotTableObject.FillOldParam(maPivotParameters);
158 maPivotTableObject.FillLabelData(maPivotParameters);
160 mxListBoxField->Setup (this);
161 mxListBoxPage->Setup (this, ScPivotLayoutTreeList::PAGE_LIST);
162 mxListBoxColumn->Setup(this, ScPivotLayoutTreeList::COLUMN_LIST);
163 mxListBoxRow->Setup (this, ScPivotLayoutTreeList::ROW_LIST);
164 mxListBoxData->Setup (this);
166 FillValuesToListBoxes();
168 // Initialize Options
169 const ScDPSaveData* pSaveData = maPivotTableObject.GetSaveData();
170 if (pSaveData == nullptr)
172 mxCheckAddFilter->set_active(false);
173 mxCheckDrillToDetail->set_active(false);
174 mxCheckExpandCollapse->set_active(false);
176 else
178 mxCheckAddFilter->set_active(pSaveData->GetFilterButton());
179 mxCheckDrillToDetail->set_active(pSaveData->GetDrillDown());
180 mxCheckExpandCollapse->set_active(pSaveData->GetExpandCollapse());
183 mxCheckIgnoreEmptyRows->set_active(maPivotParameters.bIgnoreEmptyRows);
184 mxCheckIdentifyCategories->set_active(maPivotParameters.bDetectCategories);
185 mxCheckTotalColumns->set_active(maPivotParameters.bMakeTotalCol);
186 mxCheckTotalRows->set_active(maPivotParameters.bMakeTotalRow);
188 SetupSource();
189 SetupDestination();
192 ScPivotLayoutDialog::~ScPivotLayoutDialog()
196 void ScPivotLayoutDialog::SetupSource()
198 mxSourceListBox->clear();
200 ScRange aSourceRange;
201 OUString sSourceNamedRangeName;
203 if (maPivotTableObject.GetSheetDesc())
205 const ScSheetSourceDesc* pSheetSourceDesc = maPivotTableObject.GetSheetDesc();
206 aSourceRange = pSheetSourceDesc->GetSourceRange();
208 if(!aSourceRange.IsValid())
210 // Source is probably a DB Range
211 mxSourceRadioNamedRange->set_sensitive(false);
212 mxSourceRadioSelection->set_sensitive(false);
213 ToggleSource();
214 return;
216 else
218 OUString aSourceRangeName = aSourceRange.Format(mrDocument, ScRefFlags::RANGE_ABS_3D, maAddressDetails);
219 mxSourceEdit->SetText(aSourceRangeName);
222 else
224 mxSourceRadioNamedRange->set_sensitive(false);
225 mxSourceRadioSelection->set_sensitive(false);
226 ToggleSource();
227 return;
230 // Setup Named Ranges
231 bool bIsNamedRange = false;
233 ScAreaNameIterator aIterator(mrDocument);
234 OUString aEachName;
235 ScRange aEachRange;
237 while (aIterator.Next(aEachName, aEachRange))
239 if (!aIterator.WasDBName())
241 mxSourceListBox->append_text(aEachName);
242 if (aEachRange == aSourceRange)
244 sSourceNamedRangeName = aEachName;
245 bIsNamedRange = true;
250 bool bSourceBoxHasEntries = mxSourceListBox->get_count() > 0;
252 if (bIsNamedRange)
254 mxSourceListBox->set_active_text(sSourceNamedRangeName);
255 mxSourceRadioNamedRange->set_active(true);
257 else
259 // If entries - select first entry
260 mxSourceListBox->set_active(bSourceBoxHasEntries ? 0 : -1);
261 mxSourceRadioSelection->set_active(true);
264 // If no entries disable the radio button.
265 if (!bSourceBoxHasEntries)
266 mxSourceRadioNamedRange->set_sensitive(false);
268 ToggleSource();
271 void ScPivotLayoutDialog::SetupDestination()
273 mxDestinationListBox->clear();
275 // Fill up named ranges
276 ScAreaNameIterator aIterator(mrDocument);
277 OUString aName;
278 ScRange aRange;
280 while (aIterator.Next(aName, aRange))
282 if (!aIterator.WasDBName())
284 mxDestinationListBox->append_text(aName);
288 // If entries - select first entry, otherwise disable the radio button.
289 if (mxDestinationListBox->get_count() > 0)
290 mxDestinationListBox->set_active(0);
291 else
292 mxDestinationRadioNamedRange->set_sensitive(false);
295 if (mbNewPivotTable)
297 mxDestinationRadioNewSheet->set_active(true);
299 else
301 if (maPivotParameters.nTab != MAXTAB + 1)
303 ScAddress aAddress(maPivotParameters.nCol, maPivotParameters.nRow, maPivotParameters.nTab);
304 OUString aAddressString = aAddress.Format(ScRefFlags::ADDR_ABS_3D, &mrDocument, maAddressDetails);
305 mxDestinationEdit->SetText(aAddressString);
306 mxDestinationRadioSelection->set_active(true);
310 ToggleDestination();
313 void ScPivotLayoutDialog::FillValuesToListBoxes()
315 mxListBoxField->FillLabelFields(maPivotParameters.maLabelArray);
316 mxListBoxData->FillDataField(maPivotParameters.maDataFields);
317 mxListBoxColumn->FillFields(maPivotParameters.maColFields);
318 mxListBoxRow->FillFields(maPivotParameters.maRowFields);
319 mxListBoxPage->FillFields(maPivotParameters.maPageFields);
322 void ScPivotLayoutDialog::SetActive()
324 if (mbDialogLostFocus)
326 mbDialogLostFocus = false;
327 if(mpActiveEdit != nullptr)
329 mpActiveEdit->GrabFocus();
330 if (mpActiveEdit == mxSourceEdit.get())
331 UpdateSourceRange();
334 else
336 m_xDialog->grab_focus();
339 RefInputDone();
342 void ScPivotLayoutDialog::SetReference(const ScRange& rReferenceRange, ScDocument& rDocument)
344 if (!mbDialogLostFocus)
345 return;
347 if (mpActiveEdit == nullptr)
348 return;
350 if (rReferenceRange.aStart != rReferenceRange.aEnd)
351 RefInputStart(mpActiveEdit);
353 OUString aReferenceString = rReferenceRange.Format(rDocument, ScRefFlags::RANGE_ABS_3D, maAddressDetails);
355 if (mpActiveEdit == mxSourceEdit.get())
357 mxSourceEdit->SetRefString(aReferenceString);
359 else if (mpActiveEdit == mxDestinationEdit.get())
361 mxDestinationEdit->SetRefString(aReferenceString);
365 bool ScPivotLayoutDialog::IsRefInputMode() const
367 return mbDialogLostFocus;
370 void ScPivotLayoutDialog::ItemInserted(const ScItemValue* pItemValue, ScPivotLayoutTreeList::SvPivotTreeListType eType)
372 if (pItemValue == nullptr)
373 return;
375 switch (eType)
377 case ScPivotLayoutTreeList::ROW_LIST:
378 case ScPivotLayoutTreeList::COLUMN_LIST:
379 case ScPivotLayoutTreeList::PAGE_LIST:
381 mxListBoxRow->RemoveEntryForItem(pItemValue);
382 mxListBoxColumn->RemoveEntryForItem(pItemValue);
383 mxListBoxPage->RemoveEntryForItem(pItemValue);
385 break;
386 case ScPivotLayoutTreeList::LABEL_LIST:
388 mxListBoxRow->RemoveEntryForItem(pItemValue);
389 mxListBoxColumn->RemoveEntryForItem(pItemValue);
390 mxListBoxPage->RemoveEntryForItem(pItemValue);
391 mxListBoxData->RemoveEntryForItem(pItemValue);
393 break;
394 default:
395 break;
399 void ScPivotLayoutDialog::UpdateSourceRange()
401 if (!maPivotTableObject.GetSheetDesc())
402 return;
404 ScSheetSourceDesc aSourceSheet = *maPivotTableObject.GetSheetDesc();
406 if (mxSourceRadioNamedRange->get_active())
408 OUString aEntryString = mxSourceListBox->get_active_text();
409 ScRange aSourceRange = lclGetRangeForNamedRange(aEntryString, mrDocument);
410 if (!aSourceRange.IsValid() || aSourceSheet.GetSourceRange() == aSourceRange)
411 return;
412 aSourceSheet.SetRangeName(aEntryString);
414 else if (mxSourceRadioSelection->get_active())
416 OUString aSourceString = mxSourceEdit->GetText();
417 ScRange aSourceRange;
418 ScRefFlags nResult = aSourceRange.Parse(aSourceString, mrDocument, maAddressDetails);
420 bool bIsValid = (nResult & ScRefFlags::VALID) == ScRefFlags::VALID; // aSourceString is valid
422 mxSourceEdit->SetRefValid(true);
424 if (bIsValid)
426 ScRefAddress aStart;
427 ScRefAddress aEnd;
429 ConvertDoubleRef(mrDocument, aSourceString, 1, aStart, aEnd, maAddressDetails);
430 aSourceRange.aStart = aStart.GetAddress();
431 aSourceRange.aEnd = aEnd.GetAddress();
433 else
435 aSourceRange = lclGetRangeForNamedRange(aSourceString, mrDocument);
438 if (!aSourceRange.IsValid())
440 mxSourceEdit->SetRefValid(false);
441 return;
444 if (aSourceSheet.GetSourceRange() == aSourceRange)
445 return;
447 aSourceSheet.SetSourceRange(aSourceRange);
448 if (aSourceSheet.CheckSourceRange())
450 mxSourceEdit->SetRefValid(false);
451 return;
454 else
456 return;
459 maPivotTableObject.SetSheetDesc(aSourceSheet);
460 maPivotTableObject.FillOldParam(maPivotParameters);
461 maPivotTableObject.FillLabelData(maPivotParameters);
463 FillValuesToListBoxes();
466 void ScPivotLayoutDialog::ApplyChanges()
468 ScDPSaveData aSaveData;
469 ApplySaveData(aSaveData);
470 ApplyLabelData(aSaveData);
472 ScDPObject *pOldDPObj = mrDocument.GetDPAtCursor( maPivotParameters.nCol, maPivotParameters.nRow, maPivotParameters.nTab);
473 ScRange aDestinationRange;
474 bool bToNewSheet = false;
476 if (!GetDestination(aDestinationRange, bToNewSheet))
477 return;
479 SetDispatcherLock(false);
480 SwitchToDocument();
482 sal_uInt16 nWhichPivot = ScModule::get()->GetPool().GetWhichIDFromSlotID(SID_PIVOT_TABLE);
483 ScPivotItem aPivotItem(nWhichPivot, &aSaveData, &aDestinationRange, bToNewSheet);
484 mpViewData->GetViewShell()->SetDialogDPObject(std::make_unique<ScDPObject>(maPivotTableObject));
487 SfxDispatcher* pDispatcher = GetBindings().GetDispatcher();
488 SfxCallMode const nCallMode = SfxCallMode::SLOT | SfxCallMode::RECORD;
489 const SfxPoolItemHolder aResult(pDispatcher->ExecuteList(SID_PIVOT_TABLE,
490 nCallMode, { &aPivotItem }));
492 if (aResult)
494 // existing pivot table might have moved to a new range or a new sheet
495 if ( pOldDPObj != nullptr )
497 const ScRange& rOldRange = pOldDPObj->GetOutRange();
499 ScDPObject *pDPObj = nullptr;
500 // FIXME: if the new range overlaps with the old one, the table actually doesn't move
501 // and shouldn't therefore be deleted
502 if ( ( ( rOldRange != aDestinationRange ) && !rOldRange.Contains( aDestinationRange ) )
503 || bToNewSheet )
505 pDPObj = mrDocument.GetDPAtCursor( maPivotParameters.nCol, maPivotParameters.nRow, maPivotParameters.nTab);
507 if (pDPObj)
509 ScDBDocFunc aFunc( *(mpViewData->GetDocShell() ));
510 aFunc.RemovePivotTable( *pDPObj, true, false);
511 mpViewData->GetView()->CursorPosChanged();
514 return;
517 SetDispatcherLock(true);
520 void ScPivotLayoutDialog::ApplySaveData(ScDPSaveData& rSaveData)
522 rSaveData.SetIgnoreEmptyRows(mxCheckIgnoreEmptyRows->get_active());
523 rSaveData.SetRepeatIfEmpty(mxCheckIdentifyCategories->get_active());
524 rSaveData.SetColumnGrand(mxCheckTotalColumns->get_active());
525 rSaveData.SetRowGrand(mxCheckTotalRows->get_active());
526 rSaveData.SetFilterButton(mxCheckAddFilter->get_active());
527 rSaveData.SetDrillDown(mxCheckDrillToDetail->get_active());
528 rSaveData.SetExpandCollapse(mxCheckExpandCollapse->get_active());
530 Reference<XDimensionsSupplier> xSource = maPivotTableObject.GetSource();
532 ScPivotFieldVector aPageFieldVector;
533 mxListBoxPage->PushEntriesToPivotFieldVector(aPageFieldVector);
534 ScDPObject::ConvertOrientation(rSaveData, aPageFieldVector, DataPilotFieldOrientation_PAGE,
535 xSource, maPivotParameters.maLabelArray);
537 ScPivotFieldVector aColFieldVector;
538 mxListBoxColumn->PushEntriesToPivotFieldVector(aColFieldVector);
539 ScDPObject::ConvertOrientation(rSaveData, aColFieldVector, DataPilotFieldOrientation_COLUMN,
540 xSource, maPivotParameters.maLabelArray);
542 ScPivotFieldVector aRowFieldVector;
543 mxListBoxRow->PushEntriesToPivotFieldVector(aRowFieldVector);
544 ScDPObject::ConvertOrientation(rSaveData, aRowFieldVector, DataPilotFieldOrientation_ROW,
545 xSource, maPivotParameters.maLabelArray);
547 ScPivotFieldVector aDataFieldVector;
548 mxListBoxData->PushEntriesToPivotFieldVector(aDataFieldVector);
549 ScDPObject::ConvertOrientation(rSaveData, aDataFieldVector, DataPilotFieldOrientation_DATA,
550 xSource, maPivotParameters.maLabelArray,
551 &aColFieldVector, &aRowFieldVector, &aPageFieldVector);
554 void ScPivotLayoutDialog::ApplyLabelData(const ScDPSaveData& rSaveData)
556 ScDPLabelDataVector& rLabelDataVector = GetLabelDataVector();
558 for (std::unique_ptr<ScDPLabelData> const & pLabelData : rLabelDataVector)
560 OUString aUnoName = ScDPUtil::createDuplicateDimensionName(pLabelData->maName, pLabelData->mnDupCount);
561 ScDPSaveDimension* pSaveDimensions = rSaveData.GetExistingDimensionByName(aUnoName);
563 if (pSaveDimensions == nullptr)
564 continue;
566 pSaveDimensions->SetUsedHierarchy(pLabelData->mnUsedHier);
567 pSaveDimensions->SetShowEmpty(pLabelData->mbShowAll);
568 pSaveDimensions->SetRepeatItemLabels(pLabelData->mbRepeatItemLabels);
569 pSaveDimensions->SetSortInfo(&pLabelData->maSortInfo);
570 pSaveDimensions->SetLayoutInfo(&pLabelData->maLayoutInfo);
571 pSaveDimensions->SetAutoShowInfo(&pLabelData->maShowInfo);
573 bool bManualSort = (pLabelData->maSortInfo.Mode == DataPilotFieldSortMode::MANUAL);
575 for (ScDPLabelData::Member const & rLabelMember : pLabelData->maMembers)
577 ScDPSaveMember* pMember = pSaveDimensions->GetMemberByName(rLabelMember.maName);
579 if (bManualSort || !rLabelMember.mbVisible || !rLabelMember.mbShowDetails)
581 pMember->SetIsVisible(rLabelMember.mbVisible);
582 pMember->SetShowDetails(rLabelMember.mbShowDetails);
588 bool ScPivotLayoutDialog::GetDestination(ScRange& aDestinationRange, bool& bToNewSheet)
590 bToNewSheet = false;
592 if (mxDestinationRadioNamedRange->get_active())
594 OUString aName = mxDestinationListBox->get_active_text();
595 aDestinationRange = lclGetRangeForNamedRange(aName, mrDocument);
596 if (!aDestinationRange.IsValid())
597 return false;
599 else if (mxDestinationRadioSelection->get_active())
601 ScAddress aAddress;
602 aAddress.Parse(mxDestinationEdit->GetText(), mrDocument, maAddressDetails);
603 aDestinationRange = ScRange(aAddress);
605 else
607 bToNewSheet = true;
608 aDestinationRange = ScRange(maPivotParameters.nCol, maPivotParameters.nRow, maPivotParameters.nTab);
610 return true;
613 ScItemValue* ScPivotLayoutDialog::GetItem(SCCOL nColumn)
615 return mxListBoxField->GetItem(nColumn);
618 bool ScPivotLayoutDialog::IsDataElement(SCCOL nColumn)
620 return mxListBoxField->IsDataElement(nColumn);
623 ScDPLabelData& ScPivotLayoutDialog::GetLabelData(SCCOL nColumn)
625 return *maPivotParameters.maLabelArray[nColumn];
628 void ScPivotLayoutDialog::PushDataFieldNames(std::vector<ScDPName>& rDataFieldNames)
630 mxListBoxData->PushDataFieldNames(rDataFieldNames);
633 void ScPivotLayoutDialog::Close()
635 DoClose(ScPivotLayoutWrapper::GetChildWindowId());
636 SfxDialogController::Close();
639 IMPL_LINK_NOARG( ScPivotLayoutDialog, OKClicked, weld::Button&, void )
641 /* tdf#137726 hide so it's not a candidate to be parent of any error
642 messages that may appear because this dialog is going to disappear on
643 response(RET_OK) and the error dialog is not run in its own event loop
644 but instead async */
645 m_xDialog->hide();
647 ApplyChanges();
648 m_xDialog->response(RET_OK);
651 IMPL_LINK_NOARG( ScPivotLayoutDialog, CancelClicked, weld::Button&, void )
653 m_xDialog->response(RET_CANCEL);
656 IMPL_LINK(ScPivotLayoutDialog, GetEditFocusHandler, formula::RefEdit&, rCtrl, void)
658 mpActiveEdit = &rCtrl;
659 mpActiveEdit->SelectAll();
662 IMPL_LINK(ScPivotLayoutDialog, GetButtonFocusHandler, formula::RefButton&, rCtrl, void)
664 mpActiveEdit = nullptr;
666 if (&rCtrl == mxSourceButton.get())
667 mpActiveEdit = mxSourceEdit.get();
668 else if (&rCtrl == mxDestinationButton.get())
669 mpActiveEdit = mxDestinationEdit.get();
671 if (mpActiveEdit)
672 mpActiveEdit->SelectAll();
675 IMPL_LINK_NOARG(ScPivotLayoutDialog, LoseEditFocusHandler, formula::RefEdit&, void)
677 mbDialogLostFocus = !m_xDialog->has_toplevel_focus();
680 IMPL_LINK_NOARG(ScPivotLayoutDialog, LoseButtonFocusHandler, formula::RefButton&, void)
682 mbDialogLostFocus = !m_xDialog->has_toplevel_focus();
685 IMPL_LINK_NOARG(ScPivotLayoutDialog, SourceListSelected, weld::ComboBox&, void)
687 UpdateSourceRange();
690 IMPL_LINK_NOARG(ScPivotLayoutDialog, SourceEditModified, formula::RefEdit&, void)
692 UpdateSourceRange();
695 IMPL_LINK_NOARG(ScPivotLayoutDialog, ToggleSource, weld::Toggleable&, void)
697 ToggleSource();
700 void ScPivotLayoutDialog::ToggleSource()
702 bool bNamedRange = mxSourceRadioNamedRange->get_active();
703 bool bSelection = mxSourceRadioSelection->get_active();
704 mxSourceListBox->set_sensitive(bNamedRange);
705 mxSourceButton->GetWidget()->set_sensitive(bSelection);
706 mxSourceEdit->GetWidget()->set_sensitive(bSelection);
707 UpdateSourceRange();
710 IMPL_LINK_NOARG(ScPivotLayoutDialog, ToggleDestination, weld::Toggleable&, void)
712 ToggleDestination();
715 void ScPivotLayoutDialog::ToggleDestination()
717 bool bNamedRange = mxDestinationRadioNamedRange->get_active();
718 bool bSelection = mxDestinationRadioSelection->get_active();
719 mxDestinationListBox->set_sensitive(bNamedRange);
720 mxDestinationButton->GetWidget()->set_sensitive(bSelection);
721 mxDestinationEdit->GetWidget()->set_sensitive(bSelection);
724 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */