LibreOffice Module sc (master)  1
pvfundlg.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 #undef SC_DLLIMPLEMENTATION
21 
22 #include <pvfundlg.hxx>
23 
24 #include <com/sun/star/sheet/DataPilotFieldReferenceType.hpp>
25 #include <com/sun/star/sheet/DataPilotFieldReferenceItemType.hpp>
26 #include <com/sun/star/sheet/DataPilotFieldLayoutMode.hpp>
27 #include <com/sun/star/sheet/DataPilotFieldSortMode.hpp>
28 #include <com/sun/star/sheet/DataPilotFieldShowItemsMode.hpp>
29 
30 #include <osl/diagnose.h>
31 
32 #include <scresid.hxx>
33 #include <dpobject.hxx>
34 #include <dpsave.hxx>
35 #include <pvfundlg.hrc>
36 #include <globstr.hrc>
37 #include <dputil.hxx>
38 
39 #include <vector>
40 
41 using namespace ::com::sun::star::sheet;
42 
43 using ::com::sun::star::uno::Sequence;
44 using ::std::vector;
45 
46 namespace {
47 
56 bool lclFillListBox(weld::ComboBox& rLBox, const Sequence< OUString >& rStrings)
57 {
58  bool bEmpty = false;
59  for (const OUString& str : rStrings)
60  {
61  if (!str.isEmpty())
62  rLBox.append_text(str);
63  else
64  {
65  rLBox.append_text(ScResId(STR_EMPTYDATA));
66  bEmpty = true;
67  }
68  }
69  return bEmpty;
70 }
71 
72 bool lclFillListBox(weld::ComboBox& rLBox, const vector<ScDPLabelData::Member>& rMembers, int nEmptyPos)
73 {
74  bool bEmpty = false;
75  vector<ScDPLabelData::Member>::const_iterator itr = rMembers.begin(), itrEnd = rMembers.end();
76  for (; itr != itrEnd; ++itr)
77  {
78  OUString aName = itr->getDisplayName();
79  if (!aName.isEmpty())
80  rLBox.append_text(aName);
81  else
82  {
83  rLBox.insert_text(nEmptyPos, ScResId(STR_EMPTYDATA));
84  bEmpty = true;
85  }
86  }
87  return bEmpty;
88 }
89 
90 bool lclFillListBox(weld::TreeView& rLBox, const vector<ScDPLabelData::Member>& rMembers)
91 {
92  bool bEmpty = false;
93  for (const auto& rMember : rMembers)
94  {
95  rLBox.append();
96  int pos = rLBox.n_children() - 1;
97  rLBox.set_toggle(pos, TRISTATE_FALSE);
98  OUString aName = rMember.getDisplayName();
99  if (!aName.isEmpty())
100  rLBox.set_text(pos, aName, 0);
101  else
102  {
103  rLBox.set_text(pos, ScResId(STR_EMPTYDATA), 0);
104  bEmpty = true;
105  }
106  }
107  return bEmpty;
108 }
109 
111 const PivotFunc spnFunctions[] =
112 {
125 };
126 
127 const sal_uInt16 SC_BASEITEM_PREV_POS = 0;
128 const sal_uInt16 SC_BASEITEM_NEXT_POS = 1;
129 const sal_uInt16 SC_BASEITEM_USER_POS = 2;
130 
131 const sal_uInt16 SC_SORTNAME_POS = 0;
132 const sal_uInt16 SC_SORTDATA_POS = 1;
133 
134 const tools::Long SC_SHOW_DEFAULT = 10;
135 
136 } // namespace
137 
138 ScDPFunctionListBox::ScDPFunctionListBox(std::unique_ptr<weld::TreeView> xControl)
139  : m_xControl(std::move(xControl))
140 {
142 }
143 
145 {
146  if( (nFuncMask == PivotFunc::NONE) || (nFuncMask == PivotFunc::Auto) )
147  m_xControl->unselect_all();
148  else
149  {
150  for( sal_Int32 nEntry = 0, nCount = m_xControl->n_children(); nEntry < nCount; ++nEntry )
151  {
152  if (bool(nFuncMask & spnFunctions[ nEntry ]))
153  m_xControl->select(nEntry);
154  else
155  m_xControl->unselect(nEntry);
156  }
157  }
158 }
159 
161 {
162  PivotFunc nFuncMask = PivotFunc::NONE;
163  std::vector<int> aRows = m_xControl->get_selected_rows();
164  for (int nSel : aRows)
165  nFuncMask |= spnFunctions[nSel];
166  return nFuncMask;
167 }
168 
170 {
171  OSL_ENSURE( !m_xControl->n_children(), "ScDPMultiFuncListBox::FillFunctionNames - do not add texts to resource" );
172  m_xControl->clear();
173  m_xControl->freeze();
174  for (size_t nIndex = 0; nIndex < SAL_N_ELEMENTS(SCSTR_DPFUNCLISTBOX); ++nIndex)
175  m_xControl->append_text(ScResId(SCSTR_DPFUNCLISTBOX[nIndex]));
176  m_xControl->thaw();
177  assert(m_xControl->n_children() == SAL_N_ELEMENTS(spnFunctions));
178 }
179 
180 namespace
181 {
182  int FromDataPilotFieldReferenceType(int eMode)
183  {
184  switch (eMode)
185  {
187  return 0;
188  case DataPilotFieldReferenceType::ITEM_DIFFERENCE:
189  return 1;
190  case DataPilotFieldReferenceType::ITEM_PERCENTAGE:
191  return 2;
192  case DataPilotFieldReferenceType::ITEM_PERCENTAGE_DIFFERENCE:
193  return 3;
194  case DataPilotFieldReferenceType::RUNNING_TOTAL:
195  return 4;
196  case DataPilotFieldReferenceType::ROW_PERCENTAGE:
197  return 5;
198  case DataPilotFieldReferenceType::COLUMN_PERCENTAGE:
199  return 6;
200  case DataPilotFieldReferenceType::TOTAL_PERCENTAGE:
201  return 7;
202  case DataPilotFieldReferenceType::INDEX:
203  return 8;
204  }
205  return -1;
206  }
207 
208  int ToDataPilotFieldReferenceType(int nPos)
209  {
210  switch (nPos)
211  {
212  case 0:
214  case 1:
215  return DataPilotFieldReferenceType::ITEM_DIFFERENCE;
216  case 2:
217  return DataPilotFieldReferenceType::ITEM_PERCENTAGE;
218  case 3:
219  return DataPilotFieldReferenceType::ITEM_PERCENTAGE_DIFFERENCE;
220  case 4:
221  return DataPilotFieldReferenceType::RUNNING_TOTAL;
222  case 5:
223  return DataPilotFieldReferenceType::ROW_PERCENTAGE;
224  case 6:
225  return DataPilotFieldReferenceType::COLUMN_PERCENTAGE;
226  case 7:
227  return DataPilotFieldReferenceType::TOTAL_PERCENTAGE;
228  case 8:
229  return DataPilotFieldReferenceType::INDEX;
230  }
232 
233  }
234 }
235 
237  weld::Widget* pParent, const ScDPLabelDataVector& rLabelVec,
238  const ScDPLabelData& rLabelData, const ScPivotFuncData& rFuncData)
239  : GenericDialogController(pParent, "modules/scalc/ui/datafielddialog.ui", "DataFieldDialog")
240  , mxLbFunc(new ScDPFunctionListBox(m_xBuilder->weld_tree_view("functions")))
241  , mxFtName(m_xBuilder->weld_label("name"))
242  , mxLbType(m_xBuilder->weld_combo_box("type"))
243  , mxFtBaseField(m_xBuilder->weld_label("basefieldft"))
244  , mxLbBaseField(m_xBuilder->weld_combo_box("basefield"))
245  , mxFtBaseItem(m_xBuilder->weld_label("baseitemft"))
246  , mxLbBaseItem(m_xBuilder->weld_combo_box("baseitem"))
247  , mxBtnOk(m_xBuilder->weld_button("ok"))
248  , mrLabelVec(rLabelVec)
249  , mbEmptyItem(false)
250 {
251  mxLbFunc->set_size_request(-1, mxLbFunc->get_height_rows(8));
252 
253  Init(rLabelData, rFuncData);
254 }
255 
257 {
258 }
259 
261 {
262  return mxLbFunc->GetSelection();
263 }
264 
265 DataPilotFieldReference ScDPFunctionDlg::GetFieldRef() const
266 {
267  DataPilotFieldReference aRef;
268 
269  aRef.ReferenceType = ToDataPilotFieldReferenceType(mxLbType->get_active());
270  aRef.ReferenceField = GetBaseFieldName(mxLbBaseField->get_active_text());
271 
272  sal_Int32 nBaseItemPos = mxLbBaseItem->get_active();
273  switch( nBaseItemPos )
274  {
275  case SC_BASEITEM_PREV_POS:
276  aRef.ReferenceItemType = DataPilotFieldReferenceItemType::PREVIOUS;
277  break;
278  case SC_BASEITEM_NEXT_POS:
279  aRef.ReferenceItemType = DataPilotFieldReferenceItemType::NEXT;
280  break;
281  default:
282  {
283  aRef.ReferenceItemType = DataPilotFieldReferenceItemType::NAMED;
284  if( !mbEmptyItem || (nBaseItemPos > SC_BASEITEM_USER_POS) )
285  aRef.ReferenceItemName = GetBaseItemName(mxLbBaseItem->get_active_text());
286  }
287  }
288 
289  return aRef;
290 }
291 
292 void ScDPFunctionDlg::Init( const ScDPLabelData& rLabelData, const ScPivotFuncData& rFuncData )
293 {
294  // list box
295  PivotFunc nFuncMask = (rFuncData.mnFuncMask == PivotFunc::NONE) ? PivotFunc::Sum : rFuncData.mnFuncMask;
296  mxLbFunc->SetSelection( nFuncMask );
297 
298  // field name
299  mxFtName->set_label(rLabelData.getDisplayName());
300 
301  // handlers
302  mxLbFunc->connect_row_activated( LINK( this, ScDPFunctionDlg, DblClickHdl ) );
303  mxLbType->connect_changed( LINK( this, ScDPFunctionDlg, SelectHdl ) );
304  mxLbBaseField->connect_changed( LINK( this, ScDPFunctionDlg, SelectHdl ) );
305 
306  // base field list box
307  OUString aSelectedEntry;
308  for( const auto& rxLabel : mrLabelVec )
309  {
310  mxLbBaseField->append_text(rxLabel->getDisplayName());
311  maBaseFieldNameMap.emplace(rxLabel->getDisplayName(), rxLabel->maName);
312  if (rxLabel->maName == rFuncData.maFieldRef.ReferenceField)
313  aSelectedEntry = rxLabel->getDisplayName();
314  }
315 
316  // select field reference type
317  mxLbType->set_active(FromDataPilotFieldReferenceType(rFuncData.maFieldRef.ReferenceType));
318  SelectHdl( *mxLbType ); // enables base field/item list boxes
319 
320  // select base field
321  mxLbBaseField->set_active_text(aSelectedEntry);
322  if (mxLbBaseField->get_active() == -1)
323  mxLbBaseField->set_active(0);
324  SelectHdl( *mxLbBaseField ); // fills base item list, selects base item
325 
326  // select base item
327  switch( rFuncData.maFieldRef.ReferenceItemType )
328  {
329  case DataPilotFieldReferenceItemType::PREVIOUS:
330  mxLbBaseItem->set_active( SC_BASEITEM_PREV_POS );
331  break;
332  case DataPilotFieldReferenceItemType::NEXT:
333  mxLbBaseItem->set_active( SC_BASEITEM_NEXT_POS );
334  break;
335  default:
336  {
337  if( mbEmptyItem && rFuncData.maFieldRef.ReferenceItemName.isEmpty() )
338  {
339  // select special "(empty)" entry added before other items
340  mxLbBaseItem->set_active( SC_BASEITEM_USER_POS );
341  }
342  else
343  {
344  sal_Int32 nStartPos = mbEmptyItem ? (SC_BASEITEM_USER_POS + 1) : SC_BASEITEM_USER_POS;
345  sal_Int32 nPos = FindBaseItemPos( rFuncData.maFieldRef.ReferenceItemName, nStartPos );
346  if( nPos == -1)
347  nPos = (mxLbBaseItem->get_count() > SC_BASEITEM_USER_POS) ? SC_BASEITEM_USER_POS : SC_BASEITEM_PREV_POS;
348  mxLbBaseItem->set_active( nPos );
349  }
350  }
351  }
352 }
353 
354 const OUString& ScDPFunctionDlg::GetBaseFieldName(const OUString& rLayoutName) const
355 {
356  NameMapType::const_iterator itr = maBaseFieldNameMap.find(rLayoutName);
357  return itr == maBaseFieldNameMap.end() ? rLayoutName : itr->second;
358 }
359 
360 const OUString& ScDPFunctionDlg::GetBaseItemName(const OUString& rLayoutName) const
361 {
362  NameMapType::const_iterator itr = maBaseItemNameMap.find(rLayoutName);
363  return itr == maBaseItemNameMap.end() ? rLayoutName : itr->second;
364 }
365 
366 sal_Int32 ScDPFunctionDlg::FindBaseItemPos( const OUString& rEntry, sal_Int32 nStartPos ) const
367 {
368  sal_Int32 nPos = nStartPos;
369  bool bFound = false;
370  while (nPos < mxLbBaseItem->get_count())
371  {
372  // translate the displayed field name back to its original field name.
373  const OUString& rInName = mxLbBaseItem->get_text(nPos);
374  const OUString& rName = GetBaseItemName(rInName);
375  if (rName == rEntry)
376  {
377  bFound = true;
378  break;
379  }
380  ++nPos;
381  }
382  return bFound ? nPos : -1;
383 }
384 
385 IMPL_LINK( ScDPFunctionDlg, SelectHdl, weld::ComboBox&, rLBox, void )
386 {
387  if (&rLBox == mxLbType.get())
388  {
389  bool bEnableField, bEnableItem;
390  switch (ToDataPilotFieldReferenceType(mxLbType->get_active()))
391  {
392  case DataPilotFieldReferenceType::ITEM_DIFFERENCE:
393  case DataPilotFieldReferenceType::ITEM_PERCENTAGE:
394  case DataPilotFieldReferenceType::ITEM_PERCENTAGE_DIFFERENCE:
395  bEnableField = bEnableItem = true;
396  break;
397 
398  case DataPilotFieldReferenceType::RUNNING_TOTAL:
399  bEnableField = true;
400  bEnableItem = false;
401  break;
402 
403  default:
404  bEnableField = bEnableItem = false;
405  }
406 
407  bEnableField &= (mxLbBaseField->get_count() > 0);
408  mxFtBaseField->set_sensitive( bEnableField );
409  mxLbBaseField->set_sensitive( bEnableField );
410 
411  bEnableItem &= bEnableField;
412  mxFtBaseItem->set_sensitive( bEnableItem );
413  mxLbBaseItem->set_sensitive( bEnableItem );
414  }
415  else if (&rLBox == mxLbBaseField.get())
416  {
417  // keep "previous" and "next" entries
418  while (mxLbBaseItem->get_count() > SC_BASEITEM_USER_POS)
419  mxLbBaseItem->remove(SC_BASEITEM_USER_POS);
420 
421  // update item list for current base field
422  mbEmptyItem = false;
423  size_t nBasePos = mxLbBaseField->get_active();
424  if (nBasePos < mrLabelVec.size())
425  {
426  const vector<ScDPLabelData::Member>& rMembers = mrLabelVec[nBasePos]->maMembers;
427  mbEmptyItem = lclFillListBox(*mxLbBaseItem, rMembers, SC_BASEITEM_USER_POS);
428  // build cache for base names.
429  NameMapType aMap;
430  for (const auto& rMember : rMembers)
431  aMap.emplace(rMember.getDisplayName(), rMember.maName);
432  maBaseItemNameMap.swap(aMap);
433  }
434 
435  // select base item
436  sal_uInt16 nItemPos = (mxLbBaseItem->get_count() > SC_BASEITEM_USER_POS) ? SC_BASEITEM_USER_POS : SC_BASEITEM_PREV_POS;
437  mxLbBaseItem->set_active( nItemPos );
438  }
439 }
440 
442 {
443  m_xDialog->response(RET_OK);
444  return true;
445 }
446 
448  const ScDPLabelData& rLabelData, const ScPivotFuncData& rFuncData,
449  const ScDPNameVec& rDataFields, bool bEnableLayout)
450  : GenericDialogController(pParent, "modules/scalc/ui/pivotfielddialog.ui", "PivotFieldDialog")
451  , mrDPObj(rDPObj)
452  , mrDataFields(rDataFields)
453  , maLabelData(rLabelData)
454  , mbEnableLayout(bEnableLayout)
455  , mxRbNone(m_xBuilder->weld_radio_button("none"))
456  , mxRbAuto(m_xBuilder->weld_radio_button("auto"))
457  , mxRbUser(m_xBuilder->weld_radio_button("user"))
458  , mxLbFunc(new ScDPFunctionListBox(m_xBuilder->weld_tree_view("functions")))
459  , mxFtName(m_xBuilder->weld_label("name"))
460  , mxCbShowAll(m_xBuilder->weld_check_button("showall"))
461  , mxBtnOk(m_xBuilder->weld_button("ok"))
462  , mxBtnOptions(m_xBuilder->weld_button("options"))
463 {
464  mxLbFunc->set_selection_mode(SelectionMode::Multiple);
465  mxLbFunc->set_size_request(-1, mxLbFunc->get_height_rows(8));
466  Init(rLabelData, rFuncData);
467 }
468 
470 {
471 }
472 
474 {
475  PivotFunc nFuncMask = PivotFunc::NONE;
476 
477  if (mxRbAuto->get_active())
478  nFuncMask = PivotFunc::Auto;
479  else if (mxRbUser->get_active())
480  nFuncMask = mxLbFunc->GetSelection();
481 
482  return nFuncMask;
483 }
484 
486 {
487  rLabelData.mnFuncMask = GetFuncMask();
488  rLabelData.mnUsedHier = maLabelData.mnUsedHier;
489  rLabelData.mbShowAll = mxCbShowAll->get_active();
490  rLabelData.maMembers = maLabelData.maMembers;
491  rLabelData.maSortInfo = maLabelData.maSortInfo;
493  rLabelData.maShowInfo = maLabelData.maShowInfo;
495 }
496 
497 void ScDPSubtotalDlg::Init( const ScDPLabelData& rLabelData, const ScPivotFuncData& rFuncData )
498 {
499  // field name
500  mxFtName->set_label(rLabelData.getDisplayName());
501 
502  // radio buttons
503  mxRbNone->connect_clicked( LINK( this, ScDPSubtotalDlg, RadioClickHdl ) );
504  mxRbAuto->connect_clicked( LINK( this, ScDPSubtotalDlg, RadioClickHdl ) );
505  mxRbUser->connect_clicked( LINK( this, ScDPSubtotalDlg, RadioClickHdl ) );
506 
507  weld::RadioButton* pRBtn = nullptr;
508  switch( rFuncData.mnFuncMask )
509  {
510  case PivotFunc::NONE: pRBtn = mxRbNone.get(); break;
511  case PivotFunc::Auto: pRBtn = mxRbAuto.get(); break;
512  default: pRBtn = mxRbUser.get();
513  }
514  pRBtn->set_active(true);
515  RadioClickHdl(*pRBtn);
516 
517  // list box
518  mxLbFunc->SetSelection( rFuncData.mnFuncMask );
519  mxLbFunc->connect_row_activated( LINK( this, ScDPSubtotalDlg, DblClickHdl ) );
520 
521  // show all
522  mxCbShowAll->set_active( rLabelData.mbShowAll );
523 
524  // options
525  mxBtnOptions->connect_clicked( LINK( this, ScDPSubtotalDlg, ClickHdl ) );
526 }
527 
528 IMPL_LINK(ScDPSubtotalDlg, RadioClickHdl, weld::Button&, rBtn, void)
529 {
530  mxLbFunc->set_sensitive(&rBtn == mxRbUser.get());
531 }
532 
534 {
535  m_xDialog->response(RET_OK);
536  return true;
537 }
538 
539 IMPL_LINK(ScDPSubtotalDlg, ClickHdl, weld::Button&, rBtn, void)
540 {
541  if (&rBtn == mxBtnOptions.get())
542  {
543  ScDPSubtotalOptDlg aDlg(m_xDialog.get(), mrDPObj, maLabelData, mrDataFields, mbEnableLayout);
544  if (aDlg.run() == RET_OK)
545  aDlg.FillLabelData(maLabelData);
546  }
547 }
548 
549 namespace
550 {
551  int FromDataPilotFieldLayoutMode(int eMode)
552  {
553  switch (eMode)
554  {
555  case DataPilotFieldLayoutMode::TABULAR_LAYOUT:
556  return 0;
557  case DataPilotFieldLayoutMode::OUTLINE_SUBTOTALS_TOP:
558  return 1;
559  case DataPilotFieldLayoutMode::OUTLINE_SUBTOTALS_BOTTOM:
560  return 2;
561  }
562  return -1;
563  }
564 
565  int ToDataPilotFieldLayoutMode(int nPos)
566  {
567  switch (nPos)
568  {
569  case 0:
570  return DataPilotFieldLayoutMode::TABULAR_LAYOUT;
571  case 1:
572  return DataPilotFieldLayoutMode::OUTLINE_SUBTOTALS_TOP;
573  case 2:
574  return DataPilotFieldLayoutMode::OUTLINE_SUBTOTALS_BOTTOM;
575  }
576  return DataPilotFieldLayoutMode::TABULAR_LAYOUT;
577  }
578 
579  int FromDataPilotFieldShowItemsMode(int eMode)
580  {
581  switch (eMode)
582  {
583  case DataPilotFieldShowItemsMode::FROM_TOP:
584  return 0;
585  case DataPilotFieldShowItemsMode::FROM_BOTTOM:
586  return 1;
587  }
588  return -1;
589  }
590 
591  int ToDataPilotFieldShowItemsMode(int nPos)
592  {
593  switch (nPos)
594  {
595  case 0:
596  return DataPilotFieldShowItemsMode::FROM_TOP;
597  case 1:
598  return DataPilotFieldShowItemsMode::FROM_BOTTOM;
599  }
600  return DataPilotFieldShowItemsMode::FROM_TOP;
601  }
602 }
603 
605  const ScDPLabelData& rLabelData, const ScDPNameVec& rDataFields,
606  bool bEnableLayout )
607  : GenericDialogController(pParent, "modules/scalc/ui/datafieldoptionsdialog.ui",
608  "DataFieldOptionsDialog")
609  , m_xLbSortBy(m_xBuilder->weld_combo_box("sortby"))
610  , m_xRbSortAsc(m_xBuilder->weld_radio_button("ascending"))
611  , m_xRbSortDesc(m_xBuilder->weld_radio_button("descending"))
612  , m_xRbSortMan(m_xBuilder->weld_radio_button("manual"))
613  , m_xLayoutFrame(m_xBuilder->weld_widget("layoutframe"))
614  , m_xLbLayout(m_xBuilder->weld_combo_box("layout"))
615  , m_xCbLayoutEmpty(m_xBuilder->weld_check_button("emptyline"))
616  , m_xCbRepeatItemLabels(m_xBuilder->weld_check_button("repeatitemlabels"))
617  , m_xCbShow(m_xBuilder->weld_check_button("show"))
618  , m_xNfShow(m_xBuilder->weld_spin_button("items"))
619  , m_xFtShow(m_xBuilder->weld_label("showft"))
620  , m_xFtShowFrom(m_xBuilder->weld_label("showfromft"))
621  , m_xLbShowFrom(m_xBuilder->weld_combo_box("from"))
622  , m_xFtShowUsing(m_xBuilder->weld_label("usingft"))
623  , m_xLbShowUsing(m_xBuilder->weld_combo_box("using"))
624  , m_xHideFrame(m_xBuilder->weld_widget("hideframe"))
625  , m_xLbHide(m_xBuilder->weld_tree_view("hideitems"))
626  , m_xFtHierarchy(m_xBuilder->weld_label("hierarchyft"))
627  , m_xLbHierarchy(m_xBuilder->weld_combo_box("hierarchy"))
628  , mrDPObj(rDPObj)
629  , maLabelData(rLabelData)
630 {
631  m_xLbHide->enable_toggle_buttons(weld::ColumnToggleType::Check);
632 
633  m_xLbSortBy->set_size_request(m_xLbSortBy->get_approximate_digit_width() * 18, -1);
634  m_xLbHide->set_size_request(-1, m_xLbHide->get_height_rows(5));
635  Init(rDataFields, bEnableLayout);
636 }
637 
639 {
640 }
641 
643 {
644  // *** SORTING ***
645 
646  if (m_xRbSortMan->get_active())
647  rLabelData.maSortInfo.Mode = DataPilotFieldSortMode::MANUAL;
648  else if (m_xLbSortBy->get_active() == SC_SORTNAME_POS)
649  rLabelData.maSortInfo.Mode = DataPilotFieldSortMode::NAME;
650  else
651  rLabelData.maSortInfo.Mode = DataPilotFieldSortMode::DATA;
652 
653  ScDPName aFieldName = GetFieldName(m_xLbSortBy->get_active_text());
654  if (!aFieldName.maName.isEmpty())
655  {
656  rLabelData.maSortInfo.Field =
657  ScDPUtil::createDuplicateDimensionName(aFieldName.maName, aFieldName.mnDupCount);
658  rLabelData.maSortInfo.IsAscending = m_xRbSortAsc->get_active();
659  }
660 
661  // *** LAYOUT MODE ***
662 
663  rLabelData.maLayoutInfo.LayoutMode = ToDataPilotFieldLayoutMode(m_xLbLayout->get_active());
664  rLabelData.maLayoutInfo.AddEmptyLines = m_xCbLayoutEmpty->get_active();
665  rLabelData.mbRepeatItemLabels = m_xCbRepeatItemLabels->get_active();
666 
667  // *** AUTO SHOW ***
668 
669  aFieldName = GetFieldName(m_xLbShowUsing->get_active_text());
670  if (!aFieldName.maName.isEmpty())
671  {
672  rLabelData.maShowInfo.IsEnabled = m_xCbShow->get_active();
673  rLabelData.maShowInfo.ShowItemsMode = ToDataPilotFieldShowItemsMode(m_xLbShowFrom->get_active());
674  rLabelData.maShowInfo.ItemCount = sal::static_int_cast<sal_Int32>( m_xNfShow->get_value() );
675  rLabelData.maShowInfo.DataField =
676  ScDPUtil::createDuplicateDimensionName(aFieldName.maName, aFieldName.mnDupCount);
677  }
678 
679  // *** HIDDEN ITEMS ***
680 
681  rLabelData.maMembers = maLabelData.maMembers;
682  int nVisCount = m_xLbHide->n_children();
683  for (int nPos = 0; nPos < nVisCount; ++nPos)
684  rLabelData.maMembers[nPos].mbVisible = m_xLbHide->get_toggle(nPos) == TRISTATE_FALSE;
685 
686  // *** HIERARCHY ***
687 
688  rLabelData.mnUsedHier = m_xLbHierarchy->get_active() != -1 ? m_xLbHierarchy->get_active() : 0;
689 }
690 
691 void ScDPSubtotalOptDlg::Init( const ScDPNameVec& rDataFields, bool bEnableLayout )
692 {
693  // *** SORTING ***
694 
695  sal_Int32 nSortMode = maLabelData.maSortInfo.Mode;
696 
697  // sort fields list box
698  m_xLbSortBy->append_text(maLabelData.getDisplayName());
699 
700  for( const auto& rDataField : rDataFields )
701  {
702  // Cache names for later lookup.
703  maDataFieldNameMap.emplace(rDataField.maLayoutName, rDataField);
704 
705  m_xLbSortBy->append_text(rDataField.maLayoutName);
706  m_xLbShowUsing->append_text(rDataField.maLayoutName); // for AutoShow
707  }
708 
709  sal_Int32 nSortPos = SC_SORTNAME_POS;
710  if( nSortMode == DataPilotFieldSortMode::DATA )
711  {
712  nSortPos = FindListBoxEntry( *m_xLbSortBy, maLabelData.maSortInfo.Field, SC_SORTDATA_POS );
713  if( nSortPos == -1 )
714  {
715  nSortPos = SC_SORTNAME_POS;
716  nSortMode = DataPilotFieldSortMode::MANUAL;
717  }
718  }
719  m_xLbSortBy->set_active(nSortPos);
720 
721  // sorting mode
722  m_xRbSortAsc->connect_clicked( LINK( this, ScDPSubtotalOptDlg, RadioClickHdl ) );
723  m_xRbSortDesc->connect_clicked( LINK( this, ScDPSubtotalOptDlg, RadioClickHdl ) );
724  m_xRbSortMan->connect_clicked( LINK( this, ScDPSubtotalOptDlg, RadioClickHdl ) );
725 
726  weld::RadioButton* pRBtn = nullptr;
727  switch( nSortMode )
728  {
730  case DataPilotFieldSortMode::MANUAL:
731  pRBtn = m_xRbSortMan.get();
732  break;
733  default:
734  pRBtn = maLabelData.maSortInfo.IsAscending ? m_xRbSortAsc.get() : m_xRbSortDesc.get();
735  }
736  pRBtn->set_active(true);
737  RadioClickHdl(*pRBtn);
738 
739  // *** LAYOUT MODE ***
740 
741  m_xLayoutFrame->set_sensitive(bEnableLayout);
742 
743  m_xLbLayout->set_active(FromDataPilotFieldLayoutMode(maLabelData.maLayoutInfo.LayoutMode));
744  m_xCbLayoutEmpty->set_active( maLabelData.maLayoutInfo.AddEmptyLines );
746 
747  // *** AUTO SHOW ***
748 
749  m_xCbShow->set_active( maLabelData.maShowInfo.IsEnabled );
750  m_xCbShow->connect_clicked( LINK( this, ScDPSubtotalOptDlg, CheckHdl ) );
751 
752  m_xLbShowFrom->set_active(FromDataPilotFieldShowItemsMode(maLabelData.maShowInfo.ShowItemsMode));
753  tools::Long nCount = static_cast< tools::Long >( maLabelData.maShowInfo.ItemCount );
754  if( nCount < 1 )
755  nCount = SC_SHOW_DEFAULT;
756  m_xNfShow->set_value( nCount );
757 
758  // m_xLbShowUsing already filled above
759  m_xLbShowUsing->set_active_text(maLabelData.maShowInfo.DataField);
760  if (m_xLbShowUsing->get_active() == -1)
761  m_xLbShowUsing->set_active(0);
762 
763  CheckHdl(*m_xCbShow); // enable/disable dependent controls
764 
765  // *** HIDDEN ITEMS ***
766 
767  InitHideListBox();
768 
769  // *** HIERARCHY ***
770 
771  if( maLabelData.maHiers.getLength() > 1 )
772  {
773  lclFillListBox(*m_xLbHierarchy, maLabelData.maHiers);
774  sal_Int32 nHier = maLabelData.mnUsedHier;
775  if( (nHier < 0) || (nHier >= maLabelData.maHiers.getLength()) ) nHier = 0;
776  m_xLbHierarchy->set_active( nHier );
777  m_xLbHierarchy->connect_changed( LINK( this, ScDPSubtotalOptDlg, SelectHdl ) );
778  }
779  else
780  {
781  m_xFtHierarchy->set_sensitive(false);
782  m_xLbHierarchy->set_sensitive(false);
783  }
784 }
785 
787 {
788  m_xLbHide->clear();
789  lclFillListBox(*m_xLbHide, maLabelData.maMembers);
790  size_t n = maLabelData.maMembers.size();
791  for (size_t i = 0; i < n; ++i)
792  m_xLbHide->set_toggle(i, maLabelData.maMembers[i].mbVisible ? TRISTATE_FALSE : TRISTATE_TRUE);
793  bool bEnable = m_xLbHide->n_children() > 0;
794  m_xHideFrame->set_sensitive(bEnable);
795 }
796 
797 ScDPName ScDPSubtotalOptDlg::GetFieldName(const OUString& rLayoutName) const
798 {
799  NameMapType::const_iterator itr = maDataFieldNameMap.find(rLayoutName);
800  return itr == maDataFieldNameMap.end() ? ScDPName() : itr->second;
801 }
802 
804  const weld::ComboBox& rLBox, const OUString& rEntry, sal_Int32 nStartPos ) const
805 {
806  sal_Int32 nPos = nStartPos;
807  bool bFound = false;
808  while (nPos < rLBox.get_count())
809  {
810  // translate the displayed field name back to its original field name.
811  ScDPName aName = GetFieldName(rLBox.get_text(nPos));
812  OUString aUnoName = ScDPUtil::createDuplicateDimensionName(aName.maName, aName.mnDupCount);
813  if (aUnoName == rEntry)
814  {
815  bFound = true;
816  break;
817  }
818  ++nPos;
819  }
820  return bFound ? nPos : -1;
821 }
822 
823 IMPL_LINK(ScDPSubtotalOptDlg, RadioClickHdl, weld::Button&, rBtn, void)
824 {
825  m_xLbSortBy->set_sensitive(&rBtn != m_xRbSortMan.get());
826 }
827 
828 IMPL_LINK(ScDPSubtotalOptDlg, CheckHdl, weld::Button&, rCBox, void)
829 {
830  if (&rCBox == m_xCbShow.get())
831  {
832  bool bEnable = m_xCbShow->get_active();
833  m_xNfShow->set_sensitive( bEnable );
834  m_xFtShow->set_sensitive( bEnable );
835  m_xFtShowFrom->set_sensitive( bEnable );
836  m_xLbShowFrom->set_sensitive( bEnable );
837 
838  bool bEnableUsing = bEnable && (m_xLbShowUsing->get_count() > 0);
839  m_xFtShowUsing->set_sensitive(bEnableUsing);
840  m_xLbShowUsing->set_sensitive(bEnableUsing);
841  }
842 }
843 
845 {
846  mrDPObj.GetMembers(maLabelData.mnCol, m_xLbHierarchy->get_active(), maLabelData.maMembers);
847  InitHideListBox();
848 }
849 
850 ScDPShowDetailDlg::ScDPShowDetailDlg(weld::Window* pParent, ScDPObject& rDPObj, css::sheet::DataPilotFieldOrientation nOrient)
851  : GenericDialogController(pParent, "modules/scalc/ui/showdetaildialog.ui", "ShowDetail")
852  , mrDPObj(rDPObj)
853  , mxLbDims(m_xBuilder->weld_tree_view("dimsTreeview"))
854 {
855  ScDPSaveData* pSaveData = rDPObj.GetSaveData();
856  tools::Long nDimCount = rDPObj.GetDimCount();
857  for (tools::Long nDim=0; nDim<nDimCount; nDim++)
858  {
859  bool bIsDataLayout;
860  sal_Int32 nDimFlags = 0;
861  OUString aName = rDPObj.GetDimName( nDim, bIsDataLayout, &nDimFlags );
862  if ( !bIsDataLayout && !rDPObj.IsDuplicated( nDim ) && ScDPObject::IsOrientationAllowed( nOrient, nDimFlags ) )
863  {
864  const ScDPSaveDimension* pDimension = pSaveData ? pSaveData->GetExistingDimensionByName(aName) : nullptr;
865  if ( !pDimension || (pDimension->GetOrientation() != nOrient) )
866  {
867  if (pDimension)
868  {
869  const std::optional<OUString> & pLayoutName = pDimension->GetLayoutName();
870  if (pLayoutName)
871  aName = *pLayoutName;
872  }
873  mxLbDims->append_text(aName);
874  maNameIndexMap.emplace(aName, nDim);
875  }
876  }
877  }
878  if (mxLbDims->n_children())
879  mxLbDims->select(0);
880 
881  mxLbDims->connect_row_activated(LINK(this, ScDPShowDetailDlg, DblClickHdl));
882 }
883 
885 {
886 }
887 
889 {
890  return mxLbDims->n_children() ? GenericDialogController::run() : static_cast<short>(RET_CANCEL);
891 }
892 
894 {
895  // Look up the internal dimension name which may be different from the
896  // displayed field name.
897  OUString aSelectedName = mxLbDims->get_selected_text();
898  DimNameIndexMap::const_iterator itr = maNameIndexMap.find(aSelectedName);
899  if (itr == maNameIndexMap.end())
900  // This should never happen!
901  return aSelectedName;
902 
903  tools::Long nDim = itr->second;
904  bool bIsDataLayout = false;
905  return mrDPObj.GetDimName(nDim, bIsDataLayout);
906 }
907 
909 {
910  m_xDialog->response(RET_OK);
911  return true;
912 }
913 
914 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void set_text(int row, const OUString &rText, int col=-1)=0
std::unique_ptr< weld::ComboBox > m_xLbShowUsing
Definition: pvfundlg.hxx:164
static SC_DLLPUBLIC OUString createDuplicateDimensionName(const OUString &rOriginal, size_t nDupCount)
Definition: dputil.cxx:90
void FillLabelData(ScDPLabelData &rLabelData) const
Definition: pvfundlg.cxx:485
const std::optional< OUString > & GetLayoutName() const
Definition: dpsave.cxx:384
sal_Int32 nIndex
OUString maName
Original name of the dimension.
Definition: pivot.hxx:59
std::vector< Member > maMembers
Definition: pivot.hxx:99
void Init(const ScDPLabelData &rLabelData, const ScPivotFuncData &rFuncData)
Definition: pvfundlg.cxx:292
std::unique_ptr< ScDPFunctionListBox > mxLbFunc
Definition: pvfundlg.hxx:76
sal_Int32 FindListBoxEntry(const weld::ComboBox &rLBox, const OUString &rEntry, sal_Int32 nStartPos) const
Searches for a listbox entry, starts search at specified position.
Definition: pvfundlg.cxx:803
std::unique_ptr< weld::RadioButton > m_xRbSortAsc
Definition: pvfundlg.hxx:151
void InitHideListBox()
Definition: pvfundlg.cxx:786
std::unique_ptr< weld::ComboBox > mxLbBaseField
Definition: pvfundlg.hxx:80
Reference< XControl > m_xControl
void insert_text(int pos, const OUString &rStr)
css::sheet::DataPilotFieldOrientation GetOrientation() const
Definition: dpsave.hxx:203
virtual ~ScDPSubtotalOptDlg() override
Definition: pvfundlg.cxx:638
tools::Long GetDimCount()
Definition: dpobject.cxx:1274
const ScDPLabelDataVector & mrLabelVec
Definition: pvfundlg.hxx:88
virtual OUString get_text(int pos) const =0
long Long
sal_Int64 n
ScDPSubtotalOptDlg(weld::Window *pParent, ScDPObject &rDPObj, const ScDPLabelData &rLabelData, const ScDPNameVec &rDataFields, bool bEnableLayout)
Definition: pvfundlg.cxx:604
sal_Int32 mnUsedHier
Used hierarchy.
Definition: pivot.hxx:75
bool mbShowAll
true = Show all (also empty) results.
Definition: pivot.hxx:78
virtual ~ScDPShowDetailDlg() override
Definition: pvfundlg.cxx:884
int nDimCount
TRISTATE_TRUE
RET_CANCEL
std::unique_ptr< weld::ComboBox > mxLbBaseItem
Definition: pvfundlg.hxx:82
void Init(const ScDPNameVec &rDataFields, bool bEnableLayout)
Definition: pvfundlg.cxx:691
ScDPName GetFieldName(const OUString &rLayoutName) const
Definition: pvfundlg.cxx:797
virtual int get_count() const =0
PivotFunc mnFuncMask
Definition: pivot.hxx:162
css::sheet::DataPilotFieldLayoutInfo maLayoutInfo
Layout info.
Definition: pivot.hxx:102
std::unique_ptr< weld::ComboBox > m_xLbShowFrom
Definition: pvfundlg.hxx:162
HashMap_OWString_Interface aMap
bool mbRepeatItemLabels
Definition: pivot.hxx:81
ScDPSubtotalDlg(weld::Widget *pParent, ScDPObject &rDPObj, const ScDPLabelData &rLabelData, const ScPivotFuncData &rFuncData, const ScDPNameVec &rDataFields, bool bEnableLayout)
Definition: pvfundlg.cxx:447
void Init(const ScDPLabelData &rLabelData, const ScPivotFuncData &rFuncData)
Definition: pvfundlg.cxx:497
ScDPLabelData maLabelData
The list of all data field names.
Definition: pvfundlg.hxx:114
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
size_t pos
std::unique_ptr< weld::RadioButton > mxRbUser
Definition: pvfundlg.hxx:119
std::unique_ptr< ScDPFunctionListBox > mxLbFunc
Definition: pvfundlg.hxx:120
int nCount
virtual int n_children() const =0
std::unique_ptr< weld::Label > m_xFtHierarchy
Definition: pvfundlg.hxx:167
css::sheet::DataPilotFieldReference maFieldRef
Definition: pivot.hxx:159
PivotFunc mnFuncMask
Page/Column/Row subtotal function.
Definition: pivot.hxx:74
std::unique_ptr< weld::ComboBox > m_xLbLayout
Definition: pvfundlg.hxx:155
PivotFunc
Definition: dpglobal.hxx:25
sal_Int32 FindBaseItemPos(const OUString &rEntry, sal_Int32 nStartPos) const
Searches for a listbox entry, starts search at specified position.
Definition: pvfundlg.cxx:366
virtual void set_active(bool active)=0
#define SAL_N_ELEMENTS(arr)
std::vector< ScDPName > ScDPNameVec
Definition: pivot.hxx:173
NameMapType maBaseFieldNameMap
Definition: pvfundlg.hxx:85
std::unique_ptr< weld::ComboBox > m_xLbHierarchy
Definition: pvfundlg.hxx:168
std::unique_ptr< weld::ComboBox > m_xLbSortBy
Definition: pvfundlg.hxx:150
virtual ~ScDPFunctionDlg() override
Definition: pvfundlg.cxx:256
virtual short run() override
Definition: pvfundlg.cxx:888
std::unique_ptr< weld::RadioButton > mxRbAuto
Definition: pvfundlg.hxx:118
ScDPShowDetailDlg(weld::Window *pParent, ScDPObject &rDPObj, css::sheet::DataPilotFieldOrientation nOrient)
Definition: pvfundlg.cxx:850
sal_uInt8 mnDupCount
Definition: pivot.hxx:61
int i
std::unique_ptr< weld::Label > mxFtName
Definition: pvfundlg.hxx:121
std::vector< std::unique_ptr< ScDPLabelData > > ScDPLabelDataVector
Definition: pivot.hxx:114
std::unique_ptr< weld::Button > mxBtnOptions
Definition: pvfundlg.hxx:124
std::unique_ptr< weld::RadioButton > mxRbNone
true = Enable Layout mode controls.
Definition: pvfundlg.hxx:117
virtual void set_toggle(int row, TriState eState, int col=-1)=0
TRISTATE_FALSE
std::unique_ptr< weld::TreeView > m_xControl
Definition: pvfundlg.hxx:49
SC_DLLPUBLIC ScDPSaveDimension * GetExistingDimensionByName(const OUString &rName) const
Definition: dpsave.cxx:845
OUString ScResId(const char *pId)
Definition: scdll.cxx:95
OUString GetDimensionName() const
Definition: pvfundlg.cxx:893
DimNameIndexMap maNameIndexMap
Definition: pvfundlg.hxx:198
ScDPSaveData * GetSaveData() const
Definition: dpobject.hxx:141
SC_DLLPUBLIC OUString const & getDisplayName() const
Definition: pivot2.cxx:66
std::unique_ptr< weld::CheckButton > mxCbShowAll
Definition: pvfundlg.hxx:122
void SetSelection(PivotFunc nFuncMask)
Definition: pvfundlg.cxx:144
virtual ~ScDPSubtotalDlg() override
Definition: pvfundlg.cxx:469
IMPL_LINK_NOARG(ScDPFunctionDlg, DblClickHdl, weld::TreeView &, bool)
Definition: pvfundlg.cxx:441
const OUString & GetBaseItemName(const OUString &rLayoutName) const
Definition: pvfundlg.cxx:360
const OUString & GetBaseFieldName(const OUString &rLayoutName) const
Definition: pvfundlg.cxx:354
ScDPFunctionListBox(std::unique_ptr< weld::TreeView > xControl)
Definition: pvfundlg.cxx:138
std::unique_ptr< weld::CheckButton > m_xCbShow
Definition: pvfundlg.hxx:158
std::unique_ptr< weld::SpinButton > m_xNfShow
Definition: pvfundlg.hxx:159
ScDPObject & mrDPObj
Definition: pvfundlg.hxx:199
void FillLabelData(ScDPLabelData &rLabelData) const
Definition: pvfundlg.cxx:642
std::unique_ptr< weld::ComboBox > mxLbType
Definition: pvfundlg.hxx:78
OUString GetDimName(tools::Long nDim, bool &rIsDataLayout, sal_Int32 *pFlags=nullptr)
Definition: dpobject.cxx:1196
std::unique_ptr< weld::TreeView > m_xLbHide
Definition: pvfundlg.hxx:166
std::unique_ptr< weld::CheckButton > m_xCbRepeatItemLabels
Definition: pvfundlg.hxx:157
static bool IsOrientationAllowed(css::sheet::DataPilotFieldOrientation nOrient, sal_Int32 nDimFlags)
Definition: dpobject.cxx:2705
std::unique_ptr< weld::Label > mxFtName
Definition: pvfundlg.hxx:77
NameMapType maDataFieldNameMap
Definition: pvfundlg.hxx:174
css::sheet::DataPilotFieldReference GetFieldRef() const
Definition: pvfundlg.cxx:265
css::uno::Sequence< OUString > maHiers
Hierarchies.
Definition: pivot.hxx:100
OUString aName
NameMapType maBaseItemNameMap
Definition: pvfundlg.hxx:86
RET_OK
css::sheet::DataPilotFieldSortInfo maSortInfo
Sorting info.
Definition: pivot.hxx:101
Reference< XExecutableDialog > m_xDialog
std::unique_ptr< weld::Widget > m_xLayoutFrame
Definition: pvfundlg.hxx:154
std::unique_ptr< weld::TreeView > mxLbDims
Definition: pvfundlg.hxx:201
bool IsDuplicated(tools::Long nDim)
Definition: dpobject.cxx:1245
void append(TreeIter *pRet=nullptr)
std::unique_ptr< weld::RadioButton > m_xRbSortMan
Definition: pvfundlg.hxx:153
ScDPFunctionDlg(weld::Widget *pParent, const ScDPLabelDataVector &rLabelVec, const ScDPLabelData &rLabelData, const ScPivotFuncData &rFuncData)
Definition: pvfundlg.cxx:236
IMPL_LINK(ScDPFunctionDlg, SelectHdl, weld::ComboBox &, rLBox, void)
Definition: pvfundlg.cxx:385
void append_text(const OUString &rStr)
if(!pCandidateA->getEnd().equal(pCandidateB->getStart()))
PivotFunc GetSelection() const
Definition: pvfundlg.cxx:160
std::unique_ptr< weld::Widget > m_xHideFrame
Definition: pvfundlg.hxx:165
PivotFunc GetFuncMask() const
Definition: pvfundlg.cxx:260
std::unique_ptr< weld::RadioButton > m_xRbSortDesc
Definition: pvfundlg.hxx:152
std::unique_ptr< weld::CheckButton > m_xCbLayoutEmpty
Definition: pvfundlg.hxx:156
sal_uInt16 nPos
css::sheet::DataPilotFieldAutoShowInfo maShowInfo
AutoShow info.
Definition: pivot.hxx:103
void FillFunctionNames()
Definition: pvfundlg.cxx:169
PivotFunc GetFuncMask() const
Definition: pvfundlg.cxx:473
bool mbEmptyItem
Data of all labels.
Definition: pvfundlg.hxx:89
ScDPLabelData maLabelData
The DataPilot object (for member names).
Definition: pvfundlg.hxx:171