Commit 35086852 authored by Tobias Hunger's avatar Tobias Hunger

Fix profile name generation

Pick better names for similar profiles that should share a name. This
happens a lot when e.g. importing existing projects.

Task-number: QTCREATORBUG-7676
Change-Id: I57a8c16828edc59d1c1a32f3e12785c25a4555da
Reviewed-by: Orgad Shaneh's avatarOrgad Shaneh <orgads@gmail.com>
Reviewed-by: default avatarTobias Hunger <tobias.hunger@nokia.com>
parent 09d5f45f
......@@ -101,11 +101,14 @@ Profile::~Profile()
delete d;
}
Profile *Profile::clone() const
Profile *Profile::clone(bool keepName) const
{
Profile *p = new Profile;
p->d->m_displayName = QCoreApplication::translate("ProjectExplorer::Profile", "Clone of %1")
.arg(d->m_displayName);
if (keepName)
p->d->m_displayName = d->m_displayName;
else
p->d->m_displayName = QCoreApplication::translate("ProjectExplorer::Profile", "Clone of %1")
.arg(d->m_displayName);
p->d->m_autodetected = false;
p->d->m_data = d->m_data;
p->d->m_isValid = d->m_isValid;
......@@ -133,20 +136,45 @@ QString Profile::displayName() const
return d->m_displayName;
}
static QString candidateName(const QString &name, const QString &postfix)
{
if (name.contains(postfix))
return QString();
return name + QLatin1Char('-') + postfix;
}
void Profile::setDisplayName(const QString &name)
{
// make name unique:
ProfileManager *pm = ProfileManager::instance();
QList<ProfileInformation *> profileInfo = pm->profileInformation();
QStringList nameList;
foreach (Profile *p, ProfileManager::instance()->profiles())
foreach (Profile *p, pm->profiles()) {
nameList << p->displayName();
foreach (ProfileInformation *pi, profileInfo) {
const QString postfix = pi->displayNamePostfix(p);
if (!postfix.isEmpty())
nameList << candidateName(p->displayName(), postfix);
}
}
QStringList candidateNames;
candidateNames << name;
foreach (ProfileInformation *pi, profileInfo) {
const QString postfix = pi->displayNamePostfix(this);
if (!postfix.isEmpty())
candidateNames << candidateName(name, postfix);
}
QString uniqueName = Project::makeUnique(name, nameList);
if (uniqueName != name) {
ToolChain *tc = ToolChainProfileInformation::toolChain(this);
if (tc) {
const QString tcPostfix = QString::fromLatin1("-%1").arg(tc->displayName());
if (!name.contains(tcPostfix))
uniqueName = Project::makeUnique(name + tcPostfix, nameList);
foreach (const QString &candidate, candidateNames) {
const QString tmp = Project::makeUnique(candidate, nameList);
if (tmp == candidate) {
uniqueName = tmp;
break;
}
}
}
......
......@@ -82,7 +82,7 @@ public:
void addToEnvironment(Utils::Environment &env) const;
QString toHtml();
Profile *clone() const;
Profile *clone(bool keepName = false) const;
private:
// Unimplemented.
......
......@@ -178,6 +178,12 @@ ProfileConfigWidget *ToolChainProfileInformation::createConfigWidget(Profile *p)
return new Internal::ToolChainInformationConfigWidget(p);
}
QString ToolChainProfileInformation::displayNamePostfix(const Profile *p) const
{
ToolChain *tc = toolChain(p);
return tc ? tc->displayName() : QString();
}
ProfileInformation::ItemList ToolChainProfileInformation::toUserOutput(Profile *p) const
{
ToolChain *tc = toolChain(p);
......@@ -327,6 +333,12 @@ ProfileConfigWidget *DeviceProfileInformation::createConfigWidget(Profile *p) co
return new Internal::DeviceInformationConfigWidget(p);
}
QString DeviceProfileInformation::displayNamePostfix(const Profile *p) const
{
IDevice::ConstPtr dev = device(p);
return dev.isNull() ? QString() : dev->displayName();
}
ProfileInformation::ItemList DeviceProfileInformation::toUserOutput(Profile *p) const
{
IDevice::ConstPtr dev = device(p);
......
......@@ -107,6 +107,8 @@ public:
ProfileConfigWidget *createConfigWidget(Profile *p) const;
QString displayNamePostfix(const Profile *p) const;
ItemList toUserOutput(Profile *p) const;
void addToEnvironment(const Profile *p, Utils::Environment &env) const;
......@@ -196,6 +198,8 @@ public:
ProfileConfigWidget *createConfigWidget(Profile *p) const;
QString displayNamePostfix(const Profile *p) const;
ItemList toUserOutput(Profile *p) const;
static IDevice::ConstPtr device(const Profile *p);
......
......@@ -452,6 +452,7 @@ void ProfileManager::addProfile(Profile *p)
{
if (!p)
return;
p->setDisplayName(p->displayName()); // make name unique
d->validateProfile(p);
d->m_profileList.append(p);
if (!d->m_defaultProfile ||
......@@ -466,4 +467,10 @@ void ProfileInformation::addToEnvironment(const Profile *p, Utils::Environment &
Q_UNUSED(env);
}
QString ProfileInformation::displayNamePostfix(const Profile *p) const
{
Q_UNUSED(p);
return QString();
}
} // namespace ProjectExplorer
......@@ -82,6 +82,8 @@ public:
virtual void addToEnvironment(const Profile *p, Utils::Environment &env) const;
virtual QString displayNamePostfix(const Profile *p) const;
signals:
void validationNeeded();
};
......
......@@ -98,6 +98,12 @@ QtProfileInformation::createConfigWidget(ProjectExplorer::Profile *p) const
return new Internal::QtProfileConfigWidget(p);
}
QString QtProfileInformation::displayNamePostfix(const ProjectExplorer::Profile *p) const
{
BaseQtVersion *version = qtVersion(p);
return version ? version->displayName() : QString();
}
ProjectExplorer::ProfileInformation::ItemList
QtProfileInformation::toUserOutput(ProjectExplorer::Profile *p) const
{
......
......@@ -56,6 +56,8 @@ public:
ProjectExplorer::ProfileConfigWidget *createConfigWidget(ProjectExplorer::Profile *p) const;
QString displayNamePostfix(const ProjectExplorer::Profile *p) const;
ItemList toUserOutput(ProjectExplorer::Profile *p) const;
void addToEnvironment(const ProjectExplorer::Profile *p, Utils::Environment &env) const;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment