Browse Source

Add settings for maximum parallel running modules.

Sascha Zelzer 12 years ago
parent
commit
cb4913ea13

+ 4 - 0
Applications/ctkCommandLineModuleExplorer/CMakeLists.txt

@@ -8,6 +8,7 @@ set(KIT_SRCS
   ctkCommandLineModuleExplorerMain.cpp
   ctkCmdLineModuleExplorerConstants.cpp
   ctkCmdLineModuleExplorerDirectorySettings.cpp
+  ctkCmdLineModuleExplorerGeneralModuleSettings.cpp
   ctkCmdLineModuleExplorerMainWindow.h
   ctkCmdLineModuleExplorerMainWindow.cpp
   ctkCmdLineModuleExplorerModulesSettings.cpp
@@ -22,6 +23,8 @@ set(KIT_SRCS
 
 # Headers that should run through moc
 set(KIT_MOC_SRCS
+  ctkCmdLineModuleExplorerDirectorySettings.h
+  ctkCmdLineModuleExplorerGeneralModuleSettings.h
   ctkCmdLineModuleExplorerMainWindow.h
   ctkCmdLineModuleExplorerModulesSettings.h
   ctkCmdLineModuleExplorerOutputText.h
@@ -35,6 +38,7 @@ set(KIT_MOC_SRCS
 # UI files
 set(KIT_UI_FORMS
   ctkCmdLineModuleExplorerDirectorySettings.ui
+  ctkCmdLineModuleExplorerGeneralModuleSettings.ui
   ctkCmdLineModuleExplorerMainWindow.ui
   ctkCmdLineModuleExplorerModulesSettings.ui
   ctkCmdLineModuleExplorerProgressWidget.ui

+ 2 - 0
Applications/ctkCommandLineModuleExplorer/ctkCmdLineModuleExplorerConstants.cpp

@@ -23,3 +23,5 @@
 
 const QString ctkCmdLineModuleExplorerConstants::KEY_SEARCH_PATHS = "ModuleSearchPaths";
 const QString ctkCmdLineModuleExplorerConstants::KEY_REGISTERED_MODULES = "RegisteredModules";
+
+const QString ctkCmdLineModuleExplorerConstants::KEY_MAX_PARALLEL_MODULES = "MaxParallelModules";

+ 2 - 0
Applications/ctkCommandLineModuleExplorer/ctkCmdLineModuleExplorerConstants.h

@@ -28,6 +28,8 @@ struct ctkCmdLineModuleExplorerConstants
 {
   static const QString KEY_SEARCH_PATHS;
   static const QString KEY_REGISTERED_MODULES;
+
+  static const QString KEY_MAX_PARALLEL_MODULES;
 };
 
 #endif // CTKCMDLINEMODULEEXPLORERCONSTANTS_H

+ 2 - 0
Applications/ctkCommandLineModuleExplorer/ctkCmdLineModuleExplorerDirectorySettings.h

@@ -34,6 +34,8 @@ class ctkCmdLineModuleDirectoryWatcher;
  */
 class ctkCmdLineModuleExplorerDirectorySettings : public ctkSettingsPanel, public Ui::ctkCmdLineModuleExplorerDirectorySettings
 {
+  Q_OBJECT
+
 public:
   ctkCmdLineModuleExplorerDirectorySettings(ctkCmdLineModuleDirectoryWatcher* directoryWatcher);
 

+ 40 - 0
Applications/ctkCommandLineModuleExplorer/ctkCmdLineModuleExplorerGeneralModuleSettings.cpp

@@ -0,0 +1,40 @@
+/*=============================================================================
+
+  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 "ctkCmdLineModuleExplorerGeneralModuleSettings.h"
+#include "ctkCmdLineModuleExplorerConstants.h"
+
+#include <QThreadPool>
+#include <QSettings>
+
+ctkCmdLineModuleExplorerGeneralModuleSettings::ctkCmdLineModuleExplorerGeneralModuleSettings()
+{
+  this->setupUi(this);
+
+  this->registerProperty(ctkCmdLineModuleExplorerConstants::KEY_MAX_PARALLEL_MODULES,
+                         this->MaxParallelModules, "value", SIGNAL(valueChanged(int)));
+}
+
+void ctkCmdLineModuleExplorerGeneralModuleSettings::applySettings()
+{
+  int maxParallelModules = this->propertyValue(ctkCmdLineModuleExplorerConstants::KEY_MAX_PARALLEL_MODULES).toInt();
+  QThreadPool::globalInstance()->setMaxThreadCount(maxParallelModules);
+}

+ 42 - 0
Applications/ctkCommandLineModuleExplorer/ctkCmdLineModuleExplorerGeneralModuleSettings.h

@@ -0,0 +1,42 @@
+/*=============================================================================
+
+  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 CTKCMDLINEMODULEEXPLORERGENERALMODULESETTINGS_H
+#define CTKCMDLINEMODULEEXPLORERGENERALMODULESETTINGS_H
+
+#include <ctkSettingsPanel.h>
+
+#include "ui_ctkCmdLineModuleExplorerGeneralModuleSettings.h"
+
+class ctkCmdLineModuleExplorerGeneralModuleSettings : public ctkSettingsPanel,
+    public Ui::ctkCmdLineModuleExplorerGeneralModuleSettings
+{
+  Q_OBJECT
+
+public:
+
+  ctkCmdLineModuleExplorerGeneralModuleSettings();
+
+  void applySettings();
+
+};
+
+#endif // CTKCMDLINEMODULEEXPLORERGENERALMODULESETTINGS_H

+ 97 - 0
Applications/ctkCommandLineModuleExplorer/ctkCmdLineModuleExplorerGeneralModuleSettings.ui

@@ -0,0 +1,97 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>ctkCmdLineModuleExplorerGeneralModuleSettings</class>
+ <widget class="QWidget" name="ctkCmdLineModuleExplorerGeneralModuleSettings">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>400</width>
+    <height>300</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Module Settings            </string>
+  </property>
+  <layout class="QVBoxLayout" name="verticalLayout">
+   <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>Run Settings</string>
+     </property>
+     <layout class="QGridLayout" name="gridLayout">
+      <item row="1" column="0">
+       <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>
+      <item row="0" column="1">
+       <widget class="QSpinBox" name="MaxParallelModules">
+        <property name="sizePolicy">
+         <sizepolicy hsizetype="Minimum" vsizetype="Fixed">
+          <horstretch>0</horstretch>
+          <verstretch>0</verstretch>
+         </sizepolicy>
+        </property>
+        <property name="maximumSize">
+         <size>
+          <width>60</width>
+          <height>16777215</height>
+         </size>
+        </property>
+        <property name="minimum">
+         <number>1</number>
+        </property>
+        <property name="maximum">
+         <number>999</number>
+        </property>
+       </widget>
+      </item>
+      <item row="0" column="0">
+       <widget class="QLabel" name="label">
+        <property name="text">
+         <string>Maximum parallel running modules:</string>
+        </property>
+       </widget>
+      </item>
+      <item row="0" column="2">
+       <spacer name="horizontalSpacer">
+        <property name="orientation">
+         <enum>Qt::Horizontal</enum>
+        </property>
+        <property name="sizeHint" stdset="0">
+         <size>
+          <width>40</width>
+          <height>20</height>
+         </size>
+        </property>
+       </spacer>
+      </item>
+     </layout>
+    </widget>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>

+ 12 - 2
Applications/ctkCommandLineModuleExplorer/ctkCmdLineModuleExplorerMainWindow.cpp

@@ -22,6 +22,7 @@
 #include "ctkCmdLineModuleExplorerMainWindow.h"
 #include "ui_ctkCmdLineModuleExplorerMainWindow.h"
 
+#include "ctkCmdLineModuleExplorerGeneralModuleSettings.h"
 #include "ctkCmdLineModuleExplorerDirectorySettings.h"
 #include "ctkCmdLineModuleExplorerModulesSettings.h"
 #include "ctkCmdLineModuleExplorerTabList.h"
@@ -61,6 +62,13 @@ ctkCLModuleExplorerMainWindow::ctkCLModuleExplorerMainWindow(QWidget *parent) :
 
   settings.restoreState(this->objectName(), *this);
 
+  if (!settings.contains(ctkCmdLineModuleExplorerConstants::KEY_MAX_PARALLEL_MODULES))
+  {
+    settings.setValue(ctkCmdLineModuleExplorerConstants::KEY_MAX_PARALLEL_MODULES, QThread::idealThreadCount());
+  }
+  QThreadPool::globalInstance()->setMaxThreadCount(settings.value(ctkCmdLineModuleExplorerConstants::KEY_MAX_PARALLEL_MODULES,
+                                                                  QThread::idealThreadCount()).toInt());
+
   // Frontends
   moduleFrontendFactories << new ctkCmdLineModuleFrontendFactoryQtGui;
   moduleFrontendFactories << new ctkCmdLineModuleFrontendFactoryQtWebKit;
@@ -227,8 +235,10 @@ void ctkCLModuleExplorerMainWindow::on_actionOptions_triggered()
     settingsDialog = new ctkSettingsDialog(this);
     settings.restoreState(settingsDialog->objectName(), *settingsDialog);
     settingsDialog->setSettings(&settings);
-    settingsDialog->addPanel(new ctkCmdLineModuleExplorerDirectorySettings(&directoryWatcher));
-    settingsDialog->addPanel(new ctkCmdLineModuleExplorerModulesSettings(&moduleManager));
+    ctkSettingsPanel* generalModulePanel = new ctkCmdLineModuleExplorerGeneralModuleSettings();
+    settingsDialog->addPanel(generalModulePanel);
+    settingsDialog->addPanel(new ctkCmdLineModuleExplorerDirectorySettings(&directoryWatcher), generalModulePanel);
+    settingsDialog->addPanel(new ctkCmdLineModuleExplorerModulesSettings(&moduleManager), generalModulePanel);
   }
 
   settingsDialog->exec();