Ver código fonte

Use CTK settings classes for persisting user values.

Sascha Zelzer 13 anos atrás
pai
commit
3c491165d0

+ 5 - 0
Applications/ctkCommandLineModuleExplorer/CMakeLists.txt

@@ -6,9 +6,11 @@ project(ctkCommandLineModuleExplorer)
 
 set(KIT_SRCS
   ctkCommandLineModuleExplorerMain.cpp
+  ctkCmdLineModuleExplorerConstants.cpp
   ctkCmdLineModuleExplorerDirectorySettings.cpp
   ctkCmdLineModuleExplorerMainWindow.h
   ctkCmdLineModuleExplorerMainWindow.cpp
+  ctkCmdLineModuleExplorerModulesSettings.cpp
   ctkCmdLineModuleExplorerProgressWidget.cpp
   ctkCmdLineModuleExplorerTabList.cpp
   ctkCmdLineModuleExplorerTreeWidget.cpp
@@ -17,6 +19,7 @@ set(KIT_SRCS
 # Headers that should run through moc
 set(KIT_MOC_SRCS
   ctkCmdLineModuleExplorerMainWindow.h
+  ctkCmdLineModuleExplorerModulesSettings.h
   ctkCmdLineModuleExplorerProgressWidget.h
   ctkCmdLineModuleExplorerTabList.h
   ctkCmdLineModuleExplorerTreeWidget.h
@@ -24,7 +27,9 @@ set(KIT_MOC_SRCS
 
 # UI files
 set(KIT_UI_FORMS
+  ctkCmdLineModuleExplorerDirectorySettings.ui
   ctkCmdLineModuleExplorerMainWindow.ui
+  ctkCmdLineModuleExplorerModulesSettings.ui
   ctkCmdLineModuleExplorerProgressWidget.ui
 )
 

+ 25 - 0
Applications/ctkCommandLineModuleExplorer/ctkCmdLineModuleExplorerConstants.cpp

@@ -0,0 +1,25 @@
+/*=============================================================================
+
+  Library: CTK
+
+  Copyright (c) German Cancer Research Center,
+    Division of Medical and Biological Informatics
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+
+=============================================================================*/
+
+#include "ctkCmdLineModuleExplorerConstants.h"
+
+const QString ctkCmdLineModuleExplorerConstants::KEY_SEARCH_PATHS = "ModuleSearchPaths";
+const QString ctkCmdLineModuleExplorerConstants::KEY_REGISTERED_MODULES = "RegisteredModules";

+ 33 - 0
Applications/ctkCommandLineModuleExplorer/ctkCmdLineModuleExplorerConstants.h

@@ -0,0 +1,33 @@
+/*=============================================================================
+
+  Library: CTK
+
+  Copyright (c) German Cancer Research Center,
+    Division of Medical and Biological Informatics
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+
+=============================================================================*/
+
+#ifndef CTKCMDLINEMODULEEXPLORERCONSTANTS_H
+#define CTKCMDLINEMODULEEXPLORERCONSTANTS_H
+
+#include <QString>
+
+struct ctkCmdLineModuleExplorerConstants
+{
+  static const QString KEY_SEARCH_PATHS;
+  static const QString KEY_REGISTERED_MODULES;
+};
+
+#endif // CTKCMDLINEMODULEEXPLORERCONSTANTS_H

+ 18 - 4
Applications/ctkCommandLineModuleExplorer/ctkCmdLineModuleExplorerDirectorySettings.cpp

@@ -20,14 +20,28 @@
 =============================================================================*/
 
 #include "ctkCmdLineModuleExplorerDirectorySettings.h"
+#include "ctkCmdLineModuleExplorerConstants.h"
 
 #include <ctkPathListWidget.h>
+#include <ctkCmdLineModuleDirectoryWatcher.h>
 
 #include <QVBoxLayout>
 
-ctkCmdLineModuleExplorerDirectorySettings::ctkCmdLineModuleExplorerDirectorySettings()
+ctkCmdLineModuleExplorerDirectorySettings::ctkCmdLineModuleExplorerDirectorySettings(ctkCmdLineModuleDirectoryWatcher *directoryWatcher)
+  : DirectoryWatcher(directoryWatcher)
 {
-  this->setWindowTitle("Module Paths");
-  this->setLayout(new QVBoxLayout());
-  this->layout()->addWidget(new ctkPathListWidget());
+  this->setupUi(this);
+
+  this->PathListButtonsWidget->init(this->PathListWidget);
+
+  this->registerProperty(ctkCmdLineModuleExplorerConstants::KEY_SEARCH_PATHS,
+                         this->PathListWidget, "paths", SIGNAL(pathsChanged(QStringList,QStringList)));
+}
+
+void ctkCmdLineModuleExplorerDirectorySettings::applySettings()
+{
+  QVariant newSearchPaths = this->propertyValue(ctkCmdLineModuleExplorerConstants::KEY_SEARCH_PATHS);
+  this->DirectoryWatcher->setDirectories(newSearchPaths.toStringList());
+
+  ctkSettingsPanel::applySettings();
 }

+ 13 - 2
Applications/ctkCommandLineModuleExplorer/ctkCmdLineModuleExplorerDirectorySettings.h

@@ -24,14 +24,25 @@
 
 #include <ctkSettingsPanel.h>
 
+#include "ui_ctkCmdLineModuleExplorerDirectorySettings.h"
+
+class ctkCmdLineModuleDirectoryWatcher;
+
 /**
  * \class ctkCmdLineModuleExplorerDirectorySettings
  * \brief Example application settings panel.
  */
-class ctkCmdLineModuleExplorerDirectorySettings : public ctkSettingsPanel
+class ctkCmdLineModuleExplorerDirectorySettings : public ctkSettingsPanel, public Ui::ctkCmdLineModuleExplorerDirectorySettings
 {
 public:
-  ctkCmdLineModuleExplorerDirectorySettings();
+  ctkCmdLineModuleExplorerDirectorySettings(ctkCmdLineModuleDirectoryWatcher* directoryWatcher);
+
+  void applySettings();
+
+private:
+
+  ctkCmdLineModuleDirectoryWatcher* DirectoryWatcher;
+
 };
 
 #endif // CTKCMDLINEMODULEEXPLORERDIRECTORYSETTINGS_H

+ 105 - 0
Applications/ctkCommandLineModuleExplorer/ctkCmdLineModuleExplorerDirectorySettings.ui

@@ -0,0 +1,105 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>ctkCmdLineModuleExplorerDirectorySettings</class>
+ <widget class="QWidget" name="ctkCmdLineModuleExplorerDirectorySettings">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>400</width>
+    <height>300</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Search Paths</string>
+  </property>
+  <layout class="QVBoxLayout" name="verticalLayout_2">
+   <property name="leftMargin">
+    <number>6</number>
+   </property>
+   <property name="topMargin">
+    <number>0</number>
+   </property>
+   <property name="rightMargin">
+    <number>0</number>
+   </property>
+   <property name="bottomMargin">
+    <number>0</number>
+   </property>
+   <item>
+    <widget class="QGroupBox" name="groupBox">
+     <property name="title">
+      <string>Module Search Paths</string>
+     </property>
+     <layout class="QVBoxLayout" name="verticalLayout_3">
+      <item>
+       <layout class="QGridLayout" name="gridLayout">
+        <item row="1" column="1">
+         <layout class="QVBoxLayout" name="verticalLayout">
+          <item>
+           <widget class="ctkPathListButtonsWidget" name="PathListButtonsWidget">
+            <property name="buttonsAutoRaise">
+             <bool>true</bool>
+            </property>
+            <property name="orientation">
+             <enum>Qt::Vertical</enum>
+            </property>
+           </widget>
+          </item>
+          <item>
+           <spacer name="verticalSpacer">
+            <property name="orientation">
+             <enum>Qt::Vertical</enum>
+            </property>
+            <property name="sizeHint" stdset="0">
+             <size>
+              <width>20</width>
+              <height>40</height>
+             </size>
+            </property>
+           </spacer>
+          </item>
+         </layout>
+        </item>
+        <item row="1" column="0">
+         <widget class="ctkPathListWidget" name="PathListWidget">
+          <property name="textElideMode">
+           <enum>Qt::ElideMiddle</enum>
+          </property>
+          <property name="mode">
+           <enum>ctkPathListWidget::DirectoriesOnly</enum>
+          </property>
+         </widget>
+        </item>
+        <item row="0" column="0">
+         <widget class="QLabel" name="label">
+          <property name="text">
+           <string>The following list of paths will be searched for executables which provide a XML parameter description when called with a &quot;--xml&quot; command line argument:</string>
+          </property>
+          <property name="wordWrap">
+           <bool>true</bool>
+          </property>
+         </widget>
+        </item>
+       </layout>
+      </item>
+     </layout>
+    </widget>
+   </item>
+  </layout>
+ </widget>
+ <customwidgets>
+  <customwidget>
+   <class>ctkPathListButtonsWidget</class>
+   <extends>QWidget</extends>
+   <header>ctkPathListButtonsWidget.h</header>
+  </customwidget>
+  <customwidget>
+   <class>ctkPathListWidget</class>
+   <extends>QListView</extends>
+   <header>ctkPathListWidget.h</header>
+  </customwidget>
+ </customwidgets>
+ <resources/>
+ <connections/>
+</ui>

+ 19 - 2
Applications/ctkCommandLineModuleExplorer/ctkCmdLineModuleExplorerMainWindow.cpp

@@ -23,10 +23,13 @@
 #include "ui_ctkCmdLineModuleExplorerMainWindow.h"
 
 #include "ctkCmdLineModuleExplorerDirectorySettings.h"
+#include "ctkCmdLineModuleExplorerModulesSettings.h"
 #include "ctkCmdLineModuleExplorerTabList.h"
 #include "ctkCmdLineModuleExplorerProgressWidget.h"
+#include "ctkCmdLineModuleExplorerConstants.h"
 
 #include <ctkCmdLineModuleManager.h>
+#include <ctkCmdLineModuleConcurrentHelpers.h>
 #include <ctkCmdLineModuleDescription.h>
 #include <ctkCmdLineModuleFrontendFactoryQtGui.h>
 #include <ctkCmdLineModuleFrontendFactoryQtWebKit.h>
@@ -36,6 +39,7 @@
 
 #include <ctkSettingsDialog.h>
 
+#include <QtConcurrentMap>
 #include <QDesktopServices>
 #include <QMessageBox>
 #include <QFutureSynchronizer>
@@ -52,6 +56,8 @@ ctkCLModuleExplorerMainWindow::ctkCLModuleExplorerMainWindow(QWidget *parent) :
 {
   ui->setupUi(this);
 
+  settings.restoreState(this->objectName(), *this);
+
   // Frontends
   moduleFrontendFactories << new ctkCmdLineModuleFrontendFactoryQtGui;
   moduleFrontendFactories << new ctkCmdLineModuleFrontendFactoryQtWebKit;
@@ -70,7 +76,10 @@ ctkCLModuleExplorerMainWindow::ctkCLModuleExplorerMainWindow(QWidget *parent) :
   }
 
   settingsDialog = new ctkSettingsDialog(this);
-  settingsDialog->addPanel(new ctkCmdLineModuleExplorerDirectorySettings());
+  settings.restoreState(settingsDialog->objectName(), *settingsDialog);
+  settingsDialog->setSettings(&settings);
+  settingsDialog->addPanel(new ctkCmdLineModuleExplorerDirectorySettings(&directoryWatcher));
+  settingsDialog->addPanel(new ctkCmdLineModuleExplorerModulesSettings(&moduleManager));
 
   tabList.reset(new ctkCmdLineModuleExplorerTabList(ui->mainTabWidget));
 
@@ -101,8 +110,13 @@ ctkCLModuleExplorerMainWindow::ctkCLModuleExplorerMainWindow(QWidget *parent) :
     moduleManager.registerModule(fpModule);
   }
 
+  // Register persistent modules
+  QtConcurrent::mapped(settings.value(ctkCmdLineModuleExplorerConstants::KEY_REGISTERED_MODULES).toStringList(),
+                       ctkCmdLineModuleConcurrentRegister(&moduleManager));
+
+  // Start watching directories
   directoryWatcher.setDebug(true);
-  directoryWatcher.setDirectories(QStringList(QCoreApplication::applicationDirPath()));
+  directoryWatcher.setDirectories(settings.value(ctkCmdLineModuleExplorerConstants::KEY_SEARCH_PATHS).toStringList());
 
   moduleTabActivated(NULL);
 
@@ -113,6 +127,9 @@ ctkCLModuleExplorerMainWindow::~ctkCLModuleExplorerMainWindow()
 {
   qDeleteAll(moduleBackends);
   qDeleteAll(moduleFrontendFactories);
+
+  settings.saveState(*this, this->objectName());
+  settings.saveState(*settingsDialog, settingsDialog->objectName());
 }
 
 void ctkCLModuleExplorerMainWindow::addModule(const QUrl &location)

+ 2 - 0
Applications/ctkCommandLineModuleExplorer/ctkCmdLineModuleExplorerMainWindow.h

@@ -25,6 +25,7 @@
 #include <ctkCmdLineModuleManager.h>
 #include <ctkCmdLineModuleDirectoryWatcher.h>
 #include <ctkCmdLineModuleFuture.h>
+#include <ctkSettings.h>
 
 #include <QMainWindow>
 #include <QTimer>
@@ -92,6 +93,7 @@ private:
 
   ctkCmdLineModuleDirectoryWatcher directoryWatcher;
 
+  ctkSettings settings;
   ctkSettingsDialog* settingsDialog;
 
 };

+ 73 - 0
Applications/ctkCommandLineModuleExplorer/ctkCmdLineModuleExplorerModulesSettings.cpp

@@ -0,0 +1,73 @@
+/*=============================================================================
+
+  Library: CTK
+
+  Copyright (c) German Cancer Research Center,
+    Division of Medical and Biological Informatics
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+
+=============================================================================*/
+
+#include "ctkCmdLineModuleExplorerModulesSettings.h"
+#include "ctkCmdLineModuleExplorerConstants.h"
+
+#include "ui_ctkCmdLineModuleExplorerModulesSettings.h"
+
+#include <ctkCmdLineModuleManager.h>
+#include <ctkCmdLineModuleConcurrentHelpers.h>
+
+#include <QUrl>
+#include <QtConcurrentMap>
+
+ctkCmdLineModuleExplorerModulesSettings::ctkCmdLineModuleExplorerModulesSettings(ctkCmdLineModuleManager *moduleManager)
+  : ui(new Ui::ctkCmdLineModuleExplorerModulesSettings)
+  , ModuleManager(moduleManager)
+{
+  ui->setupUi(this);
+
+  ui->PathListButtonsWidget->init(ui->PathListWidget);
+
+  this->registerProperty(ctkCmdLineModuleExplorerConstants::KEY_REGISTERED_MODULES,
+                         ui->PathListWidget, "paths", SIGNAL(pathsChanged(QStringList,QStringList)));
+}
+
+ctkCmdLineModuleExplorerModulesSettings::~ctkCmdLineModuleExplorerModulesSettings()
+{
+  delete ui;
+}
+
+void ctkCmdLineModuleExplorerModulesSettings::applySettings()
+{
+  QStringList oldModules = this->previousPropertyValue(ctkCmdLineModuleExplorerConstants::KEY_REGISTERED_MODULES).toStringList();
+  QStringList newModules = this->propertyValue(ctkCmdLineModuleExplorerConstants::KEY_REGISTERED_MODULES).toStringList();
+
+  QStringList removedModules;
+  QStringList addedModules = newModules;
+  foreach(const QString& oldModule, oldModules)
+  {
+    if (!newModules.contains(oldModule))
+    {
+      removedModules << oldModule;
+    }
+    else
+    {
+      addedModules.removeAll(oldModule);
+    }
+  }
+
+  QtConcurrent::mapped(removedModules, ctkCmdLineModuleConcurrentUnRegister(this->ModuleManager));
+  QtConcurrent::mapped(addedModules, ctkCmdLineModuleConcurrentRegister(this->ModuleManager));
+
+  ctkSettingsPanel::applySettings();
+}

+ 49 - 0
Applications/ctkCommandLineModuleExplorer/ctkCmdLineModuleExplorerModulesSettings.h

@@ -0,0 +1,49 @@
+/*=============================================================================
+
+  Library: CTK
+
+  Copyright (c) German Cancer Research Center,
+    Division of Medical and Biological Informatics
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+
+=============================================================================*/
+
+#ifndef CTKCMDLINEMODULEEXPLORERMODULESSETTINGS_H
+#define CTKCMDLINEMODULEEXPLORERMODULESSETTINGS_H
+
+#include <ctkSettingsPanel.h>
+
+class ctkCmdLineModuleManager;
+
+namespace Ui {
+class ctkCmdLineModuleExplorerModulesSettings;
+}
+
+class ctkCmdLineModuleExplorerModulesSettings : public ctkSettingsPanel
+{
+  Q_OBJECT
+  
+public:
+  explicit ctkCmdLineModuleExplorerModulesSettings(ctkCmdLineModuleManager* moduleManager);
+  ~ctkCmdLineModuleExplorerModulesSettings();
+
+  void applySettings();
+  
+private:
+  Ui::ctkCmdLineModuleExplorerModulesSettings *ui;
+
+  ctkCmdLineModuleManager* ModuleManager;
+};
+
+#endif // CTKCMDLINEMODULEEXPLORERMODULESSETTINGS_H

+ 91 - 0
Applications/ctkCommandLineModuleExplorer/ctkCmdLineModuleExplorerModulesSettings.ui

@@ -0,0 +1,91 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>ctkCmdLineModuleExplorerModulesSettings</class>
+ <widget class="QWidget" name="ctkCmdLineModuleExplorerModulesSettings">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>400</width>
+    <height>300</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Registered Modules</string>
+  </property>
+  <layout class="QHBoxLayout" name="horizontalLayout">
+   <property name="leftMargin">
+    <number>6</number>
+   </property>
+   <property name="topMargin">
+    <number>0</number>
+   </property>
+   <property name="rightMargin">
+    <number>0</number>
+   </property>
+   <property name="bottomMargin">
+    <number>0</number>
+   </property>
+   <item>
+    <widget class="QGroupBox" name="groupBox">
+     <property name="title">
+      <string>Registered Modules</string>
+     </property>
+     <layout class="QHBoxLayout" name="horizontalLayout_2">
+      <item>
+       <widget class="ctkPathListWidget" name="PathListWidget">
+        <property name="mode">
+         <enum>ctkPathListWidget::FilesOnly</enum>
+        </property>
+        <property name="fileOptions">
+         <set>ctkPathListWidget::Executable|ctkPathListWidget::Exists|ctkPathListWidget::Readable</set>
+        </property>
+       </widget>
+      </item>
+      <item>
+       <layout class="QVBoxLayout" name="verticalLayout">
+        <item>
+         <widget class="ctkPathListButtonsWidget" name="PathListButtonsWidget">
+          <property name="buttonsAutoRaise">
+           <bool>true</bool>
+          </property>
+          <property name="orientation">
+           <enum>Qt::Vertical</enum>
+          </property>
+         </widget>
+        </item>
+        <item>
+         <spacer name="verticalSpacer">
+          <property name="orientation">
+           <enum>Qt::Vertical</enum>
+          </property>
+          <property name="sizeHint" stdset="0">
+           <size>
+            <width>20</width>
+            <height>40</height>
+           </size>
+          </property>
+         </spacer>
+        </item>
+       </layout>
+      </item>
+     </layout>
+    </widget>
+   </item>
+  </layout>
+ </widget>
+ <customwidgets>
+  <customwidget>
+   <class>ctkPathListButtonsWidget</class>
+   <extends>QWidget</extends>
+   <header>ctkPathListButtonsWidget.h</header>
+  </customwidget>
+  <customwidget>
+   <class>ctkPathListWidget</class>
+   <extends>QListView</extends>
+   <header>ctkPathListWidget.h</header>
+  </customwidget>
+ </customwidgets>
+ <resources/>
+ <connections/>
+</ui>