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

Henry Castro (via logerrit) logerrit at kemper.freedesktop.org
Sat May 9 12:40:02 UTC 2020


 include/vcl/fmtfield.hxx        |    6 +++++
 include/vcl/uitest/uiobject.hxx |   18 +++++++++++++++
 vcl/source/control/fmtfield.cxx |   38 +++++++++++++++++++++++++++++++++
 vcl/source/uitest/uiobject.cxx  |   46 ++++++++++++++++++++++++++++++++++++++++
 4 files changed, 108 insertions(+)

New commits:
commit 3e325cfd1fa58b63ee2606de792b2560eaa43b24
Author:     Henry Castro <hcastro at collabora.com>
AuthorDate: Wed May 6 14:06:27 2020 -0400
Commit:     Henry Castro <hcastro at collabora.com>
CommitDate: Sat May 9 14:39:28 2020 +0200

    lok: add FormattedFieldUIObject class
    
    Required by mobile device to set "VALUE" number
    
    Change-Id: Ie18fa3c58b8ba107917a8b12a7b98c74a385975c
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/93777
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
    Reviewed-by: Henry Castro <hcastro at collabora.com>

diff --git a/include/vcl/fmtfield.hxx b/include/vcl/fmtfield.hxx
index de1a090036f7..b1801e3c0310 100644
--- a/include/vcl/fmtfield.hxx
+++ b/include/vcl/fmtfield.hxx
@@ -117,6 +117,8 @@ public:
 
     void    SetTextValue(const OUString& rText);
     // The String is transformed to a double (with a formatter) and SetValue is called afterwards
+    //
+    void    SetValueFromString(const OUString& rStr);
 
     bool    IsEmptyFieldEnabled() const         { return m_bEnableEmptyField; }
     void    EnableEmptyField(bool bEnable);
@@ -233,6 +235,10 @@ public:
     void    UseInputStringForFormatting();
     bool    IsUsingInputStringForFormatting() const { return m_bUseInputStringForFormatting;}
 
+    virtual boost::property_tree::ptree DumpAsPropertyTree() override;
+
+    virtual FactoryFunction GetUITestFactory() const override;
+
 protected:
     virtual bool EventNotify(NotifyEvent& rNEvt) override;
     void impl_Modify(bool makeValueDirty = true);
diff --git a/include/vcl/uitest/uiobject.hxx b/include/vcl/uitest/uiobject.hxx
index 5cc345a7fa7a..c7ab3d51af93 100644
--- a/include/vcl/uitest/uiobject.hxx
+++ b/include/vcl/uitest/uiobject.hxx
@@ -402,6 +402,24 @@ protected:
     virtual OUString get_name() const override;
 };
 
+class UITEST_DLLPUBLIC FormattedFieldUIObject : public SpinFieldUIObject
+{
+    VclPtr<FormattedField> mxFormattedField;
+
+public:
+    FormattedFieldUIObject(const VclPtr<FormattedField>& xEdit);
+    virtual ~FormattedFieldUIObject() override;
+
+    virtual void execute(const OUString& rAction, const StringMap& rParameters) override;
+
+    virtual StringMap get_state() override;
+
+    static std::unique_ptr<UIObject> create(vcl::Window* pWindow);
+
+protected:
+    virtual OUString get_name() const override;
+};
+
 class UITEST_DLLPUBLIC TabControlUIObject : public WindowUIObject
 {
 private:
diff --git a/vcl/source/control/fmtfield.cxx b/vcl/source/control/fmtfield.cxx
index 1f502e3102db..4014e0ebd1e5 100644
--- a/vcl/source/control/fmtfield.cxx
+++ b/vcl/source/control/fmtfield.cxx
@@ -18,6 +18,7 @@
  */
 
 #include <tools/debug.hxx>
+#include <boost/property_tree/json_parser.hpp>
 #include <comphelper/processfactory.hxx>
 #include <comphelper/string.hxx>
 #include <unotools/localedatawrapper.hxx>
@@ -27,6 +28,7 @@
 #include <vcl/commandevent.hxx>
 #include <svl/zformat.hxx>
 #include <vcl/fmtfield.hxx>
+#include <vcl/uitest/uiobject.hxx>
 #include <vcl/weld.hxx>
 #include <i18nlangtag/languagetag.hxx>
 #include <com/sun/star/lang/Locale.hpp>
@@ -836,6 +838,24 @@ void FormattedField::SetTextValue(const OUString& rText)
     ReFormat();
 }
 
