瀏覽代碼

ENH: PluginBrowser: added dock widgets for service browsing and a toolbar

Sascha Zelzer 15 年之前
父節點
當前提交
e32f48dc5f

+ 1 - 0
Applications/ctkPluginBrowser/CMakeLists.txt

@@ -26,6 +26,7 @@ SET(KIT_UI_FORMS
 
 # Resources
 SET(KIT_resources
+  ctkPluginBrowserResources.qrc
 )
 
 # Target libraries - See CMake/ctkMacroGetTargetLibraries.cmake

+ 45 - 0
Applications/ctkPluginBrowser/ctkPluginBrowser.cpp

@@ -89,6 +89,18 @@ ctkPluginBrowser::ctkPluginBrowser(ctkPluginFramework* framework)
   connect(ui.pluginsTableView, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(pluginDoubleClicked(QModelIndex)));
   connect(ui.pluginResourcesTreeView, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(dbResourceDoubleClicked(QModelIndex)));
   connect(ui.qtResourcesTreeView, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(qtResourceDoubleClicked(QModelIndex)));
+
+  startPluginAction = new QAction(QIcon(":/pluginbrowser/images/run.png"), "Start Plugin", this);
+  stopPluginAction = new QAction(QIcon(":/pluginbrowser/images/stop.png"), "Stop Plugin", this);
+
+  connect(startPluginAction, SIGNAL(triggered()), this, SLOT(startPlugin()));
+  connect(stopPluginAction, SIGNAL(triggered()), this, SLOT(stopPlugin()));
+
+  startPluginAction->setEnabled(false);
+  stopPluginAction->setEnabled(false);
+
+  ui.pluginToolBar->addAction(startPluginAction);
+  ui.pluginToolBar->addAction(stopPluginAction);
 }
 
 void ctkPluginBrowser::pluginSelected(const QModelIndex &index)
@@ -97,8 +109,23 @@ void ctkPluginBrowser::pluginSelected(const QModelIndex &index)
 
   ctkPlugin* plugin = framework->getPluginContext()->getPlugin(v.toLongLong());
 
+  startPluginAction->setEnabled(false);
+  stopPluginAction->setEnabled(false);
+
   if (!plugin) return;
 
+  const ctkPlugin::States startStates = ctkPlugin::INSTALLED | ctkPlugin::RESOLVED | ctkPlugin::STOPPING;
+  const ctkPlugin::States stopStates = ctkPlugin::STARTING | ctkPlugin::ACTIVE;
+  if (startStates.testFlag(plugin->getState()))
+  {
+    startPluginAction->setEnabled(true);
+  }
+
+  if (stopStates.testFlag(plugin->getState()))
+  {
+    stopPluginAction->setEnabled(true);
+  }
+
   QAbstractItemModel* oldModel = ui.pluginResourcesTreeView->model();
   ui.pluginResourcesTreeView->setModel(new ctkPluginResourcesTreeModel(plugin, this));
   if (oldModel) oldModel->deleteLater();;
@@ -162,3 +189,21 @@ void ctkPluginBrowser::frameworkEvent(const ctkPluginFrameworkEvent& event)
 {
   qDebug() << "FrameworkEvent: [" << event.getPlugin()->getSymbolicName() << "]" << event.getErrorString();
 }
+
+void ctkPluginBrowser::startPlugin()
+{
+  QModelIndex selection = ui.pluginsTableView->selectionModel()->currentIndex();
+  QVariant v = selection.data(Qt::UserRole);
+
+  ctkPlugin* plugin = framework->getPluginContext()->getPlugin(v.toLongLong());
+  plugin->start();
+}
+
+void ctkPluginBrowser::stopPlugin()
+{
+  QModelIndex selection = ui.pluginsTableView->selectionModel()->currentIndex();
+  QVariant v = selection.data(Qt::UserRole);
+
+  ctkPlugin* plugin = framework->getPluginContext()->getPlugin(v.toLongLong());
+  plugin->stop();
+}

+ 6 - 0
Applications/ctkPluginBrowser/ctkPluginBrowser.h

@@ -50,12 +50,18 @@ private slots:
 
   void frameworkEvent(const ctkPluginFrameworkEvent& event);
 
+  void startPlugin();
+  void stopPlugin();
+
 private:
 
   ctkPluginFramework* framework;
 
   Ui::ctkPluginBrowserWindow ui;
   ctkPluginBrowserEditors* editors;
