try with the passing action

This commit is contained in:
Marek Kochanowicz 2014-02-20 16:55:51 +01:00
parent 38a86b5015
commit 3ad6df1f92
9 changed files with 87 additions and 27 deletions

View file

@ -3,6 +3,7 @@
#include <QAbstractItemModel>
#include <QString>
#include <QApplication>
#include "../../model/world/data.hpp"
@ -58,7 +59,8 @@ void CSVFilter::EditWidget::filterRowsInserted (const QModelIndex& parent, int s
textChanged (text());
}
void CSVFilter::EditWidget::createFilterRequest (std::vector< std::pair< std::string, std::vector< std::string > > >& filterSource)
void CSVFilter::EditWidget::createFilterRequest (std::vector< std::pair< std::string, std::vector< std::string > > >& filterSource,
Qt::DropAction action)
{
const unsigned count = filterSource.size();
bool multipleElements = false;
@ -77,9 +79,34 @@ void CSVFilter::EditWidget::createFilterRequest (std::vector< std::pair< std::st
break;
}
Qt::KeyboardModifiers key = QApplication::keyboardModifiers();
QString oldContent(text());
bool replaceMode = oldContent.isEmpty() or !oldContent.contains(QRegExp("^!.*$", Qt::CaseInsensitive));
bool orMode = true; //not orMode = andMode,
bool replaceMode = false;
bool orMode = true;
switch (key)
{
case Qt::ShiftModifier:
orMode = true;
replaceMode = false;
break;
case Qt::ControlModifier:
orMode = false;
replaceMode = false;
break;
default:
replaceMode = true;
break;
}
if (oldContent.isEmpty() ||
!oldContent.contains(QRegExp("^!.*$", Qt::CaseInsensitive)))
{
replaceMode = true;
}
std::string orAnd;
if (orMode)
@ -89,12 +116,12 @@ void CSVFilter::EditWidget::createFilterRequest (std::vector< std::pair< std::st
orAnd = "and";
}
if (multipleElements) //TODO Currently only 'or' is handled, we should be able to handle 'and' as well and be able to drag records into the EditWidget already filled with the filter
if (multipleElements) //TODO appending to the existing filter
{
std::stringstream ss;
if (replaceMode)
{
ss<<'!'<<orAnd<<'(';
ss<<"!or(";
for (unsigned i = 0; i < count; ++i)
{
@ -107,16 +134,25 @@ void CSVFilter::EditWidget::createFilterRequest (std::vector< std::pair< std::st
}
ss<<')';
clear();
insert (QString::fromUtf8 (ss.str().c_str()));
if (ss.str().length() >2)
{
clear();
insert (QString::fromUtf8 (ss.str().c_str()));
}
} else {
//not handled (yet) TODO
}
} else {
if (replaceMode)
{
clear();
insert ('!' + QString::fromUtf8 (generateFilter(filterSource[0]).c_str()));
std::string filter(generateFilter(filterSource[0]));
if (!filter.empty())
{
clear();
insert ('!' + QString::fromUtf8 (generateFilter(filterSource[0]).c_str()));
}
} else {
//not handled (yet) TODO
}

View file

@ -5,6 +5,7 @@
#include <QLineEdit>
#include <QPalette>
#include <qt4/QtCore/qnamespace.h>
#include "../../model/filter/parser.hpp"
#include "../../model/filter/node.hpp"
@ -46,7 +47,8 @@ namespace CSVFilter
void filterRowsInserted (const QModelIndex& parent, int start, int end);
void createFilterRequest(std::vector<std::pair<std::string, std::vector<std::string> > >& filterSource);
void createFilterRequest(std::vector<std::pair<std::string, std::vector<std::string> > >& filterSource,
Qt::DropAction action);
};
}

View file

@ -25,8 +25,8 @@ CSVFilter::FilterBox::FilterBox (CSMWorld::Data& data, QWidget *parent)
SIGNAL (filterChanged (boost::shared_ptr<CSMFilter::Node>)),
this, SIGNAL (recordFilterChanged (boost::shared_ptr<CSMFilter::Node>)));
connect(this, SIGNAL(createFilterRequest(std::vector<std::pair<std::string, std::vector<std::string> > >&)),
recordFilterBox, SIGNAL(createFilterRequest(std::vector<std::pair<std::string, std::vector<std::string> > >&)));
connect(this, SIGNAL(createFilterRequest(std::vector<std::pair<std::string, std::vector<std::string> > >&, Qt::DropAction)),
recordFilterBox, SIGNAL(createFilterRequest(std::vector<std::pair<std::string, std::vector<std::string> > >&, Qt::DropAction)));
setAcceptDrops(true);
}
@ -35,7 +35,7 @@ void CSVFilter::FilterBox::dropEvent (QDropEvent* event)
{
std::vector<CSMWorld::UniversalId> data = dynamic_cast<const CSMWorld::TableMimeData*> (event->mimeData())->getData();
emit recordDropped(data);
emit recordDropped(data, event->proposedAction());
}
void CSVFilter::FilterBox::dragEnterEvent (QDragEnterEvent* event)

View file

@ -4,6 +4,7 @@
#include <vector>
#include <QWidget>
#include <qt4/QtCore/qnamespace.h>
#include "../../model/filter/node.hpp"
#include "../../model/world/universalid.hpp"
@ -32,8 +33,9 @@ namespace CSVFilter
signals:
void recordFilterChanged (boost::shared_ptr<CSMFilter::Node> filter);
void recordDropped (std::vector<CSMWorld::UniversalId>& types);
void createFilterRequest(std::vector<std::pair<std::string, std::vector<std::string> > >& filterSource);
void recordDropped (std::vector<CSMWorld::UniversalId>& types, Qt::DropAction action);
void createFilterRequest(std::vector<std::pair<std::string, std::vector<std::string> > >& filterSource,
Qt::DropAction action);
};
}

