]> Creatis software - clitk.git/blobdiff - vv/vvMainWindow.cxx
Add a watcher to file
[clitk.git] / vv / vvMainWindow.cxx
index 30f7da57693088207b345d4420971b291daf6858..2b414926abb673fd0bfa10f8eae36f1f5b750646 100644 (file)
@@ -25,6 +25,7 @@ It is distributed under dual licence
 #include <QUrl>
 #include <QSettings>
 #include <QShortcut>
+#include <QFileSystemWatcher>
 
 // VV include
 #include "vvMainWindow.h"
@@ -386,6 +387,9 @@ vvMainWindow::vvMainWindow():vvMainWindowBase()
     updateRecentlyOpenedFilesMenu(recent_files);
   }
 
+  //Update and get vv parameters
+  setVVSettings();
+
   // Adding all new tools (insertion in the menu)
   vvToolManager::GetInstance()->InsertToolsInMenu(this);
   vvToolManager::GetInstance()->EnableToolsInMenu(this, false);
@@ -832,8 +836,8 @@ void vvMainWindow::dropEvent(QDropEvent *event)
   if (!mimeData->hasUrls())
     return;
   std::vector<std::string> images;
-  for (auto const & url : mimeData->urls()) {
-    images.push_back(url.toLocalFile().toStdString());
+  for (int i=0; i<mimeData->urls().size(); ++i) {
+    images.push_back(mimeData->urls()[i].toLocalFile().toStdString());
   }
   LoadImages(images, vvImageReader::IMAGE);
 }
@@ -979,6 +983,12 @@ void vvMainWindow::LoadImages(std::vector<std::string> files, vvImageReader::Loa
 
         linkPanel->addImage(imageManager->GetFileName(), id.toStdString());
 
+        //Create a watcher to see if the image file is modified. In such a case, reload it automatically
+        QFileSystemWatcher* watcher = new QFileSystemWatcher;
+        watcher->addPath(files[i].c_str());
+        connect(watcher, SIGNAL(fileChanged(const QString&)), this, SLOT(SlotFileChanged(const QString&)));
+
+
         connect(mSlicerManagers.back(), SIGNAL(currentImageChanged(std::string)),
           this,SLOT(CurrentImageChanged(std::string)));
         connect(mSlicerManagers.back(), SIGNAL(currentPickedImageChanged(std::string)),
@@ -1438,6 +1448,29 @@ QString vvMainWindow::GetVectorIntAsString(std::vector<int> vectorInt)
 }
 //------------------------------------------------------------------------------
 
+//------------------------------------------------------------------------------
+void vvMainWindow::SlotFileChanged(const QString& pathname)
+{
+  std::vector<QTreeWidgetItem*> items = GetItemFromPathname(pathname);
+  for (unsigned int i=0; i< items.size(); ++i)
+    ReloadImage(items[i], 0);
+}
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+std::vector<QTreeWidgetItem*> vvMainWindow::GetItemFromPathname(const QString& pathname)
+{
+  std::vector<QTreeWidgetItem*> items;
+  for (int i = 0; i < DataTree->topLevelItemCount(); ++i) {
+    QString tempItemPathname(DataTree->topLevelItem(i)->data(COLUMN_IMAGE_NAME,Qt::UserRole).toString());
+    tempItemPathname = tempItemPathname.left(tempItemPathname.length() - 1);
+    if (tempItemPathname == pathname)
+      items.push_back(DataTree->topLevelItem(i));
+  }
+  return items;
+}
+//------------------------------------------------------------------------------
+
 //------------------------------------------------------------------------------
 //this actually returns the SlicerManager index!
 int vvMainWindow::GetSlicerIndexFromItem(QTreeWidgetItem* item)