[Libreoffice-commits] core.git: chart2/source chart2/uiconfig

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Thu Oct 4 13:42:43 UTC 2018


 chart2/source/controller/dialogs/dlg_InsertLegend.cxx    |    8 
 chart2/source/controller/dialogs/res_LegendPosition.cxx  |  200 +++++++++++++++
 chart2/source/controller/inc/dlg_InsertLegend.hxx        |    8 
 chart2/source/controller/inc/res_LegendPosition.hxx      |   38 ++
 chart2/source/controller/main/ChartController_Insert.cxx |    8 
 chart2/uiconfig/ui/dlg_InsertLegend.ui                   |   16 -
 6 files changed, 260 insertions(+), 18 deletions(-)

New commits:
commit a57f67f1773f6693f07352fcb232460350d0d091
Author:     Caolán McNamara <caolanm at redhat.com>
AuthorDate: Thu Oct 4 09:55:10 2018 +0100
Commit:     Caolán McNamara <caolanm at redhat.com>
CommitDate: Thu Oct 4 15:42:20 2018 +0200

    weld SchLegendDlg
    
    Change-Id: Ie57d195782d9fbfdf555205e53e733529b4c1ae8
    Reviewed-on: https://gerrit.libreoffice.org/61360
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/chart2/source/controller/dialogs/dlg_InsertLegend.cxx b/chart2/source/controller/dialogs/dlg_InsertLegend.cxx
index 32acbeac5784..51b95fe3f46a 100644
--- a/chart2/source/controller/dialogs/dlg_InsertLegend.cxx
+++ b/chart2/source/controller/dialogs/dlg_InsertLegend.cxx
@@ -25,11 +25,9 @@ namespace chart
 
 using namespace ::com::sun::star;
 
-SchLegendDlg::SchLegendDlg(vcl::Window* pWindow, const uno::Reference< uno::XComponentContext>& xCC )
-    : ModalDialog(pWindow
-    ,"dlg_InsertLegend"
-    ,"modules/schart/ui/dlg_InsertLegend.ui")
-    , m_xLegendPositionResources( new LegendPositionResources(*this,xCC) )
+SchLegendDlg::SchLegendDlg(weld::Window* pWindow, const uno::Reference< uno::XComponentContext>& xCC)
+    : GenericDialogController(pWindow, "modules/schart/ui/dlg_InsertLegend.ui", "dlg_InsertLegend")
+    , m_xLegendPositionResources(new SchLegendPositionResources(*m_xBuilder, xCC))
 {
 }
 
diff --git a/chart2/source/controller/dialogs/res_LegendPosition.cxx b/chart2/source/controller/dialogs/res_LegendPosition.cxx
index cca59f0b639b..0d6963266ec9 100644
--- a/chart2/source/controller/dialogs/res_LegendPosition.cxx
+++ b/chart2/source/controller/dialogs/res_LegendPosition.cxx
@@ -240,6 +240,206 @@ void LegendPositionResources::SetChangeHdl( const Link<LinkParamNone*,void>& rLi
     m_aChangeLink = rLink;
 }
 
