diff --git a/file_templates/CMakeLists.txt b/file_templates/CMakeLists.txt --- a/file_templates/CMakeLists.txt +++ b/file_templates/CMakeLists.txt @@ -1,15 +1,19 @@ set(filetemplate_DIRS classes/cpp_basic classes/private_pointer - classes/qt_widget - classes/qobject - classes/qobject_pimpl classes/python_basic classes/c_gobject classes/c_gobject_private classes/c_gobject_properties classes/qt_shared classes/qt_interface + classes/qobject + classes/qobject_pimpl + classes/qabstractitemmodel + classes/qabstractitemmodel_pimpl + classes/qt_widget + classes/qwidget_pimpl + classes/qdialog classes/qdialog_pimpl testing/cpp_cpputest @@ -43,5 +47,10 @@ common/cpp_header.h common/cpp_header_onlyfunctions.h common/cpp_implementation.cpp + common/cpp_qobject_header.h + common/cpp_qobject_implementation.cpp + common/cpp_qobject_pimpl_header.h + common/cpp_qobject_pimpl_p_header.h + common/cpp_qobject_pimpl_implementation.cpp DESTINATION ${KDE_INSTALL_DATADIR}/kdevcodegen/templates ) diff --git a/file_templates/classes/qabstractitemmodel/class.h b/file_templates/classes/qabstractitemmodel/class.h new file mode 100644 --- /dev/null +++ b/file_templates/classes/qabstractitemmodel/class.h @@ -0,0 +1,22 @@ +{% extends "cpp_qobject_header.h" %} + + +{% block qobject_default_include %} +#include +{% endblock qobject_default_include %} + + +{% block qobject_baseclass %}QAbstractItemModel{% endblock qobject_baseclass %} + + +{% block qobject_body_header %} +{{ block.super }} +{% if add_roles_enum %} + + +public: + enum {{ roles_enum_name }} { + {{ first_role_name }} = Qt::UserRole + }; +{% endif %} +{% endblock qobject_body_header %} diff --git a/file_templates/classes/qabstractitemmodel/class.cpp b/file_templates/classes/qabstractitemmodel/class.cpp new file mode 100644 --- /dev/null +++ b/file_templates/classes/qabstractitemmodel/class.cpp @@ -0,0 +1 @@ +{% extends "cpp_qobject_implementation.cpp" %} diff --git a/file_templates/classes/qabstractitemmodel/options.kcfg b/file_templates/classes/qabstractitemmodel/options.kcfg new file mode 100644 --- /dev/null +++ b/file_templates/classes/qabstractitemmodel/options.kcfg @@ -0,0 +1,21 @@ + + + + + + + true + + + + Roles + + + + CustomRole + + + diff --git a/file_templates/classes/qabstractitemmodel/qabstractitemmodel.desktop b/file_templates/classes/qabstractitemmodel/qabstractitemmodel.desktop new file mode 100644 --- /dev/null +++ b/file_templates/classes/qabstractitemmodel/qabstractitemmodel.desktop @@ -0,0 +1,20 @@ +[General] +Name=QAbstractItemModel subclass +Comment=QAbstractItemModel subclass with properties +Category=C++/Qt +Language=C++ +Type=Class +BaseClasses=public QAbstractItemModel +Files=Header,Implementation +OptionsFile=options.kcfg + +[Header] +Name=Public Header +File=class.h +OutputFile={{ name }}.h + +[Implementation] +Name=Implementation +File=class.cpp +OutputFile={{ name }}.cpp + diff --git a/file_templates/classes/qabstractitemmodel_pimpl/class.h b/file_templates/classes/qabstractitemmodel_pimpl/class.h new file mode 100644 --- /dev/null +++ b/file_templates/classes/qabstractitemmodel_pimpl/class.h @@ -0,0 +1,22 @@ +{% extends "cpp_qobject_pimpl_header.h" %} + + +{% block qobject_default_include %} +#include +{% endblock qobject_default_include %} + + +{% block qobject_baseclass %}QAbstractItemModel{% endblock qobject_baseclass %} + + +{% block qobject_body_header %} +{{ block.super }} +{% if add_roles_enum %} + + +public: + enum {{ roles_enum_name }} { + {{ first_role_name }} = Qt::UserRole + }; +{% endif %} +{% endblock qobject_body_header %} diff --git a/file_templates/classes/qabstractitemmodel_pimpl/class.cpp b/file_templates/classes/qabstractitemmodel_pimpl/class.cpp new file mode 100644 --- /dev/null +++ b/file_templates/classes/qabstractitemmodel_pimpl/class.cpp @@ -0,0 +1 @@ +{% extends "cpp_qobject_pimpl_implementation.cpp" %} diff --git a/file_templates/classes/qabstractitemmodel_pimpl/class_p.h b/file_templates/classes/qabstractitemmodel_pimpl/class_p.h new file mode 100644 --- /dev/null +++ b/file_templates/classes/qabstractitemmodel_pimpl/class_p.h @@ -0,0 +1 @@ +{% extends "cpp_qobject_pimpl_p_header.h" %} diff --git a/file_templates/classes/qabstractitemmodel_pimpl/options.kcfg b/file_templates/classes/qabstractitemmodel_pimpl/options.kcfg new file mode 100644 --- /dev/null +++ b/file_templates/classes/qabstractitemmodel_pimpl/options.kcfg @@ -0,0 +1,21 @@ + + + + + + + true + + + + Roles + + + + CustomRole + + + diff --git a/file_templates/classes/qabstractitemmodel_pimpl/qabstractitemmodel_pimpl.desktop b/file_templates/classes/qabstractitemmodel_pimpl/qabstractitemmodel_pimpl.desktop new file mode 100644 --- /dev/null +++ b/file_templates/classes/qabstractitemmodel_pimpl/qabstractitemmodel_pimpl.desktop @@ -0,0 +1,24 @@ +[General] +Name=QAbstractItemModel pimpl subclass +Comment=QAbstractItemModel subclass with private implementation +Category=C++/Qt +Language=C++ +Type=Class +BaseClasses=public QAbstractItemModel +Files=Header,PrivateHeader,Implementation +OptionsFile=options.kcfg + +[Header] +Name=Header +File=class.h +OutputFile={{ name }}.h + +[PrivateHeader] +Name=Private Header +File=class_p.h +OutputFile={{ name }}_p.h + +[Implementation] +Name=Implementation +File=class.cpp +OutputFile={{ name }}.cpp diff --git a/file_templates/classes/qdialog/class.h b/file_templates/classes/qdialog/class.h new file mode 100644 --- /dev/null +++ b/file_templates/classes/qdialog/class.h @@ -0,0 +1,34 @@ +{% extends "cpp_qobject_header.h" %} + + +{% block qobject_default_include %} +#include +{% endblock qobject_default_include %} + + +{% block includes %} +{{ block.super }} +#include +{% endblock includes %} + + +{% block qobject_baseclass %}QDialog{% endblock qobject_baseclass %} + + +{% block forward_declarations %} +namespace Ui +{ +class {{ name }}; +} +{% endblock forward_declarations %} + + +{% block class_body %} +{{ block.super }} + +{% if not private_members and not private_functions %} + +private: +{% endif %} + QScopedPointer m_ui; +{% endblock class_body %} diff --git a/file_templates/classes/qdialog/class.cpp b/file_templates/classes/qdialog/class.cpp new file mode 100644 --- /dev/null +++ b/file_templates/classes/qdialog/class.cpp @@ -0,0 +1,29 @@ +{% extends "cpp_qobject_implementation.cpp" %} + + +{% block includes %} +{{ block.super }} +#include "ui_{{ output_file_ui|cut:".ui" }}.h" +{% endblock includes %} + + +{% block public_constructor_init_list %} + : m_ui(new Ui::{{ name }}) +{% endblock public_constructor_init_list %} + + +{% block public_constructor_body %} +{{ block.super }} + m_ui->setupUi(this); +{% endblock public_constructor_body %} + + +{% block protected_constructor_init_list %} + : m_ui(new Ui::{{ name }}) +{% endblock protected_constructor_init_list %} + + +{% block protected_constructor_body %} +{{ block.super }} + m_ui->setupUi(this); +{% endblock protected_constructor_body %} diff --git a/file_templates/classes/qdialog/class.ui b/file_templates/classes/qdialog/class.ui new file mode 100644 --- /dev/null +++ b/file_templates/classes/qdialog/class.ui @@ -0,0 +1,59 @@ +{% with namespaces|join:"::"|default:"::"|add:"::"|cut:"::::"|add:name as ns_prefixed_name %} + + + {{ ns_prefixed_name }} + + + + 0 + 0 + 520 + 300 + + + + {{ window_title }} + + + + + + Qt::Vertical + + + + + + + Qt::Horizontal + + +{% if "Close" == buttonset %} + QDialogButtonBox::Close +{% else %}{# default Ok/Cancel #} + QDialogButtonBox::Ok|QDialogButtonBox::Cancel +{% endif %} + + + + + + + +{% if "Ok/Cancel" == buttonset %} + + buttonBox + accepted() + {{ ns_prefixed_name }} + accept() + +{% endif %} + + buttonBox + rejected() + {{ ns_prefixed_name }} + reject() + + + +{% endwith %} diff --git a/file_templates/classes/qdialog/options.kcfg b/file_templates/classes/qdialog/options.kcfg new file mode 100644 --- /dev/null +++ b/file_templates/classes/qdialog/options.kcfg @@ -0,0 +1,21 @@ + + + + + + + {{ name }} + + + + + + + + Ok/Cancel + + + diff --git a/file_templates/classes/qdialog/qdialog.desktop b/file_templates/classes/qdialog/qdialog.desktop new file mode 100644 --- /dev/null +++ b/file_templates/classes/qdialog/qdialog.desktop @@ -0,0 +1,24 @@ +[General] +Name=Dialog with a UI File +Comment=QDialog subclass with a separate Qt Designer file +Category=C++/Qt +Language=C++ +Type=Class +BaseClasses=public QDialog +Files=Header,Implementation,UI +OptionsFile=options.kcfg + +[Header] +Name=Public Header +File=class.h +OutputFile={{ name }}.h + +[Implementation] +Name=Implementation +File=class.cpp +OutputFile={{ name }}.cpp + +[UI] +Name=User Interface +File=class.ui +OutputFile={{ name }}.ui diff --git a/file_templates/classes/qdialog_pimpl/class.h b/file_templates/classes/qdialog_pimpl/class.h --- a/file_templates/classes/qdialog_pimpl/class.h +++ b/file_templates/classes/qdialog_pimpl/class.h @@ -1,84 +1,9 @@ -{% extends "cpp_header.h" %} -{% load kdev_filters %} +{% extends "cpp_qobject_pimpl_header.h" %} -{% block includes %} -{{ block.super }} -{% if not base_classes %} -#include -{% endif %} -{% endblock includes %} - - -{% block forward_declarations %} -class {{ name }}Private; -{% endblock forward_declarations %} - - -{% block class_declaration_open %} -{% if base_classes %} -{{ block.super }} -{% else %} -{% include "class_declaration_apidox_cpp.txt" %} -class {{ name }} : public QDialog -{ -{% endif %} -{% endblock class_declaration_open %} - -{% block class_body %} - Q_OBJECT - {% for property in members %} - {% include "class_qproperty_declaration_cpp.txt" %} - {% endfor %} - - -{% if public_functions or members %} -public: -{% endif %} - {% for method in public_functions %} - - {% include "class_method_declaration_apidox_cpp.txt" %} - {% include "class_method_declaration_cpp.txt" %} - - {% endfor %} - - {% for property in members %} - - {% include "class_property_getter_declaration_apidox_cpp.txt" %} - {% include "class_property_getter_declaration_cpp.txt" %} - {% endfor %} - - -{% if members %} -public Q_SLOTS: - {% for property in members %} - - {% include "class_property_setter_declaration_apidox_cpp.txt" %} - {% include "class_property_setter_declaration_cpp.txt" %} - - {% endfor %} - -Q_SIGNALS: - {% for property in members %} - - {% include "class_property_signal_declaration_cpp.txt" %} - - {% endfor %} -{% endif %} - - -{% if protected_functions %} -protected: - {% for method in protected_functions %} - - {% include "class_method_declaration_apidox_cpp.txt" %} - {% include "class_method_declaration_cpp.txt" %} - - {% endfor %} -{% endif %} +{% block qobject_default_include %} +#include +{% endblock qobject_default_include %} -private: - {{ name }}Private* const d_ptr; - Q_DECLARE_PRIVATE({{ name }}) -{% endblock class_body %} +{% block qobject_baseclass %}QDialog{% endblock qobject_baseclass %} diff --git a/file_templates/classes/qdialog_pimpl/class.cpp b/file_templates/classes/qdialog_pimpl/class.cpp --- a/file_templates/classes/qdialog_pimpl/class.cpp +++ b/file_templates/classes/qdialog_pimpl/class.cpp @@ -1,95 +1,13 @@ -{% extends "cpp_implementation.cpp" %} -{% load kdev_filters %} +{% extends "cpp_qobject_pimpl_implementation.cpp" %} -{% block includes %} -#include "{{ output_file_header }}" -#include "{{ output_file_privateheader }}" -{% endblock includes %} - -{% block extra_definitions %} - -{% for method in private_functions %} -{% with name|add:"Private" as name %} - -{% include "method_definition_cpp.txt" %} -{ - {% if method.type %} - return {{ method.default_return_value }}; - {% endif %} -} - -{% endwith %} -{% endfor %} - -{% endblock extra_definitions %} - -{% block function_definitions %} - -{% for method in public_functions %} -{% with method.arguments as arguments %} - -{% include "method_definition_cpp.txt" %} -{% if method.isConstructor %} - : d_ptr(new {{ name }}Private()) -{% endif %} -{ - {% if method.isConstructor %} +{% block public_constructor_body %} +{{ block.super }} d_ptr->ui.setupUi(this); - {% endif %} - {% if method.isDestructor %} - delete d_ptr; - {% endif %} - {% if method.type %}return {{ method.default_return_value }}; - {% endif %} -} +{% endblock public_constructor_body %} -{% endwith %} -{% endfor %} -{% for method in protected_functions %} -{% with method.arguments as arguments %} - -{% include "method_definition_cpp.txt" %} -{% if method.isConstructor %} - : d_ptr(new {{ name }}Private()) -{% endif %} -{ - {% if method.isConstructor %} +{% block protected_constructor_body %} +{{ block.super }} d_ptr->ui.setupUi(this); - {% endif %} - {% if method.isDestructor %} - delete d_ptr; - {% endif %} - {% if method.type %}return {{ method.default_return_value }}; - {% endif %} -} - -{% endwith %} -{% endfor %} - -{% for property in members %} - - -{% include "class_property_getter_definition_cpp.txt" %} -{ - Q_D(const {{ name }}); - return d->{{ property.name }}; -} - - -{% include "class_property_setter_definition_cpp.txt" %} -{ - Q_D({{ name }}); - if (d->{{ property.name }} == {{ property.name }}) { - return; - } - - - d->{{ property.name }} = {{ property.name }}; - emit {{ property.name }}Changed(d->{{ property.name }}); -} - -{% endfor %} - -{% endblock function_definitions %} +{% endblock protected_constructor_body %} diff --git a/file_templates/classes/qdialog_pimpl/class_p.h b/file_templates/classes/qdialog_pimpl/class_p.h --- a/file_templates/classes/qdialog_pimpl/class_p.h +++ b/file_templates/classes/qdialog_pimpl/class_p.h @@ -1,45 +1,13 @@ -{% extends "cpp_header.h" %} -{% load kdev_filters %} - - -{% block include_guard_open %} -{% with "_P_H" as include_guard_suffix %} -#ifndef {% include "include_guard_cpp.txt" %} -#define {% include "include_guard_cpp.txt" %} -{% endwith %} -{% endblock include_guard_open %} +{% extends "cpp_qobject_pimpl_p_header.h" %} {% block includes %} #include "ui_{{ output_file_ui|cut:".ui" }}.h" {% endblock includes %} -{% block class_declaration_open %} -{% include "class_declaration_apidox_cpp.txt" %} -class {{ name }}Private -{ -{% endblock class_declaration_open %} - {% block class_body %} -public: - {% for method in private_functions %} - - {% include "class_method_declaration_apidox_cpp.txt" %} - {% include "class_method_declaration_cpp.txt" %} - - {% endfor %} - - {% for property in members %} - {{property.type}} {{property.name}}; - - {% endfor %} +{{ block.super }} Ui::{{ name }} ui; {% endblock class_body %} - -{% block include_guard_close %} -{% with "_P_H" as include_guard_suffix %} -#endif // {% include "include_guard_cpp.txt" %} -{% endwith %} -{% endblock include_guard_close %} diff --git a/file_templates/classes/qobject/class.h b/file_templates/classes/qobject/class.h --- a/file_templates/classes/qobject/class.h +++ b/file_templates/classes/qobject/class.h @@ -1,89 +1,9 @@ -{% extends "cpp_header.h" %} -{% load kdev_filters %} +{% extends "cpp_qobject_header.h" %} -{% block includes %} -{{ block.super }} -{% if not base_classes %} -#include -{% endif %} -{% endblock includes %} - - -{% block class_declaration_open %} -{% if base_classes %} -{{ block.super }} -{% else %} -{% include "class_declaration_apidox_cpp.txt" %} -class {{ name }} : public QObject -{ -{% endif %} -{% endblock class_declaration_open %} - -{% block class_body %} - Q_OBJECT - {% for property in members %} - {% include "class_qproperty_declaration_cpp.txt" %} - {% endfor %} - - -{% if public_functions or members %} -public: -{% endif %} - {% for method in public_functions %} - - {% include "class_method_declaration_apidox_cpp.txt" %} - {% include "class_method_declaration_cpp.txt" %} - - {% endfor %} - - {% for property in members %} - - {% include "class_property_getter_declaration_apidox_cpp.txt" %} - {% include "class_property_getter_declaration_cpp.txt" %} - - {% endfor %} - - -{% if members %} -public Q_SLOTS: - {% for property in members %} - {% include "class_property_setter_declaration_apidox_cpp.txt" %} - {% include "class_property_setter_declaration_cpp.txt" %} - - {% endfor %} - -Q_SIGNALS: - {% for property in members %} - - {% include "class_property_signal_declaration_cpp.txt" %} - - {% endfor %} -{% endif %} - - -{% if protected_functions %} -protected: - {% for method in protected_functions %} - - {% include "class_method_declaration_apidox_cpp.txt" %} - {% include "class_method_declaration_cpp.txt" %} - - {% endfor %} -{% endif %} - - -{% if private_functions or members %} -private: - {% for method in private_functions %} - - {% include "class_method_declaration_apidox_cpp.txt" %} - {% include "class_method_declaration_cpp.txt" %} +{% block qobject_default_include %} +#include +{% endblock qobject_default_include %} - {% endfor %} - {% for property in members %} - {{property.type}} m_{{property.name}}; - {% endfor %} -{% endif %} -{% endblock class_body %} +{% block qobject_baseclass %}QObject{% endblock qobject_baseclass %} diff --git a/file_templates/classes/qobject/class.cpp b/file_templates/classes/qobject/class.cpp --- a/file_templates/classes/qobject/class.cpp +++ b/file_templates/classes/qobject/class.cpp @@ -1,65 +1 @@ -{% extends "cpp_implementation.cpp" %} -{% load kdev_filters %} - -{% block extra_definitions %} - -{% for method in private_functions %} - -{% include "method_definition_cpp.txt" %} -{ - {% if method.type %} - return {{ method.default_return_value }}; - {% endif %} -} - -{% endfor %} - -{% endblock extra_definitions %} - -{% block function_definitions %} - -{% for method in public_functions %} - -{% include "method_definition_cpp.txt" %} -{ - {% if method.type %} - return {{ method.default_return_value }}; - {% endif %} -} - -{% endfor %} - -{% for method in protected_functions %} - -{% include "method_definition_cpp.txt" %} -{ - {% if method.type %} - return {{ method.default_return_value }}; - {% endif %} -} - -{% endfor %} - -{% for property in members %} - - -{% include "class_property_getter_definition_cpp.txt" %} -{ - return m_{{ property.name }}; -} - - -{% include "class_property_setter_definition_cpp.txt" %} -{ - if (m_{{ property.name }} == {{ property.name }}) { - return; - } - - - m_{{ property.name }} = {{ property.name }}; - emit {{ property.name }}Changed(m_{{ property.name }}); -} - -{% endfor %} - -{% endblock function_definitions %} +{% extends "cpp_qobject_implementation.cpp" %} diff --git a/file_templates/classes/qobject_pimpl/class.h b/file_templates/classes/qobject_pimpl/class.h --- a/file_templates/classes/qobject_pimpl/class.h +++ b/file_templates/classes/qobject_pimpl/class.h @@ -1,84 +1,9 @@ -{% extends "cpp_header.h" %} -{% load kdev_filters %} +{% extends "cpp_qobject_pimpl_header.h" %} -{% block includes %} -{{ block.super }} -{% if not base_classes %} -#include -{% endif %} -{% endblock includes %} - - -{% block forward_declarations %} -class {{ name }}Private; -{% endblock forward_declarations %} - - -{% block class_declaration_open %} -{% if base_classes %} -{{ block.super }} -{% else %} -{% include "class_declaration_apidox_cpp.txt" %} -class {{ name }} : public QObject -{ -{% endif %} -{% endblock class_declaration_open %} - -{% block class_body %} - Q_OBJECT - {% for property in members %} - {% include "class_qproperty_declaration_cpp.txt" %} - {% endfor %} - - -{% if public_functions or members %} -public: -{% endif %} - {% for method in public_functions %} - - {% include "class_method_declaration_apidox_cpp.txt" %} - {% include "class_method_declaration_cpp.txt" %} - - {% endfor %} - - {% for property in members %} - - {% include "class_property_getter_declaration_apidox_cpp.txt" %} - {% include "class_property_getter_declaration_cpp.txt" %} - {% endfor %} - - -{% if members %} -public Q_SLOTS: - {% for property in members %} - - {% include "class_property_setter_declaration_apidox_cpp.txt" %} - {% include "class_property_setter_declaration_cpp.txt" %} - - {% endfor %} - -Q_SIGNALS: - {% for property in members %} - - {% include "class_property_signal_declaration_cpp.txt" %} - - {% endfor %} -{% endif %} - - -{% if protected_functions %} -protected: - {% for method in protected_functions %} - - {% include "class_method_declaration_apidox_cpp.txt" %} - {% include "class_method_declaration_cpp.txt" %} - - {% endfor %} -{% endif %} +{% block qobject_default_include %} +#include +{% endblock qobject_default_include %} -private: - {{ name }}Private* const d_ptr; - Q_DECLARE_PRIVATE({{ name }}) -{% endblock class_body %} +{% block qobject_baseclass %}QObject{% endblock qobject_baseclass %} diff --git a/file_templates/classes/qobject_pimpl/class.cpp b/file_templates/classes/qobject_pimpl/class.cpp --- a/file_templates/classes/qobject_pimpl/class.cpp +++ b/file_templates/classes/qobject_pimpl/class.cpp @@ -1,103 +1 @@ -{% extends "cpp_implementation.cpp" %} -{% load kdev_filters %} - -{% block includes %} -#include "{{ output_file_header }}" -#include "{{ output_file_privateheader }}" -{% endblock includes %} - - -{% block extra_definitions %} - -{% for method in private_functions %} -{% with name|add:"Private" as name %} - -{% include "method_definition_cpp.txt" %} -{ - {% if method.type %} - return {{ method.default_return_value }}; - {% endif %} -} - -{% endwith %} -{% endfor %} - -{% endblock extra_definitions %} - -{% block function_definitions %} - -{% for method in public_functions %} -{% with method.arguments as arguments %} - -{% include "method_definition_cpp.txt" %} -{% if method.isConstructor %} - {% with arguments|first as argFirst %} - {# copy constructor? #} - {% if arguments|length == 1 and argFirst.type == method.name|arg_type %} - : d_ptr(new {{ name }}Private(*{{ argFirst.name }}.d_ptr)) - {% else %} - : d_ptr(new {{ name }}Private()) - {% endif %} - {% endwith %} -{% endif %} -{ - {% if method.isDestructor %} - delete d_ptr; - {% endif %} - {% if method.type %}return {{ method.default_return_value }}; - {% endif %} -} - -{% endwith %} -{% endfor %} - -{% for method in protected_functions %} -{% with method.arguments as arguments %} - -{% include "method_definition_cpp.txt" %} -{% if method.isConstructor %} - {% with arguments|first as argFirst %} - {# copy constructor? #} - {% if arguments|length == 1 and argFirst.type == method.name|arg_type %} - : d_ptr(new {{ name }}Private(*{{ argFirst.name }}.d_ptr)) - {% else %} - : d_ptr(new {{ name }}Private()) - {% endif %} - {% endwith %} -{% endif %} -{ - {% if method.isDestructor %} - delete d_ptr; - {% endif %} - {% if method.type %}return {{ method.default_return_value }}; - {% endif %} -} - -{% endwith %} -{% endfor %} - -{% for property in members %} - - -{% include "class_property_getter_definition_cpp.txt" %} -{ - Q_D(const {{ name }}); - return d->{{ property.name }}; -} - - -{% include "class_property_setter_definition_cpp.txt" %} -{ - Q_D({{ name }}); - if (d->{{ property.name }} == {{ property.name }}) { - return; - } - - - d->{{ property.name }} = {{ property.name }}; - emit {{ property.name }}Changed(d->{{ property.name }}); -} - -{% endfor %} - -{% endblock function_definitions %} +{% extends "cpp_qobject_pimpl_implementation.cpp" %} diff --git a/file_templates/classes/qobject_pimpl/class_p.h b/file_templates/classes/qobject_pimpl/class_p.h --- a/file_templates/classes/qobject_pimpl/class_p.h +++ b/file_templates/classes/qobject_pimpl/class_p.h @@ -1,43 +1 @@ -{% extends "cpp_header.h" %} -{% load kdev_filters %} - - -{% block include_guard_open %} -{% with "_P_H" as include_guard_suffix %} -#ifndef {% include "include_guard_cpp.txt" %} -#define {% include "include_guard_cpp.txt" %} -{% endwith %} -{% endblock include_guard_open %} - - -{% block includes %} -{% endblock includes %} - - -{% block class_declaration_open %} -{% include "class_declaration_apidox_cpp.txt" %} -class {{ name }}Private -{ -{% endblock class_declaration_open %} - -{% block class_body %} -{% if members or private_functions %} -public: - {% for method in private_functions %} - - {% include "class_method_declaration_apidox_cpp.txt" %} - {% include "class_method_declaration_cpp.txt" %} - - {% endfor %} - - {% for property in members %} - {{property.type}} {{property.name}}; - {% endfor %} -{% endif %} -{% endblock class_body %} - -{% block include_guard_close %} -{% with "_P_H" as include_guard_suffix %} -#endif // {% include "include_guard_cpp.txt" %} -{% endwith %} -{% endblock include_guard_close %} +{% extends "cpp_qobject_pimpl_p_header.h" %} diff --git a/file_templates/classes/qt_widget/class.h b/file_templates/classes/qt_widget/class.h --- a/file_templates/classes/qt_widget/class.h +++ b/file_templates/classes/qt_widget/class.h @@ -1,20 +1,34 @@ -{% extends "cpp_header.h" %} +{% extends "cpp_qobject_header.h" %} + + +{% block qobject_default_include %} +#include +{% endblock qobject_default_include %} + + +{% block includes %} +{{ block.super }} +#include +{% endblock includes %} + + +{% block qobject_baseclass %}QWidget{% endblock qobject_baseclass %} + + {% block forward_declarations %} namespace Ui { class {{ name }}; } {% endblock forward_declarations %} -{% block class_body %} - Q_OBJECT - +{% block class_body %} {{ block.super }} - {% if not private_members and not private_functions %} + private: {% endif %} - Ui::{{ name }}* ui; + QScopedPointer m_ui; {% endblock class_body %} diff --git a/file_templates/classes/qt_widget/class.cpp b/file_templates/classes/qt_widget/class.cpp --- a/file_templates/classes/qt_widget/class.cpp +++ b/file_templates/classes/qt_widget/class.cpp @@ -1,26 +1,29 @@ -{% extends "cpp_implementation.cpp" %} +{% extends "cpp_qobject_implementation.cpp" %} + {% block includes %} -#include "{{ output_file_header }}" +{{ block.super }} #include "ui_{{ output_file_ui|cut:".ui" }}.h" {% endblock includes %} -{% block function_definitions %} -{% for method in functions %} - -{% with method.internal_methods as arguments %} - -{% include "method_definition_cpp.txt" %} -{ - {% if method.isConstructor %} - ui = new Ui::{{ name }}; - ui->setupUi(this); - {% endif %} - {% if method.isDestructor %} - delete ui; - {% endif %} -} - -{% endwith %} -{% endfor %} -{% endblock function_definitions %} + +{% block public_constructor_init_list %} + : m_ui(new Ui::{{ name }}) +{% endblock public_constructor_init_list %} + + +{% block public_constructor_body %} +{{ block.super }} + m_ui->setupUi(this); +{% endblock public_constructor_body %} + + +{% block protected_constructor_init_list %} + : m_ui(new Ui::{{ name }}) +{% endblock protected_constructor_init_list %} + + +{% block protected_constructor_body %} +{{ block.super }} + m_ui->setupUi(this); +{% endblock protected_constructor_body %} diff --git a/file_templates/classes/qwidget_pimpl/class.h b/file_templates/classes/qwidget_pimpl/class.h new file mode 100644 --- /dev/null +++ b/file_templates/classes/qwidget_pimpl/class.h @@ -0,0 +1,7 @@ +{% extends "cpp_qobject_pimpl_header.h" %} + +{% block qobject_default_include %} +#include +{% endblock qobject_default_include %} + +{% block qobject_baseclass %}QWidget{% endblock qobject_baseclass %} diff --git a/file_templates/classes/qwidget_pimpl/class.cpp b/file_templates/classes/qwidget_pimpl/class.cpp new file mode 100644 --- /dev/null +++ b/file_templates/classes/qwidget_pimpl/class.cpp @@ -0,0 +1,13 @@ +{% extends "cpp_qobject_pimpl_implementation.cpp" %} + + +{% block public_constructor_body %} +{{ block.super }} + d_ptr->ui.setupUi(this); +{% endblock public_constructor_body %} + + +{% block protected_constructor_body %} +{{ block.super }} + d_ptr->ui.setupUi(this); +{% endblock protected_constructor_body %} diff --git a/file_templates/classes/qwidget_pimpl/class.ui b/file_templates/classes/qwidget_pimpl/class.ui new file mode 100644 --- /dev/null +++ b/file_templates/classes/qwidget_pimpl/class.ui @@ -0,0 +1,18 @@ +{% with namespaces|join:"::"|default:"::"|add:"::"|cut:"::::"|add:name as ns_prefixed_name %} + + + {{ ns_prefixed_name }} + + + + 0 + 0 + 400 + 300 + + + + + + +{% endwith %} diff --git a/file_templates/classes/qwidget_pimpl/class_p.h b/file_templates/classes/qwidget_pimpl/class_p.h new file mode 100644 --- /dev/null +++ b/file_templates/classes/qwidget_pimpl/class_p.h @@ -0,0 +1,13 @@ +{% extends "cpp_qobject_pimpl_p_header.h" %} + + +{% block includes %} +#include "ui_{{ output_file_ui|cut:".ui" }}.h" +{% endblock includes %} + + +{% block class_body %} +{{ block.super }} + + Ui::{{ name }} ui; +{% endblock class_body %} diff --git a/file_templates/classes/qwidget_pimpl/qwidget_pimpl.desktop b/file_templates/classes/qwidget_pimpl/qwidget_pimpl.desktop new file mode 100644 --- /dev/null +++ b/file_templates/classes/qwidget_pimpl/qwidget_pimpl.desktop @@ -0,0 +1,28 @@ +[General] +Name=Widget (pimpl) with a UI File +Comment=QWidget subclass with a separate Qt Designer file and private implementation +Category=C++/Qt +Language=C++ +Type=Class +BaseClasses=public QWidget +Files=Header,PrivateHeader,Implementation,UI + +[Header] +Name=Public Header +File=class.h +OutputFile={{ name }}.h + +[PrivateHeader] +Name=Private Header +File=class_p.h +OutputFile={{ name }}_p.h + +[Implementation] +Name=Implementation +File=class.cpp +OutputFile={{ name }}.cpp + +[UI] +Name=User Interface +File=class.ui +OutputFile={{ name }}.ui diff --git a/file_templates/classes/qobject/class.h b/file_templates/common/cpp_qobject_header.h copy from file_templates/classes/qobject/class.h copy to file_templates/common/cpp_qobject_header.h --- a/file_templates/classes/qobject/class.h +++ b/file_templates/common/cpp_qobject_header.h @@ -1,10 +1,10 @@ {% extends "cpp_header.h" %} -{% load kdev_filters %} {% block includes %} {{ block.super }} {% if not base_classes %} -#include +{% block qobject_default_include %} +{% endblock qobject_default_include %} {% endif %} {% endblock includes %} @@ -14,16 +14,18 @@ {{ block.super }} {% else %} {% include "class_declaration_apidox_cpp.txt" %} -class {{ name }} : public QObject +class {{ name }} : public {% block qobject_baseclass %}QObject{% endblock qobject_baseclass %} { {% endif %} {% endblock class_declaration_open %} {% block class_body %} +{% block qobject_body_header %} Q_OBJECT {% for property in members %} {% include "class_qproperty_declaration_cpp.txt" %} {% endfor %} +{% endblock qobject_body_header %} {% if public_functions or members %} @@ -81,8 +83,8 @@ {% include "class_method_declaration_cpp.txt" %} {% endfor %} - {% for property in members %} + {{property.type}} m_{{property.name}}; {% endfor %} {% endif %} diff --git a/file_templates/classes/qobject/class.cpp b/file_templates/common/cpp_qobject_implementation.cpp copy from file_templates/classes/qobject/class.cpp copy to file_templates/common/cpp_qobject_implementation.cpp --- a/file_templates/classes/qobject/class.cpp +++ b/file_templates/common/cpp_qobject_implementation.cpp @@ -1,43 +1,31 @@ {% extends "cpp_implementation.cpp" %} -{% load kdev_filters %} -{% block extra_definitions %} - -{% for method in private_functions %} - -{% include "method_definition_cpp.txt" %} -{ - {% if method.type %} - return {{ method.default_return_value }}; - {% endif %} -} - -{% endfor %} - -{% endblock extra_definitions %} {% block function_definitions %} {% for method in public_functions %} +{% with method.arguments as arguments %} {% include "method_definition_cpp.txt" %} +{% if method.isConstructor %} +{% block public_constructor_init_list %} +{% endblock public_constructor_init_list %} +{% endif %} { - {% if method.type %} - return {{ method.default_return_value }}; - {% endif %} -} - -{% endfor %} - -{% for method in protected_functions %} - -{% include "method_definition_cpp.txt" %} -{ - {% if method.type %} +{% block public_method_body %} + {% if method.isConstructor %} +{% block public_constructor_body %} +{% endblock public_constructor_body %} + {% elif method.isDestructor %} +{% block public_destructor_body %} +{% endblock public_destructor_body %} + {% elif method.type %} return {{ method.default_return_value }}; {% endif %} +{% endblock public_method_body %} } +{% endwith %} {% endfor %} {% for property in members %} @@ -62,4 +50,39 @@ {% endfor %} +{% for method in protected_functions %} +{% with method.arguments as arguments %} + +{% include "method_definition_cpp.txt" %} +{% if method.isConstructor %} +{% block protected_constructor_init_list %} +{% endblock protected_constructor_init_list %} +{% endif %} +{ +{% block protected_method_body %} + {% if method.isConstructor %} +{% block protected_constructor_body %} +{% endblock protected_constructor_body %} + {% elif method.isDestructor %} +{% block protected_destructor_body %} +{% endblock protected_destructor_body %} + {% elif method.type %} + return {{ method.default_return_value }}; + {% endif %} +{% endblock protected_method_body %} +} + +{% endwith %} +{% endfor %} + +{% for method in private_functions %} + +{% include "method_definition_cpp.txt" %} +{ + {% if method.type %} + return {{ method.default_return_value }}; + {% endif %} +} + +{% endfor %} {% endblock function_definitions %} diff --git a/file_templates/classes/qobject_pimpl/class.h b/file_templates/common/cpp_qobject_pimpl_header.h copy from file_templates/classes/qobject_pimpl/class.h copy to file_templates/common/cpp_qobject_pimpl_header.h --- a/file_templates/classes/qobject_pimpl/class.h +++ b/file_templates/common/cpp_qobject_pimpl_header.h @@ -1,10 +1,10 @@ {% extends "cpp_header.h" %} -{% load kdev_filters %} {% block includes %} {{ block.super }} {% if not base_classes %} -#include +{% block qobject_default_include %} +{% endblock qobject_default_include %} {% endif %} {% endblock includes %} @@ -19,16 +19,19 @@ {{ block.super }} {% else %} {% include "class_declaration_apidox_cpp.txt" %} -class {{ name }} : public QObject +class {{ name }} : public {% block qobject_baseclass %}QObject{% endblock qobject_baseclass %} { {% endif %} {% endblock class_declaration_open %} + {% block class_body %} +{% block qobject_body_header %} Q_OBJECT {% for property in members %} {% include "class_qproperty_declaration_cpp.txt" %} {% endfor %} +{% endblock qobject_body_header %} {% if public_functions or members %} diff --git a/file_templates/classes/qobject_pimpl/class.cpp b/file_templates/common/cpp_qobject_pimpl_implementation.cpp copy from file_templates/classes/qobject_pimpl/class.cpp copy to file_templates/common/cpp_qobject_pimpl_implementation.cpp --- a/file_templates/classes/qobject_pimpl/class.cpp +++ b/file_templates/common/cpp_qobject_pimpl_implementation.cpp @@ -1,8 +1,9 @@ {% extends "cpp_implementation.cpp" %} {% load kdev_filters %} + {% block includes %} -#include "{{ output_file_header }}" +{{ block.super }} #include "{{ output_file_privateheader }}" {% endblock includes %} @@ -24,6 +25,7 @@ {% endblock extra_definitions %} + {% block function_definitions %} {% for method in public_functions %} @@ -41,36 +43,18 @@ {% endwith %} {% endif %} { - {% if method.isDestructor %} - delete d_ptr; - {% endif %} - {% if method.type %}return {{ method.default_return_value }}; - {% endif %} -} - -{% endwith %} -{% endfor %} - -{% for method in protected_functions %} -{% with method.arguments as arguments %} - -{% include "method_definition_cpp.txt" %} -{% if method.isConstructor %} - {% with arguments|first as argFirst %} - {# copy constructor? #} - {% if arguments|length == 1 and argFirst.type == method.name|arg_type %} - : d_ptr(new {{ name }}Private(*{{ argFirst.name }}.d_ptr)) - {% else %} - : d_ptr(new {{ name }}Private()) - {% endif %} - {% endwith %} -{% endif %} -{ - {% if method.isDestructor %} +{% block public_method_body %} + {% if method.isConstructor %} +{% block public_constructor_body %} +{% endblock public_constructor_body %} + {% elif method.isDestructor %} +{% block public_destructor_body %} delete d_ptr; +{% endblock public_destructor_body %} + {% elif method.type %} + return {{ method.default_return_value }}; {% endif %} - {% if method.type %}return {{ method.default_return_value }}; - {% endif %} +{% endblock public_method_body %} } {% endwith %} @@ -100,4 +84,36 @@ {% endfor %} +{% for method in protected_functions %} +{% with method.arguments as arguments %} + +{% include "method_definition_cpp.txt" %} +{% if method.isConstructor %} + {% with arguments|first as argFirst %} + {# copy constructor? #} + {% if arguments|length == 1 and argFirst.type == method.name|arg_type %} + : d_ptr(new {{ name }}Private(*{{ argFirst.name }}.d_ptr)) + {% else %} + : d_ptr(new {{ name }}Private()) + {% endif %} + {% endwith %} +{% endif %} +{ +{% block protected_method_body %} + {% if method.isConstructor %} +{% block protected_constructor_body %} +{% endblock protected_constructor_body %} + {% elif method.isDestructor %} +{% block protected_destructor_body %} + delete d_ptr; +{% endblock protected_destructor_body %} + {% elif method.type %} + return {{ method.default_return_value }}; + {% endif %} +{% endblock protected_method_body %} +} + +{% endwith %} +{% endfor %} + {% endblock function_definitions %} diff --git a/file_templates/classes/qobject_pimpl/class_p.h b/file_templates/common/cpp_qobject_pimpl_p_header.h copy from file_templates/classes/qobject_pimpl/class_p.h copy to file_templates/common/cpp_qobject_pimpl_p_header.h --- a/file_templates/classes/qobject_pimpl/class_p.h +++ b/file_templates/common/cpp_qobject_pimpl_p_header.h @@ -1,5 +1,4 @@ {% extends "cpp_header.h" %} -{% load kdev_filters %} {% block include_guard_open %} @@ -10,32 +9,28 @@ {% endblock include_guard_open %} -{% block includes %} -{% endblock includes %} - - {% block class_declaration_open %} {% include "class_declaration_apidox_cpp.txt" %} class {{ name }}Private { {% endblock class_declaration_open %} + {% block class_body %} -{% if members or private_functions %} public: {% for method in private_functions %} {% include "class_method_declaration_apidox_cpp.txt" %} {% include "class_method_declaration_cpp.txt" %} {% endfor %} - {% for property in members %} + {{property.type}} {{property.name}}; {% endfor %} -{% endif %} {% endblock class_body %} + {% block include_guard_close %} {% with "_P_H" as include_guard_suffix %} #endif // {% include "include_guard_cpp.txt" %}