[Libreoffice-commits] core.git: 5 commits - sc/inc sc/source
Kohei Yoshida
kohei.yoshida at collabora.com
Wed Dec 18 15:15:13 PST 2013
sc/inc/document.hxx | 3
sc/source/core/data/documen7.cxx | 28 -----
sc/source/ui/docshell/datastream.cxx | 155 ++++++++++++++++++--------------
sc/source/ui/inc/datastream.hxx | 10 +-
sc/source/ui/inc/datastreamdlg.hxx | 1
sc/source/ui/miscdlgs/datastreamdlg.cxx | 3
6 files changed, 101 insertions(+), 99 deletions(-)
New commits:
commit 12a0bf110bca1f4365a254a09ebf8761ce222865
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date: Wed Dec 18 17:48:59 2013 -0500
We don't need these yet.
Change-Id: Iff875a690f319eb92ccfb8010853714ac60dcc9a
diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx
index 61dd1bd..74d9cd1 100644
--- a/sc/inc/document.hxx
+++ b/sc/inc/document.hxx
@@ -1818,9 +1818,6 @@ public:
*/
void Broadcast( const ScHint& rHint );
- void BroadcastCells( const ScRange& rRange, sal_uLong nHint );
- void BroadcastCells( const ScRangeList& rRanges, sal_uLong nHint );
-
/// only area, no cell broadcast
void AreaBroadcast( const ScHint& rHint );
/// only areas in range, no cell broadcasts
diff --git a/sc/source/core/data/documen7.cxx b/sc/source/core/data/documen7.cxx
index ec2e1cf..b8f691b 100644
--- a/sc/source/core/data/documen7.cxx
+++ b/sc/source/core/data/documen7.cxx
@@ -104,34 +104,6 @@ void ScDocument::Broadcast( const ScHint& rHint )
}
}
-void ScDocument::BroadcastCells( const ScRange& rRange, sal_uLong nHint )
-{
- // TODO : For now, this simply makes multiple Broadcast() calls one cell
- // at a time. In the future, we should add a more efficient way to
- // make a range of cell broadcasts.
-
- ScHint aHint(nHint, rRange.aStart);
-
- for (SCCOL nCol = rRange.aStart.Col(); nCol <= rRange.aEnd.Col(); ++nCol)
- {
- for (SCROW nRow = rRange.aStart.Row(); nRow <= rRange.aEnd.Row(); ++nRow)
- {
- aHint.GetAddress().SetCol(nCol);
- aHint.GetAddress().SetRow(nRow);
- Broadcast(aHint);
- }
- }
-}
-
-void ScDocument::BroadcastCells( const ScRangeList& rRanges, sal_uLong nHint )
-{
- for (size_t i = 0, n = rRanges.size(); i < n; ++i)
- {
- const ScRange* p = rRanges[i];
- BroadcastCells(*p, nHint);
- }
-}
-
void ScDocument::AreaBroadcast( const ScHint& rHint )
{
if ( !pBASM )
commit d5452cef5f8c40fbb9da9e91c6606d525c98bfd3
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date: Wed Dec 18 16:40:36 2013 -0500
Don't forget to set document modified afterward.
Change-Id: I5b2b9a3dad2aeee6bc5a4a4767b239c92865b2f4
diff --git a/sc/source/ui/docshell/datastream.cxx b/sc/source/ui/docshell/datastream.cxx
index e9b49d8..c506ee4 100644
--- a/sc/source/ui/docshell/datastream.cxx
+++ b/sc/source/ui/docshell/datastream.cxx
@@ -392,6 +392,7 @@ void DataStream::Refresh()
{
// Hard recalc will repaint the grid area.
mpDocShell->DoHardRecalc(true);
+ mpDocShell->SetDocumentModified(true);
mfLastRefreshTime = getNow();
mnLinesSinceRefresh = 0;
commit df57f73ff7cfa8a23537d9aa9f50aca1ca7664de
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date: Wed Dec 18 16:19:05 2013 -0500
Handle "refresh on empty line" setting from the UI.
With this set, when we detect an empty line, we'll trigger refresh and
discard the line. If not set, we'll import an empty line.
Change-Id: Ic3ccb1adbd0c7273c3affff82a2d111c378f2af3
diff --git a/sc/source/ui/docshell/datastream.cxx b/sc/source/ui/docshell/datastream.cxx
index f9686ae..e9b49d8 100644
--- a/sc/source/ui/docshell/datastream.cxx
+++ b/sc/source/ui/docshell/datastream.cxx
@@ -251,6 +251,8 @@ DataStream::DataStream(ScDocShell *pShell, const OUString& rURL, const ScRange&
maDocAccess(*mpDoc),
meMove(NO_MOVE),
mbRunning(false),
+ mbValuesInLine(false),
+ mbRefreshOnEmptyLine(false),
mpLines(0),
mnLinesCount(0),
mnLinesSinceRefresh(0),
@@ -381,6 +383,11 @@ void DataStream::StopImport()
Refresh();
}
+void DataStream::SetRefreshOnEmptyLine( bool bVal )
+{
+ mbRefreshOnEmptyLine = bVal;
+}
+
void DataStream::Refresh()
{
// Hard recalc will repaint the grid area.
@@ -437,18 +444,38 @@ IMPL_LINK_NOARG(DataStream, RefreshHdl)
namespace {
+struct StrVal
+{
+ ScAddress maPos;
+ OUString maStr;
+
+ StrVal( const ScAddress& rPos, const OUString& rStr ) : maPos(rPos), maStr(rStr) {}
+};
+
+struct NumVal
+{
+ ScAddress maPos;
+ double mfVal;
+
+ NumVal( const ScAddress& rPos, double fVal ) : maPos(rPos), mfVal(fVal) {}
+};
+
+typedef std::vector<StrVal> StrValArray;
+typedef std::vector<NumVal> NumValArray;
+
/**
* This handler handles a single line CSV input.
*/
class CSVHandler
{
- DocumentStreamAccess& mrDoc;
ScAddress maPos;
SCCOL mnEndCol;
+ StrValArray maStrs;
+ NumValArray maNums;
+
public:
- CSVHandler( DocumentStreamAccess& rDoc, const ScAddress& rPos, SCCOL nEndCol ) :
- mrDoc(rDoc), maPos(rPos), mnEndCol(nEndCol) {}
+ CSVHandler( const ScAddress& rPos, SCCOL nEndCol ) : maPos(rPos), mnEndCol(nEndCol) {}
void begin_parse() {}
void end_parse() {}
@@ -462,12 +489,15 @@ public:
OUString aStr(p, n, RTL_TEXTENCODING_UTF8);
double fVal;
if (ScStringUtil::parseSimpleNumber(aStr, '.', ',', fVal))
- mrDoc.setNumericCell(maPos, fVal);
+ maNums.push_back(NumVal(maPos, fVal));
else
- mrDoc.setStringCell(maPos, aStr);
+ maStrs.push_back(StrVal(maPos, aStr));
}
maPos.IncCol();
}
+
+ const StrValArray& getStrs() const { return maStrs; }
+ const NumValArray& getNums() const { return maNums; }
};
}
@@ -478,61 +508,34 @@ void DataStream::Text2Doc()
orcus::csv_parser_config aConfig;
aConfig.delimiters.push_back(',');
aConfig.text_qualifier = '"';
- CSVHandler aHdl(maDocAccess, ScAddress(maStartRange.aStart.Col(), mnCurRow, maStartRange.aStart.Tab()), maStartRange.aEnd.Col());
+ CSVHandler aHdl(ScAddress(maStartRange.aStart.Col(), mnCurRow, maStartRange.aStart.Tab()), maStartRange.aEnd.Col());
orcus::csv_parser<CSVHandler> parser(aLine.getStr(), aLine.getLength(), aHdl, aConfig);
parser.parse();
- ++mnLinesSinceRefresh;
-}
-
-#else
-
-void DataStream::Text2Doc() {}
-
-#endif
-
-bool DataStream::ImportData()
-{
- SolarMutexGuard aGuard;
- if (ScDocShell::GetViewData()->GetViewShell()->NeedsRepaint())
- return mbRunning;
+ const StrValArray& rStrs = aHdl.getStrs();
+ const NumValArray& rNums = aHdl.getNums();
+ if (rStrs.empty() && rNums.empty() && mbRefreshOnEmptyLine)
+ {
+ // Empty line detected. Trigger refresh and discard it.
+ Refresh();
+ return;
+ }
MoveData();
- if (mbValuesInLine)
{
- // do CSV import
- Text2Doc();
+ StrValArray::const_iterator it = rStrs.begin(), itEnd = rStrs.end();
+ for (; it != itEnd; ++it)
+ maDocAccess.setStringCell(it->maPos, it->maStr);
}
- else
- {
-#if 0 // TODO : temporarily disable this code.
- ScDocumentImport aDocImport(*mpDoc);
- // read more lines at once but not too much
- for (int i = 0; i < 10; ++i)
- {
- OUString sLine( OStringToOUString(ConsumeLine(), RTL_TEXTENCODING_UTF8) );
- if (sLine.indexOf(',') <= 0)
- continue;
-
- OUString sAddress( sLine.copy(0, sLine.indexOf(',')) );
- OUString sValue( sLine.copy(sLine.indexOf(',') + 1) );
- ScAddress aAddress;
- aAddress.Parse(sAddress, mpDoc);
- if (!aAddress.IsValid())
- continue;
- if (sValue == "0" || ( sValue.indexOf(':') == -1 && sValue.toDouble() ))
- aDocImport.setNumericCell(aAddress, sValue.toDouble());
- else
- aDocImport.setStringCell(aAddress, sValue);
- maBroadcastRanges.Join(aAddress);
- }
- aDocImport.finalize();
-#endif
+ {
+ NumValArray::const_iterator it = rNums.begin(), itEnd = rNums.end();
+ for (; it != itEnd; ++it)
+ maDocAccess.setNumericCell(it->maPos, it->mfVal);
}
if (meMove == NO_MOVE)
- return mbRunning;
+ return;
if (meMove == RANGE_DOWN)
{
@@ -546,6 +549,26 @@ bool DataStream::ImportData()
// least we have processed 200 lines.
Refresh();
+ ++mnLinesSinceRefresh;
+}
+
+#else
+
+void DataStream::Text2Doc() {}
+
+#endif
+
+bool DataStream::ImportData()
+{
+ SolarMutexGuard aGuard;
+ if (!mbValuesInLine)
+ // We no longer support this mode. To be deleted later.
+ return false;
+
+ if (ScDocShell::GetViewData()->GetViewShell()->NeedsRepaint())
+ return mbRunning;
+
+ Text2Doc();
return mbRunning;
}
diff --git a/sc/source/ui/inc/datastream.hxx b/sc/source/ui/inc/datastream.hxx
index a593aad..1cde20e 100644
--- a/sc/source/ui/inc/datastream.hxx
+++ b/sc/source/ui/inc/datastream.hxx
@@ -78,6 +78,8 @@ public:
void StartImport();
void StopImport();
+ void SetRefreshOnEmptyLine( bool bVal );
+
private:
void Refresh();
@@ -91,6 +93,7 @@ private:
MoveType meMove;
bool mbRunning;
bool mbValuesInLine;
+ bool mbRefreshOnEmptyLine;
LinesList* mpLines;
size_t mnLinesCount;
size_t mnLinesSinceRefresh;
diff --git a/sc/source/ui/inc/datastreamdlg.hxx b/sc/source/ui/inc/datastreamdlg.hxx
index d817743..0a7f167 100644
--- a/sc/source/ui/inc/datastreamdlg.hxx
+++ b/sc/source/ui/inc/datastreamdlg.hxx
@@ -30,6 +30,7 @@ class DataStreamDlg : public ModalDialog
RadioButton* m_pRBScriptData;
RadioButton* m_pRBValuesInLine;
RadioButton* m_pRBAddressValue;
+ CheckBox* m_pCBRefreshOnEmpty;
RadioButton* m_pRBDataDown;
RadioButton* m_pRBRangeDown;
RadioButton* m_pRBNoMove;
diff --git a/sc/source/ui/miscdlgs/datastreamdlg.cxx b/sc/source/ui/miscdlgs/datastreamdlg.cxx
index c004fbc..fa21dd9 100644
--- a/sc/source/ui/miscdlgs/datastreamdlg.cxx
+++ b/sc/source/ui/miscdlgs/datastreamdlg.cxx
@@ -26,6 +26,7 @@ DataStreamDlg::DataStreamDlg(ScDocShell *pDocShell, Window* pParent)
get(m_pRBScriptData, "scriptdata");
get(m_pRBValuesInLine, "valuesinline");
get(m_pRBAddressValue, "addressvalue");
+ get(m_pCBRefreshOnEmpty, "refresh_ui");
get(m_pRBDataDown, "datadown");
get(m_pRBRangeDown, "rangedown");
get(m_pRBNoMove, "nomove");
@@ -166,10 +167,12 @@ void DataStreamDlg::StartStream(DataStream *pStream)
if (pStream)
{
pStream->Decode(rURL, aStartRange, nLimit, eMove, nSettings);
+ pStream->SetRefreshOnEmptyLine(m_pCBRefreshOnEmpty->IsChecked());
return;
}
pStream = DataStream::Set(mpDocShell, rURL, aStartRange, nLimit, eMove, nSettings);
+ pStream->SetRefreshOnEmptyLine(m_pCBRefreshOnEmpty->IsChecked());
DataStream::MakeToolbarVisible();
pStream->StartImport();
}
commit b8e85af1eddb58ff60d93f64e157b31a904683b2
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date: Wed Dec 18 14:55:17 2013 -0500
Fine-tune our refresh policy during streaming.
Change-Id: I9eff0bc0e4087261e2283a55211c8a9daf2a8b24
diff --git a/sc/source/ui/docshell/datastream.cxx b/sc/source/ui/docshell/datastream.cxx
index cbf8957..f9686ae 100644
--- a/sc/source/ui/docshell/datastream.cxx
+++ b/sc/source/ui/docshell/datastream.cxx
@@ -13,12 +13,12 @@
#include <com/sun/star/ui/XUIElement.hpp>
#include <officecfg/Office/Common.hxx>
#include <osl/conditn.hxx>
+#include <osl/time.h>
#include <rtl/strbuf.hxx>
#include <salhelper/thread.hxx>
#include <sfx2/linkmgr.hxx>
#include <sfx2/viewfrm.hxx>
#include <arealink.hxx>
-#include <asciiopt.hxx>
#include <datastreamdlg.hxx>
#include <dbfunc.hxx>
#include <docsh.hxx>
@@ -42,6 +42,13 @@
namespace sc {
+inline double getNow()
+{
+ TimeValue now;
+ osl_getSystemTime(&now);
+ return static_cast<double>(now.Seconds) + static_cast<double>(now.Nanosec) / 1000000000.0;
+}
+
namespace datastreams {
class CallerThread : public salhelper::Thread
@@ -246,7 +253,8 @@ DataStream::DataStream(ScDocShell *pShell, const OUString& rURL, const ScRange&
mbRunning(false),
mpLines(0),
mnLinesCount(0),
- mnRepaintCounter(0),
+ mnLinesSinceRefresh(0),
+ mfLastRefreshTime(0.0),
mnCurRow(0)
{
mxThread = new datastreams::CallerThread( this );
@@ -375,14 +383,11 @@ void DataStream::StopImport()
void DataStream::Refresh()
{
- SCROW nEndRow = mpEndRange ? mpEndRange->aEnd.Row() : MAXROW;
- ScRange aRange(maStartRange.aStart);
- aRange.aEnd = ScAddress(maStartRange.aEnd.Col(), nEndRow, maStartRange.aStart.Tab());
-
- mnRepaintCounter = 0;
-
// Hard recalc will repaint the grid area.
mpDocShell->DoHardRecalc(true);
+
+ mfLastRefreshTime = getNow();
+ mnLinesSinceRefresh = 0;
}
void DataStream::MoveData()
@@ -477,7 +482,7 @@ void DataStream::Text2Doc()
orcus::csv_parser<CSVHandler> parser(aLine.getStr(), aLine.getLength(), aHdl, aConfig);
parser.parse();
- ++mnRepaintCounter;
+ ++mnLinesSinceRefresh;
}
#else
@@ -536,7 +541,9 @@ bool DataStream::ImportData()
// maStartRange.aStart.Col(), mnCurRow, SC_FOLLOW_JUMP);
}
- if (mnRepaintCounter > 200)
+ if (getNow() - mfLastRefreshTime > 0.1 && mnLinesSinceRefresh > 200)
+ // Refresh no more frequently than every 0.1 second, and wait until at
+ // least we have processed 200 lines.
Refresh();
return mbRunning;
diff --git a/sc/source/ui/inc/datastream.hxx b/sc/source/ui/inc/datastream.hxx
index 86be03b..a593aad 100644
--- a/sc/source/ui/inc/datastream.hxx
+++ b/sc/source/ui/inc/datastream.hxx
@@ -93,7 +93,8 @@ private:
bool mbValuesInLine;
LinesList* mpLines;
size_t mnLinesCount;
- size_t mnRepaintCounter;
+ size_t mnLinesSinceRefresh;
+ double mfLastRefreshTime;
SCROW mnCurRow;
ScRange maStartRange;
boost::scoped_ptr<ScRange> mpEndRange;
commit b9524c17b56e4bdecb76880582853fdeb3380013
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date: Wed Dec 18 14:15:29 2013 -0500
Just do hard-recalc on stream refresh. That takes care of all our needs.
Change-Id: I9a454089843d1373153988a29843b95db22ee284
diff --git a/sc/source/ui/docshell/datastream.cxx b/sc/source/ui/docshell/datastream.cxx
index 9121d48..cbf8957 100644
--- a/sc/source/ui/docshell/datastream.cxx
+++ b/sc/source/ui/docshell/datastream.cxx
@@ -370,23 +370,19 @@ void DataStream::StopImport()
return;
mbRunning = false;
- Repaint();
+ Refresh();
}
-void DataStream::Repaint()
+void DataStream::Refresh()
{
SCROW nEndRow = mpEndRange ? mpEndRange->aEnd.Row() : MAXROW;
ScRange aRange(maStartRange.aStart);
aRange.aEnd = ScAddress(maStartRange.aEnd.Col(), nEndRow, maStartRange.aStart.Tab());
- mpDocShell->PostPaint(aRange, PAINT_GRID);
mnRepaintCounter = 0;
-}
-void DataStream::Broadcast()
-{
- mpDoc->BroadcastCells(maBroadcastRanges, SC_HINT_DATACHANGED);
- maBroadcastRanges.RemoveAll();
+ // Hard recalc will repaint the grid area.
+ mpDocShell->DoHardRecalc(true);
}
void DataStream::MoveData()
@@ -541,7 +537,7 @@ bool DataStream::ImportData()
}
if (mnRepaintCounter > 200)
- Repaint();
+ Refresh();
return mbRunning;
}
diff --git a/sc/source/ui/inc/datastream.hxx b/sc/source/ui/inc/datastream.hxx
index 494a73e..86be03b 100644
--- a/sc/source/ui/inc/datastream.hxx
+++ b/sc/source/ui/inc/datastream.hxx
@@ -79,8 +79,7 @@ public:
void StopImport();
private:
- void Repaint();
- void Broadcast();
+ void Refresh();
private:
ScDocShell* mpDocShell;
@@ -97,7 +96,6 @@ private:
size_t mnRepaintCounter;
SCROW mnCurRow;
ScRange maStartRange;
- ScRangeList maBroadcastRanges;
boost::scoped_ptr<ScRange> mpEndRange;
rtl::Reference<datastreams::CallerThread> mxThread;
rtl::Reference<datastreams::ReaderThread> mxReaderThread;
More information about the Libreoffice-commits
mailing list