Crossfire Server, Trunk
CREStringListDelegate.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 "CREStringListDelegate.h"
14 #include "CREStringListPanel.h"
15 
16 CREStringListDelegate::CREStringListDelegate(QObject* parent) : QStyledItemDelegate(parent)
17 {
18 }
19 
21 {
22 }
23 
24 QWidget* CREStringListDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem&, const QModelIndex&) const
25 {
26  return new CREStringListPanel(parent);
27 }
28 
29 void CREStringListDelegate::setEditorData(QWidget* editor, const QModelIndex& index) const
30 {
31  CREStringListPanel* edit = qobject_cast<CREStringListPanel*>(editor);
32  if (!edit)
33  return;
34  edit->setData(index.data(Qt::EditRole).value<QStringList>());
35 }
36 
37 void CREStringListDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const
38 {
39  CREStringListPanel* edit = qobject_cast<CREStringListPanel*>(editor);
40  if (!edit)
41  return;
42  model->setData(index, QVariant::fromValue(edit->data()), Qt::EditRole);
43 }
44 
45 void CREStringListDelegate::updateEditorGeometry(QWidget* editor, const QStyleOptionViewItem&, const QModelIndex&) const
46 {
47  if (!qApp->activeWindow())
48  return;
49  QRect r(qApp->activeWindow()->geometry());
50  r.setLeft(r.left() + r.width() * .1);
51  r.setWidth(r.width() * .8);
52  r.setTop(r.top() + r.height() * .1);
53  r.setHeight(r.height() * .8);
54  editor->setGeometry(r);
55 }
CREStringListPanel::data
QStringList data() const
Definition: CREStringListPanel.cpp:58
CREStringListPanel
Definition: CREStringListPanel.h:24
CREStringListDelegate::updateEditorGeometry
virtual void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const override
Definition: CREStringListDelegate.cpp:45
CREStringListDelegate.h
CREStringListPanel::setData
void setData(const QStringList &list)
Definition: CREStringListPanel.cpp:50
CREStringListDelegate::setEditorData
virtual void setEditorData(QWidget *editor, const QModelIndex &index) const override
Definition: CREStringListDelegate.cpp:29
CREStringListDelegate::CREStringListDelegate
CREStringListDelegate(QObject *parent)
Definition: CREStringListDelegate.cpp:16
CREStringListDelegate::setModelData
virtual void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override
Definition: CREStringListDelegate.cpp:37
npc_dialog.index
int index
Definition: npc_dialog.py:102
CREStringListDelegate::createEditor
virtual QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override
Definition: CREStringListDelegate.cpp:24
CREStringListDelegate::~CREStringListDelegate
virtual ~CREStringListDelegate()
Definition: CREStringListDelegate.cpp:20
CREStringListPanel.h
ring_occidental_mages.r
r
Definition: ring_occidental_mages.py:6