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 #include <scabstdlg.hxx>
19 
20 ScPivotLayoutTreeList::ScPivotLayoutTreeList(std::unique_ptr<weld::TreeView> xControl)
21  : ScPivotLayoutTreeListBase(std::move(xControl))
22 {
23  mxControl->connect_key_press(LINK(this, ScPivotLayoutTreeList, KeyInputHdl));
24  mxControl->connect_row_activated(LINK(this, ScPivotLayoutTreeList, DoubleClickHdl));
25 }
26 
28 {
29 }
30 
32 {
33  mpParent = pParent;
34  meType = eType;
35 }
36 
38 {
39  int nEntry = mxControl->get_cursor_index();
40  if (nEntry == -1)
41  return true;
42 
43  ScItemValue* pCurrentItemValue = reinterpret_cast<ScItemValue*>(mxControl->get_id(nEntry).toInt64());
44  ScPivotFuncData& rCurrentFunctionData = pCurrentItemValue->maFunctionData;
45 
46  if (mpParent->IsDataElement(rCurrentFunctionData.mnCol))
47  return true;
48 
49  SCCOL nCurrentColumn = rCurrentFunctionData.mnCol;
50  ScDPLabelData& rCurrentLabelData = mpParent->GetLabelData(nCurrentColumn);
51 
53 
54  std::vector<ScDPName> aDataFieldNames;
55  mpParent->PushDataFieldNames(aDataFieldNames);
56 
58  pFactory->CreateScDPSubtotalDlg(mxControl.get(), mpParent->maPivotTableObject, rCurrentLabelData, rCurrentFunctionData, aDataFieldNames));
59 
60  if (pDialog->Execute() == RET_OK)
61  {
62  pDialog->FillLabelData(rCurrentLabelData);
63  rCurrentFunctionData.mnFuncMask = pDialog->GetFuncMask();
64  }
65 
66  return true;
67 }
68 
70 {
71  mxControl->clear();
72  maItemValues.clear();
73 
74  for (const ScPivotField& rField : rFieldVector)
75  {
76  OUString aLabel = mpParent->GetItem( rField.nCol )->maName;
77  ScItemValue* pItemValue = new ScItemValue( aLabel, rField.nCol, rField.nFuncMask );
78  maItemValues.push_back(std::unique_ptr<ScItemValue>(pItemValue));
79  OUString sId(OUString::number(reinterpret_cast<sal_Int64>(pItemValue)));
80  mxControl->append(sId, pItemValue->maName);
81  }
82 }
83 
85 {
86  ScItemValue* pItemValue = reinterpret_cast<ScItemValue*>(rSource.get_selected_id().toInt64());
87  ScItemValue* pOriginalItemValue = pItemValue->mpOriginalItemValue;
88 
89  // Don't allow to add "Data" element to page fields
91  return;
92 
93  mpParent->ItemInserted(pOriginalItemValue, meType);
94 
95  InsertEntryForItem(pOriginalItemValue, nTarget);
96 }
97 
98 void ScPivotLayoutTreeList::InsertEntryForItem(const ScItemValue* pItemValue, int nPosition)
99 {
100  ScItemValue *pListItemValue = new ScItemValue(pItemValue);
101  maItemValues.push_back(std::unique_ptr<ScItemValue>(pListItemValue));
102  OUString sName = pListItemValue->maName;
103  OUString sId(OUString::number(reinterpret_cast<sal_Int64>(pListItemValue)));
104  mxControl->insert(nullptr, nPosition, &sName, &sId, nullptr, nullptr, false, nullptr);
105 }
106 
107 IMPL_LINK(ScPivotLayoutTreeList, KeyInputHdl, const KeyEvent&, rKeyEvent, bool)
108 {
109  vcl::KeyCode aCode = rKeyEvent.GetKeyCode();
110  sal_uInt16 nCode = aCode.GetCode();
111 
112  if (nCode == KEY_DELETE)
113  {
114  const int nEntry = mxControl->get_cursor_index();
115  if (nEntry != -1)
116  mxControl->remove(nEntry);
117  return true;
118  }
119 
120  return false;
121 }
122 
123 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void FillLabelData(ScDPLabelData &rLabelData) const =0
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
virtual PivotFunc GetFuncMask() const =0
void InsertEntryForItem(const ScItemValue *pItemValue, int nPosition)
virtual short Execute()=0
virtual ~ScPivotLayoutTreeList() override
sal_uInt16 nCode
const char * sName
void Setup(ScPivotLayoutDialog *pParent, SvPivotTreeListType eType)
ScItemValue * mpOriginalItemValue
std::vector< ScPivotField > ScPivotFieldVector
Definition: pivot.hxx:129
sal_Int16 SCCOL
Definition: types.hxx:22
void FillFields(ScPivotFieldVector &rFieldVector)
ScPivotFuncData maFunctionData
IMPL_LINK(ScPivotLayoutTreeList, KeyInputHdl, const KeyEvent &, rKeyEvent, bool)
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:38
RET_OK
ScPivotLayoutTreeList(std::unique_ptr< weld::TreeView > xControl)
OUString aLabel
std::unique_ptr< weld::TreeView > mxControl
OUString sId
constexpr sal_uInt16 KEY_DELETE