Browse Source

Make the ctkDICOMDatabase emit a databaseChanged() signal

Marco Nolden 14 years ago
parent
commit
0a18f241e3
2 changed files with 12 additions and 1 deletions
  1. 10 0
      Libs/DICOM/Core/ctkDICOMDatabase.cpp
  2. 2 1
      Libs/DICOM/Core/ctkDICOMDatabase.h

+ 10 - 0
Libs/DICOM/Core/ctkDICOMDatabase.cpp

@@ -32,6 +32,7 @@
 #include <QDirIterator>
 #include <QFileInfo>
 #include <QDebug>
+#include <QFileSystemWatcher>
 
 // ctkDICOM includes
 #include "ctkDICOMDatabase.h"
@@ -110,6 +111,11 @@ void ctkDICOMDatabase::openDatabase(const QString databaseFile, const QString& c
     {
       initializeDatabase();
     }
+  if (databaseFile != ":memory")
+  {
+    QFileSystemWatcher* watcher = new QFileSystemWatcher(QStringList(databaseFile),this);
+    connect(watcher, SIGNAL( fileChanged(const QString&)),this, SIGNAL ( databaseChanged() ) );
+  }
 }
 
 
@@ -385,4 +391,8 @@ void ctkDICOMDatabase::insert ( DcmDataset *dataset, QString filename ) {
       statement.exec();
       }
     }
+  if (d->DatabaseFileName == ":memory:")
+    {
+      emit databaseChanged();
+    }
 }

+ 2 - 1
Libs/DICOM/Core/ctkDICOMDatabase.h

@@ -64,7 +64,8 @@ public:
    * Insert into the database if not already exsting.
    */
   void insert ( DcmDataset *dataset );
-
+signals:
+  void databaseChanged();
 protected:
   QScopedPointer<ctkDICOMDatabasePrivate> d_ptr;