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>
14#include <PivotLayoutDialog.hxx>
15
16#include <vcl/event.hxx>
17#include <pivot.hxx>
18
19ScPivotLayoutTreeList::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 {
30 mpSubtotalDlg->Response(RET_CANCEL);
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
107void 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
116IMPL_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: */
IMPL_LINK(ScPivotLayoutTreeList, KeyInputHdl, const KeyEvent &, rKeyEvent, bool)
IMPL_LINK_NOARG(ScPivotLayoutTreeList, DoubleClickHdl, weld::TreeView &, bool)
static SC_DLLPUBLIC ScAbstractDialogFactory * Create()
Definition: scabstdlg.cxx:37
virtual VclPtr< AbstractScDPSubtotalDlg > CreateScDPSubtotalDlg(weld::Widget *pParent, ScDPObject &rDPObj, const ScDPLabelData &rLabelData, const ScPivotFuncData &rFuncData, const ScDPNameVec &rDataFields)=0
ScPivotFuncData maFunctionData
ScItemValue * mpOriginalItemValue
void ItemInserted(const ScItemValue *pItemValue, ScPivotLayoutTreeList::SvPivotTreeListType eType)
bool IsDataElement(SCCOL nColumn)
ScItemValue * GetItem(SCCOL nColumn)
std::unique_ptr< weld::TreeView > mxControl
ScPivotLayoutTreeList(std::unique_ptr< weld::TreeView > xControl)
std::vector< std::unique_ptr< ScItemValue > > maItemValues
VclPtr< AbstractScDPSubtotalDlg > mpSubtotalDlg
void Setup(ScPivotLayoutDialog *pParent, SvPivotTreeListType eType)
virtual void InsertEntryForSourceTarget(weld::TreeView &rSource, int nTarget) override
virtual ~ScPivotLayoutTreeList() override
void FillFields(ScPivotFieldVector &rFieldVector)
void InsertEntryForItem(const ScItemValue *pItemValue, int nPosition)
void clear()
sal_uInt16 GetCode() const
virtual OUString get_selected_id() const=0
RegionData_Impl * mpParent
DocumentType eType
OUString sName
constexpr sal_uInt16 KEY_DELETE
OUString toId(const void *pValue)
std::vector< ScPivotField > ScPivotFieldVector
Definition: pivot.hxx:129
PivotFunc mnFuncMask
Definition: pivot.hxx:161
sal_Int16 SCCOL
Definition: types.hxx:21
OUString aLabel
OUString sId
RET_OK
RET_CANCEL