ProjectExplorer: Add a ProjectConfiguration::target()

... with a suitable default implementation accessing a member
populated at construction time instead of walking the parent
chains on each access.

Change-Id: I58dae6da80ed0b023cc603fca13a5a205b123672
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
hjk
2019-07-26 16:08:13 +02:00
parent 8493a6b044
commit d16330de6d
16 changed files with 42 additions and 79 deletions

View File

@@ -24,6 +24,7 @@
****************************************************************************/
#include "projectconfiguration.h"
#include "target.h"
#include <utils/algorithm.h>
#include <utils/qtcassert.h>
@@ -86,10 +87,25 @@ ProjectConfiguration::ProjectConfiguration(QObject *parent, Core::Id id)
{
QTC_CHECK(id.isValid());
setObjectName(id.toString());
for (QObject *obj = this; obj; obj = obj->parent()) {
m_target = qobject_cast<Target *>(obj);
if (m_target != nullptr)
break;
}
// FIXME: Below triggers on 'real' Targets with this here a base class as it's
// not a real Target at this point of time. Plan is to cut this dependency and
// enable the check, for now the item is set manually in the Target ctor.
// QTC_CHECK(m_target);
}
ProjectConfiguration::~ProjectConfiguration() = default;
Project *ProjectConfiguration::project() const
{
return m_target->project();
}
Core::Id ProjectConfiguration::id() const
{
return m_id;
@@ -159,6 +175,12 @@ QVariantMap ProjectConfiguration::toMap() const
return map;
}
Target *ProjectConfiguration::target() const
{
return m_target;
}
bool ProjectConfiguration::fromMap(const QVariantMap &map)
{
Core::Id id = Core::Id::fromSetting(map.value(QLatin1String(CONFIGURATION_ID_KEY)));