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 }
QTableWidget::removeRow自动delete item项
最新推荐文章于 2024-08-07 17:32:17 发布