Explorar o código

Move ctkDICOMModel/checkable header initialization

up to the initialization of the ctkDICOMQueryRetrieveWidget constructor
Julien Finet %!s(int64=14) %!d(string=hai) anos
pai
achega
2c0d20e523

+ 1 - 1
Libs/DICOM/Core/ctkDICOMModel.cpp

@@ -398,7 +398,7 @@ bool ctkDICOMModel::canFetchMore ( const QModelIndex & parentValue ) const
 {
   Q_D(const ctkDICOMModel);
   Node* node = d->nodeFromIndex(parentValue);
-  return !node->AtEnd;
+  return node ? !node->AtEnd : false;
 }
 
 //------------------------------------------------------------------------------

+ 16 - 15
Libs/DICOM/Widgets/ctkDICOMQueryRetrieveWidget.cpp

@@ -38,13 +38,13 @@ public:
 //----------------------------------------------------------------------------
 // ctkDICOMQueryRetrieveWidgetPrivate methods
 
-
 //----------------------------------------------------------------------------
 // ctkDICOMQueryRetrieveWidget methods
 
 //----------------------------------------------------------------------------
-ctkDICOMQueryRetrieveWidget::ctkDICOMQueryRetrieveWidget(QWidget* _parent):Superclass(_parent), 
-  d_ptr(new ctkDICOMQueryRetrieveWidgetPrivate)
+ctkDICOMQueryRetrieveWidget::ctkDICOMQueryRetrieveWidget(QWidget* parentWidget)
+  : Superclass(parentWidget) 
+  , d_ptr(new ctkDICOMQueryRetrieveWidgetPrivate)
 {
   Q_D(ctkDICOMQueryRetrieveWidget);
   
@@ -52,6 +52,19 @@ ctkDICOMQueryRetrieveWidget::ctkDICOMQueryRetrieveWidget(QWidget* _parent):Super
 
   connect(d->QueryButton, SIGNAL(clicked()), this, SLOT(processQuery()));
   connect(d->RetrieveButton, SIGNAL(clicked()), this, SLOT(processRetrieve()));
+
+  d->results->setModel(&d->model);
+  d->model.setHeaderData(0, Qt::Horizontal, Qt::Unchecked, Qt::CheckStateRole);
+
+  QHeaderView* previousHeaderView = d->results->header();
+  ctkCheckableHeaderView* headerView = new ctkCheckableHeaderView(Qt::Horizontal, d->results);
+  headerView->setClickable(previousHeaderView->isClickable());
+  headerView->setMovable(previousHeaderView->isMovable());
+  headerView->setHighlightSections(previousHeaderView->highlightSections());
+  headerView->setPropagateToItems(true);
+  d->results->setHeader(headerView);
+  // headerView is hidden because it was created with a visisble parent widget 
+  headerView->setHidden(false);
 }
 
 //----------------------------------------------------------------------------
@@ -126,20 +139,8 @@ void ctkDICOMQueryRetrieveWidget::processQuery()
   }
   
   // checkable headers - allow user to select the patient/studies to retrieve
-  d->results->setModel(&d->model);
   d->model.setDatabase(d->queryResultDatabase.database());
 
-  d->model.setHeaderData(0, Qt::Horizontal, Qt::Unchecked, Qt::CheckStateRole);
-  QHeaderView* previousHeaderView = d->results->header();
-  ctkCheckableHeaderView* headerView = new ctkCheckableHeaderView(Qt::Horizontal, d->results);
-  headerView->setClickable(previousHeaderView->isClickable());
-  headerView->setMovable(previousHeaderView->isMovable());
-  headerView->setHighlightSections(previousHeaderView->highlightSections());
-  headerView->setPropagateToItems(true);
-  d->results->setHeader(headerView);
-  // headerView is hidden because it was created with a visisble parent widget 
-  headerView->setHidden(false);
-
   d->RetrieveButton->setEnabled(d->model.rowCount());
 }
 

+ 2 - 3
Libs/Widgets/ctkCheckableHeaderView.cpp

@@ -289,13 +289,12 @@ void ctkCheckableHeaderView::updateHeaderData(Qt::Orientation orient,
 void ctkCheckableHeaderView::updateHeaders(int firstSection, int lastSection)
 {
   Q_D(ctkCheckableHeaderView);
-  if(d->HeaderIsUpdating)
+  QAbstractItemModel *current = this->model();
+  if(d->HeaderIsUpdating || !current)
     {
     return;
     }
   d->HeaderIsUpdating = true;
-  QAbstractItemModel *current = this->model();
-  Q_ASSERT(current);
 
   firstSection = qBound(0, firstSection, this->count() -1);
   lastSection = qBound(0, lastSection, this->count() -1);