Commit 9ed4cc24 authored by Volker Krause's avatar Volker Krause
Browse files

Validate postal codes in the place editor

parent 31543e99
......@@ -4,13 +4,14 @@
SPDX-License-Identifier: LGPL-2.0-or-later
*/
import QtQuick 2.5
import QtQuick.Layouts 1.1
import QtQuick.Controls 2.1 as QQC2
import QtQuick 2.15
import QtQuick.Layouts 1.15
import QtQuick.Controls 2.15 as QQC2
import QtLocation 5.15 as QtLocation
import QtPositioning 5.15
import org.kde.kirigami 2.17 as Kirigami
import org.kde.i18n.localeData 1.0
import org.kde.contacts 1.0
import org.kde.kitinerary 1.0
import org.kde.itinerary 1.0
import "." as App
......@@ -67,6 +68,21 @@ Kirigami.FormLayout {
id: postalCode
Kirigami.FormData.label: ("Postal Code:")
text: place.address.postalCode
readonly property string format: AddressFormatRepository.formatForCountry(addressCountry.currentValue, KContacts.AddressFormatScriptPreference.Local).postalCodeRegularExpression
readonly property bool validFormat: text.match('^' + format + '$')
Kirigami.Icon {
source: postalCode.validFormat ? "dialog-ok" : "dialog-warning"
isMask: true
color: postalCode.validFormat ? Kirigami.Theme.positiveTextColor : Kirigami.Theme.neutralTextColor
visible: postalCode.text && postalCode.format
height: Kirigami.Units.iconSizes.small
width: height
anchors.right: parent.right
anchors.rightMargin: Kirigami.Units.smallSpacing
anchors.verticalCenter: parent.verticalCenter
}
}
QQC2.TextField {
......
......@@ -60,6 +60,7 @@
#if HAVE_KCRASH
#include <KCrash>
#endif
#include <KContacts/AddressFormat>
#include <QQuickStyle>
#include <QQmlApplicationEngine>
......@@ -82,6 +83,20 @@
#include <QIcon>
#include <QWindow>
void registerKContactsTypes()
{
// ### this should move into a real QML plugin for KContacts
qmlRegisterUncreatableMetaObject(KContacts::staticMetaObject, "org.kde.contacts", 1, 0, "KContacts", {});
qmlRegisterSingletonType("org.kde.contacts", 1, 0, "AddressFormatRepository", [](QQmlEngine *, QJSEngine *jsEngine) -> QJSValue {
return jsEngine->toScriptValue(KContacts::AddressFormatRepository());
});
qRegisterMetaType<KContacts::AddressFormat>();
qRegisterMetaType<KContacts::AddressFormatElement>();
qRegisterMetaType<KContacts::AddressFormatRepository>();
qRegisterMetaType<KContacts::AddressFormatPreference>();
qRegisterMetaType<KContacts::AddressFormatScriptPreference>();
}
void registerKPkPassTypes()
{
qmlRegisterUncreatableType<KPkPass::Barcode>("org.kde.pkpass", 1, 0, "Barcode", {});
......@@ -346,6 +361,7 @@ int main(int argc, char **argv)
});
#endif
registerKContactsTypes();
registerKPkPassTypes();
registerKItineraryTypes();
registerApplicationTypes();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment