GSI Object Oriented Online Offline (Go4)  GO4-6.3.0
TGo4UserCommands.cpp
Go to the documentation of this file.
1 // $Id$
2 //-----------------------------------------------------------------------
3 // The GSI Online Offline Object Oriented (Go4) Project
4 // Experiment Data Processing at EE department, GSI
5 //-----------------------------------------------------------------------
6 // Copyright (C) 2000- GSI Helmholtzzentrum fuer Schwerionenforschung GmbH
7 // Planckstr. 1, 64291 Darmstadt, Germany
8 // Contact: http://go4.gsi.de
9 //-----------------------------------------------------------------------
10 // This software can be used under the license agreements as stated
11 // in Go4License.txt file which is part of the distribution.
12 //-----------------------------------------------------------------------
13 
14 #include "TGo4UserCommands.h"
15 
16 #include "TGo4QSettings.h"
17 #include "TGo4BrowserProxy.h"
18 #include "TGo4ServerProxy.h"
19 
20 #include "TGo4UserCommandsDialog.h"
21 
22 TGo4UserCommands::TGo4UserCommands( QWidget *parent, const char *name, Qt::WindowFlags fl ) :
23  QGo4Widget( parent, name, fl)
24 {
25  setObjectName( name ? name : "Go4UserCommands");
26  setupUi(this);
27 
28  QObject::connect(CommandButton1, &QToolButton::pressed, this, &TGo4UserCommands::ExecuteAnalysisMacro_1);
29  QObject::connect(CommandButton2, &QToolButton::pressed, this, &TGo4UserCommands::ExecuteAnalysisMacro_2);
30  QObject::connect(CommandButton3, &QToolButton::pressed, this, &TGo4UserCommands::ExecuteAnalysisMacro_3);
31  QObject::connect(CommandButton4, &QToolButton::pressed, this, &TGo4UserCommands::ExecuteAnalysisMacro_4);
32  QObject::connect(CommandButton5, &QToolButton::pressed, this, &TGo4UserCommands::ExecuteAnalysisMacro_5);
33  QObject::connect(CommandButton6, &QToolButton::pressed, this, &TGo4UserCommands::ExecuteAnalysisMacro_6);
34  QObject::connect(CommandButton7, &QToolButton::pressed, this, &TGo4UserCommands::ExecuteAnalysisMacro_7);
35  QObject::connect(CommandButton8, &QToolButton::pressed, this, &TGo4UserCommands::ExecuteAnalysisMacro_8);
36  QObject::connect(CommandButton9, &QToolButton::pressed, this, &TGo4UserCommands::ExecuteAnalysisMacro_9);
37 
38  // here assign widget arrays:
39  fAnalysisMacroButtons.clear();
40  fAnalysisMacroButtons.push_back(CommandButton1);
41  fAnalysisMacroButtons.push_back(CommandButton2);
42  fAnalysisMacroButtons.push_back(CommandButton3);
43  fAnalysisMacroButtons.push_back(CommandButton4);
44  fAnalysisMacroButtons.push_back(CommandButton5);
45  fAnalysisMacroButtons.push_back(CommandButton6);
46  fAnalysisMacroButtons.push_back(CommandButton7);
47  fAnalysisMacroButtons.push_back(CommandButton8);
48  fAnalysisMacroButtons.push_back(CommandButton9);
49 
50 
51  for (int i = 0; i < GO4GUI_MAXMACRONUM; ++i)
52  {
53  fAnalysisMacroAutoExecute.push_back(false);
54  fAnalysisMacroButtons[i]->setEnabled(false);
55 
56  QString com = go4sett->getAnalysisMacroCommand(i);
57  if (com.isEmpty()) {
58  fAnalysisMacroCommands.push_back(QString(""));
59  continue;
60  }
61  fAnalysisMacroButtons[i]->setEnabled(true);
63  fAnalysisMacroCommands.push_back(com);
65  }
66 
67 
68  QObject::connect(CommandAutoButton, &QToolButton::clicked, this, &TGo4UserCommands::AnalysisMacroMonitorBtn_clicked);
69 
70  fAnalysisMacroTimer = new QTimer(this);
71  QObject::connect(fAnalysisMacroTimer, &QTimer::timeout, this, &TGo4UserCommands::AnalysisMacroMonitorTimeout);
72 
73  QObject::connect(ConfigureButton, &QToolButton::clicked, this, &TGo4UserCommands::ConfigureAnalysisMacros);
74 #ifdef USERCOMMANDS_CONFIGWINDOW
75  ConfigureButton->setCheckable(false);
76 #endif
77 
79 }
80 
82 {
83  // try to redefine shortcuts here after this widget was adopted by mainwindow toolbar
84  // seems that Qt5 overrides initial definitions:
85  for (int i = 0; i < GO4GUI_MAXMACRONUM; ++i)
86  fAnalysisMacroButtons[i]->setShortcut(QString("Ctrl+%1").arg(i+1));
87 }
88 
90 {
91  if (fAnalysisMacroTimer->isActive()) {
92  fAnalysisMacroTimer->stop();
93  CommandAutoButton->setIcon(QIcon(":/icons/startselected.png"));
94  CommandAutoButton->setToolTip("Start Command Execution Timer");
95  AutoTimeSpinBox->setEnabled(true);
96  } else {
97  double t = 1000.0 * AutoTimeSpinBox->value();
98  fAnalysisMacroTimer->start(t);
99  CommandAutoButton->setIcon(QIcon(":/icons/Stop.png"));
100  CommandAutoButton->setToolTip("Stop Command Execution Timer");
101  AutoTimeSpinBox->setEnabled(false);
102  }
103 }
104 
106 {
107  if (ConfigureButton->isChecked()) {
108  AnalysisMacroMonitorBtn_clicked(); // stop timer in editor mode
109  return;
110  }
111  for (unsigned i = 0; i < fAnalysisMacroAutoExecute.size(); ++i) {
114  }
115 }
116 
117 
119 {
120  TGo4UserCommandsDialog setup(this);
121  if (setup.exec() != QDialog::Accepted)
122  return;
123 
124  // AssignShortcuts(); // test if we can manipulate them afterwards.
125 
126  for (int id = 0; id < GO4GUI_MAXMACRONUM; ++id) {
127  // get from requester and store in go4 settings:
128  QString com = setup.GetCommand(id);
130  QString tip = setup.GetTooltip(id);
131  tip.append(": ");
132  tip.append(fAnalysisMacroButtons[id]->shortcut().toString());
133  go4sett->setAnalysisMacroTip(id, tip);
134  // tip:"<<tip.toLatin1 ().constData ()<< std::endl;
135 
136  bool execute = setup.GetAutoExecute(id);
137  go4sett->setAnalysisMacroAutomode(id, execute);
138 
139  // put new setup to gui:
140  fAnalysisMacroCommands[id] = com;
141  fAnalysisMacroButtons[id]->setToolTip(tip);
142 
143  SetAutoExecute(id, execute);
144 
145  // now activate only such elements that are defined:
146  fAnalysisMacroButtons[id]->setEnabled(true);
147  // fAnalysisMacroMonitorCheck[id]->setEnabled(true);
148  if (com.isEmpty()) {
149  fAnalysisMacroButtons[id]->setEnabled(false);
150  // fAnalysisMacroMonitorCheck[id]->setEnabled(false);
151  }
152  }
153 }
154 
156 {
157  ExecuteAnalysisMacro(0); // note the shift of index here. want to start with ctrl-1 as first macro...
158 }
159 
161 {
162  ExecuteAnalysisMacro(1); // note the shift of index here. want to start with ctrl-1 as first macro...
163 }
164 
166 {
167  ExecuteAnalysisMacro(2); // note the shift of index here. want to start with ctrl-1 as first macro...
168 }
169 
171 {
172  ExecuteAnalysisMacro(3); // note the shift of index here. want to start with ctrl-1 as first macro...
173 }
174 
176 {
177  ExecuteAnalysisMacro(4); // note the shift of index here. want to start with ctrl-1 as first macro...
178 }
179 
181 {
182  ExecuteAnalysisMacro(5); // note the shift of index here. want to start with ctrl-1 as first macro...
183 }
184 
186 {
187  ExecuteAnalysisMacro(6); // note the shift of index here. want to start with ctrl-1 as first macro...
188 }
189 
191 {
192  ExecuteAnalysisMacro(7); // note the shift of index here. want to start with ctrl-1 as first macro...
193 }
194 
196 {
197  ExecuteAnalysisMacro(8); // note the shift of index here. want to start with ctrl-1 as first macro...
198 }
199 
201 {
202  QString cmd = fAnalysisMacroCommands[id];
203  if (cmd.isEmpty())
204  return;
205  StatusMessage(QString("Invoke custom analysis command: ").append(cmd));
206  TGo4ServerProxy *serv = Browser()->FindServer();
207  if (serv) {
208  // TODO: have to check priviliges here?
209  serv->ExecuteLine(cmd.toLatin1().constData());
210  }
211 }
212 
213 void TGo4UserCommands::SetAutoExecute(int id, bool on)
214 {
215  fAnalysisMacroAutoExecute[id] = on;
216  QString iconname;
217  if (on)
218  iconname = QString(":/icons/Number-%1-icon-green.png").arg(id + 1);
219  else
220  iconname = QString(":/icons/Number-%1-icon.png").arg(id + 1);
221  fAnalysisMacroButtons[id]->setIcon(QIcon(iconname));
222 }
TGo4UserCommands(QWidget *parent=nullptr, const char *name=nullptr, Qt::WindowFlags fl=Qt::Widget)
void setAnalysisMacroTip(int id, const QString &com)
void SetAutoExecute(int id, bool on)
void AnalysisMacroMonitorBtn_clicked()
TGo4BrowserProxy * Browser()
Definition: QGo4Widget.cpp:219
std::vector< bool > fAnalysisMacroAutoExecute
void ExecuteAnalysisMacro(int id)
void AnalysisMacroMonitorTimeout()
#define GO4GUI_MAXMACRONUM
void StatusMessage(const QString &message)
Definition: QGo4Widget.cpp:239
virtual void ExecuteLine(const char *line)
bool getAnalysisMacroAutomode(int id)
QString getAnalysisMacroCommand(int id)
TGo4QSettings * go4sett
void setAnalysisMacroCommand(int id, const QString &com)
void setAnalysisMacroAutomode(int id, bool on)
std::vector< QString > fAnalysisMacroCommands
std::vector< QToolButton * > fAnalysisMacroButtons
QTimer * fAnalysisMacroTimer
QString getAnalysisMacroTip(int id)
TGo4ServerProxy * FindServer(const char *itemname=nullptr, Bool_t asanalysis=kTRUE)