TreeModel: Add a StaticTreeItem(QString) convenience constructor

Covers the common case and hopefully avoids the recurring MSVC
problem with initializer lists in this location.

Change-Id: I1b2bbb083f9fc86af3b51b8f52615fb70c832b95
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Reviewed-by: Tim Jenssen <tim.jenssen@theqtcompany.com>
This commit is contained in:
hjk
2016-06-17 08:24:47 +02:00
parent 9a8043d9ce
commit fb482846fc
7 changed files with 15 additions and 9 deletions

View File

@@ -1054,6 +1054,11 @@ StaticTreeItem::StaticTreeItem(const QStringList &displays)
{ {
} }
StaticTreeItem::StaticTreeItem(const QString &display)
: m_displays(display)
{
}
QVariant StaticTreeItem::data(int column, int role) const QVariant StaticTreeItem::data(int column, int role) const
{ {
if (role == Qt::DisplayRole && column >= 0 && column < m_displays.size()) if (role == Qt::DisplayRole && column >= 0 && column < m_displays.size())

View File

@@ -174,6 +174,7 @@ class QTCREATOR_UTILS_EXPORT StaticTreeItem : public TreeItem
{ {
public: public:
StaticTreeItem(const QStringList &displays); StaticTreeItem(const QStringList &displays);
StaticTreeItem(const QString &display);
QVariant data(int column, int role) const override; QVariant data(int column, int role) const override;
Qt::ItemFlags flags(int column) const override; Qt::ItemFlags flags(int column) const override;

View File

@@ -142,8 +142,8 @@ public:
CMakeToolItemModel::CMakeToolItemModel() CMakeToolItemModel::CMakeToolItemModel()
{ {
setHeader({tr("Name"), tr("Location")}); setHeader({tr("Name"), tr("Location")});
rootItem()->appendChild(new StaticTreeItem(QStringList(tr("Auto-detected")))); rootItem()->appendChild(new StaticTreeItem(tr("Auto-detected")));
rootItem()->appendChild(new StaticTreeItem(QStringList(tr("Manual")))); rootItem()->appendChild(new StaticTreeItem(tr("Manual")));
foreach (const CMakeTool *item, CMakeToolManager::cmakeTools()) foreach (const CMakeTool *item, CMakeToolManager::cmakeTools())
addCMakeTool(item, false); addCMakeTool(item, false);

View File

@@ -107,8 +107,8 @@ KitModel::KitModel(QBoxLayout *parentLayout, QObject *parent)
m_parentLayout(parentLayout) m_parentLayout(parentLayout)
{ {
setHeader(QStringList(tr("Name"))); setHeader(QStringList(tr("Name")));
m_autoRoot = new StaticTreeItem(QStringList(tr("Auto-detected"))); m_autoRoot = new StaticTreeItem(tr("Auto-detected"));
m_manualRoot = new StaticTreeItem(QStringList(tr("Manual"))); m_manualRoot = new StaticTreeItem(tr("Manual"));
rootItem()->appendChild(m_autoRoot); rootItem()->appendChild(m_autoRoot);
rootItem()->appendChild(m_manualRoot); rootItem()->appendChild(m_manualRoot);

View File

@@ -114,8 +114,8 @@ public:
[](ToolChainFactory *factory) { return factory->canCreate();}); [](ToolChainFactory *factory) { return factory->canCreate();});
m_model.setHeader({ ToolChainOptionsPage::tr("Name"), ToolChainOptionsPage::tr("Type") }); m_model.setHeader({ ToolChainOptionsPage::tr("Name"), ToolChainOptionsPage::tr("Type") });
m_autoRoot = new StaticTreeItem(QStringList(ToolChainOptionsPage::tr("Auto-detected"))); m_autoRoot = new StaticTreeItem(ToolChainOptionsPage::tr("Auto-detected"));
m_manualRoot = new StaticTreeItem(QStringList(ToolChainOptionsPage::tr("Manual"))); m_manualRoot = new StaticTreeItem(ToolChainOptionsPage::tr("Manual"));
m_model.rootItem()->appendChild(m_autoRoot); m_model.rootItem()->appendChild(m_autoRoot);
m_model.rootItem()->appendChild(m_manualRoot); m_model.rootItem()->appendChild(m_manualRoot);
foreach (ToolChain *tc, ToolChainManager::toolChains()) { foreach (ToolChain *tc, ToolChainManager::toolChains()) {

View File

@@ -220,8 +220,8 @@ QtOptionsPageWidget::QtOptionsPageWidget(QWidget *parent)
m_ui->versionInfoWidget->setWidget(versionInfoWidget); m_ui->versionInfoWidget->setWidget(versionInfoWidget);
m_ui->versionInfoWidget->setState(DetailsWidget::NoSummary); m_ui->versionInfoWidget->setState(DetailsWidget::NoSummary);
m_autoItem = new StaticTreeItem(QStringList(tr("Auto-detected"))); m_autoItem = new StaticTreeItem(tr("Auto-detected"));
m_manualItem = new StaticTreeItem(QStringList(tr("Manual" ))); m_manualItem = new StaticTreeItem(tr("Manual"));
m_model = new LeveledTreeModel<Utils::TreeItem, QtVersionItem>(); m_model = new LeveledTreeModel<Utils::TreeItem, QtVersionItem>();
m_model->setHeader({tr("Name"), tr("qmake Location"), tr("Type")}); m_model->setHeader({tr("Name"), tr("qmake Location"), tr("Type")});

View File

@@ -53,7 +53,7 @@ static int countLevelItems(TreeItem *base, int level)
static TreeItem *createItem(const QString &name) static TreeItem *createItem(const QString &name)
{ {
return new StaticTreeItem(QStringList(name)); return new StaticTreeItem(name);
} }
void tst_TreeModel::testIteration() void tst_TreeModel::testIteration()