Browse Source

CURA-5035 Add compatibility chart

Ian Paschal 6 years ago
parent
commit
0872d499f8

+ 108 - 0
plugins/Toolbox/resources/qml/ToolboxCompatibilityChart.qml

@@ -0,0 +1,108 @@
+// Copyright (c) 2018 Ultimaker B.V.
+// Toolbox is released under the terms of the LGPLv3 or higher.
+
+import QtQuick 2.2
+import QtQuick.Controls 1.4
+import QtQuick.Controls.Styles 1.4
+import UM 1.1 as UM
+
+Item
+{
+    anchors.topMargin: UM.Theme.getSize("default_margin").height
+    height: visible ? childrenRect.height : 0
+    visible: packageData.type == "material" && packageData.has_configs
+    Label
+    {
+        id: heading
+        anchors.topMargin: UM.Theme.getSize("default_margin").height
+        width: parent.width
+        text: catalog.i18nc("@label", "Compatibility")
+        wrapMode: Text.WordWrap
+        color: UM.Theme.getColor("text_medium")
+        font: UM.Theme.getFont("medium")
+    }
+    TableView
+    {
+        id: table
+        anchors.top: heading.bottom
+        anchors.topMargin: UM.Theme.getSize("default_margin").height
+        width: parent.width
+        frameVisible: false
+        selectionMode: 0
+        model: packageData.supported_configs
+        headerDelegate: Item
+        {
+            height: UM.Theme.getSize("toolbox_chart_row").height
+            Label
+            {
+                anchors.verticalCenter: parent.verticalCenter
+                elide: styleData.elideMode
+                text: styleData.value
+                color: UM.Theme.getColor("text")
+                font: UM.Theme.getFont("default_bold")
+            }
+            Rectangle
+            {
+                anchors.bottom: parent.bottom
+                height: UM.Theme.getSize("default_lining").height
+                width: parent.width
+                color: "black"
+            }
+        }
+        rowDelegate: Item
+        {
+            height: UM.Theme.getSize("toolbox_chart_row").height
+            Label
+            {
+                anchors.verticalCenter: parent.verticalCenter
+                elide: styleData.elideMode
+                text: styleData.value
+                color: UM.Theme.getColor("text_medium")
+                font: UM.Theme.getFont("default")
+            }
+        }
+        itemDelegate: Item
+        {
+            height: UM.Theme.getSize("toolbox_chart_row").height
+            Label
+            {
+                anchors.verticalCenter: parent.verticalCenter
+                elide: styleData.elideMode
+                text: styleData.value
+                color: UM.Theme.getColor("text_medium")
+                font: UM.Theme.getFont("default")
+            }
+        }
+
+        TableViewColumn
+        {
+            role: "machine"
+            title: "Machine"
+            width: Math.floor(table.width * 0.25)
+        }
+        TableViewColumn
+        {
+            role: "print_core"
+            title: "Print Core"
+            width: Math.floor(table.width * 0.2)
+        }
+        TableViewColumn
+        {
+            role: "build_plate"
+            title: "Build Plate"
+            width: Math.floor(table.width * 0.225)
+        }
+        TableViewColumn
+        {
+            role: "support_material"
+            title: "Support"
+            width: Math.floor(table.width * 0.225)
+        }
+        TableViewColumn
+        {
+            role: "quality"
+            title: "Quality"
+            width: Math.floor(table.width * 0.1)
+        }
+    }
+}

+ 1 - 1
plugins/Toolbox/resources/qml/ToolboxDetailPage.qml

@@ -104,7 +104,7 @@ Item
             spacing: Math.floor(UM.Theme.getSize("narrow_margin").height)
             Label
             {
-                text: details.version
+                text: details.version || catalog.i18nc("@label", "Unknown")
                 font: UM.Theme.getFont("very_small")
                 color: UM.Theme.getColor("text")
             }

