summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@suse.com>2011-11-16 01:10:39 -0500
committerKohei Yoshida <kohei.yoshida@suse.com>2011-11-18 14:13:19 -0500
commit24568e6292341ad5965c34825c8512bb3a61b334 (patch)
tree753bfa06c0bc01e68b4eea343a363bc5716e8b78
parentb42937e81c257d7eabe922bad05db31824534af8 (diff)
Handle query after the popup gets dismissed by clicking OK.
But it's not working right. :-(
-rw-r--r--sc/inc/queryparam.hxx1
-rw-r--r--sc/source/core/tool/queryparam.cxx6
-rw-r--r--sc/source/ui/view/gridwin.cxx59
3 files changed, 59 insertions, 7 deletions
diff --git a/sc/inc/queryparam.hxx b/sc/inc/queryparam.hxx
index 49fa2bceaabd..c95655e922b6 100644
--- a/sc/inc/queryparam.hxx
+++ b/sc/inc/queryparam.hxx
@@ -53,6 +53,7 @@ struct ScQueryParamBase
SC_DLLPUBLIC SCSIZE GetEntryCount() const;
SC_DLLPUBLIC const ScQueryEntry& GetEntry(SCSIZE n) const;
SC_DLLPUBLIC ScQueryEntry& GetEntry(SCSIZE n);
+ ScQueryEntry& AppendEntry();
void Resize(size_t nNew);
SC_DLLPUBLIC void DeleteQuery(size_t nPos);
void FillInExcelSyntax(const rtl::OUString& aCellStr, SCSIZE nIndex);
diff --git a/sc/source/core/tool/queryparam.cxx b/sc/source/core/tool/queryparam.cxx
index d4ead74aeafc..5b6e627d2311 100644
--- a/sc/source/core/tool/queryparam.cxx
+++ b/sc/source/core/tool/queryparam.cxx
@@ -77,6 +77,12 @@ ScQueryEntry& ScQueryParamBase::GetEntry(SCSIZE n)
return maEntries[n];
}
+ScQueryEntry& ScQueryParamBase::AppendEntry()
+{
+ maEntries.push_back(new ScQueryEntry);
+ return maEntries.back();
+}
+
void ScQueryParamBase::Resize(size_t nNew)
{
if (nNew < MAXQUERY)
diff --git a/sc/source/ui/view/gridwin.cxx b/sc/source/ui/view/gridwin.cxx
index 8d4b080a9763..5f4b0311fb25 100644
--- a/sc/source/ui/view/gridwin.cxx
+++ b/sc/source/ui/view/gridwin.cxx
@@ -614,6 +614,20 @@ public:
}
};
+class AddItemToEntry : public std::unary_function<rtl::OUString, void>
+{
+ ScQueryEntry::QueryItemsType& mrItems;
+public:
+ AddItemToEntry(ScQueryEntry::QueryItemsType& rItems) : mrItems(rItems) {}
+ void operator() (const rtl::OUString& rSelected)
+ {
+ ScQueryEntry::Item aNew;
+ aNew.maString = rSelected;
+ aNew.meType = ScQueryEntry::ByString;
+ aNew.mfVal = 0.0;
+ mrItems.push_back(aNew);
+ }
+};
}
@@ -684,21 +698,52 @@ void ScGridWindow::UpdateAutoFilterFromMenu()
ScQueryParam aParam;
pDBData->GetQueryParam(aParam);
+ // Try to use the existing entry for the column (if one exists).
SCSIZE n = aParam.GetEntryCount();
+ ScQueryEntry* pEntry = NULL;
for (SCSIZE i = 0; i < n; ++i)
{
ScQueryEntry& rEntry = aParam.GetEntry(i);
- rEntry.Clear();
+ if (!rEntry.bDoQuery)
+ break;
+
+ if (rEntry.nField == rPos.Col())
+ {
+ // existing entry found!
+ pEntry = &rEntry;
+ break;
+ }
}
- if (aSelected.empty())
+ if (!pEntry)
+ {
+ // Use the first unused entry.
+ for (SCSIZE i = 0; i < n; ++i)
+ {
+ ScQueryEntry& rEntry = aParam.GetEntry(i);
+ if (!rEntry.bDoQuery)
+ {
+ pEntry = &rEntry;
+ break;
+ }
+ }
+
+ if (!pEntry)
+ // Add a new entry.
+ pEntry = &aParam.AppendEntry();
+ }
+
+ if (!pEntry)
+ // Something went terribly wrong!
return;
- ScQueryEntry& rEntry = aParam.GetEntry(0);
- ScQueryEntry::Item& rItem = rEntry.GetQueryItem();
- rEntry.bDoQuery = true;
- rItem.meType = ScQueryEntry::ByString;
- rItem.maString = aSelected[0];
+ pEntry->bDoQuery = true;
+ pEntry->nField = rPos.Col();
+ pEntry->eConnect = SC_AND;
+
+ 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);