Crossfire Server, Trunk  R20513
CREMultilineItemDelegate.cpp
Go to the documentation of this file.
1 #include <QTextEdit>
2 #include <qstyleditemdelegate.h>
4 #include "CREQuestItemModel.h"
5 #include "Quest.h"
6 
7 CREMultilineItemDelegate::CREMultilineItemDelegate(QObject* parent) : QStyledItemDelegate(parent)
8 {
9 }
10 
12 {
13 }
14 
15 QWidget* CREMultilineItemDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& /*option*/, const QModelIndex& /*index*/) const
16 {
17  QTextEdit* edit = new QTextEdit(parent);
18  edit->setAcceptRichText(false);
19  return edit;
20 }
21 
22 void CREMultilineItemDelegate::setEditorData(QWidget* editor, const QModelIndex& index) const
23 {
24  if (!index.isValid())
25  return;
26  QTextEdit* edit = qobject_cast<QTextEdit*>(editor);
27  if (edit == NULL)
28  return;
29 
30  edit->setPlainText(index.model()->data(index, Qt::EditRole).toString());
31 }
32 
33 void CREMultilineItemDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, 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  CREQuestItemModel* qim = qobject_cast<CREQuestItemModel*>(model);
41  if (qim == NULL)
42  return;
43 
44  QVariant value = edit->toPlainText();
45  qim->setData(index, value);
46 }
virtual void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
virtual QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
virtual bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
virtual void setEditorData(QWidget *editor, const QModelIndex &index) const