Changeset View
Changeset View
Standalone View
Standalone View
src/cpp.cpp
Show First 20 Lines • Show All 508 Lines • ▼ Show 20 Line(s) | 507 | if (p.type.type == BindingType::Object) { | |||
---|---|---|---|---|---|
509 | h << " " << p.type.name << "* " << p.name << "();" << endl; | 509 | h << " " << p.type.name << "* " << p.name << "();" << endl; | ||
510 | } else { | 510 | } else { | ||
511 | h << " " << p.type.name << " " << p.name << "() const;" << endl; | 511 | h << " " << p.type.name << " " << p.name << "() const;" << endl; | ||
512 | if (p.write) { | 512 | if (p.write) { | ||
513 | h << " void set" << upperInitial(p.name) << "(" << p.type.cppSetType << " v);" << endl; | 513 | h << " void set" << upperInitial(p.name) << "(" << p.type.cppSetType << " v);" << endl; | ||
514 | } | 514 | } | ||
515 | } | 515 | } | ||
516 | } | 516 | } | ||
517 | for (auto f: o.functions) { | ||||
518 | h << " Q_INVOKABLE " << f.type.name << " " << f.name << "("; | ||||
519 | for (auto a = f.args.begin(); a < f.args.end(); a++) { | ||||
520 | h << QString("%1 %2%3").arg(a->type.cppSetType, a->name, a + 1 < f.args.end() ? ", " : ""); | ||||
521 | } | ||||
522 | h << QString(")%1;") | ||||
vandenoever: Add a new line after function declaration. | |||||
523 | .arg(f.mut ? "" : " const"); | ||||
524 | h << endl; | ||||
525 | } | ||||
517 | if (baseType(o) == "QAbstractItemModel") { | 526 | if (baseType(o) == "QAbstractItemModel") { | ||
518 | writeHeaderItemModel(h, o); | 527 | writeHeaderItemModel(h, o); | ||
519 | } | 528 | } | ||
520 | h << "signals:" << endl; | 529 | h << "signals:" << endl; | ||
521 | for (auto p: o.properties) { | 530 | for (auto p: o.properties) { | ||
522 | h << " void " << p.name << "Changed();" << endl; | 531 | h << " void " << p.name << "Changed();" << endl; | ||
523 | } | 532 | } | ||
524 | h << "};" << endl; | 533 | h << "};" << endl; | ||
▲ Show 20 Lines • Show All 148 Lines • ▼ Show 20 Line(s) | 681 | if (p.write) { | |||
673 | cpp << QString(" void %2_set(%1::Private*, %3);") | 682 | cpp << QString(" void %2_set(%1::Private*, %3);") | ||
674 | .arg(o.name, base, p.type.cSetType) << endl; | 683 | .arg(o.name, base, p.type.cSetType) << endl; | ||
675 | if (p.optional) { | 684 | if (p.optional) { | ||
676 | cpp << QString(" void %2_set_none(%1::Private*);") | 685 | cpp << QString(" void %2_set_none(%1::Private*);") | ||
677 | .arg(o.name, base) << endl; | 686 | .arg(o.name, base) << endl; | ||
678 | } | 687 | } | ||
679 | } | 688 | } | ||
680 | } | 689 | } | ||
690 | | ||||
691 | for (const Function& f: o.functions) { | ||||
692 | const QString name = QString("%1_%2").arg(lcname, f.name); | ||||
693 | cpp << QString(" %1 %2(%4%3::Private*") | ||||
694 | .arg(f.type.cSetType, name, o.name, f.mut ? "" : "const "); | ||||
695 | if (f.args.size() > 0) { | ||||
696 | cpp << ", "; | ||||
697 | for (auto a = f.args.begin(); a < f.args.end(); a++) { | ||||
698 | cpp << QString("%2%3").arg(a->type.cSetType, a + 1 < f.args.end() ? ", " : ""); | ||||
699 | } | ||||
700 | } | ||||
701 | if (f.type.name == "QString") { | ||||
702 | cpp << ", QString*, qstring_set"; | ||||
703 | } | ||||
704 | cpp << ");" << endl; | ||||
705 | } | ||||
681 | } | 706 | } | ||
682 | 707 | | |||
683 | void initializeMembersEmpty(QTextStream& cpp, const Object& o, const Configuration& conf) | 708 | void initializeMembersEmpty(QTextStream& cpp, const Object& o, const Configuration& conf) | ||
684 | { | 709 | { | ||
685 | for (const Property& p: o.properties) { | 710 | for (const Property& p: o.properties) { | ||
686 | if (p.type.type == BindingType::Object) { | 711 | if (p.type.type == BindingType::Object) { | ||
687 | initializeMembersEmpty(cpp, conf.findObject(p.type.name), conf); | 712 | initializeMembersEmpty(cpp, conf.findObject(p.type.name), conf); | ||
688 | cpp << QString(" %1m_%2(new %3(false, this)),\n") | 713 | cpp << QString(" %1m_%2(new %3(false, this)),\n") | ||
▲ Show 20 Lines • Show All 117 Lines • ▼ Show 20 Line(s) | 827 | if (p.optional) { | |||
806 | cpp << QString(" %1_set(m_d, v);").arg(base) << endl; | 831 | cpp << QString(" %1_set(m_d, v);").arg(base) << endl; | ||
807 | cpp << QString(" }") << endl; | 832 | cpp << QString(" }") << endl; | ||
808 | } else { | 833 | } else { | ||
809 | cpp << QString(" %1_set(m_d, v);").arg(base) << endl; | 834 | cpp << QString(" %1_set(m_d, v);").arg(base) << endl; | ||
810 | } | 835 | } | ||
811 | cpp << "}" << endl; | 836 | cpp << "}" << endl; | ||
812 | } | 837 | } | ||
813 | } | 838 | } | ||
839 | | ||||
840 | for (const Function& f: o.functions) { | ||||
841 | const QString base = QString("%1_%2") | ||||
842 | .arg(lcname, snakeCase(f.name)); | ||||
843 | cpp << QString("%1 %2::%3(") | ||||
844 | .arg(f.type.name, o.name, f.name); | ||||
845 | for (auto a = f.args.begin(); a < f.args.end(); a++) { | ||||
846 | cpp << QString("%1 %2%3").arg(a->type.cppSetType, a->name, a + 1 < f.args.end() ? ", " : ""); | ||||
847 | } | ||||
848 | cpp << QString(") %4\n{\n") | ||||
849 | .arg(f.mut ? "" : "const"); | ||||
850 | QString argList; | ||||
851 | if (f.args.size() > 0) { | ||||
852 | argList.append(", "); | ||||
853 | for (auto a = f.args.begin(); a < f.args.end(); a++) { | ||||
854 | argList.append(QString("%2%3").arg(a->name, a + 1 < f.args.end() ? ", " : "")); | ||||
855 | } | ||||
856 | } | ||||
857 | if (f.type.name == "QString") { | ||||
858 | cpp << QString(" %1 s;").arg(f.type.name) << endl; | ||||
859 | cpp << QString(" %1(m_d%2, &s, set_qstring);") | ||||
860 | .arg(base, argList) << endl; | ||||
861 | cpp << " return s;" << endl; | ||||
862 | } else { | ||||
863 | cpp << QString(" return %1(m_d%2);") | ||||
864 | .arg(base, argList) << endl; | ||||
865 | } | ||||
866 | cpp << "}" << endl; | ||||
867 | } | ||||
814 | } | 868 | } | ||
815 | 869 | | |||
816 | void writeHeader(const Configuration& conf) { | 870 | void writeHeader(const Configuration& conf) { | ||
817 | DifferentFileWriter w(conf.hFile.absoluteFilePath()); | 871 | DifferentFileWriter w(conf.hFile.absoluteFilePath()); | ||
818 | QTextStream h(&w.buffer); | 872 | QTextStream h(&w.buffer); | ||
819 | const QString guard(conf.hFile.fileName().replace('.', '_').toUpper()); | 873 | const QString guard(conf.hFile.fileName().replace('.', '_').toUpper()); | ||
820 | h << QString(R"(/* generated by rust_qt_binding_generator */ | 874 | h << QString(R"(/* generated by rust_qt_binding_generator */ | ||
821 | #ifndef %1 | 875 | #ifndef %1 | ||
▲ Show 20 Lines • Show All 116 Lines • Show Last 20 Lines |
Add a new line after function declaration.