Bläddra i källkod

Merge branch 'ctkCore-unitTests'

* ctkCore-unitTests:
  Call registerWorkflowStep when appropriate and add comments
  ctkTransferFunctionRepresentationTest2 - Fix style
  ctkCheckableModelHelperTest1 - Fix style
  BUG: ctkWorkflow / ctkWorkflowStep - Fix memory leak
  COMP: ctkWorkflowTest2 - Fix warning
Jean-Christophe Fillion-Robin 13 år sedan
förälder
incheckning
9f858e1392

+ 272 - 265
Libs/Core/Testing/Cpp/ctkCheckableModelHelperTest1.cpp

@@ -22,6 +22,7 @@
 #include <QCoreApplication>
 #include <QDebug>
 #include <QFocusEvent>
+#include <QScopedPointer>
 #include <QStandardItem>
 #include <QStandardItemModel>
 #include <QTimer>
@@ -37,6 +38,7 @@
 int ctkCheckableModelHelperTest1(int argc, char * argv [] )
 {
   QCoreApplication app(argc, argv);
+  Q_UNUSED(app);
 
   QStandardItemModel model;
   QList<QStandardItem*> row0;
@@ -70,273 +72,278 @@ int ctkCheckableModelHelperTest1(int argc, char * argv [] )
   QStandardItemModel modelForce;
   modelForce.appendRow(row0);
 
-  QModelIndex modelIndex;
-  ctkCheckableModelHelper* modelHelperCF =
-    new ctkCheckableModelHelper(Qt::Horizontal);
-
-  modelHelperCF->setForceCheckability(true);
-  if (!modelHelperCF->forceCheckability())
-    {
-    std::cerr << "ctkCheckableModelHelper::setForceCheckability() failed: "
-              << static_cast<int>(modelHelperCF->forceCheckability()) << std::endl;
-    return EXIT_FAILURE;
-    }
-
-  modelHelperCF->isCheckable(modelIndex);
-  modelHelperCF->toggleCheckState(modelIndex);
-
-  modelHelperCF->setForceCheckability(false);
-  if (modelHelperCF->forceCheckability())
-    {
-    std::cerr << "ctkCheckableModelHelper::setForceCheckability() failed: "
-              << static_cast<int>(modelHelperCF->forceCheckability()) << std::endl;
-    return EXIT_FAILURE;
-    }
-
-  modelHelperCF->setCheckState(modelIndex, Qt::Unchecked);
-
-  modelHelperCF->setDefaultCheckState(Qt::Checked);
-  if (modelHelperCF->defaultCheckState() != Qt::Checked)
-    {
-    std::cerr << "ctkCheckableModelHelper::setDefaultCheckState() failed: "
-              << static_cast<int>(modelHelperCF->defaultCheckState()) << std::endl;
-    return EXIT_FAILURE;
-    }
-
-  modelHelperCF->setRootIndex(modelIndex);
-  modelHelperCF->setForceCheckability(true);
-  modelHelperCF->setCheckState(modelIndex, Qt::Checked);
-  Qt::CheckState statutCheck = Qt::Checked;
-  if (modelHelperCF->checkState(modelIndex, statutCheck))
-    {
-    std::cerr << "ctkCheckableModelHelper::setCheckState() failed: "
-            << static_cast<int>(modelHelperCF->checkState(modelIndex, statutCheck)) << std::endl;
-    return EXIT_FAILURE;
-    }
-
-  modelHelperCF->checkState(modelIndex);
-
-  modelHelperCF->setModel(&modelForce);
-  if (!modelHelperCF->model())
-    {
-    std::cerr << "ctkCheckableModelHelper::setModel() failed: "
-              << "is null" << std::endl;
-    return EXIT_FAILURE;
-    }
-
-  modelHelperCF->setCheckState(modelIndex, Qt::Checked);
-  if (modelHelperCF->checkState(modelIndex, statutCheck))
-    {
-    std::cerr << "ctkCheckableModelHelper::setCheckState() failed: "
-            << static_cast<int>(modelHelperCF->checkState(modelIndex, statutCheck)) << std::endl;
-    return EXIT_FAILURE;
-    }
-
+  {
+    QModelIndex modelIndex;
+    QScopedPointer<ctkCheckableModelHelper> modelHelperCF(new ctkCheckableModelHelper(Qt::Horizontal));
+
+    modelHelperCF->setForceCheckability(true);
+    if (!modelHelperCF->forceCheckability())
+      {
+      std::cerr << "Line " << __LINE__
+                << " - ctkCheckableModelHelper::setForceCheckability() failed: "
+                << static_cast<int>(modelHelperCF->forceCheckability()) << std::endl;
+      return EXIT_FAILURE;
+      }
+
+    modelHelperCF->isCheckable(modelIndex);
+    modelHelperCF->toggleCheckState(modelIndex);
+
+    modelHelperCF->setForceCheckability(false);
+    if (modelHelperCF->forceCheckability())
+      {
+      std::cerr << "Line " << __LINE__
+                << " - ctkCheckableModelHelper::setForceCheckability() failed: "
+                << static_cast<int>(modelHelperCF->forceCheckability()) << std::endl;
+      return EXIT_FAILURE;
+      }
+
+    modelHelperCF->setCheckState(modelIndex, Qt::Unchecked);
+
+    modelHelperCF->setDefaultCheckState(Qt::Checked);
+    if (modelHelperCF->defaultCheckState() != Qt::Checked)
+      {
+      std::cerr << "Line " << __LINE__
+                << " - ctkCheckableModelHelper::setDefaultCheckState() failed: "
+                << static_cast<int>(modelHelperCF->defaultCheckState()) << std::endl;
+      return EXIT_FAILURE;
+      }
+
+    modelHelperCF->setRootIndex(modelIndex);
+    modelHelperCF->setForceCheckability(true);
+    modelHelperCF->setCheckState(modelIndex, Qt::Checked);
+    Qt::CheckState statutCheck = Qt::Checked;
+    if (modelHelperCF->checkState(modelIndex, statutCheck))
+      {
+      std::cerr << "Line " << __LINE__ << " - ctkCheckableModelHelper::setCheckState() failed: "
+                << static_cast<int>(modelHelperCF->checkState(modelIndex, statutCheck))
+                << std::endl;
+      return EXIT_FAILURE;
+      }
+
+    modelHelperCF->checkState(modelIndex);
+
+    modelHelperCF->setModel(&modelForce);
+    if (!modelHelperCF->model())
+      {
+      std::cerr << "Line " << __LINE__ << " - ctkCheckableModelHelper::setModel() failed: "
+                << "is null" << std::endl;
+      return EXIT_FAILURE;
+      }
+
+    modelHelperCF->setCheckState(modelIndex, Qt::Checked);
+    if (modelHelperCF->checkState(modelIndex, statutCheck))
+      {
+      std::cerr << "Line " << __LINE__ << " - ctkCheckableModelHelper::setCheckState() failed: "
+                << static_cast<int>(modelHelperCF->checkState(modelIndex, statutCheck))
+                << std::endl;
+      return EXIT_FAILURE;
+      }
+  } // end of local scope
+
+  {
     // Row & Column dummy insert
-  QList<QStandardItem*> col0;
-  col0 << new QStandardItem << new QStandardItem << new QStandardItem;
-  col0[0]->setText("not user checkable");
-  modelForce.appendColumn(col0);
-  modelForce.appendRow(row1);
-
-  delete modelHelperCF;
-
-  ctkCheckableModelHelper* modelHelperRC =
-    new ctkCheckableModelHelper(Qt::Vertical);
-  modelHelperRC->setForceCheckability(true);
-  modelHelperRC->setModel(&modelForce);
-  modelForce.appendColumn(col0);
-  modelForce.appendRow(row1);
-
-  //Header is checked by default
-  model.setHeaderData(0, Qt::Horizontal, Qt::Checked, Qt::CheckStateRole);
-
-  ctkCheckableModelHelper* modelHelper =
-    new ctkCheckableModelHelper(Qt::Horizontal);
-  modelHelper->setModel(&model);
-
-  // propagatetoitems is true by default
-  //modelHelper->setPropagateToItems(true);
-  modelHelper->toggleHeaderCheckState(-1);
-
-  // As propagateToItems is true, once the model is set to the modelHelper,
-  // the checkable header is updated from the check state of all the items
-  // all the items are unchecked by default, so the header becomes unchecked
-  if (modelHelper->headerCheckState(0) != Qt::Unchecked ||
-      row0[0]->checkState() != Qt::Unchecked ||
-      row1[0]->checkState() != Qt::Unchecked ||
-      row2[0]->checkState() != Qt::Unchecked)
-    {
-    std::cerr << "ctkCheckableModelHelper::checkstate() failed: "
-              << static_cast<int>(modelHelper->headerCheckState(0)) << " "
-              << static_cast<int>(row0[0]->checkState()) << " "
-              << static_cast<int>(row1[0]->checkState()) << " "
-              << static_cast<int>(row2[0]->checkState()) << std::endl;
-    return EXIT_FAILURE;
-    }
-  // Retrieve checkstate of the header
-  Qt::CheckState checkstate;
-  if (!modelHelper->headerCheckState(0, checkstate))
-    {
-    std::cerr << "ctkCheckableModelHelper::checkstate() failed: "
-              << static_cast<int>(checkstate) << std::endl;
-    return EXIT_FAILURE;
-    }
-
-  if (modelHelper->propagateDepth() == 0)
-    {
-    std::cerr << "ctkCheckableModelHelper::propagateDepth() failed: "
-              << modelHelper->propagateDepth() << std::endl;
-    return EXIT_FAILURE;
-    }
-  modelHelper->setPropagateDepth(0);
-  if (modelHelper->propagateDepth() != 0)
-    {
-    std::cerr << "ctkCheckableModelHelper::propagateDepth() failed: "
-              << modelHelper->propagateDepth() << std::endl;
-    return EXIT_FAILURE;
-    }
-  if (modelHelper->headerCheckState(0) != Qt::Unchecked ||
-      row0[0]->checkState() != Qt::Unchecked ||
-      row1[0]->checkState() != Qt::Unchecked ||
-      row2[0]->checkState() != Qt::Unchecked)
-    {
-    std::cerr << "ctkCheckableModelHelper::propagateToItems() failed: "
-              << static_cast<int>(modelHelper->headerCheckState(0)) << " "
-              << static_cast<int>(row0[0]->checkState()) << " "
-              << static_cast<int>(row1[0]->checkState()) << " "
-              << static_cast<int>(row2[0]->checkState()) << std::endl;
-    return EXIT_FAILURE;
-    }
-
-  // check the header
-  modelHelper->setHeaderCheckState(0, Qt::Checked);
-  
-  // make sure it didn't uncheck the checkable items
-  if (modelHelper->headerCheckState(0) != Qt::Checked ||
-      row0[0]->checkState() != Qt::Unchecked ||
-      row1[0]->checkState() != Qt::Unchecked ||
-      row2[0]->checkState() != Qt::Unchecked)
-    {
-    std::cerr << __LINE__ << " ctkCheckableModelHelper::toggleCheckState() failed: "
-              << static_cast<int>(modelHelper->headerCheckState(0))
-              << " "        << static_cast<int>(row0[0]->checkState()) << " "
-              << static_cast<int>(row1[0]->checkState()) << " "
-              << static_cast<int>(row2[0]->checkState()) << std::endl;
-    return EXIT_FAILURE;
-    }
+    QList<QStandardItem*> col0;
+    col0 << new QStandardItem << new QStandardItem << new QStandardItem;
+    col0[0]->setText("not user checkable");
+    modelForce.appendColumn(col0);
+    modelForce.appendRow(row1);
+
+    QScopedPointer<ctkCheckableModelHelper> modelHelperRC(new ctkCheckableModelHelper(Qt::Vertical));
+    modelHelperRC->setForceCheckability(true);
+    modelHelperRC->setModel(&modelForce);
+    modelForce.appendColumn(col0);
+    modelForce.appendRow(row1);
+
+  } // end of local scope
+
+  {
+    // Header is checked by default
+    model.setHeaderData(0, Qt::Horizontal, Qt::Checked, Qt::CheckStateRole);
+
+    QScopedPointer<ctkCheckableModelHelper> modelHelper(new ctkCheckableModelHelper(Qt::Horizontal));
+    modelHelper->setModel(&model);
+
+    // propagatetoitems is true by default
+    //modelHelper->setPropagateToItems(true);
+    modelHelper->toggleHeaderCheckState(-1);
+
+    // As propagateToItems is true, once the model is set to the modelHelper,
+    // the checkable header is updated from the check state of all the items
+    // all the items are unchecked by default, so the header becomes unchecked
+    if (modelHelper->headerCheckState(0) != Qt::Unchecked ||
+        row0[0]->checkState() != Qt::Unchecked ||
+        row1[0]->checkState() != Qt::Unchecked ||
+        row2[0]->checkState() != Qt::Unchecked)
+      {
+      std::cerr << "Line " << __LINE__ << " - ctkCheckableModelHelper::checkstate() failed: "
+                << static_cast<int>(modelHelper->headerCheckState(0)) << " "
+                << static_cast<int>(row0[0]->checkState()) << " "
+                << static_cast<int>(row1[0]->checkState()) << " "
+                << static_cast<int>(row2[0]->checkState()) << std::endl;
+      return EXIT_FAILURE;
+      }
+    // Retrieve checkstate of the header
+    Qt::CheckState checkstate;
+    if (!modelHelper->headerCheckState(0, checkstate))
+      {
+      std::cerr << "Line " << __LINE__ << " - ctkCheckableModelHelper::checkstate() failed: "
+                << static_cast<int>(checkstate) << std::endl;
+      return EXIT_FAILURE;
+      }
+
+    if (modelHelper->propagateDepth() == 0)
+      {
+      std::cerr << "Line " << __LINE__ << " - ctkCheckableModelHelper::propagateDepth() failed: "
+                << modelHelper->propagateDepth() << std::endl;
+      return EXIT_FAILURE;
+      }
+    modelHelper->setPropagateDepth(0);
+    if (modelHelper->propagateDepth() != 0)
+      {
+      std::cerr << "Line " << __LINE__ << " - ctkCheckableModelHelper::propagateDepth() failed: "
+                << modelHelper->propagateDepth() << std::endl;
+      return EXIT_FAILURE;
+      }
+    if (modelHelper->headerCheckState(0) != Qt::Unchecked ||
+        row0[0]->checkState() != Qt::Unchecked ||
+        row1[0]->checkState() != Qt::Unchecked ||
+        row2[0]->checkState() != Qt::Unchecked)
+      {
+      std::cerr << "Line " << __LINE__ << " - ctkCheckableModelHelper::propagateToItems() failed: "
+                << static_cast<int>(modelHelper->headerCheckState(0)) << " "
+                << static_cast<int>(row0[0]->checkState()) << " "
+                << static_cast<int>(row1[0]->checkState()) << " "
+                << static_cast<int>(row2[0]->checkState()) << std::endl;
+      return EXIT_FAILURE;
+      }
+
+    // check the header
+    modelHelper->setHeaderCheckState(0, Qt::Checked);
 
-  row0[0]->setCheckState(Qt::Checked);
-  // make sure it didn't uncheck the checkable items
-  if (modelHelper->headerCheckState(0) != Qt::Checked ||
-      row0[0]->checkState() != Qt::Checked ||
-      row1[0]->checkState() != Qt::Unchecked ||
-      row2[0]->checkState() != Qt::Unchecked)
-    {
-    std::cerr << "QStandardItem::setCheckState() failed: "
-              << static_cast<int>(modelHelper->headerCheckState(0)) << " "
-              << static_cast<int>(row0[0]->checkState()) << " "
-              << static_cast<int>(row1[0]->checkState()) << " "
-              << static_cast<int>(row2[0]->checkState()) << std::endl;
-    return EXIT_FAILURE;
-    }
-
-  // The checkable header gets updated with the item check states
-  modelHelper->setPropagateDepth(-1);
-
-  if (modelHelper->propagateDepth() == 0 ||
-      modelHelper->headerCheckState(0) != Qt::PartiallyChecked ||
-      row0[0]->checkState() != Qt::Checked ||
-      row1[0]->checkState() != Qt::Unchecked ||
-      row2[0]->checkState() != Qt::Unchecked)
-    {
-    std::cerr << "ctkCheckableModelHelper::setPropagateToItems() failed: "
-              << static_cast<int>(modelHelper->headerCheckState(0)) << " "
-              << static_cast<int>(row0[0]->checkState()) << " "
-              << static_cast<int>(row1[0]->checkState()) << " "
-              << static_cast<int>(row2[0]->checkState()) << std::endl;
-    return EXIT_FAILURE;
-    }
-
-  row0[0]->setCheckState(Qt::Unchecked);
-  
-  if (modelHelper->headerCheckState(0) != Qt::Unchecked ||
-      row0[0]->checkState() != Qt::Unchecked ||
-      row1[0]->checkState() != Qt::Unchecked ||
-      row2[0]->checkState() != Qt::Unchecked)
-    {
-    std::cerr << "QStandardItem::setCheckState() failed: "
-              << static_cast<int>(modelHelper->headerCheckState(0)) << " "
-              << static_cast<int>(row0[0]->checkState()) << " "
-              << static_cast<int>(row1[0]->checkState()) << " "
-              << static_cast<int>(row2[0]->checkState()) << std::endl;
-    return EXIT_FAILURE;
-    }
-
-  row1[0]->setCheckState(Qt::Checked);
-  
     // make sure it didn't uncheck the checkable items
-  if (modelHelper->headerCheckState(0) != Qt::PartiallyChecked ||
-      row0[0]->checkState() != Qt::Unchecked ||
-      row1[0]->checkState() != Qt::Checked ||
-      row2[0]->checkState() != Qt::Unchecked)
-    {
-    std::cerr << "QStandardItem::setCheckState() failed: "
-              << static_cast<int>(modelHelper->headerCheckState(0)) << " "
-              << static_cast<int>(row0[0]->checkState()) << " "
-              << static_cast<int>(row1[0]->checkState()) << " "
-              << static_cast<int>(row2[0]->checkState()) << std::endl;
-    return EXIT_FAILURE;
-    }
-
-  row1[0]->setCheckState(Qt::Checked);
-  
-  // make sure it didn't check the checkable items
-  if (modelHelper->headerCheckState(0) != Qt::PartiallyChecked ||
-      row0[0]->checkState() != Qt::Unchecked ||
-      row1[0]->checkState() != Qt::Checked ||
-      row2[0]->checkState() != Qt::Unchecked)
-    {
-    std::cerr << "QStandardItem::setCheckState() failed: "
-              << static_cast<int>(modelHelper->headerCheckState(0)) << " "
-              << static_cast<int>(row0[0]->checkState()) << " "
-              << static_cast<int>(row1[0]->checkState()) << " "
-              << static_cast<int>(row2[0]->checkState()) << std::endl;
-    return EXIT_FAILURE;
-    }
-
-  row0[0]->setCheckState(Qt::Checked);
-  row2[0]->setCheckState(Qt::Checked);
-
-  // make sure the header is now checked
-  if (modelHelper->headerCheckState(0) != Qt::Checked ||
-      row0[0]->checkState() != Qt::Checked ||
-      row1[0]->checkState() != Qt::Checked ||
-      row2[0]->checkState() != Qt::Checked)
-    {
-    std::cerr << "QStandardItem::setCheckState() failed: "
-              << static_cast<int>(modelHelper->headerCheckState(0)) << " "
-              << static_cast<int>(row0[0]->checkState()) << " "
-              << static_cast<int>(row1[0]->checkState()) << " "
-              << static_cast<int>(row2[0]->checkState()) << std::endl;
-    return EXIT_FAILURE;
-    }
-
-  modelHelper->setHeaderCheckState(0, Qt::Unchecked);
-    
-  if (modelHelper->headerCheckState(0) != Qt::Unchecked ||
-      row0[0]->checkState() != Qt::Unchecked ||
-      row1[0]->checkState() != Qt::Unchecked ||
-      row2[0]->checkState() != Qt::Unchecked)
-    {
-    std::cerr << "ctkCheckableModelHelper::setCheckState() failed: "
-              << static_cast<int>(modelHelper->headerCheckState(0)) << " "
-              << static_cast<int>(row0[0]->checkState()) << " "
-              << static_cast<int>(row1[0]->checkState()) << " "
-              << static_cast<int>(row2[0]->checkState()) << std::endl;
-    return EXIT_FAILURE;
-    }
-
-  delete modelHelper;
+    if (modelHelper->headerCheckState(0) != Qt::Checked ||
+        row0[0]->checkState() != Qt::Unchecked ||
+        row1[0]->checkState() != Qt::Unchecked ||
+        row2[0]->checkState() != Qt::Unchecked)
+      {
+      std::cerr << "Line " << __LINE__ << " - ctkCheckableModelHelper::toggleCheckState() failed: "
+                << static_cast<int>(modelHelper->headerCheckState(0))
+                << " "        << static_cast<int>(row0[0]->checkState()) << " "
+                << static_cast<int>(row1[0]->checkState()) << " "
+                << static_cast<int>(row2[0]->checkState()) << std::endl;
+      return EXIT_FAILURE;
+      }
+
+    row0[0]->setCheckState(Qt::Checked);
+    // make sure it didn't uncheck the checkable items
+    if (modelHelper->headerCheckState(0) != Qt::Checked ||
+        row0[0]->checkState() != Qt::Checked ||
+        row1[0]->checkState() != Qt::Unchecked ||
+        row2[0]->checkState() != Qt::Unchecked)
+      {
+      std::cerr << "Line " << __LINE__ << " - QStandardItem::setCheckState() failed: "
+                << static_cast<int>(modelHelper->headerCheckState(0)) << " "
+                << static_cast<int>(row0[0]->checkState()) << " "
+                << static_cast<int>(row1[0]->checkState()) << " "
+                << static_cast<int>(row2[0]->checkState()) << std::endl;
+      return EXIT_FAILURE;
+      }
+
+    // The checkable header gets updated with the item check states
+    modelHelper->setPropagateDepth(-1);
+
+    if (modelHelper->propagateDepth() == 0 ||
+        modelHelper->headerCheckState(0) != Qt::PartiallyChecked ||
+        row0[0]->checkState() != Qt::Checked ||
+        row1[0]->checkState() != Qt::Unchecked ||
+        row2[0]->checkState() != Qt::Unchecked)
+      {
+      std::cerr << "Line " << __LINE__ << " - ctkCheckableModelHelper::setPropagateToItems() failed: "
+                << static_cast<int>(modelHelper->headerCheckState(0)) << " "
+                << static_cast<int>(row0[0]->checkState()) << " "
+                << static_cast<int>(row1[0]->checkState()) << " "
+                << static_cast<int>(row2[0]->checkState()) << std::endl;
+      return EXIT_FAILURE;
+      }
+
+    row0[0]->setCheckState(Qt::Unchecked);
+
+    if (modelHelper->headerCheckState(0) != Qt::Unchecked ||
+        row0[0]->checkState() != Qt::Unchecked ||
+        row1[0]->checkState() != Qt::Unchecked ||
+        row2[0]->checkState() != Qt::Unchecked)
+      {
+      std::cerr << "Line " << __LINE__ << " - QStandardItem::setCheckState() failed: "
+                << static_cast<int>(modelHelper->headerCheckState(0)) << " "
+                << static_cast<int>(row0[0]->checkState()) << " "
+                << static_cast<int>(row1[0]->checkState()) << " "
+                << static_cast<int>(row2[0]->checkState()) << std::endl;
+      return EXIT_FAILURE;
+      }
+
+    row1[0]->setCheckState(Qt::Checked);
+
+      // make sure it didn't uncheck the checkable items
+    if (modelHelper->headerCheckState(0) != Qt::PartiallyChecked ||
+        row0[0]->checkState() != Qt::Unchecked ||
+        row1[0]->checkState() != Qt::Checked ||
+        row2[0]->checkState() != Qt::Unchecked)
+      {
+      std::cerr << "Line " << __LINE__ << " - QStandardItem::setCheckState() failed: "
+                << static_cast<int>(modelHelper->headerCheckState(0)) << " "
+                << static_cast<int>(row0[0]->checkState()) << " "
+                << static_cast<int>(row1[0]->checkState()) << " "
+                << static_cast<int>(row2[0]->checkState()) << std::endl;
+      return EXIT_FAILURE;
+      }
+
+    row1[0]->setCheckState(Qt::Checked);
+
+    // make sure it didn't check the checkable items
+    if (modelHelper->headerCheckState(0) != Qt::PartiallyChecked ||
+        row0[0]->checkState() != Qt::Unchecked ||
+        row1[0]->checkState() != Qt::Checked ||
+        row2[0]->checkState() != Qt::Unchecked)
+      {
+      std::cerr << "Line " << __LINE__ << " - QStandardItem::setCheckState() failed: "
+                << static_cast<int>(modelHelper->headerCheckState(0)) << " "
+                << static_cast<int>(row0[0]->checkState()) << " "
+                << static_cast<int>(row1[0]->checkState()) << " "
+                << static_cast<int>(row2[0]->checkState()) << std::endl;
+      return EXIT_FAILURE;
+      }
+
+    row0[0]->setCheckState(Qt::Checked);
+    row2[0]->setCheckState(Qt::Checked);
+
+    // make sure the header is now checked
+    if (modelHelper->headerCheckState(0) != Qt::Checked ||
+        row0[0]->checkState() != Qt::Checked ||
+        row1[0]->checkState() != Qt::Checked ||
+        row2[0]->checkState() != Qt::Checked)
+      {
+      std::cerr << "Line " << __LINE__ << " - QStandardItem::setCheckState() failed: "
+                << static_cast<int>(modelHelper->headerCheckState(0)) << " "
+                << static_cast<int>(row0[0]->checkState()) << " "
+                << static_cast<int>(row1[0]->checkState()) << " "
+                << static_cast<int>(row2[0]->checkState()) << std::endl;
+      return EXIT_FAILURE;
+      }
+
+    modelHelper->setHeaderCheckState(0, Qt::Unchecked);
+
+    if (modelHelper->headerCheckState(0) != Qt::Unchecked ||
+        row0[0]->checkState() != Qt::Unchecked ||
+        row1[0]->checkState() != Qt::Unchecked ||
+        row2[0]->checkState() != Qt::Unchecked)
+      {
+      std::cerr << "Line " << __LINE__ << " - ctkCheckableModelHelper::setCheckState() failed: "
+                << static_cast<int>(modelHelper->headerCheckState(0)) << " "
+                << static_cast<int>(row0[0]->checkState()) << " "
+                << static_cast<int>(row1[0]->checkState()) << " "
+                << static_cast<int>(row2[0]->checkState()) << std::endl;
+      return EXIT_FAILURE;
+      }
+  } // end of local scope
   return EXIT_SUCCESS;
 }

