Skip to content

Commit

Permalink
Fixed problem with emitting dataChanged()
Browse files Browse the repository at this point in the history
  • Loading branch information
Kakadu committed Dec 3, 2013
1 parent 6096573 commit 8af9396
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 15 deletions.
19 changes: 19 additions & 0 deletions src/mocml/Config.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
open Core_kernel.Std

module MethOptions = struct
type t =
[ `PrintMethCalls
| `DebugBlockingSections
| `AbstractItemModel of string option ] list

end

module TypeOptions = struct
type t = [`AbstractItemModel of string option ] list
let of_meth_options (config: MethOptions.t) : t =
List.fold_left ~init:[] config ~f:(fun acc -> function
| `PrintMethCalls
| `DebugBlockingSections -> acc
| `AbstractItemModel _ as x -> x::acc
)
end
21 changes: 13 additions & 8 deletions src/mocml/Qml_wrap.ml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ open B.Printf
open ParseYaml.Yaml2.Types
open Parser
open Qml
open Config

let with_file path f =
let file = open_out path in
Expand Down Expand Up @@ -64,7 +65,8 @@ let generate ?(directory=".") ?(config=[]) {classname; basename; members; slots;
p_c "}\n";

(* method: We generate C++ method and call OCaml in it *)
let do_meth ~classname (name,args,res,modif) =
let do_meth ~classname ~config (name,args,res,modif) =
let (_:Config.MethOptions.t) = config in
let (_:Parser.cpptype list) = args in
let (_:Parser.cpptype) = res in
let args = if args = [Parser.void_type] then [] else args in
Expand Down Expand Up @@ -133,7 +135,9 @@ let generate ?(directory=".") ?(config=[]) {classname; basename; members; slots;
let cpp_ans_var = "cppans" in
let new_cpp_var = Qml.getter_of_cppvars "xx" in
p_c " %s %s;\n" (Parser.string_of_type res) cpp_ans_var;
Qml.cpp_value_of_ocaml b_c (get_var,release_var, new_cpp_var) cpp_ans_var "_ans" res;
let options = Config.TypeOptions.of_meth_options config in
Qml.cpp_value_of_ocaml ~options ~cpp_var:cpp_ans_var ~ocaml_var:"_ans"
b_c (get_var,release_var, new_cpp_var) res;
p_c " CAMLreturnT(%s,%s);\n" (string_of_type res) cpp_ans_var;
end;
p_c "}\n"
Expand Down Expand Up @@ -169,7 +173,7 @@ let generate ?(directory=".") ?(config=[]) {classname; basename; members; slots;
let prop_descr_str = sprintf "Q_PROPERTY(%s %s%s READ %s NOTIFY %s)"
(string_of_type typ) name setter_string getter notifier in
p_h " %s\n" prop_descr_str;
do_meth ~classname (getter,[void_type],typ,[]);
do_meth ~config ~classname (getter,[void_type],typ,[]);
declare_cpp_signal hbuf ~name:notifier ~args:[typ] ~argnames:[name];
let stub_name = WrapAbstractItemModel.gen_cppmeth_wrapper
~config ~classname cbuf (notifier,[typ],void_type,[]) in
Expand All @@ -181,7 +185,7 @@ let generate ?(directory=".") ?(config=[]) {classname; basename; members; slots;
let () =
match setter with
| Some setter ->
do_meth ~classname (setter,[typ],bool_type,[]);
do_meth ~config ~classname (setter,[typ],bool_type,[]);
bprintf clas_def_buf " method virtual %s: %s -> unit\n" setter
(typ |> TypAst.of_verbose_typ_exn |> TypAst.to_ocaml_type);
| None -> ()
Expand Down Expand Up @@ -218,12 +222,12 @@ let generate ?(directory=".") ?(config=[]) {classname; basename; members; slots;
in

List.iter members ~f:(fun mem ->
do_meth ~classname mem;
do_meth ~config ~classname mem;
do_meth_caml mem;
);
List.iter slots ~f:(fun ((name,args,_,_) as mem) ->
p_h "public slots:\n";
do_meth ~classname mem;
do_meth ~config ~classname mem;
let f x = x |> TypAst.of_verbose_typ_exn |> TypAst.to_cpp_type in
let slot_string = sprintf "1%s(%s)" name (String.concat ~sep:","(List.map ~f args)) in
bprintf clas_def_buf
Expand Down Expand Up @@ -251,10 +255,11 @@ let generate ?(directory=".") ?(config=[]) {classname; basename; members; slots;

(* Now we will add some methods for specific basename *)
let () =
if base_classname = "QAbstractItemModel" then
if base_classname = "QAbstractItemModel" then begin
let config = (`AbstractItemModel (Some "this"))::config in
WrapAbstractItemModel.wrap ~classname ~config do_meth do_meth_caml
b_h b_c external_buf top_externals_buf clas_def_buf
else ()
end
in

(* Also we need to have a stubs to create C++ class *)
Expand Down
10 changes: 5 additions & 5 deletions src/mocml/WrapAbstractItemModel.ml
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,17 @@ let gen_cppmeth_wrapper ~classname ?(config=[]) (cbuf: Bigbuffer.t) meth =
p_c "}\n";
cpp_stub_name

let wrap ~classname ~config do_meth do_meth_caml b_h b_c external_buf top_externals_buf clas_def_buf =

let wrap ~classname ~(config: Config.MethOptions.t) do_meth do_meth_caml b_h b_c
external_buf top_externals_buf clas_def_buf =
let open Bigbuffer.Printf in
let p_h fmt = bprintf b_h fmt in
(*let p_c fmt = bprintf b_c fmt in*)

let model_members = qabstractItemView_members in
List.iter model_members ~f:(do_meth ~classname);
List.iter qabstractItemView_members ~f:(do_meth ~classname ~config);
p_h "private:\n";
p_h " QHash<int, QByteArray> _roles;\n";
p_h "public:\n";
p_h " QModelIndex makeIndex(int row,int column) {\n";
p_h " QModelIndex makeIndex(int row,int column) const {\n";
p_h " if (row==-1 || column==-1)\n";
p_h " return QModelIndex();\n";
p_h " else\n";
Expand Down
5 changes: 3 additions & 2 deletions src/mocml/qml.ml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ let ocaml_name_of_prop ~classname sort ({name;typ;_}) : string =
| `List _ -> sprintf "xxxx_list")

let cpp_value_of_ocaml ?(options=[`AbstractItemModel None])
ch (get_var,release_var,new_cpp_var) ~cpp_var ~ocaml_var typ =
~cpp_var ~ocaml_var ch (get_var,release_var,new_cpp_var) typ =
let print_cpp fmt = bprintf ch fmt in
let rec to_cpp_conv ~tab dest var (typ: TypAst.t) =
let prefix = String.concat ~sep:"" (List.init ~f:(const " ") tab) in
Expand Down Expand Up @@ -342,7 +342,8 @@ let gen_meth ~classname ~ocaml_methname ?(options=[])
end else begin
let cpp_ans_var = "cppans" in
print_cpp " %s %s;\n" (Parser.string_of_type res) cpp_ans_var;
cpp_value_of_ocaml file_cpp (get_var,release_var, new_cpp_var) cpp_ans_var "_ans" res;
cpp_value_of_ocaml file_cpp
(get_var,release_var, new_cpp_var) ~cpp_var:cpp_ans_var ~ocaml_var:"_ans" res;
match hasSetter with
| Some signal ->
assert (Parser.is_bool_type res);
Expand Down

0 comments on commit 8af9396

Please sign in to comment.