From 1b8354d05bf60430ed2b351f30f79bc85150c3c2 Mon Sep 17 00:00:00 2001 From: Ayush Singh Date: Thu, 23 Dec 2021 17:35:16 +0530 Subject: [PATCH] Made qmetaobject optional dep. --- Cargo.toml | 8 +++++-- src/klocalizedcontext.rs | 37 +++++++++++++++++++++----------- src/klocalizedstring.rs | 4 ++-- tests/klocalizedcontext_tests.rs | 8 ++++++- 4 files changed, 39 insertions(+), 18 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e629e85..b3f8807 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,7 +13,7 @@ build = "build.rs" [dependencies] cpp = "0.5" -qmetaobject = "0.2" +qmetaobject = { version = "0.2", optional = true } qttypes = "0.2" # qmetaobject = { path="../qmetaobject-rs/qmetaobject" } # qttypes = { path="../qmetaobject-rs/qttypes" } @@ -26,4 +26,8 @@ semver = "1.0" lazy_static = "1.4" [package.metadata.docs.rs] -dependencies = ["qtbase5-dev", "qtdeclarative5-dev", "libqt5svg5-dev", "qtquickcontrols2-5-dev", "qml-module-org-kde-kirigami2", "kirigami2-dev", "libkf5i18n-dev", "gettext", "libkf5coreaddons-dev", "qml-module-qtquick-layouts"] +dependencies = ["qtbase5-dev", "qtdeclarative5-dev", "libkf5i18n-dev"] +all-features = true + +[features] +all = ["qmetaobject"] \ No newline at end of file diff --git a/src/klocalizedcontext.rs b/src/klocalizedcontext.rs index 7454de2..a5f3086 100644 --- a/src/klocalizedcontext.rs +++ b/src/klocalizedcontext.rs @@ -1,7 +1,10 @@ use cpp::{cpp, cpp_class}; -use qmetaobject::prelude::*; +use qttypes::QString; use std::ffi::c_void; +#[cfg(feature = "qmetaobject")] +use qmetaobject::QmlEngine; + cpp! {{ #include #include @@ -21,11 +24,13 @@ cpp_class!( ); impl KLocalizedContext { + #[cfg(feature = "qmetaobject")] /// Initialize KLocalizedContext from Engine. - /// #Example + /// **Feature** `qmetaobject` needs to be enabled for this function. + /// # Example /// ``` /// use ki18n::klocalizedcontext::KLocalizedContext; - /// use qmetaobject::prelude::*; + /// use qmetaobject::QmlEngine; /// /// let engine = QmlEngine::new(); /// KLocalizedContext::init_from_engine(&engine); @@ -48,22 +53,28 @@ impl KLocalizedContext { } /// Set Translation Domain for current KLocalizedContext. - /// # Example - /// ``` - /// use ki18n::klocalizedcontext::KLocalizedContext; - /// use qmetaobject::prelude::*; - /// - /// let engine = QmlEngine::new(); - /// let mut context = KLocalizedContext::init_from_engine(&engine); - /// context.set_translation_domain("Test Domain".into()); - /// ``` + #[cfg_attr( + feature = "qmetaobject", + doc = r##" +# Example + +``` +use ki18n::klocalizedcontext::KLocalizedContext; +use qmetaobject::QmlEngine; + +let engine = QmlEngine::new(); +let mut context = KLocalizedContext::init_from_engine(&engine); +context.set_translation_domain("Test Domain".into()); +``` +"## + )] pub fn set_translation_domain(&mut self, domain: QString) { cpp!(unsafe [self as "KLocalizedContextHolder *", domain as "QString"] { self->klocalized->setTranslationDomain(domain); }) } - /// Retrns the current Translation Domain. + /// Returns the current Translation Domain. pub fn translation_domain(&self) -> QString { cpp!(unsafe [self as "KLocalizedContextHolder *"] -> QString as "QString" { return self->klocalized->translationDomain(); diff --git a/src/klocalizedstring.rs b/src/klocalizedstring.rs index 7ee0e3c..5a887a9 100644 --- a/src/klocalizedstring.rs +++ b/src/klocalizedstring.rs @@ -1,5 +1,5 @@ use cpp::{cpp, cpp_class}; -use qmetaobject::{QByteArray, QString, QStringList}; +use qttypes::{QByteArray, QString, QStringList}; use std::ffi::CStr; cpp! {{ @@ -116,7 +116,7 @@ impl KLocalizedString { /// TODO: Add Test pub fn with_languages(&self, languages: &QStringList) -> KLocalizedString { cpp!(unsafe [self as "KLocalizedString *", languages as "QStringList"] -> KLocalizedString as "KLocalizedString" { - return self->withLangauages(languages); + return self->withLanguages(languages); }) } } diff --git a/tests/klocalizedcontext_tests.rs b/tests/klocalizedcontext_tests.rs index 277a358..9bc163f 100644 --- a/tests/klocalizedcontext_tests.rs +++ b/tests/klocalizedcontext_tests.rs @@ -1,8 +1,13 @@ use ki18n::klocalizedcontext::KLocalizedContext; -use qmetaobject::prelude::*; +use qttypes::QString; + +#[cfg(feature = "qmetaobject")] +use qmetaobject::QmlEngine; + mod common; #[test] +#[cfg(feature = "qmetaobject")] fn cpp_ptr() { let _lock = common::lock_for_test(); @@ -14,6 +19,7 @@ fn cpp_ptr() { } #[test] +#[cfg(feature = "qmetaobject")] fn translation_domain() { let _lock = common::lock_for_test();