summaryrefslogtreecommitdiff
path: root/src/plugins/qtsupport/qtoptionspage.cpp
diff options
context:
space:
mode:
authorhjk <hjk@theqtcompany.com>2016-06-10 10:37:49 +0200
committerhjk <hjk@theqtcompany.com>2016-06-15 08:55:16 +0000
commitb281d6dad7aa43410387dbf06df07ac5f3716d42 (patch)
tree6d10a147a9278594ee3d764d098e4ad717b4ee46 /src/plugins/qtsupport/qtoptionspage.cpp
parent0c1cdc3a4aea1ebc3e8ce093576c9fc8b4ba281c (diff)
downloadqt-creator-b281d6dad7aa43410387dbf06df07ac5f3716d42.tar.gz
TreeModel: Introduce a StaticTreeItem
This splits out the case of static string displays from the TreeItem base class, making the base more lightweight. Change-Id: If1f442011ec60094399a41b65d9b5015f432f82e Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Diffstat (limited to 'src/plugins/qtsupport/qtoptionspage.cpp')
-rw-r--r--src/plugins/qtsupport/qtoptionspage.cpp32
1 files changed, 14 insertions, 18 deletions
diff --git a/src/plugins/qtsupport/qtoptionspage.cpp b/src/plugins/qtsupport/qtoptionspage.cpp
index 368e456288..89f4ecdbff 100644
--- a/src/plugins/qtsupport/qtoptionspage.cpp
+++ b/src/plugins/qtsupport/qtoptionspage.cpp
@@ -65,13 +65,8 @@ namespace Internal {
class QtVersionItem : public TreeItem
{
public:
- QtVersionItem(const QString &name) // for auto/manual node
- : TreeItem({name})
- {}
-
- QtVersionItem(BaseQtVersion *version) // for versions
- : TreeItem(),
- m_version(version)
+ explicit QtVersionItem(BaseQtVersion *version)
+ : m_version(version)
{}
~QtVersionItem()
@@ -212,15 +207,14 @@ QtOptionsPageWidget::QtOptionsPageWidget(QWidget *parent)
m_ui->versionInfoWidget->setWidget(versionInfoWidget);
m_ui->versionInfoWidget->setState(DetailsWidget::NoSummary);
- auto rootItem = new QtVersionItem(QLatin1String("root"));
- m_autoItem = new QtVersionItem(tr("Auto-detected"));
- rootItem->appendChild(m_autoItem);
- m_manualItem = new QtVersionItem(tr("Manual"));
- rootItem->appendChild(m_manualItem);
-
- m_model = new TreeModel(rootItem);
+ m_model = new TreeModel;
m_model->setHeader({tr("Name"), tr("qmake Location"), tr("Type")});
+ m_autoItem = new StaticTreeItem({ tr("Auto-detected") });
+ m_model->rootItem()->appendChild(m_autoItem);
+ m_manualItem = new StaticTreeItem({ tr("Manual") });
+ m_model->rootItem()->appendChild(m_manualItem);
+
m_filterModel = new QSortFilterProxyModel(this);
m_filterModel->setSourceModel(m_model);
m_filterModel->setSortCaseSensitivity(Qt::CaseInsensitive);
@@ -292,8 +286,8 @@ QtVersionItem *QtOptionsPageWidget::currentItem() const
{
QModelIndex idx = m_ui->qtdirList->selectionModel()->currentIndex();
QModelIndex sourceIdx = m_filterModel->mapToSource(idx);
- QtVersionItem *item = static_cast<QtVersionItem *>(m_model->itemForIndex(sourceIdx));
- return item;
+ TreeItem *item = m_model->itemForIndex(sourceIdx);
+ return item->level() == 2 ? static_cast<QtVersionItem *>(item) : 0;
}
void QtOptionsPageWidget::cleanUpQtVersions()
@@ -727,6 +721,9 @@ void QtOptionsPageWidget::qtVersionChanged()
void QtOptionsPageWidget::updateDescriptionLabel()
{
QtVersionItem *item = currentItem();
+ if (!item)
+ return;
+
const BaseQtVersion *version = item->version();
const ValidityInfo info = validInformation(version);
if (info.message.isEmpty()) {
@@ -737,8 +734,7 @@ void QtOptionsPageWidget::updateDescriptionLabel()
m_versionUi->errorLabel->setToolTip(info.toolTip);
}
m_ui->infoWidget->setSummaryText(info.description);
- if (item)
- item->setIcon(info.icon);
+ item->setIcon(info.icon);
if (version) {
m_infoBrowser->setHtml(version->toHtml(true));