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