cui/source/dialogs/QrCodeGenDialog.cxx |  134 ++++++++++++++-------------------
 cui/source/inc/QrCodeGenDialog.hxx     |   18 ----
 cui/uiconfig/ui/qrcodegen.ui           |   22 ++++-
 3 files changed, 81 insertions(+), 93 deletions(-)

New commits:
commit a0ef5c62ce8b5cac634aaf785f67a514ec334aa5
Author:     Shubham Goyal <22shub...@gmail.com>
AuthorDate: Sun Aug 4 23:23:43 2019 +0530
Commit:     Samuel Mehrbrodt <samuel.mehrbr...@cib.de>
CommitDate: Thu Aug 8 09:10:34 2019 +0200

    FIX: Error Correction in QR Code
    
    Previously only Low Error Correction value was used to build the QR
    Code. This patch aims to fix this and make use of Error Correction what
    user selects.
    
    Is fix to the commit 2de42b53b7c23223c38e64a75eae248d8a0cd4ec
    
    Patch also involves some beautification.
    
    Change-Id: Ib809569fdd7c1c7c6305c27552419c3e5e8d51b9
    Reviewed-on: https://gerrit.libreoffice.org/76958
    Tested-by: Jenkins
    Reviewed-by: Samuel Mehrbrodt <samuel.mehrbr...@cib.de>

diff --git a/cui/source/dialogs/QrCodeGenDialog.cxx 
b/cui/source/dialogs/QrCodeGenDialog.cxx
index 539a5fbb3c28..c0e9f565556e 100644
--- a/cui/source/dialogs/QrCodeGenDialog.cxx
+++ b/cui/source/dialogs/QrCodeGenDialog.cxx
@@ -14,6 +14,7 @@
 #include <unotools/streamwrap.hxx>
 #include <utility>
 #include <vcl/weld.hxx>
+#include <sal/log.hxx>
 
 #if defined(SYSTEM_QRCODEGEN)
 #include <qrcodegen/QrCode.hpp>
