Made qmetaobject optional dep.

This commit is contained in:
Ayush Singh 2021-12-23 17:35:16 +05:30
parent bb82d5fdfc
commit 1b8354d05b
4 changed files with 39 additions and 18 deletions

View file

@ -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"]

View file

@ -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 <KLocalizedContext>
#include <QtCore/QObject>
@ -21,11 +24,13 @@ cpp_class!(
);
impl KLocalizedContext {
#[cfg(feature = "qmetaobject")]
/// Initialize KLocalizedContext from Engine.
/// **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();

View file

@ -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);
})
}
}

View file

@ -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();