From 27ece7f36aec12f14987227b37a3af45b1f7e81b Mon Sep 17 00:00:00 2001 From: Stanislav Bas Date: Sat, 20 Jun 2015 17:33:36 +0300 Subject: [PATCH 01/11] Rework DropLineEdit. Make it type-sensitive --- apps/opencs/CMakeLists.txt | 2 +- apps/opencs/view/widget/droplineedit.cpp | 82 +++++++++++++++++++ apps/opencs/view/widget/droplineedit.hpp | 50 +++++++++++ apps/opencs/view/world/dialoguesubview.cpp | 5 +- .../view/world/idcompletiondelegate.cpp | 4 +- apps/opencs/view/world/util.cpp | 31 +------ apps/opencs/view/world/util.hpp | 19 ----- 7 files changed, 143 insertions(+), 50 deletions(-) create mode 100644 apps/opencs/view/widget/droplineedit.cpp create mode 100644 apps/opencs/view/widget/droplineedit.hpp diff --git a/apps/opencs/CMakeLists.txt b/apps/opencs/CMakeLists.txt index d86798af95..fa703e4972 100644 --- a/apps/opencs/CMakeLists.txt +++ b/apps/opencs/CMakeLists.txt @@ -75,7 +75,7 @@ opencs_units_noqt (view/world opencs_units (view/widget scenetoolbar scenetool scenetoolmode pushbutton scenetooltoggle scenetoolrun modebutton - scenetooltoggle2 completerpopup coloreditor colorpickerpopup + scenetooltoggle2 completerpopup coloreditor colorpickerpopup droplineedit ) opencs_units (view/render diff --git a/apps/opencs/view/widget/droplineedit.cpp b/apps/opencs/view/widget/droplineedit.cpp new file mode 100644 index 0000000000..0b2ac63816 --- /dev/null +++ b/apps/opencs/view/widget/droplineedit.cpp @@ -0,0 +1,82 @@ +#include "droplineedit.hpp" + +#include + +#include "../../model/world/tablemimedata.hpp" + +namespace +{ + const CSMWorld::TableMimeData *getEventMimeData(QDropEvent *event) + { + Q_ASSERT(event != NULL); + return dynamic_cast(event->mimeData()); + } +} + +CSVWidget::DropLineEdit::DropLineEdit(QWidget *parent, CSMWorld::UniversalId::Type type) + : QLineEdit(parent), + mDropType(type) +{ + setAcceptDrops(true); +} + +void CSVWidget::DropLineEdit::dragEnterEvent(QDragEnterEvent *event) +{ + if (canAcceptEventData(event)) + { + event->acceptProposedAction(); + } +} + +void CSVWidget::DropLineEdit::dragMoveEvent(QDragMoveEvent *event) +{ + if (canAcceptEventData(event)) + { + event->accept(); + } +} + +void CSVWidget::DropLineEdit::dropEvent(QDropEvent *event) +{ + const CSMWorld::TableMimeData *data = getEventMimeData(event); + if (data == NULL) // May happen when non-records (e.g. plain text) are dragged and dropped + { + return; + } + + int dataIndex = getAcceptedDataIndex(*data); + if (dataIndex != -1) + { + setText(data->getData()[dataIndex].getId().c_str()); + emit tableMimeDataDropped(data->getData(), data->getDocumentPtr()); + } +} + +bool CSVWidget::DropLineEdit::canAcceptEventData(QDropEvent *event) const +{ + const CSMWorld::TableMimeData *data = getEventMimeData(event); + if (data == NULL) // May happen when non-records (e.g. plain text) are dragged and dropped + { + return false; + } + return getAcceptedDataIndex(*data) != -1; +} + +int CSVWidget::DropLineEdit::getAcceptedDataIndex(const CSMWorld::TableMimeData &data) const +{ + if (mDropType == CSMWorld::UniversalId::Type_None) + { + return 0; + } + + std::vector idData = data.getData(); + int size = static_cast(idData.size()); + for (int i = 0; i < size; ++i) + { + if (idData[i].getType() == mDropType) + { + return i; + } + } + return -1; +} diff --git a/apps/opencs/view/widget/droplineedit.hpp b/apps/opencs/view/widget/droplineedit.hpp new file mode 100644 index 0000000000..e49c947b48 --- /dev/null +++ b/apps/opencs/view/widget/droplineedit.hpp @@ -0,0 +1,50 @@ +#ifndef CSV_WIDGET_DROPLINEEDIT_HPP +#define CSV_WIDGET_DROPLINEEDIT_HPP + +#include + +#include "../../model/world/universalid.hpp" + +namespace CSMDoc +{ + class Document; +} + +namespace CSMWorld +{ + class TableMimeData; +} + +namespace CSVWidget +{ + class DropLineEdit : public QLineEdit + { + Q_OBJECT + + CSMWorld::UniversalId::Type mDropType; + ///< The accepted ID type for this LineEdit. + ///< If \a mDropType has Type_None type, this LineEdit accepts all ID types + + bool canAcceptEventData(QDropEvent *event) const; + ///< Checks whether the \a event contains CSMWorld::TableMimeData with a proper ID type + + int getAcceptedDataIndex(const CSMWorld::TableMimeData &data) const; + ///< Checks whether the \a data has a proper type + ///< \return -1 if there is no suitable data (ID type) + + public: + DropLineEdit(QWidget *parent = 0, + CSMWorld::UniversalId::Type type = CSMWorld::UniversalId::Type_None); + + protected: + void dragEnterEvent(QDragEnterEvent *event); + void dragMoveEvent(QDragMoveEvent *event); + void dropEvent(QDropEvent *event); + + signals: + void tableMimeDataDropped(const std::vector &data, + const CSMDoc::Document *document); + }; +} + +#endif diff --git a/apps/opencs/view/world/dialoguesubview.cpp b/apps/opencs/view/world/dialoguesubview.cpp index 5d9eda3f24..a1dbc902ee 100644 --- a/apps/opencs/view/world/dialoguesubview.cpp +++ b/apps/opencs/view/world/dialoguesubview.cpp @@ -34,6 +34,7 @@ #include "../../model/doc/document.hpp" #include "../widget/coloreditor.hpp" +#include "../widget/droplineedit.hpp" #include "recordstatusdelegate.hpp" #include "util.hpp" @@ -306,7 +307,7 @@ QWidget* CSVWorld::DialogueDelegateDispatcher::makeEditor(CSMWorld::ColumnBase:: // NOTE: For each entry in CSVWorld::CommandDelegate::createEditor() a corresponding entry // is required here - if (qobject_cast(editor)) + if (qobject_cast(editor)) { connect(editor, SIGNAL(editingFinished()), proxy, SLOT(editorDataCommited())); @@ -850,7 +851,7 @@ void CSVWorld::DialogueSubView::tableMimeDataDropped (QWidget* editor, { if (document == &mDocument) { - qobject_cast(editor)->setText(id.getId().c_str()); + qobject_cast(editor)->setText(id.getId().c_str()); } } diff --git a/apps/opencs/view/world/idcompletiondelegate.cpp b/apps/opencs/view/world/idcompletiondelegate.cpp index 056026471b..5c92e6576d 100644 --- a/apps/opencs/view/world/idcompletiondelegate.cpp +++ b/apps/opencs/view/world/idcompletiondelegate.cpp @@ -2,6 +2,8 @@ #include "../../model/world/idcompletionmanager.hpp" +#include "../widget/droplineedit.hpp" + CSVWorld::IdCompletionDelegate::IdCompletionDelegate(CSMWorld::CommandDispatcher *dispatcher, CSMDoc::Document& document, QObject *parent) @@ -26,7 +28,7 @@ QWidget *CSVWorld::IdCompletionDelegate::createEditor(QWidget *parent, } CSMWorld::IdCompletionManager &completionManager = getDocument().getIdCompletionManager(); - DropLineEdit *editor = new DropLineEdit(parent); + CSVWidget::DropLineEdit *editor = new CSVWidget::DropLineEdit(parent); editor->setCompleter(completionManager.getCompleter(display).get()); return editor; } diff --git a/apps/opencs/view/world/util.cpp b/apps/opencs/view/world/util.cpp index 5974987c0c..684327fc2c 100644 --- a/apps/opencs/view/world/util.cpp +++ b/apps/opencs/view/world/util.cpp @@ -17,7 +17,10 @@ #include "../../model/world/commands.hpp" #include "../../model/world/tablemimedata.hpp" #include "../../model/world/commanddispatcher.hpp" + #include "../widget/coloreditor.hpp" +#include "../widget/droplineedit.hpp" + #include "dialoguespinbox.hpp" #include "scriptedit.hpp" @@ -250,7 +253,7 @@ QWidget *CSVWorld::CommandDelegate::createEditor (QWidget *parent, const QStyleO case CSMWorld::ColumnBase::Display_Video: case CSMWorld::ColumnBase::Display_GlobalVariable: - return new DropLineEdit(parent); + return new CSVWidget::DropLineEdit(parent); case CSMWorld::ColumnBase::Display_ScriptLines: @@ -324,29 +327,3 @@ void CSVWorld::CommandDelegate::setEditorData (QWidget *editor, const QModelInde } } - -CSVWorld::DropLineEdit::DropLineEdit(QWidget* parent) : -QLineEdit(parent) -{ - setAcceptDrops(true); -} - -void CSVWorld::DropLineEdit::dragEnterEvent(QDragEnterEvent *event) -{ - event->acceptProposedAction(); -} - -void CSVWorld::DropLineEdit::dragMoveEvent(QDragMoveEvent *event) -{ - event->accept(); -} - -void CSVWorld::DropLineEdit::dropEvent(QDropEvent *event) -{ - const CSMWorld::TableMimeData* data(dynamic_cast(event->mimeData())); - if (!data) // May happen when non-records (e.g. plain text) are dragged and dropped - return; - - emit tableMimeDataDropped(data->getData(), data->getDocumentPtr()); - //WIP -} diff --git a/apps/opencs/view/world/util.hpp b/apps/opencs/view/world/util.hpp index 8355e971cb..d695be0d7e 100644 --- a/apps/opencs/view/world/util.hpp +++ b/apps/opencs/view/world/util.hpp @@ -5,7 +5,6 @@ #include #include -#include #include "../../model/world/columnbase.hpp" #include "../../model/doc/document.hpp" @@ -91,24 +90,6 @@ namespace CSVWorld }; - class DropLineEdit : public QLineEdit - { - Q_OBJECT - - public: - DropLineEdit(QWidget *parent); - - private: - void dragEnterEvent(QDragEnterEvent *event); - - void dragMoveEvent(QDragMoveEvent *event); - - void dropEvent(QDropEvent *event); - - signals: - void tableMimeDataDropped(const std::vector& data, const CSMDoc::Document* document); - }; - ///< \brief Use commands instead of manipulating the model directly class CommandDelegate : public QStyledItemDelegate { From 64701b273d041411bc75caaf9527ea2183ee6679 Mon Sep 17 00:00:00 2001 From: Stanislav Bas Date: Sat, 20 Jun 2015 18:29:31 +0300 Subject: [PATCH 02/11] LineEdits for ID values accept drops with a proper type --- apps/opencs/view/widget/droplineedit.cpp | 9 ++++++++- apps/opencs/view/widget/droplineedit.hpp | 5 +++-- apps/opencs/view/world/idcompletiondelegate.cpp | 2 +- apps/opencs/view/world/util.cpp | 2 +- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/apps/opencs/view/widget/droplineedit.cpp b/apps/opencs/view/widget/droplineedit.cpp index 0b2ac63816..f3500dcd25 100644 --- a/apps/opencs/view/widget/droplineedit.cpp +++ b/apps/opencs/view/widget/droplineedit.cpp @@ -13,13 +13,20 @@ namespace } } -CSVWidget::DropLineEdit::DropLineEdit(QWidget *parent, CSMWorld::UniversalId::Type type) +CSVWidget::DropLineEdit::DropLineEdit(CSMWorld::UniversalId::Type type, QWidget *parent) : QLineEdit(parent), mDropType(type) { setAcceptDrops(true); } +CSVWidget::DropLineEdit::DropLineEdit(CSMWorld::ColumnBase::Display display, QWidget *parent) + : QLineEdit(parent), + mDropType(CSMWorld::TableMimeData::convertEnums(display)) +{ + setAcceptDrops(true); +} + void CSVWidget::DropLineEdit::dragEnterEvent(QDragEnterEvent *event) { if (canAcceptEventData(event)) diff --git a/apps/opencs/view/widget/droplineedit.hpp b/apps/opencs/view/widget/droplineedit.hpp index e49c947b48..7ba0513cc7 100644 --- a/apps/opencs/view/widget/droplineedit.hpp +++ b/apps/opencs/view/widget/droplineedit.hpp @@ -3,6 +3,7 @@ #include +#include "../../model/world/columnbase.hpp" #include "../../model/world/universalid.hpp" namespace CSMDoc @@ -33,8 +34,8 @@ namespace CSVWidget ///< \return -1 if there is no suitable data (ID type) public: - DropLineEdit(QWidget *parent = 0, - CSMWorld::UniversalId::Type type = CSMWorld::UniversalId::Type_None); + DropLineEdit(CSMWorld::UniversalId::Type type, QWidget *parent = 0); + DropLineEdit(CSMWorld::ColumnBase::Display display, QWidget *parent = 0); protected: void dragEnterEvent(QDragEnterEvent *event); diff --git a/apps/opencs/view/world/idcompletiondelegate.cpp b/apps/opencs/view/world/idcompletiondelegate.cpp index 5c92e6576d..970490828f 100644 --- a/apps/opencs/view/world/idcompletiondelegate.cpp +++ b/apps/opencs/view/world/idcompletiondelegate.cpp @@ -28,7 +28,7 @@ QWidget *CSVWorld::IdCompletionDelegate::createEditor(QWidget *parent, } CSMWorld::IdCompletionManager &completionManager = getDocument().getIdCompletionManager(); - CSVWidget::DropLineEdit *editor = new CSVWidget::DropLineEdit(parent); + CSVWidget::DropLineEdit *editor = new CSVWidget::DropLineEdit(display, parent); editor->setCompleter(completionManager.getCompleter(display).get()); return editor; } diff --git a/apps/opencs/view/world/util.cpp b/apps/opencs/view/world/util.cpp index 684327fc2c..d3969dad42 100644 --- a/apps/opencs/view/world/util.cpp +++ b/apps/opencs/view/world/util.cpp @@ -253,7 +253,7 @@ QWidget *CSVWorld::CommandDelegate::createEditor (QWidget *parent, const QStyleO case CSMWorld::ColumnBase::Display_Video: case CSMWorld::ColumnBase::Display_GlobalVariable: - return new CSVWidget::DropLineEdit(parent); + return new CSVWidget::DropLineEdit(CSMWorld::UniversalId::Type_None, parent); case CSMWorld::ColumnBase::Display_ScriptLines: From 7dcdd130bb65be9fa79d8240946458420c2248d4 Mon Sep 17 00:00:00 2001 From: Stanislav Bas Date: Sat, 20 Jun 2015 20:52:47 +0300 Subject: [PATCH 03/11] Rework Dialogue subview code according to DropLineEdit changes --- apps/opencs/view/widget/droplineedit.cpp | 9 ++- apps/opencs/view/widget/droplineedit.hpp | 3 +- apps/opencs/view/world/dialoguesubview.cpp | 70 +--------------------- apps/opencs/view/world/dialoguesubview.hpp | 20 ------- apps/opencs/view/world/util.cpp | 24 ++------ 5 files changed, 14 insertions(+), 112 deletions(-) diff --git a/apps/opencs/view/widget/droplineedit.cpp b/apps/opencs/view/widget/droplineedit.cpp index f3500dcd25..6dae157468 100644 --- a/apps/opencs/view/widget/droplineedit.cpp +++ b/apps/opencs/view/widget/droplineedit.cpp @@ -54,8 +54,9 @@ void CSVWidget::DropLineEdit::dropEvent(QDropEvent *event) int dataIndex = getAcceptedDataIndex(*data); if (dataIndex != -1) { - setText(data->getData()[dataIndex].getId().c_str()); - emit tableMimeDataDropped(data->getData(), data->getDocumentPtr()); + std::vector idData = data->getData(); + setText(idData[dataIndex].getId().c_str()); + emit tableMimeDataDropped(idData[dataIndex], data->getDocumentPtr()); } } @@ -76,11 +77,13 @@ int CSVWidget::DropLineEdit::getAcceptedDataIndex(const CSMWorld::TableMimeData return 0; } + bool isReferenceable = mDropType == CSMWorld::UniversalId::Type_Referenceable; std::vector idData = data.getData(); int size = static_cast(idData.size()); for (int i = 0; i < size; ++i) { - if (idData[i].getType() == mDropType) + CSMWorld::UniversalId::Type type = idData[i].getType(); + if (type == mDropType || isReferenceable && CSMWorld::TableMimeData::isReferencable(type)) { return i; } diff --git a/apps/opencs/view/widget/droplineedit.hpp b/apps/opencs/view/widget/droplineedit.hpp index 7ba0513cc7..ce086b7dc1 100644 --- a/apps/opencs/view/widget/droplineedit.hpp +++ b/apps/opencs/view/widget/droplineedit.hpp @@ -43,8 +43,7 @@ namespace CSVWidget void dropEvent(QDropEvent *event); signals: - void tableMimeDataDropped(const std::vector &data, - const CSMDoc::Document *document); + void tableMimeDataDropped(const CSMWorld::UniversalId &id, const CSMDoc::Document *document); }; } diff --git a/apps/opencs/view/world/dialoguesubview.cpp b/apps/opencs/view/world/dialoguesubview.cpp index a1dbc902ee..284c5928ba 100644 --- a/apps/opencs/view/world/dialoguesubview.cpp +++ b/apps/opencs/view/world/dialoguesubview.cpp @@ -130,52 +130,6 @@ QWidget* CSVWorld::DialogueDelegateDispatcherProxy::getEditor() const return mEditor; } -void CSVWorld::DialogueDelegateDispatcherProxy::tableMimeDataDropped(const std::vector& data, const CSMDoc::Document* document) -{ - QLineEdit* lineEdit = qobject_cast(mEditor); - { - if (!lineEdit || !mIndexWrapper.get()) - { - return; - } - } - for (unsigned i = 0; i < data.size(); ++i) - { - CSMWorld::UniversalId::Type type = data[i].getType(); - if (mDisplay == CSMWorld::ColumnBase::Display_Referenceable) - { - if (type == CSMWorld::UniversalId::Type_Activator - || type == CSMWorld::UniversalId::Type_Potion - || type == CSMWorld::UniversalId::Type_Apparatus - || type == CSMWorld::UniversalId::Type_Armor - || type == CSMWorld::UniversalId::Type_Book - || type == CSMWorld::UniversalId::Type_Clothing - || type == CSMWorld::UniversalId::Type_Container - || type == CSMWorld::UniversalId::Type_Creature - || type == CSMWorld::UniversalId::Type_Door - || type == CSMWorld::UniversalId::Type_Ingredient - || type == CSMWorld::UniversalId::Type_CreatureLevelledList - || type == CSMWorld::UniversalId::Type_ItemLevelledList - || type == CSMWorld::UniversalId::Type_Light - || type == CSMWorld::UniversalId::Type_Lockpick - || type == CSMWorld::UniversalId::Type_Miscellaneous - || type == CSMWorld::UniversalId::Type_Npc - || type == CSMWorld::UniversalId::Type_Probe - || type == CSMWorld::UniversalId::Type_Repair - || type == CSMWorld::UniversalId::Type_Static - || type == CSMWorld::UniversalId::Type_Weapon) - { - type = CSMWorld::UniversalId::Type_Referenceable; - } - } - if (mDisplay == CSMWorld::TableMimeData::convertEnums(type)) - { - emit tableMimeDataDropped(mEditor, mIndexWrapper->mIndex, data[i], document); - emit editorDataCommited(mEditor, mIndexWrapper->mIndex, mDisplay); - break; - } - } -} /* ==============================DialogueDelegateDispatcher========================================== */ @@ -311,12 +265,8 @@ QWidget* CSVWorld::DialogueDelegateDispatcher::makeEditor(CSMWorld::ColumnBase:: { connect(editor, SIGNAL(editingFinished()), proxy, SLOT(editorDataCommited())); - connect(editor, SIGNAL(tableMimeDataDropped(const std::vector&, const CSMDoc::Document*)), - proxy, SLOT(tableMimeDataDropped(const std::vector&, const CSMDoc::Document*))); - - connect(proxy, SIGNAL(tableMimeDataDropped(QWidget*, const QModelIndex&, const CSMWorld::UniversalId&, const CSMDoc::Document*)), - this, SIGNAL(tableMimeDataDropped(QWidget*, const QModelIndex&, const CSMWorld::UniversalId&, const CSMDoc::Document*))); - + connect(editor, SIGNAL(tableMimeDataDropped(const CSMWorld::UniversalId&, const CSMDoc::Document*)), + proxy, SLOT(editorDataCommited())); } else if (qobject_cast(editor)) { @@ -387,9 +337,6 @@ mCommandDispatcher (commandDispatcher), mDocument (document) { remake (row); - - connect(mDispatcher, SIGNAL(tableMimeDataDropped(QWidget*, const QModelIndex&, const CSMWorld::UniversalId&, const CSMDoc::Document*)), - this, SIGNAL(tableMimeDataDropped(QWidget*, const QModelIndex&, const CSMWorld::UniversalId&, const CSMDoc::Document*))); } void CSVWorld::EditWidget::remake(int row) @@ -680,8 +627,6 @@ CSVWorld::DialogueSubView::DialogueSubView (const CSMWorld::UniversalId& id, CSM mEditWidget = new EditWidget(mainWidget, mTable->getModelIndex(mCurrentId, 0).row(), mTable, mCommandDispatcher, document, false); - connect(mEditWidget, SIGNAL(tableMimeDataDropped(QWidget*, const QModelIndex&, const CSMWorld::UniversalId&, const CSMDoc::Document*)), - this, SLOT(tableMimeDataDropped(QWidget*, const QModelIndex&, const CSMWorld::UniversalId&, const CSMDoc::Document*))); mMainLayout->addWidget(mEditWidget); mEditWidget->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); @@ -844,17 +789,6 @@ void CSVWorld::DialogueSubView::rowsAboutToBeRemoved(const QModelIndex &parent, } } -void CSVWorld::DialogueSubView::tableMimeDataDropped (QWidget* editor, - const QModelIndex& index, - const CSMWorld::UniversalId& id, - const CSMDoc::Document* document) -{ - if (document == &mDocument) - { - qobject_cast(editor)->setText(id.getId().c_str()); - } -} - void CSVWorld::DialogueSubView::requestFocus (const std::string& id) { changeCurrentId(id); diff --git a/apps/opencs/view/world/dialoguesubview.hpp b/apps/opencs/view/world/dialoguesubview.hpp index 6cbd8ad778..69e0dc8648 100644 --- a/apps/opencs/view/world/dialoguesubview.hpp +++ b/apps/opencs/view/world/dialoguesubview.hpp @@ -86,18 +86,12 @@ namespace CSVWorld public slots: void editorDataCommited(); void setIndex(const QModelIndex& index); - void tableMimeDataDropped(const std::vector& data, - const CSMDoc::Document* document); signals: void editorDataCommited(QWidget* editor, const QModelIndex& index, CSMWorld::ColumnBase::Display display); - void tableMimeDataDropped(QWidget* editor, const QModelIndex& index, - const CSMWorld::UniversalId& id, - const CSMDoc::Document* document); - }; class DialogueDelegateDispatcher : public QAbstractItemDelegate @@ -153,11 +147,6 @@ namespace CSVWorld private slots: void editorDataCommited(QWidget* editor, const QModelIndex& index, CSMWorld::ColumnBase::Display display); - - signals: - void tableMimeDataDropped(QWidget* editor, const QModelIndex& index, - const CSMWorld::UniversalId& id, - const CSMDoc::Document* document); }; class EditWidget : public QScrollArea @@ -182,11 +171,6 @@ namespace CSVWorld virtual ~EditWidget(); void remake(int row); - - signals: - void tableMimeDataDropped(QWidget* editor, const QModelIndex& index, - const CSMWorld::UniversalId& id, - const CSMDoc::Document* document); }; class DialogueSubView : public CSVDoc::SubView @@ -230,10 +214,6 @@ namespace CSVWorld void dataChanged(const QModelIndex & index); ///\brief we need to care for deleting currently edited record - void tableMimeDataDropped(QWidget* editor, const QModelIndex& index, - const CSMWorld::UniversalId& id, - const CSMDoc::Document* document); - void requestFocus (const std::string& id); void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end); diff --git a/apps/opencs/view/world/util.cpp b/apps/opencs/view/world/util.cpp index d3969dad42..8155055897 100644 --- a/apps/opencs/view/world/util.cpp +++ b/apps/opencs/view/world/util.cpp @@ -236,29 +236,15 @@ QWidget *CSVWorld::CommandDelegate::createEditor (QWidget *parent, const QStyleO return new QCheckBox(parent); - case CSMWorld::ColumnBase::Display_String: - case CSMWorld::ColumnBase::Display_Skill: - case CSMWorld::ColumnBase::Display_Script: - case CSMWorld::ColumnBase::Display_Race: - case CSMWorld::ColumnBase::Display_Region: - case CSMWorld::ColumnBase::Display_Class: - case CSMWorld::ColumnBase::Display_Faction: - case CSMWorld::ColumnBase::Display_Miscellaneous: - case CSMWorld::ColumnBase::Display_Sound: - case CSMWorld::ColumnBase::Display_Mesh: - case CSMWorld::ColumnBase::Display_Icon: - case CSMWorld::ColumnBase::Display_Music: - case CSMWorld::ColumnBase::Display_SoundRes: - case CSMWorld::ColumnBase::Display_Texture: - case CSMWorld::ColumnBase::Display_Video: - case CSMWorld::ColumnBase::Display_GlobalVariable: - - return new CSVWidget::DropLineEdit(CSMWorld::UniversalId::Type_None, parent); - case CSMWorld::ColumnBase::Display_ScriptLines: return new ScriptEdit (mDocument, ScriptHighlighter::Mode_Console, parent); + case CSMWorld::ColumnBase::Display_String: + // For other Display types (that represent record IDs) with drop support IdCompletionDelegate is used + + return new CSVWidget::DropLineEdit(CSMWorld::UniversalId::Type_None, parent); + default: return QStyledItemDelegate::createEditor (parent, option, index); From dc37aea8ebd678b9824f0558b48085b30c61fe0a Mon Sep 17 00:00:00 2001 From: Stanislav Bas Date: Sat, 20 Jun 2015 21:00:15 +0300 Subject: [PATCH 04/11] Add missing mappings to TableMimeData --- apps/opencs/model/world/tablemimedata.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/apps/opencs/model/world/tablemimedata.cpp b/apps/opencs/model/world/tablemimedata.cpp index d40e0c217c..101bbf9ba2 100644 --- a/apps/opencs/model/world/tablemimedata.cpp +++ b/apps/opencs/model/world/tablemimedata.cpp @@ -264,6 +264,8 @@ namespace { CSMWorld::UniversalId::Type_Texture, CSMWorld::ColumnBase::Display_Texture }, { CSMWorld::UniversalId::Type_Video, CSMWorld::ColumnBase::Display_Video }, { CSMWorld::UniversalId::Type_Global, CSMWorld::ColumnBase::Display_GlobalVariable }, + { CSMWorld::UniversalId::Type_BodyPart, CSMWorld::ColumnBase::Display_BodyPart }, + { CSMWorld::UniversalId::Type_Enchantment, CSMWorld::ColumnBase::Display_Enchantment }, { CSMWorld::UniversalId::Type_None, CSMWorld::ColumnBase::Display_None } // end marker }; From 256545205226c44320eb813397bd23021f0e8a31 Mon Sep 17 00:00:00 2001 From: Stanislav Bas Date: Sun, 21 Jun 2015 17:08:10 +0300 Subject: [PATCH 05/11] Add some drag'n'drop utils to work with TableMimeData --- apps/opencs/CMakeLists.txt | 2 +- apps/opencs/view/world/dragdroputils.cpp | 26 ++++++++++++++++++++ apps/opencs/view/world/dragdroputils.hpp | 30 ++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 apps/opencs/view/world/dragdroputils.cpp create mode 100644 apps/opencs/view/world/dragdroputils.hpp diff --git a/apps/opencs/CMakeLists.txt b/apps/opencs/CMakeLists.txt index fa703e4972..5386da707f 100644 --- a/apps/opencs/CMakeLists.txt +++ b/apps/opencs/CMakeLists.txt @@ -70,7 +70,7 @@ opencs_units (view/world opencs_units_noqt (view/world subviews enumdelegate vartypedelegate recordstatusdelegate idtypedelegate datadisplaydelegate scripthighlighter idvalidator dialoguecreator physicssystem idcompletiondelegate - colordelegate + colordelegate dragdroputils ) opencs_units (view/widget diff --git a/apps/opencs/view/world/dragdroputils.cpp b/apps/opencs/view/world/dragdroputils.cpp new file mode 100644 index 0000000000..7f3974e539 --- /dev/null +++ b/apps/opencs/view/world/dragdroputils.cpp @@ -0,0 +1,26 @@ +#include "dragdroputils.hpp" + +#include + +#include "../../model/world/tablemimedata.hpp" + +const CSMWorld::TableMimeData *CSVWorld::DragDropUtils::getTableMimeData(const QDropEvent &event) +{ + return dynamic_cast(event.mimeData()); +} + +bool CSVWorld::DragDropUtils::canAcceptData(const QDropEvent &event, CSMWorld::ColumnBase::Display type) +{ + const CSMWorld::TableMimeData *data = getTableMimeData(event); + return data != NULL && data->holdsType(type); +} + +CSMWorld::UniversalId CSVWorld::DragDropUtils::getAcceptedData(const QDropEvent &event, + CSMWorld::ColumnBase::Display type) +{ + if (canAcceptData(event, type)) + { + return getTableMimeData(event)->returnMatching(type); + } + return CSMWorld::UniversalId::Type_None; +} diff --git a/apps/opencs/view/world/dragdroputils.hpp b/apps/opencs/view/world/dragdroputils.hpp new file mode 100644 index 0000000000..88e2958a53 --- /dev/null +++ b/apps/opencs/view/world/dragdroputils.hpp @@ -0,0 +1,30 @@ +#ifndef CSV_WORLD_DRAGDROPUTILS_HPP +#define CSV_WORLD_DRAGDROPUTILS_HPP + +#include "../../model/world/columnbase.hpp" + +class QDropEvent; + +namespace CSMWorld +{ + class TableMimeData; + class UniversalId; +} + +namespace CSVWorld +{ + class DragDropUtils + { + public: + static const CSMWorld::TableMimeData *getTableMimeData(const QDropEvent &event); + + static bool canAcceptData(const QDropEvent &event, CSMWorld::ColumnBase::Display type); + ///< Checks whether the \a event contains a valid CSMWorld::TableMimeData that holds the \a type + + static CSMWorld::UniversalId getAcceptedData(const QDropEvent &event, CSMWorld::ColumnBase::Display type); + ///< Gets the accepted data from the \a event using the \a type + ///< \return Type_None if the \a event data doesn't holds the \a type + }; +} + +#endif From a23de394f8ef2dd4c5fdb28b03cf8527cd42e3e0 Mon Sep 17 00:00:00 2001 From: Stanislav Bas Date: Sun, 21 Jun 2015 17:16:13 +0300 Subject: [PATCH 06/11] Refine DropLineEdit code --- apps/opencs/view/widget/droplineedit.cpp | 69 ++++-------------------- apps/opencs/view/widget/droplineedit.hpp | 17 ++---- apps/opencs/view/world/util.cpp | 2 +- 3 files changed, 14 insertions(+), 74 deletions(-) diff --git a/apps/opencs/view/widget/droplineedit.cpp b/apps/opencs/view/widget/droplineedit.cpp index 6dae157468..98f1d81c30 100644 --- a/apps/opencs/view/widget/droplineedit.cpp +++ b/apps/opencs/view/widget/droplineedit.cpp @@ -3,33 +3,20 @@ #include #include "../../model/world/tablemimedata.hpp" +#include "../../model/world/universalid.hpp" -namespace -{ - const CSMWorld::TableMimeData *getEventMimeData(QDropEvent *event) - { - Q_ASSERT(event != NULL); - return dynamic_cast(event->mimeData()); - } -} +#include "../world/dragdroputils.hpp" -CSVWidget::DropLineEdit::DropLineEdit(CSMWorld::UniversalId::Type type, QWidget *parent) +CSVWidget::DropLineEdit::DropLineEdit(CSMWorld::ColumnBase::Display type, QWidget *parent) : QLineEdit(parent), mDropType(type) { setAcceptDrops(true); } -CSVWidget::DropLineEdit::DropLineEdit(CSMWorld::ColumnBase::Display display, QWidget *parent) - : QLineEdit(parent), - mDropType(CSMWorld::TableMimeData::convertEnums(display)) -{ - setAcceptDrops(true); -} - void CSVWidget::DropLineEdit::dragEnterEvent(QDragEnterEvent *event) { - if (canAcceptEventData(event)) + if (CSVWorld::DragDropUtils::canAcceptData(*event, mDropType)) { event->acceptProposedAction(); } @@ -37,7 +24,7 @@ void CSVWidget::DropLineEdit::dragEnterEvent(QDragEnterEvent *event) void CSVWidget::DropLineEdit::dragMoveEvent(QDragMoveEvent *event) { - if (canAcceptEventData(event)) + if (CSVWorld::DragDropUtils::canAcceptData(*event, mDropType)) { event->accept(); } @@ -45,48 +32,10 @@ void CSVWidget::DropLineEdit::dragMoveEvent(QDragMoveEvent *event) void CSVWidget::DropLineEdit::dropEvent(QDropEvent *event) { - const CSMWorld::TableMimeData *data = getEventMimeData(event); - if (data == NULL) // May happen when non-records (e.g. plain text) are dragged and dropped + if (CSVWorld::DragDropUtils::canAcceptData(*event, mDropType)) { - return; - } - - int dataIndex = getAcceptedDataIndex(*data); - if (dataIndex != -1) - { - std::vector idData = data->getData(); - setText(idData[dataIndex].getId().c_str()); - emit tableMimeDataDropped(idData[dataIndex], data->getDocumentPtr()); + CSMWorld::UniversalId id = CSVWorld::DragDropUtils::getAcceptedData(*event, mDropType); + setText(id.getId().c_str()); + emit tableMimeDataDropped(id, CSVWorld::DragDropUtils::getTableMimeData(*event)->getDocumentPtr()); } } - -bool CSVWidget::DropLineEdit::canAcceptEventData(QDropEvent *event) const -{ - const CSMWorld::TableMimeData *data = getEventMimeData(event); - if (data == NULL) // May happen when non-records (e.g. plain text) are dragged and dropped - { - return false; - } - return getAcceptedDataIndex(*data) != -1; -} - -int CSVWidget::DropLineEdit::getAcceptedDataIndex(const CSMWorld::TableMimeData &data) const -{ - if (mDropType == CSMWorld::UniversalId::Type_None) - { - return 0; - } - - bool isReferenceable = mDropType == CSMWorld::UniversalId::Type_Referenceable; - std::vector idData = data.getData(); - int size = static_cast(idData.size()); - for (int i = 0; i < size; ++i) - { - CSMWorld::UniversalId::Type type = idData[i].getType(); - if (type == mDropType || isReferenceable && CSMWorld::TableMimeData::isReferencable(type)) - { - return i; - } - } - return -1; -} diff --git a/apps/opencs/view/widget/droplineedit.hpp b/apps/opencs/view/widget/droplineedit.hpp index ce086b7dc1..60832e71bc 100644 --- a/apps/opencs/view/widget/droplineedit.hpp +++ b/apps/opencs/view/widget/droplineedit.hpp @@ -4,7 +4,6 @@ #include #include "../../model/world/columnbase.hpp" -#include "../../model/world/universalid.hpp" namespace CSMDoc { @@ -14,6 +13,7 @@ namespace CSMDoc namespace CSMWorld { class TableMimeData; + class UniversalId; } namespace CSVWidget @@ -22,20 +22,11 @@ namespace CSVWidget { Q_OBJECT - CSMWorld::UniversalId::Type mDropType; - ///< The accepted ID type for this LineEdit. - ///< If \a mDropType has Type_None type, this LineEdit accepts all ID types - - bool canAcceptEventData(QDropEvent *event) const; - ///< Checks whether the \a event contains CSMWorld::TableMimeData with a proper ID type - - int getAcceptedDataIndex(const CSMWorld::TableMimeData &data) const; - ///< Checks whether the \a data has a proper type - ///< \return -1 if there is no suitable data (ID type) + CSMWorld::ColumnBase::Display mDropType; + ///< The accepted Display type for this LineEdit. public: - DropLineEdit(CSMWorld::UniversalId::Type type, QWidget *parent = 0); - DropLineEdit(CSMWorld::ColumnBase::Display display, QWidget *parent = 0); + DropLineEdit(CSMWorld::ColumnBase::Display type, QWidget *parent = 0); protected: void dragEnterEvent(QDragEnterEvent *event); diff --git a/apps/opencs/view/world/util.cpp b/apps/opencs/view/world/util.cpp index 8155055897..62cde4608a 100644 --- a/apps/opencs/view/world/util.cpp +++ b/apps/opencs/view/world/util.cpp @@ -243,7 +243,7 @@ QWidget *CSVWorld::CommandDelegate::createEditor (QWidget *parent, const QStyleO case CSMWorld::ColumnBase::Display_String: // For other Display types (that represent record IDs) with drop support IdCompletionDelegate is used - return new CSVWidget::DropLineEdit(CSMWorld::UniversalId::Type_None, parent); + return new CSVWidget::DropLineEdit(display, parent); default: From b9882eb59ab0c8a13d64b9ed7ffa7b1bdff0f12a Mon Sep 17 00:00:00 2001 From: Stanislav Bas Date: Sun, 21 Jun 2015 18:40:13 +0300 Subject: [PATCH 07/11] DragRecordTable checks drag type before accepting it --- apps/opencs/view/world/dragrecordtable.cpp | 53 +++++++++++++++++++++- apps/opencs/view/world/dragrecordtable.hpp | 7 +++ apps/opencs/view/world/table.cpp | 30 ------------ apps/opencs/view/world/table.hpp | 2 - 4 files changed, 58 insertions(+), 34 deletions(-) diff --git a/apps/opencs/view/world/dragrecordtable.cpp b/apps/opencs/view/world/dragrecordtable.cpp index 2a1ae1f401..3712348e22 100644 --- a/apps/opencs/view/world/dragrecordtable.cpp +++ b/apps/opencs/view/world/dragrecordtable.cpp @@ -1,8 +1,14 @@ +#include "dragrecordtable.hpp" + #include #include +#include "../../model/doc/document.hpp" + #include "../../model/world/tablemimedata.hpp" -#include "dragrecordtable.hpp" +#include "../../model/world/commands.hpp" + +#include "dragdroputils.hpp" void CSVWorld::DragRecordTable::startDragFromTable (const CSVWorld::DragRecordTable& table) { @@ -35,5 +41,48 @@ void CSVWorld::DragRecordTable::dragEnterEvent(QDragEnterEvent *event) void CSVWorld::DragRecordTable::dragMoveEvent(QDragMoveEvent *event) { - event->accept(); + QModelIndex index = indexAt(event->pos()); + if (CSVWorld::DragDropUtils::canAcceptData(*event, getIndexDisplayType(index))) + { + event->accept(); + } + else + { + event->ignore(); + } +} + +void CSVWorld::DragRecordTable::dropEvent(QDropEvent *event) +{ + QModelIndex index = indexAt(event->pos()); + CSMWorld::ColumnBase::Display display = getIndexDisplayType(index); + if (CSVWorld::DragDropUtils::canAcceptData(*event, display)) + { + const CSMWorld::TableMimeData *data = CSVWorld::DragDropUtils::getTableMimeData(*event); + if (data->fromDocument(mDocument)) + { + CSMWorld::UniversalId id = CSVWorld::DragDropUtils::getAcceptedData(*event, display); + QVariant newIndexData = QString::fromUtf8(id.getId().c_str()); + QVariant oldIndexData = index.data(Qt::EditRole); + if (newIndexData != oldIndexData) + { + mDocument.getUndoStack().push(new CSMWorld::ModifyCommand(*model(), index, newIndexData)); + } + } + } +} + +CSMWorld::ColumnBase::Display CSVWorld::DragRecordTable::getIndexDisplayType(const QModelIndex &index) const +{ + Q_ASSERT(model() != NULL); + + if (index.isValid()) + { + QVariant display = model()->headerData(index.column(), Qt::Horizontal, CSMWorld::ColumnBase::Role_Display); + if (display.isValid()) + { + return static_cast(display.toInt()); + } + } + return CSMWorld::ColumnBase::Display_None; } diff --git a/apps/opencs/view/world/dragrecordtable.hpp b/apps/opencs/view/world/dragrecordtable.hpp index 48f9e25280..560864ba5a 100644 --- a/apps/opencs/view/world/dragrecordtable.hpp +++ b/apps/opencs/view/world/dragrecordtable.hpp @@ -4,6 +4,8 @@ #include #include +#include "../../model/world/columnbase.hpp" + class QWidget; class QAction; @@ -38,6 +40,11 @@ namespace CSVWorld void dragEnterEvent(QDragEnterEvent *event); void dragMoveEvent(QDragMoveEvent *event); + + void dropEvent(QDropEvent *event); + + private: + CSMWorld::ColumnBase::Display getIndexDisplayType(const QModelIndex &index) const; }; } diff --git a/apps/opencs/view/world/table.cpp b/apps/opencs/view/world/table.cpp index 072b645c42..0ec701a65a 100644 --- a/apps/opencs/view/world/table.cpp +++ b/apps/opencs/view/world/table.cpp @@ -697,36 +697,6 @@ void CSVWorld::Table::mouseMoveEvent (QMouseEvent* event) } } -void CSVWorld::Table::dropEvent(QDropEvent *event) -{ - QModelIndex index = indexAt (event->pos()); - - if (!index.isValid()) - { - return; - } - - const CSMWorld::TableMimeData* mime = dynamic_cast (event->mimeData()); - if (!mime) // May happen when non-records (e.g. plain text) are dragged and dropped - return; - - if (mime->fromDocument (mDocument)) - { - CSMWorld::ColumnBase::Display display = static_cast - (mModel->headerData (index.column(), Qt::Horizontal, CSMWorld::ColumnBase::Role_Display).toInt()); - - if (mime->holdsType (display)) - { - CSMWorld::UniversalId record (mime->returnMatching (display)); - - std::auto_ptr command (new CSMWorld::ModifyCommand - (*mProxyModel, index, QVariant (QString::fromUtf8 (record.getId().c_str())))); - - mDocument.getUndoStack().push (command.release()); - } - } //TODO handle drops from different document -} - std::vector CSVWorld::Table::getColumnsWithDisplay(CSMWorld::ColumnBase::Display display) const { const int count = mModel->columnCount(); diff --git a/apps/opencs/view/world/table.hpp b/apps/opencs/view/world/table.hpp index 67bf3fe857..38fcd83bd6 100644 --- a/apps/opencs/view/world/table.hpp +++ b/apps/opencs/view/world/table.hpp @@ -76,8 +76,6 @@ namespace CSVWorld void mouseMoveEvent(QMouseEvent *event); - void dropEvent(QDropEvent *event); - protected: virtual void mouseDoubleClickEvent (QMouseEvent *event); From d606b62688e14ea214d0939fec908c6996cf6b82 Mon Sep 17 00:00:00 2001 From: Stanislav Bas Date: Sun, 21 Jun 2015 21:35:00 +0300 Subject: [PATCH 08/11] Nested tables accept drops --- apps/opencs/view/world/dragrecordtable.cpp | 12 +++++++-- apps/opencs/view/world/nestedtable.cpp | 29 +++++++++------------- apps/opencs/view/world/nestedtable.hpp | 12 +++------ 3 files changed, 26 insertions(+), 27 deletions(-) diff --git a/apps/opencs/view/world/dragrecordtable.cpp b/apps/opencs/view/world/dragrecordtable.cpp index 3712348e22..8d01cff3ef 100644 --- a/apps/opencs/view/world/dragrecordtable.cpp +++ b/apps/opencs/view/world/dragrecordtable.cpp @@ -12,7 +12,13 @@ void CSVWorld::DragRecordTable::startDragFromTable (const CSVWorld::DragRecordTable& table) { - CSMWorld::TableMimeData* mime = new CSMWorld::TableMimeData (table.getDraggedRecords(), mDocument); + std::vector 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) { diff --git a/apps/opencs/view/world/nestedtable.cpp b/apps/opencs/view/world/nestedtable.cpp index 112873cb9a..92df59a5fc 100644 --- a/apps/opencs/view/world/nestedtable.cpp +++ b/apps/opencs/view/world/nestedtable.cpp @@ -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 CSVWorld::NestedTable::getDraggedRecords() const { + // No drag support for nested tables + return std::vector(); } 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())); } diff --git a/apps/opencs/view/world/nestedtable.hpp b/apps/opencs/view/world/nestedtable.hpp index 5db977942a..1129204011 100644 --- a/apps/opencs/view/world/nestedtable.hpp +++ b/apps/opencs/view/world/nestedtable.hpp @@ -1,10 +1,10 @@ #ifndef CSV_WORLD_NESTEDTABLE_H #define CSV_WORLD_NESTEDTABLE_H -#include #include -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 getDraggedRecords() const; private: void contextMenuEvent (QContextMenuEvent *event); From d1339a643afced0d1e502eebe79c947b2c4ad953 Mon Sep 17 00:00:00 2001 From: Stanislav Bas Date: Wed, 24 Jun 2015 15:07:09 +0300 Subject: [PATCH 09/11] Fix for NestedTableProxyModel::forwardDataChanged() --- apps/opencs/model/world/nestedtableproxymodel.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/apps/opencs/model/world/nestedtableproxymodel.cpp b/apps/opencs/model/world/nestedtableproxymodel.cpp index acf1977168..052e629aac 100644 --- a/apps/opencs/model/world/nestedtableproxymodel.cpp +++ b/apps/opencs/model/world/nestedtableproxymodel.cpp @@ -192,4 +192,8 @@ void CSMWorld::NestedTableProxyModel::forwardDataChanged (const QModelIndex& top emit dataChanged(index(0,0), index(mMainModel->rowCount(parent)-1, mMainModel->columnCount(parent)-1)); } + else if (topLeft.parent() == parent && bottomRight.parent() == parent) + { + emit dataChanged(index(topLeft.row(), topLeft.column()), index(bottomRight.row(), bottomRight.column())); + } } From 270c17faa786917ac03f44906c055eec70da577d Mon Sep 17 00:00:00 2001 From: Stanislav Bas Date: Wed, 24 Jun 2015 16:36:09 +0300 Subject: [PATCH 10/11] Prevent drops on non-editable table cells --- apps/opencs/view/world/dragrecordtable.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/apps/opencs/view/world/dragrecordtable.cpp b/apps/opencs/view/world/dragrecordtable.cpp index 8d01cff3ef..5e8ddae26d 100644 --- a/apps/opencs/view/world/dragrecordtable.cpp +++ b/apps/opencs/view/world/dragrecordtable.cpp @@ -52,7 +52,10 @@ void CSVWorld::DragRecordTable::dragMoveEvent(QDragMoveEvent *event) QModelIndex index = indexAt(event->pos()); if (CSVWorld::DragDropUtils::canAcceptData(*event, getIndexDisplayType(index))) { - event->accept(); + if (index.flags() & Qt::ItemIsEditable) + { + event->accept(); + } } else { From e29d9bcc8eac923ecf90c73733302033e01c2700 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Wed, 24 Jun 2015 17:29:47 +0200 Subject: [PATCH 11/11] use a namespace instead of a class with only static functions --- apps/opencs/view/world/dragdroputils.hpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/apps/opencs/view/world/dragdroputils.hpp b/apps/opencs/view/world/dragdroputils.hpp index 88e2958a53..d1d780708e 100644 --- a/apps/opencs/view/world/dragdroputils.hpp +++ b/apps/opencs/view/world/dragdroputils.hpp @@ -13,18 +13,17 @@ namespace CSMWorld namespace CSVWorld { - class DragDropUtils + namespace DragDropUtils { - public: - static const CSMWorld::TableMimeData *getTableMimeData(const QDropEvent &event); + const CSMWorld::TableMimeData *getTableMimeData(const QDropEvent &event); - static bool canAcceptData(const QDropEvent &event, CSMWorld::ColumnBase::Display type); - ///< Checks whether the \a event contains a valid CSMWorld::TableMimeData that holds the \a type + bool canAcceptData(const QDropEvent &event, CSMWorld::ColumnBase::Display type); + ///< Checks whether the \a event contains a valid CSMWorld::TableMimeData that holds the \a type - static CSMWorld::UniversalId getAcceptedData(const QDropEvent &event, CSMWorld::ColumnBase::Display type); - ///< Gets the accepted data from the \a event using the \a type - ///< \return Type_None if the \a event data doesn't holds the \a type - }; + CSMWorld::UniversalId getAcceptedData(const QDropEvent &event, CSMWorld::ColumnBase::Display type); + ///< Gets the accepted data from the \a event using the \a type + ///< \return Type_None if the \a event data doesn't holds the \a type + } } #endif