diff --git a/app/common/qtutils.h b/app/common/qtutils.h index 122a5022c..fee21e596 100644 --- a/app/common/qtutils.h +++ b/app/common/qtutils.h @@ -64,6 +64,21 @@ public: static QStringList WordWrapString(const QString &s, const QFontMetrics &fm, int bounding_width); + template + static T *GetParentOfType(const QObject *child) + { + QObject *t = child->parent(); + + while (t) { + if (T *p = dynamic_cast(t)) { + return p; + } + t = t->parent(); + } + + return nullptr; + } + }; } diff --git a/app/node/project/project.cpp b/app/node/project/project.cpp index 4cf192643..b84c8ee22 100644 --- a/app/node/project/project.cpp +++ b/app/node/project/project.cpp @@ -23,6 +23,7 @@ #include #include +#include "common/qtutils.h" #include "common/xmlutils.h" #include "core.h" #include "dialog/progress/progress.h" @@ -173,16 +174,7 @@ void Project::RegenerateUuid() Project *Project::GetProjectFromObject(const QObject *o) { - QObject *t = o->parent(); - - while (t) { - if (Project *p = dynamic_cast(t)) { - return p; - } - t = t->parent(); - } - - return nullptr; + return QtUtils::GetParentOfType(o); } void Project::ColorManagerValueChanged(const NodeInput &input, const TimeRange &range)