[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.2' - include/svl include/svx sc/source svl/source svx/source

Szymon Kłos (via logerrit) logerrit at kemper.freedesktop.org
Wed Nov 27 16:03:22 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 66ecf17744754d239a56113a1384f1ac36653f80
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 17:02:08 2019 +0100

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

diff --git a/include/svl/poolitem.hxx b/include/svl/poolitem.hxx
index d812f865411e..5cf9a83bfcc4 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;
 class SvStream;
@@ -178,6 +179,7 @@ public:
     sal_uInt32               GetRefCount() const { return m_nRefCount; }
     SfxItemKind       GetKind() const { return m_nKind; }
     virtual void dumpAsXml(struct _xmlTextWriter* 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 70abe25edb3b..0968d2dda1c1 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 );
     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 554746d8139a..ec8941292103 100644
--- a/include/svx/xgrad.hxx
+++ b/include/svx/xgrad.hxx
@@ -24,6 +24,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;
 
@@ -40,6 +41,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,
@@ -71,6 +74,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 9e382d19aafc..aa1c0bfd93a2 100644
--- a/sc/source/ui/drawfunc/drawsh2.cxx
+++ b/sc/source/ui/drawfunc/drawsh2.cxx
@@ -50,6 +50,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>
 
@@ -59,54 +60,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 346e38324bce..6be08d5220aa 100644
--- a/svl/source/items/poolitem.cxx
+++ b/svl/source/items/poolitem.cxx
@@ -127,6 +127,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 fcb1b78e8bb7..37708b2cdf5c 100644
--- a/svx/source/xoutdev/xattr.cxx
+++ b/svx/source/xoutdev/xattr.cxx
@@ -61,6 +61,8 @@
 #include <basegfx/polygon/b2dpolypolygontools.hxx>
 #include <unotools/intlwrapper.hxx>
 #include <vcl/gradient.hxx>
+#include <svx/svxids.hrc>
+#include <string>
 
 #include <libxml/xmlwriter.h>
 
@@ -1915,6 +1917,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 ),
@@ -1961,6 +1992,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; }
 
@@ -2269,6 +2317,18 @@ XFillGradientItem* XFillGradientItem::checkForUniqueItem( SdrModel* pModel ) con
     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