Kaydet (Commit) ecb7a18a authored tarafından Caolán McNamara's avatar Caolán McNamara

merge SchLegendPositionResources/LegendPositionResources back together

Change-Id: I53b5bc65313a6f5e661c3f6804db256d18037c74
Reviewed-on: https://gerrit.libreoffice.org/62437
Tested-by: Jenkins
Reviewed-by: 's avatarCaolán McNamara <caolanm@redhat.com>
Tested-by: 's avatarCaolán McNamara <caolanm@redhat.com>
üst 4eecab25
...@@ -27,7 +27,7 @@ using namespace ::com::sun::star; ...@@ -27,7 +27,7 @@ using namespace ::com::sun::star;
SchLegendDlg::SchLegendDlg(weld::Window* pWindow, const uno::Reference< uno::XComponentContext>& xCC) SchLegendDlg::SchLegendDlg(weld::Window* pWindow, const uno::Reference< uno::XComponentContext>& xCC)
: GenericDialogController(pWindow, "modules/schart/ui/dlg_InsertLegend.ui", "dlg_InsertLegend") : GenericDialogController(pWindow, "modules/schart/ui/dlg_InsertLegend.ui", "dlg_InsertLegend")
, m_xLegendPositionResources(new SchLegendPositionResources(*m_xBuilder, xCC)) , m_xLegendPositionResources(new LegendPositionResources(*m_xBuilder, xCC))
{ {
} }
......
...@@ -39,6 +39,15 @@ namespace chart ...@@ -39,6 +39,15 @@ namespace chart
using namespace ::com::sun::star; using namespace ::com::sun::star;
using namespace ::com::sun::star::chart2; using namespace ::com::sun::star::chart2;
LegendPositionResources::LegendPositionResources(weld::Builder& rBuilder)
: 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();
}
LegendPositionResources::LegendPositionResources(weld::Builder& rBuilder, LegendPositionResources::LegendPositionResources(weld::Builder& rBuilder,
const uno::Reference< uno::XComponentContext >& xCC) const uno::Reference< uno::XComponentContext >& xCC)
: m_xCC(xCC) : m_xCC(xCC)
...@@ -165,147 +174,7 @@ IMPL_LINK_NOARG(LegendPositionResources, PositionEnableHdl, weld::ToggleButton&, ...@@ -165,147 +174,7 @@ IMPL_LINK_NOARG(LegendPositionResources, PositionEnableHdl, weld::ToggleButton&,
m_aChangeLink.Call(nullptr); m_aChangeLink.Call(nullptr);
} }
IMPL_LINK (LegendPositionResources, PositionChangeHdl, weld::ToggleButton&, rRadio, void) void LegendPositionResources::initFromItemSet( const SfxItemSet& rInAttrs )
{
//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 LegendPositionResources::SetChangeHdl( const Link<LinkParamNone*,void>& rLink )
{
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"))
{
}
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));
}
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 );
}
void SchLegendPositionResources::initFromItemSet( const SfxItemSet& rInAttrs )
{ {
const SfxPoolItem* pPoolItem = nullptr; const SfxPoolItem* pPoolItem = nullptr;
if( rInAttrs.GetItemState( SCHATTR_LEGEND_POS, true, &pPoolItem ) == SfxItemState::SET ) if( rInAttrs.GetItemState( SCHATTR_LEGEND_POS, true, &pPoolItem ) == SfxItemState::SET )
...@@ -330,14 +199,14 @@ void SchLegendPositionResources::initFromItemSet( const SfxItemSet& rInAttrs ) ...@@ -330,14 +199,14 @@ void SchLegendPositionResources::initFromItemSet( const SfxItemSet& rInAttrs )
} }
} }
if (m_xCbxShow && rInAttrs.GetItemState( SCHATTR_LEGEND_SHOW, true, &pPoolItem ) == SfxItemState::SET) if( m_xCbxShow && rInAttrs.GetItemState( SCHATTR_LEGEND_SHOW, true, &pPoolItem ) == SfxItemState::SET )
{ {
bool bShow = static_cast< const SfxBoolItem * >( pPoolItem )->GetValue(); bool bShow = static_cast< const SfxBoolItem * >( pPoolItem )->GetValue();
m_xCbxShow->set_active(bShow); m_xCbxShow->set_active(bShow);
} }
} }
void SchLegendPositionResources::writeToItemSet( SfxItemSet& rOutAttrs ) const void LegendPositionResources::writeToItemSet( SfxItemSet& rOutAttrs ) const
{ {
chart2::LegendPosition nLegendPosition = chart2::LegendPosition_CUSTOM; chart2::LegendPosition nLegendPosition = chart2::LegendPosition_CUSTOM;
if( m_xRbtLeft->get_active() ) if( m_xRbtLeft->get_active() )
...@@ -353,6 +222,20 @@ void SchLegendPositionResources::writeToItemSet( SfxItemSet& rOutAttrs ) const ...@@ -353,6 +222,20 @@ void SchLegendPositionResources::writeToItemSet( SfxItemSet& rOutAttrs ) const
rOutAttrs.Put( SfxBoolItem(SCHATTR_LEGEND_SHOW, !m_xCbxShow || m_xCbxShow->get_active()) ); rOutAttrs.Put( SfxBoolItem(SCHATTR_LEGEND_SHOW, !m_xCbxShow || m_xCbxShow->get_active()) );
} }
IMPL_LINK (LegendPositionResources, 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 LegendPositionResources::SetChangeHdl( const Link<LinkParamNone*,void>& rLink )
{
m_aChangeLink = rLink;
}
} //namespace chart } //namespace chart
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -31,7 +31,7 @@ class SchLegendPosTabPage : public SfxTabPage ...@@ -31,7 +31,7 @@ class SchLegendPosTabPage : public SfxTabPage
{ {
private: private:
SchLegendPositionResources m_aLegendPositionResources; LegendPositionResources m_aLegendPositionResources;
std::unique_ptr<TextDirectionListBox> m_xLbTextDirection; std::unique_ptr<TextDirectionListBox> m_xLbTextDirection;
public: public:
......
...@@ -34,7 +34,7 @@ namespace chart ...@@ -34,7 +34,7 @@ namespace chart
class SchLegendDlg : public weld::GenericDialogController class SchLegendDlg : public weld::GenericDialogController
{ {
private: private:
std::unique_ptr<SchLegendPositionResources> m_xLegendPositionResources; std::unique_ptr<LegendPositionResources> m_xLegendPositionResources;
public: public:
SchLegendDlg(weld::Window* pParent, const css::uno::Reference< css::uno::XComponentContext>& xCC); SchLegendDlg(weld::Window* pParent, const css::uno::Reference< css::uno::XComponentContext>& xCC);
......
...@@ -32,6 +32,8 @@ class LegendPositionResources final ...@@ -32,6 +32,8 @@ class LegendPositionResources final
{ {
public: public:
//constructor without Display checkbox
LegendPositionResources(weld::Builder& rBuilder);
//constructor inclusive Display checkbox //constructor inclusive Display checkbox
LegendPositionResources(weld::Builder& rBuilder, const css::uno::Reference< LegendPositionResources(weld::Builder& rBuilder, const css::uno::Reference<
css::uno::XComponentContext>& xCC ); css::uno::XComponentContext>& xCC );
...@@ -40,6 +42,9 @@ public: ...@@ -40,6 +42,9 @@ public:
void writeToResources( const css::uno::Reference< css::frame::XModel >& xChartModel ); void writeToResources( const css::uno::Reference< css::frame::XModel >& xChartModel );
void writeToModel( const css::uno::Reference< css::frame::XModel >& xChartModel ) const; 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 ); void SetChangeHdl( const Link<LinkParamNone*,void>& rLink );
DECL_LINK( PositionEnableHdl, weld::ToggleButton&, void ); DECL_LINK( PositionEnableHdl, weld::ToggleButton&, void );
...@@ -59,36 +64,6 @@ private: ...@@ -59,36 +64,6 @@ private:
std::unique_ptr<weld::RadioButton> m_xRbtBottom; std::unique_ptr<weld::RadioButton> m_xRbtBottom;
}; };
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;
DECL_LINK(PositionEnableHdl, weld::ToggleButton&, void);
private:
css::uno::Reference< css::uno::XComponentContext> m_xCC;
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 } //namespace chart
#endif #endif
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment