Skip to content

Commit

Permalink
Add methods for QStandardPathLocation.
Browse files Browse the repository at this point in the history
Also refactored QStandardPathLocation emum to separate module in qtcore.
  • Loading branch information
Ayush1325 committed Feb 26, 2022
1 parent 3dd450b commit 4de5ef0
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 30 deletions.
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

0 comments on commit 4de5ef0

Please sign in to comment.