From ac85a2bbc1d1ca4efec30c7fa7869321d5339a35 Mon Sep 17 00:00:00 2001 From: Emil Lundberg Date: Tue, 21 Nov 2017 16:33:48 +0100 Subject: [PATCH] Pass code and credential as properties to CredentialItem instead of modelData --- qml/CredentialItem.qml | 33 +++++++++++++++++---------------- qml/main.qml | 11 ++++++----- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/qml/CredentialItem.qml b/qml/CredentialItem.qml index cdea0f87..fedfadcc 100644 --- a/qml/CredentialItem.qml +++ b/qml/CredentialItem.qml @@ -3,9 +3,10 @@ import QtQuick.Controls 1.4 import QtQuick.Layouts 1.1 Rectangle { + property var code + property var credential property bool expired: true property bool isSelected: false - property var model property color textColor: (isSelected ? palette.highlightedText : palette.windowText @@ -13,8 +14,8 @@ Rectangle { property bool timerRunning: false property color unselectedColor - signal singleClick(var mouse, var entry) - signal doubleClick(var mouse, var entry) + signal singleClick(var mouse) + signal doubleClick(var mouse) signal refresh(bool force) color: { @@ -27,15 +28,15 @@ Rectangle { Layout.minimumHeight: ( 10 + issuerLbl.height + codeLbl.height + nameLbl.height - + (hasCustomTimeBar(model.credential) ? 10 : 0) + + (hasCustomTimeBar(credential) ? 10 : 0) ) Layout.fillWidth: true Layout.alignment: Qt.AlignTop MouseArea { anchors.fill: parent - onClicked: singleClick(mouse, model) - onDoubleClicked: doubleClick(mouse, model) + onClicked: singleClick(mouse) + onDoubleClicked: doubleClick(mouse) acceptedButtons: Qt.RightButton | Qt.LeftButton } @@ -48,31 +49,31 @@ Rectangle { spacing: 0 Label { id: issuerLbl - visible: model.credential.issuer != null - && model.credential.issuer.length > 0 - text: qsTr("") + model.credential.issuer + visible: credential.issuer != null + && credential.issuer.length > 0 + text: qsTr("") + credential.issuer color: textColor } Label { id: codeLbl opacity: expired ? 0.6 : 1 - visible: model.code !== null - text: qsTr("") + getSpacedCredential(model.code && model.code.value) + visible: code !== null + text: qsTr("") + getSpacedCredential(code && code.value) font.pointSize: issuerLbl.font.pointSize * 1.8 color: textColor } Label { id: nameLbl - text: model.credential.name + text: credential.name color: textColor } Timer { interval: 100 repeat: true - running: timerRunning && hasCustomTimeBar(model.credential) + running: timerRunning && hasCustomTimeBar(credential) triggeredOnStart: true onTriggered: { - var timeLeft = model.code.valid_to - (Date.now() / 1000) + var timeLeft = code.valid_to - (Date.now() / 1000) if (timeLeft <= 0 && customTimeLeftBar.value > 0) { refresh(true) } @@ -81,13 +82,13 @@ Rectangle { } ProgressBar { id: customTimeLeftBar - visible: hasCustomTimeBar(model.credential) + visible: hasCustomTimeBar(credential) Layout.topMargin: 3 Layout.fillWidth: true Layout.minimumHeight: 7 Layout.maximumHeight: 7 Layout.alignment: Qt.AlignBottom - maximumValue: model.credential.period || 0 + maximumValue: credential.period || 0 rotation: 180 } } diff --git a/qml/main.qml b/qml/main.qml index 6add647c..293bfdd0 100644 --- a/qml/main.qml +++ b/qml/main.qml @@ -275,9 +275,10 @@ ApplicationWindow { model: filteredCredentials(credentials) CredentialItem { + code: modelData.code + credential: modelData.credential expired: isExpired(modelData) isSelected: selected != null && selected.credential.key === modelData.credential.key - model: modelData timerRunning: displayTimersRunning unselectedColor: { if (index % 2 == 0) { @@ -292,7 +293,7 @@ ApplicationWindow { // A double-click should select the credential, // then generate if needed and copy the code. - selectCredential(entry, index) + selectCredential(modelData, index) generateOrCopy() } @@ -303,16 +304,16 @@ ApplicationWindow { // Left click, select or deselect credential. if (mouse.button & Qt.LeftButton) { - if (selected != null && selected.credential.key === entry.credential.key) { + if (selected != null && selected.credential.key === credential.key) { deselectCredential() } else { - selectCredential(entry, index) + selectCredential(modelData, index) } } // Right-click, select credential and open popup menu. if (mouse.button & Qt.RightButton) { - selectCredential(entry, index) + selectCredential(modelData, index) credentialMenu.popup() } }