ATLAS Offline Software
Loading...
Searching...
No Matches
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
19#include "VP1Base/VP1Msg.h"
20
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
40public:
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//___________________________________________________________________________
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;
88 m_d->colorselectbutton = 0;
89}
90
91//___________________________________________________________________________
96
97//___________________________________________________________________________
98void 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
115 m_d->view_xy->addItemCollection(ic);
117 m_d->view_rz->addItemCollection(ic);
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.
148 m_d->sys2tabpage,m_d->tabwidget,
149 m_d->system2switchable,
150 m_d->checkbox2system,
151 m_d->colorselectbutton ));
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.
177 m_d->view_xy->fitViewToContents();
178 m_d->view_rz->fitViewToContents();
179 m_d->first=false;
180 }
181}
182
183//___________________________________________________________________________
185 m_d->view_xy->clearSelections();
186 m_d->view_rz->clearSelections();
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);
205 for (VP1GraphicsItemCollection*ic : system2itemcols.value(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);
234 for (VP1GraphicsItemCollection*ic : system2itemcols.value(sys)) {
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);
241 tabwidget->removeTab(index);
242 }
243 }
244 }
245
246 view_xy->scene()->update();
247 view_rz->scene()->update();
248
249}
250
251//___________________________________________________________________________
252void 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:
306 out << m_d->colorselectbutton->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}
QMap< IVP1System *, QWidget * > sys2tabpage
QMap< QCheckBox *, IVP1System * > checkbox2system
QMap< IVP12DSystem *, QSet< VP1GraphicsItemCollection * > > system2itemcols
QList< QPair< IVP1System *, bool > > system2switchable
void addSystem(IVP12DDetViewsSystem *, double zfactor, const SystemOptions &options=AllowAll)
IVP12DDetViewsChannelWidget(const QString &name, const QString &information, const QString &contact_info)
void addGeneralSystem(IVP12DSystem *, const PROJECTION &projection, double zfactor, const SystemOptions &options=AllowAll)
QSet< VP1GraphicsItemCollection * > getItemCollections_RZ() const
QSet< VP1GraphicsItemCollection * > getItemCollections_XY() const
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