Warning, /frameworks/kcontacts/tests/qmlintegrationtest.qml is written in an unsupported language. File is not indexed.

0001 /*
0002     SPDX-FileCopyrightText: 2022 Volker Krause <vkrause@kde.org>
0003     SPDX-License-Identifier: LGPL-2.0-or-later
0004 */
0005 
0006 import QtQuick 2.15
0007 import QtQuick.Controls 2.15
0008 import QtQuick.Layouts 1.15
0009 import org.kde.i18n.localeData 1.0
0010 import org.kde.contacts 1.0
0011 import org.kde.contacts.test 1.0
0012 
0013 ApplicationWindow {
0014     visible: true
0015     width: 480
0016     height: 720
0017 
0018     ColumnLayout {
0019         ComboBox {
0020             id: styleCombo
0021             textRole: "text"
0022             valueRole: "style"
0023             model: [
0024                 { text: "Postal address", style: KContacts.AddressFormatStyle.Postal },
0025                 { text: "Multiple lines, domestic", style: KContacts.AddressFormatStyle.MultiLineDomestic },
0026                 { text: "Multiple lines, international", style: KContacts.AddressFormatStyle.MultiLineInternational },
0027                 { text: "Single line, domestic", style: KContacts.AddressFormatStyle.SingleLineDomestic },
0028                 { text: "Single line, international", style: KContacts.AddressFormatStyle.SingleLineInternational }
0029             ]
0030         }
0031 
0032         Label {
0033             text: TestData.address.formatted(styleCombo.currentValue, "Dr. Konqi", "KDE e.V.")
0034         }
0035 
0036         ComboBox {
0037             id: countryCombo
0038             model: Country.allCountries.map(c => c.alpha2)
0039         }
0040 
0041         Label {
0042             id: zipFormat
0043             text: AddressFormatRepository.formatForCountry(countryCombo.currentValue, KContacts.AddressFormatScriptPreference.Local).postalCodeRegularExpression
0044         }
0045         TextField {
0046             id: zipField
0047             text: "12345"
0048         }
0049         Label {
0050             text: zipField.text.match("^" + zipFormat.text + "$") ? "is a valid zip code" : "is not a valid zip code"
0051         }
0052 
0053         Label {
0054             text: "Formatting rule:"
0055         }
0056         Repeater {
0057             model: AddressFormatRepository.formatForCountry(countryCombo.currentValue, KContacts.AddressFormatScriptPreference.Local, KContacts.AddressFormatPreference.Business).elements
0058             Label {
0059                 text: {
0060                     const field_map = new Map([
0061                         [ KContacts.AddressFormatField.Name, "Name" ],
0062                         [ KContacts.AddressFormatField.Organization, "Organization" ],
0063                         [ KContacts.AddressFormatField.StreetAddress, "Street" ],
0064                         [ KContacts.AddressFormatField.Locality, "City" ],
0065                         [ KContacts.AddressFormatField.DependentLocality, "Dependent Locality" ],
0066                         [ KContacts.AddressFormatField.PostOfficeBox, "PO Box" ],
0067                         [ KContacts.AddressFormatField.Country, "Country" ],
0068                         [ KContacts.AddressFormatField.Region, "State" ],
0069                         [ KContacts.AddressFormatField.SortingCode, "Sorting Code" ],
0070                         [ KContacts.AddressFormatField.PostalCode, "Zip Code" ],
0071                     ]);
0072                     if (modelData.isField) { return "Field: " + field_map.get(modelData.field); }
0073                     if (modelData.isLiteral) { return "Literal: \"" + modelData.literal + "\""; }
0074                     if (modelData.isSeparator) { return "Separator"; }
0075                 }
0076                 font.bold: AddressFormatRepository.formatForCountry(countryCombo.currentValue, KContacts.AddressFormatScriptPreference.LatinScript).requiredFields & modelData.field
0077             }
0078         }
0079 
0080         Label {
0081             text: "Emails: " + TestData.addressee.emails.map(x => x.email).join(", ")
0082         }
0083         Label {
0084             text: "Address 1: " + TestData.addressee.addresses[0].formattedAddress
0085         }
0086     }
0087 }