+SchLegendPositionResources::SchLegendPositionResources(weld::Builder& rBuilder)
+    : m_xCC() // unused in this scenario
+    , m_xCbxShow() // unused in this scenario, assumed to be visible
+    , m_xRbtLeft(rBuilder.weld_radio_button("left"))
+    , m_xRbtRight(rBuilder.weld_radio_button("right"))
+    , m_xRbtTop(rBuilder.weld_radio_button("top"))
+    , m_xRbtBottom(rBuilder.weld_radio_button("bottom"))
+{
+    impl_setRadioButtonToggleHdl();
+}
+
+SchLegendPositionResources::SchLegendPositionResources(weld::Builder& rBuilder,
+    const uno::Reference< uno::XComponentContext >& xCC)
+    : m_xCC(xCC)
+    , m_xCbxShow(rBuilder.weld_check_button("show"))
+    , m_xRbtLeft(rBuilder.weld_radio_button("left"))
+    , m_xRbtRight(rBuilder.weld_radio_button("right"))
+    , m_xRbtTop(rBuilder.weld_radio_button("top"))
+    , m_xRbtBottom(rBuilder.weld_radio_button("bottom"))
+{
+    m_xCbxShow->connect_toggled(LINK(this, SchLegendPositionResources, PositionEnableHdl));
+    impl_setRadioButtonToggleHdl();
+}
+
+void SchLegendPositionResources::impl_setRadioButtonToggleHdl()
+{
+    m_xRbtLeft->connect_toggled(LINK(this, SchLegendPositionResources, PositionChangeHdl));
+    m_xRbtTop->connect_toggled(LINK(this, SchLegendPositionResources, PositionChangeHdl));
+    m_xRbtRight->connect_toggled(LINK(this, SchLegendPositionResources, PositionChangeHdl));
+    m_xRbtBottom->connect_toggled(LINK(this, SchLegendPositionResources, PositionChangeHdl));
+}
+
+SchLegendPositionResources::~SchLegendPositionResources()
+{
+}
+
+void SchLegendPositionResources::writeToResources( const uno::Reference< frame::XModel >& xChartModel )
+{
+    try
+    {
+        uno::Reference< XDiagram > xDiagram = ChartModelHelper::findDiagram( xChartModel );
+        uno::Reference< beans::XPropertySet > xProp( xDiagram->getLegend(), uno::UNO_QUERY );
+        if( xProp.is() )
+        {
+            //show
+            bool bShowLegend = false;
+            xProp->getPropertyValue( "Show" ) >>= bShowLegend;
+            if (m_xCbxShow)
+                m_xCbxShow->set_active(bShowLegend);
+            PositionEnableHdl(*m_xCbxShow);
+
+            //position
+            chart2::LegendPosition ePos;
+            xProp->getPropertyValue( "AnchorPosition" )  >>= ePos;
+            switch( ePos )
+            {
+                case chart2::LegendPosition_LINE_START:
+                    m_xRbtLeft->set_active(true);
+                    break;
+                case chart2::LegendPosition_LINE_END:
+                    m_xRbtRight->set_active(true);
+                    break;
+                case chart2::LegendPosition_PAGE_START:
+                    m_xRbtTop->set_active(true);
+                    break;
+                case chart2::LegendPosition_PAGE_END:
+                    m_xRbtBottom->set_active(true);
+                    break;
+
+                case chart2::LegendPosition_CUSTOM:
+                default:
+                    m_xRbtRight->set_active(true);
+                    break;
+            }
+        }
+    }
+    catch( const uno::Exception & )
+    {
+        DBG_UNHANDLED_EXCEPTION("chart2");
+    }
+}
+
+void SchLegendPositionResources::writeToModel( const css::uno::Reference< frame::XModel >& xChartModel ) const
+{
+    try
+    {
+        bool bShowLegend = m_xCbxShow && m_xCbxShow->get_active();
+        ChartModel& rModel = dynamic_cast<ChartModel&>(*xChartModel.get());
+        uno::Reference< beans::XPropertySet > xProp(LegendHelper::getLegend(rModel, m_xCC, bShowLegend), uno::UNO_QUERY);
+        if( xProp.is() )
+        {
+            //show
+            xProp->setPropertyValue( "Show" , uno::Any( bShowLegend ));
+
+            //position
+            chart2::LegendPosition eNewPos;
+            css::chart::ChartLegendExpansion eExp = css::chart::ChartLegendExpansion_HIGH;
+
+            if( m_xRbtLeft->get_active() )
+                eNewPos = chart2::LegendPosition_LINE_START;
+            else if( m_xRbtRight->get_active() )
+            {
+                eNewPos = chart2::LegendPosition_LINE_END;
+            }
+            else if( m_xRbtTop->get_active() )
+            {
+                eNewPos = chart2::LegendPosition_PAGE_START;
+                eExp = css::chart::ChartLegendExpansion_WIDE;
+            }
+            else if( m_xRbtBottom->get_active() )
+            {
+                eNewPos = chart2::LegendPosition_PAGE_END;
+                eExp = css::chart::ChartLegendExpansion_WIDE;
+            }
+
+            xProp->setPropertyValue( "AnchorPosition" , uno::Any( eNewPos ));
+            xProp->setPropertyValue( "Expansion" , uno::Any( eExp ));
+            xProp->setPropertyValue( "RelativePosition" , uno::Any());
+        }
+    }
+    catch( const uno::Exception & )
+    {
+        DBG_UNHANDLED_EXCEPTION("chart2" );
+    }
+}
+
+IMPL_LINK_NOARG(SchLegendPositionResources, PositionEnableHdl, weld::ToggleButton&, void)
+{
+    bool bEnable = !m_xCbxShow || m_xCbxShow->get_active();
+
+    m_xRbtLeft->set_sensitive( bEnable );
+    m_xRbtTop->set_sensitive( bEnable );
+    m_xRbtRight->set_sensitive( bEnable );
+    m_xRbtBottom->set_sensitive( bEnable );
+
+    m_aChangeLink.Call(nullptr);
+}
+
+void SchLegendPositionResources::initFromItemSet( const SfxItemSet& rInAttrs )
+{
+    const SfxPoolItem* pPoolItem = nullptr;
+    if( rInAttrs.GetItemState( SCHATTR_LEGEND_POS, true, &pPoolItem ) == SfxItemState::SET )
+    {
+        chart2::LegendPosition nLegendPosition = static_cast<chart2::LegendPosition>(static_cast<const SfxInt32Item*>(pPoolItem)->GetValue());
+        switch( nLegendPosition )
+        {
+            case chart2::LegendPosition_LINE_START:
+                m_xRbtLeft->set_active(true);
+                break;
+            case chart2::LegendPosition_PAGE_START:
+                m_xRbtTop->set_active(true);
+                break;
+            case chart2::LegendPosition_LINE_END:
+                m_xRbtRight->set_active(true);
+                break;
+            case chart2::LegendPosition_PAGE_END:
+                m_xRbtBottom->set_active(true);
+                break;
+            default:
+                break;
+        }
+    }
+
+    if (m_xCbxShow && rInAttrs.GetItemState( SCHATTR_LEGEND_SHOW, true, &pPoolItem ) == SfxItemState::SET)
+    {
+        bool bShow = static_cast< const SfxBoolItem * >( pPoolItem )->GetValue();
+        m_xCbxShow->set_active(bShow);
+    }
+}
+
+void SchLegendPositionResources::writeToItemSet( SfxItemSet& rOutAttrs ) const
+{
+    chart2::LegendPosition nLegendPosition = chart2::LegendPosition_CUSTOM;
+    if( m_xRbtLeft->get_active() )
+        nLegendPosition = chart2::LegendPosition_LINE_START;
+    else if( m_xRbtTop->get_active() )
+        nLegendPosition = chart2::LegendPosition_PAGE_START;
+    else if( m_xRbtRight->get_active() )
+        nLegendPosition = chart2::LegendPosition_LINE_END;
+    else if( m_xRbtBottom->get_active() )
+        nLegendPosition = chart2::LegendPosition_PAGE_END;
+    rOutAttrs.Put( SfxInt32Item(SCHATTR_LEGEND_POS, static_cast<sal_Int32>(nLegendPosition) ) );
+
+    rOutAttrs.Put( SfxBoolItem(SCHATTR_LEGEND_SHOW, !m_xCbxShow || m_xCbxShow->get_active()) );
+}
+
+IMPL_LINK(SchLegendPositionResources, PositionChangeHdl, weld::ToggleButton&, rRadio, void )
+{
+    //for each radio click there are coming two change events
+    //first uncheck of previous button -> ignore that call
+    //the second call gives the check of the new button
+    if (rRadio.get_active())
+        m_aChangeLink.Call(nullptr);
+}
+
+void SchLegendPositionResources::SetChangeHdl( const Link<LinkParamNone*,void>& rLink )
+{
+    m_aChangeLink = rLink;
+}
+
 } //namespace chart
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/chart2/source/controller/inc/dlg_InsertLegend.hxx b/chart2/source/controller/inc/dlg_InsertLegend.hxx
index 5376a48040e7..1b8ff7b4429f 100644
--- a/chart2/source/controller/inc/dlg_InsertLegend.hxx
+++ b/chart2/source/controller/inc/dlg_InsertLegend.hxx
@@ -19,7 +19,7 @@
 #ifndef INCLUDED_CHART2_SOURCE_CONTROLLER_INC_DLG_INSERTLEGEND_HXX
 #define INCLUDED_CHART2_SOURCE_CONTROLLER_INC_DLG_INSERTLEGEND_HXX
 