+ 4 - 68
plugins/Toolbox/resources/qml/ToolboxDetailTile.qml

@@ -10,6 +10,7 @@ Item
 {
     id: tile
     property bool installed: toolbox.isInstalled(model.id)
+    property var packageData: model
     width: detailList.width - UM.Theme.getSize("wide_margin").width
     height: Math.max(UM.Theme.getSize("toolbox_detail_tile").height, childrenRect.height + UM.Theme.getSize("default_margin").height)
     Item
@@ -158,76 +159,11 @@ Item
         }
     }
 
-    Item
+    ToolboxCompatibilityChart
     {
-        id: supportedConfigsChart
+        id: compatibilityChart
         anchors.top: normalData.bottom
-        anchors.topMargin: UM.Theme.getSize("default_margin").height
-        height: visible ? childrenRect.height : 0
         width: normalData.width
-        visible: model.type == "material" && model.supported_configs.length > 0
-        Label
-        {
-            id: compatibilityHeading
-            anchors.topMargin: UM.Theme.getSize("default_margin").height
-            width: parent.width
-            text: catalog.i18nc("@label", "Compatibility")
-            wrapMode: Text.WordWrap
-            color: UM.Theme.getColor("text_medium")
-            font: UM.Theme.getFont("default")
-        }
-        Column
-        {
-            id: compatibilityLabels
-            anchors
-            {
-                top: compatibilityHeading.bottom
-                topMargin: UM.Theme.getSize("default_margin").height
-                bottomMargin: UM.Theme.getSize("default_margin").height
-            }
-            width: childrenRect.width
-            Label
-            {
-                text: catalog.i18nc("@label", "Machines") + ":"
-                font: UM.Theme.getFont("small")
-            }
-            Label
-            {
-                text: catalog.i18nc("@label", "Print Cores") + ":"
-                font: UM.Theme.getFont("small")
-            }
-            Label
-            {
-                text: catalog.i18nc("@label", "Quality Profiles") + ":"
-                font: UM.Theme.getFont("small")
-            }
-        }
-        Column
-        {
-            id: compatibilityValues
-            anchors
-            {
-                left: compatibilityLabels.right
-                leftMargin: UM.Theme.getSize("default_margin").height
-                top: compatibilityLabels.top
-                bottom: compatibilityLabels.bottom
-            }
-            Label
-            {
-                text: "Thingy"
-                font: UM.Theme.getFont("very_small")
-            }
-            Label
-            {
-                text: "Thingy"
-                font: UM.Theme.getFont("very_small")
-            }
-            Label
-            {
-                text: "Thingy"
-                font: UM.Theme.getFont("very_small")
-            }
-        }
     }
 
     Rectangle
@@ -235,7 +171,7 @@ Item
         color: UM.Theme.getColor("lining")
         width: tile.width
         height: UM.Theme.getSize("default_lining").height
-        anchors.top: supportedConfigsChart.bottom
+        anchors.top: compatibilityChart.bottom
         anchors.topMargin: UM.Theme.getSize("default_margin").height + UM.Theme.getSize("wide_margin").height //Normal margin for spacing after chart, wide margin between items.
     }
     Connections

+ 37 - 0
plugins/Toolbox/src/ConfigsModel.py

@@ -0,0 +1,37 @@
+# Copyright (c) 2018 Ultimaker B.V.
+# Cura is released under the terms of the LGPLv3 or higher.
+
+import re
+from typing import Dict
+from PyQt5.QtCore import Qt, pyqtProperty
+from UM.Qt.ListModel import ListModel
+
+##  Model that holds supported configurations (for material/quality packages).
+class ConfigsModel(ListModel):
+    def __init__(self, parent = None):
+        super().__init__(parent)
+
+        self._configs = None
+
+        self.addRoleName(Qt.UserRole + 1, "machine")
+        self.addRoleName(Qt.UserRole + 2, "print_core")
+        self.addRoleName(Qt.UserRole + 3, "build_plate")
+        self.addRoleName(Qt.UserRole + 4, "support_material")
+        self.addRoleName(Qt.UserRole + 5, "quality")
+
+    def setConfigs(self, configs):
+        self._configs = configs
+        self._update()
+
+    def _update(self):
+        items = []
+        for item in self._configs:
+            items.append({
+                "machine":          item["machine"],
+                "print_core":       item["print_core"],
+                "build_plate":      item["build_plate"],
+                "support_material": item["support_material"],
+                "quality":          item["quality"]
+            })
+
+        self.setItems(items)

