OpenMS
Loading...
Searching...
No Matches
WizardHelper.h
Go to the documentation of this file.
1// Copyright (c) 2002-present, OpenMS Inc. -- EKU Tuebingen, ETH Zurich, and FU Berlin
2// SPDX-License-Identifier: BSD-3-Clause
3//
4// --------------------------------------------------------------------------
5// $Maintainer: Jihyung Kim $
6// $Authors: Jihyung Kim, Chris Bielow $
7// --------------------------------------------------------------------------
8
9#pragma once
10
12
13#include <vector>
14
15namespace OpenMS
16{
17 class InputFile;
18 class OutputDirectory;
19 class ParamEditor;
20
21 namespace Internal
22 {
26 template<class TWidgetClass>
28 {
29 public:
30 WizardGUILock(TWidgetClass* stw):
31 stw_(stw),
32 old_(stw->currentWidget()),
33 glock_(stw)
34 {
35 stw->setCurrentWidget(stw->ui->tab_log);
36 }
37
39 {
40 stw_->setCurrentWidget(old_);
41 }
42
43 private:
44 TWidgetClass* stw_;
47 };
48
50 struct Args
51 {
52 std::vector<String> loop_arg;
53 size_t insert_pos;
54 };
55
56 typedef std::vector<Args> ArgLoop;
57
63 struct Command
64 {
66 std::vector<String> args;
68
69 Command(const String& e, const std::vector<String>& a, const ArgLoop& l) :
70 exe(e),
71 args(a),
72 loop(l) {}
73
76 size_t getLoopCount() const
77 {
78 if (loop.empty()) return 1;
79 size_t common_size = loop[0].loop_arg.size();
80 for (const auto& l : loop)
81 {
82 if (l.loop_arg.size() != common_size) throw Exception::Precondition(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, "Internal error. Not all loop arguments support the same number of loops!");
83 if (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!");
84 }
85 return common_size;
86 }
89 std::vector<String> getArgs(const int loop_number) const
90 {
91 if (loop_number >= (int)getLoopCount())
92 {
93 throw Exception::Precondition(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, "Internal error. The loop number you requested is too high!");
94 }
95 if (loop.empty()) return args; // no looping available
96
97 std::vector<String> arg_l = args;
98 for (const auto& largs : loop) // replace all args for the current round
99 {
100 // Substitute %1 placeholder with the loop argument
101 String& target = arg_l[largs.insert_pos];
102 target.substitute("%1", largs.loop_arg[loop_number]);
103 }
104 return arg_l;
105 }
106 };
107
108 }
109} // ns OpenMS
110
111// this is required to allow Ui_[tool_name]TabWidget (auto UIC'd from .ui) to have a InputFile member
Precondition failed exception.
Definition Exception.h:128
RAII class to disable the GUI and set a busy cursor and go back to the original state when this class...
Definition GUIHelpers.h:124
A simple widget with a line-edit and a browse button to choose filenames.
Definition gui/include/OpenMS/VISUAL/InputFile.h:31
RAII class to switch to certain TabWidget, disable the GUI and go back to the orignal Tab when this c...
Definition WizardHelper.h:28
~WizardGUILock()
Definition WizardHelper.h:38
WizardGUILock(TWidgetClass *stw)
Definition WizardHelper.h:30
TWidgetClass * stw_
Definition WizardHelper.h:44
GUIHelpers::GUILock glock_
Definition WizardHelper.h:46
QWidget * old_
Definition WizardHelper.h:45
A simple widget with a line-edit and a browse button to choose filenames.
Definition OutputDirectory.h:31
A GUI for editing or viewing a Param object.
Definition ParamEditor.h:153
A more convenient string class.
Definition String.h:32
String & substitute(char from, char to)
Replaces all occurrences of the character from by the character to.
A better QTable for TOPPView, which supports exporting to TSV and conveniently adding data to cells a...
Definition TableView.h:22
std::vector< Args > ArgLoop
Definition WizardHelper.h:56
size_t insert_pos
where to insert in the target argument list (index is 0-based)
Definition WizardHelper.h:53
std::vector< String > loop_arg
list of arguments to insert; one for every loop
Definition WizardHelper.h:52
custom arguments to allow for looping calls
Definition WizardHelper.h:51
Main OpenMS namespace.
Definition openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19
Definition WizardHelper.h:64
String exe
Definition WizardHelper.h:65
size_t getLoopCount() const
Definition WizardHelper.h:76
std::vector< String > getArgs(const int loop_number) const
Definition WizardHelper.h:89
std::vector< String > args
Definition WizardHelper.h:66
Command(const String &e, const std::vector< String > &a, const ArgLoop &l)
Definition WizardHelper.h:69
ArgLoop loop
Definition WizardHelper.h:67