@@ -61,23 +62,14 @@ QrCodeGenDialog::QrCodeGenDialog(weld::Widget* pParent, 
Reference<XModel> xModel
     : GenericDialogController(pParent, "cui/ui/qrcodegen.ui", 
"QrCodeGenDialog")
     , m_xModel(std::move(xModel))
     , m_xEdittext(m_xBuilder->weld_entry("edit_text"))
-    , m_xRadioLow(m_xBuilder->weld_radio_button("button_low"))
-    , m_xRadioMedium(m_xBuilder->weld_radio_button("button_medium"))
-    , m_xRadioQuartile(m_xBuilder->weld_radio_button("button_quartile"))
-    , m_xRadioHigh(m_xBuilder->weld_radio_button("button_high"))
+    , m_xECC{ m_xBuilder->weld_radio_button("button_low"),
+              m_xBuilder->weld_radio_button("button_medium"),
+              m_xBuilder->weld_radio_button("button_quartile"),
+              m_xBuilder->weld_radio_button("button_high") }
     , m_xSpinBorder(m_xBuilder->weld_spin_button("edit_border"))
 {
-    maBox.AddButton(m_xRadioLow.get());
-    maBox.AddButton(m_xRadioMedium.get());
-    maBox.AddButton(m_xRadioQuartile.get());
-    maBox.AddButton(m_xRadioHigh.get());
-
-    // Set ECC to Low by Default.
     if (!bEditExisting)
     {
-        // ECC::Low     0
-        m_aECCSelect = css::drawing::QRCodeErrorCorrection::LOW;
-        m_xRadioLow->set_active(true);
         return;
     }
 
@@ -85,20 +77,16 @@ QrCodeGenDialog::QrCodeGenDialog(weld::Widget* pParent, 
Reference<XModel> xModel
                                                     UNO_QUERY_THROW);
     Reference<XPropertySet> xProps(xIndexAccess->getByIndex(0), 
UNO_QUERY_THROW);
 
-    // Read properties from selected qr code
-    css::drawing::QRCode aQrCode;
-    xProps->getPropertyValue("QRCodeProperties") >>= aQrCode;
+    // Read properties from selected QR Code
+    css::drawing::QRCode aQRCode;
+    xProps->getPropertyValue("QRCodeProperties") >>= aQRCode;
 
-    m_xEdittext->set_text(aQrCode.Payload);
-    GetErrorCorrection(aQrCode.ErrorCorrection);
+    m_xEdittext->set_text(aQRCode.Payload);
 
-    Link<weld::ToggleButton&, void> aLink = LINK(this, QrCodeGenDialog, 
SelectRadio_Impl);
-    m_xRadioLow->connect_toggled(aLink);
-    m_xRadioMedium->connect_toggled(aLink);
-    m_xRadioQuartile->connect_toggled(aLink);
-    m_xRadioHigh->connect_toggled(aLink);
+    //Get Error Correction Constant from selected QR Code
+    GetErrorCorrection(aQRCode.ErrorCorrection);
 
-    m_xSpinBorder->set_value(aQrCode.Border);
+    m_xSpinBorder->set_value(aQRCode.Border);
 
     // Mark this as existing shape
     m_xExistingShapeProperties = xProps;
@@ -114,13 +102,34 @@ short QrCodeGenDialog::run()
 
 void QrCodeGenDialog::Apply()
 {
-    css::drawing::QRCode aQrCode;
-    aQrCode.Payload = m_xEdittext->get_text();
-    aQrCode.ErrorCorrection = m_aECCSelect;
-    aQrCode.Border = m_xSpinBorder->get_value();
+    css::drawing::QRCode aQRCode;
+    aQRCode.Payload = m_xEdittext->get_text();
+
+    bool bLowECCActive(m_xECC[0]->get_active());
+    bool bMediumECCActive(m_xECC[1]->get_active());
+    bool bQuartileECCActive(m_xECC[2]->get_active());
+
+    if (bLowECCActive)
+    {
+        aQRCode.ErrorCorrection = css::drawing::QRCodeErrorCorrection::LOW;
+    }
+    else if (bMediumECCActive)
+    {
+        aQRCode.ErrorCorrection = css::drawing::QRCodeErrorCorrection::MEDIUM;
+    }
+    else if (bQuartileECCActive)
+    {
+        aQRCode.ErrorCorrection = 
css::drawing::QRCodeErrorCorrection::QUARTILE;
+    }
+    else
+    {
+        aQRCode.ErrorCorrection = css::drawing::QRCodeErrorCorrection::HIGH;
+    }
+
+    aQRCode.Border = m_xSpinBorder->get_value();
 
     // Read svg and replace placeholder texts
-    OUString aSvgImage = GenerateQrCode(aQrCode.Payload, 
aQrCode.ErrorCorrection, aQrCode.Border);
+    OUString aSvgImage = GenerateQRCode(aQRCode.Payload, 
aQRCode.ErrorCorrection, aQRCode.Border);
 
     // Insert/Update graphic
     SvMemoryStream aSvgStream(4096, 4096);
@@ -134,9 +143,9 @@ void QrCodeGenDialog::Apply()
     aMediaProperties[0].Value <<= xInputStream;
     Reference<XGraphic> xGraphic(xProvider->queryGraphic(aMediaProperties));
 
-    bool bIsExistingQrCode = m_xExistingShapeProperties.is();
+    bool bIsExistingQRCode = m_xExistingShapeProperties.is();
     Reference<XPropertySet> xShapeProps;
-    if (bIsExistingQrCode)
+    if (bIsExistingQRCode)
         xShapeProps = m_xExistingShapeProperties;
     else
         xShapeProps.set(Reference<lang::XMultiServiceFactory>(m_xModel, 
UNO_QUERY_THROW)
@@ -145,10 +154,10 @@ void QrCodeGenDialog::Apply()
 
     xShapeProps->setPropertyValue("Graphic", Any(xGraphic));
 
-    // Set qrcode properties
-    xShapeProps->setPropertyValue("QRCodeProperties", Any(aQrCode));
+    // Set QRCode properties
+    xShapeProps->setPropertyValue("QRCodeProperties", Any(aQRCode));
 
-    if (!bIsExistingQrCode)
+    if (!bIsExistingQRCode)
     {
         // Default size
         Reference<XShape> xShape(xShapeProps, UNO_QUERY);
@@ -198,26 +207,7 @@ void QrCodeGenDialog::Apply()
     }
 }
 
-IMPL_LINK(QrCodeGenDialog, SelectRadio_Impl, weld::ToggleButton&, rButton, 
void)
-{
-    // If the button is already active do not toggle it back.
-    if (!rButton.get_active())
-        rButton.set_active(true);
-
-    SelectErrorCorrection(rButton);
-}
-
-void QrCodeGenDialog::SelectErrorCorrection(weld::ToggleButton& rButton)
-{
-    sal_Int32 nPos = maBox.GetButtonPos(&rButton);
-    if (nPos != -1 && nPos != maBox.GetCurrentButtonPos())
-    {
-        maBox.SelectButton(&rButton);
-        m_aECCSelect = static_cast<int>(maBox.GetCurrentButtonPos()) + 1;
-    }
-}
-
-OUString QrCodeGenDialog::GenerateQrCode(OUString aQrText, int aQrECC, int 
aQrBorder)
+OUString QrCodeGenDialog::GenerateQRCode(OUString aQRText, long aQRECC, int 
aQRBorder)
 {
 #if ENABLE_FUZZERS
     return OUString();
@@ -225,8 +215,13 @@ OUString QrCodeGenDialog::GenerateQrCode(OUString aQrText, 
int aQrECC, int aQrBo
     //Select ECC:: value from aQrECC
     qrcodegen::QrCode::Ecc bqrEcc = qrcodegen::QrCode::Ecc::LOW;
 
-    switch (aQrECC)
+    switch (aQRECC)
     {
+        case 1:
+        {
+            bqrEcc = qrcodegen::QrCode::Ecc::LOW;
+            break;
+        }
         case 2:
         {
             bqrEcc = qrcodegen::QrCode::Ecc::MEDIUM;
@@ -242,20 +237,15 @@ OUString QrCodeGenDialog::GenerateQrCode(OUString 
aQrText, int aQrECC, int aQrBo
             bqrEcc = qrcodegen::QrCode::Ecc::HIGH;
             break;
         }
-        default:
-        {
-            bqrEcc = qrcodegen::QrCode::Ecc::LOW;
-            break;
-        }
     }
 
     //OuString to char* qrtext
-    OString o = OUStringToOString(aQrText, RTL_TEXTENCODING_ASCII_US);
+    OString o = OUStringToOString(aQRText, RTL_TEXTENCODING_ASCII_US);
     const char* qrtext = o.pData->buffer;
 
     //From Qr Code library.
     qrcodegen::QrCode qr0 = qrcodegen::QrCode::encodeText(qrtext, bqrEcc);
-    std::string svg = qr0.toSvgString(aQrBorder);
+    std::string svg = qr0.toSvgString(aQRBorder);
     //cstring to OUString
     char* cstr = &svg[0];
     return OUString::createFromAscii(cstr);
@@ -266,28 +256,24 @@ void QrCodeGenDialog::GetErrorCorrection(long 
ErrorCorrection)
 {
     switch (ErrorCorrection)
     {
-        case css::drawing::QRCodeErrorCorrection::MEDIUM:
+        case css::drawing::QRCodeErrorCorrection::LOW:
         {
-            m_xRadioMedium->set_active(true);
-            m_aECCSelect = ErrorCorrection;
+            m_xECC[0]->set_active(true);
             break;
         }
-        case css::drawing::QRCodeErrorCorrection::QUARTILE:
+        case css::drawing::QRCodeErrorCorrection::MEDIUM:
         {
-            m_xRadioQuartile->set_active(true);
-            m_aECCSelect = ErrorCorrection;
+            m_xECC[1]->set_active(true);
             break;
         }
-        case css::drawing::QRCodeErrorCorrection::HIGH:
+        case css::drawing::QRCodeErrorCorrection::QUARTILE:
         {
-            m_xRadioHigh->set_active(true);
-            m_aECCSelect = ErrorCorrection;
+            m_xECC[2]->set_active(true);
             break;
         }
-        default:
+        case css::drawing::QRCodeErrorCorrection::HIGH:
         {
-            m_xRadioLow->set_active(true);
-            m_aECCSelect = css::drawing::QRCodeErrorCorrection::LOW;
+            m_xECC[3]->set_active(true);
             break;
         }
     }
diff --git a/cui/source/inc/QrCodeGenDialog.hxx 
b/cui/source/inc/QrCodeGenDialog.hxx
index 4d5584fa3e53..a3ca38d48d4a 100644
--- a/cui/source/inc/QrCodeGenDialog.hxx
+++ b/cui/source/inc/QrCodeGenDialog.hxx
@@ -16,9 +16,6 @@
 
 #include <com/sun/star/beans/XPropertySet.hpp>
 
-// cuitabarea included to use Button Box class for group of Radio Buttons
-#include "cuitabarea.hxx"
-
 class QrCodeGenDialog : public weld::GenericDialogController
 {
 public:
@@ -33,23 +30,14 @@ protected:
 
 private:
     std::unique_ptr<weld::Entry> m_xEdittext;
-    std::unique_ptr<weld::RadioButton> m_xRadioLow;
-    std::unique_ptr<weld::RadioButton> m_xRadioMedium;
-    std::unique_ptr<weld::RadioButton> m_xRadioQuartile;
-    std::unique_ptr<weld::RadioButton> m_xRadioHigh;
+    std::unique_ptr<weld::RadioButton> m_xECC[4];
     std::unique_ptr<weld::SpinButton> m_xSpinBorder;
 
     css::uno::Reference<css::beans::XPropertySet> m_xExistingShapeProperties;
 
-    /* maBox - holds radioButton, helped in writing code. */
-    ButtonBox maBox;
-    /* Stores which error correction is selected. */
-    long m_aECCSelect;
-    void SelectErrorCorrection(weld::ToggleButton&);
     void GetErrorCorrection(long);
-    static OUString GenerateQrCode(OUString aQrText, int aQrECC, int 
aQrBorder);
-
-    DECL_LINK(SelectRadio_Impl, weld::ToggleButton&, void);
+    //Function contains QR Code Generating Library Calls
+    static OUString GenerateQRCode(OUString aQrText, long aQrECC, int 
aQrBorder);
 };
 
 #endif
diff --git a/cui/uiconfig/ui/qrcodegen.ui b/cui/uiconfig/ui/qrcodegen.ui
index c720b156503b..6e5b3f186292 100644
--- a/cui/uiconfig/ui/qrcodegen.ui
+++ b/cui/uiconfig/ui/qrcodegen.ui
@@ -182,14 +182,19 @@
                           <object class="GtkGrid">
                             <property name="visible">True</property>
                             <property name="can_focus">False</property>
+                            <property name="row_spacing">6</property>
+                            <property name="column_spacing">4</property>
                             <child>
                               <object class="GtkRadioButton" id="button_low">
-                                <property name="label" translatable="yes" 
context="qrcodegen|ErrorCorrection" >Low</property>
+                                <property name="label" translatable="yes" 
context="qrcodegen|ErrorCorrection">Low</property>
                                 <property name="visible">True</property>
                                 <property name="can_focus">True</property>
                                 <property 
name="receives_default">False</property>
+                                <property name="use_underline">True</property>
+                                <property name="xalign">0</property>
                                 <property name="active">True</property>
                                 <property name="draw_indicator">True</property>
+                                <property name="group">button_medium</property>
                               </object>
                               <packing>
                                 <property name="left_attach">0</property>
@@ -198,12 +203,15 @@
                             </child>
                             <child>
                               <object class="GtkRadioButton" 
id="button_medium">
-                                <property name="label" translatable="yes" 
context="qrcodegen|ErrorCorrection" >Medium</property>
+                                <property name="label" translatable="yes" 
context="qrcodegen|ErrorCorrection">Medium</property>
                                 <property name="visible">True</property>
                                 <property name="can_focus">True</property>
                                 <property 
name="receives_default">False</property>
+                                <property name="use_underline">True</property>
+                                <property name="xalign">0</property>
                                 <property name="active">True</property>
                                 <property name="draw_indicator">True</property>
+                                <property name="group">button_low</property>
                               </object>
                               <packing>
                                 <property name="left_attach">0</property>
@@ -212,12 +220,15 @@
                             </child>
                             <child>
                               <object class="GtkRadioButton" 
id="button_quartile">
-                                <property name="label" translatable="yes" 
context="qrcodegen|ErrorCorrection" >Quartile</property>
+                                <property name="label" translatable="yes" 
context="qrcodegen|ErrorCorrection">Quartile</property>
                                 <property name="visible">True</property>
                                 <property name="can_focus">True</property>
                                 <property 
name="receives_default">False</property>
+                                <property name="use_underline">True</property>
+                                <property name="xalign">0</property>
                                 <property name="active">True</property>
                                 <property name="draw_indicator">True</property>
+                                <property name="group">button_low</property>
                               </object>
                               <packing>
                                 <property name="left_attach">0</property>
@@ -226,12 +237,15 @@
                             </child>
                             <child>
                               <object class="GtkRadioButton" id="button_high">
-                                <property name="label" translatable="yes" 
context="qrcodegen|ErrorCorrection" >High</property>
+                                <property name="label" translatable="yes" 
context="qrcodegen|ErrorCorrection">High</property>
                                 <property name="visible">True</property>
                                 <property name="can_focus">True</property>
                                 <property 
name="receives_default">False</property>
+                                <property name="use_underline">True</property>
+                                <property name="xalign">0</property>
                                 <property name="active">True</property>
                                 <property name="draw_indicator">True</property>
+                                <property name="group">button_low</property>
                               </object>
                               <packing>
                                 <property name="left_attach">0</property>
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to