Explorar o código

Implemented next and previous buttons for image previewer

nherlambang %!s(int64=14) %!d(string=hai) anos
pai
achega
1e9eacd5c7

+ 123 - 1
Libs/DICOM/Widgets/ctkDICOMAppWidget.cpp

@@ -212,7 +212,6 @@ void ctkDICOMAppWidget::onThumbnailSelected(const ctkDICOMThumbnailWidget& widge
 {
     Q_D(ctkDICOMAppWidget);
 
-    logger.debug("Thumbnail selected");
     d->imagePreview->onModelSelected(widget.sourceIndex());
 }
 
@@ -283,30 +282,153 @@ void ctkDICOMAppWidget::onModelSelected(const QModelIndex &index){
 
 //----------------------------------------------------------------------------
 void ctkDICOMAppWidget::onNextImage(){
+    Q_D(ctkDICOMAppWidget);
+
+    QModelIndex currentIndex = d->imagePreview->currentImageIndex();
+
+    if(currentIndex.isValid()){
+        ctkDICOMModel* model = const_cast<ctkDICOMModel*>(qobject_cast<const ctkDICOMModel*>(currentIndex.model()));
+
+        if(model){
+            QModelIndex seriesIndex = currentIndex.parent();
+
+            int imageCount = model->rowCount(seriesIndex);
+            int imageID = currentIndex.row();
+
+            imageID = (imageID+1)%imageCount;
+
+            QModelIndex nextIndex = currentIndex.sibling(imageID, 0);
 
+            d->imagePreview->onModelSelected(nextIndex);
+        }
+    }
 }
 
 //----------------------------------------------------------------------------
 void ctkDICOMAppWidget::onPreviousImage(){
+    Q_D(ctkDICOMAppWidget);
+
+    QModelIndex currentIndex = d->imagePreview->currentImageIndex();
+
+    if(currentIndex.isValid()){
+        ctkDICOMModel* model = const_cast<ctkDICOMModel*>(qobject_cast<const ctkDICOMModel*>(currentIndex.model()));
+
+        if(model){
+            QModelIndex seriesIndex = currentIndex.parent();
+
+            int imageCount = model->rowCount(seriesIndex);
+            int imageID = currentIndex.row();
 
+            imageID--;
+            if(imageID < 0) imageID += imageCount;
+
+            QModelIndex prevIndex = currentIndex.sibling(imageID, 0);
+
+            d->imagePreview->onModelSelected(prevIndex);
+        }
+    }
 }
 
 //----------------------------------------------------------------------------
 void ctkDICOMAppWidget::onNextSeries(){
+    Q_D(ctkDICOMAppWidget);
+
+    QModelIndex currentIndex = d->imagePreview->currentImageIndex();
+
+    if(currentIndex.isValid()){
+        ctkDICOMModel* model = const_cast<ctkDICOMModel*>(qobject_cast<const ctkDICOMModel*>(currentIndex.model()));
 
+        if(model){
+            QModelIndex seriesIndex = currentIndex.parent();
+            QModelIndex studyIndex = seriesIndex.parent();
+
+            int seriesCount = model->rowCount(studyIndex);
+            int seriesID = seriesIndex.row();
+
+            seriesID = (seriesID + 1)%seriesCount;
+
+            QModelIndex nextIndex = seriesIndex.sibling(seriesID, 0);
+
+            d->imagePreview->onModelSelected(nextIndex);
+        }
+    }
 }
 
 //----------------------------------------------------------------------------
 void ctkDICOMAppWidget::onPreviousSeries(){
+    Q_D(ctkDICOMAppWidget);
+
+    QModelIndex currentIndex = d->imagePreview->currentImageIndex();
+
+    if(currentIndex.isValid()){
+        ctkDICOMModel* model = const_cast<ctkDICOMModel*>(qobject_cast<const ctkDICOMModel*>(currentIndex.model()));
+
+        if(model){
+            QModelIndex seriesIndex = currentIndex.parent();
+            QModelIndex studyIndex = seriesIndex.parent();
+
+            int seriesCount = model->rowCount(studyIndex);
+            int seriesID = seriesIndex.row();
+
+            seriesID--;
+            if(seriesID < 0) seriesID += seriesCount;
+
+            QModelIndex nextIndex = seriesIndex.sibling(seriesID, 0);
 
+            d->imagePreview->onModelSelected(nextIndex);
+        }
+    }
 }
 
 //----------------------------------------------------------------------------
 void ctkDICOMAppWidget::onNextStudy(){
+    Q_D(ctkDICOMAppWidget);
+
+    QModelIndex currentIndex = d->imagePreview->currentImageIndex();
+
+    if(currentIndex.isValid()){
+        ctkDICOMModel* model = const_cast<ctkDICOMModel*>(qobject_cast<const ctkDICOMModel*>(currentIndex.model()));
+
+        if(model){
+            QModelIndex seriesIndex = currentIndex.parent();
+            QModelIndex studyIndex = seriesIndex.parent();
+            QModelIndex patientIndex = studyIndex.parent();
+
+            int studyCount = model->rowCount(patientIndex);
+            int studyID = studyIndex.row();
 
+            studyID = (studyID + 1)%studyCount;
+
+            QModelIndex nextIndex = studyIndex.sibling(studyID, 0);
+
+            d->imagePreview->onModelSelected(nextIndex);
+        }
+    }
 }
 
 //----------------------------------------------------------------------------
 void ctkDICOMAppWidget::onPreviousStudy(){
+    Q_D(ctkDICOMAppWidget);
+
+    QModelIndex currentIndex = d->imagePreview->currentImageIndex();
+
+    if(currentIndex.isValid()){
+        ctkDICOMModel* model = const_cast<ctkDICOMModel*>(qobject_cast<const ctkDICOMModel*>(currentIndex.model()));
 
+        if(model){
+            QModelIndex seriesIndex = currentIndex.parent();
+            QModelIndex studyIndex = seriesIndex.parent();
+            QModelIndex patientIndex = studyIndex.parent();
+
+            int studyCount = model->rowCount(patientIndex);
+            int studyID = studyIndex.row();
+
+            studyID--;
+            if(studyID < 0) studyID += studyCount;
+
+            QModelIndex nextIndex = studyIndex.sibling(studyID, 0);
+
+            d->imagePreview->onModelSelected(nextIndex);
+        }
+    }
 }

+ 15 - 4
Libs/DICOM/Widgets/ctkDICOMDatasetView.cpp

@@ -58,6 +58,8 @@ public:
 
   QString databaseDirectory;
 
+  QModelIndex currentImageIndex;
+
   void init();
 
   void onPatientModelSelected(const QModelIndex& index);
@@ -109,6 +111,7 @@ void ctkDICOMDatasetViewPrivate::onPatientModelSelected(const QModelIndex &index
           ctkDICOMImage ctkImage( & dcmImage );
           q->clearImages();
           q->addImage( ctkImage );
+          this->currentImageIndex = imageIndex;
         }else{
           q->clearImages();
         }
@@ -139,6 +142,7 @@ void ctkDICOMDatasetViewPrivate::onStudyModelSelected(const QModelIndex &index){
           ctkDICOMImage ctkImage( & dcmImage );
           q->clearImages();
           q->addImage( ctkImage );
+          this->currentImageIndex = imageIndex;
         }else{
           q->clearImages();
         }
@@ -169,6 +173,7 @@ void ctkDICOMDatasetViewPrivate::onSeriesModelSelected(const QModelIndex &index)
           ctkDICOMImage ctkImage( & dcmImage );
           q->clearImages();
           q->addImage( ctkImage );
+          this->currentImageIndex = imageIndex;
         }else{
           q->clearImages();
         }
@@ -199,6 +204,7 @@ void ctkDICOMDatasetViewPrivate::onImageModelSelected(const QModelIndex &index){
           ctkDICOMImage ctkImage( & dcmImage );
           q->clearImages();
           q->addImage( ctkImage );
+          this->currentImageIndex = imageIndex;
         }else{
           q->clearImages();
         }
@@ -239,6 +245,13 @@ void ctkDICOMDatasetView::setDatabaseDirectory(const QString &directory){
 }
 
 // -------------------------------------------------------------------------
+QModelIndex ctkDICOMDatasetView::currentImageIndex(){
+    Q_D(ctkDICOMDatasetView);
+
+    return d->currentImageIndex;
+}
+
+// -------------------------------------------------------------------------
 void ctkDICOMDatasetView::addImage( const ctkDICOMImage & image )
 {
   for( unsigned int i=0; i<image.frameCount(); ++i )
@@ -260,6 +273,7 @@ void ctkDICOMDatasetView::update( bool zoomChanged,
   Superclass::update( zoomChanged, sizeChanged );
 }
 
+// -------------------------------------------------------------------------
 void ctkDICOMDatasetView::onModelSelected(const QModelIndex &index){
     Q_D(ctkDICOMDatasetView);
 
@@ -268,17 +282,14 @@ void ctkDICOMDatasetView::onModelSelected(const QModelIndex &index){
     if(model){
         QModelIndex index0 = index.sibling(index.row(), 0);
 
+
         if ( model->data(index0,ctkDICOMModel::TypeRole) == ctkDICOMModel::PatientType ){
-            logger.debug("PatientType");
             d->onPatientModelSelected(index0);
         }else if ( model->data(index0,ctkDICOMModel::TypeRole) == ctkDICOMModel::StudyType ){
-            logger.debug("StudyType");
             d->onStudyModelSelected(index0);
         }else if ( model->data(index0,ctkDICOMModel::TypeRole) == ctkDICOMModel::SeriesType ){
-            logger.debug("SeriesType");
             d->onSeriesModelSelected(index0);
         }else if ( model->data(index0,ctkDICOMModel::TypeRole) == ctkDICOMModel::ImageType ){
-            logger.debug("ImageType");
             d->onImageModelSelected(index0);
         }
     }

+ 2 - 0
Libs/DICOM/Widgets/ctkDICOMDatasetView.h

@@ -55,6 +55,8 @@ public:
 
   void setDatabaseDirectory(const QString& directory);
 
+  QModelIndex currentImageIndex();
+
 public slots:
 
   void addImage( const ctkDICOMImage & image );