112 break; |
112 break; |
113 --it_y; |
113 --it_y; |
114 } |
114 } |
115 } else if (old_height > span->height()) { |
115 } else if (old_height > span->height()) { |
116 //remove the span from all the subspans lists that intersect the columns not covered anymore |
116 //remove the span from all the subspans lists that intersect the columns not covered anymore |
117 Index::iterator it_y = index.lowerBound(-span->bottom()); |
117 Index::iterator it_y = index.lowerBound(qMin(-span->bottom(), 0)); |
118 Q_ASSERT(it_y != index.end()); //it_y must exist since the span is in the list |
118 Q_ASSERT(it_y != index.end()); //it_y must exist since the span is in the list |
119 while (-it_y.key() <= span->top() + old_height -1) { |
119 while (-it_y.key() <= span->top() + old_height -1) { |
120 if(-it_y.key() != span->bottom()) { |
120 if (-it_y.key() > span->bottom()) { |
121 (*it_y).remove(-span->left()); |
121 (*it_y).remove(-span->left()); |
122 if (it_y->isEmpty()) { |
122 if (it_y->isEmpty()) { |
123 it_y = index.erase(it_y) - 1; |
123 it_y = index.erase(it_y) - 1; |
124 } |
124 } |
125 } |
125 } |
541 foreach (QSpanCollection::Span *span, toBeDeleted) |
541 foreach (QSpanCollection::Span *span, toBeDeleted) |
542 qDebug() << span << *span; |
542 qDebug() << span << *span; |
543 #endif |
543 #endif |
544 qDeleteAll(toBeDeleted); |
544 qDeleteAll(toBeDeleted); |
545 } |
545 } |
|
546 |
|
547 #ifdef QT_BUILD_INTERNAL |
|
548 /*! |
|
549 \internal |
|
550 Checks whether the span index structure is self-consistent, and consistent with the spans list. |
|
551 */ |
|
552 bool QSpanCollection::checkConsistency() const |
|
553 { |
|
554 for (Index::const_iterator it_y = index.begin(); it_y != index.end(); ++it_y) { |
|
555 int y = -it_y.key(); |
|
556 const SubIndex &subIndex = it_y.value(); |
|
557 for (SubIndex::const_iterator it = subIndex.begin(); it != subIndex.end(); ++it) { |
|
558 int x = -it.key(); |
|
559 Span *span = it.value(); |
|
560 if (!spans.contains(span) || span->left() != x |
|
561 || y < span->top() || y > span->bottom()) |
|
562 return false; |
|
563 } |
|
564 } |
|
565 |
|
566 foreach (const Span *span, spans) { |
|
567 if (span->width() < 1 || span->height() < 1 |
|
568 || (span->width() == 1 && span->height() == 1)) |
|
569 return false; |
|
570 for (int y = span->top(); y <= span->bottom(); ++y) { |
|
571 Index::const_iterator it_y = index.find(-y); |
|
572 if (it_y == index.end()) { |
|
573 if (y == span->top()) |
|
574 return false; |
|
575 else |
|
576 continue; |
|
577 } |
|
578 const SubIndex &subIndex = it_y.value(); |
|
579 SubIndex::const_iterator it = subIndex.find(-span->left()); |
|
580 if (it == subIndex.end() || it.value() != span) |
|
581 return false; |
|
582 } |
|
583 } |
|
584 return true; |
|
585 } |
|
586 #endif |
546 |
587 |
547 class QTableCornerButton : public QAbstractButton |
588 class QTableCornerButton : public QAbstractButton |
548 { |
589 { |
549 Q_OBJECT |
590 Q_OBJECT |
550 public: |
591 public: |
1021 \reimp |
1062 \reimp |
1022 */ |
1063 */ |
1023 void QTableView::setModel(QAbstractItemModel *model) |
1064 void QTableView::setModel(QAbstractItemModel *model) |
1024 { |
1065 { |
1025 Q_D(QTableView); |
1066 Q_D(QTableView); |
1026 connect(model, SIGNAL(rowsInserted(QModelIndex,int,int)), |
1067 if (model == d->model) |
1027 this, SLOT(_q_updateSpanInsertedRows(QModelIndex,int,int))); |
1068 return; |
1028 connect(model, SIGNAL(columnsInserted(QModelIndex,int,int)), |
1069 //let's disconnect from the old model |
1029 this, SLOT(_q_updateSpanInsertedColumns(QModelIndex,int,int))); |
1070 if (d->model && d->model != QAbstractItemModelPrivate::staticEmptyModel()) { |
1030 connect(model, SIGNAL(rowsRemoved(QModelIndex,int,int)), |
1071 disconnect(d->model, SIGNAL(rowsInserted(QModelIndex,int,int)), |
1031 this, SLOT(_q_updateSpanRemovedRows(QModelIndex,int,int))); |
1072 this, SLOT(_q_updateSpanInsertedRows(QModelIndex,int,int))); |
1032 connect(model, SIGNAL(columnsRemoved(QModelIndex,int,int)), |
1073 disconnect(d->model, SIGNAL(columnsInserted(QModelIndex,int,int)), |
1033 this, SLOT(_q_updateSpanRemovedColumns(QModelIndex,int,int))); |
1074 this, SLOT(_q_updateSpanInsertedColumns(QModelIndex,int,int))); |
|
1075 disconnect(d->model, SIGNAL(rowsRemoved(QModelIndex,int,int)), |
|
1076 this, SLOT(_q_updateSpanRemovedRows(QModelIndex,int,int))); |
|
1077 disconnect(d->model, SIGNAL(columnsRemoved(QModelIndex,int,int)), |
|
1078 this, SLOT(_q_updateSpanRemovedColumns(QModelIndex,int,int))); |
|
1079 } |
|
1080 if (model) { //and connect to the new one |
|
1081 connect(model, SIGNAL(rowsInserted(QModelIndex,int,int)), |
|
1082 this, SLOT(_q_updateSpanInsertedRows(QModelIndex,int,int))); |
|
1083 connect(model, SIGNAL(columnsInserted(QModelIndex,int,int)), |
|
1084 this, SLOT(_q_updateSpanInsertedColumns(QModelIndex,int,int))); |
|
1085 connect(model, SIGNAL(rowsRemoved(QModelIndex,int,int)), |
|
1086 this, SLOT(_q_updateSpanRemovedRows(QModelIndex,int,int))); |
|
1087 connect(model, SIGNAL(columnsRemoved(QModelIndex,int,int)), |
|
1088 this, SLOT(_q_updateSpanRemovedColumns(QModelIndex,int,int))); |
|
1089 } |
1034 d->verticalHeader->setModel(model); |
1090 d->verticalHeader->setModel(model); |
1035 d->horizontalHeader->setModel(model); |
1091 d->horizontalHeader->setModel(model); |
1036 QAbstractItemView::setModel(model); |
1092 QAbstractItemView::setModel(model); |
1037 } |
1093 } |
1038 |
1094 |