1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-16 08:49:55 +00:00
openmw-tes3mp/apps/opencs/view/world/dialoguesubview.hpp

163 lines
4.7 KiB
C++
Raw Normal View History

#ifndef CSV_WORLD_DIALOGUESUBVIEW_H
#define CSV_WORLD_DIALOGUESUBVIEW_H
2014-03-07 16:15:43 +00:00
#include <map>
#include <memory>
#include <QAbstractItemDelegate>
2014-03-12 09:21:52 +00:00
#include <QScrollArea>
2014-03-07 16:15:43 +00:00
#include "../doc/subview.hpp"
2014-03-07 16:15:43 +00:00
#include "../../model/world/columnbase.hpp"
class QDataWidgetMapper;
2014-03-07 16:15:43 +00:00
class QSize;
class QEvent;
2014-03-11 08:14:13 +00:00
class QLabel;
2014-03-12 11:25:37 +00:00
class QVBoxLayout;
2014-03-07 16:15:43 +00:00
namespace CSMWorld
{
class IdTable;
}
namespace CSMDoc
{
class Document;
}
namespace CSVWorld
{
2014-03-07 16:15:43 +00:00
class CommandDelegate;
2014-03-11 08:14:13 +00:00
class NotEditableSubDelegate : public QAbstractItemDelegate
{
const CSMWorld::IdTable* mTable;
public:
NotEditableSubDelegate(const CSMWorld::IdTable* table, QObject * parent = 0);
virtual void setEditorData (QLabel* editor, 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
virtual QSize sizeHint (const QStyleOptionViewItem& option, const QModelIndex& index) const;
///< does nothing
virtual QWidget *createEditor (QWidget *parent,
const QStyleOptionViewItem& option,
const QModelIndex& index,
CSMWorld::ColumnBase::Display display = CSMWorld::ColumnBase::Display_None) const;
};
2014-03-07 21:17:40 +00:00
2014-03-08 14:10:55 +00:00
//this can't be nested into the DialogueDelegateDispatcher, because it needs to emit signals
2014-03-07 21:17:40 +00:00
class DialogueDelegateDispatcherProxy : public QObject
{
Q_OBJECT
2014-03-08 14:10:55 +00:00
class refWrapper
{
public:
refWrapper(const QModelIndex& index);
2014-03-07 21:17:40 +00:00
2014-03-08 14:10:55 +00:00
const QModelIndex& mIndex;
};
2014-03-07 21:17:40 +00:00
2014-03-08 14:10:55 +00:00
QWidget* mEditor;
2014-03-07 21:17:40 +00:00
2014-03-08 14:10:55 +00:00
CSMWorld::ColumnBase::Display mDisplay;
2014-03-07 21:17:40 +00:00
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);
};
2014-03-07 16:15:43 +00:00
class DialogueDelegateDispatcher : public QAbstractItemDelegate
{
Q_OBJECT
std::map<int, CommandDelegate*> mDelegates;
QObject* mParent;
2014-03-07 21:17:40 +00:00
CSMWorld::IdTable* mTable; //nor sure if it is needed TODO
2014-03-07 16:15:43 +00:00
QUndoStack& mUndoStack;
2014-03-11 08:14:13 +00:00
NotEditableSubDelegate mNotEditableDelegate;
2014-03-07 21:17:40 +00:00
std::vector<DialogueDelegateDispatcherProxy*> mProxys; //once we move to the C++11 we should use unique_ptr
2014-03-07 16:15:43 +00:00
public:
DialogueDelegateDispatcher(QObject* parent, CSMWorld::IdTable* table, QUndoStack& undoStack);
2014-03-07 21:17:40 +00:00
~DialogueDelegateDispatcher();
2014-03-07 16:15:43 +00:00
CSVWorld::CommandDelegate* makeDelegate(CSMWorld::ColumnBase::Display display);
QWidget* makeEditor(CSMWorld::ColumnBase::Display display, const QModelIndex& index);
///< will return null if delegate is not present, parent of the widget is same as for dispatcher itself
virtual void setEditorData (QWidget* editor, const QModelIndex& index) const;
2014-03-07 21:17:40 +00:00
virtual void setModelData (QWidget* editor, QAbstractItemModel* model, const QModelIndex& index, CSMWorld::ColumnBase::Display display) const;
2014-03-07 16:15:43 +00:00
virtual void paint (QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
///< does nothing
virtual QSize sizeHint (const QStyleOptionViewItem& option, const QModelIndex& index) const;
///< does nothing
2014-03-07 21:17:40 +00:00
private slots:
void editorDataCommited(QWidget* editor, const QModelIndex& index, CSMWorld::ColumnBase::Display display);
2014-03-07 16:15:43 +00:00
};
2014-03-12 09:21:52 +00:00
class EditWidget : public QScrollArea
{
QDataWidgetMapper *mWidgetMapper;
2014-03-07 21:17:40 +00:00
DialogueDelegateDispatcher mDispatcher;
2014-03-12 09:21:52 +00:00
QWidget* mMainWidget;
CSMWorld::IdTable* mTable;
QUndoStack& mUndoStack;
public:
2014-03-12 11:25:37 +00:00
EditWidget (QWidget *parent, int row, CSMWorld::IdTable* table, QUndoStack& undoStack, bool createAndDelete = false);
2014-03-12 11:25:37 +00:00
void remake(int row);
2014-03-12 09:21:52 +00:00
};
class DialogueSubView : public CSVDoc::SubView
{
2014-03-12 11:25:37 +00:00
Q_OBJECT
EditWidget* mEditWidget;
QVBoxLayout* mMainLayout;
CSMWorld::IdTable* mTable;
QUndoStack& mUndoStack;
int mRow;
public:
2014-03-06 19:10:13 +00:00
DialogueSubView (const CSMWorld::UniversalId& id, CSMDoc::Document& document, bool createAndDelete = false);
virtual void setEditLock (bool locked);
2014-03-12 11:25:37 +00:00
private slots:
void nextId();
void prevId();
};
}
#endif