summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
Diffstat (limited to 'sc')
-rw-r--r--sc/inc/datamapper.hxx9
-rw-r--r--sc/source/ui/dataprovider/csvdataprovider.cxx30
-rw-r--r--sc/source/ui/dataprovider/dataprovider.cxx63
-rw-r--r--sc/source/ui/dataprovider/htmldataprovider.cxx34
-rw-r--r--sc/source/ui/dataprovider/htmldataprovider.hxx8
-rw-r--r--sc/source/ui/inc/dataprovider.hxx23
6 files changed, 90 insertions, 77 deletions
diff --git a/sc/inc/datamapper.hxx b/sc/inc/datamapper.hxx
index f872f50143b8..b935e2ac36cc 100644
--- a/sc/inc/datamapper.hxx
+++ b/sc/inc/datamapper.hxx
@@ -25,6 +25,7 @@ namespace sc {
class ScDBDataManager;
class DataProvider;
class ScDBDataManager;
+class DataTransformation;
class SC_DLLPUBLIC ExternalDataSource
{
@@ -67,6 +68,8 @@ private:
std::shared_ptr<DataProvider> mpDataProvider;
std::shared_ptr<ScDBDataManager> mpDBDataManager;
+ std::vector<std::shared_ptr<sc::DataTransformation>> maDataTransformations;
+
ScDocument* mpDoc;
public:
@@ -79,6 +82,8 @@ public:
void setUpdateFrequency(double nUpdateFrequency);
void setID(const OUString& rID);
+ void setURL(const OUString& rURL);
+ void setProvider(const OUString& rProvider);
const OUString& getURL() const;
const OUString& getProvider() const;
@@ -86,8 +91,12 @@ public:
double getUpdateFrequency() const;
OUString getDBName() const;
void setDBData(const ScDBData* pDBData);
+ ScDBDataManager* getDBManager();
void refresh(ScDocument* pDoc, bool bDeterministic = false);
+
+ void AddDataTransformation(std::shared_ptr<sc::DataTransformation> mpDataTransformation);
+ const std::vector<std::shared_ptr<sc::DataTransformation>>& getDataTransformation() const;
};
class SC_DLLPUBLIC ExternalDataMapper
diff --git a/sc/source/ui/dataprovider/csvdataprovider.cxx b/sc/source/ui/dataprovider/csvdataprovider.cxx
index ed7302209896..28877c247b42 100644
--- a/sc/source/ui/dataprovider/csvdataprovider.cxx
+++ b/sc/source/ui/dataprovider/csvdataprovider.cxx
@@ -65,14 +65,14 @@ public:
namespace sc {
-CSVFetchThread::CSVFetchThread(ScDocument& rDoc, const OUString& mrURL, Idle* pIdle,
+CSVFetchThread::CSVFetchThread(ScDocument& rDoc, const OUString& mrURL, std::function<void()> aImportFinishedHdl,
const std::vector<std::shared_ptr<sc::DataTransformation>>& rDataTransformations):
Thread("CSV Fetch Thread"),
mrDocument(rDoc),
maURL (mrURL),
mbTerminate(false),
maDataTransformations(rDataTransformations),
- mpIdle(pIdle)
+ maImportFinishedHdl(aImportFinishedHdl)
{
maConfig.delimiters.push_back(',');
maConfig.text_qualifier = '"';
@@ -116,16 +116,13 @@ void CSVFetchThread::execute()
}
SolarMutexGuard aGuard;
- mpIdle->Start();
+ maImportFinishedHdl();
}
-CSVDataProvider::CSVDataProvider(ScDocument* pDoc, const OUString& rURL, ScDBDataManager* pBDDataManager):
- maURL(rURL),
- mpDocument(pDoc),
- mpDBDataManager(pBDDataManager),
- maIdle("CSVDataProvider CopyHandler")
+CSVDataProvider::CSVDataProvider(ScDocument* pDoc, sc::ExternalDataSource& rDataSource):
+ DataProvider(rDataSource),
+ mpDocument(pDoc)
{
- maIdle.SetInvokeHandler(LINK(this, CSVDataProvider, ImportFinishedHdl));
}
CSVDataProvider::~CSVDataProvider()
@@ -145,7 +142,7 @@ void CSVDataProvider::Import()
mpDoc.reset(new ScDocument(SCDOCMODE_CLIP));
mpDoc->ResetClip(mpDocument, (SCTAB)0);
- mxCSVFetchThread = new CSVFetchThread(*mpDoc, maURL, &maIdle, mpDBDataManager->getDataTransformation());
+ mxCSVFetchThread = new CSVFetchThread(*mpDoc, mrDataSource.getURL(), std::bind(&CSVDataProvider::ImportFinished, this), mrDataSource.getDataTransformation());
mxCSVFetchThread->launch();
if (mbDeterministic)
@@ -155,10 +152,9 @@ void CSVDataProvider::Import()
}
}
-IMPL_LINK_NOARG(CSVDataProvider, ImportFinishedHdl, Timer*, void)
+void CSVDataProvider::ImportFinished()
{
- mpDBDataManager->WriteToDoc(*mpDoc);
- mxCSVFetchThread.clear();
+ mrDataSource.getDBManager()->WriteToDoc(*mpDoc);
mpDoc.reset();
Refresh();
}
@@ -166,7 +162,13 @@ IMPL_LINK_NOARG(CSVDataProvider, ImportFinishedHdl, Timer*, void)
void CSVDataProvider::Refresh()
{
ScDocShell* pDocShell = static_cast<ScDocShell*>(mpDocument->GetDocumentShell());
- pDocShell->SetDocumentModified();
+ if (pDocShell)
+ pDocShell->SetDocumentModified();
+}
+
+const OUString& CSVDataProvider::GetURL() const
+{
+ return mrDataSource.getURL();
}
}
diff --git a/sc/source/ui/dataprovider/dataprovider.cxx b/sc/source/ui/dataprovider/dataprovider.cxx
index 924b3f109a30..d07edb78958c 100644
--- a/sc/source/ui/dataprovider/dataprovider.cxx
+++ b/sc/source/ui/dataprovider/dataprovider.cxx
@@ -74,6 +74,17 @@ void ExternalDataSource::setID(const OUString& rID)
maID = rID;
}
+void ExternalDataSource::setURL(const OUString& rURL)
+{
+ maURL = rURL;
+}
+
+void ExternalDataSource::setProvider(const OUString& rProvider)
+{
+ maProvider = rProvider;
+ mpDataProvider.reset();
+}
+
const OUString& ExternalDataSource::getURL() const
{
return maURL;
@@ -117,6 +128,11 @@ double ExternalDataSource::getUpdateFrequency() const
return mnUpdateFrequency;
}
+ScDBDataManager* ExternalDataSource::getDBManager()
+{
+ return mpDBDataManager.get();
+}
+
void ExternalDataSource::refresh(ScDocument* pDoc, bool bDeterministic)
{
// no DB data available
@@ -125,7 +141,7 @@ void ExternalDataSource::refresh(ScDocument* pDoc, bool bDeterministic)
// if no data provider exists, try to create one
if (!mpDataProvider)
- mpDataProvider = DataProviderFactory::getDataProvider(pDoc, maProvider, maURL, maID, mpDBDataManager.get());
+ mpDataProvider = DataProviderFactory::getDataProvider(pDoc, *this);
// if we still have not been able to create one, we can not refresh the data
if (!mpDataProvider)
@@ -137,6 +153,16 @@ void ExternalDataSource::refresh(ScDocument* pDoc, bool bDeterministic)
mpDataProvider->Import();
}
+void ExternalDataSource::AddDataTransformation(std::shared_ptr<sc::DataTransformation> mpDataTransformation)
+{
+ maDataTransformations.push_back(mpDataTransformation);
+}
+
+const std::vector<std::shared_ptr<sc::DataTransformation>>& ExternalDataSource::getDataTransformation() const
+{
+ return maDataTransformations;
+}
+
ExternalDataMapper::ExternalDataMapper(ScDocument* /*pDoc*/)
//mpDoc(pDoc)
{
@@ -161,8 +187,9 @@ std::vector<sc::ExternalDataSource>& ExternalDataMapper::getDataSources()
return maDataSources;
}
-DataProvider::DataProvider():
- mbDeterministic(false)
+DataProvider::DataProvider(sc::ExternalDataSource& rDataSource):
+ mbDeterministic(false),
+ mrDataSource(rDataSource)
{
}
@@ -198,14 +225,15 @@ void ScDBDataManager::WriteToDoc(ScDocument& rDoc)
SCCOL nColSize = std::min<SCCOL>(aDestRange.aEnd.Col() - aDestRange.aStart.Col(), nEndCol);
aDestRange.aEnd.SetCol(aDestRange.aStart.Col() + nColSize);
- SCROW nRowSize = std::min<SCCOL>(aDestRange.aEnd.Row() - aDestRange.aStart.Row(), nEndRow);
+ SCROW nRowSize = std::min<SCROW>(aDestRange.aEnd.Row() - aDestRange.aStart.Row(), nEndRow);
aDestRange.aEnd.SetRow(aDestRange.aStart.Row() + nRowSize);
ScMarkData aMark;
aMark.SelectTable(0, true);
mpDoc->CopyFromClip(aDestRange, aMark, InsertDeleteFlags::CONTENTS, nullptr, &rDoc);
ScDocShell* pDocShell = static_cast<ScDocShell*>(mpDoc->GetDocumentShell());
- pDocShell->PostPaint(aDestRange, PaintPartFlags::All);
+ if (pDocShell)
+ pDocShell->PostPaint(aDestRange, PaintPartFlags::All);
}
ScDBDataManager::ScDBDataManager(const OUString& rDBName, bool /*bAllowResize*/, ScDocument* pDoc):
@@ -224,16 +252,6 @@ void ScDBDataManager::SetDatabase(const OUString& rDBName)
maDBName = rDBName;
}
-void ScDBDataManager::AddDataTransformation(std::shared_ptr<sc::DataTransformation> mpDataTransformation)
-{
- maDataTransformations.push_back(std::move(mpDataTransformation));
-}
-
-const std::vector<std::shared_ptr<sc::DataTransformation>>& ScDBDataManager::getDataTransformation() const
-{
- return maDataTransformations;
-}
-
ScDBData* ScDBDataManager::getDBData()
{
ScDBData* pDBData = mpDoc->GetDBCollection()->getNamedDBs().findByUpperName(ScGlobal::pCharClass->uppercase(maDBName));
@@ -245,16 +263,17 @@ bool DataProviderFactory::isInternalDataProvider(const OUString& rProvider)
return rProvider.startsWith("org.libreoffice.calc");
}
-std::shared_ptr<DataProvider> DataProviderFactory::getDataProvider(ScDocument* pDoc, const OUString& rProvider,
- const OUString& rURL, const OUString& rID, ScDBDataManager* pManager)
+std::shared_ptr<DataProvider> DataProviderFactory::getDataProvider(ScDocument* pDoc,
+ sc::ExternalDataSource& rDataSource)
{
- bool bInternal = DataProviderFactory::isInternalDataProvider(rProvider);
+ const OUString& rDataProvider = rDataSource.getProvider();
+ bool bInternal = DataProviderFactory::isInternalDataProvider(rDataProvider);
if (bInternal)
{
- if (rProvider == "org.libreoffice.calc.csv")
- return std::shared_ptr<DataProvider>(new CSVDataProvider(pDoc, rURL, pManager));
- else if (rProvider == "org.libreoffice.calc.html")
- return std::shared_ptr<DataProvider>(new HTMLDataProvider(pDoc, rURL, pManager, rID));
+ if (rDataProvider == "org.libreoffice.calc.csv")
+ return std::shared_ptr<DataProvider>(new CSVDataProvider(pDoc, rDataSource));
+ else if (rDataProvider == "org.libreoffice.calc.html")
+ return std::shared_ptr<DataProvider>(new HTMLDataProvider(pDoc, rDataSource));
}
else
{
diff --git a/sc/source/ui/dataprovider/htmldataprovider.cxx b/sc/source/ui/dataprovider/htmldataprovider.cxx
index 090d6d73721f..890faf7d6bd0 100644
--- a/sc/source/ui/dataprovider/htmldataprovider.cxx
+++ b/sc/source/ui/dataprovider/htmldataprovider.cxx
@@ -27,8 +27,7 @@ class HTMLFetchThread : public salhelper::Thread
OUString maURL;
OUString maID;
const std::vector<std::shared_ptr<sc::DataTransformation>> maDataTransformations;
-
- Idle* mpIdle;
+ std::function<void()> maImportFinishedHdl;
void handleTable(xmlNodePtr pTable);
void handleRow(xmlNodePtr pRow, SCROW nRow);
@@ -36,20 +35,20 @@ class HTMLFetchThread : public salhelper::Thread
void handleCell(xmlNodePtr pCell, SCROW nRow, SCCOL nCol);
public:
- HTMLFetchThread(ScDocument& rDoc, const OUString&, const OUString& rID, Idle* pIdle,
+ HTMLFetchThread(ScDocument& rDoc, const OUString&, const OUString& rID, std::function<void()> aImportFinishedHdl,
const std::vector<std::shared_ptr<sc::DataTransformation>>& rTransformations);
virtual void execute() override;
};
-HTMLFetchThread::HTMLFetchThread(ScDocument& rDoc, const OUString& rURL, const OUString& rID, Idle* pIdle,
+HTMLFetchThread::HTMLFetchThread(ScDocument& rDoc, const OUString& rURL, const OUString& rID, std::function<void()> aImportFinishedHdl,
const std::vector<std::shared_ptr<sc::DataTransformation>>& rTransformations):
salhelper::Thread("HTML Fetch Thread"),
mrDocument(rDoc),
maURL(rURL),
maID(rID),
maDataTransformations(rTransformations),
- mpIdle(pIdle)
+ maImportFinishedHdl(aImportFinishedHdl)
{
}
@@ -207,18 +206,13 @@ void HTMLFetchThread::execute()
}
SolarMutexGuard aGuard;
- mpIdle->Start();
+ maImportFinishedHdl();
}
-HTMLDataProvider::HTMLDataProvider(ScDocument* pDoc, const OUString& rURL, ScDBDataManager* pDBManager,
- const OUString& rID):
- maID(rID),
- maURL(rURL),
- mpDocument(pDoc),
- mpDBDataManager(pDBManager),
- maIdle("HTMLDataProvider CopyHandler")
+HTMLDataProvider::HTMLDataProvider(ScDocument* pDoc, sc::ExternalDataSource& rDataSource):
+ DataProvider(rDataSource),
+ mpDocument(pDoc)
{
- maIdle.SetInvokeHandler(LINK(this, HTMLDataProvider, ImportFinishedHdl));
}
HTMLDataProvider::~HTMLDataProvider()
@@ -238,8 +232,8 @@ void HTMLDataProvider::Import()
mpDoc.reset(new ScDocument(SCDOCMODE_CLIP));
mpDoc->ResetClip(mpDocument, (SCTAB)0);
- mxHTMLFetchThread = new HTMLFetchThread(*mpDoc, maURL, maID, &maIdle,
- mpDBDataManager->getDataTransformation());
+ mxHTMLFetchThread = new HTMLFetchThread(*mpDoc, mrDataSource.getURL(), mrDataSource.getID(),
+ std::bind(&HTMLDataProvider::ImportFinished, this), mrDataSource.getDataTransformation());
mxHTMLFetchThread->launch();
if (mbDeterministic)
@@ -254,7 +248,7 @@ std::map<OUString, OUString> HTMLDataProvider::getDataSourcesForURL(const OUStri
std::map<OUString, OUString> aMap;
OStringBuffer aBuffer(64000);
- std::unique_ptr<SvStream> pStream = DataProvider::FetchStreamFromURL(maURL, aBuffer);
+ std::unique_ptr<SvStream> pStream = DataProvider::FetchStreamFromURL(mrDataSource.getURL(), aBuffer);
if (aBuffer.isEmpty())
return std::map<OUString, OUString>();
@@ -280,16 +274,16 @@ std::map<OUString, OUString> HTMLDataProvider::getDataSourcesForURL(const OUStri
return aMap;
}
-IMPL_LINK_NOARG(HTMLDataProvider, ImportFinishedHdl, Timer*, void)
+void HTMLDataProvider::ImportFinished()
{
- mpDBDataManager->WriteToDoc(*mpDoc);
+ mrDataSource.getDBManager()->WriteToDoc(*mpDoc);
mxHTMLFetchThread.clear();
mpDoc.reset();
}
const OUString& HTMLDataProvider::GetURL() const
{
- return maURL;
+ return mrDataSource.getURL();
}
}
diff --git a/sc/source/ui/dataprovider/htmldataprovider.hxx b/sc/source/ui/dataprovider/htmldataprovider.hxx
index 95bf9e0b3d36..69398632846f 100644
--- a/sc/source/ui/dataprovider/htmldataprovider.hxx
+++ b/sc/source/ui/dataprovider/htmldataprovider.hxx
@@ -21,18 +21,14 @@ class HTMLDataProvider : public DataProvider
{
private:
- OUString maID;
- OUString maURL;
ScDocument* mpDocument;
- ScDBDataManager* mpDBDataManager;
rtl::Reference<HTMLFetchThread> mxHTMLFetchThread;
std::unique_ptr<ScDocument> mpDoc;
- Idle maIdle;
public:
- HTMLDataProvider(ScDocument* pDoc, const OUString& rURL, ScDBDataManager* pDBManager, const OUString& rID);
+ HTMLDataProvider(ScDocument* pDoc, sc::ExternalDataSource& rDataSource);
virtual ~HTMLDataProvider() override;
virtual void Import() override;
@@ -41,7 +37,7 @@ public:
virtual std::map<OUString, OUString> getDataSourcesForURL(const OUString& rURL) override;
- DECL_LINK( ImportFinishedHdl, Timer*, void );
+ void ImportFinished();
};
}
diff --git a/sc/source/ui/inc/dataprovider.hxx b/sc/source/ui/inc/dataprovider.hxx
index df70c4099d2c..30e871ee6b0c 100644
--- a/sc/source/ui/inc/dataprovider.hxx
+++ b/sc/source/ui/inc/dataprovider.hxx
@@ -60,11 +60,11 @@ class CSVFetchThread : public salhelper::Thread
std::vector<std::shared_ptr<sc::DataTransformation>> maDataTransformations;
- Idle* mpIdle;
+ std::function<void()> maImportFinishedHdl;
public:
- CSVFetchThread(ScDocument& rDoc, const OUString&, Idle* pIdle,
+ CSVFetchThread(ScDocument& rDoc, const OUString&, std::function<void()> aImportFinishedHdl,
const std::vector<std::shared_ptr<sc::DataTransformation>>& mrDataTransformations);
virtual ~CSVFetchThread() override;
@@ -87,9 +87,10 @@ protected:
* If true make the threaded import deterministic for the tests.
*/
bool mbDeterministic;
+ sc::ExternalDataSource& mrDataSource;
public:
- DataProvider();
+ DataProvider(sc::ExternalDataSource& rDataSource);
virtual ~DataProvider();
@@ -106,23 +107,20 @@ public:
class CSVDataProvider : public DataProvider
{
- OUString maURL;
rtl::Reference<CSVFetchThread> mxCSVFetchThread;
ScDocument* mpDocument;
- ScDBDataManager* mpDBDataManager;
std::unique_ptr<ScDocument> mpDoc;
- Idle maIdle;
void Refresh();
public:
- CSVDataProvider (ScDocument* pDoc, const OUString& rURL, ScDBDataManager* pDBManager);
+ CSVDataProvider (ScDocument* pDoc, sc::ExternalDataSource& rDataSource);
virtual ~CSVDataProvider() override;
virtual void Import() override;
- const OUString& GetURL() const override { return maURL; }
- DECL_LINK( ImportFinishedHdl, Timer*, void );
+ const OUString& GetURL() const override;
+ void ImportFinished();
};
/**
@@ -140,17 +138,12 @@ class ScDBDataManager
OUString maDBName;
ScDocument* mpDoc;
- std::vector<std::shared_ptr<sc::DataTransformation>> maDataTransformations;
-
public:
ScDBDataManager(const OUString& rDBName, bool bAllowResize, ScDocument* pDoc);
~ScDBDataManager();
void SetDatabase(const OUString& rDBName);
- void AddDataTransformation(std::shared_ptr<sc::DataTransformation> mpDataTransformation);
- const std::vector<std::shared_ptr<sc::DataTransformation>>& getDataTransformation() const;
-
ScDBData* getDBData();
void WriteToDoc(ScDocument& rDoc);
@@ -164,7 +157,7 @@ private:
public:
- static std::shared_ptr<DataProvider> getDataProvider(ScDocument* pDoc, const OUString& rProvider, const OUString& rURL, const OUString& rID, ScDBDataManager* pManager);
+ static std::shared_ptr<DataProvider> getDataProvider(ScDocument* pDoc, sc::ExternalDataSource& rDataSource);
static std::vector<OUString> getDataProviders();
};