forked from teamnwah/openmw-tes3coop
Create filter on droping record.
This commit is contained in:
parent
c7b3e139aa
commit
eb3cbaa4e1
2 changed files with 48 additions and 1 deletions
|
@ -2,6 +2,7 @@
|
||||||
#include "editwidget.hpp"
|
#include "editwidget.hpp"
|
||||||
|
|
||||||
#include <QAbstractItemModel>
|
#include <QAbstractItemModel>
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
#include "../../model/world/data.hpp"
|
#include "../../model/world/data.hpp"
|
||||||
|
|
||||||
|
@ -59,6 +60,11 @@ 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();
|
||||||
|
|
||||||
|
std::string filter(generateFilter(*filterSource.begin()));
|
||||||
|
insert(QString::fromStdString(filter));
|
||||||
|
|
||||||
for (unsigned i = 0; i < filterSource.size(); ++i) //test
|
for (unsigned i = 0; i < filterSource.size(); ++i) //test
|
||||||
{
|
{
|
||||||
std::cout<<filterSource[i].first<<std::endl;
|
std::cout<<filterSource[i].first<<std::endl;
|
||||||
|
@ -70,3 +76,41 @@ void CSVFilter::EditWidget::createFilterRequest (std::vector< std::pair< std::st
|
||||||
std::cout<<"\n";
|
std::cout<<"\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string CSVFilter::EditWidget::generateFilter (std::pair< std::string, std::vector< std::string > >& seekedString)
|
||||||
|
{
|
||||||
|
const unsigned columns = seekedString.second.size();
|
||||||
|
|
||||||
|
bool multipleColumns = false;
|
||||||
|
switch (columns)
|
||||||
|
{
|
||||||
|
case 0: //empty
|
||||||
|
return ""; //no column to filter
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 1: //one column to look for
|
||||||
|
multipleColumns = false;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
multipleColumns = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::stringstream ss;
|
||||||
|
if (multipleColumns)
|
||||||
|
{
|
||||||
|
ss<<"!or(";
|
||||||
|
for (unsigned i = 0; i < columns; ++i)
|
||||||
|
{
|
||||||
|
ss<<"string("<<'"'<<seekedString.second[i]<<'"'<<','<<'"'<<seekedString.first<<'"'<<')';
|
||||||
|
if (i+1 != columns)
|
||||||
|
ss<<',';
|
||||||
|
}
|
||||||
|
ss<<')';
|
||||||
|
} else {
|
||||||
|
ss<<"!string"<<'('<<'"'<<seekedString.second[0]<<"\","<<'"'<<seekedString.first<<"\")";
|
||||||
|
}
|
||||||
|
|
||||||
|
return ss.str();
|
||||||
|
}
|
||||||
|
|
|
@ -33,6 +33,9 @@ namespace CSVFilter
|
||||||
|
|
||||||
void filterChanged (boost::shared_ptr<CSMFilter::Node> filter);
|
void filterChanged (boost::shared_ptr<CSMFilter::Node> filter);
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::string generateFilter(std::pair<std::string, std::vector<std::string> >& seekedString);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
|
||||||
void textChanged (const QString& text);
|
void textChanged (const QString& text);
|
||||||
|
|
Loading…
Reference in a new issue