some improvements for the time based charting

The updating seems to work. It just does not update the references yet.

Change-Id: I0a971dbe2beb113c1c3e9ef103d77d5d8c7174a0
This commit is contained in:
Markus Mohrhard 2014-01-02 05:08:32 +01:00
parent 893a7fc4e4
commit 55656ee2e8
8 changed files with 146 additions and 88 deletions

View File

@ -45,7 +45,7 @@
#include <boost/shared_ptr.hpp>
#include <boost/ptr_container/ptr_vector.hpp>
#include <salhelper/thread.hxx>
#include <vcl/timer.hxx>
class SdrPage;
@ -68,13 +68,12 @@ struct TimeBasedInfo
TimeBasedInfo():
bTimeBased(false),
nFrame(0),
eMode(AUTOMATIC),
mpThread(NULL) {}
eMode(AUTOMATIC) {}
bool bTimeBased;
size_t nFrame;
TimeBasedMode eMode;
salhelper::Thread* mpThread;
Timer maTimer;
// only valid when we are in the time based mode
::std::vector< std::vector< VDataSeries* > > m_aDataSeriesList;
@ -220,6 +219,8 @@ private: //methods
, bool bUseFixedInnerSize
, const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape>& xDiagram_MarkHandles );
DECL_LINK( UpdateTimeBased, void* );
private: //member
::osl::Mutex m_aMutex;

View File

@ -21,21 +21,23 @@
#include "ServiceMacros.hxx"
#include "MutexContainer.hxx"
#include <comphelper/uno3.hxx>
#include <cppuhelper/implbase2.hxx>
#include <cppuhelper/implbase3.hxx>
#include <com/sun/star/chart2/data/XLabeledDataSequence2.hpp>
#include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/util/XCloneable.hpp>
#include <com/sun/star/uno/XComponentContext.hpp>
#include <com/sun/star/util/XModifyBroadcaster.hpp>
#include <com/sun/star/chart2/XTimeBased.hpp>
namespace chart
{
namespace impl
{
typedef cppu::WeakImplHelper2<
typedef cppu::WeakImplHelper3<
::com::sun::star::chart2::data::XLabeledDataSequence2,
com::sun::star::chart2::XTimeBased,
::com::sun::star::lang::XServiceInfo >
LabeledDataSequence_Base;
}
@ -77,6 +79,10 @@ protected:
const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::data::XDataSequence >& xSequence )
throw (::com::sun::star::uno::RuntimeException);
// XTimeBased
virtual sal_Bool switchToNext() throw (::com::sun::star::uno::RuntimeException);
virtual sal_Bool setToPointInTime(sal_Int32 nPoint) throw (::com::sun::star::uno::RuntimeException);
// ____ XCloneable ____
virtual ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloneable > SAL_CALL createClone()
throw (::com::sun::star::uno::RuntimeException);

View File

@ -1357,14 +1357,34 @@ bool ChartModel::isTimeBased() const
void ChartModel::setTimeBased(bool bTimeBased)
{
mbTimeBased = bTimeBased;
uno::Sequence<Reference< chart2::data::XLabeledDataSequence > >
xDataSequences = getDataSequences();
sal_Int32 n = xDataSequences.getLength();
for(sal_Int32 i = 0; i < n; ++i)
{
uno::Reference< chart2::XTimeBased > xTimeBased(xDataSequences[i]->getValues(), uno::UNO_QUERY);
SAL_WARN_IF(!xTimeBased.is(), "chart2", "does not support time based charting");
if(xTimeBased.is())
{
uno::Reference< beans::XPropertySet > xPropSet(xTimeBased, uno::UNO_QUERY_THROW);
xPropSet->setPropertyValue("TimeBased", uno::makeAny(bTimeBased));
}
}
}
void ChartModel::getNextTimePoint()
{
uno::Reference< chart2::XTimeBased > xTimeBased(getUsedData(), uno::UNO_QUERY);
uno::Sequence< Reference< chart2::data::XLabeledDataSequence > > xDataSequences = getDataSequences();
sal_Int32 n = xDataSequences.getLength();
for(sal_Int32 i = 0; i < n; ++i)
{
uno::Reference< chart2::XTimeBased > xTimeBased(xDataSequences[i]->getValues(), uno::UNO_QUERY);
SAL_WARN_IF(!xTimeBased.is(), "chart2", "does not support time based charting");
if(xTimeBased.is())
{
xTimeBased->switchToNext();
}
}
}
} // namespace chart

