summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@suse.com>2011-11-16 16:59:18 -0500
committerKohei Yoshida <kohei.yoshida@suse.com>2011-11-18 14:13:20 -0500
commit965d933ed94371b3c96695a58ecc9b69742c660b (patch)
tree535c5561e0a14ffec870a3cb2a166fb8af76148d /sc
parente2177c733eb2cb5da8dd50b47842333772a0dddd (diff)
Remove the query entry when all items are selected.
Diffstat (limited to 'sc')
-rw-r--r--sc/inc/queryparam.hxx4
-rw-r--r--sc/source/core/tool/queryparam.cxx24
-rw-r--r--sc/source/ui/cctrl/checklistmenu.cxx5
-rw-r--r--sc/source/ui/inc/checklistmenu.hxx1
-rw-r--r--sc/source/ui/view/gridwin.cxx50
5 files changed, 62 insertions, 22 deletions
diff --git a/sc/inc/queryparam.hxx b/sc/inc/queryparam.hxx
index 4935ebeadf73..6c1c09a040a4 100644
--- a/sc/inc/queryparam.hxx
+++ b/sc/inc/queryparam.hxx
@@ -54,6 +54,7 @@ struct ScQueryParamBase
SC_DLLPUBLIC const ScQueryEntry& GetEntry(SCSIZE n) const;
SC_DLLPUBLIC ScQueryEntry& GetEntry(SCSIZE n);
ScQueryEntry* FindEntryByField(SCCOLROW nField, bool bNew);
+ void RemoveEntryByField(SCCOLROW nField);
void Resize(size_t nNew);
SC_DLLPUBLIC void DeleteQuery(size_t nPos);
void FillInExcelSyntax(const rtl::OUString& aCellStr, SCSIZE nIndex);
@@ -62,7 +63,8 @@ protected:
ScQueryParamBase();
ScQueryParamBase(const ScQueryParamBase& r);
- boost::ptr_vector<ScQueryEntry> maEntries;
+ typedef boost::ptr_vector<ScQueryEntry> EntriesType;
+ EntriesType maEntries;
};
// ============================================================================
diff --git a/sc/source/core/tool/queryparam.cxx b/sc/source/core/tool/queryparam.cxx
index da198e526f24..3b5a958fc84b 100644
--- a/sc/source/core/tool/queryparam.cxx
+++ b/sc/source/core/tool/queryparam.cxx
@@ -38,6 +38,17 @@ namespace {
const size_t MAXQUERY = 8;
+class FindByField : public std::unary_function<ScQueryEntry, bool>
+{
+ SCCOLROW mnField;
+public:
+ FindByField(SCCOLROW nField) : mnField(nField) {}
+ bool operator() (const ScQueryEntry& rEntry) const
+ {
+ return rEntry.nField == mnField;
+ }
+};
+
}
ScQueryParamBase::ScQueryParamBase()
@@ -108,6 +119,19 @@ ScQueryEntry* ScQueryParamBase::FindEntryByField(SCCOLROW nField, bool bNew)
return &maEntries.back();
}
+void ScQueryParamBase::RemoveEntryByField(SCCOLROW nField)
+{
+ EntriesType::iterator itr = std::find_if(maEntries.begin(), maEntries.end(), FindByField(nField));
+ if (itr != maEntries.end())
+ {
+ maEntries.erase(itr);
+ if (maEntries.size() < MAXQUERY)
+ // Make sure that we have at least MAXQUERY number of entries at
+ // all times.
+ maEntries.push_back(new ScQueryEntry);
+ }
+}
+
void ScQueryParamBase::Resize(size_t nNew)
{
if (nNew < MAXQUERY)
diff --git a/sc/source/ui/cctrl/checklistmenu.cxx b/sc/source/ui/cctrl/checklistmenu.cxx
index 5cf37629d7bd..ba2e0a31280c 100644
--- a/sc/source/ui/cctrl/checklistmenu.cxx
+++ b/sc/source/ui/cctrl/checklistmenu.cxx
@@ -1178,6 +1178,11 @@ const Size& ScCheckListMenuWindow::getWindowSize() const
return maWndSize;
}
+bool ScCheckListMenuWindow::isAllSelected() const
+{
+ return maChkToggleAll.IsChecked();
+}
+
void ScCheckListMenuWindow::getResult(ResultType& rResult)
{
ResultType aResult;
diff --git a/sc/source/ui/inc/checklistmenu.hxx b/sc/source/ui/inc/checklistmenu.hxx
index f2555d16af89..8f402d030e6f 100644
--- a/sc/source/ui/inc/checklistmenu.hxx
+++ b/sc/source/ui/inc/checklistmenu.hxx
@@ -231,6 +231,7 @@ public:
const Size& getWindowSize() const;
+ bool isAllSelected() const;
void getResult(ResultType& rResult);
void launch(const Rectangle& rRect);
void close(bool bOK);
diff --git a/sc/source/ui/view/gridwin.cxx b/sc/source/ui/view/gridwin.cxx
index 0943a17ff210..97f418cce34c 100644
--- a/sc/source/ui/view/gridwin.cxx
+++ b/sc/source/ui/view/gridwin.cxx
@@ -710,16 +710,6 @@ void ScGridWindow::LaunchAutoFilterMenu(SCCOL nCol, SCROW nRow)
void ScGridWindow::UpdateAutoFilterFromMenu()
{
- ScCheckListMenuWindow::ResultType aResult;
- mpAutoFilterPopup->getResult(aResult);
- std::vector<rtl::OUString> aSelected;
- ScCheckListMenuWindow::ResultType::const_iterator itr = aResult.begin(), itrEnd = aResult.end();
- for (; itr != itrEnd; ++itr)
- {
- if (itr->second)
- aSelected.push_back(itr->first);
- }
-
const AutoFilterData* pData =
static_cast<const AutoFilterData*>(mpAutoFilterPopup->getExtendedData());
@@ -734,20 +724,38 @@ void ScGridWindow::UpdateAutoFilterFromMenu()
ScQueryParam aParam;
pDBData->GetQueryParam(aParam);
- // Try to use the existing entry for the column (if one exists).
- ScQueryEntry* pEntry = aParam.FindEntryByField(rPos.Col(), true);
+ if (mpAutoFilterPopup->isAllSelected())
+ {
+ // Remove this entry.
+ aParam.RemoveEntryByField(rPos.Col());
+ }
+ else
+ {
+ // Try to use the existing entry for the column (if one exists).
+ ScQueryEntry* pEntry = aParam.FindEntryByField(rPos.Col(), true);
- if (!pEntry)
- // Something went terribly wrong!
- return;
+ if (!pEntry)
+ // Something went terribly wrong!
+ return;
+
+ pEntry->bDoQuery = true;
+ pEntry->nField = rPos.Col();
+ pEntry->eConnect = SC_AND;
- pEntry->bDoQuery = true;
- pEntry->nField = rPos.Col();
- pEntry->eConnect = SC_AND;
+ ScCheckListMenuWindow::ResultType aResult;
+ mpAutoFilterPopup->getResult(aResult);
+ std::vector<rtl::OUString> aSelected;
+ ScCheckListMenuWindow::ResultType::const_iterator itr = aResult.begin(), itrEnd = aResult.end();
+ for (; itr != itrEnd; ++itr)
+ {
+ if (itr->second)
+ aSelected.push_back(itr->first);
+ }
- ScQueryEntry::QueryItemsType& rItems = pEntry->GetQueryItems();
- rItems.clear();
- std::for_each(aSelected.begin(), aSelected.end(), AddItemToEntry(rItems));
+ ScQueryEntry::QueryItemsType& rItems = pEntry->GetQueryItems();
+ rItems.clear();
+ std::for_each(aSelected.begin(), aSelected.end(), AddItemToEntry(rItems));
+ }
pViewData->GetView()->Query(aParam, NULL, true);
pDBData->SetQueryParam(aParam);