View file

@ -25,6 +25,6 @@ CSVFilter::RecordFilterBox::RecordFilterBox (CSMWorld::Data& data, QWidget *pare
editWidget, SIGNAL (filterChanged (boost::shared_ptr<CSMFilter::Node>)),
this, SIGNAL (filterChanged (boost::shared_ptr<CSMFilter::Node>)));
connect(this, SIGNAL(createFilterRequest(std::vector<std::pair<std::string, std::vector<std::string> > >&)),
editWidget, SLOT(createFilterRequest(std::vector<std::pair<std::string, std::vector<std::string> > >&)));
connect(this, SIGNAL(createFilterRequest(std::vector<std::pair<std::string, std::vector<std::string> > >&, Qt::DropAction)),
editWidget, SLOT(createFilterRequest(std::vector<std::pair<std::string, std::vector<std::string> > >&, Qt::DropAction)));
}

View file

@ -4,6 +4,7 @@
#include <boost/shared_ptr.hpp>
#include <QWidget>
#include <qt4/QtCore/qnamespace.h>
#include <QHBoxLayout>
@ -27,7 +28,8 @@ namespace CSVFilter
signals:
void filterChanged (boost::shared_ptr<CSMFilter::Node> filter);
void createFilterRequest(std::vector<std::pair<std::string, std::vector<std::string> > >& filterSource);
void createFilterRequest(std::vector<std::pair<std::string, std::vector<std::string> > >& filterSource,
Qt::DropAction action);
};
}

View file

@ -4,6 +4,7 @@
#include <QHeaderView>
#include <QAction>
#include <QApplication>
#include <QMenu>
#include <QContextMenuEvent>
#include <QString>
@ -471,7 +472,20 @@ void CSVWorld::Table::mouseMoveEvent (QMouseEvent* event)
drag->setMimeData (mime);
drag->setPixmap (QString::fromStdString (mime->getIcon()));
drag->exec();
Qt::DropActions action = Qt::IgnoreAction;
switch (QApplication::keyboardModifiers())
{
case Qt::ControlModifier:
action = Qt::CopyAction;
break;
case Qt::ShiftModifier:
action = Qt::MoveAction;
break;
}
drag->exec(action);
}
}

View file

@ -62,11 +62,11 @@ CSVWorld::TableSubView::TableSubView (const CSMWorld::UniversalId& id, CSMDoc::D
SIGNAL (recordFilterChanged (boost::shared_ptr<CSMFilter::Node>)),
mTable, SLOT (recordFilterChanged (boost::shared_ptr<CSMFilter::Node>)));
connect(filterBox, SIGNAL(recordDropped(std::vector<CSMWorld::UniversalId>&)),
this, SLOT(createFilterRequest(std::vector<CSMWorld::UniversalId>&)));
connect(filterBox, SIGNAL(recordDropped(std::vector<CSMWorld::UniversalId>&, Qt::DropAction)),
this, SLOT(createFilterRequest(std::vector<CSMWorld::UniversalId>&, Qt::DropAction)));
connect(this, SIGNAL(createFilterRequest(std::vector<std::pair<std::string, std::vector<std::string> > >&)),
filterBox, SIGNAL(createFilterRequest(std::vector<std::pair<std::string, std::vector<std::string> > >&)));
connect(this, SIGNAL(createFilterRequest(std::vector<std::pair<std::string, std::vector<std::string> > >&, Qt::DropAction)),
filterBox, SIGNAL(createFilterRequest(std::vector<std::pair<std::string, std::vector<std::string> > >&, Qt::DropAction)));
}
void CSVWorld::TableSubView::setEditLock (bool locked)
@ -95,7 +95,7 @@ void CSVWorld::TableSubView::cloneRequest(const CSMWorld::UniversalId& toClone)
emit cloneRequest(toClone.getId(), toClone.getType());
}
void CSVWorld::TableSubView::createFilterRequest (std::vector< CSMWorld::UniversalId>& types)
void CSVWorld::TableSubView::createFilterRequest (std::vector< CSMWorld::UniversalId>& types, Qt::DropAction action)
{
std::vector<std::pair<std::string, std::vector<std::string> > > filterSource;
@ -106,5 +106,5 @@ void CSVWorld::TableSubView::createFilterRequest (std::vector< CSMWorld::Univers
filterSource.push_back(pair);
}
emit createFilterRequest(filterSource);
emit createFilterRequest(filterSource, action);
}

View file

@ -3,6 +3,8 @@
#include "../doc/subview.hpp"
#include <qt4/QtCore/qnamespace.h>
class QModelIndex;
namespace CSMWorld
@ -42,13 +44,15 @@ namespace CSVWorld
signals:
void cloneRequest(const std::string&,
const CSMWorld::UniversalId::Type);
void createFilterRequest(std::vector<std::pair<std::string, std::vector<std::string> > >& filterSource);
void createFilterRequest(std::vector<std::pair<std::string, std::vector<std::string> > >& filterSource,
Qt::DropAction action);
private slots:
void editRequest (int row);
void cloneRequest (const CSMWorld::UniversalId& toClone);
void createFilterRequest(std::vector< CSMWorld::UniversalId >& types);
void createFilterRequest(std::vector< CSMWorld::UniversalId >& types,
Qt::DropAction action);
};
}