{"id":472,"date":"2010-11-22T18:31:13","date_gmt":"2010-11-22T18:31:13","guid":{"rendered":"http:\/\/realnorth.net\/blog\/?p=472"},"modified":"2013-07-05T23:43:11","modified_gmt":"2013-07-06T02:43:11","slug":"master-details-view-qml","status":"publish","type":"post","link":"https:\/\/realnorth.net\/blog\/master-details-view-qml\/","title":{"rendered":"Master Details View con QML"},"content":{"rendered":"<p>Lo bueno de QML es que permite que casos de uso como una simple vista Maestro Detalle pueda ser mejorada agregando animaciones y layouts personalizados con muy poco esfuerzo.<\/p>\n<p>El ejemplo a implementar es muy simple, vamos a usar un archivo XML como data source y para presentar los datos vamos a usar un <a href=\"http:\/\/doc.qt.nokia.com\/4.7-snapshot\/qml-gridview.html\" target=\"_blank\">GridView<\/a> en donde seleccionaremos el item a mostrar en en el <a href=\"http:\/\/doc.qt.nokia.com\/4.7-snapshot\/qml-listview.html\" target=\"_blank\">ListView<\/a> que hace las veces de details view.<\/p>\n<p>La acci\u00f3n central ocurren en el delegate usado para poblar el <a href=\"http:\/\/doc.qt.nokia.com\/4.7-snapshot\/qml-gridview.html\" target=\"_blank\">GridView<\/a> el cual espera a que se haga click en alguno de los items, para pasar el index al <a href=\"http:\/\/doc.qt.nokia.com\/4.7-snapshot\/qml-listview.html\" target=\"_blank\">ListView<\/a> y disparar la animaci\u00f3n que remueve el <a href=\"http:\/\/doc.qt.nokia.com\/4.7-snapshot\/qml-gridview.html\" target=\"_blank\">GridView<\/a> de la escena para cambiar la opacidad del <a href=\"http:\/\/doc.qt.nokia.com\/4.7-snapshot\/qml-listview.html\" target=\"_blank\">ListView<\/a> de 0 a 1 para poder hacerlo visible, por ultimo hay en elemento <a href=\"http:\/\/doc.qt.nokia.com\/4.7-snapshot\/qml-text.html\" target=\"_blank\">Text<\/a> que har\u00e1 de bot\u00f3n para volver a la vista original. <\/p>\n<pre>\r\nimport Qt 4.7\r\n\r\nRectangle {\r\n    width: 360\r\n    height: 640\r\n    id:container\r\n\r\n    XmlListModel {\r\n        id: oranjeModel\r\n        source: &quot;http:\/\/localhost:3002\/players.xml&quot;\r\n        query: &quot;\/players\/player&quot;\r\n        XmlRole {\r\n            name: &quot;name&quot;\r\n            query: &quot;name\/string()&quot;\r\n        }\r\n        XmlRole {\r\n            name: &quot;number&quot;\r\n            query: &quot;number\/string()&quot;\r\n        }\r\n        XmlRole {\r\n            name: &quot;position&quot;\r\n            query: &quot;position\/string()&quot;\r\n        }\r\n        XmlRole {\r\n            name: &quot;picture&quot;\r\n            query: &quot;picture\/string()&quot;\r\n        }\r\n        XmlRole {\r\n            name: &quot;bio&quot;\r\n            query: &quot;bio\/string()&quot;\r\n        }\r\n    }\r\n\r\n    Component {\r\n        id: oranjeDelegate\r\n        Item {\r\n            width: 80\r\n            height: 110\r\n            Image {\r\n                source: picture\r\n                width: parent.width\r\n                height: parent.height\r\n                fillMode: &quot;Stretch&quot;\r\n                opacity: 0.5\r\n            }\r\n            MouseArea {\r\n                anchors.fill: parent\r\n                focus: true\r\n                onClicked: {\r\n                    oranjeDetails.currentIndex = index\r\n                    container.state = &quot;detailsView&quot;\r\n                }\r\n            }\r\n        }\r\n    }\r\n\r\n    Component {\r\n        id: oranjeDetailsDelegate\r\n        Grid {\r\n            rows: 3\r\n            spacing: 6\r\n\r\n            Row {\r\n                Image {\r\n                    source: picture\r\n                    width: 160\r\n                    height: 230\r\n                    fillMode: &quot;Stretch&quot;\r\n                }\r\n\r\n                Column {\r\n                    Text {\r\n                        text: number\r\n                        font.pointSize: 24\r\n                    }\r\n                    Text {\r\n                        text: name\r\n                        font.pointSize: 18\r\n                    }\r\n                    Text {\r\n                        text: position\r\n                        font.pointSize: 14\r\n                    }\r\n                }\r\n            }\r\n\r\n            Row {\r\n                Text {\r\n                    text: bio\r\n                    font.pointSize: 8\r\n                    width: container.width\r\n                    wrapMode: &quot;Wrap&quot;\r\n                }\r\n            }\r\n\r\n            Row {\r\n                Text {\r\n                    text: &quot;Back&quot;\r\n                    font.pointSize: 12\r\n                    color: &quot;#ed1e24&quot;\r\n                    width: container.width\r\n                    MouseArea {\r\n                        anchors.fill: parent\r\n                        onClicked: container.state = &quot;&quot;\r\n                    }\r\n                }\r\n            }\r\n\r\n        }\r\n    }\r\n\r\n    GridView {\r\n        id: oranjeList\r\n        model: oranjeModel\r\n        delegate: oranjeDelegate\r\n        width: container.width\r\n        height: container.height\r\n        cellWidth:90\r\n        cellHeight: 120\r\n    }\r\n\r\n    ListView{\r\n        id: oranjeDetails\r\n        model: oranjeModel\r\n        delegate: oranjeDetailsDelegate\r\n        opacity: 0\r\n    }\r\n\r\n    states: [\r\n        State {\r\n            name: &quot;detailsView&quot;\r\n            PropertyChanges {\r\n                target: oranjeList\r\n                x: -container.width\r\n            }\r\n        }\r\n    ]\r\n\r\n    transitions: [\r\n        Transition {\r\n            from: &quot;&quot;\r\n            to: &quot;detailsView&quot;\r\n            NumberAnimation {\r\n                properties: &quot;x&quot;\r\n                easing.type: &quot;OutBounce&quot;\r\n            }\r\n            PropertyAnimation {\r\n                target: oranjeDetails\r\n                property: &quot;opacity&quot;\r\n                to: 1\r\n            }\r\n        },\r\n        Transition {\r\n            from: &quot;detailsView&quot;\r\n            to: &quot;&quot;\r\n            NumberAnimation {\r\n                properties: &quot;x&quot;\r\n                easing.type: &quot;OutSine&quot;\r\n                duration: 250\r\n            }\r\n            PropertyAnimation {\r\n                target: oranjeDetails\r\n                property: &quot;opacity&quot;\r\n                to: 0\r\n            }\r\n        }\r\n    ]\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Lo bueno de QML es que permite que casos de uso como una simple vista Maestro Detalle pueda ser mejorada agregando animaciones y layouts personalizados con muy poco esfuerzo. El ejemplo a implementar es muy simple, vamos a usar un archivo XML como data source y para presentar los datos vamos a usar un GridView [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7,9],"tags":[43,44,46],"class_list":["post-472","post","type-post","status-publish","format-standard","hentry","category-development","category-ui","tag-qml","tag-qt","tag-qt-quick"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/realnorth.net\/blog\/wp-json\/wp\/v2\/posts\/472","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/realnorth.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/realnorth.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/realnorth.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/realnorth.net\/blog\/wp-json\/wp\/v2\/comments?post=472"}],"version-history":[{"count":1,"href":"https:\/\/realnorth.net\/blog\/wp-json\/wp\/v2\/posts\/472\/revisions"}],"predecessor-version":[{"id":2272,"href":"https:\/\/realnorth.net\/blog\/wp-json\/wp\/v2\/posts\/472\/revisions\/2272"}],"wp:attachment":[{"href":"https:\/\/realnorth.net\/blog\/wp-json\/wp\/v2\/media?parent=472"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/realnorth.net\/blog\/wp-json\/wp\/v2\/categories?post=472"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/realnorth.net\/blog\/wp-json\/wp\/v2\/tags?post=472"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}