瀏覽代碼

Merge pull request #748 from lassoan/multi-dicom-browser-refresh-issue

BUG: Fixed DICOM browser refresh issue when multiple browsers are created
Andras Lasso 7 年之前
父節點
當前提交
a83cec945d
共有 2 個文件被更改,包括 12 次插入3 次删除
  1. 7 1
      Libs/DICOM/Core/ctkDICOMDatabase.cpp
  2. 5 2
      Libs/DICOM/Core/ctkDICOMDatabase.h

+ 7 - 1
Libs/DICOM/Core/ctkDICOMDatabase.cpp

@@ -31,6 +31,7 @@
 #include <QSqlQuery>
 #include <QSqlRecord>
 #include <QStringList>
+#include <QUuid>
 #include <QVariant>
 
 // ctkDICOM includes
@@ -293,7 +294,12 @@ void ctkDICOMDatabase::openDatabase(const QString databaseFile, const QString& c
 {
   Q_D(ctkDICOMDatabase);
   d->DatabaseFileName = databaseFile;
-  d->Database = QSqlDatabase::addDatabase("QSQLITE", connectionName);
+  QString verifiedConnectionName = connectionName;
+  if (verifiedConnectionName.isEmpty())
+    {
+    verifiedConnectionName = QUuid::createUuid().toString();
+    }
+  d->Database = QSqlDatabase::addDatabase("QSQLITE", verifiedConnectionName);
   d->Database.setDatabaseName(databaseFile);
   if ( ! (d->Database.open()) )
     {

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

@@ -101,10 +101,13 @@ public:
   ///        stored to. If specified with ":memory:", the database is not
   ///        written to disk at all but instead only kept in memory (and
   ///        thus expires after destruction of this object).
-  /// @param connectionName The database connection name.
+  /// @param connectionName The database connection name. If not specified
+  ///        then a random name is generated (reusing a connection name
+  ///        must be avoided as it breaks previously created database object
+  ///        that used the same connection name).
   /// @param update the schema if it is found to be out of date
   Q_INVOKABLE virtual void openDatabase(const QString databaseFile,
-                                        const QString& connectionName = "DICOM-DB");
+                                        const QString& connectionName = "");
 
   ///
   /// close the database. It must not be used afterwards.