diff options
author | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2013-11-24 21:22:20 +0100 |
---|---|---|
committer | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2013-11-24 21:24:36 +0100 |
commit | 288be67406110dc5e0f957d79fcf775076ee513c (patch) | |
tree | 10f942b909e4c861f03bfe07899901f6fa123676 | |
parent | 718de51eb9f567fa433ac216114f5e6f16236209 (diff) |
checking every cell on a sheet is expensive, related fdo#71934
This is only the first of two places that does this.
Change-Id: I57fe1eb07630ecd86b112e88b7ad32c16e9f793a
-rw-r--r-- | sc/inc/document.hxx | 1 | ||||
-rw-r--r-- | sc/inc/table.hxx | 1 | ||||
-rw-r--r-- | sc/source/core/data/document.cxx | 16 | ||||
-rw-r--r-- | sc/source/core/data/table2.cxx | 14 | ||||
-rw-r--r-- | sc/source/ui/view/cellsh.cxx | 17 |
5 files changed, 33 insertions, 16 deletions
diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx index 49fd5713618d..b9e3dc3b6d38 100644 --- a/sc/inc/document.hxx +++ b/sc/inc/document.hxx @@ -909,6 +909,7 @@ public: SCROW GetNotePosition( SCTAB nTab, SCCOL nCol, size_t nIndex ) const; SC_DLLPUBLIC void GetAllNoteEntries( std::vector<sc::NoteEntry>& rNotes ) const; + bool ContainsNotesInRange( const ScRangeList& rRange ) const; SC_DLLPUBLIC void SetDrawPageSize(SCTAB nTab); diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx index 8eb75becd4d4..5938dcb2277c 100644 --- a/sc/inc/table.hxx +++ b/sc/inc/table.hxx @@ -382,6 +382,7 @@ public: SCROW GetNotePosition( SCCOL nCol, size_t nIndex ) const; void GetAllNoteEntries( std::vector<sc::NoteEntry>& rNotes ) const; + bool ContainsNotesInRange( const ScRange& rRange ) const; bool TestInsertRow( SCCOL nStartCol, SCCOL nEndCol, SCROW nStartRow, SCSIZE nSize ) const; void InsertRow( SCCOL nStartCol, SCCOL nEndCol, SCROW nStartRow, SCSIZE nSize ); diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx index 80696e4bd0ed..708300e72a88 100644 --- a/sc/source/core/data/document.cxx +++ b/sc/source/core/data/document.cxx @@ -6226,6 +6226,22 @@ void ScDocument::GetAllNoteEntries( std::vector<sc::NoteEntry>& rNotes ) const } } +bool ScDocument::ContainsNotesInRange( const ScRangeList& rRange ) const +{ + for( size_t i = 0; i < rRange.size(); ++i) + { + const ScRange* pRange = rRange[i]; + for( SCTAB nTab = pRange->aStart.Tab(); nTab < pRange->aEnd.Tab(); ++nTab ) + { + bool bContainsNote = maTabs[nTab]->ContainsNotesInRange( *pRange ); + if(bContainsNote) + return true; + } + } + + return false; +} + void ScDocument::SetAutoNameCache( ScAutoNameCache* pCache ) { delete pAutoNameCache; diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx index 29e10c90d09f..c0d41d1ae6cf 100644 --- a/sc/source/core/data/table2.cxx +++ b/sc/source/core/data/table2.cxx @@ -1516,6 +1516,20 @@ void ScTable::GetAllNoteEntries( std::vector<sc::NoteEntry>& rNotes ) const aCol[nCol].GetAllNoteEntries(rNotes); } +bool ScTable::ContainsNotesInRange( const ScRange& rRange ) const +{ + SCROW nStartRow = rRange.aStart.Row(); + SCROW nEndRow = rRange.aEnd.Row(); + for (SCCOL nCol = rRange.aStart.Col(); nCol <= rRange.aEnd.Col(); ++nCol) + { + bool bContainsNote = !aCol[nCol].IsNotesEmptyBlock(nStartRow, nEndRow); + if(bContainsNote) + return true; + } + + return false; +} + CellType ScTable::GetCellType( SCCOL nCol, SCROW nRow ) const { if (ValidColRow( nCol, nRow )) diff --git a/sc/source/ui/view/cellsh.cxx b/sc/source/ui/view/cellsh.cxx index 943379f2d0af..8895f963d192 100644 --- a/sc/source/ui/view/cellsh.cxx +++ b/sc/source/ui/view/cellsh.cxx @@ -979,22 +979,7 @@ void ScCellShell::GetState(SfxItemSet &rSet) // look for at least one note in selection ScRangeList aRanges; rMark.FillRangeListWithMarks( &aRanges, false ); - size_t nCount = aRanges.size(); - for (size_t nPos = 0; nPos < nCount && !bEnable; ++nPos) - { - SCTAB aTab = aRanges[nPos]->aStart.Tab(); - for (SCCOL aCol=aRanges[nPos]->aStart.Col(); aCol <= aRanges[nPos]->aEnd.Col() && !bEnable; aCol++) - { - for (SCROW aRow=aRanges[nPos]->aStart.Row(); aRow <= aRanges[nPos]->aEnd.Row(); aRow++) - { - if (pDoc->HasNote(aCol, aRow, aTab)) - { - bEnable = true; - break; - } - } - } - } + bEnable = pDoc->ContainsNotesInRange( aRanges ); } } else |