-#include <vcl/dialog.hxx>
+#include <vcl/weld.hxx>
 
 #include <memory>
 
@@ -31,13 +31,13 @@ namespace com { namespace sun { namespace star { namespace uno { class XComponen
 namespace chart
 {
 
-class SchLegendDlg : public ModalDialog
+class SchLegendDlg : public weld::GenericDialogController
 {
 private:
-    std::unique_ptr < LegendPositionResources >    m_xLegendPositionResources;
+    std::unique_ptr<SchLegendPositionResources> m_xLegendPositionResources;
 
 public:
-    SchLegendDlg( vcl::Window* pParent, const css::uno::Reference< css::uno::XComponentContext>& xCC );
+    SchLegendDlg(weld::Window* pParent, const css::uno::Reference< css::uno::XComponentContext>& xCC);
 
     void init( const css::uno::Reference< css::frame::XModel >& xChartModel );
     void writeToModel( const css::uno::Reference< css::frame::XModel >& xChartModel ) const;
diff --git a/chart2/source/controller/inc/res_LegendPosition.hxx b/chart2/source/controller/inc/res_LegendPosition.hxx
index 928a94f544b0..1568781e4818 100644
--- a/chart2/source/controller/inc/res_LegendPosition.hxx
+++ b/chart2/source/controller/inc/res_LegendPosition.hxx
@@ -20,6 +20,7 @@
 #define INCLUDED_CHART2_SOURCE_CONTROLLER_INC_RES_LEGENDPOSITION_HXX
 
 #include <vcl/button.hxx>
+#include <vcl/weld.hxx>
 #include <svl/itemset.hxx>
 
 class VclBuilderContainer;
@@ -68,6 +69,43 @@ private:
     Link<LinkParamNone*,void> m_aChangeLink;
 };
 
+
+class SchLegendPositionResources final
+{
+
+public:
+    //constructor without Display checkbox
+    SchLegendPositionResources(weld::Builder& rBuilder);
+    //constructor inclusive Display checkbox
+    SchLegendPositionResources(weld::Builder& rBuilder, const css::uno::Reference<
+                       css::uno::XComponentContext>& xCC );
+    ~SchLegendPositionResources();
+
+    void writeToResources( const css::uno::Reference< css::frame::XModel >& xChartModel );
+    void writeToModel( const css::uno::Reference< css::frame::XModel >& xChartModel ) const;
+
+    void initFromItemSet( const SfxItemSet& rInAttrs );
+    void writeToItemSet( SfxItemSet& rOutAttrs ) const;
+
+    void SetChangeHdl( const Link<LinkParamNone*,void>& rLink );
+
+    DECL_LINK(PositionEnableHdl, weld::ToggleButton&, void);
+    DECL_LINK(PositionChangeHdl, weld::ToggleButton&, void);
+
+private:
+    void impl_setRadioButtonToggleHdl();
+
+private:
+    css::uno::Reference< css::uno::XComponentContext>    m_xCC;
+    Link<LinkParamNone*,void> m_aChangeLink;
+
+    std::unique_ptr<weld::CheckButton> m_xCbxShow;
+    std::unique_ptr<weld::RadioButton> m_xRbtLeft;
+    std::unique_ptr<weld::RadioButton> m_xRbtRight;
+    std::unique_ptr<weld::RadioButton> m_xRbtTop;
+    std::unique_ptr<weld::RadioButton> m_xRbtBottom;
+};
+
 } //namespace chart
 
 #endif
diff --git a/chart2/source/controller/main/ChartController_Insert.cxx b/chart2/source/controller/main/ChartController_Insert.cxx
index e24800d71b3f..a998d18453d1 100644
--- a/chart2/source/controller/main/ChartController_Insert.cxx
+++ b/chart2/source/controller/main/ChartController_Insert.cxx
@@ -225,13 +225,13 @@ void ChartController::executeDispatch_OpenLegendDialog()
     {
         //prepare and open dialog
         SolarMutexGuard aGuard;
-        ScopedVclPtrInstance< SchLegendDlg > aDlg( GetChartWindow(), m_xCC );
-        aDlg->init( getModel() );
-        if( aDlg->Execute() == RET_OK )
+        SchLegendDlg aDlg(GetChartFrame(), m_xCC);
+        aDlg.init( getModel() );
+        if (aDlg.run() == RET_OK)
         {
             // lock controllers till end of block
             ControllerLockGuardUNO aCLGuard( getModel() );
-            aDlg->writeToModel( getModel() );
+            aDlg.writeToModel( getModel() );
             aUndoGuard.commit();
         }
     }
diff --git a/chart2/uiconfig/ui/dlg_InsertLegend.ui b/chart2/uiconfig/ui/dlg_InsertLegend.ui
index d0d6b8f40451..7ca2db0744ee 100644
--- a/chart2/uiconfig/ui/dlg_InsertLegend.ui
+++ b/chart2/uiconfig/ui/dlg_InsertLegend.ui
@@ -1,12 +1,18 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!-- Generated with glade 3.18.3 -->
+<!-- Generated with glade 3.22.1 -->
 <interface domain="chart">
   <requires lib="gtk+" version="3.18"/>
   <object class="GtkDialog" id="dlg_InsertLegend">
     <property name="can_focus">False</property>
     <property name="border_width">6</property>
     <property name="title" translatable="yes" context="dlg_InsertLegend|dlg_InsertLegend">Legend</property>
+    <property name="modal">True</property>
+    <property name="default_width">0</property>
+    <property name="default_height">0</property>
     <property name="type_hint">dialog</property>
+    <child>
+      <placeholder/>
+    </child>
     <child internal-child="vbox">
       <object class="GtkBox" id="dialog-vbox1">
         <property name="can_focus">False</property>
@@ -125,8 +131,8 @@
                                 <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">right</property>
                               </object>
                               <packing>
                                 <property name="left_attach">0</property>
@@ -142,7 +148,7 @@
                                 <property name="use_underline">True</property>
                                 <property name="xalign">0</property>
                                 <property name="draw_indicator">True</property>
-                                <property name="group">top</property>
+                                <property name="group">left</property>
                               </object>
                               <packing>
                                 <property name="left_attach">0</property>
@@ -158,7 +164,7 @@
                                 <property name="use_underline">True</property>
                                 <property name="xalign">0</property>
                                 <property name="draw_indicator">True</property>
-                                <property name="group">bottom</property>
+                                <property name="group">left</property>
                               </object>
                               <packing>
                                 <property name="left_attach">0</property>
@@ -196,8 +202,8 @@
                   <object class="GtkLabel" id="TXT_POSITION">
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
-                    <property name="xalign">0</property>
                     <property name="label" translatable="yes" context="dlg_InsertLegend|TXT_POSITION">Position</property>
+                    <property name="xalign">0</property>
                     <attributes>
                       <attribute name="weight" value="bold"/>
                     </attributes>


More information about the Libreoffice-commits mailing list