[Libreoffice-commits] core.git: sc/source
Markus Mohrhard
markus.mohrhard at googlemail.com
Wed Aug 9 12:53:56 UTC 2017
sc/source/ui/docshell/dataprovider.cxx | 44 +++++++++++++++++++++------------
sc/source/ui/inc/dataprovider.hxx | 9 ++++++
2 files changed, 37 insertions(+), 16 deletions(-)
New commits:
commit d7e92ad0c828a237b16c4643a457c9bd41da6eff
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date: Wed Aug 9 13:59:42 2017 +0200
external data: separate parsing with import and copying to final doc
We now use an Idle handler that will copy the data to the final document
after the import.
Change-Id: Ic4693dd928bc575775f28f2d0b896b3f31050062
Reviewed-on: https://gerrit.libreoffice.org/40918
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Markus Mohrhard <markus.mohrhard at googlemail.com>
diff --git a/sc/source/ui/docshell/dataprovider.cxx b/sc/source/ui/docshell/dataprovider.cxx
index 0f39adca5b20..2ce549156146 100644
--- a/sc/source/ui/docshell/dataprovider.cxx
+++ b/sc/source/ui/docshell/dataprovider.cxx
@@ -209,11 +209,12 @@ public:
}
};
-CSVFetchThread::CSVFetchThread(ScDocument& rDoc, const OUString& mrURL):
+CSVFetchThread::CSVFetchThread(ScDocument& rDoc, const OUString& mrURL, Idle* pIdle):
Thread("CSV Fetch Thread"),
mrDocument(rDoc),
maURL (mrURL),
- mbTerminate(false)
+ mbTerminate(false),
+ mpIdle(pIdle)
{
maConfig.delimiters.push_back(',');
maConfig.text_qualifier = '"';
@@ -252,7 +253,7 @@ void CSVFetchThread::execute()
for (Line & rLine : aLines)
{
if (mbTerminate)
- return;
+ break;
rLine.maCells.clear();
pStream->ReadLine(rLine.maLine);
@@ -262,7 +263,7 @@ void CSVFetchThread::execute()
if (rLine.maCells.empty())
{
- return;
+ break;
}
nCol = 0;
@@ -282,6 +283,8 @@ void CSVFetchThread::execute()
nCurRow++;
}
}
+ SolarMutexGuard aGuard;
+ mpIdle->Start();
}
osl::Mutex& CSVFetchThread::GetLinesMutex()
@@ -317,34 +320,43 @@ CSVDataProvider::CSVDataProvider(ScDocument* pDoc, const OUString& rURL, ScDBDat
mpDocument(pDoc),
mpDBDataManager(pBDDataManager),
mpLines(nullptr),
- mnLineCount(0)
+ mnLineCount(0),
+ maIdle("CSVDataProvider CopyHandler")
{
+ maIdle.SetInvokeHandler(LINK(this, CSVDataProvider, ImportFinishedHdl));
}
CSVDataProvider::~CSVDataProvider()
{
-}
-
-void CSVDataProvider::Import()
-{
- ScDocument aDoc(SCDOCMODE_CLIP);
- aDoc.ResetClip(mpDocument, (SCTAB)0);
- mxCSVFetchThread = new CSVFetchThread(aDoc, maURL);
- mxCSVFetchThread->launch();
if (mxCSVFetchThread.is())
{
mxCSVFetchThread->join();
}
+}
+
+void CSVDataProvider::Import()
+{
+ // already importing data
+ if (mpDoc)
+ return;
- WriteToDoc(aDoc, mpDBDataManager->getDBData());
+ mpDoc.reset(new ScDocument(SCDOCMODE_CLIP));
+ mpDoc->ResetClip(mpDocument, (SCTAB)0);
+ mxCSVFetchThread = new CSVFetchThread(*mpDoc, maURL, &maIdle);
+ mxCSVFetchThread->launch();
+}
+IMPL_LINK_NOARG(CSVDataProvider, ImportFinishedHdl, Timer*, void)
+{
+ WriteToDoc(*mpDoc, mpDBDataManager->getDBData());
+ mxCSVFetchThread.clear();
+ mpDoc.reset();
Refresh();
}
void CSVDataProvider::Refresh()
{
ScDocShell* pDocShell = static_cast<ScDocShell*>(mpDocument->GetDocumentShell());
- pDocShell->DoHardRecalc();
pDocShell->SetDocumentModified();
}
@@ -401,6 +413,8 @@ void CSVDataProvider::WriteToDoc(ScDocument& rDoc, ScDBData* pDBData)
}
}
}
+ ScDocShell* pDocShell = static_cast<ScDocShell*>(mpDocument->GetDocumentShell());
+ pDocShell->PostPaint(aDestRange, PaintPartFlags::All);
}
ScDBDataManager::ScDBDataManager(ScDBData* pDBData, bool /*bAllowResize*/):
diff --git a/sc/source/ui/inc/dataprovider.hxx b/sc/source/ui/inc/dataprovider.hxx
index 7f50b2ddbc5f..b0a3b5d58273 100644
--- a/sc/source/ui/inc/dataprovider.hxx
+++ b/sc/source/ui/inc/dataprovider.hxx
@@ -20,6 +20,7 @@
#include <osl/conditn.hxx>
#include <dbdata.hxx>
#include <document.hxx>
+#include <vcl/idle.hxx>
#include "docsh.hxx"
#include "scdllapi.h"
@@ -84,9 +85,11 @@ class CSVFetchThread : public salhelper::Thread
orcus::csv::parser_config maConfig;
+ Idle* mpIdle;
+
public:
- CSVFetchThread(ScDocument& rDoc, const OUString&);
+ CSVFetchThread(ScDocument& rDoc, const OUString&, Idle* pIdle);
virtual ~CSVFetchThread() override;
void RequestTerminate();
@@ -126,6 +129,8 @@ class CSVDataProvider : public DataProvider
ScDBDataManager* mpDBDataManager;
LinesType* mpLines;
size_t mnLineCount;
+ std::unique_ptr<ScDocument> mpDoc;
+ Idle maIdle;
void Refresh();
Line GetLine();
@@ -139,6 +144,8 @@ public:
// TODO: this method should be moved to the ScDBDataManager
virtual void WriteToDoc(ScDocument& rDoc, ScDBData* pDBData) override;
const OUString& GetURL() const override { return maURL; }
+
+ DECL_LINK( ImportFinishedHdl, Timer*, void );
};
More information about the Libreoffice-commits
mailing list