+ 1 - 1
Libs/Core/Testing/Cpp/ctkExampleWorkflowStepUsingSignalsAndSlots.cpp

@@ -88,7 +88,7 @@ void ctkExampleWorkflowStepUsingSignalsAndSlots::validateFails()const
   // Always returns false in this simple example
   QObject::staticMetaObject.invokeMethod(
       d->Step->ctkWorkflowStepQObject(), "validationComplete",
-      Q_ARG(bool, false));
+        Q_ARG(bool, false), Q_ARG(QString, ""));
 }
 
 //-----------------------------------------------------------------------------

+ 30 - 53
Libs/Core/Testing/Cpp/ctkTransferFunctionRepresentationTest2.cpp

@@ -21,6 +21,7 @@
 // Qt includes
 #include <QCoreApplication>
 #include <QColor>
+#include <QScopedPointer>
 
 // CTK includes
 #include "ctkTransferFunction.h"
@@ -33,12 +34,19 @@
 class ctkForcedTransferFunction: public ctkTransferFunction
 {
 public:
-  ctkForcedTransferFunction(QObject* parent = 0):ctkTransferFunction(parent), _discrete(true) {}
+  typedef ctkTransferFunction Superclass;
+  ctkForcedTransferFunction(QObject* parent = 0) : Superclass(parent)
+  {
+    this->Discrete = true;
+  }
+
+  // --------------------------------------------------------------------------
   virtual ~ctkForcedTransferFunction(){}
 
   // attributes test
-  bool _discrete;
+  bool Discrete;
 
+  // --------------------------------------------------------------------------
   virtual ctkControlPoint* controlPoint(int index)const
   {
     QColor rgb = QColor::fromRgbF(55, 56, 57);
@@ -47,84 +55,53 @@ public:
     cp->P.Value = rgb;
     return cp;
   }
+
+  // --------------------------------------------------------------------------
   virtual QVariant value(qreal pos)const
   {
     QColor rgb = QColor::fromRgbF(55, static_cast<int>(pos), 57);
     return rgb;
   }
 
-  virtual int count()const
-  {
-    return 2;
-  }
-  virtual bool isDiscrete()const
-  {
-    return _discrete;
-  }
-  virtual bool isEditable()const
-  {
-    return false;
-  }
+  // --------------------------------------------------------------------------
+  virtual int count()const { return 2; }
+  virtual bool isDiscrete()const { return Discrete; }
+  virtual bool isEditable()const { return false; }
 
+  // --------------------------------------------------------------------------
   virtual void range(qreal& minRange, qreal& maxRange)const
   {
     minRange = 0.;
     maxRange = 1.;
   }
-  virtual QVariant minValue()const
-  {
-    return 0.;
-  }
-  virtual QVariant maxValue()const
-  {
-    return 0.;
-  }
-  virtual int insertControlPoint(const ctkControlPoint& cp)
-  {
-    Q_UNUSED(cp);
-    return -1;
-  }
 
-  virtual int insertControlPoint(qreal pos)
-  {
-    Q_UNUSED(pos);
-    return -1;
-  }
-
-  virtual void removeControlPoint( qreal pos )
-  {
-    Q_UNUSED(pos);
-  }
-
-  virtual void setControlPointPos(int index, qreal pos)
-  {
-    Q_UNUSED(pos);
-    Q_UNUSED(index);
-  }
-  virtual void setControlPointValue(int index, const QVariant& value)
-  {
-    Q_UNUSED(index);
-    Q_UNUSED(value);
-  }
+  // --------------------------------------------------------------------------
+  virtual QVariant minValue()const { return 0.; }
+  virtual QVariant maxValue()const { return 0.; }
+  virtual int insertControlPoint(const ctkControlPoint& /*cp*/) { return -1; }
+  virtual int insertControlPoint(qreal /*pos*/){ return -1; }
+  virtual void removeControlPoint(qreal /*pos*/) {}
+  virtual void setControlPointPos(int /*index*/, qreal /*pos*/) {}
+  virtual void setControlPointValue(int /*index*/, const QVariant& /*value*/){}
 };
 
