MessageEventModel plain text role

Update the message role to be named plainText and use it the message delegate for openMessageContext.
This removes the need for plainText in controller so it is removed.
This commit is contained in:
James Graham
2023-04-27 16:58:52 +00:00
parent af078f03d0
commit 4b879be4ea
6 changed files with 6 additions and 19 deletions

View File

@@ -670,11 +670,6 @@ bool Controller::hasWindowSystem() const
#endif
}
QString Controller::plainText(QQuickTextDocument *document) const
{
return document->textDocument()->toPlainText();
}
bool Controller::encryptionSupported() const
{
#ifdef QUOTIENT_07

View File

@@ -207,14 +207,6 @@ public:
*/
Q_INVOKABLE QString formatByteSize(double size, int precision = 1) const;
/**
* @brief Return a plain text representation of the text in a given QQuickTextDocument.
*
* TODO: This is only used in messageDelegate to get the plain text of a message.
* This should be changed to a role in messageeventmodel via texthandler.
*/
Q_INVOKABLE QString plainText(QQuickTextDocument *document) const;
/**
* @brief Force a QQuickTextDocument to refresh when images are loaded.
*

View File

@@ -34,7 +34,7 @@ QHash<int, QByteArray> MessageEventModel::roleNames() const
{
QHash<int, QByteArray> roles = QAbstractItemModel::roleNames();
roles[DelegateTypeRole] = "delegateType";
roles[MessageRole] = "message";
roles[PlainText] = "plainText";
roles[EventIdRole] = "eventId";
roles[TimeRole] = "time";
roles[SectionRole] = "section";
@@ -493,7 +493,7 @@ QVariant MessageEventModel::data(const QModelIndex &idx, int role) const
return {};
}
if (role == MessageRole) {
if (role == PlainText) {
return m_currentRoom->eventToString(evt);
}

View File

@@ -58,7 +58,7 @@ public:
*/
enum EventRoles {
DelegateTypeRole = Qt::UserRole + 1, /**< The delegate type of the message. */
MessageRole, /**< Plain text representation of the message. */
PlainText, /**< Plain text representation of the message. */
EventIdRole, /**< The matrix event ID of the event. */
TimeRole, /**< The timestamp for when the event was sent. */
SectionRole, /**< The date of the event as a string. */

View File

@@ -79,11 +79,11 @@ TimelineContainer {
TapHandler {
acceptedButtons: Qt.LeftButton
onLongPressed: openMessageContext(model, "", model.message)
onLongPressed: openMessageContext(model, "", model.plainText)
}
TapHandler {
acceptedButtons: Qt.RightButton
onTapped: openMessageContext(model, "", model.message)
onTapped: openMessageContext(model, "", model.plainText)
}
}
}

View File

@@ -13,7 +13,7 @@ import org.kde.neochat 1.0
TimelineContainer {
id: messageDelegate
onOpenContextMenu: openMessageContext(model, label.selectedText, Controller.plainText(label.textDocument))
onOpenContextMenu: openMessageContext(model, label.selectedText, model.plainText)
innerObject: ColumnLayout {
Layout.maximumWidth: messageDelegate.contentMaxWidth