Skip to content

Commit

Permalink
coding style
Browse files Browse the repository at this point in the history
  • Loading branch information
Tectu committed Oct 9, 2023
1 parent e2b351b commit f0006e3
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions cppproperties/qt_widgets/factory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,38 @@ namespace tct::properties::qt_widgets
{
private:
template<typename T>
[[nodiscard]] static bool is_type(property_base* pb)
[[nodiscard]]
static
bool
is_type(property_base* pb)
{
return dynamic_cast<property<T>*>(pb) != nullptr;
}

template<typename T_raw, typename T_editor>
[[nodiscard]] static std::unique_ptr<QWidget> build_widget(property_base* pb)
[[nodiscard]]
static
std::unique_ptr<QWidget> build_widget(property_base* pb)
{
// Make sure the editor can handle this type
static_assert(std::is_same_v<T_raw, typename T_editor::type>);

// Convert to property<T>*
property<T_raw>* p = dynamic_cast<property<T_raw>*>(pb);
if (not p)
if (!p)
return nullptr;

return std::make_unique<T_editor>(*p);
}

public:
[[nodiscard]] static std::unique_ptr<QWidget> build_widget(property_base* pb)
[[nodiscard]]
static
std::unique_ptr<QWidget>
build_widget(property_base* pb)
{
// Sanity check
if (not pb)
if (!pb)
return nullptr;

// Get the appropriate widget
Expand All @@ -55,7 +63,9 @@ namespace tct::properties::qt_widgets
return nullptr;
}

[[nodiscard]] static std::unique_ptr<QWidget> build_form(tct::properties::properties& p)
[[nodiscard]]
static
std::unique_ptr<QWidget> build_form(tct::properties::properties& p)
{
// Layout
QFormLayout* layout = new QFormLayout;
Expand All @@ -64,15 +74,14 @@ namespace tct::properties::qt_widgets
std::unique_ptr<QWidget> w;
{
// Nested?
if (auto n = p.get_nested_properties(property_name); n) {
if (auto n = p.get_nested_properties(property_name); n)
w = std::make_unique<nested>();
}

// Regular property
else
w = build_widget(property_value);
}
if (not w)
if (!w)
w = std::make_unique<QWidget>();

// Add to layout
Expand All @@ -88,4 +97,3 @@ namespace tct::properties::qt_widgets
};

}

0 comments on commit f0006e3

Please sign in to comment.