Warning, /multimedia/kid3/src/qml/app/MapEditPage.qml is written in an unsupported language. File is not indexed.
0001 /** 0002 * \file MapEditPage.qml 0003 * Page to edit a string->string map. 0004 * 0005 * \b Project: Kid3 0006 * \author Urs Fleisch 0007 * \date 8 Mar 2019 0008 * 0009 * Copyright (C) 2019 Urs Fleisch 0010 * 0011 * This program is free software; you can redistribute it and/or modify 0012 * it under the terms of the GNU Lesser General Public License as published by 0013 * the Free Software Foundation; version 3. 0014 * 0015 * This program is distributed in the hope that it will be useful, 0016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0018 * GNU Lesser General Public License for more details. 0019 * 0020 * You should have received a copy of the GNU Lesser General Public License 0021 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0022 */ 0023 0024 import QtQuick 2.11 0025 import QtQuick.Layouts 1.11 0026 import QtQuick.Controls 2.4 0027 0028 StringListEditPage { 0029 id: page 0030 0031 readonly property string mapSeparator: String.fromCharCode(0x00a0) + 0032 String.fromCharCode(0x2192) + String.fromCharCode(0x00a0) 0033 0034 editDialog: keyValueEditDialog 0035 0036 function addElement(element) { 0037 // Insert in sorted order 0038 var idx = 0 0039 while (idx < model.count && 0040 model.get(idx).name < element.name) { 0041 ++idx 0042 } 0043 model.insert(idx, element) 0044 currentIndex = idx 0045 } 0046 0047 function setElements(map) { 0048 model.clear() 0049 for (var i = 0, len = map.length; i < len - 1; i += 2) { 0050 model.append({"name": map[i] + mapSeparator + map[i + 1]}) 0051 } 0052 } 0053 0054 function getElements() { 0055 var map = [] 0056 for (var i = 0; i < model.count; i++) { 0057 var s = model.get(i).name 0058 var sepPos = s.indexOf(mapSeparator) 0059 if (sepPos !== -1) { 0060 map.push(s.substring(0, sepPos), 0061 s.substring(sepPos + mapSeparator.length)) 0062 } 0063 } 0064 return map 0065 } 0066 0067 Dialog { 0068 id: keyValueEditDialog 0069 0070 signal completed(bool ok) 0071 0072 function setElement(element) { 0073 var text = element.name 0074 var keyValue = text.split(mapSeparator) 0075 keyLineEdit.text = keyValue[0] 0076 valueLineEdit.text = keyValue[1] || "" 0077 } 0078 0079 function getElement() { 0080 return {name: keyLineEdit.text + mapSeparator + valueLineEdit.text} 0081 } 0082 0083 modal: true 0084 width: Math.min(parent.width, constants.gu(70)) 0085 x: (parent.width - width) / 2 0086 y: 0 0087 standardButtons: Dialog.Ok | Dialog.Cancel 0088 0089 RowLayout { 0090 width: parent.width 0091 TextField { 0092 id: keyLineEdit 0093 selectByMouse: true 0094 Layout.fillWidth: true 0095 } 0096 Label { 0097 text: mapSeparator 0098 } 0099 TextField { 0100 id: valueLineEdit 0101 selectByMouse: true 0102 Layout.fillWidth: true 0103 } 0104 } 0105 0106 onAccepted: completed(true) 0107 onRejected: completed(false) 0108 } 0109 }