edit view, savind works

actorid
Marek Kochanowicz 11 years ago
parent 020e3f8fc5
commit 2e6b45dafb

@ -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})

@ -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

@ -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"<<std::endl;
std::cout<<"triggered"<<std::endl;
setModelData(editor, mTable, index, display);
}
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);
}
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));
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<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;
}
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<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);
@ -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<columns; ++i)
{
@ -130,8 +182,8 @@ CSVWorld::DialogueSubView::DialogueSubView (const CSMWorld::UniversalId& id, CSM
CSMWorld::ColumnBase::Display display = static_cast<CSMWorld::ColumnBase::Display>
(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)
{

@ -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<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
{
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<DialogueDelegateDispatcherProxy*> 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<DialogueDelegateDispatcher> mDispatcher;
DialogueDelegateDispatcher mDispatcher;
public:

@ -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_Region, new CSVDoc::SubViewFactory<DialogueSubView>);
manager.add(CSMWorld::UniversalId::Type_Spell, new CSVDoc::SubViewFactory<DialogueSubView>);
}
Loading…
Cancel
Save