cxx_qt_lib_extras/core/qcommandlineoption.rs
1// SPDX-FileCopyrightText: 2023 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
2// SPDX-FileContributor: Laurent Montel <laurent.montel@kdab.com>
3//
4// SPDX-License-Identifier: MIT OR Apache-2.0
5
6use cxx::{type_id, ExternType};
7use cxx_qt_lib::{QString, QStringList};
8use std::mem::MaybeUninit;
9
10#[cxx::bridge]
11mod ffi {
12 unsafe extern "C++" {
13 include!("cxx-qt-lib-extras/core/qcommandlineoption.h");
14 type QCommandLineOption = super::QCommandLineOption;
15 include!("cxx-qt-lib/qstring.h");
16 type QString = cxx_qt_lib::QString;
17 include!("cxx-qt-lib/qstringlist.h");
18 type QStringList = cxx_qt_lib::QStringList;
19
20 /// Returns the default values set for this option.
21 #[rust_name = "default_values"]
22 fn defaultValues(self: &QCommandLineOption) -> QStringList;
23
24 /// Returns the description set for this option.
25 fn description(self: &QCommandLineOption) -> QString;
26
27 /// Returns the names set for this option.
28 fn names(self: &QCommandLineOption) -> QStringList;
29
30 /// Sets the default value used for this option to `default_value`.
31 ///
32 /// The default value is used if the user of the application does not specify the option on the command line.
33 ///
34 /// If `default_value` is empty, the option has no default values.
35 #[rust_name = "set_default_value"]
36 fn setDefaultValue(self: &mut QCommandLineOption, default_value: &QString);
37
38 /// Sets the list of default values used for this option to `default_values`.
39 ///
40 /// The default values are used if the user of the application does not specify the option on the command line.
41 #[rust_name = "set_default_values"]
42 fn setDefaultValues(self: &mut QCommandLineOption, default_values: &QStringList);
43
44 /// Sets the description used for this option to `description`.
45 /// It is customary to add a "." at the end of the description.
46 ///
47 /// The description is used by [QCommandLineParser::showHelp](https://doc.qt.io/qt/qcommandlineparser.html#showHelp)().
48 #[rust_name = "set_description"]
49 fn setDescription(self: &mut QCommandLineOption, description: &QString);
50
51 /// Sets the name of the expected value, for the documentation, to `value_name`.
52 ///
53 /// Options without a value assigned have a boolean-like behavior: either the user specifies `–option` or they don't.
54 ///
55 /// Options with a value assigned need to set a name for the expected value, for the documentation of the option in the help output. An option with names `o` and `output`, and a value name of file will appear as `-o, --output <file>`.
56 ///
57 /// Call [`QCommandLineParser::value`](crate::QCommandLineParser::value) if you expect the option to be present only once, and [`QCommandLineParser::values`](crate::QCommandLineParser::values) if you expect that option to be present multiple times.
58 #[rust_name = "set_value_name"]
59 fn setValueName(self: &mut QCommandLineOption, value_name: &QString);
60
61 /// Returns the name of the expected value.
62 #[rust_name = "value_name"]
63 fn valueName(self: &QCommandLineOption) -> QString;
64 }
65
66 #[namespace = "rust::cxxqtlib1"]
67 unsafe extern "C++" {
68 include!("cxx-qt-lib/common.h");
69
70 #[doc(hidden)]
71 #[rust_name = "qcommandlineoption_drop"]
72 fn drop(option: &mut QCommandLineOption);
73
74 #[doc(hidden)]
75 #[rust_name = "qcommandlineoption_init_from_qcommandlineoption"]
76 fn construct(commandLineOption: &QCommandLineOption) -> QCommandLineOption;
77
78 #[doc(hidden)]
79 #[rust_name = "qcommandlineoption_init_from_qstring"]
80 fn construct(string: &QString) -> QCommandLineOption;
81
82 #[doc(hidden)]
83 #[rust_name = "qcommandlineoption_init_from_qstringlist"]
84 fn construct(names: &QStringList) -> QCommandLineOption;
85 }
86}
87
88/// The `QCommandLineOption` class defines a possible command-line option.
89///
90/// Qt Documentation: [QCommandLineOption](https://doc.qt.io/qt/qcommandlineoption.html#details)
91#[repr(C)]
92pub struct QCommandLineOption {
93 _space: MaybeUninit<usize>,
94}
95
96impl Clone for QCommandLineOption {
97 /// Constructs a copy of this `QCommandLineOption`.
98 fn clone(&self) -> Self {
99 ffi::qcommandlineoption_init_from_qcommandlineoption(self)
100 }
101}
102
103impl Drop for QCommandLineOption {
104 /// Destroys the `QCommandLineOption`.
105 fn drop(&mut self) {
106 ffi::qcommandlineoption_drop(self)
107 }
108}
109
110impl From<&QString> for QCommandLineOption {
111 /// Constructs a command line option object with the name name.
112 fn from(name: &QString) -> Self {
113 ffi::qcommandlineoption_init_from_qstring(name)
114 }
115}
116
117impl From<&QStringList> for QCommandLineOption {
118 /// Constructs a command line option object with the name name.
119 fn from(names: &QStringList) -> Self {
120 ffi::qcommandlineoption_init_from_qstringlist(names)
121 }
122}
123
124// Safety:
125//
126// Static checks on the C++ side to ensure the size is the same.
127unsafe impl ExternType for QCommandLineOption {
128 type Id = type_id!("QCommandLineOption");
129 type Kind = cxx::kind::Trivial;
130}