Commit a1349f8d authored by Sebastian Sauer's avatar Sebastian Sauer

Optimize chart-shape and made loading charts double as fast.

We compress multiple proxyModelStructureChanged() emitted during loading charts now into one single call at the end of the loading process what gives us a huge speed-up when loading charts.
With my test-document ( Harmattan-Columbus_SW_Maturity_Applications_Release-W19_10.xls ) loading all the charts in that Excel document is done more then double as fast now (before ~40-50ms per chart and after this patch ~10-20ms).
parent 1b361a3a
......@@ -858,6 +858,9 @@ void ChartProxyModel::invalidateDataSets()
void ChartProxyModel::beginLoading()
{
Q_ASSERT( !d->isLoading );
beginResetModel();
// FIXME: invalidateDataSets() used to be called explicitly at the beginning
// of ChartShape::loadOdf(). Now beginLoading() is called instead.
// So, is invalidateDataSets() still necessary here?
......@@ -873,6 +876,13 @@ void ChartProxyModel::endLoading()
// Doing this here is wrong, the data set's cell regions set in
// DataSet::loadOdf() would get overridden.
// d->rebuildDataMap();
endResetModel();
}
bool ChartProxyModel::isLoading() const
{
return d->isLoading;
}
void ChartProxyModel::setDataDirection( Qt::Orientation orientation )
......
......@@ -185,6 +185,12 @@ public:
*/
void endLoading();
/**
* Returns true if beginLoading() got called and endLoading() not
* yet what means we are in a longer loading process.
*/
bool isLoading() const;
public slots:
/**
* Connected to dataChanged() signal of source models in TableSource.
......
......@@ -902,6 +902,8 @@ bool ChartShape::loadEmbeddedDocument( KoStore *store,
bool ChartShape::loadOdf( const KoXmlElement &element,
KoShapeLoadingContext &context )
{
//struct Timer{QTime t;Timer(){t.start();} ~Timer(){qDebug()<<">>>>>"<<t.elapsed();}} timer;
// Load common attributes of (frame) shapes. If you change here,
// don't forget to also change in saveOdf().
loadOdfAttributes( element, context, OdfAllAttributes );
......@@ -925,7 +927,14 @@ bool ChartShape::loadOdfFrameElement( const KoXmlElement &element,
bool ChartShape::loadOdfChartElement( const KoXmlElement &chartElement,
KoShapeLoadingContext &context )
{
proxyModel()->beginLoading();
// Use a helper-class created on the stack to be sure a we always leave
// this method with a call to endLoading proxyModel()->endLoading()
struct ProxyModelLoadState {
ChartProxyModel *m;
ProxyModelLoadState(ChartProxyModel *m) : m(m) { m->beginLoading(); }
~ProxyModelLoadState() { m->endLoading(); }
};
ProxyModelLoadState proxyModelLoadState(proxyModel());
// The shared data will automatically be deleted in the destructor
// of KoShapeLoadingContext
......@@ -1003,7 +1012,6 @@ bool ChartShape::loadOdfChartElement( const KoXmlElement &chartElement,
return false;
}
// 2. Load the data
// int dimensions = numDimensions( chartType );
// qDebug() << "DIMENSIONS" << dimensions;
......@@ -1072,8 +1080,6 @@ bool ChartShape::loadOdfChartElement( const KoXmlElement &chartElement,
requestRepaint();
proxyModel()->endLoading();
return true;
}
......
......@@ -294,6 +294,9 @@ void PlotArea::plotAreaInit()
void PlotArea::proxyModelStructureChanged()
{
if (proxyModel()->isLoading())
return;
Q_ASSERT( xAxis() );
Q_ASSERT( yAxis() );
QMap<DataSet*, Axis*> attachedAxes;
......
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