Browse Source

Support uncheckable header in ctkCheckableHeaderView

Julien Finet 14 years ago
parent
commit
413b2b3796
1 changed files with 10 additions and 7 deletions
  1. 10 7
      Libs/Widgets/ctkCheckableHeaderView.cpp

+ 10 - 7
Libs/Widgets/ctkCheckableHeaderView.cpp

@@ -156,10 +156,18 @@ void ctkCheckableHeaderViewPrivate
 ::updateCheckState(const QModelIndex& modelIndex)
 ::updateCheckState(const QModelIndex& modelIndex)
 {
 {
   Q_Q(ctkCheckableHeaderView);
   Q_Q(ctkCheckableHeaderView);
-  
+  QVariant indexCheckState = modelIndex != q->rootIndex() ?
+    q->model()->data(modelIndex, Qt::CheckStateRole):
+    q->model()->headerData(0, q->orientation(), Qt::CheckStateRole);
+  bool checkable = false;
+  int oldCheckState = indexCheckState.toInt(&checkable);
+  if (!checkable)
+    {
+    return;
+    }
+
   Qt::CheckState newCheckState = Qt::PartiallyChecked;
   Qt::CheckState newCheckState = Qt::PartiallyChecked;
   bool firstCheckableChild = true;
   bool firstCheckableChild = true;
-  bool checkable = false;
   const int rowCount = q->orientation() == Qt::Horizontal ?
   const int rowCount = q->orientation() == Qt::Horizontal ?
     q->model()->rowCount(modelIndex) : 1;
     q->model()->rowCount(modelIndex) : 1;
   const int columnCount = q->orientation() == Qt::Vertical ?
   const int columnCount = q->orientation() == Qt::Vertical ?
@@ -194,11 +202,6 @@ void ctkCheckableHeaderViewPrivate
       break;
       break;
       } 
       } 
     }
     }
-  QVariant indexCheckState = modelIndex != q->rootIndex() ?
-    q->model()->data(modelIndex, Qt::CheckStateRole):
-    q->model()->headerData(0, q->orientation(), Qt::CheckStateRole);
-  int oldCheckState = indexCheckState.toInt(&checkable);
-  Q_ASSERT(checkable);
   if (oldCheckState == newCheckState)
   if (oldCheckState == newCheckState)
     {
     {
     return;
     return;