瀏覽代碼

Add cancel slot to indexer

Support for import button in dicom app
Steve Pieper 13 年之前
父節點
當前提交
ee57278140
共有 2 個文件被更改,包括 18 次插入1 次删除
  1. 15 1
      Libs/DICOM/Core/ctkDICOMIndexer.cpp
  2. 3 0
      Libs/DICOM/Core/ctkDICOMIndexer.h

+ 15 - 1
Libs/DICOM/Core/ctkDICOMIndexer.cpp

@@ -62,6 +62,7 @@ public:
   ~ctkDICOMIndexerPrivate();
   ~ctkDICOMIndexerPrivate();
 
 
   ctkDICOMAbstractThumbnailGenerator* thumbnailGenerator;
   ctkDICOMAbstractThumbnailGenerator* thumbnailGenerator;
+  bool                    Canceled;
 
 
 };
 };
 
 
@@ -71,6 +72,7 @@ public:
 //------------------------------------------------------------------------------
 //------------------------------------------------------------------------------
 ctkDICOMIndexerPrivate::ctkDICOMIndexerPrivate()
 ctkDICOMIndexerPrivate::ctkDICOMIndexerPrivate()
 {
 {
+  this->Canceled = false;
 }
 }
 
 
 //------------------------------------------------------------------------------
 //------------------------------------------------------------------------------
@@ -114,6 +116,8 @@ void ctkDICOMIndexer::addDirectory(ctkDICOMDatabase& ctkDICOMDatabase,
                                    const QString& directoryName,
                                    const QString& directoryName,
                                    const QString& destinationDirectoryName)
                                    const QString& destinationDirectoryName)
 {
 {
+  Q_D(ctkDICOMIndexer);
+
   const std::string src_directory(directoryName.toStdString());
   const std::string src_directory(directoryName.toStdString());
 
 
   OFList<OFString> originalDcmtkFileNames;
   OFList<OFString> originalDcmtkFileNames;
@@ -139,9 +143,13 @@ void ctkDICOMIndexer::addDirectory(ctkDICOMDatabase& ctkDICOMDatabase,
   /* iterate over all input filenames */
   /* iterate over all input filenames */
   int fileNumber = 0;
   int fileNumber = 0;
   int currentProgress = -1;
   int currentProgress = -1;
-
+  d->Canceled = false;
   while (iter != last)
   while (iter != last)
   {
   {
+    if (d->Canceled)
+      {
+      break;
+      }
     emit indexingFileNumber(++fileNumber);
     emit indexingFileNumber(++fileNumber);
     int newProgress = ( fileNumber * 100 ) / totalNumberOfFiles;
     int newProgress = ( fileNumber * 100 ) / totalNumberOfFiles;
     if (newProgress != currentProgress)
     if (newProgress != currentProgress)
@@ -196,3 +204,9 @@ void ctkDICOMIndexer::refreshDatabase(ctkDICOMDatabase& dicomDatabase, const QSt
   */ 
   */ 
   }
   }
 
 
+//----------------------------------------------------------------------------
+void ctkDICOMIndexer::cancel()
+{
+  Q_D(ctkDICOMIndexer);
+  d->Canceled = true;
+}

+ 3 - 0
Libs/DICOM/Core/ctkDICOMIndexer.h

@@ -69,6 +69,9 @@ Q_SIGNALS:
   void indexingFilePath(QString);
   void indexingFilePath(QString);
   void progress(int);
   void progress(int);
 
 
+public Q_SLOTS:
+  void cancel();
+
 protected:
 protected:
   QScopedPointer<ctkDICOMIndexerPrivate> d_ptr;
   QScopedPointer<ctkDICOMIndexerPrivate> d_ptr;