diff --git a/file_templates/CMakeLists.txt b/file_templates/CMakeLists.txt --- a/file_templates/CMakeLists.txt +++ b/file_templates/CMakeLists.txt @@ -10,6 +10,7 @@ classes/c_gobject_properties classes/qt_shared classes/qt_interface + classes/qdialog_pimpl testing/cpp_cpputest testing/cpp_gtest diff --git a/file_templates/classes/qdialog_pimpl/class.h b/file_templates/classes/qdialog_pimpl/class.h new file mode 100644 --- /dev/null +++ b/file_templates/classes/qdialog_pimpl/class.h @@ -0,0 +1,84 @@ +{% extends "cpp_header.h" %} +{% load kdev_filters %} + +{% 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 %} + + +private: + {{ name }}Private* const d_ptr; + Q_DECLARE_PRIVATE({{ name }}) +{% endblock class_body %} diff --git a/file_templates/classes/qdialog_pimpl/class.cpp b/file_templates/classes/qdialog_pimpl/class.cpp new file mode 100644 --- /dev/null +++ b/file_templates/classes/qdialog_pimpl/class.cpp @@ -0,0 +1,95 @@ +{% 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 %} + : d_ptr(new {{ name }}Private()) +{% endif %} +{ + {% if method.isConstructor %} + 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 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 %} + 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 %} diff --git a/file_templates/classes/qdialog_pimpl/class.ui b/file_templates/classes/qdialog_pimpl/class.ui new file mode 100644 --- /dev/null +++ b/file_templates/classes/qdialog_pimpl/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_pimpl/class_p.h b/file_templates/classes/qdialog_pimpl/class_p.h new file mode 100644 --- /dev/null +++ b/file_templates/classes/qdialog_pimpl/class_p.h @@ -0,0 +1,45 @@ +{% 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 %} +#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 %} + + 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/qdialog_pimpl/options.kcfg b/file_templates/classes/qdialog_pimpl/options.kcfg new file mode 100644 --- /dev/null +++ b/file_templates/classes/qdialog_pimpl/options.kcfg @@ -0,0 +1,21 @@ + + + + + + + {{ name }} + + + + + + + + Ok/Cancel + + + diff --git a/file_templates/classes/qdialog_pimpl/qdialog_pimpl.desktop b/file_templates/classes/qdialog_pimpl/qdialog_pimpl.desktop new file mode 100644 --- /dev/null +++ b/file_templates/classes/qdialog_pimpl/qdialog_pimpl.desktop @@ -0,0 +1,29 @@ +[General] +Name=Dialog (pimpl) with a UI File +Comment=QDialog subclass with a separate Qt Designer file and private implementation +Category=C++/Qt +Language=C++ +Type=Class +BaseClasses=public QDialog +Files=Header,PrivateHeader,Implementation,UI +OptionsFile=options.kcfg + +[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