Bladeren bron

Merge branch 'dicom-database-notify-changed'

Marco Nolden 14 jaren geleden
bovenliggende
commit
dd9219398b
3 gewijzigde bestanden met toevoegingen van 15 en 3 verwijderingen
  1. 10 0
      Libs/DICOM/Core/ctkDICOMDatabase.cpp
  2. 2 1
      Libs/DICOM/Core/ctkDICOMDatabase.h
  3. 3 2
      Libs/DICOM/Core/ctkDICOMModel.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;
 

+ 3 - 2
Libs/DICOM/Core/ctkDICOMModel.h

@@ -36,7 +36,7 @@ public:
   virtual ~ctkDICOMModel();
 
   void setDatabase(const QSqlDatabase& dataBase);
-  virtual void reset();
+
 
   virtual bool canFetchMore ( const QModelIndex & parent ) const;
   virtual int columnCount ( const QModelIndex & parent = QModelIndex() ) const;
@@ -53,7 +53,8 @@ public:
   virtual bool setHeaderData ( int section, Qt::Orientation orientation, const QVariant & value, int role = Qt::EditRole );
   // Sorting resets the model because fetched/unfetched items could disappear/appear respectively.
   virtual void sort(int column, Qt::SortOrder order = Qt::AscendingOrder);
-
+public slots:
+  virtual void reset();
 protected:
   QScopedPointer<ctkDICOMModelPrivate> d_ptr;