View File

@ -101,6 +101,37 @@ void SAL_CALL LabeledDataSequence::setLabel(
}
}
// XTimeBased
sal_Bool LabeledDataSequence::switchToNext()
throw (uno::RuntimeException)
{
uno::Reference< chart2::XTimeBased > xTimeBasedValues(m_xData, uno::UNO_QUERY);
if(xTimeBasedValues.is())
xTimeBasedValues->switchToNext();
uno::Reference< chart2::XTimeBased > xTimeBasedLabels(m_xLabel, uno::UNO_QUERY);
if(xTimeBasedLabels.is())
xTimeBasedLabels->switchToNext();
return sal_True;
}
sal_Bool LabeledDataSequence::setToPointInTime(sal_Int32 nPoint)
throw (uno::RuntimeException)
{
sal_Bool bRet = sal_False;
uno::Reference< chart2::XTimeBased > xTimeBasedValues(m_xData, uno::UNO_QUERY);
if(xTimeBasedValues.is())
bRet = xTimeBasedValues->setToPointInTime(nPoint);
uno::Reference< chart2::XTimeBased > xTimeBasedLabels(m_xLabel, uno::UNO_QUERY);
if(xTimeBasedLabels.is())
xTimeBasedLabels->setToPointInTime(nPoint);
return bRet;
}
// ____ XCloneable ____
uno::Reference< util::XCloneable > SAL_CALL LabeledDataSequence::createClone()
throw (uno::RuntimeException)

View File

@ -125,32 +125,6 @@ namespace
{
class theExplicitValueProviderUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theExplicitValueProviderUnoTunnelId > {};
class UpdateTimeBasedThread : public salhelper::Thread
{
public:
UpdateTimeBasedThread(ChartView& rChartView, TimeBasedInfo& rTimeBasedInfo):
salhelper::Thread("ChartUpdate"),
mrChartView(rChartView),
mrTimeBasedInfo(rTimeBasedInfo) {}
private:
virtual void execute()
{
TimeValue const aTime = { 0, 100 };
for(size_t i = 0; i < 60; ++i)
{
mrChartView.setViewDirty();
{
SolarMutexGuard aSolarGuard;
mrChartView.update();
}
wait(aTime);
}
}
ChartView& mrChartView;
TimeBasedInfo& mrTimeBasedInfo;
};
}
const uno::Sequence<sal_Int8>& ExplicitValueProvider::getUnoTunnelId()
@ -2404,13 +2378,6 @@ void ChartView::createShapes()
if(mrChartModel.isTimeBased())
{
maTimeBased.bTimeBased = true;
if(!maTimeBased.mpThread)
{
maTimeBased.mpThread = new UpdateTimeBasedThread(*this, maTimeBased);
maTimeBased.mpThread->launch();
}
}
//make sure add-in is refreshed after creating the shapes
@ -2606,7 +2573,7 @@ void ChartView::createShapes()
rSeriesPlotter[i]->getAllSeries();
std::vector< VDataSeries* >& rAllOldDataSeries =
maTimeBased.m_aDataSeriesList[i];
size_t m = std::min(aAllNewDataSeries.size(), rAllOldDataSeries.size());
size_t m = aAllNewDataSeries.size();
for(size_t j = 0; j < m; ++j)
{
rAllOldDataSeries.push_back( aAllNewDataSeries[j]->
@ -2614,7 +2581,17 @@ void ChartView::createShapes()
}
}
if(maTimeBased.eMode != MANUAL)
mrChartModel.getNextTimePoint();
else
maTimeBased.maTimer.Stop();
}
if(maTimeBased.bTimeBased && maTimeBased.eMode != MANUAL && !maTimeBased.maTimer.IsActive())
{
maTimeBased.maTimer.SetTimeout(15);
maTimeBased.maTimer.SetTimeoutHdl(LINK(this, ChartView, UpdateTimeBased));
maTimeBased.maTimer.Start();
}
}
@ -3055,6 +3032,14 @@ void ChartView::setViewDirty()
m_bViewDirty = true;
}
IMPL_LINK_NOARG(ChartView, UpdateTimeBased)
{
setViewDirty();
update();
return 0;
}
} //namespace chart
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View File

