[Libreoffice-commits] core.git: include/svl include/svx sc/source svl/source svx/source

Szymon Kłos (via logerrit) logerrit at kemper.freedesktop.org
Wed Nov 27 19:32:50 UTC 2019


 include/svl/poolitem.hxx          |    2 +
 include/svx/xflgrit.hxx           |    2 +
 include/svx/xgrad.hxx             |    5 +++
 sc/source/ui/drawfunc/drawsh2.cxx |   54 +++++++++-------------------------
 svl/source/items/poolitem.cxx     |    6 +++
 svx/source/xoutdev/xattr.cxx      |   60 ++++++++++++++++++++++++++++++++++++++
 6 files changed, 90 insertions(+), 39 deletions(-)

New commits:
commit dcb31718a238f115f703f1088ba5220e620dec1c
Author:     Szymon Kłos <szymon.klos at collabora.com>
AuthorDate: Thu Nov 21 17:47:10 2019 +0100
Commit:     Szymon Kłos <szymon.klos at collabora.com>
CommitDate: Wed Nov 27 20:31:07 2019 +0100

    jsdialogs: dumpAsJSON for SfxItems with FillGradient example
    
    Change-Id: I1b9303af6f52ad071074200bb630c587c8f611c1
    Reviewed-on: https://gerrit.libreoffice.org/83875
    Tested-by: Jenkins
    Reviewed-by: Szymon Kłos <szymon.klos at collabora.com>

diff --git a/include/svl/poolitem.hxx b/include/svl/poolitem.hxx
index cc1ddabd57a3..dd74806464cd 100644
--- a/include/svl/poolitem.hxx
+++ b/include/svl/poolitem.hxx
@@ -29,6 +29,7 @@
 #include <svl/svldllapi.h>
 #include <svl/typedwhich.hxx>
 #include <tools/mapunit.hxx>
+#include <boost/property_tree/json_parser.hpp>
 
 class IntlWrapper;
 
@@ -180,6 +181,7 @@ public:
     sal_uInt32               GetRefCount() const { return m_nRefCount; }
     SfxItemKind       GetKind() const { return m_nKind; }
     virtual void dumpAsXml(xmlTextWriterPtr pWriter) const;
