1 #include "filterbox.hpp"
2 
3 #include <QHBoxLayout>
4 #include <QDragEnterEvent>
5 
6 #include "recordfilterbox.hpp"
7 
8 #include <apps/opencs/model/world/tablemimedata.hpp>
9 
FilterBox(CSMWorld::Data & data,QWidget * parent)10 CSVFilter::FilterBox::FilterBox (CSMWorld::Data& data, QWidget *parent)
11 : QWidget (parent)
12 {
13     QHBoxLayout *layout = new QHBoxLayout (this);
14 
15     layout->setContentsMargins (0, 0, 0, 0);
16 
17     mRecordFilterBox = new RecordFilterBox (data, this);
18 
19     layout->addWidget (mRecordFilterBox);
20 
21     setLayout (layout);
22 
23     connect (mRecordFilterBox,
24         SIGNAL (filterChanged (std::shared_ptr<CSMFilter::Node>)),
25         this, SIGNAL (recordFilterChanged (std::shared_ptr<CSMFilter::Node>)));
26 
27     setAcceptDrops(true);
28 }
29 
setRecordFilter(const std::string & filter)30 void CSVFilter::FilterBox::setRecordFilter (const std::string& filter)
31 {
32     mRecordFilterBox->setFilter (filter);
33 }
34 
dropEvent(QDropEvent * event)35 void CSVFilter::FilterBox::dropEvent (QDropEvent* event)
36 {
37     const CSMWorld::TableMimeData* mime = dynamic_cast<const CSMWorld::TableMimeData*> (event->mimeData());
38     if (!mime) // May happen when non-records (e.g. plain text) are dragged and dropped
39         return;
40 
41     std::vector<CSMWorld::UniversalId> universalIdData = mime->getData();
42 
43     emit recordDropped(universalIdData, event->proposedAction());
44 }
45 
dragEnterEvent(QDragEnterEvent * event)46 void CSVFilter::FilterBox::dragEnterEvent (QDragEnterEvent* event)
47 {
48     event->acceptProposedAction();
49 }
50 
dragMoveEvent(QDragMoveEvent * event)51 void CSVFilter::FilterBox::dragMoveEvent (QDragMoveEvent* event)
52 {
53     event->accept();
54 }
55 
createFilterRequest(std::vector<std::pair<std::string,std::vector<std::string>>> & filterSource,Qt::DropAction action)56 void CSVFilter::FilterBox::createFilterRequest (std::vector< std::pair< std::string, std::vector< std::string > > >& filterSource,
57                                                 Qt::DropAction action)
58 {
59     mRecordFilterBox->createFilterRequest(filterSource, action);
60 }
61