Kaydet (Commit) 3d7d6625 authored tarafından Matúš Kukan's avatar Matúš Kukan

datastreams: implement address mode for input

In this mode, we read lines as "<address>,<value>".
Moving is disabled then, because we update each cell individually
(and also, for some reason, it was not working).

Change-Id: I55f73e5a6a26f3e962a12662deeea657ce41acd4
üst fc25afaa
...@@ -30,8 +30,8 @@ public: ...@@ -30,8 +30,8 @@ public:
~DataStreams(); ~DataStreams();
bool ImportData(); bool ImportData();
void MoveData(); void MoveData();
void Set(const OUString& rUrl, bool bIsScript, const OUString& rRange, void Set(const OUString& rUrl, bool bIsScript, bool bValuesInLine,
sal_Int32 nLimit, MoveEnum eMove); const OUString& rRange, sal_Int32 nLimit, MoveEnum eMove);
void ShowDialog(Window *pParent); void ShowDialog(Window *pParent);
void Start(); void Start();
void Stop(); void Stop();
...@@ -42,6 +42,7 @@ private: ...@@ -42,6 +42,7 @@ private:
MoveEnum meMove; MoveEnum meMove;
bool mbRunning; bool mbRunning;
bool mbIsUndoEnabled; bool mbIsUndoEnabled;
bool mbValuesInLine;
boost::scoped_ptr<ScRange> mpRange; boost::scoped_ptr<ScRange> mpRange;
boost::scoped_ptr<ScRange> mpStartRange; boost::scoped_ptr<ScRange> mpStartRange;
boost::scoped_ptr<ScRange> mpEndRange; boost::scoped_ptr<ScRange> mpEndRange;
......
...@@ -18,7 +18,9 @@ ...@@ -18,7 +18,9 @@
#include <asciiopt.hxx> #include <asciiopt.hxx>
#include <dbfunc.hxx> #include <dbfunc.hxx>
#include <docsh.hxx> #include <docsh.hxx>
#include <documentimport.hxx>
#include <impex.hxx> #include <impex.hxx>
#include <rangelst.hxx>
#include <tabvwsh.hxx> #include <tabvwsh.hxx>
#include <viewdata.hxx> #include <viewdata.hxx>
...@@ -115,18 +117,25 @@ void DataStreams::Stop() ...@@ -115,18 +117,25 @@ void DataStreams::Stop()
mpScDocument->EnableUndo(mbIsUndoEnabled); mpScDocument->EnableUndo(mbIsUndoEnabled);
} }
void DataStreams::Set(const OUString& rUrl, bool bIsScript, void DataStreams::Set(const OUString& rUrl, bool bIsScript, bool bValuesInLine,
const OUString& rRange, sal_Int32 nLimit, MoveEnum eMove) const OUString& rRange, sal_Int32 nLimit, MoveEnum eMove)
{ {
mpRange.reset ( new ScRange() );
mpRange->Parse(rRange, mpScDocument);
mpStartRange.reset( new ScRange(*mpRange.get()) );
if (bIsScript) if (bIsScript)
mpStream.reset( new SvScriptStream(rUrl) ); mpStream.reset( new SvScriptStream(rUrl) );
else else
mpStream.reset( new SvFileStream(rUrl, STREAM_READ) ); mpStream.reset( new SvFileStream(rUrl, STREAM_READ) );
mpEndRange.reset( NULL ); mpEndRange.reset( NULL );
mpRange.reset ( new ScRange() );
mbValuesInLine = bValuesInLine;
if (!mbValuesInLine)
{
meMove = NO_MOVE;
return;
}
mpRange->Parse(rRange, mpScDocument);
mpStartRange.reset( new ScRange(*mpRange.get()) );
meMove = eMove; meMove = eMove;
sal_Int32 nHeight = mpRange->aEnd.Row() - mpRange->aStart.Row() + 1; sal_Int32 nHeight = mpRange->aEnd.Row() - mpRange->aStart.Row() + 1;
nLimit = nHeight * (nLimit / nHeight); nLimit = nHeight * (nLimit / nHeight);
...@@ -168,21 +177,52 @@ bool DataStreams::ImportData() ...@@ -168,21 +177,52 @@ bool DataStreams::ImportData()
return mbRunning; return mbRunning;
} }
OString sTmp;
SolarMutexGuard aGuard;
MoveData();
if (mbValuesInLine)
{
SCROW nHeight = mpRange->aEnd.Row() - mpRange->aStart.Row() + 1; SCROW nHeight = mpRange->aEnd.Row() - mpRange->aStart.Row() + 1;
OStringBuffer aBuf; OStringBuffer aBuf;
OString sTmp;
while (nHeight--) while (nHeight--)
{ {
mpStream->ReadLine(sTmp); mpStream->ReadLine(sTmp);
aBuf.append(sTmp); aBuf.append(sTmp);
aBuf.append('\n'); aBuf.append('\n');
} }
SolarMutexGuard aGuard;
MoveData();
SvMemoryStream aMemoryStream((void *)aBuf.getStr(), aBuf.getLength(), STREAM_READ); SvMemoryStream aMemoryStream((void *)aBuf.getStr(), aBuf.getLength(), STREAM_READ);
ScImportExport aImport(mpScDocument, *mpRange); ScImportExport aImport(mpScDocument, *mpRange);
aImport.SetSeparator(','); aImport.SetSeparator(',');
aImport.ImportStream(aMemoryStream, OUString(), FORMAT_STRING); aImport.ImportStream(aMemoryStream, OUString(), FORMAT_STRING);
}
else
{
ScRangeList aRangeList;
ScDocumentImport aDocImport(*mpScDocument);
// read more lines at once but not too much
for (int i = 0; i < 10; ++i)
{
mpStream->ReadLine(sTmp);
OUString sLine(OStringToOUString(sTmp, 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, mpScDocument);
if (!aAddress.IsValid())
continue;
if (sValue == "0" || ( sValue.indexOf(':') == -1 && sValue.toDouble() ))
aDocImport.setNumericCell(aAddress, sValue.toDouble());
else
aDocImport.setStringCell(aAddress, sValue);
aRangeList.Join(aAddress);
}
aDocImport.finalize();
mpScDocShell->PostPaint( aRangeList, PAINT_GRID );
}
// ImportStream calls PostPaint for relevant area, // ImportStream calls PostPaint for relevant area,
// we need to call it explicitly only when moving rows. // we need to call it explicitly only when moving rows.
if (meMove == NO_MOVE) if (meMove == NO_MOVE)
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include <sfx2/filedlghelper.hxx> #include <sfx2/filedlghelper.hxx>
#include <svtools/inettbc.hxx> #include <svtools/inettbc.hxx>
#include <vcl/dialog.hxx> #include <vcl/dialog.hxx>
#include <vcl/layout.hxx>
#include <datastreams.hxx> #include <datastreams.hxx>
namespace { namespace {
...@@ -20,16 +21,18 @@ class DataStreamsDlg : public ModalDialog ...@@ -20,16 +21,18 @@ class DataStreamsDlg : public ModalDialog
SvtURLBox* m_pCbUrl; SvtURLBox* m_pCbUrl;
PushButton* m_pBtnBrowse; PushButton* m_pBtnBrowse;
RadioButton* m_pRBDirectData;
RadioButton* m_pRBScriptData; RadioButton* m_pRBScriptData;
RadioButton* m_pRBDataDown; RadioButton* m_pRBValuesInLine;
RadioButton* m_pRBAddressValue;
RadioButton* m_pRBRangeDown; RadioButton* m_pRBRangeDown;
RadioButton* m_pRBNoMove; RadioButton* m_pRBNoMove;
RadioButton* m_pRBMaxLimit; RadioButton* m_pRBMaxLimit;
RadioButton* m_pRBUnlimited;
Edit* m_pEdRange; Edit* m_pEdRange;
Edit* m_pEdLimit; Edit* m_pEdLimit;
OKButton* m_pBtnOk; OKButton* m_pBtnOk;
VclFrame* m_pVclFrameLimit;
VclFrame* m_pVclFrameMove;
VclFrame* m_pVclFrameRange;
DECL_LINK(UpdateHdl, void *); DECL_LINK(UpdateHdl, void *);
DECL_LINK(BrowseHdl, void *); DECL_LINK(BrowseHdl, void *);
...@@ -48,18 +51,22 @@ DataStreamsDlg::DataStreamsDlg(DataStreams *pDataStreams, Window* pParent) ...@@ -48,18 +51,22 @@ DataStreamsDlg::DataStreamsDlg(DataStreams *pDataStreams, Window* pParent)
{ {
get(m_pCbUrl, "url"); get(m_pCbUrl, "url");
get(m_pBtnBrowse, "browse"); get(m_pBtnBrowse, "browse");
get(m_pRBDirectData, "directdata");
get(m_pRBScriptData, "scriptdata"); get(m_pRBScriptData, "scriptdata");
get(m_pRBDataDown, "datadown"); get(m_pRBValuesInLine, "valuesinline");
get(m_pRBAddressValue, "addressvalue");
get(m_pRBRangeDown, "rangedown"); get(m_pRBRangeDown, "rangedown");
get(m_pRBNoMove, "nomove"); get(m_pRBNoMove, "nomove");
get(m_pRBMaxLimit, "maxlimit"); get(m_pRBMaxLimit, "maxlimit");
get(m_pRBUnlimited, "unlimited");
get(m_pEdRange, "range"); get(m_pEdRange, "range");
get(m_pEdLimit, "limit"); get(m_pEdLimit, "limit");
get(m_pBtnOk, "ok"); get(m_pBtnOk, "ok");
get(m_pVclFrameLimit, "framelimit");
get(m_pVclFrameMove, "framemove");
get(m_pVclFrameRange, "framerange");
m_pCbUrl->SetSelectHdl( LINK( this, DataStreamsDlg, UpdateHdl ) ); m_pCbUrl->SetSelectHdl( LINK( this, DataStreamsDlg, UpdateHdl ) );
m_pRBAddressValue->SetClickHdl( LINK( this, DataStreamsDlg, UpdateHdl ) );
m_pRBValuesInLine->SetClickHdl( LINK( this, DataStreamsDlg, UpdateHdl ) );
m_pEdRange->SetModifyHdl( LINK( this, DataStreamsDlg, UpdateHdl ) ); m_pEdRange->SetModifyHdl( LINK( this, DataStreamsDlg, UpdateHdl ) );
m_pBtnBrowse->SetClickHdl( LINK( this, DataStreamsDlg, BrowseHdl ) ); m_pBtnBrowse->SetClickHdl( LINK( this, DataStreamsDlg, BrowseHdl ) );
UpdateEnable(); UpdateEnable();
...@@ -71,9 +78,9 @@ void DataStreamsDlg::Start() ...@@ -71,9 +78,9 @@ void DataStreamsDlg::Start()
sal_Int32 nLimit = 0; sal_Int32 nLimit = 0;
if (m_pRBMaxLimit->IsChecked()) if (m_pRBMaxLimit->IsChecked())
nLimit = m_pEdLimit->GetText().toInt32(); nLimit = m_pEdLimit->GetText().toInt32();
mpDataStreams->Set(m_pCbUrl->GetText(), bIsScript, m_pEdRange->GetText(), mpDataStreams->Set( m_pCbUrl->GetText(), bIsScript, m_pRBValuesInLine->IsChecked(),
nLimit, m_pRBNoMove->IsChecked() ? DataStreams::NO_MOVE : m_pEdRange->GetText(), nLimit, (m_pRBNoMove->IsChecked() ? DataStreams::NO_MOVE :
m_pRBRangeDown->IsChecked() ? DataStreams::RANGE_DOWN : DataStreams::MOVE_DOWN); m_pRBRangeDown->IsChecked() ? DataStreams::RANGE_DOWN : DataStreams::MOVE_DOWN) );
mpDataStreams->Start(); mpDataStreams->Start();
} }
...@@ -96,8 +103,20 @@ IMPL_LINK_NOARG(DataStreamsDlg, UpdateHdl) ...@@ -96,8 +103,20 @@ IMPL_LINK_NOARG(DataStreamsDlg, UpdateHdl)
void DataStreamsDlg::UpdateEnable() void DataStreamsDlg::UpdateEnable()
{ {
bool bOk = !m_pEdRange->GetText().isEmpty(); bool bOk = !m_pCbUrl->GetURL().isEmpty();
bOk = bOk && !m_pCbUrl->GetURL().isEmpty(); if (m_pRBAddressValue->IsChecked())
{
m_pVclFrameLimit->Hide();
m_pVclFrameMove->Hide();
m_pVclFrameRange->Hide();
}
else
{
m_pVclFrameLimit->Show(true);
m_pVclFrameMove->Show();
m_pVclFrameRange->Show();
bOk = bOk && !m_pEdRange->GetText().isEmpty();
}
m_pBtnOk->Enable(bOk); m_pBtnOk->Enable(bOk);
} }
......
...@@ -144,7 +144,78 @@ ...@@ -144,7 +144,78 @@
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkFrame" id="frame1"> <object class="GtkFrame" id="frame4">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label_xalign">0</property>
<property name="shadow_type">none</property>
<child>
<object class="GtkAlignment" id="alignment5">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="top_padding">6</property>
<property name="left_padding">12</property>
<child>
<object class="GtkBox" id="box2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkRadioButton" id="valuesinline">
<property name="label" translatable="yes">value1,value2,...</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="use_underline">True</property>
<property name="xalign">0</property>
<property name="active">True</property>
<property name="draw_indicator">True</property>
<property name="group">addressvalue</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkRadioButton" id="addressvalue">
<property name="label" translatable="yes">address,value</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="use_underline">True</property>
<property name="xalign">0</property>
<property name="draw_indicator">True</property>
<property name="group">valuesinline</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
</child>
</object>
</child>
<child type="label">
<object class="GtkLabel" id="label4">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Interpret stream data as</property>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="padding">6</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkFrame" id="framerange">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="label_xalign">0</property> <property name="label_xalign">0</property>
...@@ -176,7 +247,7 @@ ...@@ -176,7 +247,7 @@
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
<property name="fill">True</property> <property name="fill">True</property>
<property name="position">2</property> <property name="position">3</property>
</packing> </packing>
</child> </child>
</object> </object>
...@@ -202,7 +273,7 @@ ...@@ -202,7 +273,7 @@
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkFrame" id="frame2"> <object class="GtkFrame" id="framemove">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="label_xalign">0</property> <property name="label_xalign">0</property>
...@@ -293,7 +364,7 @@ ...@@ -293,7 +364,7 @@
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkFrame" id="frame3"> <object class="GtkFrame" id="framelimit">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="label_xalign">0</property> <property name="label_xalign">0</property>
......
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