add before header include option

master
an 2019-07-03 22:50:28 -04:00
parent fddfbd59c5
commit 598336e657
2 changed files with 10 additions and 3 deletions

View File

@ -29,6 +29,8 @@ mod json {
pub rust: Rust, pub rust: Rust,
#[serde(default = "false_bool")] #[serde(default = "false_bool")]
pub overwrite_implementation: bool, pub overwrite_implementation: bool,
#[serde(rename = "beforeHeader", default)]
pub before_header: String,
} }
#[derive(Deserialize)] #[derive(Deserialize)]
@ -83,6 +85,7 @@ pub struct Config {
pub rust: Rust, pub rust: Rust,
pub rust_edition: RustEdition, pub rust_edition: RustEdition,
pub overwrite_implementation: bool, pub overwrite_implementation: bool,
pub before_header: String,
} }
impl ConfigPrivate for Config { impl ConfigPrivate for Config {
@ -492,6 +495,7 @@ fn post_process(config_file: &Path, json: json::Config) -> Result<Config, Box<Er
rust: json.rust, rust: json.rust,
rust_edition, rust_edition,
overwrite_implementation: json.overwrite_implementation, overwrite_implementation: json.overwrite_implementation,
before_header: json.before_header,
}) })
} }

View File

@ -1400,12 +1400,15 @@ pub fn write_header(conf: &Config) -> Result<()> {
"/* generated by rust_qt_binding_generator */ "/* generated by rust_qt_binding_generator */
#ifndef {0} #ifndef {0}
#define {0} #define {0}
#include <QtCore/QObject>
#include <QtCore/QAbstractItemModel>
", ",
guard guard
)?; )?;
if conf.before_header != "" {
writeln!(h, "#include \"{}\"", conf.before_header)?;
}
writeln!(h, "
#include <QtCore/QObject>
#include <QtCore/QAbstractItemModel>")?;
for name in conf.objects.keys() { for name in conf.objects.keys() {
writeln!(h, "class {};", name)?; writeln!(h, "class {};", name)?;