edit view, savind works

This commit is contained in:
Marek Kochanowicz 2014-03-07 22:17:40 +01:00
parent 020e3f8fc5
commit 2e6b45dafb
5 changed files with 110 additions and 23 deletions

View file

@ -38,8 +38,8 @@ if(EXISTS ${PROJECT_SOURCE_DIR}/.git)
set(GIT_VERSION "${GIT_VERSION_MAJOR}.${GIT_VERSION_MINOR}.${GIT_VERSION_RELEASE}") set(GIT_VERSION "${GIT_VERSION_MAJOR}.${GIT_VERSION_MINOR}.${GIT_VERSION_RELEASE}")
if(NOT ${OPENMW_VERSION} STREQUAL ${GIT_VERSION}) # if(NOT ${OPENMW_VERSION} STREQUAL ${GIT_VERSION})
message(FATAL_ERROR "Silly Zini forgot to update the version again...") # message(FATAL_ERROR "Silly Zini forgot to update the version again...")
else(NOT ${OPENMW_VERSION} STREQUAL ${GIT_VERSION}) else(NOT ${OPENMW_VERSION} STREQUAL ${GIT_VERSION})
set(OPENMW_VERSION_MAJOR ${GIT_VERSION_MAJOR}) set(OPENMW_VERSION_MAJOR ${GIT_VERSION_MAJOR})
set(OPENMW_VERSION_MINOR ${GIT_VERSION_MINOR}) set(OPENMW_VERSION_MINOR ${GIT_VERSION_MINOR})

View file

