Warning, /pim/itinerary/src/app/CountryComboBox.qml is written in an unsupported language. File is not indexed.

0001 /*
0002     SPDX-FileCopyrightText: 2021-2022 Volker Krause <vkrause@kde.org>
0003     SPDX-License-Identifier: LGPL-2.0-or-later
0004 */
0005 
0006 import QtQuick
0007 import QtQuick.Controls as QQC2
0008 import org.kde.i18n.localeData
0009 
0010 /** Combo box for showing a list of countries.
0011  *  The model is expected to be an array of ISO 3166-1 alpha 2 codes.
0012  */
0013 QQC2.ComboBox {
0014     id: root
0015 
0016     /** The currently selected country, as a KCountry object. */
0017     readonly property var currentCountry: Country.fromAlpha2(currentValue)
0018 
0019     /** Initially selected country. */
0020     property string initialCountry
0021 
0022    onModelChanged: {
0023        model = model.sort((lhs, rhs) => { return Country.fromAlpha2(lhs).name.localeCompare(Country.fromAlpha2(rhs).name); });
0024    }
0025 
0026     displayText: currentCountry ? (currentCountry.emojiFlag + ' ' + currentCountry.name) : ""
0027 
0028     delegate: QQC2.ItemDelegate {
0029         id: delegate
0030         text: {
0031             const c = Country.fromAlpha2(modelData);
0032             return c.emojiFlag + ' ' + c.name;
0033         }
0034         width: parent ? parent.width : undefined
0035 
0036         Accessible.name: Country.fromAlpha2(modelData).name
0037         Accessible.onPressAction: delegate.clicked()
0038     }
0039 
0040     Component.onCompleted: {
0041         if (initialCountry) {
0042             currentIndex = indexOfValue(initialCountry);
0043         }
0044     }
0045 
0046     Accessible.name: currentCountry.name
0047     Accessible.description: i18n("Select country")
0048     Accessible.onPressAction: root.popup.open()
0049 }