[Libreoffice-commits] core.git: 2 commits - sc/source sc/uiconfig sc/UIConfig_scalc.mk

Manuj Vashist manujvashist at gmail.com
Wed Jul 11 22:34:27 UTC 2018


 sc/UIConfig_scalc.mk                             |    2 
 sc/source/ui/dataprovider/datatransformation.cxx |    2 
 sc/source/ui/inc/dataproviderdlg.hxx             |    2 
 sc/source/ui/miscdlgs/dataproviderdlg.cxx        |  141 ++++++++++++++++++++++-
 sc/uiconfig/scalc/ui/aggregatefunctionentry.ui   |  109 +++++++++++++++++
 sc/uiconfig/scalc/ui/sorttransformationentry.ui  |   85 +++++++++++++
 6 files changed, 339 insertions(+), 2 deletions(-)

New commits:
commit 8666f3670c8e32228cdaf59ee9b879a796bbb308
Author: Manuj Vashist <manujvashist at gmail.com>
Date:   Sun Jul 8 05:11:59 2018 +0530

    Added Aggregate functions to data provider dlg
    
    Change-Id: Ic6de5319f936095fa1d165fc5901f13d0e7776f5
    Reviewed-on: https://gerrit.libreoffice.org/57027
    Tested-by: Jenkins
    Reviewed-by: Markus Mohrhard <markus.mohrhard at googlemail.com>

diff --git a/sc/UIConfig_scalc.mk b/sc/UIConfig_scalc.mk
index 424d630d08de..3b79d5d6b225 100644
--- a/sc/UIConfig_scalc.mk
+++ b/sc/UIConfig_scalc.mk
@@ -158,6 +158,7 @@ $(eval $(call gb_UIConfig_add_uifiles,modules/scalc,\
 	sc/uiconfig/scalc/ui/mergecolumnentry \
 	sc/uiconfig/scalc/ui/texttransformationentry \
 	sc/uiconfig/scalc/ui/sorttransformationentry \
+	sc/uiconfig/scalc/ui/aggregatefunctionentry \
 	sc/uiconfig/scalc/ui/movecopysheet \
 	sc/uiconfig/scalc/ui/movingaveragedialog \
 	sc/uiconfig/scalc/ui/multipleoperationsdialog \
diff --git a/sc/source/ui/dataprovider/datatransformation.cxx b/sc/source/ui/dataprovider/datatransformation.cxx
index c1bfac0895ef..aa14563985dd 100644
--- a/sc/source/ui/dataprovider/datatransformation.cxx
+++ b/sc/source/ui/dataprovider/datatransformation.cxx
@@ -8,7 +8,7 @@
  */
 
 #include <datatransformation.hxx>
-
+#include <limits>
 #include <document.hxx>
 #include <limits>
 #include <rtl/math.hxx>
diff --git a/sc/source/ui/inc/dataproviderdlg.hxx b/sc/source/ui/inc/dataproviderdlg.hxx
index b39254ddf70a..d41d9a141604 100644
--- a/sc/source/ui/inc/dataproviderdlg.hxx
+++ b/sc/source/ui/inc/dataproviderdlg.hxx
@@ -63,6 +63,7 @@ public:
     void mergeColumns();
     void textTransformation();
     void sortTransformation();
+    void aggregateFunction();
 
     void import(ScDocument* pDoc, bool bInternal = false);
 };
diff --git a/sc/source/ui/miscdlgs/dataproviderdlg.cxx b/sc/source/ui/miscdlgs/dataproviderdlg.cxx
index e07f789b1269..e30b3505d3bd 100644
--- a/sc/source/ui/miscdlgs/dataproviderdlg.cxx
+++ b/sc/source/ui/miscdlgs/dataproviderdlg.cxx
@@ -223,7 +223,8 @@ MenuData aColumnData[] = {
     { 1, "Split Column", &ScDataProviderDlg::splitColumn },
     { 2, "Merge Columns", &ScDataProviderDlg::mergeColumns },
     { 3, "Text Transformation", &ScDataProviderDlg::textTransformation },
-    { 4, "Sort Columns", &ScDataProviderDlg::sortTransformation }
+    { 4, "Sort Columns", &ScDataProviderDlg::sortTransformation },
+    { 5, "Aggregate Functions", &ScDataProviderDlg::aggregateFunction}
 };
 
 class ScDataTransformationBaseControl : public VclContainer,
@@ -563,6 +564,77 @@ std::shared_ptr<sc::DataTransformation> ScColumnTextTransformation::getTransform
     return nullptr;
 }
 
