(1) 本类定义于头文件 qitemselectionmodel . h :
/*
The QItemSelectionRange class manages information about a
range of selected items in a model.
QltemSelectionRange 类管理模型中选定项目范围的信息。
Detailed Description :
QltemSelectionRange`包含关于模型中选定项范围的信息。
项范围是模型项的连续数组,延伸以覆盖具有共同父项的多个相邻行和列;
这可以可视化为一个表格中的二维单元块。
一个选择范围具有`top()、right()'和一个`parent()、left()、bottom().
QItemSelectionRange类是模型/视图类之一,是Qt模型/视图框架的一部分。
通过使用`indexes()、函数,可以获取选定的范围中所包含的模型项。
使用QItemSelectionModel::selectedIndexes()、可获取视图中所有选中的项的列表。
您可以通过使用“ contains() ”函数来确定给定的模型项是否位于特定范围内。
还可以使用重载的等于和不等于运算符来比较范围,而“ intersects() 函数则允许您确定两个范围是否重叠。
*/
class Q_CORE_EXPORT QItemSelectionRange
{ //本类描述的是这样的选择项:这些被选择的条目都是连续的。
private: //tl : top left , br : bottom right 的含义
QPersistentModelIndex tl, br; //使用了两个持久索引作为自己的数据成员
public:
QItemSelectionRange() = default; //默认构造函数
QItemSelectionRange(const QModelIndex & topL, const QModelIndex & bottomR)//有参构造函数
: tl(topL), br(bottomR) {}
explicit
QItemSelectionRange(const QModelIndex & index) : tl(index), br(tl) {} //有参构造函数
inline bool operator==(const QItemSelectionRange & other) const //比较运算符函数
{ return (tl == other.tl && br == other.br); }
inline bool operator!=(const QItemSelectionRange & other) const
{ return !operator==(other); }
void swap(QItemSelectionRange & other) noexcept
{
tl.swap(other.tl);
br.swap(other.br);
}
inline const QPersistentModelIndex & topLeft() const { return tl; }
inline const QPersistentModelIndex & bottomRight() const { return br; }
inline int top() const { return tl.row (); }
inline int left() const { return tl.column(); }
inline int bottom() const { return br.row (); }
inline int right () const { return br.column(); }
inline int width() const { return br.column() - tl.column() + 1; }
inline int height() const { return br.row() - tl.row() + 1; }
//Returns true if the selection range is valid; otherwise returns false.
inline
bool isValid() const //若本选择范围有效,则返回 true。
{
return (
tl .isValid()
&& br.isValid()
&& tl.parent() == br.parent()
&& top () <= bottom()
&& left() <= right());
}
bool isEmpty() const;
//如果选择范围包含没有项目或仅包含禁用或标记为不可选的项目,则返回true。
//Returns the model that the items in the selection range belong to.
inline const QAbstractItemModel * model () const { return tl.model (); }
inline QModelIndex parent () const { return tl.parent(); }
//Returns the parent model item index of the items in the selection range.
//返回这些被选条目的父节点的索引。
QModelIndexList indexes() const;
//Returns the list of model index items stored in the selection.
//判断本选择范围里是否包含形参 index指向的条目。
inline bool contains( const QModelIndex & index) const
{
return (
parent() == index.parent()
&& tl.row() <= index.row() && tl.column() <= index.column()
&& br.row() >= index.row() && br.column() >= index.column()
);
}
//判断节点 parentIndex下属的子表里元素 [row, column]是否在本选择范围内。
inline bool contains(int row, int column, const QModelIndex & parentIndex) const
{
return (
parent() == parentIndex
&& tl.row() <= row && tl.column() <= column
&& br.row() >= row && br.column() >= column
);
}
//如果此选择范围与给定的 other范围相交(重叠),则返回true;否则返回false。
bool intersects (const QItemSelectionRange & other) const;
QItemSelectionRange intersected(const QItemSelectionRange & other) const;
//返回一个新的选择范围,仅包含在选定范围和 other选定范围内都找到的项目。
}; //完结 class Q_CORE_EXPORT ItemSelectionRange
Q_DECLARE_TYPEINFO(QItemSelectionRange, Q_RELOCATABLE_TYPE);
Q_CORE_EXPORT QDebug operator<<(QDebug, const QItemSelectionRange &);
//此 << 运算符函数说明本类支持调试打印输出。
(2)
谢谢
6万+

被折叠的 条评论
为什么被折叠?



