mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-18 13:12:50 +00:00
Implement record filter search by value and QVariant type recognition
This commit is contained in:
parent
fc64ab0f5a
commit
ba6c47bb07
@ -12,6 +12,7 @@
|
||||
#include <apps/opencs/model/filter/parser.hpp>
|
||||
#include <apps/opencs/model/world/universalid.hpp>
|
||||
|
||||
#include <components/debug/debuglog.hpp>
|
||||
#include <components/misc/helpviewer.hpp>
|
||||
|
||||
#include "../../model/prefs/shortcut.hpp"
|
||||
@ -94,7 +95,7 @@ void CSVFilter::EditWidget::filterRowsInserted(const QModelIndex& parent, int st
|
||||
}
|
||||
|
||||
void CSVFilter::EditWidget::createFilterRequest(
|
||||
std::vector<std::pair<std::string, std::vector<std::string>>>& filterSource, Qt::DropAction action)
|
||||
std::vector<std::pair<std::string, std::vector<std::string>>>& filterSource, Qt::DropAction action, std::string stringOrValue)
|
||||
{
|
||||
const unsigned count = filterSource.size();
|
||||
bool multipleElements = false;
|
||||
@ -164,7 +165,7 @@ void CSVFilter::EditWidget::createFilterRequest(
|
||||
|
||||
for (unsigned i = 0; i < count; ++i)
|
||||
{
|
||||
ss << generateFilter(filterSource[i]);
|
||||
ss << generateFilter(filterSource[i], stringOrValue);
|
||||
|
||||
if (i + 1 != count)
|
||||
{
|
||||
@ -185,7 +186,7 @@ void CSVFilter::EditWidget::createFilterRequest(
|
||||
ss << '!';
|
||||
}
|
||||
|
||||
ss << generateFilter(filterSource[0]);
|
||||
ss << generateFilter(filterSource[0], stringOrValue);
|
||||
|
||||
if (!replaceMode)
|
||||
{
|
||||
@ -200,7 +201,21 @@ void CSVFilter::EditWidget::createFilterRequest(
|
||||
}
|
||||
}
|
||||
|
||||
std::string CSVFilter::EditWidget::generateFilter(std::pair<std::string, std::vector<std::string>>& seekedString) const
|
||||
void CSVFilter::EditWidget::createFilterRequest(
|
||||
std::vector<std::pair<int, std::vector<std::string>>>& filterSource, Qt::DropAction action)
|
||||
{
|
||||
std::vector<std::pair<std::string, std::vector<std::string>>> convertedFilter;
|
||||
std::string stringOrValue = "value";
|
||||
for (auto pair : filterSource)
|
||||
{
|
||||
std::string a = std::to_string(pair.first);
|
||||
std::vector<std::string> b = pair.second;
|
||||
convertedFilter.emplace_back(std::make_pair (a, b));
|
||||
}
|
||||
createFilterRequest(convertedFilter, action, stringOrValue);
|
||||
}
|
||||
|
||||
std::string CSVFilter::EditWidget::generateFilter(std::pair<std::string, std::vector<std::string>>& seekedString, std::string stringOrValue) const
|
||||
{
|
||||
const unsigned columns = seekedString.second.size();
|
||||
|
||||
@ -218,6 +233,9 @@ std::string CSVFilter::EditWidget::generateFilter(std::pair<std::string, std::ve
|
||||
multipleColumns = true;
|
||||
break;
|
||||
}
|
||||
|
||||
std::string quotesResolved = seekedString.first;
|
||||
if (stringOrValue == "string") quotesResolved = '"' + seekedString.first + '"';
|
||||
|
||||
std::stringstream ss;
|
||||
if (multipleColumns)
|
||||
@ -225,7 +243,7 @@ std::string CSVFilter::EditWidget::generateFilter(std::pair<std::string, std::ve
|
||||
ss << "or(";
|
||||
for (unsigned i = 0; i < columns; ++i)
|
||||
{
|
||||
ss << "string(" << '"' << seekedString.second[i] << '"' << ',' << '"' << seekedString.first << '"' << ')';
|
||||
ss << stringOrValue << "(" << '"' << seekedString.second[i] << '"' << ',' << quotesResolved << ')';
|
||||
if (i + 1 != columns)
|
||||
ss << ',';
|
||||
}
|
||||
@ -233,7 +251,7 @@ std::string CSVFilter::EditWidget::generateFilter(std::pair<std::string, std::ve
|
||||
}
|
||||
else
|
||||
{
|
||||
ss << "string" << '(' << '"' << seekedString.second[0] << "\"," << '"' << seekedString.first << "\")";
|
||||
ss << stringOrValue << '(' << '"' << seekedString.second[0] << "\"," << quotesResolved << ")";
|
||||
}
|
||||
|
||||
return ss.str();
|
||||
|
@ -44,14 +44,18 @@ namespace CSVFilter
|
||||
EditWidget(CSMWorld::Data& data, QWidget* parent = nullptr);
|
||||
|
||||
void createFilterRequest(
|
||||
std::vector<std::pair<std::string, std::vector<std::string>>>& filterSource, Qt::DropAction action);
|
||||
std::vector<std::pair<std::string, std::vector<std::string>>>& filterSource, Qt::DropAction action, std::string stringOrValue = "string");
|
||||
|
||||
void createFilterRequest(
|
||||
std::vector<std::pair<int, std::vector<std::string>>>& filterSource, 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) const;
|
||||
std::string generateFilter(std::pair<std::string, std::vector<std::string>>& seekedString, std::string stringOrValue) const;
|
||||
|
||||
void contextMenuEvent(QContextMenuEvent* event) override;
|
||||
|
||||
private slots:
|
||||
|
@ -49,16 +49,20 @@ void CSVFilter::FilterBox::dropEvent(QDropEvent* event)
|
||||
const CSVWorld::DragRecordTable* dragTable = mime->getTableOfDragStart();
|
||||
|
||||
std::string searchString = "";
|
||||
if (index.isValid() && dragTable)
|
||||
searchString = dragTable->model()->data(index).toString().toStdString();
|
||||
Log(Debug::Warning) << "Data: " << searchString;
|
||||
|
||||
std::string searchColumn = "";
|
||||
bool isValue(false);
|
||||
if (index.isValid() && dragTable)
|
||||
{
|
||||
QVariant::Type dataType = dragTable->model()->data(index).type();
|
||||
searchColumn = dragTable->model()->headerData(index.column(), Qt::Horizontal).toString().toStdString();
|
||||
Log(Debug::Warning) << "Header: " << searchColumn;
|
||||
Log(Debug::Warning) << "Data: " << searchString;
|
||||
Log(Debug::Warning) << "Header: " << searchColumn;
|
||||
Log(Debug::Warning) << "Type:" << dataType;
|
||||
if (dataType == QMetaType::QString || dataType == QMetaType::Bool || dataType == QMetaType::Int) searchString = dragTable->model()->data(index).toString().toStdString();
|
||||
if (dataType == QMetaType::Int) isValue = true;
|
||||
}
|
||||
|
||||
emit recordDropped(universalIdData, event->proposedAction(), searchString, searchColumn);
|
||||
emit recordDropped(universalIdData, event->proposedAction(), searchString, searchColumn, isValue);
|
||||
}
|
||||
|
||||
void CSVFilter::FilterBox::dragEnterEvent(QDragEnterEvent* event)
|
||||
@ -76,3 +80,9 @@ void CSVFilter::FilterBox::createFilterRequest(
|
||||
{
|
||||
mRecordFilterBox->createFilterRequest(filterSource, action);
|
||||
}
|
||||
|
||||
void CSVFilter::FilterBox::createFilterRequest(
|
||||
std::vector<std::pair<int, std::vector<std::string>>>& filterSource, Qt::DropAction action)
|
||||
{
|
||||
mRecordFilterBox->createFilterRequest(filterSource, action);
|
||||
}
|
||||
|
@ -41,6 +41,9 @@ namespace CSVFilter
|
||||
void createFilterRequest(
|
||||
std::vector<std::pair<std::string, std::vector<std::string>>>& filterSource, Qt::DropAction action);
|
||||
|
||||
void createFilterRequest(
|
||||
std::vector<std::pair<int, std::vector<std::string>>>& filterSource, Qt::DropAction action);
|
||||
|
||||
private:
|
||||
void dragEnterEvent(QDragEnterEvent* event) override;
|
||||
|
||||
@ -51,7 +54,7 @@ namespace CSVFilter
|
||||
signals:
|
||||
void recordFilterChanged(std::shared_ptr<CSMFilter::Node> filter);
|
||||
void recordDropped(std::vector<CSMWorld::UniversalId>& types, Qt::DropAction action,
|
||||
const std::string& searchString, const std::string& searchColumn);
|
||||
const std::string& searchString, const std::string& searchColumn, bool isValue);
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -36,3 +36,9 @@ void CSVFilter::RecordFilterBox::createFilterRequest(
|
||||
{
|
||||
mEdit->createFilterRequest(filterSource, action);
|
||||
}
|
||||
|
||||
void CSVFilter::RecordFilterBox::createFilterRequest(
|
||||
std::vector<std::pair<int, std::vector<std::string>>>& filterSource, Qt::DropAction action)
|
||||
{
|
||||
mEdit->createFilterRequest(filterSource, action);
|
||||
}
|
||||
|
@ -37,6 +37,9 @@ namespace CSVFilter
|
||||
|
||||
void createFilterRequest(
|
||||
std::vector<std::pair<std::string, std::vector<std::string>>>& filterSource, Qt::DropAction action);
|
||||
|
||||
void createFilterRequest(
|
||||
std::vector<std::pair<int, std::vector<std::string>>>& filterSource, Qt::DropAction action);
|
||||
|
||||
signals:
|
||||
|
||||
|
@ -15,6 +15,8 @@
|
||||
|
||||
#include <apps/opencs/view/doc/subview.hpp>
|
||||
|
||||
#include <components/debug/debuglog.hpp>
|
||||
|
||||
#include "../../model/doc/document.hpp"
|
||||
#include "../../model/world/tablemimedata.hpp"
|
||||
|
||||
@ -151,7 +153,7 @@ void CSVWorld::TableSubView::cloneRequest(const CSMWorld::UniversalId& toClone)
|
||||
}
|
||||
|
||||
void CSVWorld::TableSubView::createFilterRequest(std::vector<CSMWorld::UniversalId>& types, Qt::DropAction action,
|
||||
const std::string& searchString, const std::string& searchColumn)
|
||||
const std::string& searchString, const std::string& searchColumn, bool isValue)
|
||||
{
|
||||
std::vector<std::pair<std::string, std::vector<std::string>>> filterSource;
|
||||
|
||||
@ -176,13 +178,31 @@ void CSVWorld::TableSubView::createFilterRequest(std::vector<CSMWorld::Universal
|
||||
|
||||
if (!filterSource.empty())
|
||||
mFilterBox->createFilterRequest(filterSource, action);
|
||||
else if (isValue)
|
||||
{
|
||||
try
|
||||
{
|
||||
std::vector<std::pair<int, std::vector<std::string>>> valueFilterSource;
|
||||
std::vector<std::string> searchColumns;
|
||||
searchColumns.emplace_back(searchColumn);
|
||||
int searchValue = std::stoi(searchString);
|
||||
Log(Debug::Warning) << "Debug: " << searchValue;
|
||||
valueFilterSource.emplace_back(searchValue, searchColumns);
|
||||
mFilterBox->createFilterRequest(valueFilterSource, action);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
Log(Debug::Warning) << "Error in converting the filter request value to integer.";
|
||||
}
|
||||
}
|
||||
else if (searchString != "")
|
||||
{
|
||||
std::vector<std::string> testVector;
|
||||
testVector.emplace_back(searchColumn);
|
||||
filterSource.emplace_back(searchString, testVector);
|
||||
std::vector<std::string> searchColumns;
|
||||
searchColumns.emplace_back(searchColumn);
|
||||
filterSource.emplace_back(searchString, searchColumns);
|
||||
mFilterBox->createFilterRequest(filterSource, action);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool CSVWorld::TableSubView::eventFilter(QObject* object, QEvent* event)
|
||||
|
@ -62,7 +62,7 @@ namespace CSVWorld
|
||||
void editRequest(const CSMWorld::UniversalId& id, const std::string& hint);
|
||||
void cloneRequest(const CSMWorld::UniversalId& toClone);
|
||||
void createFilterRequest(std::vector<CSMWorld::UniversalId>& types, Qt::DropAction action,
|
||||
const std::string& searchString, const std::string& searchColumn);
|
||||
const std::string& searchString, const std::string& searchColumn, bool isValue);
|
||||
void toggleOptions();
|
||||
|
||||
public slots:
|
||||
|
Loading…
x
Reference in New Issue
Block a user