[Libreoffice-commits] core.git: Branch 'libreoffice-5-2' - sc/source
Eike Rathke
erack at redhat.com
Thu Jul 28 09:23:31 UTC 2016
sc/source/core/data/table6.cxx | 81 ++++++++++++++++++++++++++-------
sc/source/ui/dialogs/searchresults.cxx | 55 +++++++++++++++++-----
sc/source/ui/inc/searchresults.hxx | 2
sc/source/ui/view/viewfun2.cxx | 3 -
4 files changed, 112 insertions(+), 29 deletions(-)
New commits:
commit bfa295f8a2f348c683ac28e55d5cd3c71b854f9d
Author: Eike Rathke <erack at redhat.com>
Date: Wed Jul 27 16:03:33 2016 +0200
handle notes on empty cells, display search results, tdf#65334 follow-up
This is a combination of 6 commits.
include empty cells if notes are searched, tdf#65334 follow-up
(cherry picked from commit f027c77c520adbdf8cec59e0484fc87b33cf203b)
use GetCellArea() when searching for notes, tdf#65334 follow-up
... so empty cells with notes are included as last "data" position if they are
below or right of the last "real" data, which GetLastDataPos() doesn't.
(cherry picked from commit 09cc958dee93ad0ad2ab0d8cc9cc4c09e46c3653)
do not search in empty string if there is no note, tdf#65334 follow-up
(cherry picked from commit a02f7aa735c52f5d20df0e2a94cc06879cb3dfac)
use GetCellArea() also in SearchAll() and ReplaceAll(), tdf#65334 follow-up
(cherry picked from commit 156590e7c0bf3c81f50b3d9862961e50010ea08a)
use HasCellNotes() when looping and searching for notes, tdf#65334 follow-up
... so we actually find all if on empty cells.
(cherry picked from commit d93284f65cf14fdf5e2520b474eb7383ca1d99e4)
display the SearchAll() and ReplaceAll() results for notes, tdf#65334 related
(cherry picked from commit 4f719263ae8dc44eabfba4654f9dbed92a9c5360)
9bb7464033736e7e7fa24e635ef1a3d39626002b
6c347b5bccd4ffd6a43a80e9d73a0b5fcf82926b
50bfeee96e57010455bbb9e8be4312a39d392411
e504ce7df2a17877eddf21cf309990a2a8b692ba
b9ff40b26526efdf242db2ef1804e54611f16b0e
Change-Id: Ib67b9745ffff730b209df2b82dc7e46fc4774900
Reviewed-on: https://gerrit.libreoffice.org/27603
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Caolán McNamara <caolanm at redhat.com>
Tested-by: Caolán McNamara <caolanm at redhat.com>
diff --git a/sc/source/core/data/table6.cxx b/sc/source/core/data/table6.cxx
index b5a4499..e7e7caf 100644
--- a/sc/source/core/data/table6.cxx
+++ b/sc/source/core/data/table6.cxx
@@ -68,12 +68,22 @@ bool ScTable::SearchCell(const SvxSearchItem& rSearchItem, SCCOL nCol, SCROW nRo
if (!bDoSearch)
return false;
- aCell = aCol[nCol].GetCellValue(nRow);
- if (aCell.isEmpty())
- return false;
+ ScPostIt* pNote;
+ if (rSearchItem.GetCellType() == SvxSearchCellType::NOTE)
+ {
+ pNote = aCol[nCol].GetCellNote(nRow);
+ if (!pNote)
+ return false;
+ }
+ else
+ {
+ aCell = aCol[nCol].GetCellValue(nRow);
+ if (aCell.isEmpty())
+ return false;
+ pNote = nullptr;
+ }
bool bMultiLine = false;
- ScPostIt* pNote = nullptr;
CellType eCellType = aCell.meType;
switch (rSearchItem.GetCellType())
{
@@ -105,7 +115,6 @@ bool ScTable::SearchCell(const SvxSearchItem& rSearchItem, SCCOL nCol, SCROW nRo
break;
case SvxSearchCellType::NOTE:
{
- pNote = aCol[nCol].GetCellNote(nRow);
if (pNote)
{
aString = pNote->GetText();
@@ -300,7 +309,10 @@ bool ScTable::Search(const SvxSearchItem& rSearchItem, SCCOL& rCol, SCROW& rRow,
{
SCCOL nLastCol;
SCROW nLastRow;
- GetLastDataPos(nLastCol, nLastRow);
+ if (rSearchItem.GetCellType() == SvxSearchCellType::NOTE)
+ GetCellArea( nLastCol, nLastRow);
+ else
+ GetLastDataPos(nLastCol, nLastRow);
return Search(rSearchItem, rCol, rRow, nLastCol, nLastRow, rMark, rUndoStr, pUndoDoc);
}
@@ -315,6 +327,7 @@ bool ScTable::Search(const SvxSearchItem& rSearchItem, SCCOL& rCol, SCROW& rRow,
SCROW nRow = rRow;
bool bSkipFiltered = !rSearchItem.IsSearchFiltered();
+ bool bSearchNotes = (rSearchItem.GetCellType() == SvxSearchCellType::NOTE);
if (!bAll && rSearchItem.GetBackward())
{
SCROW nLastNonFilteredRow = MAXROW + 1;
@@ -338,7 +351,12 @@ bool ScTable::Search(const SvxSearchItem& rSearchItem, SCCOL& rCol, SCROW& rRow,
{
nCol--;
if ((SCsCOL)nCol >= 0)
- bIsEmpty = aCol[nCol].IsEmptyData();
+ {
+ if (bSearchNotes)
+ bIsEmpty = !aCol[nCol].HasCellNotes();
+ else
+ bIsEmpty = aCol[nCol].IsEmptyData();
+ }
else
bIsEmpty = true;
}
@@ -365,8 +383,16 @@ bool ScTable::Search(const SvxSearchItem& rSearchItem, SCCOL& rCol, SCROW& rRow,
bFound = SearchCell(rSearchItem, nCol, nRow, rMark, rUndoStr, pUndoDoc);
if (!bFound)
{
- if (!aCol[nCol].GetPrevDataPos(nRow))
- nRow = -1;
+ if (bSearchNotes)
+ {
+ /* TODO: can we look for the previous cell note instead? */
+ --nRow;
+ }
+ else
+ {
+ if (!aCol[nCol].GetPrevDataPos(nRow))
+ nRow = -1;
+ }
}
}
if (!bFound)
@@ -379,7 +405,12 @@ bool ScTable::Search(const SvxSearchItem& rSearchItem, SCCOL& rCol, SCROW& rRow,
{
nCol--;
if ((SCsCOL)nCol >= 0)
- bIsEmpty = aCol[nCol].IsEmptyData();
+ {
+ if (bSearchNotes)
+ bIsEmpty = !aCol[nCol].HasCellNotes();
+ else
+ bIsEmpty = aCol[nCol].IsEmptyData();
+ }
else
bIsEmpty = true;
}
@@ -405,7 +436,9 @@ bool ScTable::Search(const SvxSearchItem& rSearchItem, SCCOL& rCol, SCROW& rRow,
if (!bFound)
{
nCol++;
- while ((nCol <= nLastCol) && aCol[nCol].IsEmptyData()) nCol++;
+ while ((nCol <= nLastCol) &&
+ (bSearchNotes ? !aCol[nCol].HasCellNotes() : aCol[nCol].IsEmptyData()))
+ nCol++;
}
}
if (!bFound)
@@ -428,8 +461,16 @@ bool ScTable::Search(const SvxSearchItem& rSearchItem, SCCOL& rCol, SCROW& rRow,
bFound = SearchCell(rSearchItem, nCol, nRow, rMark, rUndoStr, pUndoDoc);
if (!bFound)
{
- if (!aCol[nCol].GetNextDataPos(nRow))
- nRow = MAXROW + 1;
+ if (bSearchNotes)
+ {
+ /* TODO: can we look for the next cell note instead? */
+ ++nRow;
+ }
+ else
+ {
+ if (!aCol[nCol].GetNextDataPos(nRow))
+ nRow = MAXROW + 1;
+ }
}
}
if (!bFound)
@@ -438,7 +479,9 @@ bool ScTable::Search(const SvxSearchItem& rSearchItem, SCCOL& rCol, SCROW& rRow,
nRow = 0;
nLastNonFilteredRow = -1;
nCol++;
- while ((nCol <= nLastCol) && aCol[nCol].IsEmptyData()) nCol++;
+ while ((nCol <= nLastCol) &&
+ (bSearchNotes ? !aCol[nCol].HasCellNotes() : aCol[nCol].IsEmptyData()))
+ nCol++;
}
}
}
@@ -461,7 +504,10 @@ bool ScTable::SearchAll(const SvxSearchItem& rSearchItem, const ScMarkData& rMar
SCCOL nLastCol;
SCROW nLastRow;
- GetLastDataPos(nLastCol, nLastRow);
+ if (rSearchItem.GetCellType() == SvxSearchCellType::NOTE)
+ GetCellArea( nLastCol, nLastRow);
+ else
+ GetLastDataPos(nLastCol, nLastRow);
do
{
@@ -520,7 +566,10 @@ bool ScTable::ReplaceAll(
SCCOL nLastCol;
SCROW nLastRow;
- GetLastDataPos(nLastCol, nLastRow);
+ if (rSearchItem.GetCellType() == SvxSearchCellType::NOTE)
+ GetCellArea( nLastCol, nLastRow);
+ else
+ GetLastDataPos(nLastCol, nLastRow);
bool bEverFound = false;
while (true)
diff --git a/sc/source/ui/dialogs/searchresults.cxx b/sc/source/ui/dialogs/searchresults.cxx
index 225fb2f..c6e7470 100644
--- a/sc/source/ui/dialogs/searchresults.cxx
+++ b/sc/source/ui/dialogs/searchresults.cxx
@@ -50,24 +50,57 @@ void SearchResultsDlg::dispose()
ModelessDialog::dispose();
}
-void SearchResultsDlg::FillResults( ScDocument* pDoc, const ScRangeList &rMatchedRanges )
+void SearchResultsDlg::FillResults( ScDocument* pDoc, const ScRangeList &rMatchedRanges, bool bCellNotes )
{
mpList->Clear();
mpList->SetUpdateMode(false);
std::vector<OUString> aTabNames = pDoc->GetAllTableNames();
SCTAB nTabCount = aTabNames.size();
- for (size_t i = 0, n = rMatchedRanges.size(); i < n; ++i)
+ if (bCellNotes)
{
- ScCellIterator aIter(pDoc, *rMatchedRanges[i]);
- for (bool bHas = aIter.first(); bHas; bHas = aIter.next())
+ for (size_t i = 0, n = rMatchedRanges.size(); i < n; ++i)
{
- ScAddress aPos = aIter.GetPos();
- if (aPos.Tab() >= nTabCount)
- // Out-of-bound sheet index.
- continue;
-
- OUString aPosStr = aPos.Format(ScRefFlags::ADDR_ABS, nullptr, pDoc->GetAddressConvention());
- mpList->InsertEntry(aTabNames[aPos.Tab()] + "\t" + aPosStr + "\t" + pDoc->GetString(aPos));
+ /* TODO: a CellNotes iterator would come handy and migt speed
+ * things up a little, though we only loop through the
+ * search/replace result positions here. */
+ ScRange aRange( *rMatchedRanges[i] );
+ // Bear in mind that mostly the range is one address position
+ // or a column or a row joined.
+ ScAddress aPos( aRange.aStart );
+ for ( ; aPos.Tab() <= aRange.aEnd.Tab(); aPos.IncTab())
+ {
+ if (aPos.Tab() >= nTabCount)
+ break; // can this even happen? we just searched on existing sheets ...
+ for (aPos.SetCol( aRange.aStart.Col()); aPos.Col() <= aRange.aEnd.Col(); aPos.IncCol())
+ {
+ for (aPos.SetRow( aRange.aStart.Row()); aPos.Row() <= aRange.aEnd.Row(); aPos.IncRow())
+ {
+ const ScPostIt* pNote = pDoc->GetNote( aPos);
+ if (pNote)
+ {
+ OUString aPosStr = aPos.Format(ScRefFlags::ADDR_ABS, nullptr, pDoc->GetAddressConvention());
+ mpList->InsertEntry(aTabNames[aPos.Tab()] + "\t" + aPosStr + "\t" + pNote->GetText());
+ }
+ }
+ }
+ }
+ }
+ }
+ else
+ {
+ for (size_t i = 0, n = rMatchedRanges.size(); i < n; ++i)
+ {
+ ScCellIterator aIter(pDoc, *rMatchedRanges[i]);
+ for (bool bHas = aIter.first(); bHas; bHas = aIter.next())
+ {
+ ScAddress aPos = aIter.GetPos();
+ if (aPos.Tab() >= nTabCount)
+ // Out-of-bound sheet index.
+ continue;
+
+ OUString aPosStr = aPos.Format(ScRefFlags::ADDR_ABS, nullptr, pDoc->GetAddressConvention());
+ mpList->InsertEntry(aTabNames[aPos.Tab()] + "\t" + aPosStr + "\t" + pDoc->GetString(aPos));
+ }
}
}
mpList->SetUpdateMode(true);
diff --git a/sc/source/ui/inc/searchresults.hxx b/sc/source/ui/inc/searchresults.hxx
index 8143c48..776a23f 100644
--- a/sc/source/ui/inc/searchresults.hxx
+++ b/sc/source/ui/inc/searchresults.hxx
@@ -32,7 +32,7 @@ public:
virtual ~SearchResultsDlg();
virtual void dispose() override;
- void FillResults( ScDocument* pDoc, const ScRangeList& rMatchedRanges );
+ void FillResults( ScDocument* pDoc, const ScRangeList& rMatchedRanges, bool bCellNotes );
virtual bool Close() override;
};
diff --git a/sc/source/ui/view/viewfun2.cxx b/sc/source/ui/view/viewfun2.cxx
index d0b3cad..fb6a6eb 100644
--- a/sc/source/ui/view/viewfun2.cxx
+++ b/sc/source/ui/view/viewfun2.cxx
@@ -1742,7 +1742,8 @@ bool ScViewFunc::SearchAndReplace( const SvxSearchItem* pSearchItem,
{
sc::SearchResultsDlg* pDlg = static_cast<sc::SearchResultsDlg*>(pWnd->GetWindow());
if (pDlg)
- pDlg->FillResults(&rDoc, aMatchedRanges);
+ pDlg->FillResults(&rDoc, aMatchedRanges,
+ pSearchItem->GetCellType() == SvxSearchCellType::NOTE);
}
}
More information about the Libreoffice-commits
mailing list