Crossfire Server, Trunk
CREMultilineItemDelegate.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 <QTextEdit>
14 #include <qstyleditemdelegate.h>
16 
17 CREMultilineItemDelegate::CREMultilineItemDelegate(QObject* parent, bool asStringList, bool trimEmpty)
18 : QStyledItemDelegate(parent), myAsStringList(asStringList), myTrimEmpty(trimEmpty)
19 {
20 }
21 
23 {
24 }
25 
26 QWidget* CREMultilineItemDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& /*option*/, const QModelIndex& /*index*/) const
27 {
28  QTextEdit* edit = new QTextEdit(parent);
29  edit->setAcceptRichText(false);
30  return edit;
31 }
32 
33 void CREMultilineItemDelegate::setEditorData(QWidget* editor, const QModelIndex& index) const
34 {
35  if (!index.isValid())
36  return;
37  QTextEdit* edit = qobject_cast<QTextEdit*>(editor);
38  if (edit == NULL)
39  return;
40 
41  if (myAsStringList)
42  edit->setPlainText(index.model()->data(index, Qt::EditRole).value<QStringList>().join("\n"));
43  else
44  edit->setPlainText(index.model()->data(index, Qt::EditRole).toString());
45 }
46 
47 QStringList convert(const QString& source, bool trimEmpty)
48 {
49  QStringList value;
50  for (QString line : source.split("\n"))
51  {
52  if (!line.isEmpty() || !trimEmpty)
53  value.append(line);
54  }
55  return value;
56 }
57 
58 void CREMultilineItemDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const
59 {
60  if (!index.isValid())
61  return;
62  QTextEdit* edit = qobject_cast<QTextEdit*>(editor);
63  if (edit == NULL)
64  return;
65 
66  if (myAsStringList)
67  model->setData(index, convert(edit->toPlainText(), myTrimEmpty));
68  else
69  model->setData(index, edit->toPlainText());
70 }
line
Install Bug reporting Credits so make sure you have version or later There are files involved in the automatic convert convertall and filelist py GuildList has the list of guilds for the server GuildLocations is what is used by the install script for setting up the maps It has columns in the first is the name of the no spaces The second is the region of the the third is the destination folder for the the fourth is the exit the fifth and sixth are the x and y coords within the exit the seventh eighth and ninth are the exit location for the storage hall If field seven is then it uses the same exit map as for the guild hall itself filelist py has a list of which files to process for each guild hall convert py takes all the files in filelist py and customises them to the specific guild then outputs them into a in the same order that they are listed in GuildLocations convertall py reads the lines from GuildLocations and runs line by line
Definition: README.txt:12
CREMultilineItemDelegate::setEditorData
virtual void setEditorData(QWidget *editor, const QModelIndex &index) const override
Definition: CREMultilineItemDelegate.cpp:33
CREMultilineItemDelegate::~CREMultilineItemDelegate
virtual ~CREMultilineItemDelegate()
Definition: CREMultilineItemDelegate.cpp:22
CREMultilineItemDelegate.h
CREMultilineItemDelegate::setModelData
virtual void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override
Definition: CREMultilineItemDelegate.cpp:58
source
Almost all the spell_ *base png files are taken from JXClient s source
Definition: readme-icons.txt:1
CREMultilineItemDelegate::myTrimEmpty
bool myTrimEmpty
Definition: CREMultilineItemDelegate.h:37
convert
QStringList convert(const QString &source, bool trimEmpty)
Definition: CREMultilineItemDelegate.cpp:47
CREMultilineItemDelegate::myAsStringList
bool myAsStringList
Definition: CREMultilineItemDelegate.h:36
autojail.value
value
Definition: autojail.py:6
CREMultilineItemDelegate::createEditor
virtual QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override
Definition: CREMultilineItemDelegate.cpp:26
npc_dialog.index
int index
Definition: npc_dialog.py:102
CREMultilineItemDelegate::CREMultilineItemDelegate
CREMultilineItemDelegate(QObject *parent, bool asStringList=true, bool trimEmpty=false)
Definition: CREMultilineItemDelegate.cpp:17