+// --------------------------------------------------------------------------
 int ctkTransferFunctionRepresentationTest2( int argc, char * argv [])
 {
   Q_UNUSED(argc);
   Q_UNUSED(argv);
 
-  ctkForcedTransferFunction* dummy = new ctkForcedTransferFunction();
+  QScopedPointer<ctkForcedTransferFunction> dummy(new ctkForcedTransferFunction());
   ctkTransferFunctionRepresentation representation;
 
-  representation.setTransferFunction(dummy);
+  representation.setTransferFunction(dummy.data());
   representation.computeCurve();
   representation.computeGradient();
 
-  dummy->_discrete = false;
-  representation.setTransferFunction(dummy);
+  dummy->Discrete = false;
+  representation.setTransferFunction(dummy.data());
   representation.computeCurve();
   representation.computeGradient();
 
-  delete dummy;
   return EXIT_SUCCESS;
 }

+ 1 - 0
Libs/Core/Testing/Cpp/ctkWorkflowTest2.cpp

@@ -126,6 +126,7 @@ int ctkWorkflowTest2(int argc, char * argv [] )
   ctkWorkflow *workflow = new ctkWorkflow();
   ctkWorkflowStep *step1 = new ctkWorkflowStep(workflow, "Step 1");
   step1->setName("Step 1");
