tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sc / source / ui / miscdlgs / dataproviderdlg.cxx
blob114da63c897c31b82e1b7fd0106c99c9e11871f7
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
8 */
10 #include <dataproviderdlg.hxx>
12 #include <document.hxx>
13 #include <dataprovider.hxx>
14 #include <datatransformation.hxx>
15 #include <datamapper.hxx>
16 #include <dbdata.hxx>
18 #include <comphelper/string.hxx>
19 #include <sal/log.hxx>
20 #include <sfx2/filedlghelper.hxx>
21 #include <unotools/charclass.hxx>
22 #include <utility>
23 #include <vcl/svapp.hxx>
25 class ScDataTransformationBaseControl
27 protected:
28 std::unique_ptr<weld::Builder> mxBuilder;
29 std::unique_ptr<weld::Container> mxGrid;
30 weld::Container* mpContainer;
32 sal_uInt32 mnIndex;
34 public:
35 ScDataTransformationBaseControl(weld::Container* pParent, const OUString& rUIFile, sal_uInt32 nIndex);
36 virtual ~ScDataTransformationBaseControl();
38 void updateIndex(sal_uInt32 nIndex) { mnIndex = nIndex; }
40 virtual std::shared_ptr<sc::DataTransformation> getTransformation() = 0;
42 static SCROW getLastRow(const ScDocument& rDoc);
43 static SCCOL getLastCol(const ScDocument& rDoc);
46 SCROW ScDataTransformationBaseControl::getLastRow(const ScDocument& rDoc)
48 SCROW nEndRow = rDoc.MaxRow();
49 return rDoc.GetLastDataRow(0, 0, 0, nEndRow);
52 SCCOL ScDataTransformationBaseControl::getLastCol(const ScDocument& rDoc)
54 for (SCCOL nCol = 1; nCol <= rDoc.MaxCol(); ++nCol)
56 if (rDoc.GetCellType(nCol, 0, 0) == CELLTYPE_NONE)
58 return static_cast<SCCOL>(nCol - 1 );
61 return rDoc.MaxCol();
64 ScDataTransformationBaseControl::ScDataTransformationBaseControl(weld::Container* pParent, const OUString& rUIFile, sal_uInt32 nIndex)
65 : mxBuilder(Application::CreateBuilder(pParent, rUIFile))
66 , mxGrid(mxBuilder->weld_container(u"grid"_ustr))
67 , mpContainer(pParent)
68 , mnIndex(nIndex)
72 ScDataTransformationBaseControl::~ScDataTransformationBaseControl()
74 mpContainer->move(mxGrid.get(), nullptr);
77 namespace {
79 struct MenuData
81 const char* aTransformationName;
82 std::function<void(ScDataProviderDlg*)> maCallback;
85 MenuData aTransformationData[] = {
86 { "Delete Column", &ScDataProviderDlg::deleteColumn },
87 { "Delete Row", &ScDataProviderDlg::deleteRowTransformation},
88 { "Swap Rows", &ScDataProviderDlg::swapRowsTransformation},
89 { "Split Column", &ScDataProviderDlg::splitColumn },
90 { "Merge Columns", &ScDataProviderDlg::mergeColumns },
91 { "Text Transformation", &ScDataProviderDlg::textTransformation },
92 { "Sort Columns", &ScDataProviderDlg::sortTransformation },
93 { "Aggregate Functions", &ScDataProviderDlg::aggregateFunction},
94 { "Number Transformations", &ScDataProviderDlg::numberTransformation },
95 { "Replace Null Transformations", &ScDataProviderDlg::replaceNullTransformation },
96 { "Date & Time Transformations", &ScDataProviderDlg::dateTimeTransformation },
97 { "Find Replace Transformation", &ScDataProviderDlg::findReplaceTransformation}
100 class ScDeleteColumnTransformationControl : public ScDataTransformationBaseControl
102 private:
103 std::unique_ptr<weld::Entry> mxColumnNums;
104 std::unique_ptr<weld::Button> mxDelete;
105 std::function<void(sal_uInt32&)> maDeleteTransformation;
106 const ScDocument* mpDoc;
108 public:
109 ScDeleteColumnTransformationControl(const ScDocument* pDoc, weld::Container* pParent, sal_uInt32 aIndex, std::function<void(sal_uInt32&)> aDeleteTransformation);
111 virtual std::shared_ptr<sc::DataTransformation> getTransformation() override;
112 DECL_LINK(DeleteHdl, weld::Button&, void);
115 ScDeleteColumnTransformationControl::ScDeleteColumnTransformationControl(
116 const ScDocument* pDoc, weld::Container* pParent, sal_uInt32 nIndex, std::function<void(sal_uInt32&)> aDeleteTransformation)
117 : ScDataTransformationBaseControl(pParent, u"modules/scalc/ui/deletecolumnentry.ui"_ustr, nIndex)
118 , mxColumnNums(mxBuilder->weld_entry(u"ed_columns"_ustr))
119 , mxDelete(mxBuilder->weld_button(u"ed_delete"_ustr))
120 , maDeleteTransformation(std::move(aDeleteTransformation))
121 , mpDoc(pDoc)
123 mxDelete->connect_clicked(LINK(this,ScDeleteColumnTransformationControl, DeleteHdl));
126 std::shared_ptr<sc::DataTransformation> ScDeleteColumnTransformationControl::getTransformation()
128 OUString aColumnString = mxColumnNums->get_text();
129 std::vector<OUString> aSplitColumns = comphelper::string::split(aColumnString, ';');
130 std::set<SCCOL> ColNums;
131 for (const auto& rColStr : aSplitColumns)
133 sal_Int32 nCol = rColStr.toInt32();
134 if (nCol <= 0)
135 continue;
137 if (nCol > mpDoc->MaxCol())
138 continue;
140 // translate from 1-based column notations to internal Calc one
141 ColNums.insert(nCol - 1);
144 return std::make_shared<sc::ColumnRemoveTransformation>(std::move(ColNums));
147 class ScSplitColumnTransformationControl : public ScDataTransformationBaseControl
149 private:
150 std::unique_ptr<weld::Entry> mxSeparator;
151 std::unique_ptr<weld::Entry> mxNumColumns;
152 std::unique_ptr<weld::Button> mxDelete;
153 std::function<void(sal_uInt32&)> maDeleteTransformation;
154 const ScDocument* mpDoc;
156 public:
157 ScSplitColumnTransformationControl(const ScDocument* pDoc, weld::Container* pParent, sal_uInt32 nIndex, std::function<void(sal_uInt32&)> aDeleteTransformation);
159 virtual std::shared_ptr<sc::DataTransformation> getTransformation() override;
160 DECL_LINK(DeleteHdl, weld::Button&, void);
163 ScSplitColumnTransformationControl::ScSplitColumnTransformationControl(
164 const ScDocument* pDoc, weld::Container* pParent, sal_uInt32 nIndex,
165 std::function<void(sal_uInt32&)> aDeleteTransformation)
166 : ScDataTransformationBaseControl(pParent, u"modules/scalc/ui/splitcolumnentry.ui"_ustr, nIndex)
167 , mxSeparator(mxBuilder->weld_entry(u"ed_separator"_ustr))
168 , mxNumColumns(mxBuilder->weld_entry(u"num_cols"_ustr))
169 , mxDelete(mxBuilder->weld_button(u"ed_delete"_ustr))
170 , maDeleteTransformation(std::move(aDeleteTransformation))
171 , mpDoc(pDoc)
173 mxDelete->connect_clicked(LINK(this,ScSplitColumnTransformationControl, DeleteHdl));
176 std::shared_ptr<sc::DataTransformation> ScSplitColumnTransformationControl::getTransformation()
178 OUString aSeparator = mxSeparator->get_text();
179 sal_Unicode cSeparator = aSeparator.isEmpty() ? ',' : aSeparator[0];
180 OUString aColStr = mxNumColumns->get_text();
181 SCCOL mnCol = -1;
182 sal_Int32 nCol = aColStr.toInt32();
183 if (nCol > 0 && nCol <= mpDoc->MaxCol())
184 mnCol = nCol - 1;
185 return std::make_shared<sc::SplitColumnTransformation>(mnCol, cSeparator);
188 class ScMergeColumnTransformationControl : public ScDataTransformationBaseControl
190 private:
191 std::unique_ptr<weld::Entry> mxSeparator;
192 std::unique_ptr<weld::Entry> mxEdColumns;
193 std::unique_ptr<weld::Button> mxDelete;
194 std::function<void(sal_uInt32&)> maDeleteTransformation;
195 const ScDocument* mpDoc;
197 public:
198 ScMergeColumnTransformationControl(const ScDocument *pDoc, weld::Container* pParent, SCCOL nStartCol, SCCOL nEndCol, sal_uInt32 nIndex, std::function<void(sal_uInt32&)> aDeleteTransformation);
200 virtual std::shared_ptr<sc::DataTransformation> getTransformation() override;
201 DECL_LINK(DeleteHdl, weld::Button&, void);
204 ScMergeColumnTransformationControl::ScMergeColumnTransformationControl(
205 const ScDocument* pDoc, weld::Container* pParent, SCCOL nStartCol, SCCOL nEndCol, sal_uInt32 nIndex,
206 std::function<void(sal_uInt32&)> aDeleteTransformation)
207 : ScDataTransformationBaseControl(pParent, u"modules/scalc/ui/mergecolumnentry.ui"_ustr, nIndex)
208 , mxSeparator(mxBuilder->weld_entry(u"ed_separator"_ustr))
209 , mxEdColumns(mxBuilder->weld_entry(u"ed_columns"_ustr))
210 , mxDelete(mxBuilder->weld_button(u"ed_delete"_ustr))
211 , maDeleteTransformation(std::move(aDeleteTransformation))
212 , mpDoc(pDoc)
214 mxDelete->connect_clicked(LINK(this,ScMergeColumnTransformationControl, DeleteHdl));
216 OUStringBuffer aBuffer;
218 // map from zero based to one based column numbers
219 aBuffer.append(static_cast<sal_Int32>(nStartCol + 1));
220 for ( SCCOL nCol = nStartCol + 1; nCol <= nEndCol; ++nCol)
222 aBuffer.append(";" + OUString::number(nCol + 1));
225 mxEdColumns->set_text(aBuffer.makeStringAndClear());
228 std::shared_ptr<sc::DataTransformation> ScMergeColumnTransformationControl::getTransformation()
230 OUString aColumnString = mxEdColumns->get_text();
231 std::vector<OUString> aSplitColumns = comphelper::string::split(aColumnString, ';');
232 std::set<SCCOL> aMergedColumns;
233 for (const auto& rColStr : aSplitColumns)
235 sal_Int32 nCol = rColStr.toInt32();
236 if (nCol <= 0)
237 continue;
239 if (nCol > mpDoc->MaxCol())
240 continue;
242 // translate from 1-based column notations to internal Calc one
243 aMergedColumns.insert(nCol - 1);
245 return std::make_shared<sc::MergeColumnTransformation>(std::move(aMergedColumns), mxSeparator->get_text());
248 class ScSortTransformationControl : public ScDataTransformationBaseControl
250 private:
251 std::unique_ptr<weld::ComboBox> mxType;
252 std::unique_ptr<weld::Entry> mxEdColumns;
253 std::unique_ptr<weld::Button> mxDelete;
254 std::function<void(sal_uInt32&)> maDeleteTransformation;
255 const ScDocument* mpDoc;
257 public:
258 ScSortTransformationControl(const ScDocument* pDoc, weld::Container* pParent, sal_uInt32 nIndex, std::function<void(sal_uInt32&)> aDeleteTransformation);
260 virtual std::shared_ptr<sc::DataTransformation> getTransformation() override;
261 DECL_LINK(DeleteHdl, weld::Button&, void);
264 ScSortTransformationControl::ScSortTransformationControl(
265 const ScDocument* pDoc, weld::Container* pParent, sal_uInt32 nIndex, std::function<void(sal_uInt32&)> aDeleteTransformation)
266 : ScDataTransformationBaseControl(pParent, u"modules/scalc/ui/sorttransformationentry.ui"_ustr, nIndex)
267 , mxType(mxBuilder->weld_combo_box(u"ed_ascending"_ustr))
268 , mxEdColumns(mxBuilder->weld_entry(u"ed_columns"_ustr))
269 , mxDelete(mxBuilder->weld_button(u"ed_delete"_ustr))
270 , maDeleteTransformation(std::move(aDeleteTransformation))
271 , mpDoc(pDoc)
273 mxDelete->connect_clicked(LINK(this,ScSortTransformationControl, DeleteHdl));
276 std::shared_ptr<sc::DataTransformation> ScSortTransformationControl::getTransformation()
278 OUString aColStr = mxEdColumns->get_text();
279 bool aIsAscending = mxType->get_active();
280 SCCOL aColumn = 0;
281 sal_Int32 nCol = aColStr.toInt32();
282 if (nCol > 0 && nCol <= mpDoc->MaxCol())
283 aColumn = nCol - 1; // translate from 1-based column notations to internal Calc one
285 ScSortParam aSortParam;
286 aSortParam.nRow1=0;
287 aSortParam.nRow2=getLastRow(*mpDoc);
288 aSortParam.nCol1=0;
289 aSortParam.nCol2=getLastCol(*mpDoc);
290 aSortParam.maKeyState[0].bDoSort = true;
291 aSortParam.maKeyState[0].nField = aColumn;
292 aSortParam.maKeyState[0].bAscending = aIsAscending;
293 return std::make_shared<sc::SortTransformation>(aSortParam);
296 class ScColumnTextTransformation : public ScDataTransformationBaseControl
298 private:
299 std::unique_ptr<weld::Entry> mxColumnNums;
300 std::unique_ptr<weld::ComboBox> mxType;
301 std::unique_ptr<weld::Button> mxDelete;
302 std::function<void(sal_uInt32&)> maDeleteTransformation;
303 const ScDocument* mpDoc;
305 public:
306 ScColumnTextTransformation(const ScDocument* pDoc, weld::Container* pParent, sal_uInt32 nIndex, std::function<void(sal_uInt32&)> aDeleteTransformation);
308 virtual std::shared_ptr<sc::DataTransformation> getTransformation() override;
309 DECL_LINK(DeleteHdl, weld::Button&, void);
312 ScColumnTextTransformation::ScColumnTextTransformation(
313 const ScDocument* pDoc, weld::Container* pParent, sal_uInt32 nIndex, std::function<void(sal_uInt32&)> aDeleteTransformation)
314 : ScDataTransformationBaseControl(pParent, u"modules/scalc/ui/texttransformationentry.ui"_ustr, nIndex)
315 , mxColumnNums(mxBuilder->weld_entry(u"ed_columns"_ustr))
316 , mxType(mxBuilder->weld_combo_box(u"ed_lst"_ustr))
317 , mxDelete(mxBuilder->weld_button(u"ed_delete"_ustr))
318 , maDeleteTransformation(std::move(aDeleteTransformation))
319 , mpDoc(pDoc)
321 mxDelete->connect_clicked(LINK(this,ScColumnTextTransformation, DeleteHdl));
324 std::shared_ptr<sc::DataTransformation> ScColumnTextTransformation::getTransformation()
326 OUString aColumnString = mxColumnNums->get_text();
327 std::vector<OUString> aSplitColumns = comphelper::string::split(aColumnString, ';');
328 std::set<SCCOL> aColumns;
329 for (const auto& rColStr : aSplitColumns)
331 sal_Int32 nCol = rColStr.toInt32();
332 if (nCol <= 0)
333 continue;
335 if (nCol > mpDoc->MaxCol())
336 continue;
338 // translate from 1-based column notations to internal Calc one
339 aColumns.insert(nCol - 1);
342 sal_Int32 nPos = mxType->get_active();
343 switch (nPos)
345 case 0:
346 return std::make_shared<sc::TextTransformation>(std::move(aColumns),sc::TEXT_TRANSFORM_TYPE::TO_LOWER);
347 case 1:
348 return std::make_shared<sc::TextTransformation>(std::move(aColumns),sc::TEXT_TRANSFORM_TYPE::TO_UPPER);
349 case 2:
350 return std::make_shared<sc::TextTransformation>(std::move(aColumns),sc::TEXT_TRANSFORM_TYPE::CAPITALIZE);
351 case 3:
352 return std::make_shared<sc::TextTransformation>(std::move(aColumns),sc::TEXT_TRANSFORM_TYPE::TRIM);
353 default:
354 assert(false);
357 return nullptr;
360 class ScAggregateFunction : public ScDataTransformationBaseControl
362 private:
363 std::unique_ptr<weld::Entry> mxColumnNums;
364 std::unique_ptr<weld::ComboBox> mxType;
365 std::unique_ptr<weld::Button> mxDelete;
366 std::function<void(sal_uInt32&)> maDeleteTransformation;
367 const ScDocument* mpDoc;
369 public:
370 ScAggregateFunction(const ScDocument* pDoc, weld::Container* pParent, sal_uInt32 nIndex, std::function<void(sal_uInt32&)> aDeleteTransformation);
372 virtual std::shared_ptr<sc::DataTransformation> getTransformation() override;
373 DECL_LINK(DeleteHdl, weld::Button&, void);
376 ScAggregateFunction::ScAggregateFunction(const ScDocument* pDoc, weld::Container* pParent, sal_uInt32 nIndex,
377 std::function<void(sal_uInt32&)> aDeleteTransformation)
378 : ScDataTransformationBaseControl(pParent, u"modules/scalc/ui/aggregatefunctionentry.ui"_ustr, nIndex)
379 , mxColumnNums(mxBuilder->weld_entry(u"ed_columns"_ustr))
380 , mxType(mxBuilder->weld_combo_box(u"ed_lst"_ustr))
381 , mxDelete(mxBuilder->weld_button(u"ed_delete"_ustr))
382 , maDeleteTransformation(std::move(aDeleteTransformation))
383 , mpDoc(pDoc)
385 mxDelete->connect_clicked(LINK(this,ScAggregateFunction, DeleteHdl));
388 std::shared_ptr<sc::DataTransformation> ScAggregateFunction::getTransformation()
390 OUString aColumnString = mxColumnNums->get_text();
391 sal_Int32 nPos = mxType->get_active();
392 std::vector<OUString> aSplitColumns = comphelper::string::split(aColumnString, ';');
393 std::set<SCCOL> aColumns;
394 for (const auto& rColStr : aSplitColumns)
396 sal_Int32 nCol = rColStr.toInt32();
397 if (nCol <= 0)
398 continue;
400 if (nCol > mpDoc->MaxCol())
401 continue;
403 // translate from 1-based column notations to internal Calc one
404 aColumns.insert(nCol - 1);
406 switch (nPos)
408 case 0:
409 return std::make_shared<sc::AggregateFunction>(std::move(aColumns),sc::AGGREGATE_FUNCTION::SUM);
410 case 1:
411 return std::make_shared<sc::AggregateFunction>(std::move(aColumns),sc::AGGREGATE_FUNCTION::AVERAGE);
412 case 2:
413 return std::make_shared<sc::AggregateFunction>(std::move(aColumns),sc::AGGREGATE_FUNCTION::MIN);
414 case 3:
415 return std::make_shared<sc::AggregateFunction>(std::move(aColumns),sc::AGGREGATE_FUNCTION::MAX);
416 default:
417 assert(false);
420 return nullptr;
423 class ScNumberTransformation : public ScDataTransformationBaseControl
425 private:
426 std::unique_ptr<weld::Entry> mxColumnNums;
427 std::unique_ptr<weld::ComboBox> mxType;
428 std::unique_ptr<weld::Button> mxDelete;
429 std::function<void(sal_uInt32&)> maDeleteTransformation;
430 const ScDocument* mpDoc;
432 public:
433 ScNumberTransformation(const ScDocument *pDoc, weld::Container* pParent, sal_uInt32 nIndex, std::function<void(sal_uInt32&)> aDeleteTransformation);
435 virtual std::shared_ptr<sc::DataTransformation> getTransformation() override;
436 DECL_LINK(DeleteHdl, weld::Button&, void);
439 ScNumberTransformation::ScNumberTransformation(
440 const ScDocument *pDoc, weld::Container* pParent, sal_uInt32 nIndex, std::function<void(sal_uInt32&)> aDeleteTransformation)
441 : ScDataTransformationBaseControl(pParent, u"modules/scalc/ui/numbertransformationentry.ui"_ustr, nIndex)
442 , mxColumnNums(mxBuilder->weld_entry(u"ed_columns"_ustr))
443 , mxType(mxBuilder->weld_combo_box(u"ed_lst"_ustr))
444 , mxDelete(mxBuilder->weld_button(u"ed_delete"_ustr))
445 , maDeleteTransformation(std::move(aDeleteTransformation))
446 , mpDoc(pDoc)
448 mxDelete->connect_clicked(LINK(this,ScNumberTransformation, DeleteHdl));
451 std::shared_ptr<sc::DataTransformation> ScNumberTransformation::getTransformation()
453 OUString aColumnString = mxColumnNums->get_text();
454 sal_Int32 nPos = mxType->get_active();
455 std::vector<OUString> aSplitColumns = comphelper::string::split(aColumnString, ';');
456 std::set<SCCOL> aColumns;
457 for (const auto& rColStr : aSplitColumns)
459 sal_Int32 nCol = rColStr.toInt32();
460 if (nCol <= 0)
461 continue;
463 if (nCol > mpDoc->MaxCol())
464 continue;
466 // translate from 1-based column notations to internal Calc one
467 aColumns.insert(nCol - 1);
469 switch (nPos)
471 case 0:
472 return std::make_shared<sc::NumberTransformation>(std::move(aColumns),sc::NUMBER_TRANSFORM_TYPE::SIGN);
473 case 1:
474 return std::make_shared<sc::NumberTransformation>(std::move(aColumns),sc::NUMBER_TRANSFORM_TYPE::ROUND);
475 case 2:
476 return std::make_shared<sc::NumberTransformation>(std::move(aColumns),sc::NUMBER_TRANSFORM_TYPE::ROUND_UP);
477 case 3:
478 return std::make_shared<sc::NumberTransformation>(std::move(aColumns),sc::NUMBER_TRANSFORM_TYPE::ROUND_DOWN);
479 case 4:
480 return std::make_shared<sc::NumberTransformation>(std::move(aColumns),sc::NUMBER_TRANSFORM_TYPE::ABSOLUTE);
481 case 5:
482 return std::make_shared<sc::NumberTransformation>(std::move(aColumns),sc::NUMBER_TRANSFORM_TYPE::LOG_E);
483 case 6:
484 return std::make_shared<sc::NumberTransformation>(std::move(aColumns),sc::NUMBER_TRANSFORM_TYPE::LOG_10);
485 case 7:
486 return std::make_shared<sc::NumberTransformation>(std::move(aColumns),sc::NUMBER_TRANSFORM_TYPE::CUBE);
487 case 8:
488 return std::make_shared<sc::NumberTransformation>(std::move(aColumns),sc::NUMBER_TRANSFORM_TYPE::SQUARE);
489 case 9:
490 return std::make_shared<sc::NumberTransformation>(std::move(aColumns),sc::NUMBER_TRANSFORM_TYPE::SQUARE_ROOT);
491 case 10:
492 return std::make_shared<sc::NumberTransformation>(std::move(aColumns),sc::NUMBER_TRANSFORM_TYPE::EXPONENT);
493 case 11:
494 return std::make_shared<sc::NumberTransformation>(std::move(aColumns),sc::NUMBER_TRANSFORM_TYPE::IS_EVEN);
495 case 12:
496 return std::make_shared<sc::NumberTransformation>(std::move(aColumns),sc::NUMBER_TRANSFORM_TYPE::IS_ODD);
497 default:
498 assert(false);
501 return nullptr;
504 class ScReplaceNullTransformation : public ScDataTransformationBaseControl
506 private:
507 std::unique_ptr<weld::Entry> mxColumnNums;
508 std::unique_ptr<weld::Entry> mxReplaceString;
509 std::unique_ptr<weld::Button> mxDelete;
510 std::function<void(sal_uInt32&)> maDeleteTransformation;
511 const ScDocument *mpDoc;
513 public:
515 ScReplaceNullTransformation(const ScDocument *pDoc, weld::Container* pParent, sal_uInt32 nIndex, std::function<void(sal_uInt32&)> aDeleteTransformation);
517 virtual std::shared_ptr<sc::DataTransformation> getTransformation() override;
518 DECL_LINK(DeleteHdl, weld::Button&, void);
521 ScReplaceNullTransformation::ScReplaceNullTransformation(const ScDocument *pDoc, weld::Container* pParent, sal_uInt32 nIndex, std::function<void(sal_uInt32&)> aDeleteTransformation)
522 : ScDataTransformationBaseControl(pParent,u"modules/scalc/ui/replacenulltransformationentry.ui"_ustr, nIndex)
523 , mxColumnNums(mxBuilder->weld_entry(u"ed_columns"_ustr))
524 , mxReplaceString(mxBuilder->weld_entry(u"ed_str"_ustr))
525 , mxDelete(mxBuilder->weld_button(u"ed_delete"_ustr))
526 , maDeleteTransformation(std::move(aDeleteTransformation))
527 , mpDoc(pDoc)
529 mxDelete->connect_clicked(LINK(this,ScReplaceNullTransformation, DeleteHdl));
533 std::shared_ptr<sc::DataTransformation> ScReplaceNullTransformation::getTransformation()
535 OUString aColumnString = mxColumnNums->get_text();
536 OUString aReplaceWithString = mxReplaceString->get_text();
537 std::vector<OUString> aSplitColumns = comphelper::string::split(aColumnString, ';');
538 std::set<SCCOL> aColumns;
539 for (const auto& rColStr : aSplitColumns)
541 sal_Int32 nCol = rColStr.toInt32();
542 if (nCol <= 0)
543 continue;
545 if (nCol > mpDoc->MaxCol())
546 continue;
548 // translate from 1-based column notations to internal Calc one
549 aColumns.insert(nCol - 1);
552 return std::make_shared<sc::ReplaceNullTransformation>(std::move(aColumns),aReplaceWithString);
555 class ScDateTimeTransformation : public ScDataTransformationBaseControl
557 private:
558 std::unique_ptr<weld::Entry> mxColumnNums;
559 std::unique_ptr<weld::ComboBox> mxType;
560 std::unique_ptr<weld::Button> mxDelete;
561 std::function<void(sal_uInt32&)> maDeleteTransformation;
562 const ScDocument* mpDoc;
564 public:
566 ScDateTimeTransformation(const ScDocument* pDoc, weld::Container* pParent, sal_uInt32 nIndex, std::function<void(sal_uInt32&)> aDeleteTransformation);
568 virtual std::shared_ptr<sc::DataTransformation> getTransformation() override;
569 DECL_LINK(DeleteHdl, weld::Button&, void);
572 ScDateTimeTransformation::ScDateTimeTransformation(const ScDocument* pDoc, weld::Container* pParent, sal_uInt32 nIndex, std::function<void(sal_uInt32&)> aDeleteTransformation)
573 : ScDataTransformationBaseControl(pParent,u"modules/scalc/ui/datetimetransformationentry.ui"_ustr, nIndex)
574 , mxColumnNums(mxBuilder->weld_entry(u"ed_columns"_ustr))
575 , mxType(mxBuilder->weld_combo_box(u"ed_lst"_ustr))
576 , mxDelete(mxBuilder->weld_button(u"ed_delete"_ustr))
577 , maDeleteTransformation(std::move(aDeleteTransformation))
578 , mpDoc(pDoc)
580 mxDelete->connect_clicked(LINK(this,ScDateTimeTransformation, DeleteHdl));
583 std::shared_ptr<sc::DataTransformation> ScDateTimeTransformation::getTransformation()
585 OUString aColumnString = mxColumnNums->get_text();
586 sal_Int32 nPos = mxType->get_active();
587 std::vector<OUString> aSplitColumns = comphelper::string::split(aColumnString, ';');
588 std::set<SCCOL> aColumns;
589 for (const auto& rColStr : aSplitColumns)
591 sal_Int32 nCol = rColStr.toInt32();
592 if (nCol <= 0)
593 continue;
595 if (nCol > mpDoc->MaxCol())
596 continue;
598 // translate from 1-based column notations to internal Calc one
599 aColumns.insert(nCol - 1);
601 switch (nPos)
603 case 0:
604 return std::make_shared<sc::DateTimeTransformation>(std::move(aColumns),sc::DATETIME_TRANSFORMATION_TYPE::DATE_STRING);
605 case 1:
606 return std::make_shared<sc::DateTimeTransformation>(std::move(aColumns),sc::DATETIME_TRANSFORMATION_TYPE::YEAR);
607 case 2:
608 return std::make_shared<sc::DateTimeTransformation>(std::move(aColumns),sc::DATETIME_TRANSFORMATION_TYPE::START_OF_YEAR);
609 case 3:
610 return std::make_shared<sc::DateTimeTransformation>(std::move(aColumns),sc::DATETIME_TRANSFORMATION_TYPE::END_OF_YEAR);
611 case 4:
612 return std::make_shared<sc::DateTimeTransformation>(std::move(aColumns),sc::DATETIME_TRANSFORMATION_TYPE::MONTH);
613 case 5:
614 return std::make_shared<sc::DateTimeTransformation>(std::move(aColumns),sc::DATETIME_TRANSFORMATION_TYPE::MONTH_NAME);
615 case 6:
616 return std::make_shared<sc::DateTimeTransformation>(std::move(aColumns),sc::DATETIME_TRANSFORMATION_TYPE::START_OF_MONTH);
617 case 7:
618 return std::make_shared<sc::DateTimeTransformation>(std::move(aColumns),sc::DATETIME_TRANSFORMATION_TYPE::END_OF_MONTH);
619 case 8:
620 return std::make_shared<sc::DateTimeTransformation>(std::move(aColumns),sc::DATETIME_TRANSFORMATION_TYPE::DAY);
621 case 9:
622 return std::make_shared<sc::DateTimeTransformation>(std::move(aColumns),sc::DATETIME_TRANSFORMATION_TYPE::DAY_OF_WEEK);
623 case 10:
624 return std::make_shared<sc::DateTimeTransformation>(std::move(aColumns),sc::DATETIME_TRANSFORMATION_TYPE::DAY_OF_YEAR);
625 case 11:
626 return std::make_shared<sc::DateTimeTransformation>(std::move(aColumns),sc::DATETIME_TRANSFORMATION_TYPE::QUARTER);
627 case 12:
628 return std::make_shared<sc::DateTimeTransformation>(std::move(aColumns),sc::DATETIME_TRANSFORMATION_TYPE::START_OF_QUARTER);
629 case 13:
630 return std::make_shared<sc::DateTimeTransformation>(std::move(aColumns),sc::DATETIME_TRANSFORMATION_TYPE::END_OF_QUARTER);
631 case 14:
632 return std::make_shared<sc::DateTimeTransformation>(std::move(aColumns),sc::DATETIME_TRANSFORMATION_TYPE::HOUR);
633 case 15:
634 return std::make_shared<sc::DateTimeTransformation>(std::move(aColumns),sc::DATETIME_TRANSFORMATION_TYPE::MINUTE);
635 case 16:
636 return std::make_shared<sc::DateTimeTransformation>(std::move(aColumns),sc::DATETIME_TRANSFORMATION_TYPE::SECOND);
637 case 17:
638 return std::make_shared<sc::DateTimeTransformation>(std::move(aColumns),sc::DATETIME_TRANSFORMATION_TYPE::TIME);
639 default:
640 assert(false);
643 return nullptr;
646 class ScFindReplaceTransformation : public ScDataTransformationBaseControl
648 private:
649 std::unique_ptr<weld::Entry> mxFindString;
650 std::unique_ptr<weld::Entry> mxReplaceString;
651 std::unique_ptr<weld::Entry> mxEdColumns;
652 std::unique_ptr<weld::Button> mxDelete;
653 std::function<void(sal_uInt32&)> maDeleteTransformation;
654 const ScDocument* mpDoc;
656 public:
657 ScFindReplaceTransformation(const ScDocument* pDoc, weld::Container* pParent, sal_uInt32 nIndex, std::function<void(sal_uInt32&)> aDeleteTransformation);
659 virtual std::shared_ptr<sc::DataTransformation> getTransformation() override;
660 DECL_LINK(DeleteHdl, weld::Button&, void);
663 ScFindReplaceTransformation::ScFindReplaceTransformation(
664 const ScDocument *pDoc, weld::Container* pParent, sal_uInt32 nIndex,
665 std::function<void(sal_uInt32&)> aDeleteTransformation)
666 : ScDataTransformationBaseControl(pParent, u"modules/scalc/ui/findreplaceentry.ui"_ustr, nIndex)
667 , mxFindString(mxBuilder->weld_entry(u"ed_find"_ustr))
668 , mxReplaceString(mxBuilder->weld_entry(u"ed_replace"_ustr))
669 , mxEdColumns(mxBuilder->weld_entry(u"ed_columns"_ustr))
670 , mxDelete(mxBuilder->weld_button(u"ed_delete"_ustr))
671 , maDeleteTransformation(std::move(aDeleteTransformation))
672 , mpDoc(pDoc)
674 mxDelete->connect_clicked(LINK(this, ScFindReplaceTransformation, DeleteHdl));
677 std::shared_ptr<sc::DataTransformation> ScFindReplaceTransformation::getTransformation()
679 OUString aColStr = mxEdColumns->get_text();
680 SCCOL aColumn = -1;
681 sal_Int32 nCol = aColStr.toInt32();
682 if (nCol > 0 && nCol <= mpDoc->MaxCol())
683 aColumn = nCol - 1;
684 return std::make_shared<sc::FindReplaceTransformation>(aColumn, mxFindString->get_text(), mxReplaceString->get_text());
687 class ScDeleteRowTransformation : public ScDataTransformationBaseControl
689 private:
690 std::unique_ptr<weld::Entry> mxFindString;
691 std::unique_ptr<weld::Entry> mxEdColumns;
692 std::unique_ptr<weld::Button> mxDelete;
693 std::function<void(sal_uInt32&)> maDeleteTransformation;
694 const ScDocument* mpDoc;
696 public:
697 ScDeleteRowTransformation(const ScDocument* pDoc, weld::Container* pParent, sal_uInt32 nIndex, std::function<void(sal_uInt32&)> aDeleteTransformation);
699 virtual std::shared_ptr<sc::DataTransformation> getTransformation() override;
700 DECL_LINK(DeleteHdl, weld::Button&, void);
703 ScDeleteRowTransformation::ScDeleteRowTransformation(
704 const ScDocument *pDoc, weld::Container* pParent, sal_uInt32 nIndex,
705 std::function<void(sal_uInt32&)> aDeleteTransformation)
706 : ScDataTransformationBaseControl(pParent, u"modules/scalc/ui/deleterowentry.ui"_ustr, nIndex)
707 , mxFindString(mxBuilder->weld_entry(u"ed_find"_ustr))
708 , mxEdColumns(mxBuilder->weld_entry(u"ed_columns"_ustr))
709 , mxDelete(mxBuilder->weld_button(u"ed_delete"_ustr))
710 , maDeleteTransformation(std::move(aDeleteTransformation))
711 , mpDoc(pDoc)
713 mxDelete->connect_clicked(LINK(this, ScDeleteRowTransformation, DeleteHdl));
716 std::shared_ptr<sc::DataTransformation> ScDeleteRowTransformation::getTransformation()
718 OUString aColStr = mxEdColumns->get_text();
719 SCCOL aColumn = -1;
720 sal_Int32 nCol = aColStr.toInt32();
721 if (nCol > 0 && nCol <= mpDoc->MaxCol())
722 aColumn = nCol - 1;
723 return std::make_shared<sc::DeleteRowTransformation>(aColumn, mxFindString->get_text());
726 class ScSwapRowsTransformation : public ScDataTransformationBaseControl
728 private:
729 std::unique_ptr<weld::Entry> mxRow;
730 std::unique_ptr<weld::Entry> nxRow;
731 std::unique_ptr<weld::Button> mxDelete;
732 std::function<void(sal_uInt32&)> maDeleteTransformation;
733 const ScDocument* mpDoc;
735 public:
736 ScSwapRowsTransformation(const ScDocument* pDoc, weld::Container* pParent, sal_uInt32 nIndex, std::function<void(sal_uInt32&)> aDeleteTransformation);
738 virtual std::shared_ptr<sc::DataTransformation> getTransformation() override;
739 DECL_LINK(DeleteHdl, weld::Button&, void);
742 ScSwapRowsTransformation::ScSwapRowsTransformation(
743 const ScDocument *pDoc, weld::Container* pParent, sal_uInt32 nIndex,
744 std::function<void(sal_uInt32&)> aDeleteTransformation)
745 : ScDataTransformationBaseControl(pParent, u"modules/scalc/ui/swaprowsentry.ui"_ustr, nIndex)
746 , mxRow(mxBuilder->weld_entry(u"ed_row1"_ustr))
747 , nxRow(mxBuilder->weld_entry(u"ed_row2"_ustr))
748 , mxDelete(mxBuilder->weld_button(u"ed_delete"_ustr))
749 , maDeleteTransformation(std::move(aDeleteTransformation))
750 , mpDoc(pDoc)
752 mxDelete->connect_clicked(LINK(this, ScSwapRowsTransformation, DeleteHdl));
755 std::shared_ptr<sc::DataTransformation> ScSwapRowsTransformation::getTransformation()
757 OUString aRowStr = mxRow->get_text();
758 OUString bRowStr = nxRow->get_text();
759 SCROW aRow = -1;
760 SCROW bRow = -1;
761 sal_Int32 mRow = aRowStr.toInt32();
762 sal_Int32 nRow = bRowStr.toInt32();
763 if (mRow > 0 && mRow <= mpDoc->MaxRow())
764 aRow = mRow - 1;
765 if (nRow > 0 && nRow <= mpDoc->MaxRow())
766 bRow = nRow - 1;
767 return std::make_shared<sc::SwapRowsTransformation>(aRow, bRow);
772 ScDataProviderDlg::ScDataProviderDlg(weld::Window* pParent, std::shared_ptr<ScDocument> pDoc,
773 const ScDocument* pDocument)
774 : GenericDialogController(pParent, u"modules/scalc/ui/dataproviderdlg.ui"_ustr, u"dataproviderdlg"_ustr)
775 , mxDoc(std::move(pDoc))
776 , mxBox(m_xBuilder->weld_container(u"data_table"_ustr))
777 , m_xTableParent(mxBox->CreateChildFrame())
778 , mxTable(VclPtr<ScDataTableView>::Create(m_xTableParent, mxDoc))
779 , mxDBRanges(m_xBuilder->weld_combo_box(u"select_db_range"_ustr))
780 , mxOKBtn(m_xBuilder->weld_button(u"ok"_ustr))
781 , mxCancelBtn(m_xBuilder->weld_button(u"cancel"_ustr))
782 , mxAddTransformationBtn(m_xBuilder->weld_button(u"add_transformation"_ustr))
783 , mxScroll(m_xBuilder->weld_scrolled_window(u"scroll"_ustr))
784 , mxTransformationList(m_xBuilder->weld_container(u"transformation_ctrl"_ustr))
785 , mxTransformationBox(m_xBuilder->weld_combo_box(u"transformation_box"_ustr))
786 , mxProviderList(m_xBuilder->weld_combo_box(u"provider_lst"_ustr))
787 , mxEditURL(m_xBuilder->weld_entry(u"ed_url"_ustr))
788 , mxEditID(m_xBuilder->weld_entry(u"ed_id"_ustr))
789 , mxApplyBtn(m_xBuilder->weld_button(u"apply"_ustr))
790 , mxBrowseBtn(m_xBuilder->weld_button(u"browse"_ustr))
791 , maIdle("ScDataProviderDlg maIdle")
792 , mnIndex(0)
794 Size aPrefSize = mxTable->GetOptimalSize();
795 mxBox->set_size_request(aPrefSize.Width(), aPrefSize.Height());
796 mxTable->Show();
798 ScDBCollection* pDBCollection = pDocument->GetDBCollection();
799 auto& rNamedDBs = pDBCollection->getNamedDBs();
800 for (auto& rNamedDB : rNamedDBs)
802 mxDBRanges->append_text(rNamedDB->GetName());
805 for (const auto& i : aTransformationData)
807 mxTransformationBox->append_text(OUString::createFromAscii(i.aTransformationName));
810 pDBData = new ScDBData(u"data"_ustr, 0, 0, 0, mxDoc->MaxCol(), mxDoc->MaxRow());
811 bool bSuccess = mxDoc->GetDBCollection()->getNamedDBs().insert(std::unique_ptr<ScDBData>(pDBData));
812 SAL_WARN_IF(!bSuccess, "sc", "temporary warning");
814 auto aDataProvider = sc::DataProviderFactory::getDataProviders();
815 for (const auto& rDataProvider : aDataProvider)
817 mxProviderList->append_text(rDataProvider);
820 mxOKBtn->connect_clicked(LINK(this, ScDataProviderDlg, ApplyQuitHdl));
821 mxCancelBtn->connect_clicked(LINK(this, ScDataProviderDlg, CancelQuitHdl));
822 mxAddTransformationBtn->connect_clicked(LINK(this, ScDataProviderDlg, TransformationListHdl));
823 mxApplyBtn->connect_clicked(LINK(this, ScDataProviderDlg, ApplyBtnHdl));
824 mxBrowseBtn->connect_clicked(LINK(this, ScDataProviderDlg, BrowseBtnHdl));
825 mxTransformationBox->connect_changed(LINK(this, ScDataProviderDlg, TransformationSelectHdl));
826 mxProviderList->connect_changed(LINK(this, ScDataProviderDlg, ProviderSelectHdl));
827 mxEditID->connect_changed(LINK(this, ScDataProviderDlg, IDEditHdl));
828 mxEditURL->connect_changed(LINK(this, ScDataProviderDlg, URLEditHdl));
830 msApplyTooltip = mxApplyBtn->get_tooltip_text();
831 msAddTransformationToolTip = mxAddTransformationBtn->get_tooltip_text();
832 mxAddTransformationBtn->set_sensitive(false);
833 mxAddTransformationBtn->set_tooltip_text(OUString());
834 isValid();
836 maIdle.SetPriority( TaskPriority::LOWEST );
837 maIdle.SetInvokeHandler( LINK( this, ScDataProviderDlg, ScrollToEnd) );
840 ScDataProviderDlg::~ScDataProviderDlg()
842 mxTable.disposeAndClear();
843 m_xTableParent->dispose();
844 m_xTableParent.clear();
847 IMPL_LINK_NOARG(ScDataProviderDlg, ScrollToEnd, Timer*, void)
849 mxScroll->vadjustment_set_value(mxScroll->vadjustment_get_upper());
852 IMPL_LINK_NOARG(ScDataProviderDlg, ApplyQuitHdl, weld::Button&, void)
854 m_xDialog->response(RET_OK);
857 IMPL_LINK_NOARG(ScDataProviderDlg, CancelQuitHdl, weld::Button&, void)
859 m_xDialog->response(RET_CANCEL);
862 IMPL_LINK_NOARG(ScDataProviderDlg, TransformationListHdl, weld::Button&, void)
864 OUString transformation_string = mxTransformationBox->get_active_text();
865 for (auto& i: aTransformationData)
867 if (transformation_string == OUString::createFromAscii(i.aTransformationName))
869 i.maCallback(this);
870 maIdle.Start();
871 return;
876 IMPL_LINK_NOARG(ScDataProviderDlg, ProviderSelectHdl, weld::ComboBox&, void)
878 isValid();
881 IMPL_LINK_NOARG(ScDataProviderDlg, IDEditHdl, weld::Entry&, void)
883 isValid();
886 IMPL_LINK_NOARG(ScDataProviderDlg, URLEditHdl, weld::Entry&, void)
888 isValid();
891 IMPL_LINK_NOARG(ScDataProviderDlg, ApplyBtnHdl, weld::Button&, void)
893 updateApplyBtn(true);
894 import(*mxDoc, true);
897 IMPL_LINK_NOARG(ScDataProviderDlg, BrowseBtnHdl, weld::Button&, void)
899 sfx2::FileDialogHelper aFileDialog(0, FileDialogFlags::NONE, m_xDialog.get());
900 aFileDialog.SetContext(sfx2::FileDialogHelper::CalcDataProvider);
901 if (aFileDialog.Execute() != ERRCODE_NONE)
902 return;
904 mxEditURL->set_text(aFileDialog.GetPath());
905 isValid();
908 IMPL_LINK_NOARG(ScDataProviderDlg, TransformationSelectHdl, weld::ComboBox&, void)
910 mxAddTransformationBtn->set_sensitive(true);
911 mxAddTransformationBtn->set_tooltip_text(msAddTransformationToolTip);
914 sc::ExternalDataSource ScDataProviderDlg::getDataSource(ScDocument* pDoc)
916 sc::ExternalDataSource aSource(mxEditURL->get_text(), mxProviderList->get_active_text(), pDoc);
918 OUString aID = mxEditID->get_text();
919 aSource.setID(aID);
920 return aSource;
923 void ScDataProviderDlg::isValid()
925 bool bValid = !mxProviderList->get_active_text().isEmpty();
926 bValid &= !mxEditURL->get_text().isEmpty();
927 updateApplyBtn(bValid);
930 void ScDataProviderDlg::updateApplyBtn(bool bValidConfig)
932 if (!bValidConfig)
934 mxApplyBtn->set_sensitive(false);
935 mxApplyBtn->set_tooltip_text(OUString());
936 return;
939 mxApplyBtn->set_sensitive(true);
940 mxApplyBtn->set_tooltip_text(msApplyTooltip);
943 void ScDataProviderDlg::deleteColumn()
945 std::function<void(sal_uInt32&)> adeleteTransformation = std::bind(&ScDataProviderDlg::deletefromList,this, std::placeholders::_1);
946 maControls.emplace_back(std::make_unique<ScDeleteColumnTransformationControl>(mxDoc.get(), mxTransformationList.get(), mnIndex++, adeleteTransformation));
949 void ScDataProviderDlg::splitColumn()
951 std::function<void(sal_uInt32&)> adeleteTransformation = std::bind(&ScDataProviderDlg::deletefromList,this, std::placeholders::_1);
952 maControls.emplace_back(std::make_unique<ScSplitColumnTransformationControl>(mxDoc.get(), mxTransformationList.get(), mnIndex++, adeleteTransformation));
955 void ScDataProviderDlg::mergeColumns()
957 SCCOL nStartCol = -1;
958 SCCOL nEndCol = -1;
959 mxTable->getColRange(nStartCol, nEndCol);
960 std::function<void(sal_uInt32&)> adeleteTransformation = std::bind(&ScDataProviderDlg::deletefromList,this, std::placeholders::_1);
961 maControls.emplace_back(std::make_unique<ScMergeColumnTransformationControl>(mxDoc.get(), mxTransformationList.get(), nStartCol, nEndCol, mnIndex++, adeleteTransformation));
964 void ScDataProviderDlg::textTransformation()
966 std::function<void(sal_uInt32&)> adeleteTransformation = std::bind(&ScDataProviderDlg::deletefromList,this, std::placeholders::_1);
967 maControls.emplace_back(std::make_unique<ScColumnTextTransformation>(mxDoc.get(), mxTransformationList.get(), mnIndex++, adeleteTransformation));
970 void ScDataProviderDlg::sortTransformation()
972 std::function<void(sal_uInt32&)> adeleteTransformation = std::bind(&ScDataProviderDlg::deletefromList,this, std::placeholders::_1);
973 maControls.emplace_back(std::make_unique<ScSortTransformationControl>(mxDoc.get(), mxTransformationList.get(), mnIndex++, adeleteTransformation));
976 void ScDataProviderDlg::aggregateFunction()
978 std::function<void(sal_uInt32&)> adeleteTransformation = std::bind(&ScDataProviderDlg::deletefromList,this, std::placeholders::_1);
979 maControls.emplace_back(std::make_unique<ScAggregateFunction>(mxDoc.get(), mxTransformationList.get(), mnIndex++, adeleteTransformation));
982 void ScDataProviderDlg::numberTransformation()
984 std::function<void(sal_uInt32&)> adeleteTransformation = std::bind(&ScDataProviderDlg::deletefromList,this, std::placeholders::_1);
985 maControls.emplace_back(std::make_unique<ScNumberTransformation>(mxDoc.get(), mxTransformationList.get(), mnIndex++, adeleteTransformation));
988 void ScDataProviderDlg::replaceNullTransformation()
990 std::function<void(sal_uInt32&)> adeleteTransformation = std::bind(&ScDataProviderDlg::deletefromList,this, std::placeholders::_1);
991 maControls.emplace_back(std::make_unique<ScReplaceNullTransformation>(mxDoc.get(), mxTransformationList.get(), mnIndex++, adeleteTransformation));
994 void ScDataProviderDlg::dateTimeTransformation()
996 std::function<void(sal_uInt32&)> adeleteTransformation = std::bind(&ScDataProviderDlg::deletefromList,this, std::placeholders::_1);
997 maControls.emplace_back(std::make_unique<ScDateTimeTransformation>(mxDoc.get(), mxTransformationList.get(), mnIndex++, adeleteTransformation));
1000 void ScDataProviderDlg::findReplaceTransformation()
1002 std::function<void(sal_uInt32&)> adeleteTransformation = std::bind(&ScDataProviderDlg::deletefromList, this, std::placeholders::_1);
1003 maControls.emplace_back(std::make_unique<ScFindReplaceTransformation>(mxDoc.get(), mxTransformationList.get(), mnIndex++, adeleteTransformation));
1006 void ScDataProviderDlg::deleteRowTransformation()
1008 std::function<void(sal_uInt32&)> adeleteTransformation = std::bind(&ScDataProviderDlg::deletefromList, this, std::placeholders::_1);
1009 maControls.emplace_back(std::make_unique<ScDeleteRowTransformation>(mxDoc.get(), mxTransformationList.get(), mnIndex++, adeleteTransformation));
1012 void ScDataProviderDlg::swapRowsTransformation()
1014 std::function<void(sal_uInt32&)> adeleteTransformation = std::bind(&ScDataProviderDlg::deletefromList, this, std::placeholders::_1);
1015 maControls.emplace_back(std::make_unique<ScSwapRowsTransformation>(mxDoc.get(), mxTransformationList.get(), mnIndex++, adeleteTransformation));
1018 namespace {
1020 bool hasDBName(const OUString& rName, ScDBCollection* pDBCollection)
1022 if (pDBCollection->getNamedDBs().findByUpperName(ScGlobal::getCharClass().uppercase(rName)))
1023 return true;
1025 return false;
1030 void ScDataProviderDlg::import(ScDocument& rDoc, bool bInternal)
1032 sc::ExternalDataSource aSource = getDataSource(&rDoc);
1034 for (size_t i = 0; i < maControls.size(); ++i)
1036 ScDataTransformationBaseControl* pTransformationCtrl = maControls[i].get();
1037 aSource.AddDataTransformation(pTransformationCtrl->getTransformation());
1039 if (bInternal)
1040 aSource.setDBData(pDBData->GetName());
1041 else
1043 aSource.setDBData(mxDBRanges->get_active_text());
1044 if (!hasDBName(aSource.getDBName(), rDoc.GetDBCollection()))
1045 return;
1046 rDoc.GetExternalDataMapper().insertDataSource(aSource);
1048 aSource.refresh(&rDoc, true);
1049 mxTable->Invalidate();
1052 void ScDataProviderDlg::deletefromList(sal_uInt32 nIndex)
1054 auto itr = maControls.erase(maControls.begin() + nIndex);
1055 while (itr != maControls.end())
1057 (*itr)->updateIndex(nIndex++);
1058 ++itr;
1060 --mnIndex;
1063 IMPL_LINK_NOARG(ScDeleteColumnTransformationControl, DeleteHdl, weld::Button&, void)
1065 maDeleteTransformation(mnIndex);
1068 IMPL_LINK_NOARG(ScSplitColumnTransformationControl, DeleteHdl, weld::Button&, void)
1070 maDeleteTransformation(mnIndex);
1073 IMPL_LINK_NOARG(ScMergeColumnTransformationControl, DeleteHdl, weld::Button&, void)
1075 maDeleteTransformation(mnIndex);
1078 IMPL_LINK_NOARG(ScNumberTransformation, DeleteHdl, weld::Button&, void)
1080 maDeleteTransformation(mnIndex);
1083 IMPL_LINK_NOARG(ScAggregateFunction, DeleteHdl, weld::Button&, void)
1085 maDeleteTransformation(mnIndex);
1088 IMPL_LINK_NOARG(ScSortTransformationControl, DeleteHdl, weld::Button&, void)
1090 maDeleteTransformation(mnIndex);
1093 IMPL_LINK_NOARG(ScColumnTextTransformation, DeleteHdl, weld::Button&, void)
1095 maDeleteTransformation(mnIndex);
1098 IMPL_LINK_NOARG(ScReplaceNullTransformation, DeleteHdl, weld::Button&, void)
1100 maDeleteTransformation(mnIndex);
1103 IMPL_LINK_NOARG(ScDateTimeTransformation, DeleteHdl, weld::Button&, void)
1105 maDeleteTransformation(mnIndex);
1108 IMPL_LINK_NOARG(ScFindReplaceTransformation, DeleteHdl, weld::Button&, void)
1110 maDeleteTransformation(mnIndex);
1113 IMPL_LINK_NOARG(ScDeleteRowTransformation, DeleteHdl, weld::Button&, void)
1115 maDeleteTransformation(mnIndex);
1118 IMPL_LINK_NOARG(ScSwapRowsTransformation, DeleteHdl, weld::Button&, void)
1120 maDeleteTransformation(mnIndex);
1122 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */