[Libreoffice-commits] core.git: sc/source sc/uiconfig
Matúš Kukan
matus.kukan at collabora.com
Tue Nov 19 13:09:29 PST 2013
sc/source/ui/inc/datastreams.hxx | 5 +
sc/source/ui/miscdlgs/datastreams.cxx | 72 +++++++++++++++++++++-------
sc/source/ui/miscdlgs/datastreamsdlg.cxx | 41 +++++++++++-----
sc/uiconfig/scalc/ui/datastreams.ui | 79 +++++++++++++++++++++++++++++--
4 files changed, 164 insertions(+), 33 deletions(-)
New commits:
commit 3d7d66258373c1d4df20cce6a993b3fe013a7910
Author: Matúš Kukan <matus.kukan at collabora.com>
Date: Tue Nov 19 13:57:58 2013 +0100
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
diff --git a/sc/source/ui/inc/datastreams.hxx b/sc/source/ui/inc/datastreams.hxx
index 8233be1..80f9cd6 100644
--- a/sc/source/ui/inc/datastreams.hxx
+++ b/sc/source/ui/inc/datastreams.hxx
@@ -30,8 +30,8 @@ public:
~DataStreams();
bool ImportData();
void MoveData();
- void Set(const OUString& rUrl, bool bIsScript, const OUString& rRange,
- sal_Int32 nLimit, MoveEnum eMove);
+ void Set(const OUString& rUrl, bool bIsScript, bool bValuesInLine,
+ const OUString& rRange, sal_Int32 nLimit, MoveEnum eMove);
void ShowDialog(Window *pParent);
void Start();
void Stop();
@@ -42,6 +42,7 @@ private:
MoveEnum meMove;
bool mbRunning;
bool mbIsUndoEnabled;
+ bool mbValuesInLine;
boost::scoped_ptr<ScRange> mpRange;
boost::scoped_ptr<ScRange> mpStartRange;
boost::scoped_ptr<ScRange> mpEndRange;
diff --git a/sc/source/ui/miscdlgs/datastreams.cxx b/sc/source/ui/miscdlgs/datastreams.cxx
index dd5a821..b938513 100644
--- a/sc/source/ui/miscdlgs/datastreams.cxx
+++ b/sc/source/ui/miscdlgs/datastreams.cxx
@@ -18,7 +18,9 @@
#include <asciiopt.hxx>
#include <dbfunc.hxx>
#include <docsh.hxx>
+#include <documentimport.hxx>
#include <impex.hxx>
+#include <rangelst.hxx>
#include <tabvwsh.hxx>
#include <viewdata.hxx>
@@ -115,18 +117,25 @@ void DataStreams::Stop()
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)
{
- mpRange.reset ( new ScRange() );
- mpRange->Parse(rRange, mpScDocument);
- mpStartRange.reset( new ScRange(*mpRange.get()) );
if (bIsScript)
mpStream.reset( new SvScriptStream(rUrl) );
else
mpStream.reset( new SvFileStream(rUrl, STREAM_READ) );
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;
sal_Int32 nHeight = mpRange->aEnd.Row() - mpRange->aStart.Row() + 1;
nLimit = nHeight * (nLimit / nHeight);
@@ -168,21 +177,52 @@ bool DataStreams::ImportData()
return mbRunning;
}
- SCROW nHeight = mpRange->aEnd.Row() - mpRange->aStart.Row() + 1;
- OStringBuffer aBuf;
OString sTmp;
- while (nHeight--)
- {
- mpStream->ReadLine(sTmp);
- aBuf.append(sTmp);
- aBuf.append('\n');
- }
SolarMutexGuard aGuard;
MoveData();
- SvMemoryStream aMemoryStream((void *)aBuf.getStr(), aBuf.getLength(), STREAM_READ);
- ScImportExport aImport(mpScDocument, *mpRange);
- aImport.SetSeparator(',');
- aImport.ImportStream(aMemoryStream, OUString(), FORMAT_STRING);
+ if (mbValuesInLine)
+ {
+ SCROW nHeight = mpRange->aEnd.Row() - mpRange->aStart.Row() + 1;
+ OStringBuffer aBuf;
+ while (nHeight--)
+ {
+ mpStream->ReadLine(sTmp);
+ aBuf.append(sTmp);
+ aBuf.append('\n');
+ }
+ SvMemoryStream aMemoryStream((void *)aBuf.getStr(), aBuf.getLength(), STREAM_READ);
+ ScImportExport aImport(mpScDocument, *mpRange);
+ aImport.SetSeparator(',');
+ 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,
// we need to call it explicitly only when moving rows.
if (meMove == NO_MOVE)
diff --git a/sc/source/ui/miscdlgs/datastreamsdlg.cxx b/sc/source/ui/miscdlgs/datastreamsdlg.cxx
index 1fa07af..cbe19a3 100644
--- a/sc/source/ui/miscdlgs/datastreamsdlg.cxx
+++ b/sc/source/ui/miscdlgs/datastreamsdlg.cxx
@@ -10,6 +10,7 @@
#include <sfx2/filedlghelper.hxx>
#include <svtools/inettbc.hxx>
#include <vcl/dialog.hxx>
+#include <vcl/layout.hxx>
#include <datastreams.hxx>
namespace {
@@ -20,16 +21,18 @@ class DataStreamsDlg : public ModalDialog
SvtURLBox* m_pCbUrl;
PushButton* m_pBtnBrowse;
- RadioButton* m_pRBDirectData;
RadioButton* m_pRBScriptData;
- RadioButton* m_pRBDataDown;
+ RadioButton* m_pRBValuesInLine;
+ RadioButton* m_pRBAddressValue;
RadioButton* m_pRBRangeDown;
RadioButton* m_pRBNoMove;
RadioButton* m_pRBMaxLimit;
- RadioButton* m_pRBUnlimited;
Edit* m_pEdRange;
Edit* m_pEdLimit;
OKButton* m_pBtnOk;
+ VclFrame* m_pVclFrameLimit;
+ VclFrame* m_pVclFrameMove;
+ VclFrame* m_pVclFrameRange;
DECL_LINK(UpdateHdl, void *);
DECL_LINK(BrowseHdl, void *);
@@ -48,18 +51,22 @@ DataStreamsDlg::DataStreamsDlg(DataStreams *pDataStreams, Window* pParent)
{
get(m_pCbUrl, "url");
get(m_pBtnBrowse, "browse");
- get(m_pRBDirectData, "directdata");
get(m_pRBScriptData, "scriptdata");
- get(m_pRBDataDown, "datadown");
+ get(m_pRBValuesInLine, "valuesinline");
+ get(m_pRBAddressValue, "addressvalue");
get(m_pRBRangeDown, "rangedown");
get(m_pRBNoMove, "nomove");
get(m_pRBMaxLimit, "maxlimit");
- get(m_pRBUnlimited, "unlimited");
get(m_pEdRange, "range");
get(m_pEdLimit, "limit");
get(m_pBtnOk, "ok");
+ get(m_pVclFrameLimit, "framelimit");
+ get(m_pVclFrameMove, "framemove");
+ get(m_pVclFrameRange, "framerange");
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_pBtnBrowse->SetClickHdl( LINK( this, DataStreamsDlg, BrowseHdl ) );
UpdateEnable();
@@ -71,9 +78,9 @@ void DataStreamsDlg::Start()
sal_Int32 nLimit = 0;
if (m_pRBMaxLimit->IsChecked())
nLimit = m_pEdLimit->GetText().toInt32();
- mpDataStreams->Set(m_pCbUrl->GetText(), bIsScript, m_pEdRange->GetText(),
- nLimit, m_pRBNoMove->IsChecked() ? DataStreams::NO_MOVE :
- m_pRBRangeDown->IsChecked() ? DataStreams::RANGE_DOWN : DataStreams::MOVE_DOWN);
+ mpDataStreams->Set( m_pCbUrl->GetText(), bIsScript, m_pRBValuesInLine->IsChecked(),
+ m_pEdRange->GetText(), nLimit, (m_pRBNoMove->IsChecked() ? DataStreams::NO_MOVE :
+ m_pRBRangeDown->IsChecked() ? DataStreams::RANGE_DOWN : DataStreams::MOVE_DOWN) );
mpDataStreams->Start();
}
@@ -96,8 +103,20 @@ IMPL_LINK_NOARG(DataStreamsDlg, UpdateHdl)
void DataStreamsDlg::UpdateEnable()
{
- bool bOk = !m_pEdRange->GetText().isEmpty();
- bOk = bOk && !m_pCbUrl->GetURL().isEmpty();
+ bool 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);
}
diff --git a/sc/uiconfig/scalc/ui/datastreams.ui b/sc/uiconfig/scalc/ui/datastreams.ui
index 12282f8..853840a 100644
--- a/sc/uiconfig/scalc/ui/datastreams.ui
+++ b/sc/uiconfig/scalc/ui/datastreams.ui
@@ -144,7 +144,78 @@
</packing>
</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="can_focus">False</property>
<property name="label_xalign">0</property>
@@ -176,7 +247,7 @@
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
- <property name="position">2</property>
+ <property name="position">3</property>
</packing>
</child>
</object>
@@ -202,7 +273,7 @@
</packing>
</child>
<child>
- <object class="GtkFrame" id="frame2">
+ <object class="GtkFrame" id="framemove">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label_xalign">0</property>
@@ -293,7 +364,7 @@
</packing>
</child>
<child>
- <object class="GtkFrame" id="frame3">
+ <object class="GtkFrame" id="framelimit">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label_xalign">0</property>
More information about the Libreoffice-commits
mailing list