qt_build_utils/qml/
qmlfile.rs

1// SPDX-FileCopyrightText: 2025 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
2// SPDX-FileContributor: Leon Matthes <leon.matthes@kdab.com>
3//
4// SPDX-License-Identifier: MIT OR Apache-2.0
5
6use std::path::{Path, PathBuf};
7
8/// A QML file to be included in a QML module (e.g. by ways of [super::QmlDirBuilder]).
9#[derive(Clone, Debug, Hash)]
10pub struct QmlFile {
11    path: PathBuf,
12    singleton: bool,
13    version: Option<(usize, usize)>,
14}
15
16impl<T: AsRef<Path>> From<T> for QmlFile {
17    /// Create a new QmlFile from the given path.
18    ///
19    /// By default, no version is set for the QML file, and the file is not a singleton.
20    fn from(path: T) -> Self {
21        Self {
22            path: path.as_ref().to_path_buf(),
23            singleton: false,
24            version: None,
25        }
26    }
27}
28
29impl QmlFile {
30    /// Set whether the component inside this QML file is a singleton.
31    pub fn singleton(mut self, singleton: bool) -> Self {
32        self.singleton = singleton;
33        self
34    }
35
36    /// Returns whether the component inside this QML file is a singleton.
37    pub fn is_singleton(&self) -> bool {
38        self.singleton
39    }
40
41    /// Returns the path to the QML file.
42    pub fn get_path(&self) -> &Path {
43        &self.path
44    }
45
46    /// Assign a version to the QML file.
47    pub fn version(mut self, major: usize, minor: usize) -> Self {
48        self.version = Some((major, minor));
49        self
50    }
51
52    /// Returns the version assigned to the QML file, if any.
53    pub fn get_version(&self) -> Option<(usize, usize)> {
54        self.version
55    }
56}