mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-18 13:12:50 +00:00
Use struct with sensible member names
This commit is contained in:
parent
9b808a495c
commit
2fac4d0e40
@ -11,6 +11,8 @@
|
||||
#include <QString>
|
||||
#include <QVariant>
|
||||
|
||||
#include "filterdata.hpp"
|
||||
|
||||
#include <apps/opencs/model/filter/parser.hpp>
|
||||
#include <apps/opencs/model/world/universalid.hpp>
|
||||
|
||||
@ -96,19 +98,21 @@ void CSVFilter::EditWidget::filterRowsInserted(const QModelIndex& parent, int st
|
||||
textChanged(text());
|
||||
}
|
||||
|
||||
void CSVFilter::EditWidget::createFilterRequest(
|
||||
std::vector<std::pair<std::variant<std::string, QVariant>, std::vector<std::string>>>& filterSource,
|
||||
Qt::DropAction action)
|
||||
void CSVFilter::EditWidget::createFilterRequest(const std::vector<FilterData>& sourceFilter, Qt::DropAction action)
|
||||
{
|
||||
std::string stringOrValue = "string";
|
||||
std::vector<std::pair<std::string, std::vector<std::string>>> newFilter;
|
||||
std::vector<FilterData> newFilter;
|
||||
|
||||
for (auto pair : filterSource)
|
||||
for (auto filterData : sourceFilter)
|
||||
{
|
||||
std::string searchString = std::visit(FilterVisitor(), pair.first).first;
|
||||
stringOrValue = std::visit(FilterVisitor(), pair.first).second;
|
||||
std::vector<std::string> column = pair.second;
|
||||
newFilter.emplace_back(std::make_pair(searchString, column));
|
||||
FilterData newFilterData;
|
||||
std::pair<std::string, std::string> pair = std::visit(FilterVisitor(), filterData.searchData);
|
||||
std::string searchString = pair.first;
|
||||
stringOrValue = pair.second;
|
||||
std::vector<std::string> columns;
|
||||
newFilterData.searchData = searchString;
|
||||
newFilterData.columns = filterData.columns;
|
||||
newFilter.emplace_back(newFilterData);
|
||||
}
|
||||
|
||||
const unsigned count = newFilter.size();
|
||||
@ -215,10 +219,9 @@ void CSVFilter::EditWidget::createFilterRequest(
|
||||
}
|
||||
}
|
||||
|
||||
std::string CSVFilter::EditWidget::generateFilter(
|
||||
std::pair<std::string, std::vector<std::string>>& seekedString, std::string stringOrValue) const
|
||||
std::string CSVFilter::EditWidget::generateFilter(const FilterData& filterData, std::string stringOrValue) const
|
||||
{
|
||||
const unsigned columns = seekedString.second.size();
|
||||
const unsigned columns = filterData.columns.size();
|
||||
|
||||
bool multipleColumns = false;
|
||||
switch (columns)
|
||||
@ -235,9 +238,11 @@ std::string CSVFilter::EditWidget::generateFilter(
|
||||
break;
|
||||
}
|
||||
|
||||
std::string quotesResolved = seekedString.first;
|
||||
std::string quotesResolved;
|
||||
if (std::get_if<std::string>(&filterData.searchData))
|
||||
quotesResolved = *(std::get_if<std::string>(&filterData.searchData));
|
||||
if (stringOrValue == "string")
|
||||
quotesResolved = '"' + seekedString.first + '"';
|
||||
quotesResolved = '"' + std::get<std::string>(filterData.searchData) + '"';
|
||||
|
||||
std::stringstream ss;
|
||||
if (multipleColumns)
|
||||
@ -245,7 +250,7 @@ std::string CSVFilter::EditWidget::generateFilter(
|
||||
ss << "or(";
|
||||
for (unsigned i = 0; i < columns; ++i)
|
||||
{
|
||||
ss << stringOrValue << "(" << '"' << seekedString.second[i] << '"' << ',' << quotesResolved << ')';
|
||||
ss << stringOrValue << "(" << '"' << filterData.columns[i] << '"' << ',' << quotesResolved << ')';
|
||||
if (i + 1 != columns)
|
||||
ss << ',';
|
||||
}
|
||||
@ -253,7 +258,7 @@ std::string CSVFilter::EditWidget::generateFilter(
|
||||
}
|
||||
else
|
||||
{
|
||||
ss << stringOrValue << '(' << '"' << seekedString.second[0] << "\"," << quotesResolved << ")";
|
||||
ss << stringOrValue << '(' << '"' << filterData.columns[0] << "\"," << quotesResolved << ")";
|
||||
}
|
||||
|
||||
return ss.str();
|
||||
|
@ -11,6 +11,8 @@
|
||||
#include <variant>
|
||||
#include <vector>
|
||||
|
||||
#include "filterdata.hpp"
|
||||
|
||||
#include "../../model/filter/parser.hpp"
|
||||
|
||||
class QModelIndex;
|
||||
@ -65,17 +67,14 @@ namespace CSVFilter
|
||||
public:
|
||||
EditWidget(CSMWorld::Data& data, QWidget* parent = nullptr);
|
||||
|
||||
void createFilterRequest(
|
||||
std::vector<std::pair<std::variant<std::string, QVariant>, std::vector<std::string>>>& filterSource,
|
||||
Qt::DropAction action);
|
||||
void createFilterRequest(const std::vector<FilterData>& sourceFilter, Qt::DropAction action);
|
||||
|
||||
signals:
|
||||
|
||||
void filterChanged(std::shared_ptr<CSMFilter::Node> filter);
|
||||
|
||||
private:
|
||||
std::string generateFilter(
|
||||
std::pair<std::string, std::vector<std::string>>& seekedString, std::string stringOrValue) const;
|
||||
std::string generateFilter(const FilterData& filterData, std::string stringOrValue) const;
|
||||
|
||||
void contextMenuEvent(QContextMenuEvent* event) override;
|
||||
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include <QHBoxLayout>
|
||||
#include <QVariant>
|
||||
|
||||
#include "filterdata.hpp"
|
||||
#include "recordfilterbox.hpp"
|
||||
|
||||
#include <components/debug/debuglog.hpp>
|
||||
@ -71,9 +72,7 @@ void CSVFilter::FilterBox::dragMoveEvent(QDragMoveEvent* event)
|
||||
event->accept();
|
||||
}
|
||||
|
||||
void CSVFilter::FilterBox::createFilterRequest(
|
||||
std::vector<std::pair<std::variant<std::string, QVariant>, std::vector<std::string>>>& filterSource,
|
||||
Qt::DropAction action)
|
||||
void CSVFilter::FilterBox::createFilterRequest(const std::vector<FilterData>& sourceFilter, Qt::DropAction action)
|
||||
{
|
||||
mRecordFilterBox->createFilterRequest(filterSource, action);
|
||||
mRecordFilterBox->createFilterRequest(sourceFilter, action);
|
||||
}
|
||||
|
@ -10,6 +10,8 @@
|
||||
#include <QVariant>
|
||||
#include <QWidget>
|
||||
|
||||
#include "filterdata.hpp"
|
||||
|
||||
class QDragEnterEvent;
|
||||
class QDragMoveEvent;
|
||||
class QDropEvent;
|
||||
@ -40,9 +42,7 @@ namespace CSVFilter
|
||||
|
||||
void setRecordFilter(const std::string& filter);
|
||||
|
||||
void createFilterRequest(
|
||||
std::vector<std::pair<std::variant<std::string, QVariant>, std::vector<std::string>>>& filterSource,
|
||||
Qt::DropAction action);
|
||||
void createFilterRequest(const std::vector<FilterData>& sourceFilter, Qt::DropAction action);
|
||||
|
||||
private:
|
||||
void dragEnterEvent(QDragEnterEvent* event) override;
|
||||
|
21
apps/opencs/view/filter/filterdata.hpp
Normal file
21
apps/opencs/view/filter/filterdata.hpp
Normal file
@ -0,0 +1,21 @@
|
||||
#ifndef FILTERDATA_HPP
|
||||
#define FILTERDATA_HPP
|
||||
|
||||
#include <string>
|
||||
#include <variant>
|
||||
#include <vector>
|
||||
|
||||
#include <QVariant>
|
||||
|
||||
namespace CSVFilter
|
||||
{
|
||||
|
||||
struct FilterData
|
||||
{
|
||||
std::variant<std::string, QVariant> searchData;
|
||||
std::vector<std::string> columns;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // FILTERDATA_HPP
|
@ -7,6 +7,7 @@
|
||||
#include <QVariant>
|
||||
|
||||
#include "editwidget.hpp"
|
||||
#include "filterdata.hpp"
|
||||
|
||||
CSVFilter::RecordFilterBox::RecordFilterBox(CSMWorld::Data& data, QWidget* parent)
|
||||
: QWidget(parent)
|
||||
@ -34,9 +35,7 @@ void CSVFilter::RecordFilterBox::setFilter(const std::string& filter)
|
||||
mEdit->setText(QString::fromUtf8(filter.c_str()));
|
||||
}
|
||||
|
||||
void CSVFilter::RecordFilterBox::createFilterRequest(
|
||||
std::vector<std::pair<std::variant<std::string, QVariant>, std::vector<std::string>>>& filterSource,
|
||||
Qt::DropAction action)
|
||||
void CSVFilter::RecordFilterBox::createFilterRequest(const std::vector<FilterData>& sourceFilter, Qt::DropAction action)
|
||||
{
|
||||
mEdit->createFilterRequest(filterSource, action);
|
||||
mEdit->createFilterRequest(sourceFilter, action);
|
||||
}
|
||||
|
@ -10,6 +10,8 @@
|
||||
#include <QVariant>
|
||||
#include <QWidget>
|
||||
|
||||
#include "filterdata.hpp"
|
||||
|
||||
namespace CSMFilter
|
||||
{
|
||||
class Node;
|
||||
@ -37,9 +39,7 @@ namespace CSVFilter
|
||||
|
||||
void useFilterRequest(const std::string& idOfFilter);
|
||||
|
||||
void createFilterRequest(
|
||||
std::vector<std::pair<std::variant<std::string, QVariant>, std::vector<std::string>>>& filterSource,
|
||||
Qt::DropAction action);
|
||||
void createFilterRequest(const std::vector<FilterData>& sourceFilter, Qt::DropAction action);
|
||||
|
||||
signals:
|
||||
|
||||
|
@ -24,6 +24,7 @@
|
||||
|
||||
#include "../doc/sizehint.hpp"
|
||||
#include "../filter/filterbox.hpp"
|
||||
#include "../filter/filterdata.hpp"
|
||||
#include "table.hpp"
|
||||
#include "tablebottombox.hpp"
|
||||
|
||||
@ -157,8 +158,7 @@ void CSVWorld::TableSubView::cloneRequest(const CSMWorld::UniversalId& toClone)
|
||||
void CSVWorld::TableSubView::createFilterRequest(
|
||||
std::vector<CSMWorld::UniversalId>& types, std::pair<QVariant, std::string> columnSearchData, Qt::DropAction action)
|
||||
{
|
||||
std::vector<std::pair<std::variant<std::string, QVariant>, std::vector<std::string>>> filterSource;
|
||||
|
||||
std::vector<CSVFilter::FilterData> sourceFilter;
|
||||
std::vector<std::string> refIdColumns = mTable->getColumnsWithDisplay(
|
||||
CSMWorld::TableMimeData::convertEnums(CSMWorld::UniversalId::Type_Referenceable));
|
||||
bool hasRefIdDisplay = !refIdColumns.empty();
|
||||
@ -169,28 +169,39 @@ void CSVWorld::TableSubView::createFilterRequest(
|
||||
std::vector<std::string> col = mTable->getColumnsWithDisplay(CSMWorld::TableMimeData::convertEnums(type));
|
||||
if (!col.empty())
|
||||
{
|
||||
filterSource.emplace_back(it->getId(), col);
|
||||
CSVFilter::FilterData filterData;
|
||||
filterData.searchData = it->getId();
|
||||
filterData.columns = col;
|
||||
sourceFilter.emplace_back(filterData);
|
||||
}
|
||||
|
||||
if (hasRefIdDisplay && CSMWorld::TableMimeData::isReferencable(type))
|
||||
{
|
||||
filterSource.emplace_back(it->getId(), refIdColumns);
|
||||
CSVFilter::FilterData filterData;
|
||||
filterData.searchData = it->getId();
|
||||
filterData.columns = refIdColumns;
|
||||
sourceFilter.emplace_back(filterData);
|
||||
}
|
||||
}
|
||||
|
||||
if (!filterSource.empty())
|
||||
mFilterBox->createFilterRequest(filterSource, action);
|
||||
if (!sourceFilter.empty())
|
||||
mFilterBox->createFilterRequest(sourceFilter, action);
|
||||
else
|
||||
{
|
||||
std::vector<CSVFilter::FilterData> sourceFilterByValue;
|
||||
|
||||
QVariant qData = columnSearchData.first;
|
||||
std::string searchColumn = columnSearchData.second;
|
||||
|
||||
std::vector<std::pair<std::variant<std::string, QVariant>, std::vector<std::string>>> valueFilterSource;
|
||||
std::vector<std::string> searchColumns;
|
||||
searchColumns.emplace_back(searchColumn);
|
||||
valueFilterSource.emplace_back(qData, searchColumns);
|
||||
|
||||
mFilterBox->createFilterRequest(valueFilterSource, action);
|
||||
CSVFilter::FilterData filterData;
|
||||
filterData.searchData = qData;
|
||||
filterData.columns = searchColumns;
|
||||
|
||||
sourceFilterByValue.emplace_back(filterData);
|
||||
|
||||
mFilterBox->createFilterRequest(sourceFilterByValue, action);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user