From d96284ee3eafcb5d9e26656bb29cb25bcb484ffc Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Mon, 29 Nov 2021 19:35:57 +0100 Subject: [PATCH] Only show formatted description in detail page We can't show rich text in the package list, because the we use the onLineLaidOut signal there, which doesn't work with Rich Text. So for the package list we should NOT use the formatted version of the description because that will contain ugly HTML tags that the user wouldn't want to see. Show the original description there. Use the formatted description only in the detail page where we don't use onLineLaidOut. Contributes to issue CURA-8565. --- plugins/Marketplace/PackageModel.py | 9 +++++++-- plugins/Marketplace/resources/qml/PackageCard.qml | 3 ++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/plugins/Marketplace/PackageModel.py b/plugins/Marketplace/PackageModel.py index 294b34c8b3..7528a71440 100644 --- a/plugins/Marketplace/PackageModel.py +++ b/plugins/Marketplace/PackageModel.py @@ -34,7 +34,8 @@ class PackageModel(QObject): self._package_version = package_data.get("package_version", "") # Display purpose, no need for 'UM.Version'. self._package_info_url = package_data.get("website", "") # Not to be confused with 'download_url'. self._download_count = package_data.get("download_count", 0) - self._description = self._format(package_data.get("description", "")) + self._description = package_data.get("description", "") + self._formatted_description = self._format(self._description) self._download_url = package_data.get("download_url", "") self._release_notes = package_data.get("release_notes", "") # Not used yet, propose to add to description? @@ -48,7 +49,7 @@ class PackageModel(QObject): self._section_title = section_title # Note that there's a lot more info in the package_data than just these specified here. - def _format(self, text): + def _format(self, text: str) -> str: """ Formats a user-readable block of text for display. :return: A block of rich text with formatting embedded. @@ -95,6 +96,10 @@ class PackageModel(QObject): def description(self): return self._description + @pyqtProperty(str, constant = True) + def formattedDescription(self) -> str: + return self._formatted_description + @pyqtProperty(str, constant=True) def authorName(self): return self._author_name diff --git a/plugins/Marketplace/resources/qml/PackageCard.qml b/plugins/Marketplace/resources/qml/PackageCard.qml index 2c0aaa250a..8f94dc990b 100644 --- a/plugins/Marketplace/resources/qml/PackageCard.qml +++ b/plugins/Marketplace/resources/qml/PackageCard.qml @@ -233,6 +233,7 @@ Rectangle property real lastLineWidth: 0; //Store the width of the last line, to properly position the elision. text: packageData.description + textFormat: Text.PlainText //Must be plain text, or we won't get onLineLaidOut signals. Don't auto-detect! font: UM.Theme.getFont("default") color: UM.Theme.getColor("text") maximumLineCount: 2 @@ -401,7 +402,7 @@ Rectangle { width: parent.width - parent.padding * 2 - text: packageData.description + text: packageData.formattedDescription font: UM.Theme.getFont("default") color: UM.Theme.getColor("text") linkColor: UM.Theme.getColor("text_link")