Bladeren bron

ctkModelTester was not listening to headerDataChanged

Crash in ctkModelTester::testParent when no model is set.
Typo in assert comment.
Wrong test when the model is null.
Benjamin Long 14 jaren geleden
bovenliggende
commit
c159f777d9
2 gewijzigde bestanden met toevoegingen van 12 en 6 verwijderingen
  1. 8 6
      Libs/Core/ctkModelTester.cpp
  2. 4 0
      Libs/Core/ctkModelTester.h

+ 8 - 6
Libs/Core/ctkModelTester.cpp

@@ -112,6 +112,8 @@ void ctkModelTester::setModel(QAbstractItemModel *_model)
             this, SLOT(onColumnsRemoved(const QModelIndex& , int, int)));
     connect(_model, SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)),
             this, SLOT(onDataChanged(const QModelIndex& , const QModelIndex &)));
+    connect(_model, SIGNAL(headerDataChanged(Qt::Orientation,int,int)),
+            this, SLOT(onHeaderDataChanged(Qt::Orientation,int,int)));
     connect(_model, SIGNAL(layoutAboutToBeChanged()), this, SLOT(onLayoutAboutToBeChanged()));
     connect(_model, SIGNAL(layoutChanged()), this, SLOT(onLayoutChanged()));
     connect(_model, SIGNAL(modelAboutToBeReset()), this, SLOT(onModelAboutToBeReset()));
@@ -218,10 +220,9 @@ void ctkModelTester::testModelIndex(const QModelIndex& index)const
   if (!index.isValid())
     {// invalid index
     this->test(index.model() == 0, "An invalid index can't have a valid model.");
-    this->test(index.model() != d->Model, "An invalid index can't have a valid model.");
     this->test(index.column() == -1, "An invalid index can't have a valid column.");
     this->test(index.row() == -1, "An invalid index can't have a valid row.");
-    this->test(index.parent().isValid() == false, "An invalid index can't have a valid row.");
+    this->test(index.parent().isValid() == false, "An invalid index can't have a valid parent.");
     this->test(index.row() == -1, "An invalid index can't have a valid row.");
     for(int i = 0; i < 100; ++i)
       {
@@ -265,6 +266,10 @@ void ctkModelTester::testData(const QModelIndex& index)const
 void ctkModelTester::testParent(const QModelIndex& vparent)const
 {
   Q_D(const ctkModelTester);
+  if (!d->Model)
+    {
+    return;
+    }
   if (!d->Model->hasChildren(vparent))
     {
     // it's asking a lot :-)
@@ -362,7 +367,7 @@ void ctkModelTester::onDataChanged(const QModelIndex & topLeft, const QModelInde
   this->test(bottomRight.column() >= topLeft.column(), "topLeft can't have a column lower than bottomRight");
   for (int i = topLeft.row(); i <= bottomRight.row(); ++i)
     {
-    for (int j = topLeft.column(); j < bottomRight.column(); ++j)
+    for (int j = topLeft.column(); j <= bottomRight.column(); ++j)
       {
       this->test(topLeft.sibling(i,j).isValid(), "Changed data must be valid");
       // do the test on the indexes here, it's easier to debug than in testModel();
@@ -385,9 +390,6 @@ void ctkModelTester::onHeaderDataChanged(Qt::Orientation orientation, int first,
     case Qt::Vertical:
       this->test(d->Model->rowCount() > last, "There is no more vertical headers than rows.");
       break;
-    default:
-      this->test(orientation == Qt::Horizontal || orientation == Qt::Vertical, "Wrong orientation.");
-      break;
     }
   this->testModel();
 }

+ 4 - 0
Libs/Core/ctkModelTester.h

@@ -58,6 +58,10 @@ public:
   ///
   /// Constructor that set the model to test.
   /// A new model can later be set using setModel(...)
+  /// by default, throwOnError is true,
+  ///             nestedInsert is false,
+  ///             testDataEnabled is true,
+  ///             verbose is true.
   ctkModelTester(QAbstractItemModel *model, QObject *parent = 0);
 
   ///