ATLAS Offline Software
IVP12DStandardChannelWidget.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 // //
7 // Implementation of class IVP12DStandardChannelWidget //
8 // //
9 // Author: Thomas Kittelmann <Thomas.Kittelmann@cern.ch> //
10 // //
11 // Initial version: April 2007 //
12 // //
14 
16 #include "VP1Base/IVP12DSystem.h"
21 #include "VP1Base/VP1TabWidget.h"
24 #include "VP1Base/VP1Msg.h"
25 
26 #include <QVBoxLayout>
27 #include <QGraphicsScene>
28 #include <QCheckBox>
29 #include <QMap>
30 #include <QBuffer>
31 #include <QByteArray>
32 
33 
34 #include <cassert>
35 
36 
38 public:
41  bool first;
42  QMap<IVP12DSystem*,QSet<VP1GraphicsItemCollection*> > system2itemcols;
43 
44  QMap<QCheckBox*,IVP1System*> checkbox2system;
45  QList<IVP1System*> systemsAllowedControllers;
46  QList<QPair<IVP1System*,bool> > system2switchable;
47  QMap<IVP1System*,bool> system2startdisabled;
48 
49  void updateSystemState(QCheckBox*);
50 
51  QMap<IVP1System*,QWidget*> sys2tabpage;
53 
55 
56 };
57 
58 //___________________________________________________________________________
59 IVP12DStandardChannelWidget::IVP12DStandardChannelWidget(const QString & name, const QString & information, const QString & contact_info)
60  : IVP1ChannelWidget(name,information,contact_info), m_d(new Imp())
61 {
62  m_d->channel=this;
63  m_d->first=true;
64  setMinimumSize(150,240);//minimum y size is to avoid absurd squeezing of buttons.
65 
66  QVBoxLayout * vboxLayout = new QVBoxLayout(this);
67  vboxLayout->setSpacing(0);
68  vboxLayout->setMargin(0);
69  VP12DExaminerViewer * examiner = new VP12DExaminerViewer(this);
70  vboxLayout->addWidget(examiner);
72 
73  m_d->view = examiner->view();
74 
75  m_d->tabwidget = 0;
76 }
77 
78 //___________________________________________________________________________
80 {
81  delete m_d;
82 }
83 
84 //___________________________________________________________________________
85 void IVP12DStandardChannelWidget::addSystem( IVP12DSystem*system, const SystemOptions& options ) {
86 
87  bool handleSelections = ! (options & DisallowSelections);
88  bool switchable = ! (options & DisallowSwitchable);
89  bool allowController = ! (options & DisallowController);
90  bool allowMovable = ! (options & DisallowMovable);
91  bool startDisabled = (options & StartDisabled);
92 
93  registerSystem(system);
94 
95  assert(!m_d->system2itemcols.contains(system));
96  m_d->system2itemcols.insert(system,system->getItemCollections());
99  }
100 
102  m_d->view->setDisallowInteractions(ic, !handleSelections );
103  }
105  m_d->view->setDisallowMovable(ic, !allowMovable );
106  }
107 
108  m_d->system2switchable << QPair<IVP1System*,bool>(system,switchable);
109 
110  assert(!m_d->system2startdisabled.contains(system));
111  m_d->system2startdisabled.insert(system,startDisabled);
112  assert(m_d->system2startdisabled.contains(system));
113 
114  if (allowController) {
115  m_d->systemsAllowedControllers << system;
116  connect(system,SIGNAL(itemFromSystemSelected()),this,SLOT(showControlsForSystem()));
117  }
118 }
119 
120 //___________________________________________________________________________
122  //Fixme: Less code should be replicated here and in IVP13DStandardChannelWidget+IVP12DDetViewsChannelWidget
123 
124  //Set up the controller.
130  connect(m_d->colorselectbutton,SIGNAL(colorChanged(const QColor&)),this,SLOT(setBackgroundColor(const QColor&)));
131  m_d->system2switchable.clear();
132 
133  QMapIterator<QCheckBox*,IVP1System*> it(m_d->checkbox2system);
134  while (it.hasNext()) {
135  it.next();
136 
137  assert(m_d->system2startdisabled.contains(it.value()));
138  if (m_d->system2startdisabled[it.value()]) {
139  it.key()->setChecked(false);
140  m_d->updateSystemState(it.key());
141  }
142 
143  connect(it.key(),SIGNAL(toggled(bool)),this,SLOT(toggleSystemActive()));
144  }
145 }
146 
147 
148 //___________________________________________________________________________
150  if (m_d->first) {
152  m_d->first=false;
153  }
154 }
155 
156 //___________________________________________________________________________
159 }
160 
161 //___________________________________________________________________________
163 {
164  QCheckBox * cb = static_cast<QCheckBox*>(sender()); assert(cb);
165  m_d->updateSystemState(cb);
166 }
167 
168 //___________________________________________________________________________
170 {
171  assert(checkbox2system.contains(cb));
172  IVP12DSystem*sys = static_cast<IVP12DSystem*>(checkbox2system.value(cb)); assert(sys);
173 
174  assert(system2itemcols.contains(sys));
175  if (cb->isChecked()) {
176  channel->turnOn(sys);
178  ic->reattachToView();
179  }
180  if (tabwidget&&sys2tabpage.contains(sys)) {
181  int sysindex = systemsAllowedControllers.indexOf(sys);
182  if (sysindex>=0) {
183  IVP1System*nextsystem(0);
184  for (int i=sysindex+1;i<systemsAllowedControllers.count();++i) {
185  //Loop through latter systems with controllers in order and
186  //find the first of those which currently has an active
187  //controller:
188  IVP1System* testsys = systemsAllowedControllers.at(i);
189  if (sys2tabpage.contains(testsys)&&tabwidget->indexOf(sys2tabpage[testsys])>-1) {
190  nextsystem=testsys;
191  break;
192  }
193  }
194  //put before tab of "nextsystem" (or at the end if no nextsystem):
195  int index = (nextsystem?tabwidget->indexOf(sys2tabpage[nextsystem]):99999);
196  tabwidget->insertTab(index,sys2tabpage[sys],sys->name());
197  int index2 = tabwidget->indexOf(sys2tabpage[sys]);
198  if (index2!=-1) {
199  tabwidget->setTabEnabled(index2,true);
200  }
201  }
202  }
203  } else {
204  //Fixme: if system being turned off has selections, we should deselect!!
205  channel->turnOff(sys,false);
207  ic->detachFromView();
208  }
209  if (tabwidget&&sys2tabpage.contains(sys)) {
210  int index = tabwidget->indexOf(sys2tabpage[sys]);
211  if (index!=-1) {
212  tabwidget->setTabEnabled(index,false);
214  }
215  }
216  }
217 
218  view->scene()->update();
219 
220 }
221 
222 //___________________________________________________________________________
224 {
226 }
227 
228 //___________________________________________________________________________
230 {
231  if (!col.isValid())
232  return;
233  m_d->view->setBackgroundBrush(col);
234 }
235 
236 //___________________________________________________________________________
238 {
239  if (!m_d->tabwidget)
240  return;
241  IVP1System * sys = static_cast<IVP1System*>(sender());
242  if (!sys) {
243  message("showControlsForSystem Error: Unable to determine system identity.");
244  return;
245  }
246  if (!m_d->sys2tabpage.contains(sys)) {
247  //Dont send warning here. The system in question might simply not have a controller!
248  return;
249  }
250 
251  int index = m_d->tabwidget->indexOf(m_d->sys2tabpage[sys]);
252  if (index<0||!m_d->tabwidget->isTabEnabled(index)) {
253  message("Warning: Asked to show controller for a disabled system. Surely you jest?");
254  return;
255  }
256 
257  m_d->tabwidget->setCurrentIndex(index);
258 }
259 
260 
261 //___________________________________________________________________________
263 {
264  VP1Msg::messageVerbose("IVP12DStandardChannelWidget::saveState");
265  // ===> Setup stream writing to a byteArray:
266  QByteArray byteArray;
267  QBuffer buffer(&byteArray);
268  buffer.open(QIODevice::WriteOnly);
269  QDataStream out(&buffer);
270 
271  // ===> Write Data:
272 
273  //Version & base state:
274  out << (qint32)0; //version
275  out << IVP1ChannelWidget::saveState();//Always include state info from the base class.
276 
277  //Background color:
279 
280  //Systems turned on/off:
281  //Fixme: Make sure that if you have two copies of the same system,
282  //that the text in the checkbox gets appended some stuff like [1],
283  //[2], etc., so that the strings used here will be unique.
284  QMap<QString, bool> sysname2turnedon;
285  QMap<QCheckBox*,IVP1System*>::const_iterator it = m_d->checkbox2system.constBegin();
286  while (it != m_d->checkbox2system.constEnd()) {
287  sysname2turnedon.insert(it.key()->text(),it.key()->isChecked());
288  ++it;
289  }
290 
291  out << sysname2turnedon;
292 
293  //Current system tab:
294  if (m_d->tabwidget)
295  out << m_d->tabwidget->tabText(m_d->tabwidget->currentIndex());
296  else
297  out << QString("");
298 
299  // ===> Finish up:
300  buffer.close();
301  return byteArray;
302 }
303 
304 //___________________________________________________________________________
306 {
307  VP1Msg::messageVerbose("IVP12DStandardChannelWidget::restoreFromState");
308 
309  // ===> Setup stream for getting the contents of the byteArray:
310  QBuffer buffer(&ba);
311  buffer.open(QIODevice::ReadOnly);
312  QDataStream state(&buffer);
313  // ===> Check version and pass on state info to base class:
314  qint32 version;
315  state >> version;
316  if (version!=0) {
317  message("Warning: State data in .vp1 file is in wrong format - ignoring!");
318  return;
319  }
320  QByteArray basestate;
321  state >> basestate;
323  // ===> Decode the state info:
324 
325  QColor bgdcol;
326  state >> bgdcol;
327  if (bgdcol!=m_d->colorselectbutton->color())
328  m_d->colorselectbutton->setColor(bgdcol);
329  setBackgroundColor(bgdcol);
330 
331  //Switch systems on/off:
332  QMap<QString, bool> sysname2turnedon;
333  state >> sysname2turnedon;
334  QMap<QCheckBox*,IVP1System*>::const_iterator it = m_d->checkbox2system.constBegin();
335  while (it != m_d->checkbox2system.constEnd()) {
336  if (sysname2turnedon.contains(it.key()->text())) {
337  if (sysname2turnedon[it.key()->text()]!=it.key()->isChecked())
338  it.key()->setChecked(sysname2turnedon[it.key()->text()]);
339  } else {
340  message("Warning: Config data does not contain information about switched state of subsystem '"+it.key()->text()+"'");
341  }
342  ++it;
343  }
344 
345  //Current system tab
346  QString tabname;
347  state >> tabname;
348  if (m_d->tabwidget) {
349  for (int i = 0; i < m_d->tabwidget->count(); ++i) {
350  if (m_d->tabwidget->tabText(i) == tabname) {
351  m_d->tabwidget->setCurrentIndex(i);
352  break;
353  }
354  }
355  }
356 
357  // ===> Finish up:
358  buffer.close();
359 }
IVP1ChannelWidget::registerSystem
void registerSystem(IVP1System *)
Definition: IVP1ChannelWidget.cxx:221
VP1GraphicsView::clearSelections
void clearSelections()
Definition: VP1GraphicsView.cxx:673
IVP12DStandardChannelWidget::saveState
virtual QByteArray saveState()
Definition: IVP12DStandardChannelWidget.cxx:262
VP1TabWidget::tabText
QString tabText(int) const
Definition: VP1TabWidget.cxx:291
IVP12DStandardChannelWidget::DisallowController
@ DisallowController
Definition: IVP12DStandardChannelWidget.h:35
IVP12DSystem.h
IVP12DStandardChannelWidget::m_d
Imp * m_d
Definition: IVP12DStandardChannelWidget.h:63
IVP12DStandardChannelWidget.h
IVP12DStandardChannelWidget::Imp::first
bool first
Definition: IVP12DStandardChannelWidget.cxx:41
IVP12DStandardChannelWidget::DisallowSelections
@ DisallowSelections
Definition: IVP12DStandardChannelWidget.h:33
index
Definition: index.py:1
VP1Msg.h
IVP12DStandardChannelWidget::IVP12DStandardChannelWidget
IVP12DStandardChannelWidget(const QString &name, const QString &information, const QString &contact_info)
Definition: IVP12DStandardChannelWidget.cxx:59
IVP12DStandardChannelWidget::Imp::colorselectbutton
VP1ColorSelectButton * colorselectbutton
Definition: IVP12DStandardChannelWidget.cxx:54
VP1ColorSelectButton::setColor
void setColor(const QColor &)
Definition: VP1ColorSelectButton.cxx:95
IVP12DStandardChannelWidget::Imp::updateSystemState
void updateSystemState(QCheckBox *)
Definition: IVP12DStandardChannelWidget.cxx:169
fillPileUpNoiseLumi.connect
string connect
Definition: fillPileUpNoiseLumi.py:70
IVP12DStandardChannelWidget::Imp::channel
IVP12DStandardChannelWidget * channel
Definition: IVP12DStandardChannelWidget.cxx:39
CSV_InDetExporter.new
new
Definition: CSV_InDetExporter.py:145
VP12DExaminerViewer.h
skel.it
it
Definition: skel.GENtoEVGEN.py:396
IVP1ChannelWidget::registerController
void registerController(QWidget *)
Definition: IVP1ChannelWidget.cxx:210
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
IVP12DStandardChannelWidget::Imp::tabwidget
VP1TabWidget * tabwidget
Definition: IVP12DStandardChannelWidget.cxx:52
VP12DExaminerViewer::view
VP1GraphicsView * view() const
Definition: VP12DExaminerViewer.cxx:195
VP1GraphicsItemCollection.h
IVP12DStandardChannelWidget::Imp::system2startdisabled
QMap< IVP1System *, bool > system2startdisabled
Definition: IVP12DStandardChannelWidget.cxx:47
IVP12DSystemSimple.h
IVP1ChannelWidget::turnOff
void turnOff(IVP1System *, const bool &immediateErase=true)
Definition: IVP1ChannelWidget.cxx:246
VP1ColorSelectButton
Definition: VP1ColorSelectButton.h:20
mapkey::sys
@ sys
Definition: TElectronEfficiencyCorrectionTool.cxx:42
IVP12DStandardChannelWidget::Imp::sys2tabpage
QMap< IVP1System *, QWidget * > sys2tabpage
Definition: IVP12DStandardChannelWidget.cxx:51
IVP12DSystem
Definition: IVP12DSystem.h:25
VP1TabWidget
Definition: VP1TabWidget.h:45
IVP12DStandardChannelWidget::toggleSystemActive
void toggleSystemActive()
Definition: IVP12DStandardChannelWidget.cxx:162
IVP1System
Definition: IVP1System.h:36
createCoolChannelIdFile.buffer
buffer
Definition: createCoolChannelIdFile.py:12
IVP12DStandardChannelWidget::Imp::view
VP1GraphicsView * view
Definition: IVP12DStandardChannelWidget.cxx:40
IVP12DStandardChannelWidget::Imp::system2itemcols
QMap< IVP12DSystem *, QSet< VP1GraphicsItemCollection * > > system2itemcols
Definition: IVP12DStandardChannelWidget.cxx:42
IVP12DStandardChannelWidget::Imp::system2switchable
QList< QPair< IVP1System *, bool > > system2switchable
Definition: IVP12DStandardChannelWidget.cxx:46
lumiFormat.i
int i
Definition: lumiFormat.py:85
VP1GraphicsView::addItemCollection
void addItemCollection(VP1GraphicsItemCollection *)
Definition: VP1GraphicsView.cxx:380
VP1GraphicsView::fitViewToContents
void fitViewToContents()
Definition: VP1GraphicsView.cxx:220
IVP12DStandardChannelWidget::Imp::systemsAllowedControllers
QList< IVP1System * > systemsAllowedControllers
Definition: IVP12DStandardChannelWidget.cxx:45
IVP12DStandardChannelWidget::addSystem
void addSystem(IVP12DSystem *, const SystemOptions &options=AllowAll)
Definition: IVP12DStandardChannelWidget.cxx:85
VP1GraphicsView::setDisallowMovable
void setDisallowMovable(VP1GraphicsItemCollection *, const bool &disallow=true)
Definition: VP1GraphicsView.cxx:918
VP1TabWidget::removeTab
virtual void removeTab(int index)
Definition: VP1TabWidget.cxx:473
IVP1ChannelWidget::message
void message(QString)
VP1ColorSelectButton::color
QColor color() const
Definition: VP1ColorSelectButton.cxx:108
python.AtlRunQueryLib.options
options
Definition: AtlRunQueryLib.py:379
IVP12DStandardChannelWidget::setBackgroundColor
void setBackgroundColor(const QColor &)
Definition: IVP12DStandardChannelWidget.cxx:229
VP1GraphicsView::setDisallowInteractions
void setDisallowInteractions(VP1GraphicsItemCollection *, const bool &disallow=true)
Definition: VP1GraphicsView.cxx:901
VP1ColorSelectButton.h
IVP12DStandardChannelWidget::StartDisabled
@ StartDisabled
Definition: IVP12DStandardChannelWidget.h:37
IVP12DStandardChannelWidget::DisallowSwitchable
@ DisallowSwitchable
Definition: IVP12DStandardChannelWidget.h:34
grepfile.ic
int ic
Definition: grepfile.py:33
IVP12DStandardChannelWidget::showControlsForSystem
void showControlsForSystem()
Definition: IVP12DStandardChannelWidget.cxx:237
IVP1ChannelWidget
Definition: IVP1ChannelWidget.h:34
IVP1ChannelWidget::state
State state() const
Definition: IVP1ChannelWidget.cxx:102
IVP1ChannelWidget::restoreFromState
virtual void restoreFromState(QByteArray)
Definition: IVP1ChannelWidget.cxx:326
IVP1ChannelWidget::saveState
virtual QByteArray saveState()
Definition: IVP1ChannelWidget.cxx:320
IVP12DStandardChannelWidget::systemRefreshed
void systemRefreshed(IVP1System *)
Definition: IVP12DStandardChannelWidget.cxx:149
Trk::index2
@ index2
Definition: BoundarySurfaceFace.h:49
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
IVP12DStandardChannelWidget::~IVP12DStandardChannelWidget
virtual ~IVP12DStandardChannelWidget()
Definition: IVP12DStandardChannelWidget.cxx:79
IVP12DSystem::getItemCollections
const QSet< VP1GraphicsItemCollection * > & getItemCollections()
Definition: IVP12DSystem.cxx:55
VP1Msg::messageVerbose
static void messageVerbose(const QString &)
Definition: VP1Msg.cxx:84
VP1TabWidget.h
IVP12DStandardChannelWidget::create
void create()
Definition: IVP12DStandardChannelWidget.cxx:121
query_example.col
col
Definition: query_example.py:7
IVP12DStandardChannelWidget::systemErased
void systemErased(IVP1System *)
Definition: IVP12DStandardChannelWidget.cxx:157
get_generator_info.version
version
Definition: get_generator_info.py:33
VP1ControllerHelper::compositionController
static QWidget * compositionController(const QList< IVP1System * > &systemsWithControllersAllowed, QMap< IVP1System *, QWidget * > &sys2tabpage, VP1TabWidget *&tabwidget, const QList< QPair< IVP1System *, bool > > &system2switchable, QMap< QCheckBox *, IVP1System * > &checkbox2system, VP1ColorSelectButton *&colorselectbutton, QWidget *extrawidget=0, bool nobgdcolorsel=false)
Definition: VP1ControllerHelper.cxx:28
IVP12DSystemSimple
Definition: IVP12DSystemSimple.h:22
IVP12DStandardChannelWidget::Imp::checkbox2system
QMap< QCheckBox *, IVP1System * > checkbox2system
Definition: IVP12DStandardChannelWidget.cxx:44
VP1GraphicsView.h
IVP12DStandardChannelWidget::DisallowMovable
@ DisallowMovable
Definition: IVP12DStandardChannelWidget.h:36
VP1GraphicsItemCollection
Definition: VP1GraphicsItemCollection.h:53
IVP12DStandardChannelWidget
Definition: IVP12DStandardChannelWidget.h:22
VP1ControllerHelper.h
VP12DExaminerViewer
Definition: VP12DExaminerViewer.h:26
IVP1ChannelWidget::turnOn
void turnOn(IVP1System *)
Definition: IVP1ChannelWidget.cxx:237
IVP12DStandardChannelWidget::Imp
Definition: IVP12DStandardChannelWidget.cxx:37
VP1GraphicsView
Definition: VP1GraphicsView.h:22
IVP12DStandardChannelWidget::restoreFromState
virtual void restoreFromState(QByteArray)
Definition: IVP12DStandardChannelWidget.cxx:305