GSI Object Oriented Online Offline (Go4)  GO4-6.1.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TGo4UserCommands.cpp
Go to the documentation of this file.
1 // $Id: TGo4UserCommands.cpp 3129 2021-03-30 09:46:41Z linev $
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, SIGNAL (pressed()), this, SLOT (ExecuteAnalysisMacro_1()));
29  QObject::connect (CommandButton2, SIGNAL (pressed()), this, SLOT (ExecuteAnalysisMacro_2()));
30  QObject::connect (CommandButton3, SIGNAL (pressed()), this, SLOT (ExecuteAnalysisMacro_3()));
31  QObject::connect (CommandButton4, SIGNAL (pressed()), this, SLOT (ExecuteAnalysisMacro_4()));
32  QObject::connect (CommandButton5, SIGNAL (pressed()), this, SLOT (ExecuteAnalysisMacro_5()));
33  QObject::connect (CommandButton6, SIGNAL (pressed()), this, SLOT (ExecuteAnalysisMacro_6()));
34  QObject::connect (CommandButton7, SIGNAL (pressed()), this, SLOT (ExecuteAnalysisMacro_7()));
35  QObject::connect (CommandButton8, SIGNAL (pressed()), this, SLOT (ExecuteAnalysisMacro_8()));
36  QObject::connect (CommandButton9, SIGNAL (pressed()), this, SLOT (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  {
59  fAnalysisMacroCommands.push_back(QString(""));
60  continue;
61  }
62  fAnalysisMacroButtons[i]->setEnabled(true);
64  fAnalysisMacroCommands.push_back(com);
66  }
67 
68 
69  QObject::connect(CommandAutoButton, SIGNAL (clicked ()), this, SLOT (AnalysisMacroMonitorBtn_clicked ()));
70 
71  fAnalysisMacroTimer = new QTimer(this);
72  QObject::connect(fAnalysisMacroTimer, SIGNAL (timeout ()), this, SLOT (AnalysisMacroMonitorTimeout()));
73 
74  QObject::connect(ConfigureButton, SIGNAL (clicked ()), this, SLOT (ConfigureAnalysisMacros()));
75 #ifdef USERCOMMANDS_CONFIGWINDOW
76  ConfigureButton->setCheckable(false);
77 #endif
78 
80 }
81 
83 {
84  // try to redefine shortcuts here after this widget was adopted by mainwindow toolbar
85  // seems that Qt5 overrides initial definitions:
86  for (int i = 0; i < GO4GUI_MAXMACRONUM; ++i)
87  {
88  int butid = i + 1;
89  fAnalysisMacroButtons[i]->setShortcut(QString("Ctrl+%1").arg(butid));
90 // std::cout << "set button shortcut "<<i<<" to "<<fAnalysisMacroButtons[i]->shortcut().toString().toLatin1 ().constData ()<< std::endl;
91  //fAnalysisMacroButtons[i]->setShortcut(QKeySequence(Qt::CTRL, Qt::Key_0 + butid));
92  }
93 
94 }
95 
97 {
98  //std::cout << "AnalysisMacroMonitorBtn_clicked " <<std::endl;
99 
100  if(fAnalysisMacroTimer->isActive())
101  {
102  fAnalysisMacroTimer->stop();
103  CommandAutoButton->setIcon(QIcon( ":/icons/startselected.png" ));
104  CommandAutoButton->setToolTip("Start Command Execution Timer");
105  AutoTimeSpinBox->setEnabled(true);
106  }
107  else
108  {
109  double t=1000.0*AutoTimeSpinBox->value();
110  fAnalysisMacroTimer->start(t);
111  CommandAutoButton->setIcon(QIcon( ":/icons/Stop.png" ));
112  CommandAutoButton->setToolTip("Stop Command Execution Timer");
113  AutoTimeSpinBox->setEnabled(false);
114 
115  }
116 }
117 
118 
120 {
121  //std::cout << "AnalysisMacroMonitorTimeout" <<std::endl;
122  if(ConfigureButton->isChecked())
123  {
124  AnalysisMacroMonitorBtn_clicked(); // stop timer in editor mode
125  return;
126  }
127  for(int i=0; i<fAnalysisMacroAutoExecute.size(); ++i)
128  {
131  }
132 
133 }
134 
135 
137 {
138  //std::cout << "ConfigureAnalysisMacros " <<std::endl;
139 
140 TGo4UserCommandsDialog setup(this);
141 if ( setup.exec() != QDialog::Accepted ) return;
142 
143 //AssignShortcuts(); // test if we can manipulate them afterwards.
144 
145 for(int id=0; id<GO4GUI_MAXMACRONUM;++id)
146 {
147  // get from requester and store in go4 settings:
148  QString com=setup.GetCommand(id);
150  QString tip=setup.GetTooltip(id);
151  tip.append(": ");
152  tip.append(fAnalysisMacroButtons[id]->shortcut().toString());
153  go4sett->setAnalysisMacroTip(id, tip);
154  //std::cout<<"ConfigureAnalysisMacros - index"<<id<<" set command "<<com.toLatin1 ().constData ()<<", tip:"<<tip.toLatin1 ().constData ()<< std::endl;
155 
156  bool execute=setup.GetAutoExecute(id);
157  go4sett->setAnalysisMacroAutomode(id, execute);
158 
159  // put new setup to gui:
160  fAnalysisMacroCommands[id]=com;
161  fAnalysisMacroButtons[id]->setToolTip(tip);
162 
163  SetAutoExecute(id,execute);
164 
165 
166  // now activate only such elements that are defined:
167  fAnalysisMacroButtons[id]->setEnabled(true);
168  //fAnalysisMacroMonitorCheck[id]->setEnabled(true);
169  if(com.isEmpty()){
170  fAnalysisMacroButtons[id]->setEnabled(false);
171  //fAnalysisMacroMonitorCheck[id]->setEnabled(false);
172  }
173 
174 
175 }
176 
177 
178 
179 
180 }
181 
183 {
184  ExecuteAnalysisMacro(0); // note the shift of index here. want to start with ctrl-1 as first macro...
185 }
186 
188 {
189  ExecuteAnalysisMacro(1); // note the shift of index here. want to start with ctrl-1 as first macro...
190 }
191 
193 {
194  ExecuteAnalysisMacro(2); // note the shift of index here. want to start with ctrl-1 as first macro...
195 }
196 
198 {
199  ExecuteAnalysisMacro(3); // note the shift of index here. want to start with ctrl-1 as first macro...
200 }
201 
202 
204 {
205  ExecuteAnalysisMacro(4); // note the shift of index here. want to start with ctrl-1 as first macro...
206 }
207 
209 {
210  ExecuteAnalysisMacro(5); // note the shift of index here. want to start with ctrl-1 as first macro...
211 }
212 
214 {
215  ExecuteAnalysisMacro(6); // note the shift of index here. want to start with ctrl-1 as first macro...
216 }
217 
219 {
220  ExecuteAnalysisMacro(7); // note the shift of index here. want to start with ctrl-1 as first macro...
221 }
222 
224 {
225  ExecuteAnalysisMacro(8); // note the shift of index here. want to start with ctrl-1 as first macro...
226 }
227 
228 
229 
231 {
232  //std::cout << "ExecuteAnalysisMacro "<< id <<std::endl;
233  QString cmd=fAnalysisMacroCommands[id];
234  if (cmd.length()==0) return;
235  //std::cout << "Invoke custom analysis command: "<< cmd.toLatin1().constData() <<std::endl;
236  StatusMessage(QString("Invoke custom analysis command: ").append(cmd));
237  TGo4ServerProxy* serv = Browser()->FindServer();
238  if (serv!=0)
239  {
240  // TODO: have to check priviliges here?
241  serv->ExecuteLine(cmd.toLatin1().constData());
242  }
243 }
244 
245 
246 
247 
248 void TGo4UserCommands::SetAutoExecute(int id, bool on)
249 {
251  QString iconname;
252  if(on)
253  {
254  iconname=QString(":/icons/Number-%1-icon-green.png").arg(id+1);
255  }
256  else
257  {
258  iconname=QString(":/icons/Number-%1-icon.png").arg(id+1);
259  }
260  fAnalysisMacroButtons[id]->setIcon(QIcon(iconname));
261 }
262 
263 
264 
265 
void setAnalysisMacroTip(int id, const QString &com)
void SetAutoExecute(int id, bool on)
void AnalysisMacroMonitorBtn_clicked()
TGo4UserCommands(QWidget *parent=0, const char *name=0, Qt::WindowFlags fl=Qt::Widget)
TGo4ServerProxy * FindServer(const char *itemname=0, Bool_t asanalysis=kTRUE)
TGo4BrowserProxy * Browser()
Definition: QGo4Widget.cpp:224
std::vector< bool > fAnalysisMacroAutoExecute
void ExecuteAnalysisMacro(int id)
void AnalysisMacroMonitorTimeout()
#define GO4GUI_MAXMACRONUM
void StatusMessage(const QString &message)
Definition: QGo4Widget.cpp:245
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)