mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-03-14 01:19:59 +00:00
Implement enum class FilterType
This commit is contained in:
parent
2e7d41373b
commit
6b0998ff85
@ -100,15 +100,15 @@ void CSVFilter::EditWidget::filterRowsInserted(const QModelIndex& parent, int st
|
||||
|
||||
void CSVFilter::EditWidget::createFilterRequest(const std::vector<FilterData>& sourceFilter, Qt::DropAction action)
|
||||
{
|
||||
std::string stringOrValue = "string";
|
||||
FilterType filterType = FilterType::String;
|
||||
std::vector<FilterData> newFilter;
|
||||
|
||||
for (auto filterData : sourceFilter)
|
||||
{
|
||||
FilterData newFilterData;
|
||||
std::pair<std::string, std::string> pair = std::visit(FilterVisitor(), filterData.searchData);
|
||||
std::pair<std::string, FilterType> pair = std::visit(FilterVisitor(), filterData.searchData);
|
||||
std::string searchString = pair.first;
|
||||
stringOrValue = pair.second;
|
||||
filterType = pair.second;
|
||||
std::vector<std::string> columns;
|
||||
newFilterData.searchData = searchString;
|
||||
newFilterData.columns = filterData.columns;
|
||||
@ -183,7 +183,7 @@ void CSVFilter::EditWidget::createFilterRequest(const std::vector<FilterData>& s
|
||||
|
||||
for (unsigned i = 0; i < count; ++i)
|
||||
{
|
||||
ss << generateFilter(newFilter[i], stringOrValue);
|
||||
ss << generateFilter(newFilter[i], filterType);
|
||||
|
||||
if (i + 1 != count)
|
||||
{
|
||||
@ -204,7 +204,7 @@ void CSVFilter::EditWidget::createFilterRequest(const std::vector<FilterData>& s
|
||||
ss << '!';
|
||||
}
|
||||
|
||||
ss << generateFilter(newFilter[0], stringOrValue);
|
||||
ss << generateFilter(newFilter[0], filterType);
|
||||
|
||||
if (!replaceMode)
|
||||
{
|
||||
@ -219,7 +219,7 @@ void CSVFilter::EditWidget::createFilterRequest(const std::vector<FilterData>& s
|
||||
}
|
||||
}
|
||||
|
||||
std::string CSVFilter::EditWidget::generateFilter(const FilterData& filterData, std::string stringOrValue) const
|
||||
std::string CSVFilter::EditWidget::generateFilter(const FilterData& filterData, const FilterType& filterType) const
|
||||
{
|
||||
const unsigned columns = filterData.columns.size();
|
||||
|
||||
@ -246,16 +246,18 @@ std::string CSVFilter::EditWidget::generateFilter(const FilterData& filterData,
|
||||
Log(Debug::Warning) << "Generating record filter failed.";
|
||||
return "";
|
||||
}
|
||||
if (stringOrValue == "string")
|
||||
if (filterType == FilterType::String)
|
||||
quotesResolved = '"' + quotesResolved + '"';
|
||||
|
||||
std::stringstream ss;
|
||||
|
||||
if (multipleColumns)
|
||||
{
|
||||
ss << "or(";
|
||||
for (unsigned i = 0; i < columns; ++i)
|
||||
{
|
||||
ss << stringOrValue << "(" << '"' << filterData.columns[i] << '"' << ',' << quotesResolved << ')';
|
||||
ss << filterTypeName(filterType) << "(" << '"' << filterData.columns[i] << '"' << ',' << quotesResolved
|
||||
<< ')';
|
||||
if (i + 1 != columns)
|
||||
ss << ',';
|
||||
}
|
||||
@ -263,7 +265,7 @@ std::string CSVFilter::EditWidget::generateFilter(const FilterData& filterData,
|
||||
}
|
||||
else
|
||||
{
|
||||
ss << stringOrValue << '(' << '"' << filterData.columns[0] << "\"," << quotesResolved << ")";
|
||||
ss << filterTypeName(filterType) << '(' << '"' << filterData.columns[0] << "\"," << quotesResolved << ")";
|
||||
}
|
||||
|
||||
return ss.str();
|
||||
|
@ -33,23 +33,29 @@ namespace CSMWorld
|
||||
|
||||
namespace CSVFilter
|
||||
{
|
||||
enum class FilterType
|
||||
{
|
||||
String,
|
||||
Value
|
||||
};
|
||||
|
||||
struct FilterVisitor
|
||||
{
|
||||
std::pair<std::string, std::string> operator()(const std::string& stringData)
|
||||
std::pair<std::string, FilterType> operator()(const std::string& stringData)
|
||||
{
|
||||
std::string stringOrValue = "string";
|
||||
return std::make_pair(stringData, stringOrValue);
|
||||
FilterType filterType = FilterType::String;
|
||||
return std::make_pair(stringData, filterType);
|
||||
}
|
||||
|
||||
std::pair<std::string, std::string> operator()(const QVariant& variantData)
|
||||
std::pair<std::string, FilterType> operator()(const QVariant& variantData)
|
||||
{
|
||||
std::string stringOrValue;
|
||||
FilterType filterType = FilterType::String;
|
||||
QMetaType::Type dataType = static_cast<QMetaType::Type>(variantData.type());
|
||||
if (dataType == QMetaType::QString || dataType == QMetaType::Bool || dataType == QMetaType::Int)
|
||||
stringOrValue = "string";
|
||||
filterType = FilterType::String;
|
||||
if (dataType == QMetaType::Int || dataType == QMetaType::Float)
|
||||
stringOrValue = "value";
|
||||
return std::make_pair(variantData.toString().toStdString(), stringOrValue);
|
||||
filterType = FilterType::Value;
|
||||
return std::make_pair(variantData.toString().toStdString(), filterType);
|
||||
}
|
||||
};
|
||||
|
||||
@ -74,10 +80,22 @@ namespace CSVFilter
|
||||
void filterChanged(std::shared_ptr<CSMFilter::Node> filter);
|
||||
|
||||
private:
|
||||
std::string generateFilter(const FilterData& filterData, std::string stringOrValue) const;
|
||||
std::string generateFilter(const FilterData& filterData, const FilterType& filterType) const;
|
||||
|
||||
void contextMenuEvent(QContextMenuEvent* event) override;
|
||||
|
||||
constexpr std::string_view filterTypeName(const FilterType& type) const
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case FilterType::String:
|
||||
return "string";
|
||||
case FilterType::Value:
|
||||
return "value";
|
||||
}
|
||||
return "unknown type";
|
||||
}
|
||||
|
||||
private slots:
|
||||
|
||||
void textChanged(const QString& text);
|
||||
|
Loading…
x
Reference in New Issue
Block a user