@ -60,7 +60,7 @@ opencs_hdrs_noqt (view/doc
opencs_units (view/world opencs_units (view/world
table tablesubview scriptsubview util regionmapsubview tablebottombox creator genericcreator table tablesubview scriptsubview util regionmapsubview tablebottombox creator genericcreator
cellcreator referenceablecreator referencecreator scenesubview scenetoolbar scenetool cellcreator referenceablecreator referencecreator scenesubview scenetoolbar scenetool
scenetoolmode infocreator scriptedit dialoguecreator scenetoolmode infocreator scriptedit dialoguesubview
) )
opencs_units (view/render opencs_units (view/render

View file

@ -20,11 +20,45 @@
#include "recordstatusdelegate.hpp" #include "recordstatusdelegate.hpp"
#include "util.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) : CSVWorld::DialogueDelegateDispatcher::DialogueDelegateDispatcher(QObject* parent, CSMWorld::IdTable* table, QUndoStack& undoStack) :
mParent(parent), mParent(parent),
mTable(table), mTable(table),
mUndoStack(undoStack) mUndoStack(undoStack)
{} {
}
CSVWorld::CommandDelegate* CSVWorld::DialogueDelegateDispatcher::makeDelegate(CSMWorld::ColumnBase::Display display) CSVWorld::CommandDelegate* CSVWorld::DialogueDelegateDispatcher::makeDelegate(CSMWorld::ColumnBase::Display display)
{ {
@ -39,13 +73,13 @@ CSVWorld::CommandDelegate* CSVWorld::DialogueDelegateDispatcher::makeDelegate(CS
{ {
delegate = delegateIt->second; delegate = delegateIt->second;
} }
connect(this, SIGNAL(closeEditor(QWidget *)), this, SLOT(editorDataCommited(QWidget*)));
return delegate; return delegate;
} }
void CSVWorld::DialogueDelegateDispatcher::editorDataCommited( QWidget * editor ) void CSVWorld::DialogueDelegateDispatcher::editorDataCommited(QWidget* editor, const QModelIndex& index, CSMWorld::ColumnBase::Display display)
{ {
std::cout<<"triggered"<<std::endl; std::cout<<"triggered"<<std::endl;
setModelData(editor, mTable, index, display);
} }
void CSVWorld::DialogueDelegateDispatcher::setEditorData (QWidget* editor, const QModelIndex& index) const void CSVWorld::DialogueDelegateDispatcher::setEditorData (QWidget* editor, const QModelIndex& index) const
@ -58,20 +92,22 @@ void CSVWorld::DialogueDelegateDispatcher::setEditorData (QWidget* editor, const
{ {
delegateIt->second->setEditorData(editor, index); delegateIt->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<CSMWorld::ColumnBase::Display>
(mTable->headerData (index.column(), Qt::Horizontal, CSMWorld::ColumnBase::Role_Display).toInt());
std::cout<<"setting data\n";
std::map<int, CommandDelegate*>::const_iterator delegateIt(mDelegates.find(display)); std::map<int, CommandDelegate*>::const_iterator delegateIt(mDelegates.find(display));
if (delegateIt != mDelegates.end()) if (delegateIt != mDelegates.end())
{ {
delegateIt->second->setModelData(editor, model, index); 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()) if (delegateIt != mDelegates.end())
{ {
editor = delegateIt->second->createEditor(dynamic_cast<QWidget*>(mParent), QStyleOptionViewItem(), index); editor = delegateIt->second->createEditor(dynamic_cast<QWidget*>(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; 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, CSVWorld::DialogueSubView::DialogueSubView (const CSMWorld::UniversalId& id, CSMDoc::Document& document,
bool createAndDelete) : bool createAndDelete) :
SubView (id), SubView (id),
mDispatcher(new DialogueDelegateDispatcher(this, dynamic_cast<CSMWorld::IdTable*>(document.getData().getTableModel (id)), document.getUndoStack())) mDispatcher(this, dynamic_cast<CSMWorld::IdTable*>(document.getData().getTableModel (id)), document.getUndoStack())
{ {
QWidget *widget = new QWidget (this); QWidget *widget = new QWidget (this);
@ -117,7 +169,7 @@ CSVWorld::DialogueSubView::DialogueSubView (const CSMWorld::UniversalId& id, CSM
mWidgetMapper = new QDataWidgetMapper (this); mWidgetMapper = new QDataWidgetMapper (this);
mWidgetMapper->setModel (model); mWidgetMapper->setModel (model);
mWidgetMapper->setItemDelegate(mDispatcher.get()); mWidgetMapper->setItemDelegate(&mDispatcher);
for (int i=0; i<columns; ++i) for (int i=0; i<columns; ++i)
{ {
@ -130,8 +182,8 @@ CSVWorld::DialogueSubView::DialogueSubView (const CSMWorld::UniversalId& id, CSM
CSMWorld::ColumnBase::Display display = static_cast<CSMWorld::ColumnBase::Display> CSMWorld::ColumnBase::Display display = static_cast<CSMWorld::ColumnBase::Display>
(model->headerData (i, Qt::Horizontal, CSMWorld::ColumnBase::Role_Display).toInt()); (model->headerData (i, Qt::Horizontal, CSMWorld::ColumnBase::Role_Display).toInt());
mDispatcher->makeDelegate(display); mDispatcher.makeDelegate(display);
QWidget *widget = mDispatcher->makeEditor(display, (model->index (0, i))); QWidget *widget = mDispatcher.makeEditor(display, (model->index (0, i)));
if (widget) if (widget)
{ {

View file

@ -27,6 +27,36 @@ namespace CSVWorld
{ {
class CommandDelegate; 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<refWrapper> 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 class DialogueDelegateDispatcher : public QAbstractItemDelegate
{ {
Q_OBJECT Q_OBJECT
@ -34,13 +64,17 @@ namespace CSVWorld
QObject* mParent; 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; QUndoStack& mUndoStack;
std::vector<DialogueDelegateDispatcherProxy*> mProxys; //once we move to the C++11 we should use unique_ptr
public: public:
DialogueDelegateDispatcher(QObject* parent, CSMWorld::IdTable* table, QUndoStack& undoStack); DialogueDelegateDispatcher(QObject* parent, CSMWorld::IdTable* table, QUndoStack& undoStack);
~DialogueDelegateDispatcher();
CSVWorld::CommandDelegate* makeDelegate(CSMWorld::ColumnBase::Display display); CSVWorld::CommandDelegate* makeDelegate(CSMWorld::ColumnBase::Display display);
QWidget* makeEditor(CSMWorld::ColumnBase::Display display, const QModelIndex& index); 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 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; virtual void paint (QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
///< does nothing ///< does nothing
@ -57,14 +91,14 @@ namespace CSVWorld
///< does nothing ///< does nothing
private slots: private slots:
void editorDataCommited( QWidget * editor ); void editorDataCommited(QWidget* editor, const QModelIndex& index, CSMWorld::ColumnBase::Display display);
}; };
class DialogueSubView : public CSVDoc::SubView class DialogueSubView : public CSVDoc::SubView
{ {
QDataWidgetMapper *mWidgetMapper; QDataWidgetMapper *mWidgetMapper;
std::auto_ptr<DialogueDelegateDispatcher> mDispatcher; DialogueDelegateDispatcher mDispatcher;
public: public:

View file

@ -80,4 +80,5 @@ void CSVWorld::addSubViewFactories (CSVDoc::SubViewFactoryManager& manager)
manager.add (CSMWorld::UniversalId::Type_Scene, new CSVDoc::SubViewFactory<SceneSubView>); manager.add (CSMWorld::UniversalId::Type_Scene, new CSVDoc::SubViewFactory<SceneSubView>);
manager.add(CSMWorld::UniversalId::Type_Region, new CSVDoc::SubViewFactory<DialogueSubView>); manager.add(CSMWorld::UniversalId::Type_Region, new CSVDoc::SubViewFactory<DialogueSubView>);
manager.add(CSMWorld::UniversalId::Type_Spell, new CSVDoc::SubViewFactory<DialogueSubView>);
} }