+// currently used by online
+void FormattedField::SetValueFromString(const OUString& rStr)
+{
+    sal_Int32 nEnd;
+    rtl_math_ConversionStatus eStatus;
+    double fValue = ::rtl::math::stringToDouble(rStr, '.', GetDecimalDigits(), &eStatus, &nEnd );
+
+    if (eStatus == rtl_math_ConversionStatus_Ok &&
+        nEnd == rStr.getLength())
+    {
+        SetValue(fValue);
+    }
+    else
+    {
+        SAL_WARN("vcl", "fail to convert the value: " << rStr);
+    }
+}
+
 void FormattedField::EnableEmptyField(bool bEnable)
 {
     if (bEnable == m_bEnableEmptyField)
@@ -1061,6 +1081,24 @@ void FormattedField::UseInputStringForFormatting()
     m_bUseInputStringForFormatting = true;
 }
 
+boost::property_tree::ptree FormattedField::DumpAsPropertyTree()
+{
+    boost::property_tree::ptree aTree(SpinField::DumpAsPropertyTree());
+    aTree.put("min", rtl::math::doubleToString(GetMinValue(),
+        rtl_math_StringFormat_F, GetDecimalDigits(), '.').getStr());
+    aTree.put("max", rtl::math::doubleToString(GetMaxValue(),
+        rtl_math_StringFormat_F, GetDecimalDigits(), '.').getStr());
+    aTree.put("value", rtl::math::doubleToString(GetValue(),
+        rtl_math_StringFormat_F, GetDecimalDigits(), '.').getStr());
+
+    return aTree;
+}
+
+FactoryFunction FormattedField::GetUITestFactory() const
+{
+    return FormattedFieldUIObject::create;
+}
+
 DoubleNumericField::DoubleNumericField(vcl::Window* pParent, WinBits nStyle)
     : FormattedField(pParent, nStyle)
 {
diff --git a/vcl/source/uitest/uiobject.cxx b/vcl/source/uitest/uiobject.cxx
index c32a118017cb..efbf8e06dcf4 100644
--- a/vcl/source/uitest/uiobject.cxx
+++ b/vcl/source/uitest/uiobject.cxx
@@ -14,6 +14,7 @@
 #include <vcl/lstbox.hxx>
 #include <vcl/combobox.hxx>
 #include <vcl/spin.hxx>
+#include <vcl/fmtfield.hxx>
 #include <vcl/spinfld.hxx>
 #include <vcl/button.hxx>
 #include <vcl/dialog.hxx>
@@ -1251,6 +1252,51 @@ std::unique_ptr<UIObject> MetricFieldUIObject::create(vcl::Window* pWindow)
     return std::unique_ptr<UIObject>(new MetricFieldUIObject(pMetricField));
 }
 
+FormattedFieldUIObject::FormattedFieldUIObject(const VclPtr<FormattedField>& xFormattedField):
+    SpinFieldUIObject(xFormattedField),
+    mxFormattedField(xFormattedField)
+{
+}
+
+FormattedFieldUIObject::~FormattedFieldUIObject()
+{
+}
+
+void FormattedFieldUIObject::execute(const OUString& rAction,
+        const StringMap& rParameters)
+{
+    if (rAction == "VALUE")
+    {
+        auto itPos = rParameters.find("VALUE");
+        if (itPos != rParameters.end())
+        {
+            mxFormattedField->SetValueFromString(itPos->second);
+        }
+    }
+    else
+        SpinFieldUIObject::execute(rAction, rParameters);
+}
+
+StringMap FormattedFieldUIObject::get_state()
+{
+    StringMap aMap = EditUIObject::get_state();
+    aMap["Value"] = OUString::number(mxFormattedField->GetValue());
+
+    return aMap;
+}
+
+OUString FormattedFieldUIObject::get_name() const
+{
+    return "FormattedFieldUIObject";
+}
+
+std::unique_ptr<UIObject> FormattedFieldUIObject::create(vcl::Window* pWindow)
+{
+    FormattedField* pFormattedField = dynamic_cast<FormattedField*>(pWindow);
+    assert(pFormattedField);
+    return std::unique_ptr<UIObject>(new FormattedFieldUIObject(pFormattedField));
+}
+
 TabControlUIObject::TabControlUIObject(const VclPtr<TabControl>& xTabControl):
     WindowUIObject(xTabControl),
     mxTabControl(xTabControl)


More information about the Libreoffice-commits mailing list