OpenMS
WizardHelper.h
Go to the documentation of this file.
1 // --------------------------------------------------------------------------
2 // OpenMS -- Open-Source Mass Spectrometry
3 // --------------------------------------------------------------------------
4 // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
5 // ETH Zurich, and Freie Universitaet Berlin 2002-2023.
6 //
7 // This software is released under a three-clause BSD license:
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of any author or any participating institution
14 // may be used to endorse or promote products derived from this software
15 // without specific prior written permission.
16 // For a full list of authors, refer to the file AUTHORS.
17 // --------------------------------------------------------------------------
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
22 // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // --------------------------------------------------------------------------
31 // $Maintainer: Jihyung Kim $
32 // $Authors: Jihyung Kim, Chris Bielow $
33 // --------------------------------------------------------------------------
34 
35 #pragma once
36 
37 namespace OpenMS
38 {
39  class InputFile;
40  class OutputDirectory;
41  class ParamEditor;
42 
43  namespace Internal
44  {
48  template<class TWidgetClass>
50  {
51  public:
52  WizardGUILock(TWidgetClass* stw):
53  stw_(stw),
54  old_(stw->currentWidget()),
55  glock_(stw)
56  {
57  stw->setCurrentWidget(stw->ui->tab_log);
58  }
59 
61  {
62  stw_->setCurrentWidget(old_);
63  }
64 
65  private:
66  TWidgetClass* stw_;
69  };
70 
72  struct Args
73  {
74  QStringList loop_arg;
75  size_t insert_pos;
76  };
77 
78  typedef std::vector<Args> ArgLoop;
79 
85  struct Command
86  {
88  QStringList args;
90 
91  Command(const String& e, const QStringList& a, const ArgLoop& l) :
92  exe(e),
93  args(a),
94  loop(l) {}
95 
98  size_t getLoopCount() const
99  {
100  if (loop.empty()) return 1;
101  size_t common_size = loop[0].loop_arg.size();
102  for (const auto& l : loop)
103  {
104  if (l.loop_arg.size() != (int)common_size) throw Exception::Precondition(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, "Internal error. Not all loop arguments support the same number of loops!");
105  if ((int)l.insert_pos >= args.size()) throw Exception::Precondition(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, "Internal error. Loop argument wants to insert after end of template arguments!");
106  }
107  return common_size;
108  }
111  QStringList getArgs(const int loop_number) const
112  {
113  if (loop_number >= (int)getLoopCount())
114  {
115  throw Exception::Precondition(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, "Internal error. The loop number you requested is too high!");
116  }
117  if (loop.empty()) return args; // no looping available
118 
119  QStringList arg_l = args;
120  for (const auto& largs : loop) // replace all args for the current round
121  {
122  arg_l[largs.insert_pos] = args[largs.insert_pos].arg(largs.loop_arg[loop_number]);
123  }
124  return arg_l;
125  }
126  };
127 
128  }
129 } // ns OpenMS
130 
131 // this is required to allow Ui_[tool_name]TabWidget (auto UIC'd from .ui) to have a InputFile member
OpenMS::TableView TableView
Definition: WizardHelper.h:135
OpenMS::InputFile InputFile
Definition: WizardHelper.h:132
OpenMS::OutputDirectory OutputDirectory
Definition: WizardHelper.h:133
OpenMS::ParamEditor ParamEditor
Definition: WizardHelper.h:134
Precondition failed exception.
Definition: Exception.h:159
RAII class to disable the GUI and set a busy cursor and go back to the original state when this class...
Definition: GUIHelpers.h:149
A simple widget with a line-edit and a browse button to choose filenames.
Definition: gui/include/OpenMS/VISUAL/InputFile.h:57
RAII class to switch to certain TabWidget, disable the GUI and go back to the orignal Tab when this c...
Definition: WizardHelper.h:50
~WizardGUILock()
Definition: WizardHelper.h:60
WizardGUILock(TWidgetClass *stw)
Definition: WizardHelper.h:52
TWidgetClass * stw_
Definition: WizardHelper.h:66
GUIHelpers::GUILock glock_
Definition: WizardHelper.h:68
QWidget * old_
Definition: WizardHelper.h:67
A simple widget with a line-edit and a browse button to choose filenames.
Definition: OutputDirectory.h:57
A GUI for editing or viewing a Param object.
Definition: ParamEditor.h:180
A more convenient string class.
Definition: String.h:60
A better QTable for TOPPView, which supports exporting to TSV and conveniently adding data to cells a...
Definition: TableView.h:48
QStringList loop_arg
list of arguments to insert; one for every loop
Definition: WizardHelper.h:74
std::vector< Args > ArgLoop
Definition: WizardHelper.h:78
size_t insert_pos
where to insert in the target argument list (index is 0-based)
Definition: WizardHelper.h:75
custom arguments to allow for looping calls
Definition: WizardHelper.h:73
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:48
Definition: WizardHelper.h:86
QStringList getArgs(const int loop_number) const
Definition: WizardHelper.h:111
String exe
Definition: WizardHelper.h:87
size_t getLoopCount() const
Definition: WizardHelper.h:98
QStringList args
Definition: WizardHelper.h:88
ArgLoop loop
Definition: WizardHelper.h:89
Command(const String &e, const QStringList &a, const ArgLoop &l)
Definition: WizardHelper.h:91