+
+  QAction* startPluginAction;
+  QAction* stopPluginAction;
 };
 
 #endif // CTKPLUGINBROWSER_H

+ 119 - 1
Applications/ctkPluginBrowser/ctkPluginBrowserMainWindow.ui

@@ -152,6 +152,122 @@
     </layout>
    </widget>
   </widget>
+  <widget class="QDockWidget" name="dockWidget_4">
+   <property name="windowTitle">
+    <string>Services</string>
+   </property>
+   <attribute name="dockWidgetArea">
+    <number>2</number>
+   </attribute>
+   <widget class="QWidget" name="dockWidgetContents_4">
+    <layout class="QVBoxLayout" name="verticalLayout_5">
+     <property name="spacing">
+      <number>0</number>
+     </property>
+     <property name="margin">
+      <number>0</number>
+     </property>
+     <item>
+      <widget class="QWidget" name="widget" native="true">
+       <layout class="QVBoxLayout" name="verticalLayout_7">
+        <property name="spacing">
+         <number>0</number>
+        </property>
+        <property name="margin">
+         <number>0</number>
+        </property>
+        <item>
+         <widget class="QWidget" name="widget_2" native="true">
+          <layout class="QHBoxLayout" name="horizontalLayout">
+           <property name="spacing">
+            <number>2</number>
+           </property>
+           <property name="margin">
+            <number>0</number>
+           </property>
+           <item>
+            <widget class="QToolButton" name="linkServicesToolButton">
+             <property name="maximumSize">
+              <size>
+               <width>24</width>
+               <height>24</height>
+              </size>
+             </property>
+             <property name="text">
+              <string>...</string>
+             </property>
+             <property name="icon">
+              <iconset resource="ctkPluginBrowserResources.qrc">
+               <normaloff>:/pluginbrowser/images/linkicon.png</normaloff>:/pluginbrowser/images/linkicon.png</iconset>
+             </property>
+             <property name="checkable">
+              <bool>true</bool>
+             </property>
+            </widget>
+           </item>
+           <item>
+            <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>
+        <item>
+         <widget class="QSplitter" name="splitter">
+          <property name="orientation">
+           <enum>Qt::Vertical</enum>
+          </property>
+          <widget class="QTableView" name="servicesTableView"/>
+          <widget class="QTableView" name="servicePropsTableView"/>
+         </widget>
+        </item>
+       </layout>
+      </widget>
+     </item>
+    </layout>
+   </widget>
+  </widget>
+  <widget class="QDockWidget" name="dockWidget_5">
+   <property name="windowTitle">
+    <string>Events</string>
+   </property>
+   <attribute name="dockWidgetArea">
+    <number>8</number>
+   </attribute>
+   <widget class="QWidget" name="dockWidgetContents_5">
+    <layout class="QVBoxLayout" name="verticalLayout_6">
+     <property name="spacing">
+      <number>0</number>
+     </property>
+     <property name="margin">
+      <number>0</number>
+     </property>
+     <item>
+      <widget class="QTableView" name="eventsTableView"/>
+     </item>
+    </layout>
+   </widget>
+  </widget>
+  <widget class="QToolBar" name="pluginToolBar">
+   <property name="windowTitle">
+    <string>toolBar</string>
+   </property>
+   <attribute name="toolBarArea">
+    <enum>TopToolBarArea</enum>
+   </attribute>
+   <attribute name="toolBarBreak">
+    <bool>false</bool>
+   </attribute>
+  </widget>
   <action name="actionExit">
    <property name="text">
     <string>Exit</string>
@@ -161,6 +277,8 @@
    </property>
   </action>
  </widget>
- <resources/>
+ <resources>
+  <include location="ctkPluginBrowserResources.qrc"/>
+ </resources>
  <connections/>
 </ui>

+ 7 - 0
Applications/ctkPluginBrowser/ctkPluginBrowserResources.qrc

@@ -0,0 +1,7 @@
+<RCC>
+    <qresource prefix="/pluginbrowser">
+        <file>images/linkicon.png</file>
+        <file>images/run.png</file>
+        <file>images/stop.png</file>
+    </qresource>
+</RCC>

二進制
Applications/ctkPluginBrowser/images/linkicon.png


二進制
Applications/ctkPluginBrowser/images/run.png


二進制
Applications/ctkPluginBrowser/images/stop.png