@ -21,6 +21,13 @@ interface XTimeBased : com::sun::star::uno::XInterface
* FALSE if the data wrapped around
*/
boolean switchToNext();
/**
* point is the zero based index into the time based array
*
* @return FALSE if the point is outside of the supported array
*/
boolean setToPointInTime( [in] long point );
};
}; }; }; };

View File

@ -42,7 +42,7 @@
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/util/XCloneable.hpp>
#include <com/sun/star/util/XModifyBroadcaster.hpp>
#include <cppuhelper/implbase3.hxx>
#include <cppuhelper/implbase2.hxx>
#include <cppuhelper/implbase5.hxx>
#include <cppuhelper/implbase8.hxx>
#include <rtl/ustring.hxx>
@ -190,9 +190,8 @@ private:
// DataSource
class ScChart2DataSource : public
::cppu::WeakImplHelper3<
::cppu::WeakImplHelper2<
::com::sun::star::chart2::data::XDataSource,
com::sun::star::chart2::XTimeBased,
::com::sun::star::lang::XServiceInfo>,
SfxListener
{
@ -207,10 +206,6 @@ public:
::com::sun::star::chart2::data::XLabeledDataSequence > > SAL_CALL
getDataSequences() throw (::com::sun::star::uno::RuntimeException);
// XTimeBased
virtual sal_Bool switchToNext() throw(
::com::sun::star::uno::RuntimeException);
// XServiceInfo
virtual OUString SAL_CALL getImplementationName() throw(
::com::sun::star::uno::RuntimeException);
@ -226,19 +221,12 @@ public:
void AddLabeledSequence(const com::sun::star::uno::Reference < com::sun::star::chart2::data::XLabeledDataSequence >& xNew);
void SetTimeBased(SCTAB nTimeBasedStart, SCTAB nTimeBasedEnd);
private:
ScDocument* m_pDocument;
typedef std::list < com::sun::star::uno::Reference< com::sun::star::chart2::data::XLabeledDataSequence > > LabeledList;
LabeledList m_aLabeledSequences;
bool bTimeBased;
SCTAB mnTimeBasedStart;
SCTAB mnTimeBasedEnd;
SCTAB mnCurrentTab;
};
// DataSequence
@ -292,6 +280,7 @@ public:
// XTimeBased
virtual sal_Bool switchToNext() throw (::com::sun::star::uno::RuntimeException);
virtual sal_Bool setToPointInTime(sal_Int32 nPoint) throw (::com::sun::star::uno::RuntimeException);
// XPropertySet
virtual ::com::sun::star::uno::Reference<
@ -475,6 +464,12 @@ private:
bool m_bGotDataChangedHint;
bool m_bExtDataRebuildQueued;
bool mbTimeBased;
SCTAB mnTimeBasedStart;
SCTAB mnTimeBasedEnd;
SCTAB mnCurrentTab;
};
#endif // SC_CHART2UNO_HXX

View File

