1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-16 17:29:55 +00:00

Implement basic filter generation from the dragged table cell (cell content and column header)

This commit is contained in:
unelsson 2023-01-15 01:58:09 +02:00
parent bc1027ee95
commit 6a864cd9f6
7 changed files with 43 additions and 13 deletions

View file

@ -4,9 +4,9 @@
#include <string>
#include <vector>
#include <QModelIndex>
#include <QStringList>
#include <QtCore/QMimeData>
#include <QModelIndex>
#include "columnbase.hpp"
#include "universalid.hpp"
@ -36,7 +36,7 @@ namespace CSMWorld
std::vector<UniversalId> mUniversalId;
QStringList mObjectsFormats;
const CSMDoc::Document& mDocument;
const CSVWorld::DragRecordTable* mTableOfDragStart;
CSVWorld::DragRecordTable* mTableOfDragStart;
QModelIndex mIndexAtDragStart;
public:
@ -64,9 +64,13 @@ namespace CSMWorld
UniversalId returnMatching(CSMWorld::ColumnBase::Display type) const;
void setIndexAtDragStart(QModelIndex index) {mIndexAtDragStart = index;}
void setIndexAtDragStart(QModelIndex index) { mIndexAtDragStart = index; }
void setTableOfDragStart(const CSVWorld::DragRecordTable* table) {mTableOfDragStart = table;}
void setTableOfDragStart(CSVWorld::DragRecordTable* table) { mTableOfDragStart = table; }
const QModelIndex getIndexAtDragStart() const { return mIndexAtDragStart; }
const CSVWorld::DragRecordTable* getTableOfDragStart() const { return mTableOfDragStart; }
static CSMWorld::UniversalId::Type convertEnums(CSMWorld::ColumnBase::Display type);

View file

@ -9,8 +9,11 @@
#include "recordfilterbox.hpp"
#include <components/debug/debuglog.hpp>
#include <apps/opencs/model/world/tablemimedata.hpp>
#include <apps/opencs/model/world/universalid.hpp>
#include <apps/opencs/view/world/dragrecordtable.hpp>
CSVFilter::FilterBox::FilterBox(CSMWorld::Data& data, QWidget* parent)
: QWidget(parent)
@ -42,8 +45,20 @@ void CSVFilter::FilterBox::dropEvent(QDropEvent* event)
return;
std::vector<CSMWorld::UniversalId> universalIdData = mime->getData();
QModelIndex index = mime->getIndexAtDragStart();
const CSVWorld::DragRecordTable* dragTable = mime->getTableOfDragStart();
emit recordDropped(universalIdData, event->proposedAction());
std::string searchString = "";
if (index.isValid() && dragTable)
searchString = dragTable->model()->data(index).toString().toStdString();
Log(Debug::Warning) << "Data: " << searchString;
std::string searchColumn = "";
if (index.isValid() && dragTable)
searchColumn = dragTable->model()->headerData(index.column(), Qt::Horizontal).toString().toStdString();
Log(Debug::Warning) << "Header: " << searchColumn;
emit recordDropped(universalIdData, event->proposedAction(), searchString, searchColumn);
}
void CSVFilter::FilterBox::dragEnterEvent(QDragEnterEvent* event)

View file

@ -50,7 +50,8 @@ namespace CSVFilter
signals:
void recordFilterChanged(std::shared_ptr<CSMFilter::Node> filter);
void recordDropped(std::vector<CSMWorld::UniversalId>& types, Qt::DropAction action);
void recordDropped(std::vector<CSMWorld::UniversalId>& types, Qt::DropAction action,
const std::string& searchString, const std::string& searchColumn);
};
}

View file

@ -16,7 +16,7 @@
#include "dragdroputils.hpp"
void CSVWorld::DragRecordTable::startDragFromTable(const CSVWorld::DragRecordTable& table, QModelIndex index)
void CSVWorld::DragRecordTable::startDragFromTable(CSVWorld::DragRecordTable& table, QModelIndex index)
{
std::vector<CSMWorld::UniversalId> records = table.getDraggedRecords();
if (records.empty())

View file

@ -42,7 +42,7 @@ namespace CSVWorld
void setEditLock(bool locked);
protected:
void startDragFromTable(const DragRecordTable& table, QModelIndex index);
void startDragFromTable(DragRecordTable& table, QModelIndex index);
void dragEnterEvent(QDragEnterEvent* event) override;

View file

@ -150,7 +150,8 @@ void CSVWorld::TableSubView::cloneRequest(const CSMWorld::UniversalId& toClone)
emit cloneRequest(toClone.getId(), toClone.getType());
}
void CSVWorld::TableSubView::createFilterRequest(std::vector<CSMWorld::UniversalId>& types, Qt::DropAction action)
void CSVWorld::TableSubView::createFilterRequest(std::vector<CSMWorld::UniversalId>& types, Qt::DropAction action,
const std::string& searchString, const std::string& searchColumn)
{
std::vector<std::pair<std::string, std::vector<std::string>>> filterSource;
@ -173,7 +174,15 @@ void CSVWorld::TableSubView::createFilterRequest(std::vector<CSMWorld::Universal
}
}
mFilterBox->createFilterRequest(filterSource, action);
if (!filterSource.empty())
mFilterBox->createFilterRequest(filterSource, action);
else if (searchString != "")
{
std::vector<std::string> testVector;
testVector.emplace_back(searchColumn);
filterSource.emplace_back(searchString, testVector);
mFilterBox->createFilterRequest(filterSource, action);
}
}
bool CSVWorld::TableSubView::eventFilter(QObject* object, QEvent* event)

View file

@ -61,7 +61,8 @@ 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);
void createFilterRequest(std::vector<CSMWorld::UniversalId>& types, Qt::DropAction action,
const std::string& searchString, const std::string& searchColumn);
void toggleOptions();
public slots: