From 18fc8acc71c5d8839668c1cadc2555fdc6b4b438 Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Tue, 29 Apr 2014 12:27:26 +0200 Subject: [PATCH] able to drag existing cells from the regionmap --- apps/opencs/view/world/dragrecordtable.cpp | 5 +++-- apps/opencs/view/world/dragrecordtable.hpp | 9 +++++---- apps/opencs/view/world/regionmap.cpp | 17 ++++++++++++++++- apps/opencs/view/world/regionmap.hpp | 11 +++++++++-- apps/opencs/view/world/table.hpp | 2 -- 5 files changed, 33 insertions(+), 11 deletions(-) diff --git a/apps/opencs/view/world/dragrecordtable.cpp b/apps/opencs/view/world/dragrecordtable.cpp index 4aa13308a1..f962f6f10f 100644 --- a/apps/opencs/view/world/dragrecordtable.cpp +++ b/apps/opencs/view/world/dragrecordtable.cpp @@ -16,6 +16,7 @@ void CSVWorld::DragRecordTable::startDrag (const CSVWorld::DragRecordTable& tabl } } -CSVWorld::DragRecordTable::DragRecordTable (CSMDoc::Document& document) : -mDocument(document) +CSVWorld::DragRecordTable::DragRecordTable (CSMDoc::Document& document, QWidget* parent) : +mDocument(document), +QTableView(parent) {} diff --git a/apps/opencs/view/world/dragrecordtable.hpp b/apps/opencs/view/world/dragrecordtable.hpp index 4e5389f061..7a2b517430 100644 --- a/apps/opencs/view/world/dragrecordtable.hpp +++ b/apps/opencs/view/world/dragrecordtable.hpp @@ -1,8 +1,9 @@ -#ifndef CSV_WORLD_REGIONMAP_H -#define CSV_WORLD_REGIONMAP_H +#ifndef CSV_WORLD_DRAGRECORDTABLE_H +#define CSV_WORLD_DRAGRECORDTABLE_H #include +class QWidget; class QAction; namespace CSMDoc @@ -23,7 +24,7 @@ namespace CSVWorld CSMDoc::Document& mDocument; public: - DragRecordTable(CSMDoc::Document& document); + DragRecordTable(CSMDoc::Document& document, QWidget* parent = NULL); virtual std::vector getDragedRecords() const = 0; @@ -33,4 +34,4 @@ namespace CSVWorld } #endif - + diff --git a/apps/opencs/view/world/regionmap.cpp b/apps/opencs/view/world/regionmap.cpp index bfce1fce46..85b79c3f2c 100644 --- a/apps/opencs/view/world/regionmap.cpp +++ b/apps/opencs/view/world/regionmap.cpp @@ -181,7 +181,7 @@ void CSVWorld::RegionMap::setRegion (const std::string& regionId) CSVWorld::RegionMap::RegionMap (const CSMWorld::UniversalId& universalId, CSMDoc::Document& document, QWidget *parent) -: QTableView (parent), mEditLock (false), mDocument (document) +: mEditLock (false), DragRecordTable(document, parent) { verticalHeader()->hide(); horizontalHeader()->hide(); @@ -348,4 +348,19 @@ void CSVWorld::RegionMap::viewInTable() void CSVWorld::RegionMap::mouseMoveEvent (QMouseEvent* event) { + startDrag(*this); +} + +std::vector< CSMWorld::UniversalId > CSVWorld::RegionMap::getDragedRecords() const +{ + QModelIndexList selected = getSelectedCells(); + std::vector ids; + foreach (QModelIndex it, selected) + { + ids.push_back( + CSMWorld::UniversalId + (CSMWorld::UniversalId::Type_Cell, + model()->data(it, CSMWorld::RegionMap::Role_CellId).toString().toUtf8().constData())); + } + return ids; } diff --git a/apps/opencs/view/world/regionmap.hpp b/apps/opencs/view/world/regionmap.hpp index d894fd9ccf..596ddfaed5 100644 --- a/apps/opencs/view/world/regionmap.hpp +++ b/apps/opencs/view/world/regionmap.hpp @@ -1,8 +1,14 @@ #ifndef CSV_WORLD_REGIONMAP_H #define CSV_WORLD_REGIONMAP_H +#include +#include + +#include #include +#include "./dragrecordtable.hpp" + class QAction; namespace CSMDoc @@ -17,7 +23,7 @@ namespace CSMWorld namespace CSVWorld { - class RegionMap : public QTableView + class RegionMap : public DragRecordTable { Q_OBJECT @@ -30,7 +36,6 @@ namespace CSVWorld QAction *mViewAction; QAction *mViewInTableAction; bool mEditLock; - CSMDoc::Document& mDocument; std::string mRegionId; private: @@ -59,6 +64,8 @@ namespace CSVWorld void setEditLock (bool locked); + virtual std::vector getDragedRecords() const; + signals: void editRequest (const CSMWorld::UniversalId& id, const std::string& hint); diff --git a/apps/opencs/view/world/table.hpp b/apps/opencs/view/world/table.hpp index 926ba0e956..30b487ce84 100644 --- a/apps/opencs/view/world/table.hpp +++ b/apps/opencs/view/world/table.hpp @@ -4,7 +4,6 @@ #include #include -#include #include #include "../../model/filter/node.hpp" @@ -25,7 +24,6 @@ namespace CSMWorld class UniversalId; class IdTableProxyModel; class IdTable; - class TableMimeData; } namespace CSVWorld