comparison qt/qtd/MOC.d @ 319:894d40eb89b6 signals

new signals and slots syntax. have to use prefixes now: signal_fooed and slot_onFooed
author eldar_ins@eldar-laptop
date Fri, 25 Dec 2009 21:48:32 +0500
parents 55ee4603365d
children 5c6455c4889b
comparison
equal deleted inserted replaced
318:ce07227f00c1 319:894d40eb89b6
4 4
5 import std.typetuple; 5 import std.typetuple;
6 6
7 import qt.Signal; 7 import qt.Signal;
8 import qt.qtd.MetaMarshall; 8 import qt.qtd.MetaMarshall;
9 import qt.qtd.Meta;
10
9 public import qt.core.QString; 11 public import qt.core.QString;
10 12
11 public import std.traits; 13 public import std.traits;
12 /** 14 /**
13 Utils. 15 Utils.
79 // ret = newArray!char(n); 81 // ret = newArray!char(n);
80 for(int i = 0; i < n; i++) 82 for(int i = 0; i < n; i++)
81 ret ~= value; 83 ret ~= value;
82 } 84 }
83 return cast(string)ret; 85 return cast(string)ret;
84 }
85
86 template Repeat(T, int I)
87 {
88 static if (!I) alias TypeTuple!() Repeat;
89 else alias TypeTuple!(T, Repeat!(T, I - 1)) Repeat;
90 } 86 }
91 87
92 /** 88 /**
93 CTFE MOC port. 89 CTFE MOC port.
94 */ 90 */
407 if(methodCount) 403 if(methodCount)
408 { 404 {
409 res ~= " 405 res ~= "
410 if (_c == QMetaObject.Call.InvokeMetaMethod) { 406 if (_c == QMetaObject.Call.InvokeMetaMethod) {
411 switch (_id) {"; 407 switch (_id) {";
412 foreach(i, bogus; Repeat!(void, methodCount)) { 408 foreach(i, _; Repeat!(void, methodCount)) {
413 res ~= " 409 res ~= "
414 case " ~ __toString(i) ~ ": " ~ MetaEntryName!(Methods[i].at) ~ "(" ~ metaCallArgs!(MetaEntryArgs!(Methods[i].at))() ~ "); break;"; 410 case " ~ __toString(i) ~ ": " ~ MetaEntryName!(Methods[i].at) ~ "(" ~ metaCallArgs!(MetaEntryArgs!(Methods[i].at))() ~ "); break;";
415 } 411 }
416 res ~= "\n default: ;\n }\n"; 412 res ~= "\n default: ;\n }\n";
417 res ~= " _id -= " ~ __toString(methodCount) ~ ";"; 413 res ~= " _id -= " ~ __toString(methodCount) ~ ";";
504 res ~= newFunc(funcSig, args); 500 res ~= newFunc(funcSig, args);
505 } 501 }
506 return res; 502 return res;
507 } 503 }
508 504
509 string generateMetaInfo(string className, alias Signals, alias Slots)()
510 {
511 string res = "";
512 auto signalList = genFuncDefs!(Signals, newSignal)();
513 auto slotList = genFuncDefs!(Slots, newSlot)();
514 res ~= generateCode(className, signalList, slotList);
515 res ~= generate_qt_metacall!(Signals, Slots);
516 res ~= generateMetaObjectConstruction!(Signals, Slots);
517 res ~= generateQMetaObject(className);
518 return res;
519 }
520
521 template Q_OBJECT_BIND() 505 template Q_OBJECT_BIND()
522 { 506 {
523 mixin ("enum lastSignalIndex_" ~ typeof(this).stringof ~ " = " ~ toStringNow!(lastSignalIndex!(typeof(this))) ~ ";"); 507 mixin ("enum lastSignalIndex_" ~ typeof(this).stringof ~ " = " ~ toStringNow!(lastSignalIndex!(typeof(this))) ~ ";");
524 } 508 }
525 509 /*
526 template Q_OBJECT() 510 template Q_OBJECT()
527 { 511 {
528 // pragma(msg, toStringNow!(lastSignalIndex!(typeof(this)))); 512 // pragma(msg, toStringNow!(lastSignalIndex!(typeof(this))));
529 mixin ("enum lastSignalIndex_" ~ typeof(this).stringof ~ " = " ~ toStringNow!(lastSignalIndex!(typeof(this))) ~ ";"); 513 mixin ("enum lastSignalIndex_" ~ typeof(this).stringof ~ " = " ~ toStringNow!(lastSignalIndex!(typeof(this))) ~ ";");
530 514
531 alias TupleWrapper!(findSymbols!(slotPrefix, typeof(this), ByOwner!(typeof(this)))) Slots; 515 alias TupleWrapper!(findSymbols!(slotPrefix, typeof(this), ByOwner!(typeof(this)))) Slots;
532 alias TupleWrapper!(findSymbols!(signalPrefix, typeof(this), ByOwner!(typeof(this)))) Signals; 516 alias TupleWrapper!(findSymbols!(signalPrefix, typeof(this), ByOwner!(typeof(this)))) Signals;
533 pragma(msg, generateMetaInfo!((typeof(this)).stringof, Signals, Slots)()); 517 pragma(msg, generateMetaInfo!((typeof(this)).stringof, Signals, Slots)());
534 mixin(generateMetaInfo!((typeof(this)).stringof, Signals, Slots)()); 518 mixin(generateMetaInfo!((typeof(this)).stringof, Signals, Slots)());
535 } 519 }
520 */
521 // ------------------------------------------------------------------------------------------
522
523 string generateSignalEmitters(alias Funcs)()
524 {
525 string res;
526 enum funcsCount = Funcs.at.length;
527 foreach(i, bogus; Repeat!(void, funcsCount))
528 {
529 res ~= SignalEmitter!(MetaEntryArgs!(Funcs.at[i].at))(SignalType.NewSignal, MetaEntryName!(Funcs.at[i].at), [], i);
530 }
531 return res;
532 }
533
534 string generateSlotAliases(alias Funcs)()
535 {
536 string res;
537 enum funcsCount = Funcs.at.length;
538 foreach(i, bogus; Repeat!(void, funcsCount))
539 {
540 string name = MetaEntryName!(Funcs.at[i].at);
541 res ~= format_ctfe(" alias slot_${} ${};\n", name, name);
542 }
543 return res;
544 }
545
546
547 string generateMetaInfo(T, alias Signals, alias Slots)()
548 {
549 string res = "";
550 auto signalList = genFuncDefs!(Signals, newSignal)();
551 auto slotList = genFuncDefs!(Slots, newSlot)();
552 res ~= generateSignalEmitters!(Signals)();
553 res ~= generateSlotAliases!(Slots)();
554 res ~= generateCode(T.stringof, signalList, slotList);
555 res ~= generate_qt_metacall!(Signals, Slots);
556 res ~= generateMetaObjectConstruction!(Signals, Slots);
557 res ~= generateQMetaObject(T.stringof);
558 return res;
559 }
560
561 template Q_OBJECT()
562 {
563 alias findSignals!(typeof(this)) SignalFuncs;
564 alias toMetaEntries!(SignalFuncs) SignalMetaEntries;
565 alias findSlots!(typeof(this)) SlotFuncs;
566 alias toMetaEntries!(SlotFuncs) SlotMetaEntries;
567
568 mixin(generateMetaInfo!(typeof(this), SignalMetaEntries, SlotMetaEntries)());
569 pragma(msg, generateMetaInfo!(typeof(this), SignalMetaEntries, SlotMetaEntries)());
570 }