+  step1->setId("FirstStep");
   step1->setDescription("Description for step 1");
   ctkWorkflowStep *step2 = new ctkWorkflowStep(workflow, "Step 2");
   step2->setName("Step 2");

+ 19 - 0
Libs/Core/ctkWorkflow.cpp

@@ -19,6 +19,7 @@
 =========================================================================*/
 
 // Qt includes
+#include <QDebug>
 #include <QStateMachine>
 #include <QState>
 
@@ -538,6 +539,12 @@ ctkWorkflow::~ctkWorkflow()
     {
     d->StateMachine->stop();
     }
+
+  // Clean registered step
+  while (!d->registeredSteps.isEmpty())
+    {
+    delete d->registeredSteps.takeFirst();
+    }
 }
 
 // --------------------------------------------------------------------------
@@ -621,6 +628,18 @@ bool ctkWorkflow::addTransition(ctkWorkflowStep* origin, ctkWorkflowStep* destin
 }
 
 // --------------------------------------------------------------------------
+void ctkWorkflow::registerWorkflowStep(ctkWorkflowStep* step)
+{
+  Q_D(ctkWorkflow);
+  if (!step)
+    {
+    qCritical() << "ctkWorkflow::registerWorkflowStep - Failed to register Null step !";
+    return;
+    }
+  d->registeredSteps << step;
+}
+
+// --------------------------------------------------------------------------
 bool ctkWorkflow::hasTransition(ctkWorkflowStep* origin, ctkWorkflowStep* destination,
                                 const QString& branchId,
                                 const ctkWorkflow::TransitionDirectionality directionality)

