1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-12 10:03:53 +02:00
vcmi/mapeditor/inspector/messagewidget.cpp

64 lines
1.3 KiB
C++
Raw Normal View History

2022-10-08 22:32:02 +02:00
/*
* messagewidget.cpp, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
*
* License: GNU General Public License v2.0 or later
* Full text of license available in license.txt file, in main folder
*
*/
2022-10-16 12:22:34 +02:00
#include "StdInc.h"
2022-09-18 01:23:17 +02:00
#include "messagewidget.h"
#include "ui_messagewidget.h"
MessageWidget::MessageWidget(QWidget *parent) :
QDialog(parent),
ui(new Ui::MessageWidget)
{
ui->setupUi(this);
}
MessageWidget::~MessageWidget()
{
delete ui;
}
void MessageWidget::setMessage(const QString & m)
{
ui->messageEdit->setPlainText(m);
}
QString MessageWidget::getMessage() const
{
return ui->messageEdit->toPlainText();
}
2022-10-16 23:16:27 +02:00
QWidget * MessageDelegate::createEditor(QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index) const
2022-09-18 01:23:17 +02:00
{
return new MessageWidget(parent);
}
2022-10-16 23:16:27 +02:00
void MessageDelegate::setEditorData(QWidget * editor, const QModelIndex & index) const
2022-09-18 01:23:17 +02:00
{
if(auto *ed = qobject_cast<MessageWidget *>(editor))
{
ed->setMessage(index.data().toString());
}
else
{
QStyledItemDelegate::setEditorData(editor, index);
}
}
2022-10-16 23:16:27 +02:00
void MessageDelegate::setModelData(QWidget * editor, QAbstractItemModel * model, const QModelIndex & index) const
2022-09-18 01:23:17 +02:00
{
if(auto *ed = qobject_cast<MessageWidget *>(editor))
{
model->setData(index, ed->getMessage());
}
else
{
QStyledItemDelegate::setModelData(editor, model, index);
}
}