Commit 164b8acf authored by hjk's avatar hjk

ProjectExplorer: Use LeveledTreeModel for KitModel

More typesafety, more compact code.

Change-Id: I7da6925d4dd04a84d2b8a305217ba87f622d8edc
Reviewed-by: Tobias Hunger's avatarTobias Hunger <tobias.hunger@qt.io>
parent 044743d4
......@@ -102,8 +102,9 @@ public:
// KitModel
// --------------------------------------------------------------------------
KitModel::KitModel(QBoxLayout *parentLayout, QObject *parent) : TreeModel(parent),
m_parentLayout(parentLayout)
KitModel::KitModel(QBoxLayout *parentLayout, QObject *parent)
: LeveledTreeModel<TreeItem, KitNode>(parent),
m_parentLayout(parentLayout)
{
setHeader(QStringList(tr("Name")));
m_autoRoot = new TreeItem(QStringList(tr("Auto-detected")));
......@@ -195,7 +196,7 @@ void KitModel::isAutoDetectedChanged()
void KitModel::validateKitNames()
{
QHash<QString, int> nameHash;
forEachItemAtLevel<KitNode *>(2, [&nameHash](KitNode *n) {
forSecondLevelItems([&nameHash](KitNode *n) {
const QString displayName = n->widget->displayName();
if (nameHash.contains(displayName))
++nameHash[displayName];
......@@ -203,7 +204,7 @@ void KitModel::validateKitNames()
nameHash.insert(displayName, 1);
});
forEachItemAtLevel<KitNode *>(2, [&nameHash](KitNode *n) {
forSecondLevelItems([&nameHash](KitNode *n) {
const QString displayName = n->widget->displayName();
n->widget->setHasUniqueName(nameHash.value(displayName) == 1);
});
......@@ -212,7 +213,7 @@ void KitModel::validateKitNames()
void KitModel::apply()
{
// Add/update dirty nodes before removing kits. This ensures the right kit ends up as default.
forEachItemAtLevel<KitNode *>(2, [](KitNode *n) {
forSecondLevelItems([](KitNode *n) {
if (n->widget->isDirty()) {
n->widget->apply();
n->update();
......@@ -240,7 +241,7 @@ void KitModel::markForRemoval(Kit *k)
}
if (node == m_defaultNode)
setDefaultNode(findItemAtLevel<KitNode *>(2, [node](KitNode *kn) { return kn != node; }));
setDefaultNode(findSecondLevelItem([node](KitNode *kn) { return kn != node; }));
takeItem(node);
if (node->widget->configures(0))
......@@ -272,7 +273,7 @@ Kit *KitModel::markForAddition(Kit *baseKit)
KitNode *KitModel::findWorkingCopy(Kit *k) const
{
return findItemAtLevel<KitNode *>(2, [k](KitNode *n) { return n->widget->workingCopy() == k; });
return findSecondLevelItem([k](KitNode *n) { return n->widget->workingCopy() == k; });
}
KitNode *KitModel::createNode(Kit *k)
......@@ -337,12 +338,12 @@ void KitModel::removeKit(Kit *k)
}
}
KitNode *node = findItemAtLevel<KitNode *>(2, [k](KitNode *n) {
KitNode *node = findSecondLevelItem([k](KitNode *n) {
return n->widget->configures(k);
});
if (node == m_defaultNode)
setDefaultNode(findItemAtLevel<KitNode *>(2, [node](KitNode *kn) { return kn != node; }));
setDefaultNode(findSecondLevelItem([node](KitNode *kn) { return kn != node; }));
delete takeItem(node);
......@@ -353,7 +354,7 @@ void KitModel::removeKit(Kit *k)
void KitModel::changeDefaultKit()
{
Kit *defaultKit = KitManager::defaultKit();
KitNode *node = findItemAtLevel<KitNode *>(2, [defaultKit](KitNode *n) {
KitNode *node = findSecondLevelItem([defaultKit](KitNode *n) {
return n->widget->configures(defaultKit);
});
setDefaultNode(node);
......
......@@ -48,7 +48,7 @@ class KitNode;
// KitModel:
// --------------------------------------------------------------------------
class KitModel : public Utils::TreeModel
class KitModel : public Utils::LeveledTreeModel<Utils::TreeItem, KitNode>
{
Q_OBJECT
......
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