+ 9 - 0
Libs/Core/ctkWorkflow.h

@@ -110,6 +110,15 @@ public:
   Q_INVOKABLE ctkWorkflowStep* initialStep()const;
   Q_INVOKABLE virtual void setInitialStep(ctkWorkflowStep* step);
 
+  /// \brief Register ctkWorkflowStep so that ctkWorkflow keeps track of the associated steps
+  /// and clean the memory when appropriate.
+  /// \note This function is declared public for convenience and shouldn't be directly used.
+  /// The step will register itself when instantiated.
+  /// \note Since ctkWorkflowStep are neither QObject nor QWidget, they will be registered. On
+  /// on the othen hand, ctkWorkflowWidgetStep will be managed by their parent QWidget and
+  /// won't be registered.
+  void registerWorkflowStep(ctkWorkflowStep* step);
+
   /// Get the current step of the state machine
   Q_INVOKABLE ctkWorkflowStep* currentStep()const;
 

+ 4 - 1
Libs/Core/ctkWorkflowStep.cpp

@@ -117,6 +117,8 @@ void ctkWorkflowStepPrivate::invokeOnExitCommandInternal(const ctkWorkflowStep*
 // --------------------------------------------------------------------------
 ctkWorkflowStep::ctkWorkflowStep(): d_ptr(new ctkWorkflowStepPrivate(*this))
 {
+  Q_D(ctkWorkflowStep);
+  d->Workflow->registerWorkflowStep(this);
 }
 
 // --------------------------------------------------------------------------
@@ -127,6 +129,8 @@ ctkWorkflowStep::ctkWorkflowStep(ctkWorkflow* newWorkflow, const QString& newId)
 
   d->Id = newId;
   d->Workflow = newWorkflow;
+
+  d->Workflow->registerWorkflowStep(this);
 }
 
 // --------------------------------------------------------------------------
@@ -150,7 +154,6 @@ ctkWorkflowStep::~ctkWorkflowStep()
 
 // --------------------------------------------------------------------------
 CTK_GET_CPP(ctkWorkflowStep, ctkWorkflow*, workflow, Workflow);
-CTK_SET_CPP(ctkWorkflowStep, ctkWorkflow*, setWorkflow, Workflow);
 
 // --------------------------------------------------------------------------
 CTK_GET_CPP(ctkWorkflowStep, QString, id, Id);

+ 3 - 0
Libs/Core/ctkWorkflow_p.h

@@ -266,6 +266,9 @@ public:
   typedef QMap<ctkWorkflowStep*, forwardAndBackwardSteps*> StepToForwardAndBackwardStepMapType;
   typedef QList<ctkWorkflowStep*>                          StepListType;
 
+  // Register a list of pointers to the steps in the worflow for cleaning purpose
+  StepListType registeredSteps;
+
   // Maintain a map of <state, step> key/value pairs, to find the step
   // that a given state belongs to
   typedef QMap<const QAbstractState*, ctkWorkflowStep*>           StateToStepMapType;