@@ -12,6 +12,7 @@ use std::io;
1212/// A qmldir file is a plain-text file that contains the commands
1313pub struct QmlDirBuilder {
1414 class_name : Option < String > ,
15+ depends : Vec < String > ,
1516 plugin : Option < ( bool , String ) > ,
1617 type_info : Option < String > ,
1718 uri : QmlUri ,
@@ -23,6 +24,7 @@ impl QmlDirBuilder {
2324 pub fn new ( uri : QmlUri ) -> Self {
2425 Self {
2526 class_name : None ,
27+ depends : vec ! [ ] ,
2628 plugin : None ,
2729 type_info : None ,
2830 uri,
@@ -51,6 +53,10 @@ impl QmlDirBuilder {
5153 writeln ! ( writer, "typeinfo {file}" ) ?;
5254 }
5355
56+ for depend in self . depends {
57+ writeln ! ( writer, "depends {depend}" ) ?;
58+ }
59+
5460 // Prefer is always specified for now
5561 writeln ! ( writer, "prefer :/qt/qml/{}/" , self . uri. as_dirs( ) )
5662 }
@@ -68,6 +74,18 @@ impl QmlDirBuilder {
6874 self
6975 }
7076
77+ /// Declares that this module depends on another
78+ pub fn depend ( mut self , depend : impl Into < String > ) -> Self {
79+ self . depends . push ( depend. into ( ) ) ;
80+ self
81+ }
82+
83+ /// Declares that this module depends on another
84+ pub fn depends < T : Into < String > > ( mut self , depends : impl IntoIterator < Item = T > ) -> Self {
85+ self . depends . extend ( depends. into_iter ( ) . map ( Into :: into) ) ;
86+ self
87+ }
88+
7189 /// Declares a plugin to be made available by the module.
7290 ///
7391 /// optional denotes that the plugin itself does not contain any relevant code
@@ -105,7 +123,6 @@ impl QmlDirBuilder {
105123 // object type declaration
106124 // internal object type declaration
107125 // javascript resource definition
108- // module dependencies declaration
109126 // module import declaration
110127 // designer support declaration
111128}
@@ -119,6 +136,7 @@ mod test {
119136 let mut result = Vec :: new ( ) ;
120137 QmlDirBuilder :: new ( QmlUri :: new ( [ "com" , "kdab" ] ) )
121138 . class_name ( "C" )
139+ . depends ( [ "QtQuick" , "com.kdab.a" ] )
122140 . plugin ( "P" , true )
123141 . type_info ( "T" )
124142 . write ( & mut result)
@@ -129,6 +147,8 @@ mod test {
129147optional plugin P
130148classname C
131149typeinfo T
150+ depends QtQuick
151+ depends com.kdab.a
132152prefer :/qt/qml/com/kdab/
133153"
134154 ) ;
0 commit comments