+class ScAggregateFunction : public ScDataTransformationBaseControl
+{
+private:
+    VclPtr<Edit> maColumnNums;
+    VclPtr<ListBox> maType;
+
+public:
+
+    ScAggregateFunction(vcl::Window* pParent);
+    ~ScAggregateFunction() override;
+
+    virtual void dispose() override;
+
+    virtual std::shared_ptr<sc::DataTransformation> getTransformation() override;
+
+};
+
+ScAggregateFunction::ScAggregateFunction(vcl::Window* pParent):
+    ScDataTransformationBaseControl(pParent,"modules/scalc/ui/aggregatefunctionentry.ui")
+{
+    get(maColumnNums, "ed_columns");
+    get(maType, "ed_lst");
+}
+
+ScAggregateFunction::~ScAggregateFunction()
+{
+    disposeOnce();
+}
+
+void ScAggregateFunction::dispose()
+{
+    maColumnNums.clear();
+    maType.clear();
+    ScDataTransformationBaseControl::dispose();
+}
+
+std::shared_ptr<sc::DataTransformation> ScAggregateFunction::getTransformation()
+{
+    OUString aColumnString = maColumnNums->GetText();
+    sal_Int32 nPos = maType->GetSelectedEntryPos();
+    std::vector<OUString> aSplitColumns = comphelper::string::split(aColumnString, ';');
+    std::set<SCCOL> aColumns;
+    for (auto& rColStr : aSplitColumns)
+    {
+        sal_Int32 nCol = rColStr.toInt32();
+        if (nCol <= 0)
+            continue;
+
+        if (nCol > MAXCOL)
+            continue;
+
+        // translate from 1-based column notations to internal Calc one
+        aColumns.insert(nCol - 1);
+    }
+    switch (nPos)
+    {
+        case 0:
+            return std::make_shared<sc::AggregateFunction>(aColumns,sc::AGGREGATE_FUNCTION::SUM);
+        case 1:
+            return std::make_shared<sc::AggregateFunction>(aColumns,sc::AGGREGATE_FUNCTION::AVERAGE);
+        case 2:
+            return std::make_shared<sc::AggregateFunction>(aColumns,sc::AGGREGATE_FUNCTION::MIN);
+        case 3:
+            return std::make_shared<sc::AggregateFunction>(aColumns,sc::AGGREGATE_FUNCTION::MAX);
+        default:
+            assert(false);
+    }
+
+    return nullptr;
+}
+    
 }
 
 ScDataProviderDlg::ScDataProviderDlg(vcl::Window* pParent, std::shared_ptr<ScDocument> pDoc, ScDocument* pDocument):
@@ -721,6 +793,12 @@ void ScDataProviderDlg::sortTransformation()
     mpList->addEntry(pSortTransforamtionEntry);
 }
 
