1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-26 00:35:23 +00:00

Nested tables accept drops

This commit is contained in:
Stanislav Bas 2015-06-21 21:35:00 +03:00
parent b9882eb59a
commit d606b62688
3 changed files with 26 additions and 27 deletions

View File

@ -12,7 +12,13 @@
void CSVWorld::DragRecordTable::startDragFromTable (const CSVWorld::DragRecordTable& table)
{
CSMWorld::TableMimeData* mime = new CSMWorld::TableMimeData (table.getDraggedRecords(), mDocument);
std::vector<CSMWorld::UniversalId> records = table.getDraggedRecords();
if (records.empty())
{
return;
}
CSMWorld::TableMimeData* mime = new CSMWorld::TableMimeData (records, mDocument);
if (mime)
{
@ -27,7 +33,9 @@ CSVWorld::DragRecordTable::DragRecordTable (CSMDoc::Document& document, QWidget*
QTableView(parent),
mDocument(document),
mEditLock(false)
{}
{
setAcceptDrops(true);
}
void CSVWorld::DragRecordTable::setEditLock (bool locked)
{

View File

@ -14,8 +14,7 @@ CSVWorld::NestedTable::NestedTable(CSMDoc::Document& document,
CSMWorld::UniversalId id,
CSMWorld::NestedTableProxyModel* model,
QWidget* parent)
: QTableView(parent),
mUndoStack(document.getUndoStack()),
: DragRecordTable(document, parent),
mModel(model)
{
mDispatcher = new CSMWorld::CommandDispatcher (document, id, this);
@ -47,8 +46,6 @@ CSVWorld::NestedTable::NestedTable(CSMDoc::Document& document,
setModel(model);
setAcceptDrops(true);
mAddNewRowAction = new QAction (tr ("Add new row"), this);
connect(mAddNewRowAction, SIGNAL(triggered()),
@ -60,12 +57,10 @@ CSVWorld::NestedTable::NestedTable(CSMDoc::Document& document,
this, SLOT(removeRowActionTriggered()));
}
void CSVWorld::NestedTable::dragEnterEvent(QDragEnterEvent *event)
{
}
void CSVWorld::NestedTable::dragMoveEvent(QDragMoveEvent *event)
std::vector<CSMWorld::UniversalId> CSVWorld::NestedTable::getDraggedRecords() const
{
// No drag support for nested tables
return std::vector<CSMWorld::UniversalId>();
}
void CSVWorld::NestedTable::contextMenuEvent (QContextMenuEvent *event)
@ -84,16 +79,16 @@ void CSVWorld::NestedTable::contextMenuEvent (QContextMenuEvent *event)
void CSVWorld::NestedTable::removeRowActionTriggered()
{
mUndoStack.push(new CSMWorld::DeleteNestedCommand(*(mModel->model()),
mModel->getParentId(),
selectionModel()->selectedRows().begin()->row(),
mModel->getParentColumn()));
mDocument.getUndoStack().push(new CSMWorld::DeleteNestedCommand(*(mModel->model()),
mModel->getParentId(),
selectionModel()->selectedRows().begin()->row(),
mModel->getParentColumn()));
}
void CSVWorld::NestedTable::addNewRowActionTriggered()
{
mUndoStack.push(new CSMWorld::AddNestedCommand(*(mModel->model()),
mModel->getParentId(),
selectionModel()->selectedRows().size(),
mModel->getParentColumn()));
mDocument.getUndoStack().push(new CSMWorld::AddNestedCommand(*(mModel->model()),
mModel->getParentId(),
selectionModel()->selectedRows().size(),
mModel->getParentColumn()));
}

View File

@ -1,10 +1,10 @@
#ifndef CSV_WORLD_NESTEDTABLE_H
#define CSV_WORLD_NESTEDTABLE_H
#include <QTableView>
#include <QEvent>
class QUndoStack;
#include "dragrecordtable.hpp"
class QAction;
class QContextMenuEvent;
@ -22,13 +22,12 @@ namespace CSMDoc
namespace CSVWorld
{
class NestedTable : public QTableView
class NestedTable : public DragRecordTable
{
Q_OBJECT
QAction *mAddNewRowAction;
QAction *mRemoveRowAction;
QUndoStack& mUndoStack;
CSMWorld::NestedTableProxyModel* mModel;
CSMWorld::CommandDispatcher *mDispatcher;
@ -38,10 +37,7 @@ namespace CSVWorld
CSMWorld::NestedTableProxyModel* model,
QWidget* parent = NULL);
protected:
void dragEnterEvent(QDragEnterEvent *event);
void dragMoveEvent(QDragMoveEvent *event);
virtual std::vector<CSMWorld::UniversalId> getDraggedRecords() const;
private:
void contextMenuEvent (QContextMenuEvent *event);