We can handle droping multiple records

This commit is contained in:
Marek Kochanowicz 2014-02-20 14:13:12 +01:00
parent b788ab8b4c
commit 38a86b5015

View file

@ -60,20 +60,66 @@ void CSVFilter::EditWidget::filterRowsInserted (const QModelIndex& parent, int s
void CSVFilter::EditWidget::createFilterRequest (std::vector< std::pair< std::string, std::vector< std::string > > >& filterSource) void CSVFilter::EditWidget::createFilterRequest (std::vector< std::pair< std::string, std::vector< std::string > > >& filterSource)
{ {
clear(); const unsigned count = filterSource.size();
bool multipleElements = false;
std::string filter(generateFilter(*filterSource.begin())); switch (count)
insert(QString::fromUtf8(filter.c_str())); {
case 0: //empty
return; //nothing to do here
for (unsigned i = 0; i < filterSource.size(); ++i) //test case 1: //only single
{ multipleElements = false;
std::cout<<filterSource[i].first<<std::endl; break;
std::cout<<"Columns:\n";
for (unsigned j = 0; j < filterSource[i].second.size(); ++j) default:
{ multipleElements = true;
std::cout<<filterSource[i].second[j]<<std::endl; break;
}
QString oldContent(text());
bool replaceMode = oldContent.isEmpty() or !oldContent.contains(QRegExp("^!.*$", Qt::CaseInsensitive));
bool orMode = true; //not orMode = andMode,
std::string orAnd;
if (orMode)
{
orAnd = "or";
} else {
orAnd = "and";
}
if (multipleElements) //TODO Currently only 'or' is handled, we should be able to handle 'and' as well and be able to drag records into the EditWidget already filled with the filter
{
std::stringstream ss;
if (replaceMode)
{
ss<<'!'<<orAnd<<'(';
for (unsigned i = 0; i < count; ++i)
{
ss<<generateFilter (filterSource[i]);
if (i+1 != count)
{
ss<<", ";
}
}
ss<<')';
clear();
insert (QString::fromUtf8 (ss.str().c_str()));
} else {
//not handled (yet) TODO
}
} else {
if (replaceMode)
{
clear();
insert ('!' + QString::fromUtf8 (generateFilter(filterSource[0]).c_str()));
} else {
//not handled (yet) TODO
} }
std::cout<<"\n";
} }
} }
@ -99,7 +145,7 @@ std::string CSVFilter::EditWidget::generateFilter (std::pair< std::string, std::
std::stringstream ss; std::stringstream ss;
if (multipleColumns) if (multipleColumns)
{ {
ss<<"!or("; ss<<"or(";
for (unsigned i = 0; i < columns; ++i) for (unsigned i = 0; i < columns; ++i)
{ {
ss<<"string("<<'"'<<seekedString.second[i]<<'"'<<','<<'"'<<seekedString.first<<'"'<<')'; ss<<"string("<<'"'<<seekedString.second[i]<<'"'<<','<<'"'<<seekedString.first<<'"'<<')';
@ -108,7 +154,7 @@ std::string CSVFilter::EditWidget::generateFilter (std::pair< std::string, std::
} }
ss<<')'; ss<<')';
} else { } else {
ss<<"!string"<<'('<<'"'<<seekedString.second[0]<<"\","<<'"'<<seekedString.first<<"\")"; ss<<"string"<<'('<<'"'<<seekedString.second[0]<<"\","<<'"'<<seekedString.first<<"\")";
} }
return ss.str(); return ss.str();