2012-12-13 12:35:08 +00:00
|
|
|
#ifndef CSV_WORLD_DIALOGUESUBVIEW_H
|
|
|
|
#define CSV_WORLD_DIALOGUESUBVIEW_H
|
|
|
|
|
2015-07-03 15:48:13 +00:00
|
|
|
#include <set>
|
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
|
|
|
|
2018-12-01 20:27:43 +00:00
|
|
|
#ifndef Q_MOC_RUN
|
2012-12-13 12:35:08 +00:00
|
|
|
#include "../doc/subview.hpp"
|
2014-06-08 12:10:08 +00:00
|
|
|
|
2014-03-07 16:15:43 +00:00
|
|
|
#include "../../model/world/columnbase.hpp"
|
2014-06-08 12:10:08 +00:00
|
|
|
#include "../../model/world/commanddispatcher.hpp"
|
2015-07-03 12:37:10 +00:00
|
|
|
#include "../../model/world/universalid.hpp"
|
2018-12-01 20:27:43 +00:00
|
|
|
#endif
|
2012-12-13 12:35:08 +00:00
|
|
|
|
2013-01-08 13:59:40 +00:00
|
|
|
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;
|
2015-07-03 12:37:10 +00:00
|
|
|
class QMenu;
|
2014-03-07 16:15:43 +00:00
|
|
|
|
|
|
|
namespace CSMWorld
|
|
|
|
{
|
|
|
|
class IdTable;
|
2015-03-30 05:41:55 +00:00
|
|
|
class NestedTableProxyModel;
|
2014-03-07 16:15:43 +00:00
|
|
|
}
|
2013-01-08 13:59:40 +00:00
|
|
|
|
2015-12-15 09:40:00 +00:00
|
|
|
namespace CSMPrefs
|
|
|
|
{
|
|
|
|
class Setting;
|
|
|
|
}
|
|
|
|
|
2012-12-13 12:35:08 +00:00
|
|
|
namespace CSMDoc
|
|
|
|
{
|
|
|
|
class Document;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace CSVWorld
|
|
|
|
{
|
2014-03-07 16:15:43 +00:00
|
|
|
class CommandDelegate;
|
2014-03-18 08:36:22 +00:00
|
|
|
class CreatorFactoryBase;
|
|
|
|
class TableBottomBox;
|
2014-03-07 16:15:43 +00:00
|
|
|
|
2014-03-11 08:14:13 +00:00
|
|
|
class NotEditableSubDelegate : public QAbstractItemDelegate
|
|
|
|
{
|
|
|
|
const CSMWorld::IdTable* mTable;
|
|
|
|
public:
|
2014-06-17 16:28:49 +00:00
|
|
|
NotEditableSubDelegate(const CSMWorld::IdTable* table,
|
2020-11-13 07:39:47 +00:00
|
|
|
QObject * parent = nullptr);
|
2014-03-11 08:14:13 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void setEditorData (QWidget* editor, const QModelIndex& index) const override;
|
2014-03-11 08:14:13 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void setModelData (QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const override;
|
2014-03-11 08:14:13 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void paint (QPainter* painter,
|
2014-06-17 16:28:49 +00:00
|
|
|
const QStyleOptionViewItem& option,
|
2020-10-16 18:18:54 +00:00
|
|
|
const QModelIndex& index) const override;
|
2014-03-11 08:14:13 +00:00
|
|
|
///< does nothing
|
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
QSize sizeHint (const QStyleOptionViewItem& option,
|
|
|
|
const QModelIndex& index) const override;
|
2014-03-11 08:14:13 +00:00
|
|
|
///< does nothing
|
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
QWidget *createEditor (QWidget *parent,
|
2014-03-11 08:14:13 +00:00
|
|
|
const QStyleOptionViewItem& option,
|
2020-10-16 18:18:54 +00:00
|
|
|
const QModelIndex& index) const override;
|
2014-03-11 08:14:13 +00:00
|
|
|
};
|
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
|
|
|
|
2017-04-28 15:30:26 +00:00
|
|
|
std::unique_ptr<refWrapper> mIndexWrapper;
|
2014-03-12 18:55:51 +00:00
|
|
|
|
2014-03-07 21:17:40 +00:00
|
|
|
public:
|
2014-06-17 16:28:49 +00:00
|
|
|
DialogueDelegateDispatcherProxy(QWidget* editor,
|
|
|
|
CSMWorld::ColumnBase::Display display);
|
2014-03-07 21:17:40 +00:00
|
|
|
QWidget* getEditor() const;
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
void editorDataCommited();
|
|
|
|
void setIndex(const QModelIndex& index);
|
|
|
|
|
|
|
|
signals:
|
2014-06-17 16:28:49 +00:00
|
|
|
void editorDataCommited(QWidget* editor,
|
|
|
|
const QModelIndex& index,
|
|
|
|
CSMWorld::ColumnBase::Display display);
|
2014-03-13 15:50:04 +00:00
|
|
|
|
2014-03-07 21:17:40 +00:00
|
|
|
};
|
|
|
|
|
2014-03-07 16:15:43 +00:00
|
|
|
class DialogueDelegateDispatcher : public QAbstractItemDelegate
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
std::map<int, CommandDelegate*> mDelegates;
|
|
|
|
|
|
|
|
QObject* mParent;
|
|
|
|
|
2015-04-16 15:27:36 +00:00
|
|
|
QAbstractItemModel* mTable;
|
2014-03-07 16:15:43 +00:00
|
|
|
|
2015-01-15 13:24:33 +00:00
|
|
|
CSMWorld::CommandDispatcher& mCommandDispatcher;
|
|
|
|
CSMDoc::Document& mDocument;
|
2014-03-07 16:15:43 +00:00
|
|
|
|
2014-03-11 08:14:13 +00:00
|
|
|
NotEditableSubDelegate mNotEditableDelegate;
|
|
|
|
|
2014-06-17 16:28:49 +00:00
|
|
|
std::vector<DialogueDelegateDispatcherProxy*> mProxys;
|
2015-03-06 03:36:13 +00:00
|
|
|
//once we move to the C++11 we should use unique_ptr
|
2014-03-07 21:17:40 +00:00
|
|
|
|
2014-03-07 16:15:43 +00:00
|
|
|
public:
|
2014-06-17 16:28:49 +00:00
|
|
|
DialogueDelegateDispatcher(QObject* parent,
|
|
|
|
CSMWorld::IdTable* table,
|
2015-04-24 23:39:37 +00:00
|
|
|
CSMWorld::CommandDispatcher& commandDispatcher,
|
2015-04-16 15:27:36 +00:00
|
|
|
CSMDoc::Document& document,
|
2020-11-13 07:39:47 +00:00
|
|
|
QAbstractItemModel* model = nullptr);
|
2014-03-07 16:15:43 +00:00
|
|
|
|
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);
|
2015-04-16 15:27:36 +00:00
|
|
|
///< will return null if delegate is not present, parent of the widget is
|
|
|
|
//same as for dispatcher itself
|
2014-03-07 16:15:43 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void setEditorData (QWidget* editor, const QModelIndex& index) const override;
|
2014-03-07 16:15:43 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void setModelData (QWidget* editor, QAbstractItemModel* model,
|
|
|
|
const QModelIndex& index) const override;
|
2015-03-14 01:42:46 +00:00
|
|
|
|
2015-04-16 15:27:36 +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
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void paint (QPainter* painter,
|
2014-06-17 16:28:49 +00:00
|
|
|
const QStyleOptionViewItem& option,
|
2020-10-16 18:18:54 +00:00
|
|
|
const QModelIndex& index) const override;
|
2014-03-07 16:15:43 +00:00
|
|
|
///< does nothing
|
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
QSize sizeHint (const QStyleOptionViewItem& option,
|
|
|
|
const QModelIndex& index) const override;
|
2014-03-07 16:15:43 +00:00
|
|
|
///< does nothing
|
|
|
|
|
2014-03-07 21:17:40 +00:00
|
|
|
private slots:
|
2014-06-17 16:28:49 +00:00
|
|
|
void editorDataCommited(QWidget* editor, const QModelIndex& index,
|
|
|
|
CSMWorld::ColumnBase::Display display);
|
2014-03-07 16:15:43 +00:00
|
|
|
};
|
|
|
|
|
2015-07-03 15:48:13 +00:00
|
|
|
/// A context menu with "Edit 'ID'" action for editors in the dialogue subview
|
2015-07-03 12:37:10 +00:00
|
|
|
class IdContextMenu : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
QWidget *mWidget;
|
|
|
|
CSMWorld::UniversalId::Type mIdType;
|
2015-07-03 15:48:13 +00:00
|
|
|
std::set<std::string> mExcludedIds;
|
|
|
|
///< A list of IDs that should not have the Edit 'ID' action.
|
2015-07-03 12:37:10 +00:00
|
|
|
|
|
|
|
QMenu *mContextMenu;
|
|
|
|
QAction *mEditIdAction;
|
|
|
|
|
|
|
|
QString getWidgetValue() const;
|
2015-07-03 13:51:47 +00:00
|
|
|
void addEditIdActionToMenu(const QString &text);
|
|
|
|
void removeEditIdActionFromMenu();
|
2015-07-03 12:37:10 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
IdContextMenu(QWidget *widget, CSMWorld::ColumnBase::Display display);
|
|
|
|
|
2015-07-03 15:48:13 +00:00
|
|
|
void excludeId(const std::string &id);
|
|
|
|
|
2015-07-03 12:37:10 +00:00
|
|
|
private slots:
|
|
|
|
void showContextMenu(const QPoint &pos);
|
2015-07-03 13:24:08 +00:00
|
|
|
void editIdRequest();
|
2015-07-03 12:37:10 +00:00
|
|
|
|
|
|
|
signals:
|
|
|
|
void editIdRequest(const CSMWorld::UniversalId &id, const std::string &hint);
|
|
|
|
};
|
|
|
|
|
2014-03-12 09:21:52 +00:00
|
|
|
class EditWidget : public QScrollArea
|
2012-12-13 12:35:08 +00:00
|
|
|
{
|
2014-03-13 15:50:04 +00:00
|
|
|
Q_OBJECT
|
2013-01-08 13:59:40 +00:00
|
|
|
QDataWidgetMapper *mWidgetMapper;
|
2015-04-16 15:27:36 +00:00
|
|
|
QDataWidgetMapper *mNestedTableMapper;
|
2015-05-19 09:19:52 +00:00
|
|
|
DialogueDelegateDispatcher *mDispatcher;
|
2015-04-16 15:27:36 +00:00
|
|
|
DialogueDelegateDispatcher *mNestedTableDispatcher;
|
2014-03-12 09:21:52 +00:00
|
|
|
QWidget* mMainWidget;
|
|
|
|
CSMWorld::IdTable* mTable;
|
2015-01-15 13:24:33 +00:00
|
|
|
CSMWorld::CommandDispatcher& mCommandDispatcher;
|
2014-08-23 10:25:12 +00:00
|
|
|
CSMDoc::Document& mDocument;
|
2015-03-30 05:41:55 +00:00
|
|
|
std::vector<CSMWorld::NestedTableProxyModel*> mNestedModels; //Plain, raw C pointers, deleted in the dtor
|
2014-03-12 09:21:52 +00:00
|
|
|
|
2015-07-13 10:52:18 +00:00
|
|
|
void createEditorContextMenu(QWidget *editor,
|
|
|
|
CSMWorld::ColumnBase::Display display,
|
2015-07-04 16:55:48 +00:00
|
|
|
int currentRow) const;
|
2014-03-12 09:21:52 +00:00
|
|
|
public:
|
|
|
|
|
2014-06-17 16:28:49 +00:00
|
|
|
EditWidget (QWidget *parent, int row, CSMWorld::IdTable* table,
|
2015-04-24 23:39:37 +00:00
|
|
|
CSMWorld::CommandDispatcher& commandDispatcher,
|
2015-03-06 03:36:13 +00:00
|
|
|
CSMDoc::Document& document, bool createAndDelete = false);
|
2012-12-13 12:35:08 +00:00
|
|
|
|
2014-07-07 08:27:48 +00:00
|
|
|
virtual ~EditWidget();
|
2012-12-13 12:35:08 +00:00
|
|
|
|
2014-03-12 11:25:37 +00:00
|
|
|
void remake(int row);
|
2015-07-03 13:24:08 +00:00
|
|
|
|
|
|
|
signals:
|
|
|
|
void editIdRequest(const CSMWorld::UniversalId &id, const std::string &hint);
|
2014-03-12 09:21:52 +00:00
|
|
|
};
|
|
|
|
|
2015-06-26 13:17:47 +00:00
|
|
|
class SimpleDialogueSubView : public CSVDoc::SubView
|
2014-03-12 09:21:52 +00:00
|
|
|
{
|
2015-06-27 13:29:54 +00:00
|
|
|
Q_OBJECT
|
2014-03-12 11:25:37 +00:00
|
|
|
|
2015-06-27 13:29:54 +00:00
|
|
|
EditWidget* mEditWidget;
|
|
|
|
QVBoxLayout* mMainLayout;
|
|
|
|
CSMWorld::IdTable* mTable;
|
|
|
|
bool mLocked;
|
|
|
|
const CSMDoc::Document& mDocument;
|
|
|
|
CSMWorld::CommandDispatcher mCommandDispatcher;
|
2014-03-12 11:25:37 +00:00
|
|
|
|
2015-06-26 13:17:47 +00:00
|
|
|
protected:
|
2012-12-13 12:35:08 +00:00
|
|
|
|
2015-06-26 13:17:47 +00:00
|
|
|
QVBoxLayout& getMainLayout();
|
2012-12-13 12:35:08 +00:00
|
|
|
|
2015-06-26 13:17:47 +00:00
|
|
|
CSMWorld::IdTable& getTable();
|
2014-03-12 11:25:37 +00:00
|
|
|
|
2015-06-26 13:17:47 +00:00
|
|
|
CSMWorld::CommandDispatcher& getCommandDispatcher();
|
2014-03-12 11:25:37 +00:00
|
|
|
|
2015-06-26 13:17:47 +00:00
|
|
|
EditWidget& getEditWidget();
|
2014-03-12 11:25:37 +00:00
|
|
|
|
2015-06-27 13:29:54 +00:00
|
|
|
void updateCurrentId();
|
2014-03-12 15:06:59 +00:00
|
|
|
|
2015-06-26 13:17:47 +00:00
|
|
|
bool isLocked() const;
|
2015-07-13 10:52:18 +00:00
|
|
|
|
2015-06-26 13:17:47 +00:00
|
|
|
public:
|
2014-03-19 10:42:43 +00:00
|
|
|
|
2015-06-26 13:17:47 +00:00
|
|
|
SimpleDialogueSubView (const CSMWorld::UniversalId& id, CSMDoc::Document& document);
|
2014-03-19 11:01:36 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void setEditLock (bool locked) override;
|
2015-06-26 13:17:47 +00:00
|
|
|
|
|
|
|
private slots:
|
2014-03-18 08:36:22 +00:00
|
|
|
|
2014-03-13 17:26:59 +00:00
|
|
|
void dataChanged(const QModelIndex & index);
|
2014-03-12 15:06:59 +00:00
|
|
|
///\brief we need to care for deleting currently edited record
|
2014-03-13 15:50:04 +00:00
|
|
|
|
2015-05-24 13:19:06 +00:00
|
|
|
void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end);
|
2012-12-13 12:35:08 +00:00
|
|
|
};
|
2015-06-26 13:17:47 +00:00
|
|
|
|
2015-06-27 12:25:48 +00:00
|
|
|
class RecordButtonBar;
|
|
|
|
|
2015-06-26 13:17:47 +00:00
|
|
|
class DialogueSubView : public SimpleDialogueSubView
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
2015-07-13 10:52:18 +00:00
|
|
|
|
2015-06-26 13:17:47 +00:00
|
|
|
TableBottomBox* mBottom;
|
2015-06-27 12:25:48 +00:00
|
|
|
RecordButtonBar *mButtons;
|
2015-06-26 13:17:47 +00:00
|
|
|
|
2015-07-13 10:52:18 +00:00
|
|
|
private:
|
|
|
|
|
|
|
|
void addButtonBar();
|
|
|
|
|
2015-06-26 13:17:47 +00:00
|
|
|
public:
|
|
|
|
|
|
|
|
DialogueSubView (const CSMWorld::UniversalId& id, CSMDoc::Document& document,
|
|
|
|
const CreatorFactoryBase& creatorFactory, bool sorting = false);
|
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void setEditLock (bool locked) override;
|
2015-06-27 12:25:48 +00:00
|
|
|
|
2015-06-26 13:17:47 +00:00
|
|
|
private slots:
|
|
|
|
|
2015-12-15 09:40:00 +00:00
|
|
|
void settingChanged (const CSMPrefs::Setting *setting);
|
|
|
|
|
2015-06-26 13:17:47 +00:00
|
|
|
void showPreview();
|
|
|
|
|
|
|
|
void viewRecord();
|
2015-06-27 12:42:22 +00:00
|
|
|
|
2015-07-13 10:52:18 +00:00
|
|
|
void switchToRow (int row);
|
2015-06-27 13:29:54 +00:00
|
|
|
|
|
|
|
void requestFocus (const std::string& id);
|
2015-06-26 13:17:47 +00:00
|
|
|
};
|
2012-12-13 12:35:08 +00:00
|
|
|
}
|
|
|
|
|
2014-06-09 08:26:53 +00:00
|
|
|
#endif
|