From 37d262b1477f6da0cb4e624bfd3fe1bebf62e211 Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Fri, 14 Feb 2014 15:12:34 +0100 Subject: [PATCH 01/17] Splited very long line. --- apps/opencs/model/doc/document.hpp | 5 ++++- apps/opencs/model/world/tablemimedata.hpp | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/apps/opencs/model/doc/document.hpp b/apps/opencs/model/doc/document.hpp index 437b0c513..201fb4342 100644 --- a/apps/opencs/model/doc/document.hpp +++ b/apps/opencs/model/doc/document.hpp @@ -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(); diff --git a/apps/opencs/model/world/tablemimedata.hpp b/apps/opencs/model/world/tablemimedata.hpp index 2829a0754..51785714e 100644 --- a/apps/opencs/model/world/tablemimedata.hpp +++ b/apps/opencs/model/world/tablemimedata.hpp @@ -42,4 +42,4 @@ namespace CSMWorld CSMWorld::UniversalId::Type convertEnums(CSMWorld::ColumnBase::Display type) const; }; } -#endif // TABLEMIMEDATA_H +#endif // TABLEMIMEDATA_H \ No newline at end of file From f3dc45f1ec735159be0b3e387b4dafde46b1db25 Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Fri, 14 Feb 2014 15:29:10 +0100 Subject: [PATCH 02/17] long line split. --- apps/opencs/model/doc/documentmanager.hpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/apps/opencs/model/doc/documentmanager.hpp b/apps/opencs/model/doc/documentmanager.hpp index b80a18642..b969862e9 100644 --- a/apps/opencs/model/doc/documentmanager.hpp +++ b/apps/opencs/model/doc/documentmanager.hpp @@ -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 From d6820b977ead88e15b838d168e9324261f4f58ee Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Sat, 15 Feb 2014 12:22:32 +0100 Subject: [PATCH 03/17] store const ref to the document in the table. --- apps/opencs/view/world/table.cpp | 4 ++-- apps/opencs/view/world/table.hpp | 12 +++++++++++- apps/opencs/view/world/tablesubview.cpp | 2 +- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/apps/opencs/view/world/table.cpp b/apps/opencs/view/world/table.cpp index c077d5f7f..419935991 100644 --- a/apps/opencs/view/world/table.cpp +++ b/apps/opencs/view/world/table.cpp @@ -162,8 +162,8 @@ std::vector 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 (*data.getTableModel (id)); diff --git a/apps/opencs/view/world/table.hpp b/apps/opencs/view/world/table.hpp index 6102a133a..ff08db06f 100644 --- a/apps/opencs/view/world/table.hpp +++ b/apps/opencs/view/world/table.hpp @@ -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. diff --git a/apps/opencs/view/world/tablesubview.cpp b/apps/opencs/view/world/tablesubview.cpp index 981faaf59..d379db51a 100644 --- a/apps/opencs/view/world/tablesubview.cpp +++ b/apps/opencs/view/world/tablesubview.cpp @@ -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); From b1f63947e8a74d0fdce58b511cb588401dd0c4b4 Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Sat, 15 Feb 2014 12:40:07 +0100 Subject: [PATCH 04/17] Checking if the drop comes from same document. --- apps/opencs/model/world/tablemimedata.cpp | 12 +++++++--- apps/opencs/model/world/tablemimedata.hpp | 20 ++++++++++++++-- apps/opencs/view/world/table.cpp | 29 +++++++++++++---------- 3 files changed, 43 insertions(+), 18 deletions(-) diff --git a/apps/opencs/model/world/tablemimedata.cpp b/apps/opencs/model/world/tablemimedata.cpp index b0cf0abcc..ee37dfce6 100644 --- a/apps/opencs/model/world/tablemimedata.cpp +++ b/apps/opencs/model/world/tablemimedata.cpp @@ -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::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) diff --git a/apps/opencs/model/world/tablemimedata.hpp b/apps/opencs/model/world/tablemimedata.hpp index 51785714e..7c05386fb 100644 --- a/apps/opencs/model/world/tablemimedata.hpp +++ b/apps/opencs/model/world/tablemimedata.hpp @@ -10,6 +10,10 @@ #include "universalid.hpp" #include "columnbase.hpp" +namespace CSMDoc +{ + class Document; +} namespace CSMWorld { @@ -24,21 +28,33 @@ namespace CSMWorld class TableMimeData : public QMimeData { public: - TableMimeData(UniversalId id); - TableMimeData(std::vector& id); + TableMimeData(UniversalId id, const CSMDoc::Document& document); + + TableMimeData(std::vector& id, const CSMDoc::Document& document); + ~TableMimeData(); + virtual QStringList formats() const; + std::string getIcon() const; + std::vector 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 mUniversalId; QStringList mObjectsFormats; + const CSMDoc::Document& mDocument; CSMWorld::UniversalId::Type convertEnums(CSMWorld::ColumnBase::Display type) const; }; } diff --git a/apps/opencs/view/world/table.cpp b/apps/opencs/view/world/table.cpp index 419935991..79700458d 100644 --- a/apps/opencs/view/world/table.cpp +++ b/apps/opencs/view/world/table.cpp @@ -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,24 @@ void CSVWorld::Table::dropEvent(QDropEvent *event) { QModelIndex index = indexAt (event->pos()); - CSMWorld::ColumnBase::Display display = static_cast - (mModel->headerData(index.column(), Qt::Horizontal, CSMWorld::ColumnBase::Role_Display).toInt()); - - if (dynamic_cast(event->mimeData())->holdsType(display)) + if (dynamic_cast (event->mimeData())->fromDocument (mDocument)) { - const CSMWorld::TableMimeData* mime = dynamic_cast - (event->mimeData()); + CSMWorld::ColumnBase::Display display = static_cast + (mModel->headerData (index.column(), Qt::Horizontal, CSMWorld::ColumnBase::Role_Display).toInt()); - CSMWorld::UniversalId record (mime->returnMatching (display)); + if (dynamic_cast (event->mimeData())->holdsType (display)) + { + const CSMWorld::TableMimeData* mime = dynamic_cast + (event->mimeData()); - std::auto_ptr command (new CSMWorld::ModifyCommand - (*mProxyModel, index, QVariant (QString::fromStdString (record.getId())))); + CSMWorld::UniversalId record (mime->returnMatching (display)); - mUndoStack.push (command.release()); - } + std::auto_ptr command (new CSMWorld::ModifyCommand + (*mProxyModel, index, QVariant (QString::fromStdString (record.getId())))); + + mUndoStack.push (command.release()); + } + } //TODO handle drops from different document } void CSVWorld::Table::dragMoveEvent(QDragMoveEvent *event) From 4ee90c24e58778ab73262af8b099c0ced4f5de83 Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Sat, 15 Feb 2014 13:22:14 +0100 Subject: [PATCH 05/17] more readable code. --- apps/opencs/view/world/table.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/apps/opencs/view/world/table.cpp b/apps/opencs/view/world/table.cpp index 79700458d..73b1fd226 100644 --- a/apps/opencs/view/world/table.cpp +++ b/apps/opencs/view/world/table.cpp @@ -485,16 +485,14 @@ void CSVWorld::Table::dropEvent(QDropEvent *event) { QModelIndex index = indexAt (event->pos()); - if (dynamic_cast (event->mimeData())->fromDocument (mDocument)) + const CSMWorld::TableMimeData* mime = dynamic_cast (event->mimeData()); + if (mime->fromDocument (mDocument)) { CSMWorld::ColumnBase::Display display = static_cast (mModel->headerData (index.column(), Qt::Horizontal, CSMWorld::ColumnBase::Role_Display).toInt()); - if (dynamic_cast (event->mimeData())->holdsType (display)) + if (mime->holdsType (display)) { - const CSMWorld::TableMimeData* mime = dynamic_cast - (event->mimeData()); - CSMWorld::UniversalId record (mime->returnMatching (display)); std::auto_ptr command (new CSMWorld::ModifyCommand From 56be62b95644789d24568618098bf451aec51667 Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Sat, 15 Feb 2014 13:23:51 +0100 Subject: [PATCH 06/17] small reformatting --- apps/opencs/model/world/tablemimedata.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/opencs/model/world/tablemimedata.hpp b/apps/opencs/model/world/tablemimedata.hpp index 7c05386fb..010a18acb 100644 --- a/apps/opencs/model/world/tablemimedata.hpp +++ b/apps/opencs/model/world/tablemimedata.hpp @@ -53,8 +53,8 @@ namespace CSMWorld private: std::vector mUniversalId; QStringList mObjectsFormats; - const CSMDoc::Document& mDocument; + CSMWorld::UniversalId::Type convertEnums(CSMWorld::ColumnBase::Display type) const; }; } From 97fe5465bf4bf6ec2c72a622eb5c226f1b7a547d Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Sat, 15 Feb 2014 17:55:18 +0100 Subject: [PATCH 07/17] created new files --- apps/opencs/CMakeLists.txt | 2 +- apps/opencs/view/world/scriptedit.cpp | 39 ++++++++++++++++++++++++++ apps/opencs/view/world/scriptedit.hpp | 40 +++++++++++++++++++++++++++ 3 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 apps/opencs/view/world/scriptedit.cpp create mode 100644 apps/opencs/view/world/scriptedit.hpp diff --git a/apps/opencs/CMakeLists.txt b/apps/opencs/CMakeLists.txt index 318cc4912..cd89240c2 100644 --- a/apps/opencs/CMakeLists.txt +++ b/apps/opencs/CMakeLists.txt @@ -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 diff --git a/apps/opencs/view/world/scriptedit.cpp b/apps/opencs/view/world/scriptedit.cpp new file mode 100644 index 000000000..3a71d8f0c --- /dev/null +++ b/apps/opencs/view/world/scriptedit.cpp @@ -0,0 +1,39 @@ +/* + * + * Copyright 2014 Marek Kochanowicz + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License or (at your option) version 3 or any later version + * accepted by the membership of KDE e.V. (or its successor approved + * by the membership of KDE e.V.), which shall act as a proxy + * defined in Section 14 of version 3 of the license. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#include "scriptedit.hpp" + +void CSVWorld::ScriptEdit::dragEnterEvent (QDragEnterEvent* event) +{ + event->acceptProposedAction(); +} + +void CSVWorld::ScriptEdit::dragMoveEvent (QDragMoveEvent* event) +{ + event->accept(); +} + +void CSVWorld::ScriptEdit::dropEvent (QDropEvent* event) +{ + +} +// kate: indent-mode cstyle; indent-width 4; replace-tabs on; diff --git a/apps/opencs/view/world/scriptedit.hpp b/apps/opencs/view/world/scriptedit.hpp new file mode 100644 index 000000000..74e15ecbf --- /dev/null +++ b/apps/opencs/view/world/scriptedit.hpp @@ -0,0 +1,40 @@ +/* + * + * Copyright 2014 Marek Kochanowicz + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License or (at your option) version 3 or any later version + * accepted by the membership of KDE e.V. (or its successor approved + * by the membership of KDE e.V.), which shall act as a proxy + * defined in Section 14 of version 3 of the license. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#ifndef SCRIPTEDIT_H +#define SCRIPTEDIT_H + +#include + +namespace CSVWorld +{ + class ScriptEdit : public QTextEdit + { + void dragEnterEvent (QDragEnterEvent* event); + + void dropEvent (QDropEvent* event); + + void dragMoveEvent (QDragMoveEvent* event); + }; +} +#endif // SCRIPTEDIT_H +// kate: indent-mode cstyle; indent-width 4; replace-tabs on; \ No newline at end of file From 930b77e60a1d7afb00a6a5766e009d0e49d28e56 Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Sat, 15 Feb 2014 19:52:40 +0100 Subject: [PATCH 08/17] allow drag and drop into the script edit window. --- apps/opencs/view/world/scriptedit.cpp | 42 +++++++++++------------- apps/opencs/view/world/scriptedit.hpp | 33 +++++-------------- apps/opencs/view/world/scriptsubview.cpp | 3 +- 3 files changed, 31 insertions(+), 47 deletions(-) diff --git a/apps/opencs/view/world/scriptedit.cpp b/apps/opencs/view/world/scriptedit.cpp index 3a71d8f0c..4eb652add 100644 --- a/apps/opencs/view/world/scriptedit.cpp +++ b/apps/opencs/view/world/scriptedit.cpp @@ -1,27 +1,18 @@ -/* - * - * Copyright 2014 Marek Kochanowicz - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License or (at your option) version 3 or any later version - * accepted by the membership of KDE e.V. (or its successor approved - * by the membership of KDE e.V.), which shall act as a proxy - * defined in Section 14 of version 3 of the license. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - #include "scriptedit.hpp" +#include + +#include + +#include "../../model/world/universalid.hpp" +#include "../../model/world/tablemimedata.hpp" + +CSVWorld::ScriptEdit::ScriptEdit (QWidget* parent) : +QTextEdit(parent) +{ + +} + void CSVWorld::ScriptEdit::dragEnterEvent (QDragEnterEvent* event) { event->acceptProposedAction(); @@ -34,6 +25,13 @@ void CSVWorld::ScriptEdit::dragMoveEvent (QDragMoveEvent* event) void CSVWorld::ScriptEdit::dropEvent (QDropEvent* event) { + const CSMWorld::TableMimeData* mime = dynamic_cast (event->mimeData()); + std::vector records (mime->getData()); + + for (std::vector::iterator it = records.begin(); it != records.end(); ++it) + { + insertPlainText (QString::fromStdString (it->getId())); + } } // kate: indent-mode cstyle; indent-width 4; replace-tabs on; diff --git a/apps/opencs/view/world/scriptedit.hpp b/apps/opencs/view/world/scriptedit.hpp index 74e15ecbf..6df4acc5f 100644 --- a/apps/opencs/view/world/scriptedit.hpp +++ b/apps/opencs/view/world/scriptedit.hpp @@ -1,34 +1,19 @@ -/* - * - * Copyright 2014 Marek Kochanowicz - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License or (at your option) version 3 or any later version - * accepted by the membership of KDE e.V. (or its successor approved - * by the membership of KDE e.V.), which shall act as a proxy - * defined in Section 14 of version 3 of the license. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - #ifndef SCRIPTEDIT_H #define SCRIPTEDIT_H -#include +#include + +class QWidget; namespace CSVWorld { class ScriptEdit : public QTextEdit { + Q_OBJECT + public: + ScriptEdit (QWidget* parent); + + private: void dragEnterEvent (QDragEnterEvent* event); void dropEvent (QDropEvent* event); @@ -37,4 +22,4 @@ namespace CSVWorld }; } #endif // SCRIPTEDIT_H -// kate: indent-mode cstyle; indent-width 4; replace-tabs on; \ No newline at end of file +// kate: indent-mode cstyle; indent-width 4; replace-tabs on; diff --git a/apps/opencs/view/world/scriptsubview.cpp b/apps/opencs/view/world/scriptsubview.cpp index 446c34e5f..4fe5aafac 100644 --- a/apps/opencs/view/world/scriptsubview.cpp +++ b/apps/opencs/view/world/scriptsubview.cpp @@ -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)); mEditor->setAcceptRichText (false); mEditor->setLineWrapMode (QTextEdit::NoWrap); From 41606a67e4bad4184841ac2f492f309fa2f233a5 Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Sat, 15 Feb 2014 20:49:09 +0100 Subject: [PATCH 09/17] implemented whitelist of allowed types in the scripts --- apps/opencs/view/world/scriptedit.cpp | 41 +++++++++++++++++++++++---- apps/opencs/view/world/scriptedit.hpp | 5 ++++ 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/apps/opencs/view/world/scriptedit.cpp b/apps/opencs/view/world/scriptedit.cpp index 4eb652add..20b76ad72 100644 --- a/apps/opencs/view/world/scriptedit.cpp +++ b/apps/opencs/view/world/scriptedit.cpp @@ -1,25 +1,51 @@ #include "scriptedit.hpp" -#include - #include #include "../../model/world/universalid.hpp" #include "../../model/world/tablemimedata.hpp" CSVWorld::ScriptEdit::ScriptEdit (QWidget* parent) : -QTextEdit(parent) + QTextEdit (parent) { - + mAllowedTypes <pos())); event->acceptProposedAction(); } void CSVWorld::ScriptEdit::dragMoveEvent (QDragMoveEvent* event) { + setTextCursor (cursorForPosition (event->pos())); event->accept(); } @@ -27,11 +53,16 @@ void CSVWorld::ScriptEdit::dropEvent (QDropEvent* event) { const CSMWorld::TableMimeData* mime = dynamic_cast (event->mimeData()); + setTextCursor (cursorForPosition (event->pos())); + std::vector records (mime->getData()); for (std::vector::iterator it = records.begin(); it != records.end(); ++it) { - insertPlainText (QString::fromStdString (it->getId())); + if (mAllowedTypes.contains (it->getType())) + { + insertPlainText (QString::fromStdString (it->getId() + " ")); + } } } // kate: indent-mode cstyle; indent-width 4; replace-tabs on; diff --git a/apps/opencs/view/world/scriptedit.hpp b/apps/opencs/view/world/scriptedit.hpp index 6df4acc5f..5355b57ce 100644 --- a/apps/opencs/view/world/scriptedit.hpp +++ b/apps/opencs/view/world/scriptedit.hpp @@ -2,6 +2,9 @@ #define SCRIPTEDIT_H #include +#include + +#include "../../model/world/universalid.hpp" class QWidget; @@ -14,6 +17,8 @@ namespace CSVWorld ScriptEdit (QWidget* parent); private: + QVector mAllowedTypes; + void dragEnterEvent (QDragEnterEvent* event); void dropEvent (QDropEvent* event); From ec8c8a9d88292eee2c34ed50d680b7632b750f30 Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Sat, 15 Feb 2014 22:05:42 +0100 Subject: [PATCH 10/17] -journalinfo +topic --- apps/opencs/view/world/scriptedit.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/opencs/view/world/scriptedit.cpp b/apps/opencs/view/world/scriptedit.cpp index 20b76ad72..c3e38052c 100644 --- a/apps/opencs/view/world/scriptedit.cpp +++ b/apps/opencs/view/world/scriptedit.cpp @@ -9,8 +9,8 @@ CSVWorld::ScriptEdit::ScriptEdit (QWidget* parent) : QTextEdit (parent) { mAllowedTypes < Date: Sat, 15 Feb 2014 22:14:27 +0100 Subject: [PATCH 11/17] Put the id in the quote. --- apps/opencs/view/world/scriptedit.cpp | 5 ++--- apps/opencs/view/world/scriptedit.hpp | 3 +-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/apps/opencs/view/world/scriptedit.cpp b/apps/opencs/view/world/scriptedit.cpp index c3e38052c..88e990c10 100644 --- a/apps/opencs/view/world/scriptedit.cpp +++ b/apps/opencs/view/world/scriptedit.cpp @@ -61,8 +61,7 @@ void CSVWorld::ScriptEdit::dropEvent (QDropEvent* event) { if (mAllowedTypes.contains (it->getType())) { - insertPlainText (QString::fromStdString (it->getId() + " ")); + QString::fromStdString ('"' + it->getId() + '"')); } } -} -// kate: indent-mode cstyle; indent-width 4; replace-tabs on; +} \ No newline at end of file diff --git a/apps/opencs/view/world/scriptedit.hpp b/apps/opencs/view/world/scriptedit.hpp index 5355b57ce..a110f58c8 100644 --- a/apps/opencs/view/world/scriptedit.hpp +++ b/apps/opencs/view/world/scriptedit.hpp @@ -26,5 +26,4 @@ namespace CSVWorld void dragMoveEvent (QDragMoveEvent* event); }; } -#endif // SCRIPTEDIT_H -// kate: indent-mode cstyle; indent-width 4; replace-tabs on; +#endif // SCRIPTEDIT_H \ No newline at end of file From cbe1fe2f9581b1a458b59360c7902b0d6ebd923c Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Sat, 15 Feb 2014 22:38:59 +0100 Subject: [PATCH 12/17] removed misplaced bracket --- apps/opencs/view/world/scriptedit.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/opencs/view/world/scriptedit.cpp b/apps/opencs/view/world/scriptedit.cpp index 88e990c10..f7f82c978 100644 --- a/apps/opencs/view/world/scriptedit.cpp +++ b/apps/opencs/view/world/scriptedit.cpp @@ -61,7 +61,7 @@ void CSVWorld::ScriptEdit::dropEvent (QDropEvent* event) { if (mAllowedTypes.contains (it->getType())) { - QString::fromStdString ('"' + it->getId() + '"')); + QString::fromStdString ('"' + it->getId() + '"'); } } } \ No newline at end of file From 17af865a9fcbb6ebf88f39e6accb4a8fa4840833 Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Sun, 16 Feb 2014 09:51:33 +0100 Subject: [PATCH 13/17] checking for the source of the drop, reject those from other files for now --- apps/opencs/view/world/scriptedit.cpp | 18 +++++++++++------- apps/opencs/view/world/scriptedit.hpp | 8 +++++++- apps/opencs/view/world/scriptsubview.cpp | 2 +- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/apps/opencs/view/world/scriptedit.cpp b/apps/opencs/view/world/scriptedit.cpp index f7f82c978..ecfaa3ba8 100644 --- a/apps/opencs/view/world/scriptedit.cpp +++ b/apps/opencs/view/world/scriptedit.cpp @@ -5,8 +5,9 @@ #include "../../model/world/universalid.hpp" #include "../../model/world/tablemimedata.hpp" -CSVWorld::ScriptEdit::ScriptEdit (QWidget* parent) : - QTextEdit (parent) +CSVWorld::ScriptEdit::ScriptEdit (QWidget* parent, const CSMDoc::Document& document) : + QTextEdit (parent), + mDocument (document) { mAllowedTypes <pos())); - std::vector records (mime->getData()); - - for (std::vector::iterator it = records.begin(); it != records.end(); ++it) + if (mime->fromDocument (mDocument)) { - if (mAllowedTypes.contains (it->getType())) + std::vector records (mime->getData()); + + for (std::vector::iterator it = records.begin(); it != records.end(); ++it) { - QString::fromStdString ('"' + it->getId() + '"'); + if (mAllowedTypes.contains (it->getType())) + { + QString::fromStdString ('"' + it->getId() + '"'); + } } } } \ No newline at end of file diff --git a/apps/opencs/view/world/scriptedit.hpp b/apps/opencs/view/world/scriptedit.hpp index a110f58c8..dc97382b3 100644 --- a/apps/opencs/view/world/scriptedit.hpp +++ b/apps/opencs/view/world/scriptedit.hpp @@ -8,16 +8,22 @@ class QWidget; +namespace CSMDoc +{ + class Document; +} + namespace CSVWorld { class ScriptEdit : public QTextEdit { Q_OBJECT public: - ScriptEdit (QWidget* parent); + ScriptEdit (QWidget* parent, const CSMDoc::Document& document); private: QVector mAllowedTypes; + const CSMDoc::Document& mDocument; void dragEnterEvent (QDragEnterEvent* event); diff --git a/apps/opencs/view/world/scriptsubview.cpp b/apps/opencs/view/world/scriptsubview.cpp index 4fe5aafac..fa41151ca 100644 --- a/apps/opencs/view/world/scriptsubview.cpp +++ b/apps/opencs/view/world/scriptsubview.cpp @@ -28,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 ScriptEdit (this)); + setWidget (mEditor = new ScriptEdit (this, mDocument)); mEditor->setAcceptRichText (false); mEditor->setLineWrapMode (QTextEdit::NoWrap); From 3cc23a9cb3660347f55008d9c801dcfef3240c7a Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Sun, 16 Feb 2014 18:41:42 +0100 Subject: [PATCH 14/17] very basic, but safe putting down " " --- apps/opencs/view/world/scriptedit.cpp | 21 +++++++++++++++++++-- apps/opencs/view/world/scriptedit.hpp | 2 ++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/apps/opencs/view/world/scriptedit.cpp b/apps/opencs/view/world/scriptedit.cpp index ecfaa3ba8..5d80d2904 100644 --- a/apps/opencs/view/world/scriptedit.cpp +++ b/apps/opencs/view/world/scriptedit.cpp @@ -1,6 +1,10 @@ #include "scriptedit.hpp" +#include + #include +#include +#include #include "../../model/world/universalid.hpp" #include "../../model/world/tablemimedata.hpp" @@ -64,8 +68,21 @@ void CSVWorld::ScriptEdit::dropEvent (QDropEvent* event) { if (mAllowedTypes.contains (it->getType())) { - QString::fromStdString ('"' + it->getId() + '"'); + if (stringNeedsQuote(it->getId())) + { + insertPlainText(QString::fromStdString ('"' + it->getId() + '"')); + } else { + insertPlainText(QString::fromStdString (it->getId())); + } } } } -} \ No newline at end of file +} + +bool CSVWorld::ScriptEdit::stringNeedsQuote (const std::string& id) +{ + QString string(QString::fromStdString(id)); // 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… + QRegExp regexp("^[a-z]{1}[a-z|0-9]{0,}$", Qt::CaseInsensitive); + return !(string.contains(regexp)); +} diff --git a/apps/opencs/view/world/scriptedit.hpp b/apps/opencs/view/world/scriptedit.hpp index dc97382b3..afad12048 100644 --- a/apps/opencs/view/world/scriptedit.hpp +++ b/apps/opencs/view/world/scriptedit.hpp @@ -30,6 +30,8 @@ namespace CSVWorld void dropEvent (QDropEvent* event); void dragMoveEvent (QDragMoveEvent* event); + + bool stringNeedsQuote(const std::string& id); }; } #endif // SCRIPTEDIT_H \ No newline at end of file From b83817e05e7f2dd9e519edb1f71be9c0ae7ca602 Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Sun, 16 Feb 2014 20:18:28 +0100 Subject: [PATCH 15/17] May only include alphanumeric characters and underscores and may not start with a number. --- apps/opencs/view/world/scriptedit.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/opencs/view/world/scriptedit.cpp b/apps/opencs/view/world/scriptedit.cpp index 5d80d2904..1e1bb0e2e 100644 --- a/apps/opencs/view/world/scriptedit.cpp +++ b/apps/opencs/view/world/scriptedit.cpp @@ -83,6 +83,6 @@ bool CSVWorld::ScriptEdit::stringNeedsQuote (const std::string& id) { QString string(QString::fromStdString(id)); // 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… - QRegExp regexp("^[a-z]{1}[a-z|0-9]{0,}$", Qt::CaseInsensitive); + QRegExp regexp("^[a-z]{1}[a-z|0-9|_]{0,}$", Qt::CaseInsensitive); return !(string.contains(regexp)); } From e1a0f60041f5ff0d2f7a8970cab33a3c551e904c Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Sun, 16 Feb 2014 20:26:22 +0100 Subject: [PATCH 16/17] allow _foo ids without qoute --- apps/opencs/view/world/scriptedit.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/opencs/view/world/scriptedit.cpp b/apps/opencs/view/world/scriptedit.cpp index 1e1bb0e2e..79b123ee4 100644 --- a/apps/opencs/view/world/scriptedit.cpp +++ b/apps/opencs/view/world/scriptedit.cpp @@ -83,6 +83,6 @@ bool CSVWorld::ScriptEdit::stringNeedsQuote (const std::string& id) { QString string(QString::fromStdString(id)); // 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… - QRegExp regexp("^[a-z]{1}[a-z|0-9|_]{0,}$", Qt::CaseInsensitive); + QRegExp regexp("^[a-z|_]{1}[a-z|0-9|_]{0,}$", Qt::CaseInsensitive); return !(string.contains(regexp)); } From 2bb9e4750718bc1c5cdb859ca0debbee5d53516d Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Mon, 17 Feb 2014 08:58:55 +0100 Subject: [PATCH 17/17] Improvements. --- apps/opencs/view/world/scriptedit.cpp | 10 +++++----- apps/opencs/view/world/scriptedit.hpp | 4 +++- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/apps/opencs/view/world/scriptedit.cpp b/apps/opencs/view/world/scriptedit.cpp index 79b123ee4..fccac75b4 100644 --- a/apps/opencs/view/world/scriptedit.cpp +++ b/apps/opencs/view/world/scriptedit.cpp @@ -11,7 +11,8 @@ CSVWorld::ScriptEdit::ScriptEdit (QWidget* parent, const CSMDoc::Document& document) : QTextEdit (parent), - mDocument (document) + mDocument (document), + mWhiteListQoutes("^[a-z|_]{1}[a-z|0-9|_]{0,}$", Qt::CaseInsensitive) { mAllowedTypes < is only for c++11, so let's use qregexp for now. + const QString string(QString::fromStdString(id)); // 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… - QRegExp regexp("^[a-z|_]{1}[a-z|0-9|_]{0,}$", Qt::CaseInsensitive); - return !(string.contains(regexp)); + return !(string.contains(mWhiteListQoutes)); } diff --git a/apps/opencs/view/world/scriptedit.hpp b/apps/opencs/view/world/scriptedit.hpp index afad12048..b4627c2fe 100644 --- a/apps/opencs/view/world/scriptedit.hpp +++ b/apps/opencs/view/world/scriptedit.hpp @@ -7,6 +7,7 @@ #include "../../model/world/universalid.hpp" class QWidget; +class QRegExp; namespace CSMDoc { @@ -24,6 +25,7 @@ namespace CSVWorld private: QVector mAllowedTypes; const CSMDoc::Document& mDocument; + const QRegExp mWhiteListQoutes; void dragEnterEvent (QDragEnterEvent* event); @@ -31,7 +33,7 @@ namespace CSVWorld void dragMoveEvent (QDragMoveEvent* event); - bool stringNeedsQuote(const std::string& id); + bool stringNeedsQuote(const std::string& id) const; }; } #endif // SCRIPTEDIT_H \ No newline at end of file