+    virtual boost::property_tree::ptree dumpAsJSON() const;
 
     /** Only SfxVoidItem shall and must return true for this.
 
diff --git a/include/svx/xflgrit.hxx b/include/svx/xflgrit.hxx
index 5f136e25f824..1b1d860c8fb9 100644
--- a/include/svx/xflgrit.hxx
+++ b/include/svx/xflgrit.hxx
@@ -56,6 +56,8 @@ public:
 
     static bool CompareValueFunc( const NameOrIndex* p1, const NameOrIndex* p2 );
     std::unique_ptr<XFillGradientItem> checkForUniqueItem( SdrModel* pModel ) const;
+
+    virtual boost::property_tree::ptree dumpAsJSON() const override;
 };
 
 #endif
diff --git a/include/svx/xgrad.hxx b/include/svx/xgrad.hxx
index e31a4d2ef648..268b0e06253b 100644
--- a/include/svx/xgrad.hxx
+++ b/include/svx/xgrad.hxx
@@ -23,6 +23,7 @@
 #include <tools/color.hxx>
 #include <svx/svxdllapi.h>
 #include <com/sun/star/awt/GradientStyle.hpp>
+#include <boost/property_tree/json_parser.hpp>
 
 class Gradient;
 
@@ -39,6 +40,8 @@ class SAL_WARN_UNUSED SVX_DLLPUBLIC XGradient final
     sal_uInt16          nIntensEnd;
     sal_uInt16          nStepCount;
 
+    static std::string GradientStyleToString(css::awt::GradientStyle eStyle);
+
 public:
     XGradient();
     XGradient( const Color& rStart, const Color& rEnd,
@@ -70,6 +73,8 @@ public:
     sal_uInt16         GetStartIntens() const           { return nIntensStart; }
     sal_uInt16         GetEndIntens() const             { return nIntensEnd; }
     sal_uInt16         GetSteps() const                 { return nStepCount; }
+
+    boost::property_tree::ptree dumpAsJSON() const;
 };
 
 #endif
diff --git a/sc/source/ui/drawfunc/drawsh2.cxx b/sc/source/ui/drawfunc/drawsh2.cxx
index 118412c24822..e2ef0c75a173 100644
--- a/sc/source/ui/drawfunc/drawsh2.cxx
+++ b/sc/source/ui/drawfunc/drawsh2.cxx
@@ -48,6 +48,7 @@
 #include <svx/svdoole2.hxx>
 #include <svx/svdocapt.hxx>
 #include <svx/xfillit0.hxx>
+#include <svx/xflgrit.hxx>
 #include <comphelper/lok.hxx>
 #include <LibreOfficeKit/LibreOfficeKitEnums.h>
 
@@ -57,54 +58,29 @@ using namespace com::sun::star::drawing;
 using namespace com::sun::star;
 
 namespace {
-    OUString lcl_fillStyleEnumToString(FillStyle eStyle)
-    {
-        switch (eStyle)
-        {
-            case FillStyle_NONE:
-                return "NONE";
-
-            case FillStyle_SOLID:
-                return "SOLID";
-
-            case FillStyle_GRADIENT:
-                return "GRADIENT";
-
-            case FillStyle_HATCH:
-                return "HATCH";
-
-            case FillStyle_BITMAP:
-                return "BITMAP";
-
-            default:
-                return "";
-        }
-    }
-
     void lcl_sendAttrUpdatesForLOK(SfxViewShell* pShell, const SfxItemSet& rSet)
     {
         if (!pShell)
             return;
 
-        OUString sPayload;
-        const SfxPoolItem* pItem = rSet.GetItem(SID_ATTR_FILL_STYLE);
+        boost::property_tree::ptree aTree;
+        boost::property_tree::ptree anArray;
 
-        if (pItem)
+        for(int i = 0; i < rSet.Count(); i++)
         {
-            const XFillStyleItem* pFillStyleItem = static_cast<const XFillStyleItem*>(pItem);
-            FillStyle eStyle;
-            css::uno::Any aAny;
-
-            pFillStyleItem->QueryValue(aAny);
-            aAny >>= eStyle;
-            sPayload = ".uno:FillStyle=" + lcl_fillStyleEnumToString(eStyle);
+            sal_uInt16 nWhich = rSet.GetWhichByPos(i);
+            if (rSet.HasItem(nWhich) && SfxItemState::SET >= rSet.GetItemState(nWhich))
+            {
+                boost::property_tree::ptree aItem = rSet.Get(nWhich).dumpAsJSON();
+                if (!aItem.empty())
+                    anArray.push_back(std::make_pair("", aItem));
+            }
         }
+        aTree.add_child("items", anArray);
 
-        if (!sPayload.isEmpty())
-        {
-            pShell->libreOfficeKitViewCallback(LOK_CALLBACK_STATE_CHANGED,
-                OUStringToOString(sPayload, RTL_TEXTENCODING_ASCII_US).getStr());
-        }
+        std::stringstream aStream;
+        boost::property_tree::write_json(aStream, aTree);
+        pShell->libreOfficeKitViewCallback(LOK_CALLBACK_STATE_CHANGED, aStream.str().c_str());
     }
 }
 
diff --git a/svl/source/items/poolitem.cxx b/svl/source/items/poolitem.cxx
index ec37b68d3417..daa676a9e458 100644
--- a/svl/source/items/poolitem.cxx
+++ b/svl/source/items/poolitem.cxx
@@ -552,6 +552,12 @@ void SfxPoolItem::dumpAsXml(xmlTextWriterPtr pWriter) const
     xmlTextWriterEndElement(pWriter);
 }
 
+boost::property_tree::ptree SfxPoolItem::dumpAsJSON() const
+{
+    boost::property_tree::ptree aTree;
+    return aTree;
+}
+
 std::unique_ptr<SfxPoolItem> SfxPoolItem::CloneSetWhich( sal_uInt16 nNewWhich ) const
 {
     std::unique_ptr<SfxPoolItem> pItem(Clone());
diff --git a/svx/source/xoutdev/xattr.cxx b/svx/source/xoutdev/xattr.cxx
index af477725dc23..e443ce84cd26 100644
--- a/svx/source/xoutdev/xattr.cxx
+++ b/svx/source/xoutdev/xattr.cxx
@@ -88,6 +88,8 @@
 #include <unotools/intlwrapper.hxx>
 #include <unotools/syslocale.hxx>
 #include <vcl/gradient.hxx>
+#include <svx/svxids.hrc>
+#include <string>
 
 #include <libxml/xmlwriter.h>
 
@@ -1909,6 +1911,35 @@ bool XSecondaryFillColorItem::GetPresentation
     return true;
 }
 
+std::string XGradient::GradientStyleToString(css::awt::GradientStyle eStyle)
+{
+    switch (eStyle)
+    {
+        case css::awt::GradientStyle::GradientStyle_LINEAR:
+            return "Linear";
+
+        case css::awt::GradientStyle::GradientStyle_AXIAL:
+            return "Axial";
+
+        case css::awt::GradientStyle::GradientStyle_RADIAL:
+            return "Radial";
+
+        case css::awt::GradientStyle::GradientStyle_ELLIPTICAL:
+            return "Elliptical";
+
+        case css::awt::GradientStyle::GradientStyle_SQUARE:
+            return "Square";
+
+        case css::awt::GradientStyle::GradientStyle_RECT:
+            return "Rect";
+
+        case css::awt::GradientStyle::GradientStyle_MAKE_FIXED_SIZE:
+            return "FixedSize";
+    }
+
+    return "";
+}
+
 XGradient::XGradient() :
     eStyle( css::awt::GradientStyle_LINEAR ),
     aStartColor( COL_BLACK ),
@@ -1955,6 +1986,23 @@ bool XGradient::operator==(const XGradient& rGradient) const
              nStepCount     == rGradient.nStepCount );
 }
 
+boost::property_tree::ptree XGradient::dumpAsJSON() const
+{
+    boost::property_tree::ptree aTree;
+
+    aTree.put("style", XGradient::GradientStyleToString(eStyle));
+    aTree.put("startcolor",aStartColor.AsRGBHexString());
+    aTree.put("endcolor", aEndColor.AsRGBHexString());
+    aTree.put("angle", std::to_string(nAngle));
+    aTree.put("border", std::to_string(nBorder));
+    aTree.put("x", std::to_string(nOfsX));
+    aTree.put("y", std::to_string(nOfsY));
+    aTree.put("intensstart", std::to_string(nIntensStart));
+    aTree.put("intensend", std::to_string(nIntensEnd));
+    aTree.put("stepcount", std::to_string(nStepCount));
+
+    return aTree;
+}
 
 SfxPoolItem* XFillGradientItem::CreateDefault() { return new XFillGradientItem; }
 
@@ -2255,6 +2303,18 @@ std::unique_ptr<XFillGradientItem> XFillGradientItem::checkForUniqueItem( SdrMod
     return nullptr;
 }
 
+boost::property_tree::ptree XFillGradientItem::dumpAsJSON() const
+{
+    boost::property_tree::ptree aTree = SfxPoolItem::dumpAsJSON();
+
+    if (Which() == XATTR_FILLGRADIENT)
+        aTree.put("which", ".uno:FillGradient");
+
+    aTree.push_back(std::make_pair("data", GetGradientValue().dumpAsJSON()));
+
+    return aTree;
+}
+
 
 SfxPoolItem* XFillFloatTransparenceItem::CreateDefault() { return new XFillFloatTransparenceItem; }
 


More information about the Libreoffice-commits mailing list