+void ScDataProviderDlg::aggregateFunction()
+{
+    VclPtr<ScAggregateFunction> pAggregateFuntionEntry = VclPtr<ScAggregateFunction>::Create(mpList);
+    mpList->addEntry(pAggregateFuntionEntry);
+}
+
 void ScDataProviderDlg::import(ScDocument* pDoc, bool bInternal)
 {
     sc::ExternalDataSource aSource = mpDataProviderCtrl->getDataSource(pDoc);
diff --git a/sc/uiconfig/scalc/ui/aggregatefunctionentry.ui b/sc/uiconfig/scalc/ui/aggregatefunctionentry.ui
new file mode 100644
index 000000000000..345ff6ea8054
--- /dev/null
+++ b/sc/uiconfig/scalc/ui/aggregatefunctionentry.ui
@@ -0,0 +1,109 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.20.2 -->
+<interface domain="sc">
+  <requires lib="gtk+" version="3.18"/>
+  <object class="GtkGrid" id="grid">
+    <property name="visible">True</property>
+    <property name="can_focus">False</property>
+    <property name="hexpand">True</property>
+    <property name="border_width">6</property>
+    <property name="row_spacing">6</property>
+    <property name="column_spacing">12</property>
+    <child>
+      <object class="GtkBox">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="orientation">vertical</property>
+        <child>
+          <object class="GtkLabel">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="label" translatable="yes" context="aggregatefunctionentry|name">Aggregate Functions</property>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkGrid" id="grid_details">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <child>
+              <object class="GtkLabel" id="label1">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="label" translatable="yes" context="aggregatefunctionentry|type">Type:</property>
+                <accessibility>
+                  <relation type="label-for" target="ed_lst"/>
+                </accessibility>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkLabel" id="label2">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="label" translatable="yes" context="aggregatefunctionentry|columns">Columns:</property>
+                <accessibility>
+                  <relation type="label-for" target="ed_columns"/>
+                </accessibility>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkComboBoxText" id="ed_lst">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="active">0</property>
+                <property name="active_id">0</property>
+                <items>
+                  <item id="0" translatable="yes" context="aggregatefunctionentry|sum">Sum</item>
+                  <item id="1" translatable="yes" context="aggregatefunctionentry|average">Average</item>
+                  <item id="2" translatable="yes" context="aggregatefunctionentry|min">Minimum Value</item>
+                  <item id="3" translatable="yes" context="aggregatefunctionentry|max">Maximum Value</item>
+                </items>
+                <accessibility>
+                  <relation type="labelled-by" target="label1"/>
+                </accessibility>
+              </object>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="top_attach">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkEntry" id="ed_columns">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <accessibility>
+                  <relation type="labelled-by" target="label2"/>
+                </accessibility>
+              </object>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="top_attach">1</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+      </object>
+      <packing>
+        <property name="left_attach">0</property>
+        <property name="top_attach">0</property>
+      </packing>
+    </child>
+  </object>
+</interface>
commit 537ca51ddb2ad2052cb0ca33fd8656d42ad46733
Author: Manuj Vashist <manujvashist at gmail.com>
Date:   Wed Jul 4 03:18:59 2018 +0530

    Added Sort Transformation in Data Provider dlg
    
    Change-Id: I68ea3d2fc40163d0f3a67bb3723341f8e382db27
    Reviewed-on: https://gerrit.libreoffice.org/56914
    Tested-by: Jenkins
    Reviewed-by: Markus Mohrhard <markus.mohrhard at googlemail.com>

diff --git a/sc/UIConfig_scalc.mk b/sc/UIConfig_scalc.mk
index 498540b645fb..424d630d08de 100644
--- a/sc/UIConfig_scalc.mk
+++ b/sc/UIConfig_scalc.mk
@@ -157,6 +157,7 @@ $(eval $(call gb_UIConfig_add_uifiles,modules/scalc,\
 	sc/uiconfig/scalc/ui/mergecellsdialog \
 	sc/uiconfig/scalc/ui/mergecolumnentry \
 	sc/uiconfig/scalc/ui/texttransformationentry \
+	sc/uiconfig/scalc/ui/sorttransformationentry \
 	sc/uiconfig/scalc/ui/movecopysheet \
 	sc/uiconfig/scalc/ui/movingaveragedialog \
 	sc/uiconfig/scalc/ui/multipleoperationsdialog \
diff --git a/sc/source/ui/inc/dataproviderdlg.hxx b/sc/source/ui/inc/dataproviderdlg.hxx
index cd3f681754f0..b39254ddf70a 100644
--- a/sc/source/ui/inc/dataproviderdlg.hxx
+++ b/sc/source/ui/inc/dataproviderdlg.hxx
@@ -62,6 +62,7 @@ public:
     void splitColumn();
     void mergeColumns();
     void textTransformation();
+    void sortTransformation();
 
     void import(ScDocument* pDoc, bool bInternal = false);
 };
diff --git a/sc/source/ui/miscdlgs/dataproviderdlg.cxx b/sc/source/ui/miscdlgs/dataproviderdlg.cxx
index c2ce2f6d4e4f..e07f789b1269 100644
--- a/sc/source/ui/miscdlgs/dataproviderdlg.cxx
+++ b/sc/source/ui/miscdlgs/dataproviderdlg.cxx
@@ -222,7 +222,8 @@ MenuData aColumnData[] = {
     { 0, "Delete Column", &ScDataProviderDlg::deleteColumn },
     { 1, "Split Column", &ScDataProviderDlg::splitColumn },
     { 2, "Merge Columns", &ScDataProviderDlg::mergeColumns },
-    { 3, "Text Transformation", &ScDataProviderDlg::textTransformation }
+    { 3, "Text Transformation", &ScDataProviderDlg::textTransformation },
+    { 4, "Sort Columns", &ScDataProviderDlg::sortTransformation }
 };
 
 class ScDataTransformationBaseControl : public VclContainer,
@@ -436,6 +437,60 @@ std::shared_ptr<sc::DataTransformation> ScMergeColumnTransformationControl::getT
     return std::make_shared<sc::MergeColumnTransformation>(aMergedColumns, mpSeparator->GetText());
 }
 
+class ScSortTransformationControl : public ScDataTransformationBaseControl
+{
+private:
+
+    VclPtr<CheckBox> mpAscending;
+    VclPtr<Edit> mpEdColumns;
+
+public:
+    ScSortTransformationControl(vcl::Window* pParent);
+    ~ScSortTransformationControl() override;
+
+    virtual void dispose() override;
+
+    virtual std::shared_ptr<sc::DataTransformation> getTransformation() override;
+};
+
+ScSortTransformationControl::ScSortTransformationControl(vcl::Window* pParent):
+    ScDataTransformationBaseControl(pParent, "modules/scalc/ui/sorttransformationentry.ui")
+{
+    get(mpAscending, "ed_ascending");
+    get(mpEdColumns, "ed_columns");
+}
+
+ScSortTransformationControl::~ScSortTransformationControl()
+{
+    disposeOnce();
+}
+
+void ScSortTransformationControl::dispose()
+{
+    mpAscending.clear();
+    mpEdColumns.clear();
+
+    ScDataTransformationBaseControl::dispose();
+}
+
+std::shared_ptr<sc::DataTransformation> ScSortTransformationControl::getTransformation()
+{
+    OUString aColStr = mpEdColumns->GetText();
+    bool aIsAscending = mpAscending->IsChecked();
+    SCCOL aColumn = 0;
+    sal_Int32 nCol = aColStr.toInt32();
+    if (nCol > 0 && nCol <= MAXCOL)
+        aColumn = nCol - 1;     // translate from 1-based column notations to internal Calc one
+
+    ScSortParam aSortParam;
+    ScSortKeyState aSortKey;
+    aSortKey.bDoSort = true;
+    aSortKey.nField = aColumn;
+    aSortKey.bAscending = aIsAscending;
+    aSortParam.maKeyState.push_back(aSortKey);
+    return std::make_shared<sc::SortTransformation>(aSortParam);
+}
+
 class ScColumnTextTransformation : public ScDataTransformationBaseControl
 {
 private:
@@ -660,6 +715,12 @@ void ScDataProviderDlg::textTransformation()
     mpList->addEntry(pTextTransforamtionEntry);
 }
 
+void ScDataProviderDlg::sortTransformation()
+{
+    VclPtr<ScSortTransformationControl> pSortTransforamtionEntry = VclPtr<ScSortTransformationControl>::Create(mpList);
+    mpList->addEntry(pSortTransforamtionEntry);
+}
+
 void ScDataProviderDlg::import(ScDocument* pDoc, bool bInternal)
 {
     sc::ExternalDataSource aSource = mpDataProviderCtrl->getDataSource(pDoc);
diff --git a/sc/uiconfig/scalc/ui/sorttransformationentry.ui b/sc/uiconfig/scalc/ui/sorttransformationentry.ui
new file mode 100644
index 000000000000..070c0b478a7c
--- /dev/null
+++ b/sc/uiconfig/scalc/ui/sorttransformationentry.ui
@@ -0,0 +1,85 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.20.2 -->
+<interface domain="sc">
+  <requires lib="gtk+" version="3.18"/>
+  <object class="GtkGrid" id="grid">
+    <property name="visible">True</property>
+    <property name="can_focus">False</property>
+    <property name="hexpand">True</property>
+    <property name="border_width">6</property>
+    <property name="row_spacing">6</property>
+    <property name="column_spacing">12</property>
+    <child>
+      <object class="GtkBox">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="orientation">vertical</property>
+        <child>
+          <object class="GtkLabel">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="label" translatable="yes" context="sorttransformationentry|name">Sort Transformation</property>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkGrid" id="grid_details">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <child>
+              <object class="GtkCheckButton" id="ed_ascending">
+                <property name="visible">True</property>
+                <property name="label" translatable="yes" context="sorttransformationentry|type">Ascending Order</property>
+                <property name="can_focus">True</property>
+              </object>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="top_attach">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkLabel" id="label1">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="label" translatable="yes" context="sorttransformationentry|column">Column:</property>
+                <accessibility>
+                  <relation type="label-for" target="ed_columns"/>
+                </accessibility>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkEntry" id="ed_columns">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <accessibility>
+                  <relation type="labelled-by" target="label1"/>
+                </accessibility>
+              </object>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="top_attach">1</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+      </object>
+      <packing>
+        <property name="left_attach">0</property>
+        <property name="top_attach">0</property>
+      </packing>
+    </child>
+  </object>
+</interface>


More information about the Libreoffice-commits mailing list