forked from qt-creator/qt-creator
TreeModel: Introduce a TreeItem::indexInParent() convenience function
To shorten user code and hide the ugly const_cast. Change-Id: I798bd105932004ea17cb95b243fc38ccfcda0a2c Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -766,6 +766,11 @@ int TreeItem::level() const
|
|||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int TreeItem::indexInParent() const
|
||||||
|
{
|
||||||
|
return m_parent ? m_parent->m_children.indexOf(const_cast<TreeItem *>(this)) : -1;
|
||||||
|
}
|
||||||
|
|
||||||
QModelIndex TreeItem::index() const
|
QModelIndex TreeItem::index() const
|
||||||
{
|
{
|
||||||
QTC_ASSERT(m_model, return QModelIndex());
|
QTC_ASSERT(m_model, return QModelIndex());
|
||||||
|
|||||||
@@ -65,6 +65,7 @@ public:
|
|||||||
int level() const;
|
int level() const;
|
||||||
|
|
||||||
int childCount() const { return m_children.size(); }
|
int childCount() const { return m_children.size(); }
|
||||||
|
int indexInParent() const;
|
||||||
TreeItem *childAt(int index) const;
|
TreeItem *childAt(int index) const;
|
||||||
QVector<TreeItem *> children() const { return m_children; }
|
QVector<TreeItem *> children() const { return m_children; }
|
||||||
QModelIndex index() const;
|
QModelIndex index() const;
|
||||||
|
|||||||
@@ -272,7 +272,7 @@ QVariant ExplainingStepItem::data(int column, int role) const
|
|||||||
case ClangStaticAnalyzerDiagnosticModel::DiagnosticRole:
|
case ClangStaticAnalyzerDiagnosticModel::DiagnosticRole:
|
||||||
return QVariant::fromValue(static_cast<DiagnosticItem *>(parent())->diagnostic());
|
return QVariant::fromValue(static_cast<DiagnosticItem *>(parent())->diagnostic());
|
||||||
case Qt::DisplayRole: {
|
case Qt::DisplayRole: {
|
||||||
const int row = parent()->children().indexOf(const_cast<ExplainingStepItem *>(this)) + 1;
|
const int row = indexInParent() + 1;
|
||||||
const int padding = static_cast<int>(std::log10(parent()->childCount()))
|
const int padding = static_cast<int>(std::log10(parent()->childCount()))
|
||||||
- static_cast<int>(std::log10(row));
|
- static_cast<int>(std::log10(row));
|
||||||
return QString::fromLatin1("%1%2: %3")
|
return QString::fromLatin1("%1%2: %3")
|
||||||
|
|||||||
@@ -361,7 +361,7 @@ void ProjectWindow::deregisterProject(Project *project)
|
|||||||
void ProjectWindow::startupProjectChanged(Project *project)
|
void ProjectWindow::startupProjectChanged(Project *project)
|
||||||
{
|
{
|
||||||
if (ProjectItem *projectItem = itemForProject(project)) {
|
if (ProjectItem *projectItem = itemForProject(project)) {
|
||||||
int index = projectItem->parent()->children().indexOf(projectItem);
|
int index = projectItem->indexInParent();
|
||||||
QTC_ASSERT(index != -1, return);
|
QTC_ASSERT(index != -1, return);
|
||||||
m_projectSelection->setCurrentIndex(index);
|
m_projectSelection->setCurrentIndex(index);
|
||||||
m_selectorModel->rootItem()->m_currentProjectIndex = index;
|
m_selectorModel->rootItem()->m_currentProjectIndex = index;
|
||||||
|
|||||||
@@ -278,7 +278,7 @@ QVariant FrameItem::data(int column, int role) const
|
|||||||
case ErrorListModel::ErrorRole:
|
case ErrorListModel::ErrorRole:
|
||||||
return QVariant::fromValue(getErrorItem()->error());
|
return QVariant::fromValue(getErrorItem()->error());
|
||||||
case Qt::DisplayRole: {
|
case Qt::DisplayRole: {
|
||||||
const int row = parent()->children().indexOf(const_cast<FrameItem *>(this)) + 1;
|
const int row = indexInParent() + 1;
|
||||||
const int padding = static_cast<int>(std::log10(parent()->childCount()))
|
const int padding = static_cast<int>(std::log10(parent()->childCount()))
|
||||||
- static_cast<int>(std::log10(row));
|
- static_cast<int>(std::log10(row));
|
||||||
return QString::fromLatin1("%1%2: %3")
|
return QString::fromLatin1("%1%2: %3")
|
||||||
|
|||||||
Reference in New Issue
Block a user