Skip to content

Commit

Permalink
ENH: Add ctk::modelChildIndex implementation accepting const model
Browse files Browse the repository at this point in the history
This will avoid explicit use of "const_cast" when function "ctk::modelChildIndex"
is called from const functions.
  • Loading branch information
jcfr committed Dec 18, 2021
1 parent 0e368d7 commit 7413a7e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Libs/Core/ctkUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -519,3 +519,9 @@ QModelIndex ctk::modelChildIndex(QAbstractItemModel* item, const QModelIndex &pa
return parent.child(row, column);
#endif
}

//------------------------------------------------------------------------------
QModelIndex ctk::modelChildIndex(const QAbstractItemModel* item, const QModelIndex &parent, int row, int column)
{
return ctk::modelChildIndex(const_cast<QAbstractItemModel*>(item), parent, row, column);
}
3 changes: 3 additions & 0 deletions Libs/Core/ctkUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,15 @@ CTK_CORE_EXPORT QTextStream &flush(QTextStream &stream);
CTK_CORE_EXPORT QTextStream & endl(QTextStream &stream);


///@{
/// \ingroup Core
/// \brief Returns the child of the model index that is stored in the given row and column.
///
/// This method was added so that the same code compiles without deprecation warnings
/// pre and post Qt 5.8.
CTK_CORE_EXPORT QModelIndex modelChildIndex(QAbstractItemModel* item, const QModelIndex &parent, int row, int column);
CTK_CORE_EXPORT QModelIndex modelChildIndex(const QAbstractItemModel* item, const QModelIndex &parent, int row, int column);
///}@
}

#endif

0 comments on commit 7413a7e

Please sign in to comment.