Quellcode durchsuchen

ctkModelTester optionally tests valid displayrole data

Julien Finet vor 14 Jahren
Ursprung
Commit
87c276da4b
2 geänderte Dateien mit 30 neuen und 0 gelöschten Zeilen
  1. 22 0
      Libs/Core/ctkModelTester.cpp
  2. 8 0
      Libs/Core/ctkModelTester.h

+ 22 - 0
Libs/Core/ctkModelTester.cpp

@@ -33,6 +33,7 @@ public:
   QAbstractItemModel *Model;
   bool ThrowOnError;
   bool NestedInserts;
+  bool TestDataEnabled;
 
   struct Change
   {
@@ -59,6 +60,7 @@ ctkModelTesterPrivate::ctkModelTesterPrivate()
   this->Model = 0;
   this->ThrowOnError = true;
   this->NestedInserts = false;
+  this->TestDataEnabled = true;
 }
 
 //-----------------------------------------------------------------------------
@@ -160,6 +162,21 @@ bool ctkModelTester::nestedInserts()const
   return d->NestedInserts;
 }
 
+
+//-----------------------------------------------------------------------------
+void ctkModelTester::setTestDataEnabled( bool enable )
+{
+  Q_D(ctkModelTester);
+  d->TestDataEnabled = enable;
+}
+
+//-----------------------------------------------------------------------------
+bool ctkModelTester::testDataEnabled()const
+{
+  Q_D(const ctkModelTester);
+  return d->TestDataEnabled;
+}
+
 //-----------------------------------------------------------------------------
 void  ctkModelTester::test(bool result, const QString& errorString)const
 {
@@ -205,6 +222,11 @@ void ctkModelTester::testModelIndex(const QModelIndex& index)const
 //-----------------------------------------------------------------------------
 void ctkModelTester::testData(const QModelIndex& index)const
 {
+  Q_D(const ctkModelTester);
+  if (!d->TestDataEnabled)
+    {
+    return;
+    }
   if (!index.isValid())
     {
     this->test(!index.data(Qt::DisplayRole).isValid(), 

+ 8 - 0
Libs/Core/ctkModelTester.h

@@ -83,6 +83,14 @@ public:
   bool nestedInserts()const;
 
   ///
+  /// When TestData is enabled, it checks if the display role of a valid
+  /// model index is valid too.
+  /// You can disable the test if you are ok with temporary invalid display
+  /// roles.
+  void setTestDataEnabled(bool enable);
+  bool testDataEnabled()const;
+
+  ///
   /// Test the data consistency of a QModelIndex.
   /// Note: Only DisplayRole is checked.
   virtual void testData(const QModelIndex& index)const;