Skip to content
Snippets Groups Projects
Commit 6288a56e authored by Janik Zikovsky's avatar Janik Zikovsky
Browse files

Refs #4941: macro to create a QtDesigner plugin very quickly

parent 61a84137
No related branches found
No related tags found
No related merge requests found
...@@ -6,6 +6,10 @@ ...@@ -6,6 +6,10 @@
#include "MantidQtMantidWidgets/AlgorithmSelectorWidget.h" #include "MantidQtMantidWidgets/AlgorithmSelectorWidget.h"
#include "MantidQtDesignerPlugins/DesignerPlugin.h" #include "MantidQtDesignerPlugins/DesignerPlugin.h"
#include "MantidQtMantidWidgets/ScriptEditor.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 The PluginCollectionInterface implements the interface for the plugin library and holds a
...@@ -51,48 +55,53 @@ private: ...@@ -51,48 +55,53 @@ private:
//============================================================================== //==============================================================================
/** Plugin for QtDesigner for the AlgorithmSelectorWidget */ /** Macro to REALLY quickly declare a plugin for
class AlgorithmSelectorWidgetPlugin : public DesignerPlugin * a widget in MantidWidgets
{ *
public: * @param PluginClass :: name to give your plugin
AlgorithmSelectorWidgetPlugin(QObject * parent) * @param WidgetClass :: fully-qualified name of the widget class
: DesignerPlugin(parent) * @param ToolTip :: a string with the tooltip
{} */
#define DECLARE_WIDGET_PLUGIN(PluginClass, WidgetClass, ToolTip) \
/// Returns a pointer to a newly constructed widget for this plugin wraps class PluginClass : public DesignerPlugin { \
QWidget *createWidget(QWidget *parent) public: \
{ PluginClass(QObject * parent) : DesignerPlugin(parent) {} \
return new MantidQt::MantidWidgets::AlgorithmSelectorWidget(parent); QWidget *createWidget(QWidget *parent) \
} { return new WidgetClass(parent); } \
QString name() const \
/// Returns the fully-qualified class name { return #WidgetClass; } \
virtual QString name() const QString toolTip() const \
{ { return ToolTip; } \
return "MantidQt::MantidWidgets::AlgorithmSelectorWidget";
}
}; };
//============================================================================== //==============================================================================
/** Plugin for QtDesigner for the ScriptEditor */ DECLARE_WIDGET_PLUGIN(AlgorithmSelectorWidgetPlugin,
class ScriptEditorPlugin : public DesignerPlugin MantidQt::MantidWidgets::AlgorithmSelectorWidget,
{ "Widget for picking algorithms");
public:
ScriptEditorPlugin(QObject * parent) DECLARE_WIDGET_PLUGIN(ScriptEditorPlugin,
: DesignerPlugin(parent) ScriptEditor,
{} "Widget for editing python script");
/// Returns a pointer to a newly constructed widget for this plugin wraps DECLARE_WIDGET_PLUGIN(FileFinderPlugin,
QWidget *createWidget(QWidget *parent) MantidQt::MantidWidgets::MWRunFiles,
{ "Searches for the given files within the paths defined by\nMantid's datasearch.directories property");
return new ScriptEditor(parent);
} DECLARE_WIDGET_PLUGIN(InstrumentSelectorPlugin,
MantidQt::MantidWidgets::InstrumentSelector,
/// Returns the fully-qualified class name "Sets the current instrument within Mantid");
virtual QString name() const
{ DECLARE_WIDGET_PLUGIN(MuonFitBrowserPlugin,
return "ScriptEditor"; 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 #endif
...@@ -108,19 +108,14 @@ QString DesignerPlugin::includeFile() const ...@@ -108,19 +108,14 @@ QString DesignerPlugin::includeFile() const
*/ */
QString DesignerPlugin::domXml() const QString DesignerPlugin::domXml() const
{ {
std::string name = this->getShortName();
name[0] = static_cast<char>(tolower(static_cast<int>(name[0])));
return QString::fromStdString( return QString::fromStdString(
"<widget class=\"" "<widget class=\""
+ this->name().toStdString() + this->name().toStdString()
+ "\" name=\"" + "\" name=\""
+ this->getShortName() + + name +
"\">\n" "\">\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"); "</widget>\n");
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment