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