QTableWidget::removeRow自动delete item项

100	bool QTableModel::removeRows(int row, int count, const QModelIndex &)
101	{
102	if (count < 1 || row < 0 || row + count > verticalHeaderItems.count())
103	return false;
104	
105	beginRemoveRows(QModelIndex(), row, row + count - 1);
106	int i = tableIndex(row, 0);
107	int n = count * columnCount();
108	QTableWidgetItem *oldItem = 0;
109	for (int j = i; j < n + i; ++j) {
110	oldItem = tableItems.at(j);
111	if (oldItem)
112	oldItem->view = 0;
113	delete oldItem;
114	}
115	tableItems.remove(qMax(i, 0), n);
116	for (int v = row; v < row + count; ++v) {
117	oldItem = verticalHeaderItems.at(v);
118	if (oldItem)
119	oldItem->view = 0;
120	delete oldItem;
121	}
122	verticalHeaderItems.remove(row, count);
123	endRemoveRows();
124	return true;
125	}
126	
127	bool QTableModel::removeColumns(int column, int count, const QModelIndex &)
128	{
129	if (count < 1 || column < 0 || column + count > horizontalHeaderItems.count())
130	return false;
131	
132	beginRemoveColumns(QModelIndex(), column, column + count - 1);
133	QTableWidgetItem *oldItem = 0;
134	for (int row = rowCount() - 1; row >= 0; --row) {
135	int i = tableIndex(row, column);
136	for (int j = i; j < i + count; ++j) {
137	oldItem = tableItems.at(j);
138	if (oldItem)
139	oldItem->view = 0;
140	delete oldItem;
141	}
142	tableItems.remove(i, count);
143	}
144	for (int h=column; h<column+count; ++h) {
145	oldItem = horizontalHeaderItems.at(h);
146	if (oldItem)
147	oldItem->view = 0;
148	delete oldItem;
149	}
150	horizontalHeaderItems.remove(column, count);
151	endRemoveColumns();
152	return true;
153	}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值