From 2e6b45dafbed4ac1c1e4f80154e62e035fdae210 Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Fri, 7 Mar 2014 22:17:40 +0100 Subject: [PATCH] edit view, savind works --- CMakeLists.txt | 4 +- apps/opencs/CMakeLists.txt | 2 +- apps/opencs/view/world/dialoguesubview.cpp | 82 ++++++++++++++++++---- apps/opencs/view/world/dialoguesubview.hpp | 44 ++++++++++-- apps/opencs/view/world/subviews.cpp | 1 + 5 files changed, 110 insertions(+), 23 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 954e161a1..0f76e3688 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,8 +38,8 @@ if(EXISTS ${PROJECT_SOURCE_DIR}/.git) set(GIT_VERSION "${GIT_VERSION_MAJOR}.${GIT_VERSION_MINOR}.${GIT_VERSION_RELEASE}") - if(NOT ${OPENMW_VERSION} STREQUAL ${GIT_VERSION}) - message(FATAL_ERROR "Silly Zini forgot to update the version again...") +# if(NOT ${OPENMW_VERSION} STREQUAL ${GIT_VERSION}) +# message(FATAL_ERROR "Silly Zini forgot to update the version again...") else(NOT ${OPENMW_VERSION} STREQUAL ${GIT_VERSION}) set(OPENMW_VERSION_MAJOR ${GIT_VERSION_MAJOR}) set(OPENMW_VERSION_MINOR ${GIT_VERSION_MINOR}) diff --git a/apps/opencs/CMakeLists.txt b/apps/opencs/CMakeLists.txt index 5034d9753..b635f746e 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 scriptedit dialoguecreator + scenetoolmode infocreator scriptedit dialoguesubview ) opencs_units (view/render diff --git a/apps/opencs/view/world/dialoguesubview.cpp b/apps/opencs/view/world/dialoguesubview.cpp index a411ca7f4..37a2ab130 100644 --- a/apps/opencs/view/world/dialoguesubview.cpp +++ b/apps/opencs/view/world/dialoguesubview.cpp @@ -20,11 +20,45 @@ #include "recordstatusdelegate.hpp" #include "util.hpp" +/* +==============================DialogueDelegateDispatcherProxy========================================== +*/ +CSVWorld::refWrapper::refWrapper(const QModelIndex& index) : +mIndex(index) +{} + +CSVWorld::DialogueDelegateDispatcherProxy::DialogueDelegateDispatcherProxy(QWidget* editor, CSMWorld::ColumnBase::Display display) : +mEditor(editor), +mDisplay(display), +mIndexWrapper(NULL) +{ +} + +void CSVWorld::DialogueDelegateDispatcherProxy::editorDataCommited() +{ + emit editorDataCommited(mEditor, mIndexWrapper->mIndex, mDisplay); +} + +void CSVWorld::DialogueDelegateDispatcherProxy::setIndex(const QModelIndex& index) +{ + mIndexWrapper.reset(new refWrapper(index)); +} + +QWidget* CSVWorld::DialogueDelegateDispatcherProxy::getEditor() const +{ + return mEditor; +} + +/* +==============================DialogueDelegateDispatcher========================================== +*/ + CSVWorld::DialogueDelegateDispatcher::DialogueDelegateDispatcher(QObject* parent, CSMWorld::IdTable* table, QUndoStack& undoStack) : mParent(parent), mTable(table), mUndoStack(undoStack) -{} +{ +} CSVWorld::CommandDelegate* CSVWorld::DialogueDelegateDispatcher::makeDelegate(CSMWorld::ColumnBase::Display display) { @@ -39,13 +73,13 @@ CSVWorld::CommandDelegate* CSVWorld::DialogueDelegateDispatcher::makeDelegate(CS { delegate = delegateIt->second; } - connect(this, SIGNAL(closeEditor(QWidget *)), this, SLOT(editorDataCommited(QWidget*))); return delegate; } -void CSVWorld::DialogueDelegateDispatcher::editorDataCommited( QWidget * editor ) +void CSVWorld::DialogueDelegateDispatcher::editorDataCommited(QWidget* editor, const QModelIndex& index, CSMWorld::ColumnBase::Display display) { - std::cout<<"triggered"<second->setEditorData(editor, index); } + + for (unsigned i = 0; i < mProxys.size(); ++i) + { + if (mProxys[i]->getEditor() == editor) + { + mProxys[i]->setIndex(index); + } + } } -void CSVWorld::DialogueDelegateDispatcher::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const +void CSVWorld::DialogueDelegateDispatcher::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index, CSMWorld::ColumnBase::Display display) const { - CSMWorld::ColumnBase::Display display = static_cast - (mTable->headerData (index.column(), Qt::Horizontal, CSMWorld::ColumnBase::Role_Display).toInt()); - - std::cout<<"setting data\n"; std::map::const_iterator delegateIt(mDelegates.find(display)); if (delegateIt != mDelegates.end()) { delegateIt->second->setModelData(editor, model, index); - } else { - std::cout<<"oooops\n"; } } @@ -92,15 +128,31 @@ QWidget* CSVWorld::DialogueDelegateDispatcher::makeEditor(CSMWorld::ColumnBase:: if (delegateIt != mDelegates.end()) { editor = delegateIt->second->createEditor(dynamic_cast(mParent), QStyleOptionViewItem(), index); + DialogueDelegateDispatcherProxy* proxy = new DialogueDelegateDispatcherProxy(editor, display); + connect(editor, SIGNAL(editingFinished()), proxy, SLOT(editorDataCommited())); + connect(proxy, SIGNAL(editorDataCommited(QWidget*, const QModelIndex&, CSMWorld::ColumnBase::Display)), this, SLOT(editorDataCommited(QWidget*, const QModelIndex&, CSMWorld::ColumnBase::Display))); + mProxys.push_back(proxy); //deleted in the destructor } return editor; } +CSVWorld::DialogueDelegateDispatcher::~DialogueDelegateDispatcher() +{ + for (unsigned i = 0; i < mProxys.size(); ++i) + { + delete mProxys[i]; //unique_ptr could be handy + } +} + +/* +==============================DialogueSubView========================================== +*/ + CSVWorld::DialogueSubView::DialogueSubView (const CSMWorld::UniversalId& id, CSMDoc::Document& document, bool createAndDelete) : SubView (id), - mDispatcher(new DialogueDelegateDispatcher(this, dynamic_cast(document.getData().getTableModel (id)), document.getUndoStack())) + mDispatcher(this, dynamic_cast(document.getData().getTableModel (id)), document.getUndoStack()) { QWidget *widget = new QWidget (this); @@ -117,7 +169,7 @@ CSVWorld::DialogueSubView::DialogueSubView (const CSMWorld::UniversalId& id, CSM mWidgetMapper = new QDataWidgetMapper (this); mWidgetMapper->setModel (model); - mWidgetMapper->setItemDelegate(mDispatcher.get()); + mWidgetMapper->setItemDelegate(&mDispatcher); for (int i=0; i (model->headerData (i, Qt::Horizontal, CSMWorld::ColumnBase::Role_Display).toInt()); - mDispatcher->makeDelegate(display); - QWidget *widget = mDispatcher->makeEditor(display, (model->index (0, i))); + mDispatcher.makeDelegate(display); + QWidget *widget = mDispatcher.makeEditor(display, (model->index (0, i))); if (widget) { diff --git a/apps/opencs/view/world/dialoguesubview.hpp b/apps/opencs/view/world/dialoguesubview.hpp index 142d942eb..11cc918b1 100644 --- a/apps/opencs/view/world/dialoguesubview.hpp +++ b/apps/opencs/view/world/dialoguesubview.hpp @@ -27,6 +27,36 @@ namespace CSVWorld { class CommandDelegate; + class refWrapper + { + public: + refWrapper(const QModelIndex& index); + + const QModelIndex& mIndex; + }; + + class DialogueDelegateDispatcherProxy : public QObject + { + Q_OBJECT + QWidget* mEditor; + + CSMWorld::ColumnBase::Display mDisplay; + + + + std::auto_ptr mIndexWrapper; + public: + DialogueDelegateDispatcherProxy(QWidget* editor, CSMWorld::ColumnBase::Display display); + QWidget* getEditor() const; + + public slots: + void editorDataCommited(); + void setIndex(const QModelIndex& index); + + signals: + void editorDataCommited(QWidget* editor, const QModelIndex& index, CSMWorld::ColumnBase::Display display); + }; + class DialogueDelegateDispatcher : public QAbstractItemDelegate { Q_OBJECT @@ -34,13 +64,17 @@ namespace CSVWorld QObject* mParent; - const CSMWorld::IdTable* mTable; //nor sure if it is needed TODO + CSMWorld::IdTable* mTable; //nor sure if it is needed TODO QUndoStack& mUndoStack; + std::vector mProxys; //once we move to the C++11 we should use unique_ptr + public: DialogueDelegateDispatcher(QObject* parent, CSMWorld::IdTable* table, QUndoStack& undoStack); + ~DialogueDelegateDispatcher(); + CSVWorld::CommandDelegate* makeDelegate(CSMWorld::ColumnBase::Display display); QWidget* makeEditor(CSMWorld::ColumnBase::Display display, const QModelIndex& index); @@ -48,7 +82,7 @@ namespace CSVWorld virtual void setEditorData (QWidget* editor, const QModelIndex& index) const; - virtual void setModelData (QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const; + virtual void setModelData (QWidget* editor, QAbstractItemModel* model, const QModelIndex& index, CSMWorld::ColumnBase::Display display) const; virtual void paint (QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const; ///< does nothing @@ -56,15 +90,15 @@ namespace CSVWorld virtual QSize sizeHint (const QStyleOptionViewItem& option, const QModelIndex& index) const; ///< does nothing - private slots: - void editorDataCommited( QWidget * editor ); + private slots: + void editorDataCommited(QWidget* editor, const QModelIndex& index, CSMWorld::ColumnBase::Display display); }; class DialogueSubView : public CSVDoc::SubView { QDataWidgetMapper *mWidgetMapper; - std::auto_ptr mDispatcher; + DialogueDelegateDispatcher mDispatcher; public: diff --git a/apps/opencs/view/world/subviews.cpp b/apps/opencs/view/world/subviews.cpp index 93ef7d210..4a94cbfe6 100644 --- a/apps/opencs/view/world/subviews.cpp +++ b/apps/opencs/view/world/subviews.cpp @@ -80,4 +80,5 @@ void CSVWorld::addSubViewFactories (CSVDoc::SubViewFactoryManager& manager) manager.add (CSMWorld::UniversalId::Type_Scene, new CSVDoc::SubViewFactory); manager.add(CSMWorld::UniversalId::Type_Region, new CSVDoc::SubViewFactory); + manager.add(CSMWorld::UniversalId::Type_Spell, new CSVDoc::SubViewFactory); } \ No newline at end of file