Changeset View
Changeset View
Standalone View
Standalone View
src/cpp.cpp
Show First 20 Lines • Show All 105 Lines • ▼ Show 20 Line(s) | 95 | for (auto ip: o.itemProperties) { | |||
---|---|---|---|---|---|
106 | } else { | 106 | } else { | ||
107 | h << QString(" Q_INVOKABLE %2 %1(const QModelIndex& index) const;\n").arg(ip.name, r); | 107 | h << QString(" Q_INVOKABLE %2 %1(const QModelIndex& index) const;\n").arg(ip.name, r); | ||
108 | if (ip.write) { | 108 | if (ip.write) { | ||
109 | h << QString(" Q_INVOKABLE bool set%1(const QModelIndex& index, %2 value);\n").arg(upperInitial(ip.name), rw); | 109 | h << QString(" Q_INVOKABLE bool set%1(const QModelIndex& index, %2 value);\n").arg(upperInitial(ip.name), rw); | ||
110 | } | 110 | } | ||
111 | } | 111 | } | ||
112 | } | 112 | } | ||
113 | h << R"( | 113 | h << R"( | ||
114 | signals: | 114 | Q_SIGNALS: | ||
115 | // new data is ready to be made available to the model with fetchMore() | 115 | // new data is ready to be made available to the model with fetchMore() | ||
116 | void newDataReady(const QModelIndex &parent) const; | 116 | void newDataReady(const QModelIndex &parent) const; | ||
117 | private: | 117 | private: | ||
118 | QHash<QPair<int,Qt::ItemDataRole>, QVariant> m_headerData; | 118 | QHash<QPair<int,Qt::ItemDataRole>, QVariant> m_headerData; | ||
119 | void initHeaderData(); | 119 | void initHeaderData(); | ||
120 | void updatePersistentIndexes(); | 120 | void updatePersistentIndexes(); | ||
121 | )"; | 121 | )"; | ||
122 | } | 122 | } | ||
▲ Show 20 Lines • Show All 87 Lines • ▼ Show 20 Line(s) | 209 | cpp << QString(" set = %1_set_data_%2(m_d%3, %4);") | |||
210 | .arg(lcname, snakeCase(ip.name), idx, val) << endl; | 210 | .arg(lcname, snakeCase(ip.name), idx, val) << endl; | ||
211 | } | 211 | } | ||
212 | if (ip.optional) { | 212 | if (ip.optional) { | ||
213 | cpp << " }\n"; | 213 | cpp << " }\n"; | ||
214 | } | 214 | } | ||
215 | if (o.type == ObjectType::List) { | 215 | if (o.type == ObjectType::List) { | ||
216 | cpp << R"( if (set) { | 216 | cpp << R"( if (set) { | ||
217 | QModelIndex index = createIndex(row, 0, row); | 217 | QModelIndex index = createIndex(row, 0, row); | ||
218 | emit dataChanged(index, index); | 218 | Q_EMIT dataChanged(index, index); | ||
219 | } | 219 | } | ||
220 | return set; | 220 | return set; | ||
221 | } | 221 | } | ||
222 | 222 | | |||
223 | )"; | 223 | )"; | ||
224 | } else { | 224 | } else { | ||
225 | cpp << R"( if (set) { | 225 | cpp << R"( if (set) { | ||
226 | emit dataChanged(index, index); | 226 | Q_EMIT dataChanged(index, index); | ||
227 | } | 227 | } | ||
228 | return set; | 228 | return set; | ||
229 | } | 229 | } | ||
230 | 230 | | |||
231 | )"; | 231 | )"; | ||
232 | } | 232 | } | ||
233 | } | 233 | } | ||
234 | 234 | | |||
▲ Show 20 Lines • Show All 396 Lines • ▼ Show 20 Line(s) | 627 | for (auto a = f.args.begin(); a < f.args.end(); a++) { | |||
631 | h << QString("%1 %2").arg(a->type.cppSetType, a->name); | 631 | h << QString("%1 %2").arg(a->type.cppSetType, a->name); | ||
632 | } | 632 | } | ||
633 | h << QString(")%1;").arg(f.mut ? "" : " const"); | 633 | h << QString(")%1;").arg(f.mut ? "" : " const"); | ||
634 | h << endl; | 634 | h << endl; | ||
635 | } | 635 | } | ||
636 | if (baseType(o) == "QAbstractItemModel") { | 636 | if (baseType(o) == "QAbstractItemModel") { | ||
637 | writeHeaderItemModel(h, o); | 637 | writeHeaderItemModel(h, o); | ||
638 | } | 638 | } | ||
639 | h << "signals:" << endl; | 639 | h << "Q_SIGNALS:" << endl; | ||
640 | for (auto p: o.properties) { | 640 | for (auto p: o.properties) { | ||
641 | h << " void " << p.name << "Changed();" << endl; | 641 | h << " void " << p.name << "Changed();" << endl; | ||
642 | } | 642 | } | ||
643 | h << "};" << endl; | 643 | h << "};" << endl; | ||
644 | } | 644 | } | ||
645 | 645 | | |||
646 | void constructorArgsDecl(QTextStream& cpp, const Object& o, const Configuration& conf) { | 646 | void constructorArgsDecl(QTextStream& cpp, const Object& o, const Configuration& conf) { | ||
647 | cpp << o.name << "*"; | 647 | cpp << o.name << "*"; | ||
▲ Show 20 Lines • Show All 50 Lines • ▼ Show 20 Line(s) | 697 | constructorArgs(cpp, "m_" + p.name + "->", | |||
698 | conf.findObject(p.type.name), conf); | 698 | conf.findObject(p.type.name), conf); | ||
699 | } else { | 699 | } else { | ||
700 | cpp << ",\n " << changedF(o, p); | 700 | cpp << ",\n " << changedF(o, p); | ||
701 | } | 701 | } | ||
702 | } | 702 | } | ||
703 | if (o.type == ObjectType::List) { | 703 | if (o.type == ObjectType::List) { | ||
704 | cpp << QString(R"(, | 704 | cpp << QString(R"(, | ||
705 | [](const %1* o) { | 705 | [](const %1* o) { | ||
706 | emit o->newDataReady(QModelIndex()); | 706 | Q_EMIT o->newDataReady(QModelIndex()); | ||
707 | }, | 707 | }, | ||
708 | [](%1* o) { | 708 | [](%1* o) { | ||
709 | emit o->layoutAboutToBeChanged(); | 709 | Q_EMIT o->layoutAboutToBeChanged(); | ||
710 | }, | 710 | }, | ||
711 | [](%1* o) { | 711 | [](%1* o) { | ||
712 | o->updatePersistentIndexes(); | 712 | o->updatePersistentIndexes(); | ||
713 | emit o->layoutChanged(); | 713 | Q_EMIT o->layoutChanged(); | ||
714 | }, | 714 | }, | ||
715 | [](%1* o, quintptr first, quintptr last) { | 715 | [](%1* o, quintptr first, quintptr last) { | ||
716 | o->dataChanged(o->createIndex(first, 0, first), | 716 | o->dataChanged(o->createIndex(first, 0, first), | ||
717 | o->createIndex(last, %2, last)); | 717 | o->createIndex(last, %2, last)); | ||
718 | }, | 718 | }, | ||
719 | [](%1* o) { | 719 | [](%1* o) { | ||
720 | o->beginResetModel(); | 720 | o->beginResetModel(); | ||
721 | }, | 721 | }, | ||
Show All 20 Lines | |||||
742 | } | 742 | } | ||
743 | )").arg(o.name, QString::number(o.columnCount - 1)); | 743 | )").arg(o.name, QString::number(o.columnCount - 1)); | ||
744 | } | 744 | } | ||
745 | if (o.type == ObjectType::Tree) { | 745 | if (o.type == ObjectType::Tree) { | ||
746 | cpp << QString(R"(, | 746 | cpp << QString(R"(, | ||
747 | [](const %1* o, option_quintptr id) { | 747 | [](const %1* o, option_quintptr id) { | ||
748 | if (id.some) { | 748 | if (id.some) { | ||
749 | int row = %2_row(o->m_d, id.value); | 749 | int row = %2_row(o->m_d, id.value); | ||
750 | emit o->newDataReady(o->createIndex(row, 0, id.value)); | 750 | Q_EMIT o->newDataReady(o->createIndex(row, 0, id.value)); | ||
751 | } else { | 751 | } else { | ||
752 | emit o->newDataReady(QModelIndex()); | 752 | Q_EMIT o->newDataReady(QModelIndex()); | ||
753 | } | 753 | } | ||
754 | }, | 754 | }, | ||
755 | [](%1* o) { | 755 | [](%1* o) { | ||
756 | emit o->layoutAboutToBeChanged(); | 756 | Q_EMIT o->layoutAboutToBeChanged(); | ||
757 | }, | 757 | }, | ||
758 | [](%1* o) { | 758 | [](%1* o) { | ||
759 | o->updatePersistentIndexes(); | 759 | o->updatePersistentIndexes(); | ||
760 | emit o->layoutChanged(); | 760 | Q_EMIT o->layoutChanged(); | ||
761 | }, | 761 | }, | ||
762 | [](%1* o, quintptr first, quintptr last) { | 762 | [](%1* o, quintptr first, quintptr last) { | ||
763 | quintptr frow = %2_row(o->m_d, first); | 763 | quintptr frow = %2_row(o->m_d, first); | ||
764 | quintptr lrow = %2_row(o->m_d, first); | 764 | quintptr lrow = %2_row(o->m_d, first); | ||
765 | o->dataChanged(o->createIndex(frow, 0, first), | 765 | o->dataChanged(o->createIndex(frow, 0, first), | ||
766 | o->createIndex(lrow, %3, last)); | 766 | o->createIndex(lrow, %3, last)); | ||
767 | }, | 767 | }, | ||
768 | [](%1* o) { | 768 | [](%1* o) { | ||
▲ Show 20 Lines • Show All 399 Lines • ▼ Show 20 Line(s) | 1167 | )"; | |||
1168 | } | 1168 | } | ||
1169 | 1169 | | |||
1170 | for (auto o: conf.objects) { | 1170 | for (auto o: conf.objects) { | ||
1171 | for (auto p: o.properties) { | 1171 | for (auto p: o.properties) { | ||
1172 | if (p.type.type == BindingType::Object) { | 1172 | if (p.type.type == BindingType::Object) { | ||
1173 | continue; | 1173 | continue; | ||
1174 | } | 1174 | } | ||
1175 | cpp << " inline void " << changedF(o, p) << "(" << o.name << "* o)\n"; | 1175 | cpp << " inline void " << changedF(o, p) << "(" << o.name << "* o)\n"; | ||
1176 | cpp << " {\n emit o->" << p.name << "Changed();\n }\n"; | 1176 | cpp << " {\n Q_EMIT o->" << p.name << "Changed();\n }\n"; | ||
1177 | } | 1177 | } | ||
1178 | } | 1178 | } | ||
1179 | cpp << "}\n"; | 1179 | cpp << "}\n"; | ||
1180 | 1180 | | |||
1181 | for (auto object: conf.objects) { | 1181 | for (auto object: conf.objects) { | ||
1182 | if (object.type != ObjectType::Object) { | 1182 | if (object.type != ObjectType::Object) { | ||
1183 | writeCppModel(cpp, object); | 1183 | writeCppModel(cpp, object); | ||
1184 | } | 1184 | } | ||
Show All 10 Lines |