LibreOffice Module sc (master)  1
dataproviderdlg.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 
10 #include <dataproviderdlg.hxx>
11 
12 #include <document.hxx>
13 #include <dataprovider.hxx>
14 #include <datatransformation.hxx>
15 #include <datamapper.hxx>
16 #include <dbdata.hxx>
17 
18 #include <comphelper/string.hxx>
19 #include <sal/log.hxx>
20 #include <sfx2/filedlghelper.hxx>
21 #include <unotools/charclass.hxx>
22 #include <vcl/svapp.hxx>
23 
24 #include <utility>
25 
27 {
28 protected:
29  std::unique_ptr<weld::Builder> mxBuilder;
30  std::unique_ptr<weld::Container> mxGrid;
32 
33  sal_uInt32 mnIndex;
34 
35 public:
36  ScDataTransformationBaseControl(weld::Container* pParent, const OUString& rUIFile, sal_uInt32 nIndex);
38 
39  void updateIndex(sal_uInt32 nIndex) { mnIndex = nIndex; }
40 
41  virtual std::shared_ptr<sc::DataTransformation> getTransformation() = 0;
42 
43  static SCROW getLastRow(const ScDocument& rDoc);
44  static SCCOL getLastCol(const ScDocument& rDoc);
45 };
46 
48 {
49  SCROW nEndRow = rDoc.MaxRow();
50  return rDoc.GetLastDataRow(0, 0, 0, nEndRow);
51 }
52 
54 {
55  for (SCCOL nCol = 1; nCol <= rDoc.MaxCol(); ++nCol)
56  {
57  if (rDoc.GetCellType(nCol, 0, 0) == CELLTYPE_NONE)
58  {
59  return static_cast<SCCOL>(nCol - 1 );
60  }
61  }
62  return rDoc.MaxCol();
63 }
64 
65 ScDataTransformationBaseControl::ScDataTransformationBaseControl(weld::Container* pParent, const OUString& rUIFile, sal_uInt32 nIndex)
66  : mxBuilder(Application::CreateBuilder(pParent, rUIFile))
67  , mxGrid(mxBuilder->weld_container("grid"))
68  , mpContainer(pParent)
69  , mnIndex(nIndex)
70 {
71 }
72 
74 {
75  mpContainer->move(mxGrid.get(), nullptr);
76 }
77 
78 namespace {
79 
80 struct MenuData
81 {
82  const char* aTransformationName;
83  std::function<void(ScDataProviderDlg*)> maCallback;
84 };
85 
86 MenuData aTransformationData[] = {
87  { "Delete Column", &ScDataProviderDlg::deleteColumn },
90  { "Split Column", &ScDataProviderDlg::splitColumn },
91  { "Merge Columns", &ScDataProviderDlg::mergeColumns },
92  { "Text Transformation", &ScDataProviderDlg::textTransformation },
93  { "Sort Columns", &ScDataProviderDlg::sortTransformation },
94  { "Aggregate Functions", &ScDataProviderDlg::aggregateFunction},
95  { "Number Transformations", &ScDataProviderDlg::numberTransformation },
96  { "Replace Null Transformations", &ScDataProviderDlg::replaceNullTransformation },
97  { "Date & Time Transformations", &ScDataProviderDlg::dateTimeTransformation },
98  { "Find Replace Transformation", &ScDataProviderDlg::findReplaceTransformation}
99 };
100 
101 class ScDeleteColumnTransformationControl : public ScDataTransformationBaseControl
102 {
103 private:
104  std::unique_ptr<weld::Entry> mxColumnNums;
105  std::unique_ptr<weld::Button> mxDelete;
106  std::function<void(sal_uInt32&)> maDeleteTransformation;
107  const ScDocument* mpDoc;
108 
109 public:
110  ScDeleteColumnTransformationControl(const ScDocument* pDoc, weld::Container* pParent, sal_uInt32 aIndex, std::function<void(sal_uInt32&)> aDeleteTransformation);
111 
112  virtual std::shared_ptr<sc::DataTransformation> getTransformation() override;
113  DECL_LINK(DeleteHdl, weld::Button&, void);
114 };
115 
116 ScDeleteColumnTransformationControl::ScDeleteColumnTransformationControl(
117  const ScDocument* pDoc, weld::Container* pParent, sal_uInt32 nIndex, std::function<void(sal_uInt32&)> aDeleteTransformation)
118  : ScDataTransformationBaseControl(pParent, "modules/scalc/ui/deletecolumnentry.ui", nIndex)
119  , mxColumnNums(mxBuilder->weld_entry("ed_columns"))
120  , mxDelete(mxBuilder->weld_button("ed_delete"))
121  , maDeleteTransformation(std::move(aDeleteTransformation))
122  , mpDoc(pDoc)
123 {
124  mxDelete->connect_clicked(LINK(this,ScDeleteColumnTransformationControl, DeleteHdl));
125 }
126 
127 std::shared_ptr<sc::DataTransformation> ScDeleteColumnTransformationControl::getTransformation()
128 {
129  OUString aColumnString = mxColumnNums->get_text();
130  std::vector<OUString> aSplitColumns = comphelper::string::split(aColumnString, ';');
131  std::set<SCCOL> ColNums;
132  for (const auto& rColStr : aSplitColumns)
133  {
134  sal_Int32 nCol = rColStr.toInt32();
135  if (nCol <= 0)
136  continue;
137 
138  if (nCol > mpDoc->MaxCol())
139  continue;
140 
141  // translate from 1-based column notations to internal Calc one
142  ColNums.insert(nCol - 1);
143  }
144 
145  return std::make_shared<sc::ColumnRemoveTransformation>(std::move(ColNums));
146 }
147 
148 class ScSplitColumnTransformationControl : public ScDataTransformationBaseControl
149 {
150 private:
151  std::unique_ptr<weld::Entry> mxSeparator;
152  std::unique_ptr<weld::Entry> mxNumColumns;
153  std::unique_ptr<weld::Button> mxDelete;
154  std::function<void(sal_uInt32&)> maDeleteTransformation;
155  const ScDocument* mpDoc;
156 
157 public:
158  ScSplitColumnTransformationControl(const ScDocument* pDoc, weld::Container* pParent, sal_uInt32 nIndex, std::function<void(sal_uInt32&)> aDeleteTransformation);
159 
160  virtual std::shared_ptr<sc::DataTransformation> getTransformation() override;
161  DECL_LINK(DeleteHdl, weld::Button&, void);
162 };
163 
164 ScSplitColumnTransformationControl::ScSplitColumnTransformationControl(
165  const ScDocument* pDoc, weld::Container* pParent, sal_uInt32 nIndex,
166  std::function<void(sal_uInt32&)> aDeleteTransformation)
167  : ScDataTransformationBaseControl(pParent, "modules/scalc/ui/splitcolumnentry.ui", nIndex)
168  , mxSeparator(mxBuilder->weld_entry("ed_separator"))
169  , mxNumColumns(mxBuilder->weld_entry("num_cols"))
170  , mxDelete(mxBuilder->weld_button("ed_delete"))
171  , maDeleteTransformation(std::move(aDeleteTransformation))
172  , mpDoc(pDoc)
173 {
174  mxDelete->connect_clicked(LINK(this,ScSplitColumnTransformationControl, DeleteHdl));
175 }
176 
177 std::shared_ptr<sc::DataTransformation> ScSplitColumnTransformationControl::getTransformation()
178 {
179  OUString aSeparator = mxSeparator->get_text();
180  sal_Unicode cSeparator = aSeparator.isEmpty() ? ',' : aSeparator[0];
181  OUString aColStr = mxNumColumns->get_text();
182  SCCOL mnCol = -1;
183  sal_Int32 nCol = aColStr.toInt32();
184  if (nCol > 0 && nCol <= mpDoc->MaxCol())
185  mnCol = nCol - 1;
186  return std::make_shared<sc::SplitColumnTransformation>(mnCol, cSeparator);
187 }
188 
189 class ScMergeColumnTransformationControl : public ScDataTransformationBaseControl
190 {
191 private:
192  std::unique_ptr<weld::Entry> mxSeparator;
193  std::unique_ptr<weld::Entry> mxEdColumns;
194  std::unique_ptr<weld::Button> mxDelete;
195  std::function<void(sal_uInt32&)> maDeleteTransformation;
196  const ScDocument* mpDoc;
197 
198 public:
199  ScMergeColumnTransformationControl(const ScDocument *pDoc, weld::Container* pParent, SCCOL nStartCol, SCCOL nEndCol, sal_uInt32 nIndex, std::function<void(sal_uInt32&)> aDeleteTransformation);
200 
201  virtual std::shared_ptr<sc::DataTransformation> getTransformation() override;
202  DECL_LINK(DeleteHdl, weld::Button&, void);
203 };
204 
205 ScMergeColumnTransformationControl::ScMergeColumnTransformationControl(
206  const ScDocument* pDoc, weld::Container* pParent, SCCOL nStartCol, SCCOL nEndCol, sal_uInt32 nIndex,
207  std::function<void(sal_uInt32&)> aDeleteTransformation)
208  : ScDataTransformationBaseControl(pParent, "modules/scalc/ui/mergecolumnentry.ui", nIndex)
209  , mxSeparator(mxBuilder->weld_entry("ed_separator"))
210  , mxEdColumns(mxBuilder->weld_entry("ed_columns"))
211  , mxDelete(mxBuilder->weld_button("ed_delete"))
212  , maDeleteTransformation(std::move(aDeleteTransformation))
213  , mpDoc(pDoc)
214 {
215  mxDelete->connect_clicked(LINK(this,ScMergeColumnTransformationControl, DeleteHdl));
216 
217  OUStringBuffer aBuffer;
218 
219  // map from zero based to one based column numbers
220  aBuffer.append(static_cast<sal_Int32>(nStartCol + 1));
221  for ( SCCOL nCol = nStartCol + 1; nCol <= nEndCol; ++nCol)
222  {
223  aBuffer.append(";" + OUString::number(nCol + 1));
224  }
225 
226  mxEdColumns->set_text(aBuffer.makeStringAndClear());
227 }
228 
229 std::shared_ptr<sc::DataTransformation> ScMergeColumnTransformationControl::getTransformation()
230 {
231  OUString aColumnString = mxEdColumns->get_text();
232  std::vector<OUString> aSplitColumns = comphelper::string::split(aColumnString, ';');
233  std::set<SCCOL> aMergedColumns;
234  for (const auto& rColStr : aSplitColumns)
235  {
236  sal_Int32 nCol = rColStr.toInt32();
237  if (nCol <= 0)
238  continue;
239 
240  if (nCol > mpDoc->MaxCol())
241  continue;
242 
243  // translate from 1-based column notations to internal Calc one
244  aMergedColumns.insert(nCol - 1);
245  }
246  return std::make_shared<sc::MergeColumnTransformation>(std::move(aMergedColumns), mxSeparator->get_text());
247 }
248 
249 class ScSortTransformationControl : public ScDataTransformationBaseControl
250 {
251 private:
252  std::unique_ptr<weld::ComboBox> mxType;
253  std::unique_ptr<weld::Entry> mxEdColumns;
254  std::unique_ptr<weld::Button> mxDelete;
255  std::function<void(sal_uInt32&)> maDeleteTransformation;
256  const ScDocument* mpDoc;
257 
258 public:
259  ScSortTransformationControl(const ScDocument* pDoc, weld::Container* pParent, sal_uInt32 nIndex, std::function<void(sal_uInt32&)> aDeleteTransformation);
260 
261  virtual std::shared_ptr<sc::DataTransformation> getTransformation() override;
262  DECL_LINK(DeleteHdl, weld::Button&, void);
263 };
264 
265 ScSortTransformationControl::ScSortTransformationControl(
266  const ScDocument* pDoc, weld::Container* pParent, sal_uInt32 nIndex, std::function<void(sal_uInt32&)> aDeleteTransformation)
267  : ScDataTransformationBaseControl(pParent, "modules/scalc/ui/sorttransformationentry.ui", nIndex)
268  , mxType(mxBuilder->weld_combo_box("ed_ascending"))
269  , mxEdColumns(mxBuilder->weld_entry("ed_columns"))
270  , mxDelete(mxBuilder->weld_button("ed_delete"))
271  , maDeleteTransformation(std::move(aDeleteTransformation))
272  , mpDoc(pDoc)
273 {
274  mxDelete->connect_clicked(LINK(this,ScSortTransformationControl, DeleteHdl));
275 }
276 
277 std::shared_ptr<sc::DataTransformation> ScSortTransformationControl::getTransformation()
278 {
279  OUString aColStr = mxEdColumns->get_text();
280  bool aIsAscending = mxType->get_active();
281  SCCOL aColumn = 0;
282  sal_Int32 nCol = aColStr.toInt32();
283  if (nCol > 0 && nCol <= mpDoc->MaxCol())
284  aColumn = nCol - 1; // translate from 1-based column notations to internal Calc one
285 
286  ScSortParam aSortParam;
287  aSortParam.nRow1=0;
288  aSortParam.nRow2=getLastRow(*mpDoc);
289  aSortParam.nCol1=0;
290  aSortParam.nCol2=getLastCol(*mpDoc);
291  aSortParam.maKeyState[0].bDoSort = true;
292  aSortParam.maKeyState[0].nField = aColumn;
293  aSortParam.maKeyState[0].bAscending = aIsAscending;
294  return std::make_shared<sc::SortTransformation>(aSortParam);
295 }
296 
297 class ScColumnTextTransformation : public ScDataTransformationBaseControl
298 {
299 private:
300  std::unique_ptr<weld::Entry> mxColumnNums;
301  std::unique_ptr<weld::ComboBox> mxType;
302  std::unique_ptr<weld::Button> mxDelete;
303  std::function<void(sal_uInt32&)> maDeleteTransformation;
304  const ScDocument* mpDoc;
305 
306 public:
307  ScColumnTextTransformation(const ScDocument* pDoc, weld::Container* pParent, sal_uInt32 nIndex, std::function<void(sal_uInt32&)> aDeleteTransformation);
308 
309  virtual std::shared_ptr<sc::DataTransformation> getTransformation() override;
310  DECL_LINK(DeleteHdl, weld::Button&, void);
311 };
312 
313 ScColumnTextTransformation::ScColumnTextTransformation(
314  const ScDocument* pDoc, weld::Container* pParent, sal_uInt32 nIndex, std::function<void(sal_uInt32&)> aDeleteTransformation)
315  : ScDataTransformationBaseControl(pParent, "modules/scalc/ui/texttransformationentry.ui", nIndex)
316  , mxColumnNums(mxBuilder->weld_entry("ed_columns"))
317  , mxType(mxBuilder->weld_combo_box("ed_lst"))
318  , mxDelete(mxBuilder->weld_button("ed_delete"))
319  , maDeleteTransformation(std::move(aDeleteTransformation))
320  , mpDoc(pDoc)
321 {
322  mxDelete->connect_clicked(LINK(this,ScColumnTextTransformation, DeleteHdl));
323 }
324 
325 std::shared_ptr<sc::DataTransformation> ScColumnTextTransformation::getTransformation()
326 {
327  OUString aColumnString = mxColumnNums->get_text();
328  std::vector<OUString> aSplitColumns = comphelper::string::split(aColumnString, ';');
329  std::set<SCCOL> aColumns;
330  for (const auto& rColStr : aSplitColumns)
331  {
332  sal_Int32 nCol = rColStr.toInt32();
333  if (nCol <= 0)
334  continue;
335 
336  if (nCol > mpDoc->MaxCol())
337  continue;
338 
339  // translate from 1-based column notations to internal Calc one
340  aColumns.insert(nCol - 1);
341  }
342 
343  sal_Int32 nPos = mxType->get_active();
344  switch (nPos)
345  {
346  case 0:
347  return std::make_shared<sc::TextTransformation>(std::move(aColumns),sc::TEXT_TRANSFORM_TYPE::TO_LOWER);
348  case 1:
349  return std::make_shared<sc::TextTransformation>(std::move(aColumns),sc::TEXT_TRANSFORM_TYPE::TO_UPPER);
350  case 2:
351  return std::make_shared<sc::TextTransformation>(std::move(aColumns),sc::TEXT_TRANSFORM_TYPE::CAPITALIZE);
352  case 3:
353  return std::make_shared<sc::TextTransformation>(std::move(aColumns),sc::TEXT_TRANSFORM_TYPE::TRIM);
354  default:
355  assert(false);
356  }
357 
358  return nullptr;
359 }
360 
361 class ScAggregateFunction : public ScDataTransformationBaseControl
362 {
363 private:
364  std::unique_ptr<weld::Entry> mxColumnNums;
365  std::unique_ptr<weld::ComboBox> mxType;
366  std::unique_ptr<weld::Button> mxDelete;
367  std::function<void(sal_uInt32&)> maDeleteTransformation;
368  const ScDocument* mpDoc;
369 
370 public:
371  ScAggregateFunction(const ScDocument* pDoc, weld::Container* pParent, sal_uInt32 nIndex, std::function<void(sal_uInt32&)> aDeleteTransformation);
372 
373  virtual std::shared_ptr<sc::DataTransformation> getTransformation() override;
374  DECL_LINK(DeleteHdl, weld::Button&, void);
375 };
376 
377 ScAggregateFunction::ScAggregateFunction(const ScDocument* pDoc, weld::Container* pParent, sal_uInt32 nIndex,
378  std::function<void(sal_uInt32&)> aDeleteTransformation)
379  : ScDataTransformationBaseControl(pParent, "modules/scalc/ui/aggregatefunctionentry.ui", nIndex)
380  , mxColumnNums(mxBuilder->weld_entry("ed_columns"))
381  , mxType(mxBuilder->weld_combo_box("ed_lst"))
382  , mxDelete(mxBuilder->weld_button("ed_delete"))
383  , maDeleteTransformation(std::move(aDeleteTransformation))
384  , mpDoc(pDoc)
385 {
386  mxDelete->connect_clicked(LINK(this,ScAggregateFunction, DeleteHdl));
387 }
388 
389 std::shared_ptr<sc::DataTransformation> ScAggregateFunction::getTransformation()
390 {
391  OUString aColumnString = mxColumnNums->get_text();
392  sal_Int32 nPos = mxType->get_active();
393  std::vector<OUString> aSplitColumns = comphelper::string::split(aColumnString, ';');
394  std::set<SCCOL> aColumns;
395  for (const auto& rColStr : aSplitColumns)
396  {
397  sal_Int32 nCol = rColStr.toInt32();
398  if (nCol <= 0)
399  continue;
400 
401  if (nCol > mpDoc->MaxCol())
402  continue;
403 
404  // translate from 1-based column notations to internal Calc one
405  aColumns.insert(nCol - 1);
406  }
407  switch (nPos)
408  {
409  case 0:
410  return std::make_shared<sc::AggregateFunction>(std::move(aColumns),sc::AGGREGATE_FUNCTION::SUM);
411  case 1:
412  return std::make_shared<sc::AggregateFunction>(std::move(aColumns),sc::AGGREGATE_FUNCTION::AVERAGE);
413  case 2:
414  return std::make_shared<sc::AggregateFunction>(std::move(aColumns),sc::AGGREGATE_FUNCTION::MIN);
415  case 3:
416  return std::make_shared<sc::AggregateFunction>(std::move(aColumns),sc::AGGREGATE_FUNCTION::MAX);
417  default:
418  assert(false);
419  }
420 
421  return nullptr;
422 }
423 
424 class ScNumberTransformation : public ScDataTransformationBaseControl
425 {
426 private:
427  std::unique_ptr<weld::Entry> mxColumnNums;
428  std::unique_ptr<weld::ComboBox> mxType;
429  std::unique_ptr<weld::Button> mxDelete;
430  std::function<void(sal_uInt32&)> maDeleteTransformation;
431  const ScDocument* mpDoc;
432 
433 public:
434  ScNumberTransformation(const ScDocument *pDoc, weld::Container* pParent, sal_uInt32 nIndex, std::function<void(sal_uInt32&)> aDeleteTransformation);
435 
436  virtual std::shared_ptr<sc::DataTransformation> getTransformation() override;
437  DECL_LINK(DeleteHdl, weld::Button&, void);
438 };
439 
440 ScNumberTransformation::ScNumberTransformation(
441  const ScDocument *pDoc, weld::Container* pParent, sal_uInt32 nIndex, std::function<void(sal_uInt32&)> aDeleteTransformation)
442  : ScDataTransformationBaseControl(pParent, "modules/scalc/ui/numbertransformationentry.ui", nIndex)
443  , mxColumnNums(mxBuilder->weld_entry("ed_columns"))
444  , mxType(mxBuilder->weld_combo_box("ed_lst"))
445  , mxDelete(mxBuilder->weld_button("ed_delete"))
446  , maDeleteTransformation(std::move(aDeleteTransformation))
447  , mpDoc(pDoc)
448 {
449  mxDelete->connect_clicked(LINK(this,ScNumberTransformation, DeleteHdl));
450 }
451 
452 std::shared_ptr<sc::DataTransformation> ScNumberTransformation::getTransformation()
453 {
454  OUString aColumnString = mxColumnNums->get_text();
455  sal_Int32 nPos = mxType->get_active();
456  std::vector<OUString> aSplitColumns = comphelper::string::split(aColumnString, ';');
457  std::set<SCCOL> aColumns;
458  for (const auto& rColStr : aSplitColumns)
459  {
460  sal_Int32 nCol = rColStr.toInt32();
461  if (nCol <= 0)
462  continue;
463 
464  if (nCol > mpDoc->MaxCol())
465  continue;
466 
467  // translate from 1-based column notations to internal Calc one
468  aColumns.insert(nCol - 1);
469  }
470  switch (nPos)
471  {
472  case 0:
473  return std::make_shared<sc::NumberTransformation>(std::move(aColumns),sc::NUMBER_TRANSFORM_TYPE::SIGN);
474  case 1:
475  return std::make_shared<sc::NumberTransformation>(std::move(aColumns),sc::NUMBER_TRANSFORM_TYPE::ROUND);
476  case 2:
477  return std::make_shared<sc::NumberTransformation>(std::move(aColumns),sc::NUMBER_TRANSFORM_TYPE::ROUND_UP);
478  case 3:
479  return std::make_shared<sc::NumberTransformation>(std::move(aColumns),sc::NUMBER_TRANSFORM_TYPE::ROUND_DOWN);
480  case 4:
481  return std::make_shared<sc::NumberTransformation>(std::move(aColumns),sc::NUMBER_TRANSFORM_TYPE::ABSOLUTE);
482  case 5:
483  return std::make_shared<sc::NumberTransformation>(std::move(aColumns),sc::NUMBER_TRANSFORM_TYPE::LOG_E);
484  case 6:
485  return std::make_shared<sc::NumberTransformation>(std::move(aColumns),sc::NUMBER_TRANSFORM_TYPE::LOG_10);
486  case 7:
487  return std::make_shared<sc::NumberTransformation>(std::move(aColumns),sc::NUMBER_TRANSFORM_TYPE::CUBE);
488  case 8:
489  return std::make_shared<sc::NumberTransformation>(std::move(aColumns),sc::NUMBER_TRANSFORM_TYPE::SQUARE);
490  case 9:
491  return std::make_shared<sc::NumberTransformation>(std::move(aColumns),sc::NUMBER_TRANSFORM_TYPE::SQUARE_ROOT);
492  case 10:
493  return std::make_shared<sc::NumberTransformation>(std::move(aColumns),sc::NUMBER_TRANSFORM_TYPE::EXPONENT);
494  case 11:
495  return std::make_shared<sc::NumberTransformation>(std::move(aColumns),sc::NUMBER_TRANSFORM_TYPE::IS_EVEN);
496  case 12:
497  return std::make_shared<sc::NumberTransformation>(std::move(aColumns),sc::NUMBER_TRANSFORM_TYPE::IS_ODD);
498  default:
499  assert(false);
500  }
501 
502  return nullptr;
503 }
504 
505 class ScReplaceNullTransformation : public ScDataTransformationBaseControl
506 {
507 private:
508  std::unique_ptr<weld::Entry> mxColumnNums;
509  std::unique_ptr<weld::Entry> mxReplaceString;
510  std::unique_ptr<weld::Button> mxDelete;
511  std::function<void(sal_uInt32&)> maDeleteTransformation;
512  const ScDocument *mpDoc;
513 
514 public:
515 
516  ScReplaceNullTransformation(const ScDocument *pDoc, weld::Container* pParent, sal_uInt32 nIndex, std::function<void(sal_uInt32&)> aDeleteTransformation);
517 
518  virtual std::shared_ptr<sc::DataTransformation> getTransformation() override;
519  DECL_LINK(DeleteHdl, weld::Button&, void);
520 };
521 
522 ScReplaceNullTransformation::ScReplaceNullTransformation(const ScDocument *pDoc, weld::Container* pParent, sal_uInt32 nIndex, std::function<void(sal_uInt32&)> aDeleteTransformation)
523  : ScDataTransformationBaseControl(pParent,"modules/scalc/ui/replacenulltransformationentry.ui", nIndex)
524  , mxColumnNums(mxBuilder->weld_entry("ed_columns"))
525  , mxReplaceString(mxBuilder->weld_entry("ed_str"))
526  , mxDelete(mxBuilder->weld_button("ed_delete"))
527  , maDeleteTransformation(aDeleteTransformation)
528  , mpDoc(pDoc)
529 {
530  mxDelete->connect_clicked(LINK(this,ScReplaceNullTransformation, DeleteHdl));
531 }
532 
533 
534 std::shared_ptr<sc::DataTransformation> ScReplaceNullTransformation::getTransformation()
535 {
536  OUString aColumnString = mxColumnNums->get_text();
537  OUString aReplaceWithString = mxReplaceString->get_text();
538  std::vector<OUString> aSplitColumns = comphelper::string::split(aColumnString, ';');
539  std::set<SCCOL> aColumns;
540  for (const auto& rColStr : aSplitColumns)
541  {
542  sal_Int32 nCol = rColStr.toInt32();
543  if (nCol <= 0)
544  continue;
545 
546  if (nCol > mpDoc->MaxCol())
547  continue;
548 
549  // translate from 1-based column notations to internal Calc one
550  aColumns.insert(nCol - 1);
551  }
552 
553  return std::make_shared<sc::ReplaceNullTransformation>(std::move(aColumns),aReplaceWithString);
554 }
555 
556 class ScDateTimeTransformation : public ScDataTransformationBaseControl
557 {
558 private:
559  std::unique_ptr<weld::Entry> mxColumnNums;
560  std::unique_ptr<weld::ComboBox> mxType;
561  std::unique_ptr<weld::Button> mxDelete;
562  std::function<void(sal_uInt32&)> maDeleteTransformation;
563  const ScDocument* mpDoc;
564 
565 public:
566 
567  ScDateTimeTransformation(const ScDocument* pDoc, weld::Container* pParent, sal_uInt32 nIndex, std::function<void(sal_uInt32&)> aDeleteTransformation);
568 
569  virtual std::shared_ptr<sc::DataTransformation> getTransformation() override;
570  DECL_LINK(DeleteHdl, weld::Button&, void);
571 };
572 
573 ScDateTimeTransformation::ScDateTimeTransformation(const ScDocument* pDoc, weld::Container* pParent, sal_uInt32 nIndex, std::function<void(sal_uInt32&)> aDeleteTransformation)
574  : ScDataTransformationBaseControl(pParent,"modules/scalc/ui/datetimetransformationentry.ui", nIndex)
575  , mxColumnNums(mxBuilder->weld_entry("ed_columns"))
576  , mxType(mxBuilder->weld_combo_box("ed_lst"))
577  , mxDelete(mxBuilder->weld_button("ed_delete"))
578  , maDeleteTransformation(aDeleteTransformation)
579  , mpDoc(pDoc)
580 {
581  mxDelete->connect_clicked(LINK(this,ScDateTimeTransformation, DeleteHdl));
582 }
583 
584 std::shared_ptr<sc::DataTransformation> ScDateTimeTransformation::getTransformation()
585 {
586  OUString aColumnString = mxColumnNums->get_text();
587  sal_Int32 nPos = mxType->get_active();
588  std::vector<OUString> aSplitColumns = comphelper::string::split(aColumnString, ';');
589  std::set<SCCOL> aColumns;
590  for (const auto& rColStr : aSplitColumns)
591  {
592  sal_Int32 nCol = rColStr.toInt32();
593  if (nCol <= 0)
594  continue;
595 
596  if (nCol > mpDoc->MaxCol())
597  continue;
598 
599  // translate from 1-based column notations to internal Calc one
600  aColumns.insert(nCol - 1);
601  }
602  switch (nPos)
603  {
604  case 0:
605  return std::make_shared<sc::DateTimeTransformation>(std::move(aColumns),sc::DATETIME_TRANSFORMATION_TYPE::DATE_STRING);
606  case 1:
607  return std::make_shared<sc::DateTimeTransformation>(std::move(aColumns),sc::DATETIME_TRANSFORMATION_TYPE::YEAR);
608  case 2:
609  return std::make_shared<sc::DateTimeTransformation>(std::move(aColumns),sc::DATETIME_TRANSFORMATION_TYPE::START_OF_YEAR);
610  case 3:
611  return std::make_shared<sc::DateTimeTransformation>(std::move(aColumns),sc::DATETIME_TRANSFORMATION_TYPE::END_OF_YEAR);
612  case 4:
613  return std::make_shared<sc::DateTimeTransformation>(std::move(aColumns),sc::DATETIME_TRANSFORMATION_TYPE::MONTH);
614  case 5:
615  return std::make_shared<sc::DateTimeTransformation>(std::move(aColumns),sc::DATETIME_TRANSFORMATION_TYPE::MONTH_NAME);
616  case 6:
617  return std::make_shared<sc::DateTimeTransformation>(std::move(aColumns),sc::DATETIME_TRANSFORMATION_TYPE::START_OF_MONTH);
618  case 7:
619  return std::make_shared<sc::DateTimeTransformation>(std::move(aColumns),sc::DATETIME_TRANSFORMATION_TYPE::END_OF_MONTH);
620  case 8:
621  return std::make_shared<sc::DateTimeTransformation>(std::move(aColumns),sc::DATETIME_TRANSFORMATION_TYPE::DAY);
622  case 9:
623  return std::make_shared<sc::DateTimeTransformation>(std::move(aColumns),sc::DATETIME_TRANSFORMATION_TYPE::DAY_OF_WEEK);
624  case 10:
625  return std::make_shared<sc::DateTimeTransformation>(std::move(aColumns),sc::DATETIME_TRANSFORMATION_TYPE::DAY_OF_YEAR);
626  case 11:
627  return std::make_shared<sc::DateTimeTransformation>(std::move(aColumns),sc::DATETIME_TRANSFORMATION_TYPE::QUARTER);
628  case 12:
629  return std::make_shared<sc::DateTimeTransformation>(std::move(aColumns),sc::DATETIME_TRANSFORMATION_TYPE::START_OF_QUARTER);
630  case 13:
631  return std::make_shared<sc::DateTimeTransformation>(std::move(aColumns),sc::DATETIME_TRANSFORMATION_TYPE::END_OF_QUARTER);
632  case 14:
633  return std::make_shared<sc::DateTimeTransformation>(std::move(aColumns),sc::DATETIME_TRANSFORMATION_TYPE::HOUR);
634  case 15:
635  return std::make_shared<sc::DateTimeTransformation>(std::move(aColumns),sc::DATETIME_TRANSFORMATION_TYPE::MINUTE);
636  case 16:
637  return std::make_shared<sc::DateTimeTransformation>(std::move(aColumns),sc::DATETIME_TRANSFORMATION_TYPE::SECOND);
638  case 17:
639  return std::make_shared<sc::DateTimeTransformation>(std::move(aColumns),sc::DATETIME_TRANSFORMATION_TYPE::TIME);
640  default:
641  assert(false);
642  }
643 
644  return nullptr;
645 }
646 
647 class ScFindReplaceTransformation : public ScDataTransformationBaseControl
648 {
649 private:
650  std::unique_ptr<weld::Entry> mxFindString;
651  std::unique_ptr<weld::Entry> mxReplaceString;
652  std::unique_ptr<weld::Entry> mxEdColumns;
653  std::unique_ptr<weld::Button> mxDelete;
654  std::function<void(sal_uInt32&)> maDeleteTransformation;
655  const ScDocument* mpDoc;
656 
657 public:
658  ScFindReplaceTransformation(const ScDocument* pDoc, weld::Container* pParent, sal_uInt32 nIndex, std::function<void(sal_uInt32&)> aDeleteTransformation);
659 
660  virtual std::shared_ptr<sc::DataTransformation> getTransformation() override;
661  DECL_LINK(DeleteHdl, weld::Button&, void);
662 };
663 
664 ScFindReplaceTransformation::ScFindReplaceTransformation(
665  const ScDocument *pDoc, weld::Container* pParent, sal_uInt32 nIndex,
666  std::function<void(sal_uInt32&)> aDeleteTransformation)
667  : ScDataTransformationBaseControl(pParent, "modules/scalc/ui/findreplaceentry.ui", nIndex)
668  , mxFindString(mxBuilder->weld_entry("ed_find"))
669  , mxReplaceString(mxBuilder->weld_entry("ed_replace"))
670  , mxEdColumns(mxBuilder->weld_entry("ed_columns"))
671  , mxDelete(mxBuilder->weld_button("ed_delete"))
672  , maDeleteTransformation(std::move(aDeleteTransformation))
673  , mpDoc(pDoc)
674 {
675  mxDelete->connect_clicked(LINK(this, ScFindReplaceTransformation, DeleteHdl));
676 }
677 
678 std::shared_ptr<sc::DataTransformation> ScFindReplaceTransformation::getTransformation()
679 {
680  OUString aColStr = mxEdColumns->get_text();
681  SCCOL aColumn = -1;
682  sal_Int32 nCol = aColStr.toInt32();
683  if (nCol > 0 && nCol <= mpDoc->MaxCol())
684  aColumn = nCol - 1;
685  return std::make_shared<sc::FindReplaceTransformation>(aColumn, mxFindString->get_text(), mxReplaceString->get_text());
686 }
687 
688 class ScDeleteRowTransformation : public ScDataTransformationBaseControl
689 {
690 private:
691  std::unique_ptr<weld::Entry> mxFindString;
692  std::unique_ptr<weld::Entry> mxEdColumns;
693  std::unique_ptr<weld::Button> mxDelete;
694  std::function<void(sal_uInt32&)> maDeleteTransformation;
695  const ScDocument* mpDoc;
696 
697 public:
698  ScDeleteRowTransformation(const ScDocument* pDoc, weld::Container* pParent, sal_uInt32 nIndex, std::function<void(sal_uInt32&)> aDeleteTransformation);
699 
700  virtual std::shared_ptr<sc::DataTransformation> getTransformation() override;
701  DECL_LINK(DeleteHdl, weld::Button&, void);
702 };
703 
704 ScDeleteRowTransformation::ScDeleteRowTransformation(
705  const ScDocument *pDoc, weld::Container* pParent, sal_uInt32 nIndex,
706  std::function<void(sal_uInt32&)> aDeleteTransformation)
707  : ScDataTransformationBaseControl(pParent, "modules/scalc/ui/deleterowentry.ui", nIndex)
708  , mxFindString(mxBuilder->weld_entry("ed_find"))
709  , mxEdColumns(mxBuilder->weld_entry("ed_columns"))
710  , mxDelete(mxBuilder->weld_button("ed_delete"))
711  , maDeleteTransformation(std::move(aDeleteTransformation))
712  , mpDoc(pDoc)
713 {
714  mxDelete->connect_clicked(LINK(this, ScDeleteRowTransformation, DeleteHdl));
715 }
716 
717 std::shared_ptr<sc::DataTransformation> ScDeleteRowTransformation::getTransformation()
718 {
719  OUString aColStr = mxEdColumns->get_text();
720  SCCOL aColumn = -1;
721  sal_Int32 nCol = aColStr.toInt32();
722  if (nCol > 0 && nCol <= mpDoc->MaxCol())
723  aColumn = nCol - 1;
724  return std::make_shared<sc::DeleteRowTransformation>(aColumn, mxFindString->get_text());
725 }
726 
727 class ScSwapRowsTransformation : public ScDataTransformationBaseControl
728 {
729 private:
730  std::unique_ptr<weld::Entry> mxRow;
731  std::unique_ptr<weld::Entry> nxRow;
732  std::unique_ptr<weld::Button> mxDelete;
733  std::function<void(sal_uInt32&)> maDeleteTransformation;
734  const ScDocument* mpDoc;
735 
736 public:
737  ScSwapRowsTransformation(const ScDocument* pDoc, weld::Container* pParent, sal_uInt32 nIndex, std::function<void(sal_uInt32&)> aDeleteTransformation);
738 
739  virtual std::shared_ptr<sc::DataTransformation> getTransformation() override;
740  DECL_LINK(DeleteHdl, weld::Button&, void);
741 };
742 
743 ScSwapRowsTransformation::ScSwapRowsTransformation(
744  const ScDocument *pDoc, weld::Container* pParent, sal_uInt32 nIndex,
745  std::function<void(sal_uInt32&)> aDeleteTransformation)
746  : ScDataTransformationBaseControl(pParent, "modules/scalc/ui/swaprowsentry.ui", nIndex)
747  , mxRow(mxBuilder->weld_entry("ed_row1"))
748  , nxRow(mxBuilder->weld_entry("ed_row2"))
749  , mxDelete(mxBuilder->weld_button("ed_delete"))
750  , maDeleteTransformation(std::move(aDeleteTransformation))
751  , mpDoc(pDoc)
752 {
753  mxDelete->connect_clicked(LINK(this, ScSwapRowsTransformation, DeleteHdl));
754 }
755 
756 std::shared_ptr<sc::DataTransformation> ScSwapRowsTransformation::getTransformation()
757 {
758  OUString aRowStr = mxRow->get_text();
759  OUString bRowStr = nxRow->get_text();
760  SCROW aRow = -1;
761  SCROW bRow = -1;
762  sal_Int32 mRow = aRowStr.toInt32();
763  sal_Int32 nRow = bRowStr.toInt32();
764  if (mRow > 0 && mRow <= mpDoc->MaxRow())
765  aRow = mRow - 1;
766  if (nRow > 0 && nRow <= mpDoc->MaxRow())
767  bRow = nRow - 1;
768  return std::make_shared<sc::SwapRowsTransformation>(aRow, bRow);
769 }
770 
771 }
772 
773 ScDataProviderDlg::ScDataProviderDlg(weld::Window* pParent, std::shared_ptr<ScDocument> pDoc,
774  const ScDocument* pDocument)
775  : GenericDialogController(pParent, "modules/scalc/ui/dataproviderdlg.ui", "dataproviderdlg")
776  , mxDoc(std::move(pDoc))
777  , mxBox(m_xBuilder->weld_container("data_table"))
778  , m_xTableParent(mxBox->CreateChildFrame())
779  , mxTable(VclPtr<ScDataTableView>::Create(m_xTableParent, mxDoc))
780  , mxDBRanges(m_xBuilder->weld_combo_box("select_db_range"))
781  , mxOKBtn(m_xBuilder->weld_button("okay"))
782  , mxCancelBtn(m_xBuilder->weld_button("cancel"))
783  , mxAddTransformationBtn(m_xBuilder->weld_button("add_transformation"))
784  , mxScroll(m_xBuilder->weld_scrolled_window("scroll"))
785  , mxTransformationList(m_xBuilder->weld_container("transformation_ctrl"))
786  , mxTransformationBox(m_xBuilder->weld_combo_box("transformation_box"))
787  , mxProviderList(m_xBuilder->weld_combo_box("provider_lst"))
788  , mxEditURL(m_xBuilder->weld_entry("ed_url"))
789  , mxEditID(m_xBuilder->weld_entry("ed_id"))
790  , mxApplyBtn(m_xBuilder->weld_button("apply"))
791  , mxBrowseBtn(m_xBuilder->weld_button("browse"))
792  , maIdle("ScDataProviderDlg maIdle")
793  , mnIndex(0)
794 {
795  Size aPrefSize = mxTable->GetOptimalSize();
796  mxBox->set_size_request(aPrefSize.Width(), aPrefSize.Height());
797  mxTable->Show();
798 
799  ScDBCollection* pDBCollection = pDocument->GetDBCollection();
800  auto& rNamedDBs = pDBCollection->getNamedDBs();
801  for (auto& rNamedDB : rNamedDBs)
802  {
803  mxDBRanges->append_text(rNamedDB->GetName());
804  }
805 
806  for (const auto& i : aTransformationData)
807  {
808  mxTransformationBox->append_text(OUString::createFromAscii(i.aTransformationName));
809  }
810 
811  pDBData = new ScDBData("data", 0, 0, 0, mxDoc->MaxCol(), mxDoc->MaxRow());
812  bool bSuccess = mxDoc->GetDBCollection()->getNamedDBs().insert(std::unique_ptr<ScDBData>(pDBData));
813  SAL_WARN_IF(!bSuccess, "sc", "temporary warning");
814 
815  auto aDataProvider = sc::DataProviderFactory::getDataProviders();
816  for (const auto& rDataProvider : aDataProvider)
817  {
818  mxProviderList->append_text(rDataProvider);
819  }
820 
821  mxOKBtn->connect_clicked(LINK(this, ScDataProviderDlg, ApplyQuitHdl));
822  mxCancelBtn->connect_clicked(LINK(this, ScDataProviderDlg, CancelQuitHdl));
823  mxAddTransformationBtn->connect_clicked(LINK(this, ScDataProviderDlg, TransformationListHdl));
824  mxApplyBtn->connect_clicked(LINK(this, ScDataProviderDlg, ApplyBtnHdl));
825  mxBrowseBtn->connect_clicked(LINK(this, ScDataProviderDlg, BrowseBtnHdl));
826  mxTransformationBox->connect_changed(LINK(this, ScDataProviderDlg, TransformationSelectHdl));
827  mxProviderList->connect_changed(LINK(this, ScDataProviderDlg, ProviderSelectHdl));
828  mxEditID->connect_changed(LINK(this, ScDataProviderDlg, IDEditHdl));
829  mxEditURL->connect_changed(LINK(this, ScDataProviderDlg, URLEditHdl));
830 
831  msApplyTooltip = mxApplyBtn->get_tooltip_text();
833  mxAddTransformationBtn->set_sensitive(false);
834  mxAddTransformationBtn->set_tooltip_text(OUString());
835  isValid();
836 
837  maIdle.SetPriority( TaskPriority::LOWEST );
838  maIdle.SetInvokeHandler( LINK( this, ScDataProviderDlg, ScrollToEnd) );
839 }
840 
842 {
844  m_xTableParent->dispose();
845  m_xTableParent.clear();
846 }
847 
849 {
850  mxScroll->vadjustment_set_value(mxScroll->vadjustment_get_upper());
851 }
852 
854 {
855  m_xDialog->response(RET_OK);
856 }
857 
859 {
860  m_xDialog->response(RET_CANCEL);
861 }
862 
863 IMPL_LINK_NOARG(ScDataProviderDlg, TransformationListHdl, weld::Button&, void)
864 {
865  OUString transformation_string = mxTransformationBox->get_active_text();
866  for (auto& i: aTransformationData)
867  {
868  if (transformation_string == OUString::createFromAscii(i.aTransformationName))
869  {
870  i.maCallback(this);
871  maIdle.Start();
872  return;
873  }
874  }
875 }
876 
878 {
879  isValid();
880 }
881 
883 {
884  isValid();
885 }
886 
888 {
889  isValid();
890 }
891 
893 {
894  updateApplyBtn(true);
895  import(*mxDoc, true);
896 }
897 
899 {
900  sfx2::FileDialogHelper aFileDialog(0, FileDialogFlags::NONE, m_xDialog.get());
902  if (aFileDialog.Execute() != ERRCODE_NONE)
903  return;
904 
905  mxEditURL->set_text(aFileDialog.GetPath());
906  isValid();
907 }
908 
909 IMPL_LINK_NOARG(ScDataProviderDlg, TransformationSelectHdl, weld::ComboBox&, void)
910 {
911  mxAddTransformationBtn->set_sensitive(true);
912  mxAddTransformationBtn->set_tooltip_text(msAddTransformationToolTip);
913 }
914 
916 {
917  OUString aURL = mxEditURL->get_text();
918  OUString aProvider = mxProviderList->get_active_text();
919  sc::ExternalDataSource aSource(aURL, aProvider, pDoc);
920 
921  OUString aID = mxEditID->get_text();
922  aSource.setID(aID);
923  return aSource;
924 }
925 
927 {
928  bool bValid = !mxProviderList->get_active_text().isEmpty();
929  bValid &= !mxEditURL->get_text().isEmpty();
930  updateApplyBtn(bValid);
931 }
932 
933 void ScDataProviderDlg::updateApplyBtn(bool bValidConfig)
934 {
935  if (!bValidConfig)
936  {
937  mxApplyBtn->set_sensitive(false);
938  mxApplyBtn->set_tooltip_text(OUString());
939  return;
940  }
941 
942  mxApplyBtn->set_sensitive(true);
943  mxApplyBtn->set_tooltip_text(msApplyTooltip);
944 }
945 
947 {
948  std::function<void(sal_uInt32&)> adeleteTransformation = std::bind(&ScDataProviderDlg::deletefromList,this, std::placeholders::_1);
949  maControls.emplace_back(std::make_unique<ScDeleteColumnTransformationControl>(mxDoc.get(), mxTransformationList.get(), mnIndex++, adeleteTransformation));
950 }
951 
953 {
954  std::function<void(sal_uInt32&)> adeleteTransformation = std::bind(&ScDataProviderDlg::deletefromList,this, std::placeholders::_1);
955  maControls.emplace_back(std::make_unique<ScSplitColumnTransformationControl>(mxDoc.get(), mxTransformationList.get(), mnIndex++, adeleteTransformation));
956 }
957 
959 {
960  SCCOL nStartCol = -1;
961  SCCOL nEndCol = -1;
962  mxTable->getColRange(nStartCol, nEndCol);
963  std::function<void(sal_uInt32&)> adeleteTransformation = std::bind(&ScDataProviderDlg::deletefromList,this, std::placeholders::_1);
964  maControls.emplace_back(std::make_unique<ScMergeColumnTransformationControl>(mxDoc.get(), mxTransformationList.get(), nStartCol, nEndCol, mnIndex++, adeleteTransformation));
965 }
966 
968 {
969  std::function<void(sal_uInt32&)> adeleteTransformation = std::bind(&ScDataProviderDlg::deletefromList,this, std::placeholders::_1);
970  maControls.emplace_back(std::make_unique<ScColumnTextTransformation>(mxDoc.get(), mxTransformationList.get(), mnIndex++, adeleteTransformation));
971 }
972 
974 {
975  std::function<void(sal_uInt32&)> adeleteTransformation = std::bind(&ScDataProviderDlg::deletefromList,this, std::placeholders::_1);
976  maControls.emplace_back(std::make_unique<ScSortTransformationControl>(mxDoc.get(), mxTransformationList.get(), mnIndex++, adeleteTransformation));
977 }
978 
980 {
981  std::function<void(sal_uInt32&)> adeleteTransformation = std::bind(&ScDataProviderDlg::deletefromList,this, std::placeholders::_1);
982  maControls.emplace_back(std::make_unique<ScAggregateFunction>(mxDoc.get(), mxTransformationList.get(), mnIndex++, adeleteTransformation));
983 }
984 
986 {
987  std::function<void(sal_uInt32&)> adeleteTransformation = std::bind(&ScDataProviderDlg::deletefromList,this, std::placeholders::_1);
988  maControls.emplace_back(std::make_unique<ScNumberTransformation>(mxDoc.get(), mxTransformationList.get(), mnIndex++, adeleteTransformation));
989 }
990 
992 {
993  std::function<void(sal_uInt32&)> adeleteTransformation = std::bind(&ScDataProviderDlg::deletefromList,this, std::placeholders::_1);
994  maControls.emplace_back(std::make_unique<ScReplaceNullTransformation>(mxDoc.get(), mxTransformationList.get(), mnIndex++, adeleteTransformation));
995 }
996 
998 {
999  std::function<void(sal_uInt32&)> adeleteTransformation = std::bind(&ScDataProviderDlg::deletefromList,this, std::placeholders::_1);
1000  maControls.emplace_back(std::make_unique<ScDateTimeTransformation>(mxDoc.get(), mxTransformationList.get(), mnIndex++, adeleteTransformation));
1001 }
1002 
1004 {
1005  std::function<void(sal_uInt32&)> adeleteTransformation = std::bind(&ScDataProviderDlg::deletefromList, this, std::placeholders::_1);
1006  maControls.emplace_back(std::make_unique<ScFindReplaceTransformation>(mxDoc.get(), mxTransformationList.get(), mnIndex++, adeleteTransformation));
1007 }
1008 
1010 {
1011  std::function<void(sal_uInt32&)> adeleteTransformation = std::bind(&ScDataProviderDlg::deletefromList, this, std::placeholders::_1);
1012  maControls.emplace_back(std::make_unique<ScDeleteRowTransformation>(mxDoc.get(), mxTransformationList.get(), mnIndex++, adeleteTransformation));
1013 }
1014 
1016 {
1017  std::function<void(sal_uInt32&)> adeleteTransformation = std::bind(&ScDataProviderDlg::deletefromList, this, std::placeholders::_1);
1018  maControls.emplace_back(std::make_unique<ScSwapRowsTransformation>(mxDoc.get(), mxTransformationList.get(), mnIndex++, adeleteTransformation));
1019 }
1020 
1021 namespace {
1022 
1023 bool hasDBName(const OUString& rName, ScDBCollection* pDBCollection)
1024 {
1025  if (pDBCollection->getNamedDBs().findByUpperName(ScGlobal::getCharClass().uppercase(rName)))
1026  return true;
1027 
1028  return false;
1029 }
1030 
1031 }
1032 
1033 void ScDataProviderDlg::import(ScDocument& rDoc, bool bInternal)
1034 {
1035  sc::ExternalDataSource aSource = getDataSource(&rDoc);
1036 
1037  for (size_t i = 0; i < maControls.size(); ++i)
1038  {
1039  ScDataTransformationBaseControl* pTransformationCtrl = maControls[i].get();
1040  aSource.AddDataTransformation(pTransformationCtrl->getTransformation());
1041  }
1042  if (bInternal)
1043  aSource.setDBData(pDBData->GetName());
1044  else
1045  {
1046  aSource.setDBData(mxDBRanges->get_active_text());
1047  if (!hasDBName(aSource.getDBName(), rDoc.GetDBCollection()))
1048  return;
1049  rDoc.GetExternalDataMapper().insertDataSource(aSource);
1050  }
1051  aSource.refresh(&rDoc, true);
1052  mxTable->Invalidate();
1053 }
1054 
1055 void ScDataProviderDlg::deletefromList(sal_uInt32 nIndex)
1056 {
1057  auto itr = maControls.erase(maControls.begin() + nIndex);
1058  while (itr != maControls.end())
1059  {
1060  (*itr)->updateIndex(nIndex++);
1061  ++itr;
1062  }
1063  --mnIndex;
1064 }
1065 
1066 IMPL_LINK_NOARG(ScDeleteColumnTransformationControl, DeleteHdl, weld::Button&, void)
1067 {
1068  maDeleteTransformation(mnIndex);
1069 }
1070 
1071 IMPL_LINK_NOARG(ScSplitColumnTransformationControl, DeleteHdl, weld::Button&, void)
1072 {
1073  maDeleteTransformation(mnIndex);
1074 }
1075 
1076 IMPL_LINK_NOARG(ScMergeColumnTransformationControl, DeleteHdl, weld::Button&, void)
1077 {
1078  maDeleteTransformation(mnIndex);
1079 }
1080 
1081 IMPL_LINK_NOARG(ScNumberTransformation, DeleteHdl, weld::Button&, void)
1082 {
1083  maDeleteTransformation(mnIndex);
1084 }
1085 
1086 IMPL_LINK_NOARG(ScAggregateFunction, DeleteHdl, weld::Button&, void)
1087 {
1088  maDeleteTransformation(mnIndex);
1089 }
1090 
1091 IMPL_LINK_NOARG(ScSortTransformationControl, DeleteHdl, weld::Button&, void)
1092 {
1093  maDeleteTransformation(mnIndex);
1094 }
1095 
1096 IMPL_LINK_NOARG(ScColumnTextTransformation, DeleteHdl, weld::Button&, void)
1097 {
1098  maDeleteTransformation(mnIndex);
1099 }
1100 
1101 IMPL_LINK_NOARG(ScReplaceNullTransformation, DeleteHdl, weld::Button&, void)
1102 {
1103  maDeleteTransformation(mnIndex);
1104 }
1105 
1106 IMPL_LINK_NOARG(ScDateTimeTransformation, DeleteHdl, weld::Button&, void)
1107 {
1108  maDeleteTransformation(mnIndex);
1109 }
1110 
1111 IMPL_LINK_NOARG(ScFindReplaceTransformation, DeleteHdl, weld::Button&, void)
1112 {
1113  maDeleteTransformation(mnIndex);
1114 }
1115 
1116 IMPL_LINK_NOARG(ScDeleteRowTransformation, DeleteHdl, weld::Button&, void)
1117 {
1118  maDeleteTransformation(mnIndex);
1119 }
1120 
1121 IMPL_LINK_NOARG(ScSwapRowsTransformation, DeleteHdl, weld::Button&, void)
1122 {
1123  maDeleteTransformation(mnIndex);
1124 }
1125 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static SCROW getLastRow(const ScDocument &rDoc)
::std::vector< ScSortKeyState > maKeyState
Definition: sortparam.hxx:121
DECL_LINK(CheckNameHdl, SvxNameDialog &, bool)
std::shared_ptr< ScDocument > mxDoc
URL aURL
SC_DLLPUBLIC ScDBCollection * GetDBCollection() const
Definition: document.hxx:825
std::unique_ptr< weld::Button > mxCancelBtn
static SCCOL getLastCol(const ScDocument &rDoc)
std::unique_ptr< weld::Button > mxOKBtn
static std::vector< OUString > getDataProviders()
std::vector< OUString > split(std::u16string_view rStr, sal_Unicode cSeparator)
void getColRange(SCCOL &rStartCol, SCCOL &rEndCol) const
std::unique_ptr< weld::Button > mxBrowseBtn
void Create(SwFormatVertOrient &rItem, SvStream &rStrm, sal_uInt16 nVersionAbusedAsSize)
void disposeAndClear()
sal_Int32 mnCol
std::unique_ptr< weld::Button > mxApplyBtn
RET_CANCEL
std::unique_ptr< weld::Container > mxBox
void AddDataTransformation(const std::shared_ptr< sc::DataTransformation > &mpDataTransformation)
constexpr tools::Long Width() const
sal_uInt16 sal_Unicode
std::unique_ptr< weld::Container > mxTransformationList
SC_DLLPUBLIC SCROW MaxRow() const
Definition: document.hxx:891
SC_DLLPUBLIC sc::ExternalDataMapper & GetExternalDataMapper()
ScDataTransformationBaseControl(weld::Container *pParent, const OUString &rUIFile, sal_uInt32 nIndex)
void updateApplyBtn(bool bValidConfig)
void setID(const OUString &rID)
void SetContext(Context _eNewContext)
std::unique_ptr< weld::ComboBox > mxTransformationBox
SC_DLLPUBLIC SCCOL MaxCol() const
Definition: document.hxx:890
css::uno::Reference< css::awt::XWindow > m_xTableParent
SC_DLLPUBLIC CellType GetCellType(SCCOL nCol, SCROW nRow, SCTAB nTab) const
Definition: document.cxx:3781
int i
std::unique_ptr< weld::Entry > mxEditID
void import(ScDocument &rDoc, bool bInternal=false)
void updateIndex(sal_uInt32 nIndex)
sal_Int16 SCCOL
Definition: types.hxx:21
OUString getDBName() const
void deletefromList(sal_uInt32 nIndex)
static SC_DLLPUBLIC const CharClass & getCharClass()
Definition: global.cxx:1024
virtual void Invalidate(InvalidateFlags nFlags=InvalidateFlags::NONE)
std::unique_ptr< weld::Builder > mxBuilder
void refresh(ScDocument *pDoc, bool bDeterministic=false)
const OUString & GetName() const
Definition: dbdata.hxx:121
virtual void move(weld::Widget *pWidget, weld::Container *pNewParent)=0
std::unique_ptr< weld::ComboBox > mxProviderList
sc::ExternalDataSource getDataSource(ScDocument *pDoc)
ScDBData * findByUpperName(const OUString &rName)
Definition: dbdata.cxx:1196
virtual ~ScDataProviderDlg() override
sal_Int32 SCROW
Definition: types.hxx:17
void insertDataSource(const ExternalDataSource &rSource)
std::unique_ptr< char[]> aBuffer
#define SAL_WARN_IF(condition, area, stream)
#define ERRCODE_NONE
constexpr tools::Long Height() const
RET_OK
Reference< XExecutableDialog > m_xDialog
virtual std::shared_ptr< sc::DataTransformation > getTransformation()=0
void SetInvokeHandler(const Link< Timer *, void > &rLink)
SC_DLLPUBLIC SCROW GetLastDataRow(SCTAB nTab, SCCOL nCol1, SCCOL nCol2, SCROW nLastRow) const
Return the last non-empty row position in given columns that's no greater than the initial last row p...
Definition: document.cxx:1080
ScDataProviderDlg(weld::Window *pWindow, std::shared_ptr< ScDocument > pDoc, const ScDocument *pDocument)
NamedDBs & getNamedDBs()
Definition: dbdata.hxx:316
IMPL_LINK_NOARG(ScDataProviderDlg, ScrollToEnd, Timer *, void)
virtual Size GetOptimalSize() const override
OUString msAddTransformationToolTip
void SetPriority(TaskPriority ePriority)
int mnIndex
std::unique_ptr< weld::ComboBox > mxDBRanges
std::unique_ptr< weld::Entry > mxEditURL
VclPtr< ScDataTableView > mxTable
void setDBData(const OUString &rDBName)
std::vector< std::unique_ptr< ScDataTransformationBaseControl > > maControls
std::unique_ptr< weld::Container > mxGrid
std::unique_ptr< weld::Button > mxAddTransformationBtn
sal_uInt16 nPos
void Show(bool bVisible=true, ShowFlags nFlags=ShowFlags::NONE)