From 6288a56e29c6753b755b0d23c9baeccc4ec3ab75 Mon Sep 17 00:00:00 2001
From: Janik Zikovsky <zikovskyjl@ornl.gov>
Date: Wed, 7 Mar 2012 14:34:34 -0500
Subject: [PATCH] Refs #4941: macro to create a QtDesigner plugin very quickly

---
 .../PluginCollectionInterface.h               | 87 ++++++++++---------
 .../DesignerPlugins/src/DesignerPlugin.cpp    | 13 +--
 2 files changed, 52 insertions(+), 48 deletions(-)

diff --git a/Code/Mantid/MantidQt/DesignerPlugins/inc/MantidQtDesignerPlugins/PluginCollectionInterface.h b/Code/Mantid/MantidQt/DesignerPlugins/inc/MantidQtDesignerPlugins/PluginCollectionInterface.h
index fdc557adda8..0a49fda74cf 100644
--- a/Code/Mantid/MantidQt/DesignerPlugins/inc/MantidQtDesignerPlugins/PluginCollectionInterface.h
+++ b/Code/Mantid/MantidQt/DesignerPlugins/inc/MantidQtDesignerPlugins/PluginCollectionInterface.h
@@ -6,6 +6,10 @@
 #include "MantidQtMantidWidgets/AlgorithmSelectorWidget.h"
 #include "MantidQtDesignerPlugins/DesignerPlugin.h"
 #include "MantidQtMantidWidgets/ScriptEditor.h"
+#include "MantidQtMantidWidgets/MWRunFiles.h"
+#include "MantidQtMantidWidgets/FitPropertyBrowser.h"
+#include "MantidQtMantidWidgets/MuonFitPropertyBrowser.h"
+#include "MantidQtMantidWidgets/InstrumentSelector.h"
 
 /** 
 The PluginCollectionInterface implements the interface for the plugin library and holds a 
@@ -51,48 +55,53 @@ private:
 
 
 //==============================================================================
-/** Plugin for QtDesigner for the AlgorithmSelectorWidget */
-class AlgorithmSelectorWidgetPlugin : public DesignerPlugin
-{
-public:
-  AlgorithmSelectorWidgetPlugin(QObject * parent)
-  : DesignerPlugin(parent)
-  {}
-
-  /// Returns a pointer to a newly constructed widget for this plugin wraps
-  QWidget *createWidget(QWidget *parent)
-  {
-    return new MantidQt::MantidWidgets::AlgorithmSelectorWidget(parent);
-  }
-
-  /// Returns the fully-qualified class name
-  virtual QString name() const
-  {
-    return "MantidQt::MantidWidgets::AlgorithmSelectorWidget";
-  }
+/** Macro to REALLY quickly declare a plugin for
+ * a widget in MantidWidgets
+ *
+ * @param PluginClass :: name to give your plugin
+ * @param WidgetClass :: fully-qualified name of the widget class
+ * @param ToolTip :: a string with the tooltip
+ */
+#define DECLARE_WIDGET_PLUGIN(PluginClass, WidgetClass, ToolTip) \
+class PluginClass : public DesignerPlugin { \
+public: \
+  PluginClass(QObject * parent) : DesignerPlugin(parent) {} \
+  QWidget *createWidget(QWidget *parent) \
+  { return new WidgetClass(parent); } \
+  QString name() const \
+  { return #WidgetClass; } \
+  QString toolTip() const \
+  { return ToolTip; } \
 };
 
 
 //==============================================================================
-/** Plugin for QtDesigner for the ScriptEditor */
-class ScriptEditorPlugin : public DesignerPlugin
-{
-public:
-  ScriptEditorPlugin(QObject * parent)
-  : DesignerPlugin(parent)
-  {}
-
-  /// Returns a pointer to a newly constructed widget for this plugin wraps
-  QWidget *createWidget(QWidget *parent)
-  {
-    return new ScriptEditor(parent);
-  }
-
-  /// Returns the fully-qualified class name
-  virtual QString name() const
-  {
-    return "ScriptEditor";
-  }
-};
+DECLARE_WIDGET_PLUGIN(AlgorithmSelectorWidgetPlugin,
+    MantidQt::MantidWidgets::AlgorithmSelectorWidget,
+    "Widget for picking algorithms");
+
+DECLARE_WIDGET_PLUGIN(ScriptEditorPlugin,
+    ScriptEditor,
+    "Widget for editing python script");
+
+DECLARE_WIDGET_PLUGIN(FileFinderPlugin,
+    MantidQt::MantidWidgets::MWRunFiles,
+    "Searches for the given files within the paths defined by\nMantid's datasearch.directories property");
+
+DECLARE_WIDGET_PLUGIN(InstrumentSelectorPlugin,
+    MantidQt::MantidWidgets::InstrumentSelector,
+    "Sets the current instrument within Mantid");
+
+DECLARE_WIDGET_PLUGIN(MuonFitBrowserPlugin,
+    MantidQt::MantidWidgets::MuonFitPropertyBrowser,
+    "The menu for fitting functions within Muon Analysis");
+
+DECLARE_WIDGET_PLUGIN(FitBrowserPlugin,
+    MantidQt::MantidWidgets::FitPropertyBrowser,
+    "The menu for fitting functions");
+
+DECLARE_WIDGET_PLUGIN(WorkspaceSelectorPlugin,
+    MantidQt::MantidWidgets::WorkspaceSelector,
+    "Select a workspace for use in this operation");
 
 #endif
diff --git a/Code/Mantid/MantidQt/DesignerPlugins/src/DesignerPlugin.cpp b/Code/Mantid/MantidQt/DesignerPlugins/src/DesignerPlugin.cpp
index f59012a56e2..1136d8477c3 100644
--- a/Code/Mantid/MantidQt/DesignerPlugins/src/DesignerPlugin.cpp
+++ b/Code/Mantid/MantidQt/DesignerPlugins/src/DesignerPlugin.cpp
@@ -108,19 +108,14 @@ QString DesignerPlugin::includeFile() const
  */
 QString DesignerPlugin::domXml() const
 {
+  std::string name = this->getShortName();
+  name[0] = static_cast<char>(tolower(static_cast<int>(name[0])));
+
   return QString::fromStdString(
       "<widget class=\""
       + this->name().toStdString()
       + "\" name=\""
-      + this->getShortName() +
+      + name +
       "\">\n"
-    " <property name=\"geometry\">\n"
-    "  <rect>\n"
-    "   <x>0</x>\n"
-    "   <y>0</y>\n"
-    "   <width>300</width>\n"
-    "   <height>200</height>\n"
-    "  </rect>\n"
-    " </property>\n"
     "</widget>\n");
 }
-- 
GitLab