ATLAS Offline Software
Loading...
Searching...
No Matches
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
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
38public:
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//___________________________________________________________________________
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);
71 m_d->colorselectbutton = 0;
72
73 m_d->view = examiner->view();
74
75 m_d->tabwidget = 0;
76}
77
78//___________________________________________________________________________
83
84//___________________________________________________________________________
85void 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());
98 m_d->view->addItemCollection(ic);
99 }
100
101 for (VP1GraphicsItemCollection* ic : system->getItemCollections()){
102 m_d->view->setDisallowInteractions(ic, !handleSelections );
103 }
104 for (VP1GraphicsItemCollection* ic : system->getItemCollections()){
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.
126 m_d->sys2tabpage,m_d->tabwidget,
127 m_d->system2switchable,
128 m_d->checkbox2system,
129 m_d->colorselectbutton ));
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) {
151 m_d->view->fitViewToContents();
152 m_d->first=false;
153 }
154}
155
156//___________________________________________________________________________
158 m_d->view->clearSelections();
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);
177 for(VP1GraphicsItemCollection*ic : system2itemcols.value(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);
206 for(VP1GraphicsItemCollection*ic : system2itemcols.value(sys)) {
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);
213 tabwidget->removeTab(index);
214 }
215 }
216 }
217
218 view->scene()->update();
219
220}
221
222//___________________________________________________________________________
223void IVP12DStandardChannelWidget::addSystem(IVP12DSystemSimple* sys, const SystemOptions& options )
224{
225 addSystem((IVP12DSystem*)sys,options);
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:
278 out << m_d->colorselectbutton->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}
QMap< QCheckBox *, IVP1System * > checkbox2system
QMap< IVP1System *, QWidget * > sys2tabpage
QMap< IVP12DSystem *, QSet< VP1GraphicsItemCollection * > > system2itemcols
QList< QPair< IVP1System *, bool > > system2switchable
void addSystem(IVP12DSystem *, const SystemOptions &options=AllowAll)
IVP12DStandardChannelWidget(const QString &name, const QString &information, const QString &contact_info)
const QSet< VP1GraphicsItemCollection * > & getItemCollections()
void registerSystem(IVP1System *)
void registerController(QWidget *)
virtual void restoreFromState(QByteArray)
void message(QString)
const QString & information() const
const QString & name() const
IVP1ChannelWidget(const QString &name, const QString &information, const QString &contact_info)
const QString & contact_info() const
virtual QByteArray saveState()
VP1GraphicsView * view() const
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)
static void messageVerbose(const QString &)
Definition VP1Msg.cxx:84
Definition index.py:1