+ 15 - 4
plugins/Toolbox/src/PackagesModel.py

@@ -5,9 +5,8 @@ import re
 from typing import Dict
 
 from PyQt5.QtCore import Qt, pyqtProperty
-
 from UM.Qt.ListModel import ListModel
-
+from .ConfigsModel import ConfigsModel
 
 ##  Model that holds cura packages. By setting the filter property the instances held by this model can be changed.
 class PackagesModel(ListModel):
@@ -29,7 +28,8 @@ class PackagesModel(ListModel):
         self.addRoleName(Qt.UserRole + 11, "download_url")
         self.addRoleName(Qt.UserRole + 12, "last_updated")
         self.addRoleName(Qt.UserRole + 13, "is_bundled")
-        self.addRoleName(Qt.UserRole + 14, "supported_configs")
+        self.addRoleName(Qt.UserRole + 14, "has_configs")
+        self.addRoleName(Qt.UserRole + 15, "supported_configs")
 
         # List of filters for queries. The result is the union of the each list of results.
         self._filter = {}  # type: Dict[str, str]
@@ -42,6 +42,16 @@ class PackagesModel(ListModel):
         items = []
 
         for package in self._metadata:
+
+            has_configs = False
+            configs_model = None
+            if "data" in package:
+                if "supported_configs" in package["data"]:
+                    if len(package["data"]["supported_configs"]) > 0:
+                        has_configs = True
+                        configs_model = ConfigsModel()
+                        configs_model.setConfigs(package["data"]["supported_configs"])
+
             items.append({
                 "id":                package["package_id"],
                 "type":              package["package_type"],
@@ -56,7 +66,8 @@ class PackagesModel(ListModel):
                 "download_url":      package["download_url"] if "download_url" in package else None,
                 "last_updated":      package["last_updated"] if "last_updated" in package else None,
                 "is_bundled":        package["is_bundled"] if "is_bundled" in package else False,
-                "supported_configs": package["supported_configs"] if "supported_configs" in package else []
+                "has_configs":       has_configs,
+                "supported_configs": configs_model
             })
 
         # Filter on all the key-word arguments.

+ 2 - 0
plugins/Toolbox/src/Toolbox.py

@@ -21,6 +21,7 @@ from UM.Version import Version
 from cura.CuraApplication import CuraApplication
 from .AuthorsModel import AuthorsModel
 from .PackagesModel import PackagesModel
+from .ConfigsModel import ConfigsModel
 
 i18n_catalog = i18nCatalog("cura")
 
@@ -373,6 +374,7 @@ class Toolbox(QObject, Extension):
                             # one is because there are not separate API calls
                             # for different kinds of showcases.
                             self._metadata[type] = json_data["data"]
+                            print(json_data["data"])
                             self._models[type].setMetadata(self._metadata[type])
 
                         # Do some auto filtering

+ 2 - 1
resources/themes/cura-light/theme.json

@@ -459,6 +459,7 @@
         "toolbox_heading_label": [1.0, 4.0],
         "toolbox_header": [1.0, 4.0],
         "toolbox_action_button": [8.0, 2.5],
-        "toolbox_progress_bar": [8.0, 0.5]
+        "toolbox_progress_bar": [8.0, 0.5],
+        "toolbox_chart_row": [1.0, 2.0]
     }
 }