コード例 #1
0
ファイル: factory-method.cpp プロジェクト: respu/injeqt
factory_method make_factory_method(const types_by_name &known_types, const type &t, const type &f)
{
	assert(!t.is_empty());
	assert(!t.is_qobject());
	assert(!f.is_empty());
	assert(!f.is_qobject());

	auto meta_object = f.meta_object();
	auto method_count = meta_object->methodCount();
	auto factory_methods = std::vector<factory_method>{};

	for (decltype(method_count) i = 0; i < method_count; i++)
	{
		auto method = meta_object->method(i);
		if (method.parameterCount() != 0)
			continue;
		auto return_type = type_by_pointer(known_types, method.typeName());
		if (return_type.is_empty())
			continue;
		auto interfaces = extract_interfaces(return_type);
		if (interfaces.contains(t))
			factory_methods.emplace_back(return_type, method);
	}

	if (factory_methods.size() == 1)
		return factory_methods.front();
	else
		return factory_method{};
}
コード例 #2
0
void getMeta(const QObject* object, QTextStream& output) {
    const auto metaObject = object->metaObject();
    // properties
    const auto propertyCount = metaObject->propertyCount();
    for (int i = 0; i < propertyCount; i++) {
        const auto property = metaObject->property(i);

        if (QString(property.typeName()).endsWith("*")) {
            const auto propertyObject = object->property(property.name());
            getMeta(qvariant_cast<QObject*>(propertyObject), output);
            output << "Object" << " "
            << property.typeName() << " "
            << qPrintable(QString(metaObject->className()) + "::" + property.name())
            << endl;
        } else {
            output << "Property" << " "
            << property.typeName() << " "
            << qPrintable(QString(metaObject->className()) + "::" + property.name())
            << endl;
        }
    }

    // methods
    const auto methodCount = metaObject->methodCount();
    for (int i = 0; i < methodCount; i++) {
        const auto method = metaObject->method(i);
        switch (method.methodType()) {
            case QMetaMethod::Slot: {
                if (method.access() == QMetaMethod::Public) {
                    output << "Slot" << " "
                    << method.typeName() << " "
                    << qPrintable(QString(metaObject->className()) + "::" + method.methodSignature().constData())
                    << endl;
                }
                break;
            }
            case QMetaMethod::Signal: {
                output << "Signal" << " "
                << method.typeName() << " "
                << qPrintable(QString(metaObject->className()) + "::" + method.methodSignature().constData())
                << endl;
                break;
            }
            default: {

            }
        }
    }
}
コード例 #3
0
ファイル: action-method.cpp プロジェクト: ovz/injeqt
std::vector<action_method> extract_actions(const std::string &action_tag, const type &for_type)
{
	assert(!for_type.is_empty());

	auto result = std::vector<action_method>{};

	auto meta_object = for_type.meta_object();
	auto method_count = meta_object->methodCount();
	for (decltype(method_count) i = 0; i < method_count; i++)
	{
		auto probably_action = meta_object->method(i);
		auto method_tag = std::string{probably_action.tag()};
		if (action_tag == method_tag)
			result.emplace_back(make_action_method(probably_action));
	}

	return result;
}