From cd9f2b9e93d9b19e5f0fbb06e0a4e698d2c75513 Mon Sep 17 00:00:00 2001 From: "tatiana.novikova" <tatiana.novikova@demlabs.net> Date: Tue, 3 Mar 2020 13:29:14 +0300 Subject: [PATCH] [+] Add ability to append the default data to the beginning of model --- widgets/DapComboBox.qml | 12 ++++++++++++ widgets/DapComboBoxForm.ui.qml | 8 +++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/widgets/DapComboBox.qml b/widgets/DapComboBox.qml index 67452ec..b147f40 100644 --- a/widgets/DapComboBox.qml +++ b/widgets/DapComboBox.qml @@ -3,6 +3,18 @@ import QtQuick.Controls 2.0 DapComboBoxForm { + Component.onCompleted: + { + if(isDefaultNeedToAppend && model.get(0, comboBoxTextRole[0]) !== mainLineText) + { + if(comboBoxTextRole[0] === "name") + model.insert(0, {name: mainLineText}); + else if(comboBoxTextRole[0] === "text") + model.insert(0, {text: mainLineText}); + currentIndex = 0; + } + } + delegate: ItemDelegate { diff --git a/widgets/DapComboBoxForm.ui.qml b/widgets/DapComboBoxForm.ui.qml index fab312f..dfc27dc 100644 --- a/widgets/DapComboBoxForm.ui.qml +++ b/widgets/DapComboBoxForm.ui.qml @@ -84,6 +84,8 @@ ComboBox property var mainRow: [""] //@detalis mainLineText Text without unneccesary part. property string mainLineText + ///@details isDefaultNeedToAppend Sign to add default data to the beginning of model + property bool isDefaultNeedToAppend: false width: popup.visible ? widthPopupComboBoxActive : widthPopupComboBoxNormal @@ -134,8 +136,12 @@ ComboBox Text { anchors.verticalCenter: parent.verticalCenter - text: (popup.visible) ? + /*text: (popup.visible) ? (index < mainRow.length ? mainRow[index] : ""): + mainLineText*/ + + text: (popup.visible) ? + (dapComboBox.currentIndex === -1 ? mainLineText : (index < mainRow.length ? mainRow[index] : "") ) : mainLineText font: popup.visible ? ((fontComboBox.length > index) ? -- GitLab