From a18034f1b208e721abdff3050e2606d99a6e9971 Mon Sep 17 00:00:00 2001 From: Nicolas Fella Date: Tue, 1 Oct 2024 18:16:17 +0200 Subject: [PATCH] Add QLocale --- crates/cxx-qt-lib-extras/build.rs | 2 + .../cxx-qt-lib-extras/include/core/qlocale.h | 28 + crates/cxx-qt-lib-extras/src/core/mod.rs | 6 + crates/cxx-qt-lib-extras/src/core/qlocale.cpp | 17 + crates/cxx-qt-lib-extras/src/core/qlocale.rs | 590 ++++++++++++++++++ crates/cxx-qt-lib/src/core/mod.rs | 6 +- crates/cxx-qt-lib/src/core/qt.rs | 16 +- tests/qt_types_standalone/CMakeLists.txt | 1 + tests/qt_types_standalone/cpp/main.cpp | 2 + tests/qt_types_standalone/cpp/qlocale.h | 31 + tests/qt_types_standalone/rust/Cargo.toml | 1 + tests/qt_types_standalone/rust/build.rs | 1 + tests/qt_types_standalone/rust/src/lib.rs | 1 + tests/qt_types_standalone/rust/src/qlocale.rs | 27 + 14 files changed, 724 insertions(+), 5 deletions(-) create mode 100644 crates/cxx-qt-lib-extras/include/core/qlocale.h create mode 100644 crates/cxx-qt-lib-extras/src/core/qlocale.cpp create mode 100644 crates/cxx-qt-lib-extras/src/core/qlocale.rs create mode 100644 tests/qt_types_standalone/cpp/qlocale.h create mode 100644 tests/qt_types_standalone/rust/src/qlocale.rs diff --git a/crates/cxx-qt-lib-extras/build.rs b/crates/cxx-qt-lib-extras/build.rs index 7900a3c81..acc497b24 100644 --- a/crates/cxx-qt-lib-extras/build.rs +++ b/crates/cxx-qt-lib-extras/build.rs @@ -56,6 +56,7 @@ fn main() { "core/qelapsedtimer", "core/qcommandlineoption", "core/qcommandlineparser", + "core/qlocale", "gui/qapplication", ]; @@ -67,6 +68,7 @@ fn main() { "core/qelapsedtimer", "core/qcommandlineoption", "core/qcommandlineparser", + "core/qlocale", "gui/qapplication", ]; diff --git a/crates/cxx-qt-lib-extras/include/core/qlocale.h b/crates/cxx-qt-lib-extras/include/core/qlocale.h new file mode 100644 index 000000000..64eee25e8 --- /dev/null +++ b/crates/cxx-qt-lib-extras/include/core/qlocale.h @@ -0,0 +1,28 @@ +// clang-format off +// SPDX-FileCopyrightText: 2024 Klarälvdalens Datakonsult AB, a KDAB Group company +// clang-format on +// SPDX-FileContributor: Nicolas Fella +// +// SPDX-License-Identifier: MIT OR Apache-2.0 +#pragma once + +#include + +#include "rust/cxx.h" + +namespace rust { + +template<> +struct IsRelocatable : ::std::true_type +{}; + +namespace cxxqtlib1 { + +using QLocaleTagSeparator = QLocale::TagSeparator; +using QLocaleCurrencySymbolFormat = QLocale::CurrencySymbolFormat; +using QLocaleFormatType = QLocale::FormatType; +using QLocaleLanguage = QLocale::Language; +using QLocaleMeasurementSystem = QLocale::MeasurementSystem; + +} +} diff --git a/crates/cxx-qt-lib-extras/src/core/mod.rs b/crates/cxx-qt-lib-extras/src/core/mod.rs index 5a4723091..bdabeec31 100644 --- a/crates/cxx-qt-lib-extras/src/core/mod.rs +++ b/crates/cxx-qt-lib-extras/src/core/mod.rs @@ -11,3 +11,9 @@ pub use qcommandlineoption::QCommandLineOption; mod qcommandlineparser; pub use qcommandlineparser::QCommandLineParser; + +mod qlocale; +pub use qlocale::{ + QLocale, QLocaleCurrencySymbolFormat, QLocaleFormatType, QLocaleLanguage, + QLocaleMeasurementSystem, QLocaleTagSeparator, +}; diff --git a/crates/cxx-qt-lib-extras/src/core/qlocale.cpp b/crates/cxx-qt-lib-extras/src/core/qlocale.cpp new file mode 100644 index 000000000..a7ca0b4de --- /dev/null +++ b/crates/cxx-qt-lib-extras/src/core/qlocale.cpp @@ -0,0 +1,17 @@ +// clang-format off +// SPDX-FileCopyrightText: 2024 Klarälvdalens Datakonsult AB, a KDAB Group company +// clang-format on +// SPDX-FileContributor: Nicolas Fella +// +// SPDX-License-Identifier: MIT OR Apache-2.0 +#include "cxx-qt-lib-extras/qlocale.h" +#include + +assert_alignment_and_size(QLocale, { ::std::size_t a0; }); + +static_assert(!::std::is_trivially_copy_assignable::value); +static_assert(!::std::is_trivially_copy_constructible::value); + +static_assert(!::std::is_trivially_destructible::value); + +static_assert(QTypeInfo::isRelocatable); diff --git a/crates/cxx-qt-lib-extras/src/core/qlocale.rs b/crates/cxx-qt-lib-extras/src/core/qlocale.rs new file mode 100644 index 000000000..156c558ab --- /dev/null +++ b/crates/cxx-qt-lib-extras/src/core/qlocale.rs @@ -0,0 +1,590 @@ +// SPDX-FileCopyrightText: 2024 Klarälvdalens Datakonsult AB, a KDAB Group company +// SPDX-FileContributor: Nicolas Fella +// +// SPDX-License-Identifier: MIT OR Apache-2.0 + +use cxx::{type_id, ExternType}; +use std::mem::MaybeUninit; + +#[cxx::bridge] +mod ffi { + + #[repr(u8)] + #[namespace = "rust::cxxqtlib1"] + enum QLocaleTagSeparator { + Dash = 45, // - + Underscore = 95, // _ + } + + #[repr(i32)] + #[namespace = "rust::cxxqtlib1"] + enum QLocaleCurrencySymbolFormat { + CurrencyIsoCode, + CurrencySymbol, + CurrencyDisplayName, + } + + #[repr(i32)] + #[namespace = "rust::cxxqtlib1"] + enum QLocaleFormatType { + LongFormat, + ShortFormat, + NarrowFormat, + } + + #[repr(u16)] + #[namespace = "rust::cxxqtlib1"] + enum QLocaleLanguage { + AnyLanguage = 0, + C = 1, + Abkhazian = 2, + Afar = 3, + Afrikaans = 4, + Aghem = 5, + Akan = 6, + Akkadian = 7, + Akoose = 8, + Albanian = 9, + AmericanSignLanguage = 10, + Amharic = 11, + AncientEgyptian = 12, + AncientGreek = 13, + Arabic = 14, + Aragonese = 15, + Aramaic = 16, + Armenian = 17, + Assamese = 18, + Asturian = 19, + Asu = 20, + Atsam = 21, + Avaric = 22, + Avestan = 23, + Aymara = 24, + Azerbaijani = 25, + Bafia = 26, + Balinese = 27, + Bambara = 28, + Bamun = 29, + Bangla = 30, + Basaa = 31, + Bashkir = 32, + Basque = 33, + BatakToba = 34, + Belarusian = 35, + Bemba = 36, + Bena = 37, + Bhojpuri = 38, + Bislama = 39, + Blin = 40, + Bodo = 41, + Bosnian = 42, + Breton = 43, + Buginese = 44, + Bulgarian = 45, + Burmese = 46, + Cantonese = 47, + Catalan = 48, + Cebuano = 49, + CentralAtlasTamazight = 50, + CentralKurdish = 51, + Chakma = 52, + Chamorro = 53, + Chechen = 54, + Cherokee = 55, + Chickasaw = 56, + Chiga = 57, + Chinese = 58, + Church = 59, + Chuvash = 60, + Colognian = 61, + Coptic = 62, + Cornish = 63, + Corsican = 64, + Cree = 65, + Croatian = 66, + Czech = 67, + Danish = 68, + Divehi = 69, + Dogri = 70, + Duala = 71, + Dutch = 72, + Dzongkha = 73, + Embu = 74, + English = 75, + Erzya = 76, + Esperanto = 77, + Estonian = 78, + Ewe = 79, + Ewondo = 80, + Faroese = 81, + Fijian = 82, + Filipino = 83, + Finnish = 84, + French = 85, + Friulian = 86, + Fulah = 87, + Gaelic = 88, + Ga = 89, + Galician = 90, + Ganda = 91, + Geez = 92, + Georgian = 93, + German = 94, + Gothic = 95, + Greek = 96, + Guarani = 97, + Gujarati = 98, + Gusii = 99, + Haitian = 100, + Hausa = 101, + Hawaiian = 102, + Hebrew = 103, + Herero = 104, + Hindi = 105, + HiriMotu = 106, + Hungarian = 107, + Icelandic = 108, + Ido = 109, + Igbo = 110, + InariSami = 111, + Indonesian = 112, + Ingush = 113, + Interlingua = 114, + Interlingue = 115, + Inuktitut = 116, + Inupiaq = 117, + Irish = 118, + Italian = 119, + Japanese = 120, + Javanese = 121, + Jju = 122, + JolaFonyi = 123, + Kabuverdianu = 124, + Kabyle = 125, + Kako = 126, + Kalaallisut = 127, + Kalenjin = 128, + Kamba = 129, + Kannada = 130, + Kanuri = 131, + Kashmiri = 132, + Kazakh = 133, + Kenyang = 134, + Khmer = 135, + Kiche = 136, + Kikuyu = 137, + Kinyarwanda = 138, + Komi = 139, + Kongo = 140, + Konkani = 141, + Korean = 142, + Koro = 143, + KoyraboroSenni = 144, + KoyraChiini = 145, + Kpelle = 146, + Kuanyama = 147, + Kurdish = 148, + Kwasio = 149, + Kyrgyz = 150, + Lakota = 151, + Langi = 152, + Lao = 153, + Latin = 154, + Latvian = 155, + Lezghian = 156, + Limburgish = 157, + Lingala = 158, + LiteraryChinese = 159, + Lithuanian = 160, + Lojban = 161, + LowerSorbian = 162, + LowGerman = 163, + LubaKatanga = 164, + LuleSami = 165, + Luo = 166, + Luxembourgish = 167, + Luyia = 168, + Macedonian = 169, + Machame = 170, + Maithili = 171, + MakhuwaMeetto = 172, + Makonde = 173, + Malagasy = 174, + Malayalam = 175, + Malay = 176, + Maltese = 177, + Mandingo = 178, + Manipuri = 179, + Manx = 180, + Maori = 181, + Mapuche = 182, + Marathi = 183, + Marshallese = 184, + Masai = 185, + Mazanderani = 186, + Mende = 187, + Meru = 188, + Meta = 189, + Mohawk = 190, + Mongolian = 191, + Morisyen = 192, + Mundang = 193, + Muscogee = 194, + Nama = 195, + NauruLanguage = 196, + Navajo = 197, + Ndonga = 198, + Nepali = 199, + Newari = 200, + Ngiemboon = 201, + Ngomba = 202, + NigerianPidgin = 203, + Nko = 204, + NorthernLuri = 205, + NorthernSami = 206, + NorthernSotho = 207, + NorthNdebele = 208, + NorwegianBokmal = 209, + NorwegianNynorsk = 210, + Nuer = 211, + Nyanja = 212, + Nyankole = 213, + Occitan = 214, + Odia = 215, + Ojibwa = 216, + OldIrish = 217, + OldNorse = 218, + OldPersian = 219, + Oromo = 220, + Osage = 221, + Ossetic = 222, + Pahlavi = 223, + Palauan = 224, + Pali = 225, + Papiamento = 226, + Pashto = 227, + Persian = 228, + Phoenician = 229, + Polish = 230, + Portuguese = 231, + Prussian = 232, + Punjabi = 233, + Quechua = 234, + Romanian = 235, + Romansh = 236, + Rombo = 237, + Rundi = 238, + Russian = 239, + Rwa = 240, + Saho = 241, + Sakha = 242, + Samburu = 243, + Samoan = 244, + Sango = 245, + Sangu = 246, + Sanskrit = 247, + Santali = 248, + Sardinian = 249, + Saurashtra = 250, + Sena = 251, + Serbian = 252, + Shambala = 253, + Shona = 254, + SichuanYi = 255, + Sicilian = 256, + Sidamo = 257, + Silesian = 258, + Sindhi = 259, + Sinhala = 260, + SkoltSami = 261, + Slovak = 262, + Slovenian = 263, + Soga = 264, + Somali = 265, + SouthernKurdish = 266, + SouthernSami = 267, + SouthernSotho = 268, + SouthNdebele = 269, + Spanish = 270, + StandardMoroccanTamazight = 271, + Sundanese = 272, + Swahili = 273, + Swati = 274, + Swedish = 275, + SwissGerman = 276, + Syriac = 277, + Tachelhit = 278, + Tahitian = 279, + TaiDam = 280, + Taita = 281, + Tajik = 282, + Tamil = 283, + Taroko = 284, + Tasawaq = 285, + Tatar = 286, + Telugu = 287, + Teso = 288, + Thai = 289, + Tibetan = 290, + Tigre = 291, + Tigrinya = 292, + TokelauLanguage = 293, + TokPisin = 294, + Tongan = 295, + Tsonga = 296, + Tswana = 297, + Turkish = 298, + Turkmen = 299, + TuvaluLanguage = 300, + Tyap = 301, + Ugaritic = 302, + Ukrainian = 303, + UpperSorbian = 304, + Urdu = 305, + Uyghur = 306, + Uzbek = 307, + Vai = 308, + Venda = 309, + Vietnamese = 310, + Volapuk = 311, + Vunjo = 312, + Walloon = 313, + Walser = 314, + Warlpiri = 315, + Welsh = 316, + WesternBalochi = 317, + WesternFrisian = 318, + Wolaytta = 319, + Wolof = 320, + Xhosa = 321, + Yangben = 322, + Yiddish = 323, + Yoruba = 324, + Zarma = 325, + Zhuang = 326, + Zulu = 327, + Kaingang = 328, + Nheengatu = 329, + Haryanvi = 330, + NorthernFrisian = 331, + Rajasthani = 332, + Moksha = 333, + TokiPona = 334, + Pijin = 335, + Obolo = 336, + Baluchi = 337, + Ligurian = 338, + Rohingya = 339, + Torwali = 340, + Anii = 341, + Kangri = 342, + Venetian = 343, + Kuvi = 344, + + Afan = 220, // Oromo, + Bengali = 30, // Bangla, + Bhutani = 73, // Dzongkha, + Byelorussian = 35, // Belarusian, + Cambodian = 135, // Khmer, + CentralMoroccoTamazight = 50, // CentralAtlasTamazight, + Chewa = 212, // Nyanja, + Frisian = 318, // WesternFrisian, + Greenlandic = 127, // Kalaallisut, + Inupiak = 117, // Inupiaq, + Kirghiz = 150, // Kyrgyz, + Kurundi = 238, // Rundi, + Kwanyama = 147, // Kuanyama, + Navaho = 197, // Navajo, + Oriya = 215, // Odia, + RhaetoRomance = 236, // Romansh, + Uighur = 306, // Uyghur, + Uigur = 306, // Uyghur, + Walamo = 319, // Wolaytta, + + LastLanguage = 344, // Kuvi, + } + + #[repr(i32)] + #[namespace = "rust::cxxqtlib1"] + enum QLocaleMeasurementSystem { + MetricSystem = 0, + ImperialUSSystem = 1, + ImperialUKSystem = 2, + ImperialSystem = 1, // ImperialUSSystem + } + + #[namespace = "Qt"] + unsafe extern "C++" { + include!("cxx-qt-lib/qt.h"); + type DayOfWeek = cxx_qt_lib::DayOfWeek; + } + + unsafe extern "C++" { + include!("cxx-qt-lib/qstring.h"); + type QString = cxx_qt_lib::QString; + + include!("cxx-qt-lib/qstringlist.h"); + type QStringList = cxx_qt_lib::QStringList; + + include!("cxx-qt-lib-extras/qlocale.h"); + type QLocale = super::QLocale; + + /// Returns the localized name of the "AM" suffix for times specified using the conventions of the 12-hour clock. + #[rust_name = "am_text"] + fn amText(self: &QLocale) -> QString; + + /// Returns the BCP47 field names joined with dashes. + // QString QLocale::bcp47Name(QLocale::TagSeparator separator = TagSeparator::Dash) const + #[rust_name = "bcp47_name"] + fn bcp47Name(self: &QLocale, separator: QLocaleTagSeparator) -> QString; + + /// Returns the locale to use for collation. + #[rust_name = "collation"] + fn collation(self: &QLocale) -> QLocale; + + #[rust_name = "create_separated_list"] + fn createSeparatedList(self: &QLocale, list: &QStringList) -> QString; + + /// Returns a currency symbol according to the format. + // QString QLocale::currencySymbol(QLocale::CurrencySymbolFormat format = CurrencySymbol) const + #[rust_name = "currency_symbol"] + fn currencySymbol(self: &QLocale, format: QLocaleCurrencySymbolFormat) -> QString; + + /// Returns the date format used for the current locale. + #[rust_name = "date_format"] + fn dateFormat(self: &QLocale, format: QLocaleFormatType) -> QString; + + /// Returns the date time format used for the current locale. + #[rust_name = "date_time_format"] + fn dateTimeFormat(self: &QLocale, format: QLocaleFormatType) -> QString; + + /// Returns the localized name of the day (where 1 represents Monday, 2 represents Tuesday and so on), in the format specified by type. + // QString QLocale::dayName(int day, QLocale::FormatType type = LongFormat) const + #[rust_name = "day_name"] + fn dayName(self: &QLocale, day: i32, formatType: QLocaleFormatType) -> QString; + + /// Returns the fractional part separator for this locale. + #[rust_name = "decimal_point"] + fn decimalPoint(self: &QLocale) -> QString; + + /// Returns the exponent separator for this locale. + #[rust_name = "exponential"] + fn exponential(self: &QLocale) -> QString; + + /// Returns the first day of the week according to the current locale. + // Qt::DayOfWeek QLocale::firstDayOfWeek() const + #[rust_name = "first_day_of_week"] + fn firstDayOfWeek(self: &QLocale) -> DayOfWeek; + + // QString QLocale::formattedDataSize(qint64 bytes, int precision = 2, QLocale::DataSizeFormats format = DataSizeIecFormat) const + + /// Returns the digit-grouping separator for this locale. + #[rust_name = "group_separator"] + fn groupSeparator(self: &QLocale) -> QString; + + /// Returns the language of this locale. + // QLocale::Language QLocale::language() const + #[rust_name = "language"] + fn language(self: &QLocale) -> QLocaleLanguage; + + /// Returns the two- or three-letter language code for language, as defined in the ISO 639 standards. + // QString QLocale::languageToCode(QLocale::Language language, QLocale::LanguageCodeTypes codeTypes = AnyLanguageCode) + + /// Returns a QString containing the name of language. + // static QString QLocale::languageToString(QLocale::Language language) + // #[rust_name = "language_to_string"] + // fn languageToString(language: QLocaleLanguage) -> QString; + + // QList QLocale::matchingLocales(QLocale::Language language, QLocale::Script script, QLocale::Territory territory) + + /// Returns the measurement system for the locale. + // QLocale::MeasurementSystem QLocale::measurementSystem() const + #[rust_name = "measurement_system"] + fn measurementSystem(self: &QLocale) -> QLocaleMeasurementSystem; + + /// Returns the localized name of month, in the format specified by type. + // QString QLocale::monthName(int month, QLocale::FormatType type = LongFormat) const + #[rust_name = "month_name"] + fn monthName(self: &QLocale, month: i32, formatType: QLocaleFormatType) -> QString; + + /// The short name of this locale. + // QString QLocale::name(QLocale::TagSeparator separator = TagSeparator::Underscore) const + #[rust_name = "name"] + fn name(self: &QLocale, separator: QLocaleTagSeparator) -> QString; + + /// Returns a native name of the language for the locale. For example "Schweizer Hochdeutsch" for the Swiss-German locale. + #[rust_name = "native_language_name"] + fn nativeLanguageName(self: &QLocale) -> QString; + + /// Returns a native name of the territory for the locale. For example "España" for Spanish/Spain locale. + #[rust_name = "native_territory_name"] + fn nativeTerritoryName(self: &QLocale) -> QString; + + } + + #[namespace = "rust::cxxqtlib1"] + unsafe extern "C++" { + + type QLocaleTagSeparator; + type QLocaleCurrencySymbolFormat; + type QLocaleFormatType; + type QLocaleLanguage; + type QLocaleMeasurementSystem; + + include!("cxx-qt-lib/common.h"); + + #[doc(hidden)] + #[rust_name = "qlocale_init_default"] + fn construct() -> QLocale; + + #[doc(hidden)] + #[allow(dead_code)] + #[rust_name = "qlocale_init_from_name"] + fn construct(name: &QString) -> QLocale; + + #[doc(hidden)] + #[rust_name = "qlocale_drop"] + fn drop(locale: &mut QLocale); + + #[doc(hidden)] + #[rust_name = "qlocale_init_from_qlocale"] + fn construct(locale: &QLocale) -> QLocale; + } +} + +pub use ffi::QLocaleCurrencySymbolFormat; +pub use ffi::QLocaleFormatType; +pub use ffi::QLocaleLanguage; +pub use ffi::QLocaleMeasurementSystem; +pub use ffi::QLocaleTagSeparator; + +#[repr(C)] +pub struct QLocale { + _cspec: MaybeUninit, +} + +impl Default for QLocale { + fn default() -> Self { + ffi::qlocale_init_default() + } +} + +impl Drop for QLocale { + fn drop(&mut self) { + ffi::qlocale_drop(self) + } +} + +impl Clone for QLocale { + fn clone(&self) -> Self { + ffi::qlocale_init_from_qlocale(self) + } +} + +// Safety: + +// Static checks on the C++ side ensure that QSize is trivial. +unsafe impl ExternType for QLocale { + type Id = type_id!("QLocale"); + type Kind = cxx::kind::Trivial; +} diff --git a/crates/cxx-qt-lib/src/core/mod.rs b/crates/cxx-qt-lib/src/core/mod.rs index a2e9bfa33..0d0315e1f 100644 --- a/crates/cxx-qt-lib/src/core/mod.rs +++ b/crates/cxx-qt-lib/src/core/mod.rs @@ -75,9 +75,9 @@ pub use qstringlist::QStringList; mod qt; pub use qt::{ - AspectRatioMode, BGMode, CaseSensitivity, ClipOperation, ConnectionType, DateFormat, FillRule, - LayoutDirection, PenCapStyle, PenJoinStyle, PenStyle, SizeMode, SplitBehaviorFlags, TimeSpec, - TransformationMode, + AspectRatioMode, BGMode, CaseSensitivity, ClipOperation, ConnectionType, DateFormat, DayOfWeek, + FillRule, LayoutDirection, PenCapStyle, PenJoinStyle, PenStyle, SizeMode, SplitBehaviorFlags, + TimeSpec, TransformationMode, }; mod qtime; diff --git a/crates/cxx-qt-lib/src/core/qt.rs b/crates/cxx-qt-lib/src/core/qt.rs index 3f8398b8e..efbb56ee9 100644 --- a/crates/cxx-qt-lib/src/core/qt.rs +++ b/crates/cxx-qt-lib/src/core/qt.rs @@ -145,11 +145,23 @@ mod ffi { RelativeSize, } + #[repr(i32)] + enum DayOfWeek { + Monday = 1, + Tuesday = 2, + Wednesday = 3, + Thursday = 4, + Friday = 5, + Saturday = 6, + Sunday = 7, + } + unsafe extern "C++" { include!("cxx-qt-lib/qt.h"); type AspectRatioMode; type CaseSensitivity; type DateFormat; + type DayOfWeek; type SplitBehaviorFlags; type TimeSpec; type TransformationMode; @@ -165,8 +177,8 @@ mod ffi { } pub use ffi::{ - AspectRatioMode, BGMode, CaseSensitivity, ClipOperation, DateFormat, FillRule, LayoutDirection, - PenCapStyle, PenJoinStyle, PenStyle, SizeMode, SplitBehaviorFlags, TimeSpec, + AspectRatioMode, BGMode, CaseSensitivity, ClipOperation, DateFormat, DayOfWeek, FillRule, + LayoutDirection, PenCapStyle, PenJoinStyle, PenStyle, SizeMode, SplitBehaviorFlags, TimeSpec, TransformationMode, }; diff --git a/tests/qt_types_standalone/CMakeLists.txt b/tests/qt_types_standalone/CMakeLists.txt index 68e5da39c..e5cbb5e75 100644 --- a/tests/qt_types_standalone/CMakeLists.txt +++ b/tests/qt_types_standalone/CMakeLists.txt @@ -56,6 +56,7 @@ add_executable(${APP_NAME} cpp/qhash.h cpp/qline.h cpp/qlinef.h + cpp/qlocale.h cpp/qlist.h cpp/qmap.h cpp/qmargins.h diff --git a/tests/qt_types_standalone/cpp/main.cpp b/tests/qt_types_standalone/cpp/main.cpp index 76cf83407..6fff59e46 100644 --- a/tests/qt_types_standalone/cpp/main.cpp +++ b/tests/qt_types_standalone/cpp/main.cpp @@ -20,6 +20,7 @@ #include "qhash.h" #include "qline.h" #include "qlinef.h" +#include "qlocale.h" #include "qlist.h" #include "qmap.h" #include "qmargins.h" @@ -75,6 +76,7 @@ main(int argc, char* argv[]) runTest(QScopedPointer(new QHashTest)); runTest(QScopedPointer(new QLineTest)); runTest(QScopedPointer(new QLineFTest)); + runTest(QScopedPointer(new QLocaleTest)); runTest(QScopedPointer(new QListTest)); runTest(QScopedPointer(new QMapTest)); runTest(QScopedPointer(new QMarginsTest)); diff --git a/tests/qt_types_standalone/cpp/qlocale.h b/tests/qt_types_standalone/cpp/qlocale.h new file mode 100644 index 000000000..05d4cb745 --- /dev/null +++ b/tests/qt_types_standalone/cpp/qlocale.h @@ -0,0 +1,31 @@ +// clang-format off +// SPDX-FileCopyrightText: 2024 Klarälvdalens Datakonsult AB, a KDAB Group company +// clang-format on +// SPDX-FileContributor: Nicolas Fella +// +// SPDX-License-Identifier: MIT OR Apache-2.0 +#pragma once + +#include +#include + +#include "qt_types_standalone/src/qlocale.cxx.h" + +class QLocaleTest : public QObject +{ + Q_OBJECT + +private Q_SLOTS: + void construct() + { + const auto m = construct_qlocale(); + QVERIFY(!m.name().isEmpty()); + } + + void clone() + { + const auto locale = QLocale(QStringLiteral("de_DE")); + const auto c = clone_qlocale(locale); + QCOMPARE(c.name(), QStringLiteral("de_DE")); + } +}; diff --git a/tests/qt_types_standalone/rust/Cargo.toml b/tests/qt_types_standalone/rust/Cargo.toml index 7acaf9020..21f5ac43b 100644 --- a/tests/qt_types_standalone/rust/Cargo.toml +++ b/tests/qt_types_standalone/rust/Cargo.toml @@ -17,6 +17,7 @@ crate-type = ["staticlib"] cxx.workspace = true cxx-qt-gen.workspace = true cxx-qt-lib = { workspace = true, features = ["full"] } +cxx-qt-lib-extras = { workspace = true } [build-dependencies] cxx-qt-build.workspace = true diff --git a/tests/qt_types_standalone/rust/build.rs b/tests/qt_types_standalone/rust/build.rs index 3c752a8f2..0500e2fe0 100644 --- a/tests/qt_types_standalone/rust/build.rs +++ b/tests/qt_types_standalone/rust/build.rs @@ -20,6 +20,7 @@ fn main() { .file("src/qline.rs") .file("src/qlinef.rs") .file("src/qlist.rs") + .file("src/qlocale.rs") .file("src/qmap.rs") .file("src/qmargins.rs") .file("src/qmarginsf.rs") diff --git a/tests/qt_types_standalone/rust/src/lib.rs b/tests/qt_types_standalone/rust/src/lib.rs index edee936a9..630122118 100644 --- a/tests/qt_types_standalone/rust/src/lib.rs +++ b/tests/qt_types_standalone/rust/src/lib.rs @@ -17,6 +17,7 @@ mod qhash; mod qline; mod qlinef; mod qlist; +mod qlocale; mod qmap; mod qmargins; mod qmarginsf; diff --git a/tests/qt_types_standalone/rust/src/qlocale.rs b/tests/qt_types_standalone/rust/src/qlocale.rs new file mode 100644 index 000000000..fde9cf485 --- /dev/null +++ b/tests/qt_types_standalone/rust/src/qlocale.rs @@ -0,0 +1,27 @@ +// SPDX-FileCopyrightText: 2024 Klarälvdalens Datakonsult AB, a KDAB Group company +// SPDX-FileContributor: Nicolas Fella +// +// SPDX-License-Identifier: MIT OR Apache-2.0 + +use cxx_qt_lib_extras::QLocale; + +#[cxx::bridge] +mod qline_cxx { + unsafe extern "C++" { + include!("cxx-qt-lib-extras/qlocale.h"); + type QLocale = cxx_qt_lib_extras::QLocale; + } + + extern "Rust" { + fn construct_qlocale() -> QLocale; + fn clone_qlocale(l: &QLocale) -> QLocale; + } +} + +fn construct_qlocale() -> QLocale { + QLocale::default() +} + +fn clone_qlocale(l: &QLocale) -> QLocale { + l.clone() +}