mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-21 07:53:53 +00:00
Merge remote-tracking branch 'sirherrbatka/DragDrop'
This commit is contained in:
commit
02c6c65705
11 changed files with 193 additions and 27 deletions
|
@ -60,7 +60,7 @@ opencs_hdrs_noqt (view/doc
|
|||
opencs_units (view/world
|
||||
table tablesubview scriptsubview util regionmapsubview tablebottombox creator genericcreator
|
||||
cellcreator referenceablecreator referencecreator scenesubview scenetoolbar scenetool
|
||||
scenetoolmode infocreator
|
||||
scenetoolmode infocreator scriptedit
|
||||
)
|
||||
|
||||
opencs_units (view/render
|
||||
|
|
|
@ -71,7 +71,10 @@ namespace CSMDoc
|
|||
|
||||
public:
|
||||
|
||||
Document (const Files::ConfigurationManager& configuration, const std::vector< boost::filesystem::path >& files, const boost::filesystem::path& savePath, const boost::filesystem::path& resDir, bool new_);
|
||||
Document (const Files::ConfigurationManager& configuration,
|
||||
const std::vector< boost::filesystem::path >& files,
|
||||
const boost::filesystem::path& savePath,
|
||||
const boost::filesystem::path& resDir, bool new_);
|
||||
|
||||
~Document();
|
||||
|
||||
|
|
|
@ -29,7 +29,9 @@ namespace CSMDoc
|
|||
|
||||
~DocumentManager();
|
||||
|
||||
Document *addDocument (const std::vector< boost::filesystem::path >& files, const boost::filesystem::path& savePath, bool new_);
|
||||
Document *addDocument (const std::vector< boost::filesystem::path >& files,
|
||||
const boost::filesystem::path& savePath,
|
||||
bool new_);
|
||||
///< The ownership of the returned document is not transferred to the caller.
|
||||
///
|
||||
/// \param new_ Do not load the last content file in \a files and instead create in an
|
||||
|
|
|
@ -4,14 +4,15 @@
|
|||
#include "universalid.hpp"
|
||||
#include "columnbase.hpp"
|
||||
|
||||
CSMWorld::TableMimeData::TableMimeData (UniversalId id)
|
||||
CSMWorld::TableMimeData::TableMimeData (UniversalId id, const CSMDoc::Document& document) :
|
||||
mDocument(document)
|
||||
{
|
||||
mUniversalId.push_back (id);
|
||||
mObjectsFormats << QString::fromStdString ("tabledata/" + id.getTypeName());
|
||||
}
|
||||
|
||||
CSMWorld::TableMimeData::TableMimeData (std::vector< CSMWorld::UniversalId >& id) :
|
||||
mUniversalId (id)
|
||||
CSMWorld::TableMimeData::TableMimeData (std::vector< CSMWorld::UniversalId >& id, const CSMDoc::Document& document) :
|
||||
mUniversalId (id), mDocument(document)
|
||||
{
|
||||
for (std::vector<UniversalId>::iterator it (mUniversalId.begin()); it != mUniversalId.end(); ++it)
|
||||
{
|
||||
|
@ -115,6 +116,11 @@ CSMWorld::UniversalId CSMWorld::TableMimeData::returnMatching (CSMWorld::ColumnB
|
|||
throw ("TableMimeData object does not hold object of the seeked type");
|
||||
}
|
||||
|
||||
bool CSMWorld::TableMimeData::fromDocument (const CSMDoc::Document& document) const
|
||||
{
|
||||
return &document == &mDocument;
|
||||
}
|
||||
|
||||
CSMWorld::UniversalId::Type CSMWorld::TableMimeData::convertEnums (CSMWorld::ColumnBase::Display type) const
|
||||
{
|
||||
switch (type)
|
||||
|
|
|
@ -10,6 +10,10 @@
|
|||
#include "universalid.hpp"
|
||||
#include "columnbase.hpp"
|
||||
|
||||
namespace CSMDoc
|
||||
{
|
||||
class Document;
|
||||
}
|
||||
|
||||
namespace CSMWorld
|
||||
{
|
||||
|
@ -24,22 +28,34 @@ namespace CSMWorld
|
|||
class TableMimeData : public QMimeData
|
||||
{
|
||||
public:
|
||||
TableMimeData(UniversalId id);
|
||||
TableMimeData(std::vector<UniversalId>& id);
|
||||
TableMimeData(UniversalId id, const CSMDoc::Document& document);
|
||||
|
||||
TableMimeData(std::vector<UniversalId>& id, const CSMDoc::Document& document);
|
||||
|
||||
~TableMimeData();
|
||||
|
||||
virtual QStringList formats() const;
|
||||
|
||||
std::string getIcon() const;
|
||||
|
||||
std::vector<UniversalId> getData() const;
|
||||
|
||||
bool holdsType(UniversalId::Type type) const;
|
||||
|
||||
bool holdsType(CSMWorld::ColumnBase::Display type) const;
|
||||
|
||||
bool fromDocument(const CSMDoc::Document& document) const;
|
||||
|
||||
UniversalId returnMatching(UniversalId::Type type) const;
|
||||
|
||||
UniversalId returnMatching(CSMWorld::ColumnBase::Display type) const;
|
||||
|
||||
private:
|
||||
std::vector<UniversalId> mUniversalId;
|
||||
QStringList mObjectsFormats;
|
||||
const CSMDoc::Document& mDocument;
|
||||
|
||||
CSMWorld::UniversalId::Type convertEnums(CSMWorld::ColumnBase::Display type) const;
|
||||
};
|
||||
}
|
||||
#endif // TABLEMIMEDATA_H
|
||||
#endif // TABLEMIMEDATA_H
|
88
apps/opencs/view/world/scriptedit.cpp
Normal file
88
apps/opencs/view/world/scriptedit.cpp
Normal file
|
@ -0,0 +1,88 @@
|
|||
#include "scriptedit.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include <QDragEnterEvent>
|
||||
#include <QRegExp>
|
||||
#include <QString>
|
||||
|
||||
#include "../../model/world/universalid.hpp"
|
||||
#include "../../model/world/tablemimedata.hpp"
|
||||
|
||||
CSVWorld::ScriptEdit::ScriptEdit (QWidget* parent, const CSMDoc::Document& document) :
|
||||
QTextEdit (parent),
|
||||
mDocument (document),
|
||||
mWhiteListQoutes("^[a-z|_]{1}[a-z|0-9|_]{0,}$", Qt::CaseInsensitive)
|
||||
{
|
||||
mAllowedTypes <<CSMWorld::UniversalId::Type_Journal
|
||||
<<CSMWorld::UniversalId::Type_Global
|
||||
<<CSMWorld::UniversalId::Type_Topic
|
||||
<<CSMWorld::UniversalId::Type_Sound
|
||||
<<CSMWorld::UniversalId::Type_Spell
|
||||
<<CSMWorld::UniversalId::Type_Cell
|
||||
<<CSMWorld::UniversalId::Type_Referenceable
|
||||
<<CSMWorld::UniversalId::Type_Activator
|
||||
<<CSMWorld::UniversalId::Type_Potion
|
||||
<<CSMWorld::UniversalId::Type_Apparatus
|
||||
<<CSMWorld::UniversalId::Type_Armor
|
||||
<<CSMWorld::UniversalId::Type_Book
|
||||
<<CSMWorld::UniversalId::Type_Clothing
|
||||
<<CSMWorld::UniversalId::Type_Container
|
||||
<<CSMWorld::UniversalId::Type_Creature
|
||||
<<CSMWorld::UniversalId::Type_Door
|
||||
<<CSMWorld::UniversalId::Type_Ingredient
|
||||
<<CSMWorld::UniversalId::Type_CreatureLevelledList
|
||||
<<CSMWorld::UniversalId::Type_ItemLevelledList
|
||||
<<CSMWorld::UniversalId::Type_Light
|
||||
<<CSMWorld::UniversalId::Type_Lockpick
|
||||
<<CSMWorld::UniversalId::Type_Miscellaneous
|
||||
<<CSMWorld::UniversalId::Type_Npc
|
||||
<<CSMWorld::UniversalId::Type_Probe
|
||||
<<CSMWorld::UniversalId::Type_Repair
|
||||
<<CSMWorld::UniversalId::Type_Static
|
||||
<<CSMWorld::UniversalId::Type_Weapon;
|
||||
}
|
||||
|
||||
void CSVWorld::ScriptEdit::dragEnterEvent (QDragEnterEvent* event)
|
||||
{
|
||||
setTextCursor (cursorForPosition (event->pos()));
|
||||
event->acceptProposedAction();
|
||||
}
|
||||
|
||||
void CSVWorld::ScriptEdit::dragMoveEvent (QDragMoveEvent* event)
|
||||
{
|
||||
setTextCursor (cursorForPosition (event->pos()));
|
||||
event->accept();
|
||||
}
|
||||
|
||||
void CSVWorld::ScriptEdit::dropEvent (QDropEvent* event)
|
||||
{
|
||||
const CSMWorld::TableMimeData* mime = dynamic_cast<const CSMWorld::TableMimeData*> (event->mimeData());
|
||||
|
||||
setTextCursor (cursorForPosition (event->pos()));
|
||||
|
||||
if (mime->fromDocument (mDocument))
|
||||
{
|
||||
std::vector<CSMWorld::UniversalId> records (mime->getData());
|
||||
|
||||
for (std::vector<CSMWorld::UniversalId>::iterator it = records.begin(); it != records.end(); ++it)
|
||||
{
|
||||
if (mAllowedTypes.contains (it->getType()))
|
||||
{
|
||||
if (stringNeedsQuote(it->getId()))
|
||||
{
|
||||
insertPlainText(QString::fromStdString ('"' + it->getId() + '"'));
|
||||
} else {
|
||||
insertPlainText(QString::fromStdString (it->getId()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool CSVWorld::ScriptEdit::stringNeedsQuote (const std::string& id) const
|
||||
{
|
||||
const QString string(QString::fromStdString(id)); //<regex> is only for c++11, so let's use qregexp for now.
|
||||
//I'm not quite sure when do we need to put quotes. To be safe we will use quotes for anything other than…
|
||||
return !(string.contains(mWhiteListQoutes));
|
||||
}
|
39
apps/opencs/view/world/scriptedit.hpp
Normal file
39
apps/opencs/view/world/scriptedit.hpp
Normal file
|
@ -0,0 +1,39 @@
|
|||
#ifndef SCRIPTEDIT_H
|
||||
#define SCRIPTEDIT_H
|
||||
|
||||
#include <qtextedit.h>
|
||||
#include <QVector>
|
||||
|
||||
#include "../../model/world/universalid.hpp"
|
||||
|
||||
class QWidget;
|
||||
class QRegExp;
|
||||
|
||||
namespace CSMDoc
|
||||
{
|
||||
class Document;
|
||||
}
|
||||
|
||||
namespace CSVWorld
|
||||
{
|
||||
class ScriptEdit : public QTextEdit
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
ScriptEdit (QWidget* parent, const CSMDoc::Document& document);
|
||||
|
||||
private:
|
||||
QVector<CSMWorld::UniversalId::Type> mAllowedTypes;
|
||||
const CSMDoc::Document& mDocument;
|
||||
const QRegExp mWhiteListQoutes;
|
||||
|
||||
void dragEnterEvent (QDragEnterEvent* event);
|
||||
|
||||
void dropEvent (QDropEvent* event);
|
||||
|
||||
void dragMoveEvent (QDragMoveEvent* event);
|
||||
|
||||
bool stringNeedsQuote(const std::string& id) const;
|
||||
};
|
||||
}
|
||||
#endif // SCRIPTEDIT_H
|
|
@ -13,6 +13,7 @@
|
|||
#include "../../model/world/idtable.hpp"
|
||||
|
||||
#include "scripthighlighter.hpp"
|
||||
#include "scriptedit.hpp"
|
||||
|
||||
CSVWorld::ScriptSubView::ChangeLock::ChangeLock (ScriptSubView& view) : mView (view)
|
||||
{
|
||||
|
@ -27,7 +28,7 @@ CSVWorld::ScriptSubView::ChangeLock::~ChangeLock()
|
|||
CSVWorld::ScriptSubView::ScriptSubView (const CSMWorld::UniversalId& id, CSMDoc::Document& document)
|
||||
: SubView (id), mDocument (document), mColumn (-1), mChangeLocked (0)
|
||||
{
|
||||
setWidget (mEditor = new QTextEdit (this));
|
||||
setWidget (mEditor = new ScriptEdit (this, mDocument));
|
||||
|
||||
mEditor->setAcceptRichText (false);
|
||||
mEditor->setLineWrapMode (QTextEdit::NoWrap);
|
||||
|
|
|
@ -162,8 +162,8 @@ std::vector<std::string> CSVWorld::Table::listDeletableSelectedIds() const
|
|||
}
|
||||
|
||||
CSVWorld::Table::Table (const CSMWorld::UniversalId& id, CSMWorld::Data& data, QUndoStack& undoStack,
|
||||
bool createAndDelete, bool sorting)
|
||||
: mUndoStack (undoStack), mCreateAction (0), mCloneAction(0), mEditLock (false), mRecordStatusDisplay (0)
|
||||
bool createAndDelete, bool sorting, const CSMDoc::Document& document)
|
||||
: mUndoStack (undoStack), mCreateAction (0), mCloneAction(0), mEditLock (false), mRecordStatusDisplay (0), mDocument(document)
|
||||
{
|
||||
mModel = &dynamic_cast<CSMWorld::IdTable&> (*data.getTableModel (id));
|
||||
|
||||
|
@ -455,7 +455,7 @@ void CSVWorld::Table::mouseMoveEvent (QMouseEvent* event)
|
|||
|
||||
if (selectedRows.size() == 1)
|
||||
{
|
||||
mime = new CSMWorld::TableMimeData (getUniversalId (selectedRows.begin()->row()));
|
||||
mime = new CSMWorld::TableMimeData (getUniversalId (selectedRows.begin()->row()), mDocument);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -466,7 +466,7 @@ void CSVWorld::Table::mouseMoveEvent (QMouseEvent* event)
|
|||
idToDrag.push_back (getUniversalId (it.row()));
|
||||
}
|
||||
|
||||
mime = new CSMWorld::TableMimeData (idToDrag);
|
||||
mime = new CSMWorld::TableMimeData (idToDrag, mDocument);
|
||||
}
|
||||
|
||||
drag->setMimeData (mime);
|
||||
|
@ -485,21 +485,22 @@ void CSVWorld::Table::dropEvent(QDropEvent *event)
|
|||
{
|
||||
QModelIndex index = indexAt (event->pos());
|
||||
|
||||
CSMWorld::ColumnBase::Display display = static_cast<CSMWorld::ColumnBase::Display>
|
||||
(mModel->headerData(index.column(), Qt::Horizontal, CSMWorld::ColumnBase::Role_Display).toInt());
|
||||
|
||||
if (dynamic_cast<const CSMWorld::TableMimeData*>(event->mimeData())->holdsType(display))
|
||||
const CSMWorld::TableMimeData* mime = dynamic_cast<const CSMWorld::TableMimeData*> (event->mimeData());
|
||||
if (mime->fromDocument (mDocument))
|
||||
{
|
||||
const CSMWorld::TableMimeData* mime = dynamic_cast<const CSMWorld::TableMimeData*>
|
||||
(event->mimeData());
|
||||
CSMWorld::ColumnBase::Display display = static_cast<CSMWorld::ColumnBase::Display>
|
||||
(mModel->headerData (index.column(), Qt::Horizontal, CSMWorld::ColumnBase::Role_Display).toInt());
|
||||
|
||||
CSMWorld::UniversalId record (mime->returnMatching (display));
|
||||
if (mime->holdsType (display))
|
||||
{
|
||||
CSMWorld::UniversalId record (mime->returnMatching (display));
|
||||
|
||||
std::auto_ptr<CSMWorld::ModifyCommand> command (new CSMWorld::ModifyCommand
|
||||
(*mProxyModel, index, QVariant (QString::fromStdString (record.getId()))));
|
||||
std::auto_ptr<CSMWorld::ModifyCommand> command (new CSMWorld::ModifyCommand
|
||||
(*mProxyModel, index, QVariant (QString::fromStdString (record.getId()))));
|
||||
|
||||
mUndoStack.push (command.release());
|
||||
}
|
||||
mUndoStack.push (command.release());
|
||||
}
|
||||
} //TODO handle drops from different document
|
||||
}
|
||||
|
||||
void CSVWorld::Table::dragMoveEvent(QDragMoveEvent *event)
|
||||
|
|
|
@ -9,6 +9,10 @@
|
|||
|
||||
#include "../../model/filter/node.hpp"
|
||||
|
||||
namespace CSMDoc {
|
||||
class Document;
|
||||
}
|
||||
|
||||
class QUndoStack;
|
||||
class QAction;
|
||||
|
||||
|
@ -43,6 +47,10 @@ namespace CSVWorld
|
|||
bool mEditLock;
|
||||
int mRecordStatusDisplay;
|
||||
|
||||
/// \brief This variable is used exclusivly for checking if dropEvents came from the same document. Most likely you
|
||||
/// should NOT use it for anything else.
|
||||
const CSMDoc::Document& mDocument;
|
||||
|
||||
private:
|
||||
|
||||
void contextMenuEvent (QContextMenuEvent *event);
|
||||
|
@ -62,7 +70,9 @@ namespace CSVWorld
|
|||
|
||||
public:
|
||||
|
||||
Table (const CSMWorld::UniversalId& id, CSMWorld::Data& data, QUndoStack& undoStack, bool createAndDelete, bool sorting);
|
||||
Table (const CSMWorld::UniversalId& id, CSMWorld::Data& data, QUndoStack& undoStack, bool createAndDelete,
|
||||
bool sorting, const CSMDoc::Document& document);
|
||||
|
||||
///< \param createAndDelete Allow creation and deletion of records.
|
||||
/// \param sorting Allow changing order of rows in the view via column headers.
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ CSVWorld::TableSubView::TableSubView (const CSMWorld::UniversalId& id, CSMDoc::D
|
|||
new TableBottomBox (creatorFactory, document.getData(), document.getUndoStack(), id, this), 0);
|
||||
|
||||
layout->insertWidget (0, mTable =
|
||||
new Table (id, document.getData(), document.getUndoStack(), mBottom->canCreateAndDelete(), sorting), 2);
|
||||
new Table (id, document.getData(), document.getUndoStack(), mBottom->canCreateAndDelete(), sorting, document), 2);
|
||||
|
||||
CSVFilter::FilterBox *filterBox = new CSVFilter::FilterBox (document.getData(), this);
|
||||
|
||||
|
|
Loading…
Reference in a new issue