Commit 10e1a4e5 authored by Christoph Cullmann's avatar Christoph Cullmann 🐮
Browse files

read/write right role

parent b53085ab
......@@ -53,9 +53,10 @@ void KateOutputView::slotMessage(const QVariantMap &message)
/**
* body column, formatted text
* we just set the full message as attribute
* we have our KateOutputMessageStyledDelegate to render this!
*/
auto bodyColumn = new QStandardItem();
bodyColumn->setData(QVariant::fromValue(message));
bodyColumn->setData(QVariant::fromValue(message), KateOutputMessageStyledDelegate::MessageRole);
/**
* add new message to model as one row
......
......@@ -22,22 +22,24 @@ class KateOutputMessageStyledDelegate : public QStyledItemDelegate
{
Q_OBJECT
public:
/**
* the role for the message
*/
static constexpr int MessageRole = Qt::UserRole + 1;
private:
/**
* setup text document from data
*/
static void setupText(QTextDocument &doc, const QVariant &data)
static void setupText(QTextDocument &doc, const QModelIndex &index)
{
const auto message = data.toMap();
printf("MUHH\n");
const auto message = index.data(KateOutputMessageStyledDelegate::MessageRole).toMap();
if (message.contains(QStringLiteral("plainText"))) {
printf("MUHH1\n");
doc.setPlainText(message.value(QStringLiteral("plainText")).toString());
} else if (message.contains(QStringLiteral("markDown"))) {
printf("MUHH2\n");
doc.setMarkdown(message.value(QStringLiteral("markDown")).toString());
} else if (message.contains(QStringLiteral("html"))) {
printf("MUHH4\n");
doc.setHtml(message.value(QStringLiteral("html")).toString());
}
}
......@@ -48,14 +50,14 @@ public:
void paint(QPainter *painter, const QStyleOptionViewItem &, const QModelIndex &index) const override
{
QTextDocument doc;
setupText(doc, index.data());
setupText(doc, index);
doc.drawContents(painter);
}
QSize sizeHint(const QStyleOptionViewItem &, const QModelIndex &index) const override
{
QTextDocument doc;
setupText(doc, index.data());
setupText(doc, index);
return doc.size().toSize();
}
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment