Crossfire Server, Trunk
CREPrePostConditionDelegate.cpp
Go to the documentation of this file.
1 /*
2  * Crossfire -- cooperative multi-player graphical RPG and adventure game
3  *
4  * Copyright (c) 2022 the Crossfire Development Team
5  *
6  * Crossfire is free software and comes with ABSOLUTELY NO WARRANTY. You are
7  * welcome to redistribute it under certain conditions. For details, please
8  * see COPYING and LICENSE.
9  *
10  * The authors can be reached via e-mail at <crossfire@metalforge.org>.
11  */
12 
13 #include <QtWidgets>
15 #include "CREMessageItemModel.h"
16 #include "CREPrePostPanel.h"
17 
19  QStyledItemDelegate(parent), myMode(mode), myMessages(manager)
20 {
21 }
22 
23 QWidget* CREPrePostSingleConditionDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem&, const QModelIndex&) const
24 {
26 }
27 
28 void CREPrePostSingleConditionDelegate::setEditorData(QWidget* editor, const QModelIndex& index) const
29 {
30  CREPrePostPanel* edit = qobject_cast<CREPrePostPanel*>(editor);
31  if (!edit)
32  return;
33  edit->setData(index.data(Qt::UserRole).value<QStringList>());
34 }
35 
36 void CREPrePostSingleConditionDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const
37 {
38  CREPrePostPanel* edit = qobject_cast<CREPrePostPanel*>(editor);
39  if (!edit)
40  return;
41  QStringList data = edit->getData();
42  model->setData(index, data, Qt::UserRole);
44  data.pop_front();
45  model->setData(index, data.join(" "), Qt::DisplayRole);
46 }
47 
48 void CREPrePostSingleConditionDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem&, const QModelIndex&) const
49 {
50  if (!qApp->activeWindow())
51  return;
52  QRect r(qApp->activeWindow()->geometry());
53  r.setLeft(r.left() + r.width() * .1);
54  r.setWidth(r.width() * .8);
55  r.setTop(r.top() + r.height() * .1);
56  r.setHeight(r.height() * .8);
57  editor->setGeometry(r);
58 }
59 
60 
62  : QStyledItemDelegate(parent), myMode(mode), myMessages(manager)
63 {
64 }
65 
67 {
68 }
69 
70 QWidget* CREPrePostConditionDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem&, const QModelIndex&) const
71 {
72  return new CREPrePostList(parent, myMode, myMessages);
73 }
74 
75 void CREPrePostConditionDelegate::setEditorData(QWidget* editor, const QModelIndex& index) const
76 {
77  if (!index.isValid())
78  return;
79  CREPrePostList* list = qobject_cast<CREPrePostList*>(editor);
80  if (list == NULL)
81  return;
82 
83  QVariant data = index.model()->data(index, Qt::EditRole);
84  if (!data.canConvert<QList<QStringList>>())
85  return;
86 
87  list->setData(data.value<QList<QStringList>>());
88 }
89 
90 void CREPrePostConditionDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const
91 {
92  if (!index.isValid())
93  return;
94  CREPrePostList* list = qobject_cast<CREPrePostList*>(editor);
95  if (list == NULL)
96  return;
97 
98  model->setData(index, QVariant::fromValue(list->data()));
99 }
100 
101 void CREPrePostConditionDelegate::updateEditorGeometry(QWidget* editor, const QStyleOptionViewItem&, const QModelIndex&) const
102 {
103  if (!qApp->activeWindow())
104  return;
105  QRect r(qApp->activeWindow()->geometry());
106  r.setLeft(r.left() + r.width() * .1);
107  r.setWidth(r.width() * .8);
108  r.setTop(r.top() + r.height() * .1);
109  r.setHeight(r.height() * .8);
110  editor->setGeometry(r);
111 }
CREPrePostConditionDelegate::updateEditorGeometry
virtual void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const override
Definition: CREPrePostConditionDelegate.cpp:101
CREPrePostSingleConditionDelegate::myMode
PrePostWidget::Mode myMode
Definition: CREPrePostConditionDelegate.h:40
CREPrePostConditionDelegate::setModelData
virtual void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override
Definition: CREPrePostConditionDelegate.cpp:90
CREPrePostPanel::getData
QStringList getData()
Definition: CREPrePostPanel.cpp:479
CREPrePostConditionDelegate::CREPrePostConditionDelegate
CREPrePostConditionDelegate(QObject *parent, PrePostWidget::Mode mode, const MessageManager *manager)
Definition: CREPrePostConditionDelegate.cpp:61
CREPrePostList
Definition: CREPrePostList.h:53
guildoracle.list
list
Definition: guildoracle.py:87
CREPrePostConditionDelegate::setEditorData
virtual void setEditorData(QWidget *editor, const QModelIndex &index) const override
Definition: CREPrePostConditionDelegate.cpp:75
CREPrePostSingleConditionDelegate::CREPrePostSingleConditionDelegate
CREPrePostSingleConditionDelegate(QObject *parent, PrePostWidget::Mode mode, const MessageManager *manager)
Definition: CREPrePostConditionDelegate.cpp:18
CREPrePostSingleConditionDelegate::setModelData
virtual void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override
Definition: CREPrePostConditionDelegate.cpp:36
PrePostWidget::SetWhen
@ SetWhen
Definition: CREPrePostList.h:27
MessageManager::postConditions
QList< QuestConditionScript * > postConditions() const
Definition: MessageManager.cpp:106
PrePostWidget::PreConditions
@ PreConditions
Definition: CREPrePostList.h:27
CREPrePostPanel.h
MessageManager::preConditions
QList< QuestConditionScript * > preConditions() const
Definition: MessageManager.cpp:101
CREPrePostSingleConditionDelegate::setEditorData
virtual void setEditorData(QWidget *editor, const QModelIndex &index) const override
Definition: CREPrePostConditionDelegate.cpp:28
CREPrePostSingleConditionDelegate::myMessages
const MessageManager * myMessages
Definition: CREPrePostConditionDelegate.h:41
navar-midane_time.data
data
Definition: navar-midane_time.py:11
MessageManager
Definition: MessageManager.h:25
CREPrePostConditionDelegate::myMessages
const MessageManager * myMessages
Definition: CREPrePostConditionDelegate.h:66
CREPrePostConditionDelegate::myMode
PrePostWidget::Mode myMode
Definition: CREPrePostConditionDelegate.h:65
CREPrePostSingleConditionDelegate::updateEditorGeometry
virtual void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const override
Definition: CREPrePostConditionDelegate.cpp:48
CREPrePostPanel
Definition: CREPrePostPanel.h:152
CREPrePostConditionDelegate::~CREPrePostConditionDelegate
virtual ~CREPrePostConditionDelegate()
Definition: CREPrePostConditionDelegate.cpp:66
CREPrePostConditionDelegate::createEditor
virtual QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override
Definition: CREPrePostConditionDelegate.cpp:70
CREPrePostPanel::setData
void setData(const QStringList &data)
Definition: CREPrePostPanel.cpp:484
CREPrePostSingleConditionDelegate::createEditor
virtual QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override
Definition: CREPrePostConditionDelegate.cpp:23
PrePostWidget::Mode
Mode
Definition: CREPrePostList.h:27
npc_dialog.index
int index
Definition: npc_dialog.py:102
CREPrePostConditionDelegate.h
manager
static AssetsManager * manager
Definition: assets.cpp:60
CREMessageItemModel.h
ring_occidental_mages.r
r
Definition: ring_occidental_mages.py:6