Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add methods for QStandardPathLocation. #254

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 2 additions & 30 deletions qttypes/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ use internal_prelude::*;

mod qtcore;
pub use crate::qtcore::{
qreal, NormalizationForm, QByteArray, QListIterator, QString, QStringList, QUrl, QVariantList,
UnicodeVersion,
qreal, NormalizationForm, QByteArray, QListIterator, QStandardPathLocation, QString,
QStringList, QUrl, QVariantList, UnicodeVersion,
};

mod gui;
Expand Down Expand Up @@ -1382,34 +1382,6 @@ impl QPen {
// qreal widthF() const
}

/// Bindings for [`QStandardPaths::StandardLocation`][enum] enum.
///
/// [enum]: https://doc.qt.io/qt-5/qstandardpaths.html#StandardLocation-enum
#[repr(C)]
#[derive(Clone, Copy, PartialEq, Debug)]
#[allow(non_camel_case_types)]
pub enum QStandardPathLocation {
DesktopLocation = 0,
DocumentsLocation = 1,
FontsLocation = 2,
ApplicationsLocation = 3,
MusicLocation = 4,
MoviesLocation = 5,
PicturesLocation = 6,
TempLocation = 7,
HomeLocation = 8,
AppLocalDataLocation = 9,
CacheLocation = 10,
GenericDataLocation = 11,
RuntimeLocation = 12,
ConfigLocation = 13,
DownloadLocation = 14,
GenericCacheLocation = 15,
GenericConfigLocation = 16,
AppDataLocation = 17,
AppConfigLocation = 18,
}

/// Bindings for [`Qt::BrushStyle`][enum] enum.
///
/// [enum]: https://doc.qt.io/qt-5/qt.html#BrushStyle-enum
Expand Down
2 changes: 2 additions & 0 deletions qttypes/src/qtcore/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ mod primitives;
mod qbytearray;
mod qchar;
mod qlist;
mod qstandardpaths;
mod qstring;
mod qurl;

pub use self::primitives::qreal;
pub use self::qbytearray::QByteArray;
pub use self::qchar::UnicodeVersion;
pub use self::qlist::{QListIterator, QStringList, QVariantList};
pub use self::qstandardpaths::QStandardPathLocation;
pub use self::qstring::{NormalizationForm, QString};
pub use self::qurl::QUrl;
55 changes: 55 additions & 0 deletions qttypes/src/qtcore/qstandardpaths.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
use crate::{cpp, QString, QStringList};

cpp! {{
#include <QtCore/QStandardPaths>
}}

/// Bindings for [`QStandardPaths::StandardLocation`][enum] enum.
///
/// [enum]: https://doc.qt.io/qt-5/qstandardpaths.html#StandardLocation-enum
#[repr(C)]
#[derive(Clone, Copy, PartialEq, Debug)]
#[allow(non_camel_case_types)]
pub enum QStandardPathLocation {
DesktopLocation = 0,
DocumentsLocation = 1,
FontsLocation = 2,
ApplicationsLocation = 3,
MusicLocation = 4,
MoviesLocation = 5,
PicturesLocation = 6,
TempLocation = 7,
HomeLocation = 8,
AppLocalDataLocation = 9,
CacheLocation = 10,
GenericDataLocation = 11,
RuntimeLocation = 12,
ConfigLocation = 13,
DownloadLocation = 14,
GenericCacheLocation = 15,
GenericConfigLocation = 16,
AppDataLocation = 17,
AppConfigLocation = 18,
}

impl QStandardPathLocation {
pub fn display_name(t: Self) -> Option<QString> {
cpp!(unsafe [t as "QStandardPaths::StandardLocation"] -> QString as "QString" {
return QStandardPaths::displayName(t);
})
.to_option()
}

pub fn standard_locations(t: Self) -> QStringList {
cpp!(unsafe [t as "QStandardPaths::StandardLocation"] -> QStringList as "QStringList" {
return QStandardPaths::standardLocations(t);
})
}

pub fn writable_location(t: Self) -> Option<QString> {
cpp!(unsafe [t as "QStandardPaths::StandardLocation"] -> QString as "QString" {
return QStandardPaths::writableLocation(t);
})
.to_option()
}
}
11 changes: 11 additions & 0 deletions qttypes/src/qtcore/qstring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,17 @@ impl QString {
return self->normalized(mode, version);
})
}

/// A function that converts QString to Option<QString>.
/// Checks if the QString is null.
/// Note: null QString is differnt from empty QString.
pub fn to_option(self) -> Option<Self> {
if self.is_null() {
None
} else {
Some(self)
}
}
}

impl From<QUrl> for QString {
Expand Down