LibreOffice Module sc (master)  1
PivotLayoutTreeList.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 
12 #include <memory>
13 #include <PivotLayoutTreeList.hxx>
14 #include <PivotLayoutDialog.hxx>
15 
16 #include <vcl/event.hxx>
17 #include <pivot.hxx>
18 
19 ScPivotLayoutTreeList::ScPivotLayoutTreeList(std::unique_ptr<weld::TreeView> xControl)
20  : ScPivotLayoutTreeListBase(std::move(xControl))
21 {
22  mxControl->connect_key_press(LINK(this, ScPivotLayoutTreeList, KeyInputHdl));
23  mxControl->connect_row_activated(LINK(this, ScPivotLayoutTreeList, DoubleClickHdl));
24 }
25 
27 {
28  if (mpSubtotalDlg)
29  {
32  }
33 }
34 
36 {
37  mpParent = pParent;
38  meType = eType;
39 }
40 
42 {
43  int nEntry = mxControl->get_cursor_index();
44  if (nEntry == -1)
45  return true;
46 
47  ScItemValue* pCurrentItemValue = weld::fromId<ScItemValue*>(mxControl->get_id(nEntry));
48  ScPivotFuncData& rCurrentFunctionData = pCurrentItemValue->maFunctionData;
49  SCCOL nCurrentColumn = rCurrentFunctionData.mnCol;
50 
51  if (mpParent->IsDataElement(nCurrentColumn))
52  return true;
53 
54  ScDPLabelData& rCurrentLabelData = mpParent->GetLabelData(nCurrentColumn);
55 
57 
58  maDataFieldNames.clear();
59  mpParent->PushDataFieldNames(maDataFieldNames);
60 
61  mpSubtotalDlg = pFactory->CreateScDPSubtotalDlg(mxControl.get(), mpParent->maPivotTableObject,
62  rCurrentLabelData, rCurrentFunctionData,
63  maDataFieldNames);
64 
65  mpSubtotalDlg->StartExecuteAsync([this, pCurrentItemValue, nCurrentColumn](int nResult) {
66  if (nResult == RET_OK)
67  {
68  mpSubtotalDlg->FillLabelData(mpParent->GetLabelData(nCurrentColumn));
69  pCurrentItemValue->maFunctionData.mnFuncMask = mpSubtotalDlg->GetFuncMask();
70  }
71 
72  mpSubtotalDlg.disposeAndClear();
73  });
74 
75  return true;
76 }
77 
79 {
80  mxControl->clear();
81  maItemValues.clear();
82 
83  for (const ScPivotField& rField : rFieldVector)
84  {
85  OUString aLabel = mpParent->GetItem(rField.nCol)->maName;
86  ScItemValue* pItemValue = new ScItemValue(aLabel, rField.nCol, rField.nFuncMask);
87  maItemValues.push_back(std::unique_ptr<ScItemValue>(pItemValue));
88  OUString sId(weld::toId(pItemValue));
89  mxControl->append(sId, pItemValue->maName);
90  }
91 }
92 
94 {
95  ScItemValue* pItemValue = weld::fromId<ScItemValue*>(rSource.get_selected_id());
96  ScItemValue* pOriginalItemValue = pItemValue->mpOriginalItemValue;
97 
98  // Don't allow to add "Data" element to page fields
100  return;
101 
102  mpParent->ItemInserted(pOriginalItemValue, meType);
103 
104  InsertEntryForItem(pOriginalItemValue, nTarget);
105 }
106 
107 void ScPivotLayoutTreeList::InsertEntryForItem(const ScItemValue* pItemValue, int nPosition)
108 {
109  ScItemValue* pListItemValue = new ScItemValue(pItemValue);
110  maItemValues.push_back(std::unique_ptr<ScItemValue>(pListItemValue));
111  OUString sName = pListItemValue->maName;
112  OUString sId(weld::toId(pListItemValue));
113  mxControl->insert(nullptr, nPosition, &sName, &sId, nullptr, nullptr, false, nullptr);
114 }
115 
116 IMPL_LINK(ScPivotLayoutTreeList, KeyInputHdl, const KeyEvent&, rKeyEvent, bool)
117 {
118  vcl::KeyCode aCode = rKeyEvent.GetKeyCode();
119  sal_uInt16 nCode = aCode.GetCode();
120 
121  if (nCode == KEY_DELETE)
122  {
123  const int nEntry = mxControl->get_cursor_index();
124  if (nEntry != -1)
125  mxControl->remove(nEntry);
126  return true;
127  }
128 
129  return false;
130 }
131 
132 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual VclPtr< AbstractScDPSubtotalDlg > CreateScDPSubtotalDlg(weld::Widget *pParent, ScDPObject &rDPObj, const ScDPLabelData &rLabelData, const ScPivotFuncData &rFuncData, const ScDPNameVec &rDataFields)=0
bool IsDataElement(SCCOL nColumn)
sal_uInt16 GetCode() const
void InsertEntryForItem(const ScItemValue *pItemValue, int nPosition)
RET_CANCEL
PivotFunc mnFuncMask
Definition: pivot.hxx:161
virtual ~ScPivotLayoutTreeList() override
sal_uInt16 nCode
const char * sName
void Setup(ScPivotLayoutDialog *pParent, SvPivotTreeListType eType)
ScItemValue * mpOriginalItemValue
void clear()
std::vector< ScPivotField > ScPivotFieldVector
Definition: pivot.hxx:129
sal_Int16 SCCOL
Definition: types.hxx:21
void FillFields(ScPivotFieldVector &rFieldVector)
ScPivotFuncData maFunctionData
IMPL_LINK(ScPivotLayoutTreeList, KeyInputHdl, const KeyEvent &, rKeyEvent, bool)
VclPtr< AbstractScDPSubtotalDlg > mpSubtotalDlg
bool StartExecuteAsync(const std::function< void(sal_Int32)> &rEndDialogFn)
virtual OUString get_selected_id() const =0
RegionData_Impl * mpParent
OUString toId(const void *pValue)
ScItemValue * GetItem(SCCOL nColumn)
IMPL_LINK_NOARG(ScPivotLayoutTreeList, DoubleClickHdl, weld::TreeView &, bool)
virtual void InsertEntryForSourceTarget(weld::TreeView &rSource, int nTarget) override
std::vector< std::unique_ptr< ScItemValue > > maItemValues
void ItemInserted(const ScItemValue *pItemValue, ScPivotLayoutTreeList::SvPivotTreeListType eType)
static SC_DLLPUBLIC ScAbstractDialogFactory * Create()
Definition: scabstdlg.cxx:37
RET_OK
ScPivotLayoutTreeList(std::unique_ptr< weld::TreeView > xControl)
OUString aLabel
std::unique_ptr< weld::TreeView > mxControl
constexpr sal_uInt16 KEY_DELETE
virtual void Response(int nResponse)=0
OUString sId