summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2015-09-02 19:31:29 +0200
committerEike Rathke <erack@redhat.com>2015-09-03 00:09:02 +0200
commit834eddc8f75fa73b36f3ab5804104829809d8949 (patch)
tree26714708f1763c4e32cdff7b868a16f3277a5604
parent1cb61611c2308df86bf9acfafe25faff624dad26 (diff)
TableRef: add RefreshTableColumnNames() from range
Change-Id: I32a47e306469aec5fe366a6621129e14b0d49c13
-rw-r--r--sc/inc/dbdata.hxx6
-rw-r--r--sc/inc/document.hxx1
-rw-r--r--sc/source/core/data/documen3.cxx6
-rw-r--r--sc/source/core/tool/dbdata.cxx42
-rw-r--r--sc/source/ui/docshell/docsh.cxx5
5 files changed, 60 insertions, 0 deletions
diff --git a/sc/inc/dbdata.hxx b/sc/inc/dbdata.hxx
index efe0d2f5052e..22ccc329886e 100644
--- a/sc/inc/dbdata.hxx
+++ b/sc/inc/dbdata.hxx
@@ -125,6 +125,10 @@ public:
/** Refresh/update the column names with the header row's cell contents. */
SC_DLLPUBLIC void RefreshTableColumnNames( ScDocument* pDoc );
+ /** Refresh/update the column names with the header row's cell contents
+ within the given range. */
+ void RefreshTableColumnNames( ScDocument* pDoc, const ScRange& rRange );
+
/** Finds the column named rName and returns the corresponding offset
within the table.
@returns -1 if not found.
@@ -283,6 +287,8 @@ public:
ScDBData* GetDBAtArea(SCTAB nTab, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2);
ScDBData* GetDBNearCursor(SCCOL nCol, SCROW nRow, SCTAB nTab );
+ void RefreshTableColumnNames( const ScRange& rRange );
+
void DeleteOnTab( SCTAB nTab );
void UpdateReference(UpdateRefMode eUpdateRefMode,
SCCOL nCol1, SCROW nRow1, SCTAB nTab1,
diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx
index 9ea6729f6377..c19bc6feceac 100644
--- a/sc/inc/document.hxx
+++ b/sc/inc/document.hxx
@@ -570,6 +570,7 @@ public:
ScDBData* GetDBAtCursor(SCCOL nCol, SCROW nRow, SCTAB nTab, ScDBDataPortion ePortion);
const ScDBData* GetDBAtArea(SCTAB nTab, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2) const;
ScDBData* GetDBAtArea(SCTAB nTab, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2);
+ void RefreshTableColumnNames( const ScRange& rRange );
SC_DLLPUBLIC const ScRangeData* GetRangeAtBlock( const ScRange& rBlock, OUString* pName=NULL ) const;
diff --git a/sc/source/core/data/documen3.cxx b/sc/source/core/data/documen3.cxx
index 32791dab34d1..53dff9231cb8 100644
--- a/sc/source/core/data/documen3.cxx
+++ b/sc/source/core/data/documen3.cxx
@@ -313,6 +313,12 @@ ScDBData* ScDocument::GetDBAtArea(SCTAB nTab, SCCOL nCol1, SCROW nRow1, SCCOL nC
return NULL;
}
+void ScDocument::RefreshTableColumnNames( const ScRange& rRange )
+{
+ if (pDBCollection)
+ pDBCollection->RefreshTableColumnNames( rRange);
+}
+
bool ScDocument::HasPivotTable() const
{
return pDPCollection && pDPCollection->GetCount();
diff --git a/sc/source/core/tool/dbdata.cxx b/sc/source/core/tool/dbdata.cxx
index 825e6ca51124..cf86a1e67d2f 100644
--- a/sc/source/core/tool/dbdata.cxx
+++ b/sc/source/core/tool/dbdata.cxx
@@ -728,6 +728,42 @@ void ScDBData::RefreshTableColumnNames( ScDocument* pDoc )
aNewNames.swap( maTableColumnNames);
}
+void ScDBData::RefreshTableColumnNames( ScDocument* pDoc, const ScRange& rRange )
+{
+ if (!HasHeader())
+ return;
+
+ ScRange aRange( ScAddress::UNINITIALIZED);
+ GetArea( aRange);
+ aRange.aEnd.SetRow( aRange.aStart.Row());
+ ScRange aIntersection( aRange.Intersection( rRange));
+ if (!aIntersection.IsValid())
+ return;
+
+ if (maTableColumnNames.empty())
+ {
+ RefreshTableColumnNames( pDoc);
+ return;
+ }
+
+ // Update column names from cells in intersecting header range, but don't
+ // set names to empty string.
+ ScHorizontalCellIterator aIter( pDoc, nTable,
+ aIntersection.aStart.Col(), nStartRow, aIntersection.aEnd.Col(), nStartRow);
+ ScRefCellValue* pCell;
+ SCCOL nCol;
+ SCROW nRow;
+ for (size_t i=0; (pCell = aIter.GetNext( nCol, nRow)) != nullptr; ++i)
+ {
+ if (pCell->hasString())
+ {
+ const OUString& rStr = pCell->getString( pDoc);
+ if (!rStr.isEmpty())
+ maTableColumnNames[nCol-nStartCol] = rStr;
+ }
+ }
+}
+
sal_Int32 ScDBData::GetColumnNameOffset( const OUString& rName ) const
{
if (maTableColumnNames.empty())
@@ -1173,6 +1209,12 @@ ScDBData* ScDBCollection::GetDBAtArea(SCTAB nTab, SCCOL nCol1, SCROW nRow1, SCCO
return NULL;
}
+void ScDBCollection::RefreshTableColumnNames( const ScRange& rRange )
+{
+ for (auto const& it : maNamedDBs)
+ it->RefreshTableColumnNames( pDoc, rRange);
+}
+
void ScDBCollection::DeleteOnTab( SCTAB nTab )
{
FindByTable func(nTab);
diff --git a/sc/source/ui/docshell/docsh.cxx b/sc/source/ui/docshell/docsh.cxx
index db72e8e4421c..5acd5b4ec9c1 100644
--- a/sc/source/ui/docshell/docsh.cxx
+++ b/sc/source/ui/docshell/docsh.cxx
@@ -3067,6 +3067,11 @@ ScDocShellModificator::ScDocShellModificator( ScDocShell& rDS )
ScDocShellModificator::~ScDocShellModificator()
{
ScDocument& rDoc = rDocShell.GetDocument();
+ if (!mvContentModified.empty() && !rDoc.IsImportingXML())
+ {
+ for (auto const& it : mvContentModified)
+ rDoc.RefreshTableColumnNames( it);
+ }
rDoc.SetAutoCalcShellDisabled( bAutoCalcShellDisabled );
if ( !bAutoCalcShellDisabled && rDocShell.IsDocumentModifiedPending() )
rDocShell.SetDocumentModified(); // last one shuts off the lights