diff --git a/apps/opencs/view/filter/editwidget.cpp b/apps/opencs/view/filter/editwidget.cpp index c7ad0d75ac..8078a72486 100644 --- a/apps/opencs/view/filter/editwidget.cpp +++ b/apps/opencs/view/filter/editwidget.cpp @@ -12,6 +12,7 @@ #include #include +#include #include #include "../../model/prefs/shortcut.hpp" @@ -94,7 +95,7 @@ void CSVFilter::EditWidget::filterRowsInserted(const QModelIndex& parent, int st } void CSVFilter::EditWidget::createFilterRequest( - std::vector>>& filterSource, Qt::DropAction action) + std::vector>>& 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>& seekedString) const +void CSVFilter::EditWidget::createFilterRequest( + std::vector>>& filterSource, Qt::DropAction action) +{ + std::vector>> convertedFilter; + std::string stringOrValue = "value"; + for (auto pair : filterSource) + { + std::string a = std::to_string(pair.first); + std::vector b = pair.second; + convertedFilter.emplace_back(std::make_pair (a, b)); + } + createFilterRequest(convertedFilter, action, stringOrValue); +} + +std::string CSVFilter::EditWidget::generateFilter(std::pair>& seekedString, std::string stringOrValue) const { const unsigned columns = seekedString.second.size(); @@ -218,6 +233,9 @@ std::string CSVFilter::EditWidget::generateFilter(std::pair>>& filterSource, Qt::DropAction action); + std::vector>>& filterSource, Qt::DropAction action, std::string stringOrValue = "string"); + + void createFilterRequest( + std::vector>>& filterSource, Qt::DropAction action); signals: void filterChanged(std::shared_ptr filter); private: - std::string generateFilter(std::pair>& seekedString) const; + std::string generateFilter(std::pair>& seekedString, std::string stringOrValue) const; + void contextMenuEvent(QContextMenuEvent* event) override; private slots: diff --git a/apps/opencs/view/filter/filterbox.cpp b/apps/opencs/view/filter/filterbox.cpp index d99544c5ce..fed5873945 100644 --- a/apps/opencs/view/filter/filterbox.cpp +++ b/apps/opencs/view/filter/filterbox.cpp @@ -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; - - emit recordDropped(universalIdData, event->proposedAction(), searchString, 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, 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>>& filterSource, Qt::DropAction action) +{ + mRecordFilterBox->createFilterRequest(filterSource, action); +} diff --git a/apps/opencs/view/filter/filterbox.hpp b/apps/opencs/view/filter/filterbox.hpp index 78692e908b..152a97eacd 100644 --- a/apps/opencs/view/filter/filterbox.hpp +++ b/apps/opencs/view/filter/filterbox.hpp @@ -41,6 +41,9 @@ namespace CSVFilter void createFilterRequest( std::vector>>& filterSource, Qt::DropAction action); + void createFilterRequest( + std::vector>>& filterSource, Qt::DropAction action); + private: void dragEnterEvent(QDragEnterEvent* event) override; @@ -51,7 +54,7 @@ namespace CSVFilter signals: void recordFilterChanged(std::shared_ptr filter); void recordDropped(std::vector& types, Qt::DropAction action, - const std::string& searchString, const std::string& searchColumn); + const std::string& searchString, const std::string& searchColumn, bool isValue); }; } diff --git a/apps/opencs/view/filter/recordfilterbox.cpp b/apps/opencs/view/filter/recordfilterbox.cpp index 41c60f7d1f..610f11cd15 100644 --- a/apps/opencs/view/filter/recordfilterbox.cpp +++ b/apps/opencs/view/filter/recordfilterbox.cpp @@ -36,3 +36,9 @@ void CSVFilter::RecordFilterBox::createFilterRequest( { mEdit->createFilterRequest(filterSource, action); } + +void CSVFilter::RecordFilterBox::createFilterRequest( + std::vector>>& filterSource, Qt::DropAction action) +{ + mEdit->createFilterRequest(filterSource, action); +} diff --git a/apps/opencs/view/filter/recordfilterbox.hpp b/apps/opencs/view/filter/recordfilterbox.hpp index 0c514512f4..fc759765c0 100644 --- a/apps/opencs/view/filter/recordfilterbox.hpp +++ b/apps/opencs/view/filter/recordfilterbox.hpp @@ -37,6 +37,9 @@ namespace CSVFilter void createFilterRequest( std::vector>>& filterSource, Qt::DropAction action); + + void createFilterRequest( + std::vector>>& filterSource, Qt::DropAction action); signals: diff --git a/apps/opencs/view/world/tablesubview.cpp b/apps/opencs/view/world/tablesubview.cpp index c656411967..4864cf6347 100644 --- a/apps/opencs/view/world/tablesubview.cpp +++ b/apps/opencs/view/world/tablesubview.cpp @@ -15,6 +15,8 @@ #include +#include + #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& types, Qt::DropAction action, - const std::string& searchString, const std::string& searchColumn) + const std::string& searchString, const std::string& searchColumn, bool isValue) { std::vector>> filterSource; @@ -176,13 +178,31 @@ void CSVWorld::TableSubView::createFilterRequest(std::vectorcreateFilterRequest(filterSource, action); + else if (isValue) + { + try + { + std::vector>> valueFilterSource; + std::vector 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 testVector; - testVector.emplace_back(searchColumn); - filterSource.emplace_back(searchString, testVector); + std::vector searchColumns; + searchColumns.emplace_back(searchColumn); + filterSource.emplace_back(searchString, searchColumns); mFilterBox->createFilterRequest(filterSource, action); } + } bool CSVWorld::TableSubView::eventFilter(QObject* object, QEvent* event) diff --git a/apps/opencs/view/world/tablesubview.hpp b/apps/opencs/view/world/tablesubview.hpp index 45e1c26154..f8652483b5 100644 --- a/apps/opencs/view/world/tablesubview.hpp +++ b/apps/opencs/view/world/tablesubview.hpp @@ -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& 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: