src/gui/itemviews/qtableview.cpp
changeset 3 41300fa6a67c
parent 0 1918ee327afb
child 4 3b1da2848fc7
child 7 f7bc934e204c
child 18 2f34d5167611
equal deleted inserted replaced
2:56cd8111b7f7 3:41300fa6a67c
   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 
  2063     Q_D(const QTableView);
  2119     Q_D(const QTableView);
  2064 
  2120 
  2065     if (!model())
  2121     if (!model())
  2066         return -1;
  2122         return -1;
  2067 
  2123 
       
  2124     ensurePolished();
       
  2125 
  2068     int left = qMax(0, columnAt(0));
  2126     int left = qMax(0, columnAt(0));
  2069     int right = columnAt(d->viewport->width());
  2127     int right = columnAt(d->viewport->width());
  2070     if (right == -1) // the table don't have enough columns to fill the viewport
  2128     if (right == -1) // the table don't have enough columns to fill the viewport
  2071         right = d->model->columnCount(d->root) - 1;
  2129         right = d->model->columnCount(d->root) - 1;
  2072 
  2130 
  2119 {
  2177 {
  2120     Q_D(const QTableView);
  2178     Q_D(const QTableView);
  2121 
  2179 
  2122     if (!model())
  2180     if (!model())
  2123         return -1;
  2181         return -1;
       
  2182 
       
  2183     ensurePolished();
  2124 
  2184 
  2125     int top = qMax(0, rowAt(0));
  2185     int top = qMax(0, rowAt(0));
  2126     int bottom = rowAt(d->viewport->height());
  2186     int bottom = rowAt(d->viewport->height());
  2127     if (!isVisible() || bottom == -1) // the table don't have enough rows to fill the viewport
  2187     if (!isVisible() || bottom == -1) // the table don't have enough rows to fill the viewport
  2128         bottom = d->model->rowCount(d->root) - 1;
  2188         bottom = d->model->rowCount(d->root) - 1;