@ -1579,8 +1579,6 @@ ScChart2DataProvider::createDataSource(
}
pDS = new ScChart2DataSource(m_pDocument);
if(bTimeBased)
pDS->SetTimeBased(nTimeBasedStart, nTimeBasedEnd);
::std::list< Reference< chart2::data::XLabeledDataSequence > >::iterator aItr( aSeqs.begin() );
::std::list< Reference< chart2::data::XLabeledDataSequence > >::iterator aEndItr( aSeqs.end() );
@ -2455,33 +2453,6 @@ void ScChart2DataSource::AddLabeledSequence(const uno::Reference < chart2::data:
m_aLabeledSequences.push_back(xNew);
}
sal_Bool ScChart2DataSource::switchToNext() throw ( uno::RuntimeException)
{
if(mnCurrentTab != mnTimeBasedEnd)
{
for(LabeledList::iterator itr = m_aLabeledSequences.begin(),
itrEnd = m_aLabeledSequences.end(); itr != itrEnd; ++itr)
{
uno::Reference< chart2::XTimeBased> xTimeBased(*itr, uno::UNO_QUERY);
if(xTimeBased.is())
xTimeBased->switchToNext();
}
++mnCurrentTab;
return sal_True;
}
return sal_False;
}
void ScChart2DataSource::SetTimeBased(SCTAB nTimeBasedStart, SCTAB nTimeBasedEnd)
{
mnCurrentTab = nTimeBasedStart;
mnTimeBasedStart = nTimeBasedStart;
mnTimeBasedEnd = nTimeBasedEnd;
bTimeBased = true;
}
// DataSequence ==============================================================
ScChart2DataSequence::Item::Item() :
@ -3528,6 +3499,12 @@ void SAL_CALL ScChart2DataSequence::setPropertyValue(
if( bOldValue != m_bIncludeHiddenCells )
m_aDataArray.clear();//data array is dirty now
}
else if( rPropertyName == "TimeBased" )
{
sal_Bool bTimeBased = mbTimeBased;
rValue>>= bTimeBased;
mbTimeBased = bTimeBased;
}
else
throw beans::UnknownPropertyException();
// TODO: support optional properties
@ -3552,6 +3529,10 @@ uno::Any SAL_CALL ScChart2DataSequence::getPropertyValue(const OUString& rProper
BuildDataCache();
aRet <<= m_aHiddenValues;
}
else if (rPropertyName == "TimeBased")
{
aRet <<= mbTimeBased;
}
else
throw beans::UnknownPropertyException();
// TODO: support optional properties
@ -3613,6 +3594,9 @@ sal_Bool ScChart2DataSequence::switchToNext()
if(!m_pTokens)
return sal_True;
if(mnCurrentTab >= mnTimeBasedEnd)
return false;
for(vector<ScTokenRef>::iterator itr = m_pTokens->begin(),
itrEnd = m_pTokens->end(); itr != itrEnd; ++itr)
{
@ -3632,4 +3616,33 @@ sal_Bool ScChart2DataSequence::switchToNext()
return sal_True;
}
sal_Bool ScChart2DataSequence::setToPointInTime(sal_Int32 nPoint)
throw (uno::RuntimeException)
{
if(!m_pTokens)
return sal_True;
if(nPoint > mnTimeBasedEnd - mnTimeBasedStart)
return false;
SCTAB nTab = mnTimeBasedStart + nPoint;
for(vector<ScTokenRef>::iterator itr = m_pTokens->begin(),
itrEnd = m_pTokens->end(); itr != itrEnd; ++itr)
{
if ((*itr)->GetType() != svDoubleRef)
continue;
ScComplexRefData& rData = (*itr)->GetDoubleRef();
ScSingleRefData& s = rData.Ref1;
ScSingleRefData& e = rData.Ref2;
s.SetAbsTab(nTab);
e.SetAbsTab(nTab);
}
RebuildDataCache();
return sal_True;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */