1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
13 #include <PivotLayoutTreeList.hxx>
14 #include <PivotLayoutDialog.hxx>
16 #include <vcl/event.hxx>
19 ScPivotLayoutTreeList::ScPivotLayoutTreeList(std::unique_ptr
<weld::TreeView
> xControl
)
20 : ScPivotLayoutTreeListBase(std::move(xControl
))
22 mxControl
->connect_key_press(LINK(this, ScPivotLayoutTreeList
, KeyInputHdl
));
23 mxControl
->connect_row_activated(LINK(this, ScPivotLayoutTreeList
, DoubleClickHdl
));
26 ScPivotLayoutTreeList::~ScPivotLayoutTreeList()
30 mpSubtotalDlg
->Response(RET_CANCEL
);
31 mpSubtotalDlg
.clear();
35 void ScPivotLayoutTreeList::Setup(ScPivotLayoutDialog
* pParent
, SvPivotTreeListType eType
)
41 IMPL_LINK_NOARG(ScPivotLayoutTreeList
, DoubleClickHdl
, weld::TreeView
&, bool)
43 int nEntry
= mxControl
->get_cursor_index();
47 ScItemValue
* pCurrentItemValue
= weld::fromId
<ScItemValue
*>(mxControl
->get_id(nEntry
));
48 ScPivotFuncData
& rCurrentFunctionData
= pCurrentItemValue
->maFunctionData
;
49 SCCOL nCurrentColumn
= rCurrentFunctionData
.mnCol
;
51 if (mpParent
->IsDataElement(nCurrentColumn
))
54 ScDPLabelData
& rCurrentLabelData
= mpParent
->GetLabelData(nCurrentColumn
);
56 ScAbstractDialogFactory
* pFactory
= ScAbstractDialogFactory::Create();
58 maDataFieldNames
.clear();
59 mpParent
->PushDataFieldNames(maDataFieldNames
);
61 mpSubtotalDlg
= pFactory
->CreateScDPSubtotalDlg(mxControl
.get(), mpParent
->maPivotTableObject
,
62 rCurrentLabelData
, rCurrentFunctionData
,
65 mpSubtotalDlg
->StartExecuteAsync([this, pCurrentItemValue
, nCurrentColumn
](int nResult
) {
66 if (nResult
== RET_OK
)
68 mpSubtotalDlg
->FillLabelData(mpParent
->GetLabelData(nCurrentColumn
));
69 pCurrentItemValue
->maFunctionData
.mnFuncMask
= mpSubtotalDlg
->GetFuncMask();
72 mpSubtotalDlg
.disposeAndClear();
78 void ScPivotLayoutTreeList::FillFields(ScPivotFieldVector
& rFieldVector
)
83 for (const ScPivotField
& rField
: rFieldVector
)
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
);
93 void ScPivotLayoutTreeList::InsertEntryForSourceTarget(weld::TreeView
& rSource
, int nTarget
)
95 ScItemValue
* pItemValue
= weld::fromId
<ScItemValue
*>(rSource
.get_selected_id());
96 ScItemValue
* pOriginalItemValue
= pItemValue
->mpOriginalItemValue
;
98 // Don't allow to add "Data" element to page fields
99 if (meType
== PAGE_LIST
&& mpParent
->IsDataElement(pItemValue
->maFunctionData
.mnCol
))
102 mpParent
->ItemInserted(pOriginalItemValue
, meType
);
104 InsertEntryForItem(pOriginalItemValue
, nTarget
);
107 void ScPivotLayoutTreeList::InsertEntryForItem(const ScItemValue
* pItemValue
, int nPosition
)
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);
116 IMPL_LINK(ScPivotLayoutTreeList
, KeyInputHdl
, const KeyEvent
&, rKeyEvent
, bool)
118 vcl::KeyCode aCode
= rKeyEvent
.GetKeyCode();
119 sal_uInt16 nCode
= aCode
.GetCode();
121 if (nCode
== KEY_DELETE
)
123 const int nEntry
= mxControl
->get_cursor_index();
125 mxControl
->remove(nEntry
);
132 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */