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
48  = reinterpret_cast<ScItemValue*>(mxControl->get_id(nEntry).toInt64());
49  ScPivotFuncData& rCurrentFunctionData = pCurrentItemValue->maFunctionData;
50  SCCOL nCurrentColumn = rCurrentFunctionData.mnCol;
51 
52  if (mpParent->IsDataElement(nCurrentColumn))
53  return true;
54 
55  ScDPLabelData& rCurrentLabelData = mpParent->GetLabelData(nCurrentColumn);
56 
58 
59  maDataFieldNames.clear();
60  mpParent->PushDataFieldNames(maDataFieldNames);
61 
62  mpSubtotalDlg = pFactory->CreateScDPSubtotalDlg(mxControl.get(), mpParent->maPivotTableObject,
63  rCurrentLabelData, rCurrentFunctionData,
64  maDataFieldNames);
65 
66  mpSubtotalDlg->StartExecuteAsync([this, pCurrentItemValue, nCurrentColumn](int nResult) {
67  if (nResult == RET_OK)
68  {
69  mpSubtotalDlg->FillLabelData(mpParent->GetLabelData(nCurrentColumn));
70  pCurrentItemValue->maFunctionData.mnFuncMask = mpSubtotalDlg->GetFuncMask();
71  }
72 
73  mpSubtotalDlg.disposeAndClear();
74  });
75 
76  return true;
77 }
78 
80 {
81  mxControl->clear();
82  maItemValues.clear();
83 
84  for (const ScPivotField& rField : rFieldVector)
85  {
86  OUString aLabel = mpParent->GetItem(rField.nCol)->maName;
87  ScItemValue* pItemValue = new ScItemValue(aLabel, rField.nCol, rField.nFuncMask);
88  maItemValues.push_back(std::unique_ptr<ScItemValue>(pItemValue));
89  OUString sId(OUString::number(reinterpret_cast<sal_Int64>(pItemValue)));
90  mxControl->append(sId, pItemValue->maName);
91  }
92 }
93 
95 {
96  ScItemValue* pItemValue = reinterpret_cast<ScItemValue*>(rSource.get_selected_id().toInt64());
97  ScItemValue* pOriginalItemValue = pItemValue->mpOriginalItemValue;
98 
99  // Don't allow to add "Data" element to page fields
100  if (meType == PAGE_LIST && mpParent->IsDataElement(pItemValue->maFunctionData.mnCol))
101  return;
102 
103  mpParent->ItemInserted(pOriginalItemValue, meType);
104 
105  InsertEntryForItem(pOriginalItemValue, nTarget);
106 }
107 
108 void ScPivotLayoutTreeList::InsertEntryForItem(const ScItemValue* pItemValue, int nPosition)
109 {
110  ScItemValue* pListItemValue = new ScItemValue(pItemValue);
111  maItemValues.push_back(std::unique_ptr<ScItemValue>(pListItemValue));
112  OUString sName = pListItemValue->maName;
113  OUString sId(OUString::number(reinterpret_cast<sal_Int64>(pListItemValue)));
114  mxControl->insert(nullptr, nPosition, &sName, &sId, nullptr, nullptr, false, nullptr);
115 }
116 
117 IMPL_LINK(ScPivotLayoutTreeList, KeyInputHdl, const KeyEvent&, rKeyEvent, bool)
118 {
119  vcl::KeyCode aCode = rKeyEvent.GetKeyCode();
120  sal_uInt16 nCode = aCode.GetCode();
121 
122  if (nCode == KEY_DELETE)
123  {
124  const int nEntry = mxControl->get_cursor_index();
125  if (nEntry != -1)
126  mxControl->remove(nEntry);
127  return true;
128  }
129 
130  return false;
131 }
132 
133 /* 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
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