enable dragging on the region map cells

openmw-30
Marek Kochanowicz 11 years ago
parent eeb18b533e
commit 4d79f00e28

@ -26,3 +26,13 @@ void CSVWorld::DragRecordTable::setEditLock (bool locked)
{
mEditLock = locked;
}
void CSVWorld::DragRecordTable::dragEnterEvent(QDragEnterEvent *event)
{
event->acceptProposedAction();
}
void CSVWorld::DragRecordTable::dragMoveEvent(QDragMoveEvent *event)
{
event->accept();
}

@ -2,6 +2,7 @@
#define CSV_WORLD_DRAGRECORDTABLE_H
#include <QTableView>
#include <QtGui/qevent.h>
class QWidget;
class QAction;
@ -33,6 +34,10 @@ namespace CSVWorld
protected:
void startDrag(const DragRecordTable& table);
void dragEnterEvent(QDragEnterEvent *event);
void dragMoveEvent(QDragMoveEvent *event);
};
}

@ -4,6 +4,7 @@
#include <algorithm>
#include <set>
#include <sstream>
#include <qt4/QtCore/qabstractitemmodel.h>
#include <QHeaderView>
#include <QContextMenuEvent>
@ -224,6 +225,8 @@ CSVWorld::RegionMap::RegionMap (const CSMWorld::UniversalId& universalId,
mViewInTableAction = new QAction (tr ("View Cells in Table"), this);
connect (mViewInTableAction, SIGNAL (triggered()), this, SLOT (viewInTable()));
addAction (mViewInTableAction);
setAcceptDrops(true);
}
void CSVWorld::RegionMap::selectAll()
@ -367,3 +370,37 @@ std::vector< CSMWorld::UniversalId > CSVWorld::RegionMap::getDragedRecords() con
}
return ids;
}
void CSVWorld::RegionMap::dropEvent (QDropEvent* event)
{
QModelIndex index = indexAt (event->pos());
bool exists = QTableView::model()->data(index, Qt::BackgroundRole)!=QBrush (Qt::DiagCrossPattern);
if (!index.isValid() || !exists)
{
return;
}
const CSMWorld::TableMimeData* mime = dynamic_cast<const CSMWorld::TableMimeData*> (event->mimeData());
if (mime->fromDocument(mDocument) && mime->holdsType(CSMWorld::UniversalId::Type_Region))
{
CSMWorld::UniversalId record (mime->returnMatching (CSMWorld::UniversalId::Type_Region));
QAbstractItemModel *regionModel = model();
CSMWorld::IdTable *cellsModel = &dynamic_cast<CSMWorld::IdTable&> (*
mDocument.getData().getTableModel (CSMWorld::UniversalId::Type_Cells));
std::string cellId(regionModel->data (index, CSMWorld::RegionMap::Role_CellId).
toString().toUtf8().constData());
QModelIndex index2 = cellsModel->getModelIndex (cellId,
cellsModel->findColumnIndex (CSMWorld::Columns::ColumnId_Region));
mDocument.getUndoStack().push(new CSMWorld::ModifyCommand
(*cellsModel, index2, QString::fromUtf8(record.getId().c_str())));
mRegionId = record.getId();
}
}

@ -56,6 +56,8 @@ namespace CSVWorld
void mouseMoveEvent(QMouseEvent *event);
void dropEvent(QDropEvent* event);
public:
RegionMap (const CSMWorld::UniversalId& universalId, CSMDoc::Document& document,

@ -516,11 +516,6 @@ void CSVWorld::Table::mouseMoveEvent (QMouseEvent* event)
}
}
void CSVWorld::Table::dragEnterEvent(QDragEnterEvent *event)
{
event->acceptProposedAction();
}
void CSVWorld::Table::dropEvent(QDropEvent *event)
{
QModelIndex index = indexAt (event->pos());
@ -548,11 +543,6 @@ void CSVWorld::Table::dropEvent(QDropEvent *event)
} //TODO handle drops from different document
}
void CSVWorld::Table::dragMoveEvent(QDragMoveEvent *event)
{
event->accept();
}
std::vector<std::string> CSVWorld::Table::getColumnsWithDisplay(CSMWorld::ColumnBase::Display display) const
{
const int count = mModel->columnCount();

@ -59,10 +59,6 @@ namespace CSVWorld
void mouseMoveEvent(QMouseEvent *event);
void dragEnterEvent(QDragEnterEvent *event);
void dragMoveEvent(QDragMoveEvent *event);
void dropEvent(QDropEvent *event);
public:
@ -94,6 +90,7 @@ namespace CSVWorld
/// \param modified Number of added and modified records
void createRequest();
void cloneRequest(const CSMWorld::UniversalId&);
private slots:

Loading…
Cancel
Save