summaryrefslogtreecommitdiff
path: root/chart2/source/tools/RangeHighlighter.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'chart2/source/tools/RangeHighlighter.cxx')
-rw-r--r--chart2/source/tools/RangeHighlighter.cxx110
1 files changed, 51 insertions, 59 deletions
diff --git a/chart2/source/tools/RangeHighlighter.cxx b/chart2/source/tools/RangeHighlighter.cxx
index b326d0bacce9..69a2951108a4 100644
--- a/chart2/source/tools/RangeHighlighter.cxx
+++ b/chart2/source/tools/RangeHighlighter.cxx
@@ -19,20 +19,21 @@
#include <RangeHighlighter.hxx>
#include <WeakListenerAdapter.hxx>
-#include <ChartModelHelper.hxx>
+#include <ChartModel.hxx>
#include <DataSourceHelper.hxx>
#include <ObjectIdentifier.hxx>
+#include <DataSeries.hxx>
#include <DataSeriesHelper.hxx>
+#include <Diagram.hxx>
#include <com/sun/star/chart2/ScaleData.hpp>
#include <com/sun/star/chart2/XAxis.hpp>
#include <com/sun/star/chart2/XDataSeries.hpp>
#include <com/sun/star/chart/ErrorBarStyle.hpp>
-#include <com/sun/star/chart2/XChartDocument.hpp>
#include <com/sun/star/drawing/XShape.hpp>
#include <com/sun/star/view/XSelectionSupplier.hpp>
#include <comphelper/sequence.hxx>
-#include <tools/diagnose_ex.h>
+#include <comphelper/diagnose_ex.hxx>
#include <tools/color.hxx>
using namespace ::com::sun::star;
@@ -47,17 +48,18 @@ const Color defaultPreferredColor = COL_LIGHTBLUE;
void lcl_fillRanges(
Sequence< chart2::data::HighlightedRange > & rOutRanges,
- const Sequence< OUString >& aRangeStrings,
+ const std::vector< OUString >& aRangeStrings,
Color nPreferredColor,
sal_Int32 nIndex = -1 )
{
- rOutRanges.realloc( aRangeStrings.getLength());
- for( sal_Int32 i=0; i<aRangeStrings.getLength(); ++i )
+ rOutRanges.realloc( aRangeStrings.size());
+ auto pOutRanges = rOutRanges.getArray();
+ for( size_t i=0; i<aRangeStrings.size(); ++i )
{
- rOutRanges[i].RangeRepresentation = aRangeStrings[i];
- rOutRanges[i].PreferredColor = sal_Int32(nPreferredColor);
- rOutRanges[i].AllowMerginigWithOtherRanges = false;
- rOutRanges[i].Index = nIndex;
+ pOutRanges[i].RangeRepresentation = aRangeStrings[i];
+ pOutRanges[i].PreferredColor = sal_Int32(nPreferredColor);
+ pOutRanges[i].AllowMerginigWithOtherRanges = false;
+ pOutRanges[i].Index = nIndex;
}
}
@@ -67,9 +69,9 @@ namespace chart
{
RangeHighlighter::RangeHighlighter(
- const Reference< view::XSelectionSupplier > & xSelectionSupplier ) :
- impl::RangeHighlighter_Base( m_aMutex ),
- m_xSelectionSupplier( xSelectionSupplier ),
+ const rtl::Reference< ChartModel > & xChartModel ) :
+ m_xSelectionSupplier(xChartModel->getCurrentController(), uno::UNO_QUERY),
+ m_xChartModel( xChartModel ),
m_nAddedListenerCount( 0 ),
m_bIncludeHiddenCells(true)
{
@@ -87,22 +89,18 @@ Sequence< chart2::data::HighlightedRange > SAL_CALL RangeHighlighter::getSelecte
void RangeHighlighter::determineRanges()
{
m_aSelectedRanges.realloc( 0 );
+ if( !m_xChartModel.is())
+ return;
if( !m_xSelectionSupplier.is())
return;
try
{
- Reference< frame::XController > xController( m_xSelectionSupplier, uno::UNO_QUERY );
- Reference< frame::XModel > xChartModel;
- if( xController.is())
- xChartModel.set( xController->getModel());
-
- m_bIncludeHiddenCells = ChartModelHelper::isIncludeHiddenCells( xChartModel );
+ m_bIncludeHiddenCells = m_xChartModel->isIncludeHiddenCells();
uno::Any aSelection( m_xSelectionSupplier->getSelection());
- const uno::Type& rType = aSelection.getValueType();
- if ( rType == cppu::UnoType<OUString>::get() )
+ if (aSelection.getValueType() == cppu::UnoType<OUString>::get())
{
// @todo??: maybe getSelection() should return a model object rather than a CID
@@ -112,7 +110,7 @@ void RangeHighlighter::determineRanges()
{
ObjectType eObjectType = ObjectIdentifier::getObjectType( aCID );
sal_Int32 nIndex = ObjectIdentifier::getIndexFromParticleOrCID( aCID );
- Reference< chart2::XDataSeries > xDataSeries( ObjectIdentifier::getDataSeriesForCID( aCID, xChartModel ) );
+ rtl::Reference< DataSeries > xDataSeries( ObjectIdentifier::getDataSeriesForCID( aCID, m_xChartModel ) );
if( eObjectType == OBJECTTYPE_LEGEND_ENTRY )
{
OUString aParentParticel( ObjectIdentifier::getFullParentParticle( aCID ) );
@@ -134,7 +132,7 @@ void RangeHighlighter::determineRanges()
{
// select error bar ranges, or data series, if the style is
// not set to FROM_DATA
- fillRangesForErrorBars( ObjectIdentifier::getObjectPropertySet( aCID, xChartModel ), xDataSeries );
+ fillRangesForErrorBars( ObjectIdentifier::getObjectPropertySet( aCID, m_xChartModel ), xDataSeries );
return;
}
else if( xDataSeries.is() )
@@ -146,7 +144,7 @@ void RangeHighlighter::determineRanges()
else if( eObjectType == OBJECTTYPE_AXIS )
{
// Axis (Categories)
- Reference< chart2::XAxis > xAxis( ObjectIdentifier::getObjectPropertySet( aCID, xChartModel ), uno::UNO_QUERY );
+ Reference< chart2::XAxis > xAxis( ObjectIdentifier::getObjectPropertySet( aCID, m_xChartModel ), uno::UNO_QUERY );
if( xAxis.is())
{
fillRangesForCategories( xAxis );
@@ -160,7 +158,7 @@ void RangeHighlighter::determineRanges()
)
{
// Diagram
- Reference< chart2::XDiagram > xDia( ObjectIdentifier::getDiagramForCID( aCID, xChartModel ) );
+ rtl::Reference< ::chart::Diagram > xDia( ObjectIdentifier::getDiagramForCID( aCID, m_xChartModel ) );
if( xDia.is())
{
fillRangesForDiagram( xDia );
@@ -169,11 +167,9 @@ void RangeHighlighter::determineRanges()
}
}
}
- else if ( rType == cppu::UnoType< drawing::XShape >::get() )
+ else if (Reference<drawing::XShape> xShape; aSelection >>= xShape)
{
// #i12587# support for shapes in chart
- Reference< drawing::XShape > xShape;
- aSelection >>= xShape;
if ( xShape.is() )
{
return;
@@ -182,8 +178,7 @@ void RangeHighlighter::determineRanges()
else
{
//if nothing is selected select all ranges
- Reference< chart2::XChartDocument > xChartDoc( xChartModel, uno::UNO_QUERY_THROW );
- fillRangesForDiagram( xChartDoc->getFirstDiagram() );
+ fillRangesForDiagram( m_xChartModel->getFirstChartDiagram() );
return;
}
}
@@ -193,17 +188,18 @@ void RangeHighlighter::determineRanges()
}
}
-void RangeHighlighter::fillRangesForDiagram( const Reference< chart2::XDiagram > & xDiagram )
+void RangeHighlighter::fillRangesForDiagram( const rtl::Reference< Diagram > & xDiagram )
{
- Sequence< OUString > aSelectedRanges( DataSourceHelper::getUsedDataRanges( xDiagram ));
- m_aSelectedRanges.realloc( aSelectedRanges.getLength());
+ std::vector< OUString > aSelectedRanges( DataSourceHelper::getUsedDataRanges( xDiagram ));
+ m_aSelectedRanges.realloc( aSelectedRanges.size());
+ auto pSelectedRanges = m_aSelectedRanges.getArray();
// @todo: merge ranges
- for( sal_Int32 i=0; i<aSelectedRanges.getLength(); ++i )
+ for( size_t i=0; i<aSelectedRanges.size(); ++i )
{
- m_aSelectedRanges[i].RangeRepresentation = aSelectedRanges[i];
- m_aSelectedRanges[i].Index = -1;
- m_aSelectedRanges[i].PreferredColor = sal_Int32(defaultPreferredColor);
- m_aSelectedRanges[i].AllowMerginigWithOtherRanges = true;
+ pSelectedRanges[i].RangeRepresentation = aSelectedRanges[i];
+ pSelectedRanges[i].Index = -1;
+ pSelectedRanges[i].PreferredColor = sal_Int32(defaultPreferredColor);
+ pSelectedRanges[i].AllowMerginigWithOtherRanges = true;
}
}
@@ -229,7 +225,7 @@ void RangeHighlighter::fillRangesForErrorBars(
sal_Int32 nStyle = css::chart::ErrorBarStyle::NONE;
bUsesRangesAsErrorBars =
( xErrorBar.is() &&
- (xErrorBar->getPropertyValue( "ErrorBarStyle") >>= nStyle) &&
+ (xErrorBar->getPropertyValue( u"ErrorBarStyle"_ustr) >>= nStyle) &&
nStyle == css::chart::ErrorBarStyle::FROM_DATA );
}
catch( const uno::Exception & )
@@ -263,19 +259,15 @@ void RangeHighlighter::fillRangesForCategories( const Reference< chart2::XAxis >
defaultPreferredColor );
}
-void RangeHighlighter::fillRangesForDataPoint( const Reference< uno::XInterface > & xDataSeries, sal_Int32 nIndex )
+void RangeHighlighter::fillRangesForDataPoint( const rtl::Reference< DataSeries > & xDataSeries, sal_Int32 nIndex )
{
if( !xDataSeries.is())
return;
- Reference< chart2::data::XDataSource > xSource( xDataSeries, uno::UNO_QUERY );
- if( !xSource.is() )
- return;
-
Color nPreferredColor = defaultPreferredColor;
std::vector< chart2::data::HighlightedRange > aHilightedRanges;
- const Sequence< Reference< chart2::data::XLabeledDataSequence > > aLSeqSeq( xSource->getDataSequences());
- for( Reference< chart2::data::XLabeledDataSequence > const & labelDataSeq : aLSeqSeq )
+ const std::vector< uno::Reference< chart2::data::XLabeledDataSequence > > & aLSeqSeq( xDataSeries->getDataSequences2());
+ for( uno::Reference< chart2::data::XLabeledDataSequence > const & labelDataSeq : aLSeqSeq )
{
Reference< chart2::data::XDataSequence > xLabel( labelDataSeq->getLabel());
Reference< chart2::data::XDataSequence > xValues( labelDataSeq->getValues());
@@ -305,7 +297,8 @@ void SAL_CALL RangeHighlighter::addSelectionChangeListener( const Reference< vie
if( m_nAddedListenerCount == 0 )
startListening();
- rBHelper.addListener( cppu::UnoType<decltype(xListener)>::get(), xListener);
+ std::unique_lock g(m_aMutex);
+ maSelectionChangeListeners.addInterface( g, xListener);
++m_nAddedListenerCount;
//bring the new listener up to the current state
@@ -315,7 +308,8 @@ void SAL_CALL RangeHighlighter::addSelectionChangeListener( const Reference< vie
void SAL_CALL RangeHighlighter::removeSelectionChangeListener( const Reference< view::XSelectionChangeListener >& xListener )
{
- rBHelper.removeListener( cppu::UnoType<decltype(xListener)>::get(), xListener );
+ std::unique_lock g(m_aMutex);
+ maSelectionChangeListeners.removeInterface( g, xListener );
--m_nAddedListenerCount;
if( m_nAddedListenerCount == 0 )
stopListening();
@@ -333,18 +327,16 @@ void SAL_CALL RangeHighlighter::selectionChanged( const lang::EventObject& /*aEv
void RangeHighlighter::fireSelectionEvent()
{
- ::cppu::OInterfaceContainerHelper* pIC = rBHelper.getContainer(
- cppu::UnoType< view::XSelectionChangeListener >::get() );
- if( pIC )
+ std::unique_lock g(m_aMutex);
+ if( maSelectionChangeListeners.getLength(g) )
{
lang::EventObject aEvent( static_cast< lang::XComponent* >( this ) );
- ::cppu::OInterfaceIteratorHelper aIt( *pIC );
- while( aIt.hasMoreElements() )
- {
- uno::Reference< view::XSelectionChangeListener > xListener( aIt.next(), uno::UNO_QUERY );
- if( xListener.is() )
- xListener->selectionChanged( aEvent );
- }
+ maSelectionChangeListeners.forEach(g,
+ [&aEvent](const css::uno::Reference<view::XSelectionChangeListener>& xListener)
+ {
+ xListener->selectionChanged(aEvent);
+ }
+ );
}
}
@@ -382,7 +374,7 @@ void RangeHighlighter::stopListening()
// ____ WeakComponentImplHelperBase ____
// is called when dispose() is called at this component
-void SAL_CALL RangeHighlighter::disposing()
+void RangeHighlighter::disposing(std::unique_lock<std::mutex>&)
{
// @todo: remove listener. Currently the controller shows an assertion
// because it is already disposed