[Libreoffice-commits] core.git: 3 commits - sc/inc sc/qa sc/source
Kohei Yoshida
kohei.yoshida at collabora.com
Mon Jul 28 19:13:26 PDT 2014
sc/inc/column.hxx | 6 ++-
sc/inc/document.hxx | 8 +---
sc/inc/formulacell.hxx | 1
sc/inc/table.hxx | 6 ++-
sc/qa/unit/ucalc.hxx | 2 +
sc/qa/unit/ucalc_sharedformula.cxx | 68 ++++++++++++++++++++++++++++++++++++
sc/source/core/data/column2.cxx | 22 -----------
sc/source/core/data/column4.cxx | 43 +++++++++++++++-------
sc/source/core/data/documen4.cxx | 11 -----
sc/source/core/data/document10.cxx | 17 +++++++--
sc/source/core/data/formulacell.cxx | 51 ---------------------------
sc/source/core/data/table4.cxx | 6 ---
sc/source/core/data/table7.cxx | 11 ++++-
sc/source/ui/dbgui/dbnamdlg.cxx | 7 ++-
sc/source/ui/docshell/dbdocfun.cxx | 51 +++++++++++++++++++++++----
sc/source/ui/docshell/docfunc.cxx | 4 +-
sc/source/ui/docshell/docsh5.cxx | 4 +-
sc/source/ui/inc/dbdocfun.hxx | 3 +
sc/source/ui/inc/dbfunc.hxx | 2 -
sc/source/ui/undo/undocell.cxx | 2 -
sc/source/ui/undo/undodat.cxx | 8 ++--
sc/source/ui/undo/undorangename.cxx | 2 -
sc/source/ui/unoobj/nameuno.cxx | 2 -
sc/source/ui/view/dbfunc.cxx | 45 -----------------------
sc/source/ui/view/viewfunc.cxx | 2 -
25 files changed, 199 insertions(+), 185 deletions(-)
New commits:
commit 300845922eec7a28bc1da337acd21f138685d759
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date: Mon Jul 28 21:34:40 2014 -0400
fdo#79578: Properly update formulas upon change in db collection.
Update it to handle formula groups correctly.
Change-Id: I009a7fcf3d3fb17ef6951c50534ca6bc1fffc259
diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx
index 6191577..1a08163 100644
--- a/sc/inc/column.hxx
+++ b/sc/inc/column.hxx
@@ -381,9 +381,12 @@ public:
void PreprocessRangeNameUpdate(
sc::EndListeningContext& rEndListenCxt, sc::CompileFormulaContext& rCompileCxt );
- void PostprocessRangeNameUpdate(
+ void CompileHybridFormula(
sc::StartListeningContext& rStartListenCxt, sc::CompileFormulaContext& rCompileCxt );
+ void PreprocessDBDataUpdate(
+ sc::EndListeningContext& rEndListenCxt, sc::CompileFormulaContext& rCompileCxt );
+
const SfxPoolItem* GetAttr( SCROW nRow, sal_uInt16 nWhich ) const;
const ScPatternAttr* GetPattern( SCROW nRow ) const;
const ScPatternAttr* GetMostUsedPattern( SCROW nStartRow, SCROW nEndRow ) const;
@@ -486,7 +489,6 @@ public:
void CollectListeners( std::vector<SvtListener*>& rListeners, SCROW nRow1, SCROW nRow2 );
void CompileDBFormula( sc::CompileFormulaContext& rCxt );
- void CompileDBFormula( sc::CompileFormulaContext& rCxt, bool bCreateFormulaString );
void CompileColRowNameFormula( sc::CompileFormulaContext& rCxt );
sal_Int32 GetMaxStringLen( SCROW nRowStart, SCROW nRowEnd, rtl_TextEncoding eCharSet ) const;
diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx
index 44e88c0..c7b797b 100644
--- a/sc/inc/document.hxx
+++ b/sc/inc/document.hxx
@@ -519,11 +519,8 @@ public:
* Call this immediately before updating all named ranges.
*/
SC_DLLPUBLIC void PreprocessRangeNameUpdate();
-
- /**
- * Call this immediately after all named ranges have been updated.
- */
- SC_DLLPUBLIC void PostprocessRangeNameUpdate();
+ SC_DLLPUBLIC void PreprocessDBDataUpdate();
+ SC_DLLPUBLIC void CompileHybridFormula();
/**
* Insert a new named expression to the global scope.
@@ -1978,7 +1975,6 @@ public:
void StartTrackTimer();
void CompileDBFormula();
- void CompileDBFormula( bool bCreateFormulaString );
void CompileColRowNameFormula();
/** Maximum string length of a column, e.g. for dBase export.
diff --git a/sc/inc/formulacell.hxx b/sc/inc/formulacell.hxx
index cc234c9..b765ff0 100644
--- a/sc/inc/formulacell.hxx
+++ b/sc/inc/formulacell.hxx
@@ -309,7 +309,6 @@ public:
bool IsRunning() const { return bRunning;}
void SetRunning( bool bVal );
void CompileDBFormula( sc::CompileFormulaContext& rCxt );
- void CompileDBFormula( sc::CompileFormulaContext& rCxt, bool bCreateFormulaString );
void CompileColRowNameFormula( sc::CompileFormulaContext& rCxt );
ScFormulaCell* GetPrevious() const { return pPrevious; }
ScFormulaCell* GetNext() const { return pNext; }
diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx
index 9701463..4486d42 100644
--- a/sc/inc/table.hxx
+++ b/sc/inc/table.hxx
@@ -860,9 +860,12 @@ public:
void PreprocessRangeNameUpdate(
sc::EndListeningContext& rEndListenCxt, sc::CompileFormulaContext& rCompileCxt );
- void PostprocessRangeNameUpdate(
+ void CompileHybridFormula(
sc::StartListeningContext& rStartListenCxt, sc::CompileFormulaContext& rCompileCxt );
+ void PreprocessDBDataUpdate(
+ sc::EndListeningContext& rEndListenCxt, sc::CompileFormulaContext& rCompileCxt );
+
ScConditionalFormatList* GetCondFormList();
const ScConditionalFormatList* GetCondFormList() const;
void SetCondFormList( ScConditionalFormatList* pList );
@@ -1045,7 +1048,6 @@ private:
bool GetNextMarkedCell( SCCOL& rCol, SCROW& rRow, const ScMarkData& rMark ) const;
bool TestTabRefAbs(SCTAB nTable) const;
void CompileDBFormula( sc::CompileFormulaContext& rCxt );
- void CompileDBFormula( sc::CompileFormulaContext& rCxt, bool bCreateFormulaString );
void CompileColRowNameFormula( sc::CompileFormulaContext& rCxt );
void StartListening( const ScAddress& rAddress, SvtListener* pListener );
diff --git a/sc/source/core/data/column2.cxx b/sc/source/core/data/column2.cxx
index 2c6c890..082d4a1 100644
--- a/sc/source/core/data/column2.cxx
+++ b/sc/source/core/data/column2.cxx
@@ -2935,21 +2935,6 @@ public:
}
};
-class CompileDBFormula2Handler
-{
- sc::CompileFormulaContext& mrCxt;
- bool mbCreateFormulaString;
-
-public:
- CompileDBFormula2Handler( sc::CompileFormulaContext& rCxt, bool bCreateFormulaString ) :
- mrCxt(rCxt), mbCreateFormulaString(bCreateFormulaString) {}
-
- void operator() (size_t, ScFormulaCell* p)
- {
- p->CompileDBFormula(mrCxt, mbCreateFormulaString);
- }
-};
-
struct CompileColRowNameFormulaHandler
{
sc::CompileFormulaContext& mrCxt;
@@ -2971,13 +2956,6 @@ void ScColumn::CompileDBFormula( sc::CompileFormulaContext& rCxt )
RegroupFormulaCells();
}
-void ScColumn::CompileDBFormula( sc::CompileFormulaContext& rCxt, bool bCreateFormulaString )
-{
- CompileDBFormula2Handler aFunc(rCxt, bCreateFormulaString);
- sc::ProcessFormula(maCells, aFunc);
- RegroupFormulaCells();
-}
-
void ScColumn::CompileColRowNameFormula( sc::CompileFormulaContext& rCxt )
{
CompileColRowNameFormulaHandler aFunc(rCxt);
diff --git a/sc/source/core/data/column4.cxx b/sc/source/core/data/column4.cxx
index a883891..131f8cc 100644
--- a/sc/source/core/data/column4.cxx
+++ b/sc/source/core/data/column4.cxx
@@ -552,15 +552,19 @@ void ScColumn::GetNotesInRange(SCROW nStartRow, SCROW nEndRow,
namespace {
-class PreRangeNameUpdateHandler
+class RecompileByOpcodeHandler
{
ScDocument* mpDoc;
+ const boost::unordered_set<OpCode>& mrOps;
sc::EndListeningContext& mrEndListenCxt;
sc::CompileFormulaContext& mrCompileFormulaCxt;
public:
- PreRangeNameUpdateHandler( ScDocument* pDoc, sc::EndListeningContext& rEndListenCxt, sc::CompileFormulaContext& rCompileCxt ) :
+ RecompileByOpcodeHandler(
+ ScDocument* pDoc, const boost::unordered_set<OpCode>& rOps,
+ sc::EndListeningContext& rEndListenCxt, sc::CompileFormulaContext& rCompileCxt ) :
mpDoc(pDoc),
+ mrOps(rOps),
mrEndListenCxt(rEndListenCxt),
mrCompileFormulaCxt(rCompileCxt) {}
@@ -580,12 +584,7 @@ public:
pTop = rEntry.mpCell;
ScTokenArray* pCode = pTop->GetCode();
-
- boost::unordered_set<OpCode> aOps;
- aOps.insert(ocBad);
- aOps.insert(ocColRowName);
- aOps.insert(ocName);
- bool bRecompile = pCode->HasOpCodes(aOps);
+ bool bRecompile = pCode->HasOpCodes(mrOps);
if (bRecompile)
{
@@ -621,14 +620,14 @@ public:
}
};
-class PostRangeNameUpdateHandler
+class CompileHybridFormulaHandler
{
ScDocument* mpDoc;
sc::StartListeningContext& mrStartListenCxt;
sc::CompileFormulaContext& mrCompileFormulaCxt;
public:
- PostRangeNameUpdateHandler( ScDocument* pDoc, sc::StartListeningContext& rStartListenCxt, sc::CompileFormulaContext& rCompileCxt ) :
+ CompileHybridFormulaHandler( ScDocument* pDoc, sc::StartListeningContext& rStartListenCxt, sc::CompileFormulaContext& rCompileCxt ) :
mpDoc(pDoc),
mrStartListenCxt(rStartListenCxt),
mrCompileFormulaCxt(rCompileCxt) {}
@@ -694,17 +693,35 @@ void ScColumn::PreprocessRangeNameUpdate(
// Collect all formula groups.
std::vector<sc::FormulaGroupEntry> aGroups = GetFormulaGroupEntries();
- PreRangeNameUpdateHandler aFunc(pDocument, rEndListenCxt, rCompileCxt);
+ boost::unordered_set<OpCode> aOps;
+ aOps.insert(ocBad);
+ aOps.insert(ocColRowName);
+ aOps.insert(ocName);
+ RecompileByOpcodeHandler aFunc(pDocument, aOps, rEndListenCxt, rCompileCxt);
+ std::for_each(aGroups.begin(), aGroups.end(), aFunc);
+}
+
+void ScColumn::PreprocessDBDataUpdate(
+ sc::EndListeningContext& rEndListenCxt, sc::CompileFormulaContext& rCompileCxt )
+{
+ // Collect all formula groups.
+ std::vector<sc::FormulaGroupEntry> aGroups = GetFormulaGroupEntries();
+
+ boost::unordered_set<OpCode> aOps;
+ aOps.insert(ocBad);
+ aOps.insert(ocColRowName);
+ aOps.insert(ocDBArea);
+ RecompileByOpcodeHandler aFunc(pDocument, aOps, rEndListenCxt, rCompileCxt);
std::for_each(aGroups.begin(), aGroups.end(), aFunc);
}
-void ScColumn::PostprocessRangeNameUpdate(
+void ScColumn::CompileHybridFormula(
sc::StartListeningContext& rStartListenCxt, sc::CompileFormulaContext& rCompileCxt )
{
// Collect all formula groups.
std::vector<sc::FormulaGroupEntry> aGroups = GetFormulaGroupEntries();
- PostRangeNameUpdateHandler aFunc(pDocument, rStartListenCxt, rCompileCxt);
+ CompileHybridFormulaHandler aFunc(pDocument, rStartListenCxt, rCompileCxt);
std::for_each(aGroups.begin(), aGroups.end(), aFunc);
}
diff --git a/sc/source/core/data/documen4.cxx b/sc/source/core/data/documen4.cxx
index 6c92c54..5b29418 100644
--- a/sc/source/core/data/documen4.cxx
+++ b/sc/source/core/data/documen4.cxx
@@ -548,17 +548,6 @@ void ScDocument::CompileDBFormula()
}
}
-void ScDocument::CompileDBFormula( bool bCreateFormulaString )
-{
- sc::CompileFormulaContext aCxt(this);
- TableContainer::iterator it = maTabs.begin();
- for (;it != maTabs.end(); ++it)
- {
- if (*it)
- (*it)->CompileDBFormula(aCxt, bCreateFormulaString);
- }
-}
-
void ScDocument::CompileColRowNameFormula()
{
sc::CompileFormulaContext aCxt(this);
diff --git a/sc/source/core/data/document10.cxx b/sc/source/core/data/document10.cxx
index d44bc33..eb9a742 100644
--- a/sc/source/core/data/document10.cxx
+++ b/sc/source/core/data/document10.cxx
@@ -252,7 +252,20 @@ void ScDocument::PreprocessRangeNameUpdate()
}
}
-void ScDocument::PostprocessRangeNameUpdate()
+void ScDocument::PreprocessDBDataUpdate()
+{
+ sc::EndListeningContext aEndListenCxt(*this);
+ sc::CompileFormulaContext aCompileCxt(this);
+
+ TableContainer::iterator it = maTabs.begin(), itEnd = maTabs.end();
+ for (; it != itEnd; ++it)
+ {
+ ScTable* p = *it;
+ p->PreprocessDBDataUpdate(aEndListenCxt, aCompileCxt);
+ }
+}
+
+void ScDocument::CompileHybridFormula()
{
sc::StartListeningContext aStartListenCxt(*this);
sc::CompileFormulaContext aCompileCxt(this);
@@ -260,7 +273,7 @@ void ScDocument::PostprocessRangeNameUpdate()
for (; it != itEnd; ++it)
{
ScTable* p = *it;
- p->PostprocessRangeNameUpdate(aStartListenCxt, aCompileCxt);
+ p->CompileHybridFormula(aStartListenCxt, aCompileCxt);
}
}
diff --git a/sc/source/core/data/formulacell.cxx b/sc/source/core/data/formulacell.cxx
index 8d9dee1..3c506ae 100644
--- a/sc/source/core/data/formulacell.cxx
+++ b/sc/source/core/data/formulacell.cxx
@@ -3424,57 +3424,6 @@ void ScFormulaCell::CompileDBFormula( sc::CompileFormulaContext& rCxt )
}
}
-void ScFormulaCell::CompileDBFormula( sc::CompileFormulaContext& rCxt, bool bCreateFormulaString )
-{
- // Two phases must be called after each other
- // 1. Formula String with old generated names
- // 2. Formula String with new generated names
- if ( bCreateFormulaString )
- {
- bool bRecompile = false;
- pCode->Reset();
- for ( FormulaToken* p = pCode->First(); p && !bRecompile; p = pCode->Next() )
- {
- switch ( p->GetOpCode() )
- {
- case ocBad: // DB Area eventually goes bad
- case ocColRowName: // in case of the same names
- case ocDBArea: // DB Area
- bRecompile = true;
- break;
- case ocName:
- if ( p->GetIndex() >= SC_START_INDEX_DB_COLL )
- bRecompile = true; // DB Area
- break;
- default:
- ; // nothing
- }
- }
- if ( bRecompile )
- {
- OUString aFormula = GetFormula(rCxt);
- if ( GetMatrixFlag() != MM_NONE && !aFormula.isEmpty() )
- {
- if ( aFormula[ aFormula.getLength()-1 ] == '}' )
- aFormula = aFormula.copy( 0, aFormula.getLength()-1 );
- if ( aFormula[0] == '{' )
- aFormula = aFormula.copy( 1 );
- }
- EndListeningTo( pDocument );
- pDocument->RemoveFromFormulaTree( this );
- pCode->Clear();
- SetHybridFormula(aFormula, rCxt.getGrammar());
- }
- }
- else if ( !pCode->GetLen() && !aResult.GetHybridFormula().isEmpty() )
- {
- rCxt.setGrammar(eTempGrammar);
- Compile(rCxt, aResult.GetHybridFormula(), false);
- aResult.SetToken( NULL);
- SetDirty();
- }
-}
-
void ScFormulaCell::CompileColRowNameFormula( sc::CompileFormulaContext& rCxt )
{
pCode->Reset();
diff --git a/sc/source/core/data/table4.cxx b/sc/source/core/data/table4.cxx
index 48b475e..02d1664 100644
--- a/sc/source/core/data/table4.cxx
+++ b/sc/source/core/data/table4.cxx
@@ -2169,12 +2169,6 @@ void ScTable::CompileDBFormula( sc::CompileFormulaContext& rCxt )
aCol[i].CompileDBFormula(rCxt);
}
-void ScTable::CompileDBFormula( sc::CompileFormulaContext& rCxt, bool bCreateFormulaString )
-{
- for (SCCOL i = 0; i <= MAXCOL; ++i)
- aCol[i].CompileDBFormula(rCxt, bCreateFormulaString);
-}
-
void ScTable::CompileColRowNameFormula( sc::CompileFormulaContext& rCxt )
{
for (SCCOL i = 0; i <= MAXCOL; ++i)
diff --git a/sc/source/core/data/table7.cxx b/sc/source/core/data/table7.cxx
index 6ff53de..6763565 100644
--- a/sc/source/core/data/table7.cxx
+++ b/sc/source/core/data/table7.cxx
@@ -89,11 +89,18 @@ void ScTable::PreprocessRangeNameUpdate(
aCol[i].PreprocessRangeNameUpdate(rEndListenCxt, rCompileCxt);
}
-void ScTable::PostprocessRangeNameUpdate(
+void ScTable::PreprocessDBDataUpdate(
+ sc::EndListeningContext& rEndListenCxt, sc::CompileFormulaContext& rCompileCxt )
+{
+ for (SCCOL i = 0; i <= MAXCOL; ++i)
+ aCol[i].PreprocessDBDataUpdate(rEndListenCxt, rCompileCxt);
+}
+
+void ScTable::CompileHybridFormula(
sc::StartListeningContext& rStartListenCxt, sc::CompileFormulaContext& rCompileCxt )
{
for (SCCOL i = 0; i <= MAXCOL; ++i)
- aCol[i].PostprocessRangeNameUpdate(rStartListenCxt, rCompileCxt);
+ aCol[i].CompileHybridFormula(rStartListenCxt, rCompileCxt);
}
void ScTable::UpdateScriptTypes( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2 )
diff --git a/sc/source/ui/docshell/dbdocfun.cxx b/sc/source/ui/docshell/dbdocfun.cxx
index 0ecb0aa..d22ce07 100644
--- a/sc/source/ui/docshell/dbdocfun.cxx
+++ b/sc/source/ui/docshell/dbdocfun.cxx
@@ -77,7 +77,7 @@ bool ScDBDocFunc::AddDBRange( const OUString& rName, const ScRange& rRange, bool
bool bCompile = !rDoc.IsImportingXML();
bool bOk;
if ( bCompile )
- rDoc.CompileDBFormula( true ); // CreateFormulaString
+ rDoc.PreprocessDBDataUpdate();
if ( rName == STR_DB_LOCAL_NONAME )
{
rDoc.SetAnonymousDBData(rRange.aStart.Tab() , pNew);
@@ -88,7 +88,7 @@ bool ScDBDocFunc::AddDBRange( const OUString& rName, const ScRange& rRange, bool
bOk = pDocColl->getNamedDBs().insert(pNew);
}
if ( bCompile )
- rDoc.CompileDBFormula( false ); // CompileFormulaString
+ rDoc.CompileHybridFormula();
if (!bOk)
{
@@ -126,9 +126,9 @@ bool ScDBDocFunc::DeleteDBRange(const OUString& rName)
if (bUndo)
pUndoColl = new ScDBCollection( *pDocColl );
- rDoc.CompileDBFormula( true ); // CreateFormulaString
+ rDoc.PreprocessDBDataUpdate();
rDBs.erase(*p);
- rDoc.CompileDBFormula( false ); // CompileFormulaString
+ rDoc.CompileHybridFormula();
if (bUndo)
{
@@ -162,7 +162,7 @@ bool ScDBDocFunc::RenameDBRange( const OUString& rOld, const OUString& rNew )
ScDBCollection* pUndoColl = new ScDBCollection( *pDocColl );
- rDoc.CompileDBFormula(true); // CreateFormulaString
+ rDoc.PreprocessDBDataUpdate();
rDBs.erase(*pOld);
bool bInserted = rDBs.insert(pNewData);
if (!bInserted) // Fehler -> alten Zustand wiederherstellen
@@ -171,7 +171,7 @@ bool ScDBDocFunc::RenameDBRange( const OUString& rOld, const OUString& rNew )
rDoc.SetDBCollection(pUndoColl); // gehoert dann dem Dokument
}
- rDoc.CompileDBFormula( false ); // CompileFormulaString
+ rDoc.CompileHybridFormula();
if (bInserted) // Einfuegen hat geklappt
{
@@ -264,9 +264,9 @@ void ScDBDocFunc::ModifyAllDBData( const ScDBCollection& rNewColl, const std::ve
// register target in SBA no longer necessary
- rDoc.CompileDBFormula( true ); // CreateFormulaString
+ rDoc.PreprocessDBDataUpdate();
rDoc.SetDBCollection( new ScDBCollection( rNewColl ) );
- rDoc.CompileDBFormula( false ); // CompileFormulaString
+ rDoc.CompileHybridFormula();
pOldColl = NULL;
rDocShell.PostPaint(ScRange(0, 0, 0, MAXCOL, MAXROW, MAXTAB), PAINT_GRID);
aModificator.SetDocumentModified();
diff --git a/sc/source/ui/docshell/docfunc.cxx b/sc/source/ui/docshell/docfunc.cxx
index fd1d5ce..adce808 100644
--- a/sc/source/ui/docshell/docfunc.cxx
+++ b/sc/source/ui/docshell/docfunc.cxx
@@ -4838,7 +4838,7 @@ bool ScDocFunc::SetNewRangeNames( ScRangeName* pNewRanges, bool bModifyDoc, SCTA
else
rDoc.SetRangeName( pNewRanges ); // takes ownership
if ( bCompile )
- rDoc.PostprocessRangeNameUpdate();
+ rDoc.CompileHybridFormula();
if (bModifyDoc)
{
@@ -4864,7 +4864,7 @@ void ScDocFunc::ModifyAllRangeNames( const boost::ptr_map<OUString, ScRangeName>
rDoc.PreprocessRangeNameUpdate();
rDoc.SetAllRangeNames(rRangeMap);
- rDoc.PostprocessRangeNameUpdate();
+ rDoc.CompileHybridFormula();
aModificator.SetDocumentModified();
SfxGetpApp()->Broadcast(SfxSimpleHint(SC_HINT_AREAS_CHANGED));
diff --git a/sc/source/ui/docshell/docsh5.cxx b/sc/source/ui/docshell/docsh5.cxx
index a46e426..f0bb58f 100644
--- a/sc/source/ui/docshell/docsh5.cxx
+++ b/sc/source/ui/docshell/docsh5.cxx
@@ -254,7 +254,7 @@ ScDBData* ScDocShell::GetDBData( const ScRange& rMarked, ScGetDBMode eMode, ScGe
OUString aNewName;
if (eMode==SC_DB_IMPORT)
{
- aDocument.CompileDBFormula( true ); // CreateFormulaString
+ aDocument.PreprocessDBDataUpdate();
pUndoColl = new ScDBCollection( *pColl ); // Undo fuer Import1-Bereich
OUString aImport = ScGlobal::GetRscString( STR_DBNAME_IMPORT );
@@ -286,7 +286,7 @@ ScDBData* ScDocShell::GetDBData( const ScRange& rMarked, ScGetDBMode eMode, ScGe
if ( pUndoColl )
{
- aDocument.CompileDBFormula( false ); // CompileFormulaString
+ aDocument.CompileHybridFormula();
ScDBCollection* pRedoColl = new ScDBCollection( *pColl );
GetUndoManager()->AddUndoAction( new ScUndoDBData( this, pUndoColl, pRedoColl ) );
diff --git a/sc/source/ui/undo/undocell.cxx b/sc/source/ui/undo/undocell.cxx
index 5ece768..bc37706 100644
--- a/sc/source/ui/undo/undocell.cxx
+++ b/sc/source/ui/undo/undocell.cxx
@@ -1008,7 +1008,7 @@ void ScUndoRangeNames::DoChange( bool bUndo )
rDoc.SetRangeName( new ScRangeName( *pNewRanges ) );
}
- rDoc.PostprocessRangeNameUpdate();
+ rDoc.CompileHybridFormula();
SfxGetpApp()->Broadcast( SfxSimpleHint( SC_HINT_AREAS_CHANGED ) );
}
diff --git a/sc/source/ui/undo/undodat.cxx b/sc/source/ui/undo/undodat.cxx
index 4f4d165..ac1b8fd 100644
--- a/sc/source/ui/undo/undodat.cxx
+++ b/sc/source/ui/undo/undodat.cxx
@@ -1013,9 +1013,9 @@ void ScUndoDBData::Undo()
bool bOldAutoCalc = rDoc.GetAutoCalc();
rDoc.SetAutoCalc( false ); // Avoid unnecessary calculations
- rDoc.CompileDBFormula( true ); // CreateFormulaString
+ rDoc.PreprocessDBDataUpdate();
rDoc.SetDBCollection( new ScDBCollection(*pUndoColl), true );
- rDoc.CompileDBFormula( false ); // CompileFormulaString
+ rDoc.CompileHybridFormula();
rDoc.SetAutoCalc( bOldAutoCalc );
SfxGetpApp()->Broadcast( SfxSimpleHint( SC_HINT_DBAREAS_CHANGED ) );
@@ -1031,9 +1031,9 @@ void ScUndoDBData::Redo()
bool bOldAutoCalc = rDoc.GetAutoCalc();
rDoc.SetAutoCalc( false ); // Avoid unnecessary calculations
- rDoc.CompileDBFormula( true ); // CreateFormulaString
+ rDoc.PreprocessDBDataUpdate();
rDoc.SetDBCollection( new ScDBCollection(*pRedoColl), true );
- rDoc.CompileDBFormula( false ); // CompileFormulaString
+ rDoc.CompileHybridFormula();
rDoc.SetAutoCalc( bOldAutoCalc );
SfxGetpApp()->Broadcast( SfxSimpleHint( SC_HINT_DBAREAS_CHANGED ) );
diff --git a/sc/source/ui/undo/undorangename.cxx b/sc/source/ui/undo/undorangename.cxx
index 8eafa6b..790661f 100644
--- a/sc/source/ui/undo/undorangename.cxx
+++ b/sc/source/ui/undo/undorangename.cxx
@@ -78,7 +78,7 @@ void ScUndoAllRangeNames::DoChange(const boost::ptr_map<OUString, ScRangeName>&
rDoc.PreprocessRangeNameUpdate();
rDoc.SetAllRangeNames(rNames);
- rDoc.PostprocessRangeNameUpdate();
+ rDoc.CompileHybridFormula();
SfxGetpApp()->Broadcast(SfxSimpleHint(SC_HINT_AREAS_CHANGED));
}
diff --git a/sc/source/ui/unoobj/nameuno.cxx b/sc/source/ui/unoobj/nameuno.cxx
index cc6fdea..ff09c0e 100644
--- a/sc/source/ui/unoobj/nameuno.cxx
+++ b/sc/source/ui/unoobj/nameuno.cxx
@@ -740,7 +740,7 @@ void ScNamedRangesObj::lock()
/** called from the XActionLockable interface methods on final unlock */
void ScNamedRangesObj::unlock()
{
- pDocShell->GetDocument().PostprocessRangeNameUpdate();
+ pDocShell->GetDocument().CompileHybridFormula();
}
// document::XActionLockable
diff --git a/sc/source/ui/view/viewfunc.cxx b/sc/source/ui/view/viewfunc.cxx
index 1e4ba7f..c3359a0 100644
--- a/sc/source/ui/view/viewfunc.cxx
+++ b/sc/source/ui/view/viewfunc.cxx
@@ -2783,7 +2783,7 @@ bool ScViewFunc::InsertName( const OUString& rName, const OUString& rSymbol,
bOk = true;
pNewEntry = NULL; // never delete, insert took ownership
- rDoc.PostprocessRangeNameUpdate();
+ rDoc.CompileHybridFormula();
aModificator.SetDocumentModified();
SfxGetpApp()->Broadcast( SfxSimpleHint( SC_HINT_AREAS_CHANGED ) );
commit a0b9200eed928ac81d798bd59aed69ed6d470bac
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date: Mon Jul 28 19:16:12 2014 -0400
fdo#79578: Write test for this first.
Change-Id: I46ccf0954f9397779244132488d93f3162cf04d6
diff --git a/sc/qa/unit/ucalc.hxx b/sc/qa/unit/ucalc.hxx
index 3197990..880fde6 100644
--- a/sc/qa/unit/ucalc.hxx
+++ b/sc/qa/unit/ucalc.hxx
@@ -299,6 +299,7 @@ public:
void testSharedFormulaInsertColumn();
void testSharedFormulaMoveBlock();
void testSharedFormulaUpdateOnNamedRangeChange();
+ void testSharedFormulaUpdateOnDBChange();
void testFormulaPosition();
void testMixData();
@@ -503,6 +504,7 @@ public:
CPPUNIT_TEST(testSharedFormulasCopyPaste);
CPPUNIT_TEST(testSharedFormulaInsertColumn);
CPPUNIT_TEST(testSharedFormulaUpdateOnNamedRangeChange);
+ CPPUNIT_TEST(testSharedFormulaUpdateOnDBChange);
CPPUNIT_TEST(testFormulaPosition);
CPPUNIT_TEST(testMixData);
CPPUNIT_TEST(testJumpToPrecedentsDependents);
diff --git a/sc/qa/unit/ucalc_sharedformula.cxx b/sc/qa/unit/ucalc_sharedformula.cxx
index 06c09b0..b4babd6 100644
--- a/sc/qa/unit/ucalc_sharedformula.cxx
+++ b/sc/qa/unit/ucalc_sharedformula.cxx
@@ -16,9 +16,11 @@
#include "undoblk.hxx"
#include "scopetools.hxx"
#include <docfunc.hxx>
+#include <dbdocfun.hxx>
#include <tokenarray.hxx>
#include <tokenstringcontext.hxx>
#include <globalnames.hxx>
+#include <dbdata.hxx>
#include <svl/sharedstring.hxx>
@@ -1307,4 +1309,70 @@ void Test::testSharedFormulaUpdateOnNamedRangeChange()
m_pDoc->DeleteTab(0);
}
+void Test::testSharedFormulaUpdateOnDBChange()
+{
+ sc::AutoCalcSwitch aACSwitch(*m_pDoc, true); // turn on auto calc.
+
+ m_pDoc->InsertTab(0, "RangeTest");
+
+ // Put 1, 2, 3, 4 in A1:A4.
+ for (SCROW i = 0; i <= 3; ++i)
+ m_pDoc->SetValue(ScAddress(0,i,0), (i+1));
+
+ ScDBCollection* pDBs = m_pDoc->GetDBCollection();
+ CPPUNIT_ASSERT_MESSAGE("Failed to fetch DB collection object.", pDBs);
+
+ // Define database range 'MyRange' for A1:A2.
+ ScDBData* pData = new ScDBData("MyRange", 0, 0, 0, 0, 1);
+ bool bInserted = pDBs->getNamedDBs().insert(pData);
+ CPPUNIT_ASSERT_MESSAGE("Failed to insert a new database range.", bInserted);
+
+ // Insert in C2:C4 a group of formula cells that reference MyRange.
+ for (SCROW i = 1; i <= 3; ++i)
+ m_pDoc->SetString(ScAddress(2,i,0), "=SUM(MyRange)");
+
+ // Make sure C2:C4 is a formula group.
+ const ScFormulaCell* pFC = m_pDoc->GetFormulaCell(ScAddress(2,1,0));
+ CPPUNIT_ASSERT(pFC);
+ CPPUNIT_ASSERT(pFC->IsSharedTop());
+ CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(3), pFC->GetSharedLength());
+
+ // Check the initial formula results.
+ CPPUNIT_ASSERT_EQUAL(3.0, m_pDoc->GetValue(ScAddress(2,1,0)));
+ CPPUNIT_ASSERT_EQUAL(3.0, m_pDoc->GetValue(ScAddress(2,2,0)));
+ CPPUNIT_ASSERT_EQUAL(3.0, m_pDoc->GetValue(ScAddress(2,3,0)));
+
+ ScDBDocFunc aFunc(getDocShell());
+
+ // Change the range referenced by MyRange to A1:A4.
+ ScDBCollection aNewDBs(m_pDoc);
+ bInserted = aNewDBs.getNamedDBs().insert(new ScDBData("MyRange", 0, 0, 0, 0, 3));
+ CPPUNIT_ASSERT_MESSAGE("Failed to insert a new database range.", bInserted);
+
+ std::vector<ScRange> aDeleted;
+ aFunc.ModifyAllDBData(aNewDBs, aDeleted);
+
+ // Check the updated formula results.
+ CPPUNIT_ASSERT_EQUAL(10.0, m_pDoc->GetValue(ScAddress(2,1,0)));
+ CPPUNIT_ASSERT_EQUAL(10.0, m_pDoc->GetValue(ScAddress(2,2,0)));
+ CPPUNIT_ASSERT_EQUAL(10.0, m_pDoc->GetValue(ScAddress(2,3,0)));
+
+ SfxUndoManager* pUndoMgr = m_pDoc->GetUndoManager();
+ CPPUNIT_ASSERT(pUndoMgr);
+
+ // Undo and check the results.
+ pUndoMgr->Undo();
+ CPPUNIT_ASSERT_EQUAL(3.0, m_pDoc->GetValue(ScAddress(2,1,0)));
+ CPPUNIT_ASSERT_EQUAL(3.0, m_pDoc->GetValue(ScAddress(2,2,0)));
+ CPPUNIT_ASSERT_EQUAL(3.0, m_pDoc->GetValue(ScAddress(2,3,0)));
+
+ // Redo and check the results.
+ pUndoMgr->Redo();
+ CPPUNIT_ASSERT_EQUAL(10.0, m_pDoc->GetValue(ScAddress(2,1,0)));
+ CPPUNIT_ASSERT_EQUAL(10.0, m_pDoc->GetValue(ScAddress(2,2,0)));
+ CPPUNIT_ASSERT_EQUAL(10.0, m_pDoc->GetValue(ScAddress(2,3,0)));
+
+ m_pDoc->DeleteTab(0);
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit ab409bf7fbe8a9af75fdd253a760ffbaf92a8376
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date: Mon Jul 28 17:54:24 2014 -0400
Move this fucntion to ScDBDocFunc.
so that it could be usable from unit test.
Change-Id: Iea10cb473bc17d7e030c018fd2c84fbeccce3e47
diff --git a/sc/source/ui/dbgui/dbnamdlg.cxx b/sc/source/ui/dbgui/dbnamdlg.cxx
index b49a148..c70040f 100644
--- a/sc/source/ui/dbgui/dbnamdlg.cxx
+++ b/sc/source/ui/dbgui/dbnamdlg.cxx
@@ -31,6 +31,7 @@
#include "rangenam.hxx"
#include "globalnames.hxx"
#include "dbnamdlg.hxx"
+#include <dbdocfun.hxx>
#define ABS_SREF SCA_VALID \
| SCA_COL_ABSOLUTE | SCA_ROW_ABSOLUTE | SCA_TAB_ABSOLUTE
@@ -373,8 +374,10 @@ IMPL_LINK_NOARG(ScDbNameDlg, OkBtnHdl)
// beide werden nur als Referenz uebergeben, so dass an dieser
// Stelle keine Speicherleichen entstehen koennen:
if ( pViewData )
- pViewData->GetView()->
- NotifyCloseDbNameDlg( aLocalDbCol, aRemoveList );
+ {
+ ScDBDocFunc aFunc(*pViewData->GetDocShell());
+ aFunc.ModifyAllDBData(aLocalDbCol, aRemoveList);
+ }
Close();
return 0;
diff --git a/sc/source/ui/docshell/dbdocfun.cxx b/sc/source/ui/docshell/dbdocfun.cxx
index 187621d..0ecb0aa 100644
--- a/sc/source/ui/docshell/dbdocfun.cxx
+++ b/sc/source/ui/docshell/dbdocfun.cxx
@@ -241,6 +241,45 @@ bool ScDBDocFunc::ModifyDBData( const ScDBData& rNewData )
return bDone;
}
+void ScDBDocFunc::ModifyAllDBData( const ScDBCollection& rNewColl, const std::vector<ScRange>& rDelAreaList )
+{
+ ScDocShellModificator aModificator(rDocShell);
+ ScDocument& rDoc = rDocShell.GetDocument();
+ ScDBCollection* pOldColl = rDoc.GetDBCollection();
+ ScDBCollection* pUndoColl = NULL;
+ bool bRecord = rDoc.IsUndoEnabled();
+
+ std::vector<ScRange>::const_iterator iter;
+ for (iter = rDelAreaList.begin(); iter != rDelAreaList.end(); ++iter)
+ {
+ // unregistering target in SBA no longer necessary
+ const ScAddress& rStart = iter->aStart;
+ const ScAddress& rEnd = iter->aEnd;
+ rDocShell.DBAreaDeleted(
+ rStart.Tab(), rStart.Col(), rStart.Row(), rEnd.Col(), rEnd.Row());
+ }
+
+ if (bRecord)
+ pUndoColl = new ScDBCollection( *pOldColl );
+
+ // register target in SBA no longer necessary
+
+ rDoc.CompileDBFormula( true ); // CreateFormulaString
+ rDoc.SetDBCollection( new ScDBCollection( rNewColl ) );
+ rDoc.CompileDBFormula( false ); // CompileFormulaString
+ pOldColl = NULL;
+ rDocShell.PostPaint(ScRange(0, 0, 0, MAXCOL, MAXROW, MAXTAB), PAINT_GRID);
+ aModificator.SetDocumentModified();
+ SfxGetpApp()->Broadcast( SfxSimpleHint( SC_HINT_DBAREAS_CHANGED ) );
+
+ if (bRecord)
+ {
+ ScDBCollection* pRedoColl = new ScDBCollection(rNewColl);
+ rDocShell.GetUndoManager()->AddUndoAction(
+ new ScUndoDBData(&rDocShell, pUndoColl, pRedoColl));
+ }
+}
+
bool ScDBDocFunc::RepeatDB( const OUString& rDBName, bool bRecord, bool bApi, bool bIsUnnamed, SCTAB aTab )
{
//! auch fuer ScDBFunc::RepeatDB benutzen!
diff --git a/sc/source/ui/inc/dbdocfun.hxx b/sc/source/ui/inc/dbdocfun.hxx
index 13fd9bc..714a2db 100644
--- a/sc/source/ui/inc/dbdocfun.hxx
+++ b/sc/source/ui/inc/dbdocfun.hxx
@@ -35,6 +35,7 @@ class ScDocShell;
class ScAddress;
class ScRange;
class ScDPObject;
+class ScDBCollection;
namespace com { namespace sun { namespace star {
namespace beans {
@@ -85,6 +86,8 @@ public:
bool RenameDBRange( const OUString& rOld, const OUString& rNew );
bool ModifyDBData( const ScDBData& rNewData ); // Name unveraendert
+ void ModifyAllDBData( const ScDBCollection& rNewColl, const std::vector<ScRange>& rDelAreaList );
+
bool RepeatDB( const OUString& rDBName, bool bRecord, bool bApi, bool bIsUnnamed=false, SCTAB aTab = 0);
bool DataPilotUpdate( ScDPObject* pOldObj, const ScDPObject* pNewObj,
diff --git a/sc/source/ui/inc/dbfunc.hxx b/sc/source/ui/inc/dbfunc.hxx
index 0e3b197..72c376c 100644
--- a/sc/source/ui/inc/dbfunc.hxx
+++ b/sc/source/ui/inc/dbfunc.hxx
@@ -70,8 +70,6 @@ public:
ScDBData* GetDBData( bool bMarkArea = true, ScGetDBMode eMode = SC_DB_MAKE, ScGetDBSelection eSel = SC_DBSEL_KEEP);
ScDBData* GetAnonymousDBData();
- void NotifyCloseDbNameDlg( const ScDBCollection& rNewColl, const std::vector<ScRange> &rDelAreaList );
-
void Consolidate( const ScConsolidateParam& rParam, bool bRecord = true );
bool MakePivotTable(
diff --git a/sc/source/ui/view/dbfunc.cxx b/sc/source/ui/view/dbfunc.cxx
index a1a5fc2..50d638c 100644
--- a/sc/source/ui/view/dbfunc.cxx
+++ b/sc/source/ui/view/dbfunc.cxx
@@ -191,51 +191,6 @@ ScDBData* ScDBFunc::GetAnonymousDBData()
return pDocSh->GetAnonymousDBData(aRange);
}
-// change database range (dialog)
-
-void ScDBFunc::NotifyCloseDbNameDlg( const ScDBCollection& rNewColl, const std::vector<ScRange> &rDelAreaList )
-{
-
- ScDocShell* pDocShell = GetViewData().GetDocShell();
- ScDocShellModificator aModificator( *pDocShell );
- ScDocument& rDoc = pDocShell->GetDocument();
- ScDBCollection* pOldColl = rDoc.GetDBCollection();
- ScDBCollection* pUndoColl = NULL;
- const bool bRecord (rDoc.IsUndoEnabled());
-
- std::vector<ScRange>::const_iterator iter;
- for (iter = rDelAreaList.begin(); iter != rDelAreaList.end(); ++iter)
- {
- // unregistering target in SBA no longer necessary
- const ScAddress& rStart = iter->aStart;
- const ScAddress& rEnd = iter->aEnd;
- pDocShell->DBAreaDeleted( rStart.Tab(),
- rStart.Col(), rStart.Row(),
- rEnd.Col(), rEnd.Row() );
-
- }
-
- if (bRecord)
- pUndoColl = new ScDBCollection( *pOldColl );
-
- // register target in SBA no longer necessary
-
- rDoc.CompileDBFormula( true ); // CreateFormulaString
- rDoc.SetDBCollection( new ScDBCollection( rNewColl ) );
- rDoc.CompileDBFormula( false ); // CompileFormulaString
- pOldColl = NULL;
- pDocShell->PostPaint(ScRange(0, 0, 0, MAXCOL, MAXROW, MAXTAB), PAINT_GRID);
- aModificator.SetDocumentModified();
- SfxGetpApp()->Broadcast( SfxSimpleHint( SC_HINT_DBAREAS_CHANGED ) );
-
- if (bRecord)
- {
- ScDBCollection* pRedoColl = new ScDBCollection( rNewColl );
- pDocShell->GetUndoManager()->AddUndoAction(
- new ScUndoDBData( pDocShell, pUndoColl, pRedoColl ) );
- }
-}
-
// main functions
// Sort
More information about the Libreoffice-commits
mailing list