Commit c2ed4408 authored by Tobias Hunger's avatar Tobias Hunger

Kit: Change displayName generation

Do not care whether the unexpandedDisplay name is unique or not, nor
whether the display name is unique or not.

Warn if it is not in the Kits Options Page, but that is all.

Change-Id: I1cbeb5beb477d533092ade6ef67a97044e53477c
Reviewed-by: default avatarDaniel Teske <daniel.teske@digia.com>
parent d56f217f
......@@ -104,20 +104,17 @@ public:
m_id(id),
m_nestedBlockingLevel(0),
m_autodetected(false),
m_autoDetectionSource(QString()),
m_sdkProvided(false),
m_isValid(true),
m_hasWarning(false),
m_hasValidityInfo(false),
m_mustNotify(false),
m_mustNotifyAboutDisplayName(false),
m_macroExpander(0)
{
if (!id.isValid())
m_id = Id::fromString(QUuid::createUuid().toString());
m_displayName = QCoreApplication::translate("ProjectExplorer::Kit", "Unnamed");
m_previousDisplayName = m_displayName;
m_iconPath = Utils::FileName::fromLatin1(":///DESKTOP///");
QList<Utils::AbstractMacroExpander *> expanders;
......@@ -133,25 +130,17 @@ public:
~KitPrivate()
{ delete m_macroExpander; }
void updatePreviousDisplayName()
{
QTC_ASSERT(m_macroExpander, return);
m_previousDisplayName = Utils::expandMacros(m_displayName, m_macroExpander);
}
QString m_displayName;
QString m_previousDisplayName;
QString m_fileSystemFriendlyName;
QString m_autoDetectionSource;
Id m_id;
int m_nestedBlockingLevel;
bool m_autodetected;
QString m_autoDetectionSource;
bool m_sdkProvided;
bool m_isValid;
bool m_hasWarning;
bool m_hasValidityInfo;
bool m_mustNotify;
bool m_mustNotifyAboutDisplayName;
QIcon m_icon;
Utils::FileName m_iconPath;
......@@ -174,7 +163,6 @@ Kit::Kit(Core::Id id) :
d->m_data.insert(sti->id(), sti->defaultValue(this));
d->m_icon = icon(d->m_iconPath);
d->updatePreviousDisplayName();
}
Kit::Kit(const QVariantMap &data) :
......@@ -212,8 +200,6 @@ Kit::Kit(const QVariantMap &data) :
QStringList stickyInfoList = data.value(QLatin1String(STICKY_INFO_KEY)).toStringList();
foreach (const QString &stickyInfo, stickyInfoList)
d->m_sticky.insert(Core::Id::fromString(stickyInfo));
d->updatePreviousDisplayName();
}
Kit::~Kit()
......@@ -231,12 +217,9 @@ void Kit::unblockNotification()
--d->m_nestedBlockingLevel;
if (d->m_nestedBlockingLevel > 0)
return;
if (d->m_mustNotifyAboutDisplayName)
kitDisplayNameChanged();
else if (d->m_mustNotify)
kitUpdated();
kitUpdated();
d->m_mustNotify = false;
d->m_mustNotifyAboutDisplayName = false;
}
Kit *Kit::clone(bool keepName) const
......@@ -255,7 +238,6 @@ Kit *Kit::clone(bool keepName) const
k->d->m_iconPath = d->m_iconPath;
k->d->m_sticky = d->m_sticky;
k->d->m_mutable = d->m_mutable;
k->d->updatePreviousDisplayName();
return k;
}
......@@ -270,10 +252,8 @@ void Kit::copyFrom(const Kit *k)
d->m_displayName = k->d->m_displayName;
d->m_fileSystemFriendlyName = k->d->m_fileSystemFriendlyName;
d->m_mustNotify = true;
d->m_mustNotifyAboutDisplayName = false;
d->m_sticky = k->d->m_sticky;
d->m_mutable = k->d->m_mutable;
d->updatePreviousDisplayName();
}
bool Kit::isValid() const
......@@ -360,8 +340,7 @@ void Kit::setUnexpandedDisplayName(const QString &name)
return;
d->m_displayName = name;
d->updatePreviousDisplayName();
kitDisplayNameChanged();
kitUpdated();
}
QStringList Kit::candidateNameList(const QString &base) const
......@@ -576,7 +555,7 @@ IOutputParser *Kit::createOutputParser() const
return first;
}
QString Kit::toHtml() const
QString Kit::toHtml(const QList<Task> &additional) const
{
QString rc;
QTextStream str(&rc);
......@@ -584,8 +563,9 @@ QString Kit::toHtml() const
str << "<h3>" << displayName() << "</h3>";
str << "<table>";
if (!isValid() || hasWarning()) {
QList<Task> issues = validate();
if (!isValid() || hasWarning() || !additional.isEmpty()) {
QList<Task> issues = additional;
issues.append(validate());
str << "<p>";
foreach (const Task &t, issues) {
str << "<b>";
......@@ -712,28 +692,11 @@ Utils::AbstractMacroExpander *Kit::macroExpander() const
void Kit::kitUpdated()
{
if (d->m_nestedBlockingLevel > 0) {
if (!d->m_mustNotifyAboutDisplayName)
d->m_mustNotify = true;
return;
}
d->m_hasValidityInfo = false;
if (displayName() != d->m_previousDisplayName) {
d->updatePreviousDisplayName();
KitManager::notifyAboutDisplayNameChange(this);
} else {
KitManager::notifyAboutUpdate(this);
}
}
void Kit::kitDisplayNameChanged()
{
if (d->m_nestedBlockingLevel > 0) {
d->m_mustNotifyAboutDisplayName = true;
d->m_mustNotify = false;
d->m_mustNotify = true;
return;
}
d->m_hasValidityInfo = false;
KitManager::notifyAboutDisplayNameChange(this);
KitManager::notifyAboutUpdate(this);
}
} // namespace ProjectExplorer
......@@ -108,7 +108,7 @@ public:
void addToEnvironment(Utils::Environment &env) const;
IOutputParser *createOutputParser() const;
QString toHtml() const;
QString toHtml(const QList<Task> &additional = QList<Task>()) const;
Kit *clone(bool keepName = false) const;
void copyFrom(const Kit *k);
......
......@@ -107,14 +107,13 @@ public:
Kit *m_defaultKit;
bool m_initialized;
bool m_keepDisplayNameUnique;
QList<KitInformation *> m_informationList;
QList<Kit *> m_kitList;
Utils::PersistentSettingsWriter *m_writer;
};
KitManagerPrivate::KitManagerPrivate() :
m_defaultKit(0), m_initialized(false), m_keepDisplayNameUnique(true), m_writer(0)
m_defaultKit(0), m_initialized(false), m_writer(0)
{ }
KitManagerPrivate::~KitManagerPrivate()
......@@ -155,13 +154,6 @@ KitManager::KitManager(QObject *parent) :
this, SIGNAL(kitsChanged()));
}
bool KitManager::setKeepDisplayNameUnique(bool unique)
{
bool current = d->m_keepDisplayNameUnique;
d->m_keepDisplayNameUnique = unique;
return current;
}
void KitManager::restoreKits()
{
QTC_ASSERT(!d->m_initialized, return);
......@@ -477,45 +469,6 @@ void KitManager::deleteKit(Kit *k)
delete k;
}
QString KitManager::uniqueKitName(const Kit *k, const QList<Kit *> &allKits)
{
QStringList nameList;
nameList << QString(); // Disallow empty kit names!
foreach (Kit *tmp, allKits) {
if (tmp == k)
continue;
nameList.append(tmp->candidateNameList(tmp->displayName()));
}
const QString dn = k->displayName();
const QString udn = k->unexpandedDisplayName();
QString uniqueName = Project::makeUnique(dn, nameList);
if (uniqueName == dn)
return udn;
QStringList candidateNames = k->candidateNameList(udn);
foreach (const QString &candidate, candidateNames) {
QString expandedCandidate = Utils::expandMacros(candidate, k->macroExpander());
if (!nameList.contains(expandedCandidate))
return candidate;
}
return udn + uniqueName.mid(dn.count());
}
void KitManager::notifyAboutDisplayNameChange(Kit *k)
{
if (!k)
return;
if (d->m_kitList.contains(k) && d->m_keepDisplayNameUnique)
k->setUnexpandedDisplayName(uniqueKitName(k, kits()));
int pos = d->m_kitList.indexOf(k);
if (pos >= 0 && d->m_initialized)
d->moveKit(pos);
notifyAboutUpdate(k);
}
void KitManager::notifyAboutUpdate(ProjectExplorer::Kit *k)
{
if (!k || !isLoaded())
......@@ -539,8 +492,6 @@ bool KitManager::registerKit(ProjectExplorer::Kit *k)
if (kits().contains(k))
return false;
k->setUnexpandedDisplayName(uniqueKitName(k, kits()));
// make sure we have all the information in our kits:
m_instance->addKit(k);
......
......@@ -144,8 +144,6 @@ public:
static void deleteKit(Kit *k);
static QString uniqueKitName(const Kit *k, const QList<Kit *> &allKits);
static bool registerKit(ProjectExplorer::Kit *k);
static void deregisterKit(ProjectExplorer::Kit *k);
static void setDefaultKit(ProjectExplorer::Kit *k);
......@@ -177,8 +175,6 @@ signals:
private:
explicit KitManager(QObject *parent = 0);
static bool setKeepDisplayNameUnique(bool unique);
// Make sure the this is only called after all
// KitInformation are registered!
void restoreKits();
......@@ -192,7 +188,6 @@ private:
};
KitList restoreKits(const Utils::FileName &fileName);
static void notifyAboutDisplayNameChange(ProjectExplorer::Kit *k);
static void notifyAboutUpdate(ProjectExplorer::Kit *k);
void addKit(Kit *k);
......
......@@ -32,6 +32,7 @@
#include "kit.h"
#include "kitmanager.h"
#include "task.h"
#include <utils/detailswidget.h>
#include <utils/qtcassert.h>
......@@ -62,7 +63,8 @@ KitManagerConfigWidget::KitManagerConfigWidget(Kit *k) :
m_fileSystemFriendlyNameLineEdit(new QLineEdit),
m_kit(k),
m_modifiedKit(new Kit(Core::Id(WORKING_COPY_KIT_ID))),
m_fixingKit(false)
m_fixingKit(false),
m_hasUniqueName(true)
{
static const Qt::Alignment alignment
= static_cast<Qt::Alignment>(style()->styleHint(QStyle::SH_FormLayoutLabelAlignment));
......@@ -182,12 +184,17 @@ bool KitManagerConfigWidget::isValid() const
bool KitManagerConfigWidget::hasWarning() const
{
return m_modifiedKit->hasWarning();
return m_modifiedKit->hasWarning() || !m_hasUniqueName;
}
QString KitManagerConfigWidget::validityMessage() const
{
return m_modifiedKit->toHtml();
QList<Task> tmp;
if (!m_hasUniqueName) {
tmp.append(Task(Task::Warning, tr("Display name is not unique."), Utils::FileName(), -1,
ProjectExplorer::Constants::TASK_CATEGORY_COMPILE));
}
return m_modifiedKit->toHtml(tmp);
}
void KitManagerConfigWidget::addConfigWidget(ProjectExplorer::KitConfigWidget *widget)
......@@ -234,6 +241,11 @@ void KitManagerConfigWidget::updateVisibility()
}
}
void KitManagerConfigWidget::setHasUniqueName(bool unique)
{
m_hasUniqueName = unique;
}
void KitManagerConfigWidget::makeStickySubWidgetsReadOnly()
{
foreach (KitConfigWidget *w, m_widgets) {
......
......@@ -72,6 +72,8 @@ public:
void removeKit();
void updateVisibility();
void setHasUniqueName(bool unique);
signals:
void dirty();
......@@ -103,6 +105,7 @@ private:
Kit *m_modifiedKit;
bool m_isDefaultKit;
bool m_fixingKit;
bool m_hasUniqueName;
QPixmap m_background;
QList<QAction *> m_actions;
};
......
......@@ -105,10 +105,12 @@ KitModel::KitModel(QBoxLayout *parentLayout, QObject *parent) :
connect(KitManager::instance(), SIGNAL(kitAdded(ProjectExplorer::Kit*)),
this, SLOT(addKit(ProjectExplorer::Kit*)));
connect(KitManager::instance(), SIGNAL(kitRemoved(ProjectExplorer::Kit*)),
this, SLOT(removeKit(ProjectExplorer::Kit*)));
connect(KitManager::instance(), SIGNAL(kitUpdated(ProjectExplorer::Kit*)),
this, SLOT(updateKit(ProjectExplorer::Kit*)));
connect(KitManager::instance(), SIGNAL(unmanagedKitUpdated(ProjectExplorer::Kit*)),
this, SLOT(updateKit(ProjectExplorer::Kit*)));
connect(KitManager::instance(), SIGNAL(kitRemoved(ProjectExplorer::Kit*)),
this, SLOT(removeKit(ProjectExplorer::Kit*)));
connect(KitManager::instance(), SIGNAL(defaultkitChanged()),
this, SLOT(changeDefaultKit()));
}
......@@ -276,6 +278,25 @@ void KitModel::setDirty()
}
}
void KitModel::validateKitNames()
{
QList<KitNode *> nodes = m_manualRoot->childNodes;
nodes << m_autoRoot->childNodes;
QHash<QString, int> nameHash;
foreach (KitNode *n, nodes) {
const QString displayName = n->widget->displayName();
if (nameHash.contains(displayName))
++nameHash[displayName];
else
nameHash.insert(displayName, 1);
}
foreach (KitNode *n, nodes) {
const QString displayName = n->widget->displayName();
n->widget->setHasUniqueName(nameHash.value(displayName) == 1);
}
}
void KitModel::apply()
{
// Remove unused kits:
......@@ -286,8 +307,6 @@ void KitModel::apply()
}
// Update kits:
bool unique = KitManager::setKeepDisplayNameUnique(false);
m_keepUnique = false;
nodes = m_autoRoot->childNodes; // These can be dirty due to being made default!
nodes.append(m_manualRoot->childNodes);
foreach (KitNode *n, nodes) {
......@@ -298,8 +317,6 @@ void KitModel::apply()
emit dataChanged(index(n, 0), index(n, columnCount(QModelIndex())));
}
}
m_keepUnique = unique;
KitManager::setKeepDisplayNameUnique(unique);
}
void KitModel::markForRemoval(Kit *k)
......@@ -352,12 +369,6 @@ Kit *KitModel::markForAddition(Kit *baseKit)
return k;
}
QString KitModel::findNameFor(Kit *k)
{
QList<Kit *> kits = kitList(m_root);
return KitManager::uniqueKitName(k, kits);
}
QModelIndex KitModel::index(KitNode *node, int column) const
{
if (node->parent == 0) // is root (or was marked for deletion)
......@@ -428,6 +439,13 @@ void KitModel::addKit(Kit *k)
createNode(parent, k);
endInsertRows();
validateKitNames();
emit kitStateChanged();
}
void KitModel::updateKit(Kit *k)
{
validateKitNames();
emit kitStateChanged();
}
......@@ -464,15 +482,10 @@ void KitModel::removeKit(Kit *k)
endRemoveRows();
delete node;
validateKitNames();
emit kitStateChanged();
}
void KitModel::updateKit(Kit *k)
{
if (m_keepUnique)
k->setUnexpandedDisplayName(findNameFor(k));
}
void KitModel::changeDefaultKit()
{
Kit *defaultKit = KitManager::defaultKit();
......
......@@ -86,17 +86,16 @@ public:
void markForRemoval(Kit *k);
Kit *markForAddition(Kit *baseKit);
QString findNameFor(Kit *k);
signals:
void kitStateChanged();
private slots:
void addKit(ProjectExplorer::Kit *k);
void updateKit(ProjectExplorer::Kit *k);
void removeKit(ProjectExplorer::Kit *k);
void updateKit(ProjectExplorer::Kit*);
void changeDefaultKit();
void setDirty();
void validateKitNames();
private:
QModelIndex index(KitNode *, int column = 0) 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