Browse Source

Allow CmdLineModuleManager to clear cache

Matt Clarkson 11 years ago
parent
commit
03196ea65a

+ 5 - 0
Applications/ctkCommandLineModuleExplorer/ctkCmdLineModuleExplorerMainWindow.cpp

@@ -267,6 +267,11 @@ void ctkCLModuleExplorerMainWindow::on_actionReset_triggered()
   this->tabList->activeTab()->resetValues();
 }
 
+void ctkCLModuleExplorerMainWindow::on_actionClear_Cache_triggered()
+{
+  moduleManager.clearCache();
+}
+
 void ctkCLModuleExplorerMainWindow::checkModulePaused()
 {
   if (this->currentFutureWatcher.future().isPaused())

+ 1 - 0
Applications/ctkCommandLineModuleExplorer/ctkCmdLineModuleExplorerMainWindow.h

@@ -68,6 +68,7 @@ protected Q_SLOTS:
   void on_actionQuit_triggered();
 
   void on_actionReset_triggered();
+  void on_actionClear_Cache_triggered();
 
   void checkModulePaused();
   void currentModuleResumed();

+ 8 - 2
Applications/ctkCommandLineModuleExplorer/ctkCmdLineModuleExplorerMainWindow.ui

@@ -45,7 +45,7 @@
      <x>0</x>
      <y>0</y>
      <width>1126</width>
-     <height>25</height>
+     <height>22</height>
     </rect>
    </property>
    <widget class="QMenu" name="menuFile">
@@ -66,6 +66,7 @@
     <addaction name="actionReset"/>
     <addaction name="separator"/>
     <addaction name="actionOptions"/>
+    <addaction name="actionClear_Cache"/>
    </widget>
    <addaction name="menuFile"/>
    <addaction name="menuModule"/>
@@ -201,7 +202,7 @@
              <x>0</x>
              <y>0</y>
              <width>250</width>
-             <height>194</height>
+             <height>208</height>
             </rect>
            </property>
            <layout class="QVBoxLayout" name="verticalLayout_5">
@@ -349,6 +350,11 @@
     <string>Reset to default values</string>
    </property>
   </action>
+  <action name="actionClear_Cache">
+   <property name="text">
+    <string>Clear Cache</string>
+   </property>
+  </action>
  </widget>
  <customwidgets>
   <customwidget>

+ 8 - 0
Libs/CommandLineModules/Core/ctkCmdLineModuleCache.cpp

@@ -181,3 +181,11 @@ void ctkCmdLineModuleCache::removeCacheEntry(const QUrl& moduleLocation)
     xmlFile.remove();
   }
 }
+
+void ctkCmdLineModuleCache::clearCache()
+{
+  foreach(const QUrl &url, d->LocationToXmlDescription.keys())
+  {
+    removeCacheEntry(url);
+  }
+}

+ 10 - 0
Libs/CommandLineModules/Core/ctkCmdLineModuleCache_p.h

@@ -32,6 +32,11 @@ class QUrl;
  * \class ctkCmdLineModuleCache
  * \brief Private non-exported class to contain a cache of
  * XML descriptions and time-stamps.
+ *
+ * The intention is that this Cache is an in-memory representation
+ * of a file-system directory containing XML files and a corresponding
+ * timestamp. Hence these should always be in synch.
+ *
  * \ingroup CommandLineModulesCore_API
  */
 class ctkCmdLineModuleCache
@@ -80,6 +85,11 @@ public:
    */
   void removeCacheEntry(const QUrl& moduleLocation);
 
+  /**
+   * @brief Clears all entries from the XML/timestamp cache.
+   */
+  void clearCache();
+
 private:
 
   QScopedPointer<ctkCmdLineModuleCachePrivate> d;

+ 8 - 0
Libs/CommandLineModules/Core/ctkCmdLineModuleManager.cpp

@@ -272,6 +272,14 @@ void ctkCmdLineModuleManager::unregisterModule(const ctkCmdLineModuleReference&
   emit moduleUnregistered(ref);
 }
 
+
+//----------------------------------------------------------------------------
+void ctkCmdLineModuleManager::clearCache()
+{
+  d->ModuleCache->clearCache();
+}
+
+
 //----------------------------------------------------------------------------
 ctkCmdLineModuleReference ctkCmdLineModuleManager::moduleReference(const QUrl &location) const
 {

+ 5 - 0
Libs/CommandLineModules/Core/ctkCmdLineModuleManager.h

@@ -132,6 +132,11 @@ public:
   void unregisterModule(const ctkCmdLineModuleReference& moduleRef);
 
   /**
+   * @brief Clears the XML/timestamp cache.
+   */
+  void clearCache();
+
+  /**
    * @brief Returns a ctkCmdLineModuleReference object for the given URL.
    * @param location The location URL for which to get a module reference.
    * @return The module reference for the location or an invalid module reference