ATLAS Offline Software
VP1Controller.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 
7 // //
8 // Implementation of class VP1Controller //
9 // //
10 // Author: Thomas H. Kittelmann (Thomas.Kittelmann@cern.ch) //
11 // Initial version: August 2008 //
12 // //
14 
15 #include "VP1Base/VP1Controller.h"
17 #include "VP1Base/IVP1System.h"
18 #include "VP1Base/VP1Serialise.h"
19 #include "VP1Base/VP1Deserialise.h"
23 
24 #include <QPushButton>
25 #include <QCheckBox>
26 #include <QComboBox>
27 #include <QGroupBox>
28 #include <QSpinBox>
29 #include <QDoubleSpinBox>
30 #include <QRadioButton>
31 #include <QSlider>
32 #include <QScrollArea>
33 #include <QScrollBar>
34 #include <QShortcut>
35 #include <QButtonGroup>
36 #include <QTimer>
37 
38 #include <Inventor/C/errors/debugerror.h>
39 #include <Inventor/SbColor4f.h>
40 #include <Inventor/nodes/SoMaterial.h>
41 
43 
44 
45 //____________________________________________________________________
47 public:
48 
49  const char * lastUpdateSlot;
51  class DialogInfo {
52  public:
53  DialogInfo(QPushButton * lb,QWidget * dw,QAbstractButton * ec)
54  : enabledButton(ec), dialogWidget(dw), launchButton(lb), neverShown(true) {}
55  ~DialogInfo() { delete dialogWidget; }
56  QAbstractButton * enabledButton;
57  QWidget * dialogWidget;
58  QPushButton * launchButton;
59  bool neverShown;
60  };
61 
62  QList<DialogInfo *> dialogs;
63 
64  SoMaterial * fallBackMaterial;
65 };
66 
67 //____________________________________________________________________
69 {
70  m_initVarsMode = true;
72  m_initVarsMode = false;
73 }
74 
75 //____________________________________________________________________
76 VP1Controller::VP1Controller(IVP1System * sys, const QString& classname )
77  : QWidget(0),//Controllers always created parentless.
78  VP1HelperClassBase(sys,classname),
79  m_d(new Imp),
80  m_initVarsMode(true)//Start as true in case any possible_change
81  //stuff are called before intLastVars()?
82 {
83  m_d->fallBackMaterial = 0;
84  m_d->lastUpdateSlot = 0;
85  m_d->collWidget = 0;
86  setObjectName(classname);
87 }
88 
89 //____________________________________________________________________
91 {
92  for (Imp::DialogInfo* di : m_d->dialogs)
93  delete di;
94  if (m_d->fallBackMaterial)
95  m_d->fallBackMaterial->unref();
96  delete m_d;
97 }
98 
99 //____________________________________________________________________
100 QString VP1Controller::toString( const bool& par )
101 {
102  return par?"On":"Off";
103 }
104 
105 //____________________________________________________________________
106 QString VP1Controller::toString( const QList<VP1Interval>& l )
107 {
108  QString s;
109  for(int i=0;i<l.count();++i)
110  s+= l.at(i).toString()+(i==l.count()-1?"":", ");
111  return s;
112 }
113 
114 //____________________________________________________________________
115 QString VP1Controller::toString( SbColor4f p )
116 {
117  float r, g, b, a;
118  p.getValue(r, g, b, a);
119  return "("+str(r)+", "+str(g)+", "+str(b)+", "+str(1-a)+")";
120 }
121 
122 //____________________________________________________________________
123 void VP1Controller::initDialog(QWidget * dialog, QPushButton* launchButton, QPushButton* closeButton,QAbstractButton* enabledButton)
124 {
125  QString txt(enabledButton?enabledButton->text():launchButton->text());
126  txt.replace("&&","&");
127  dialog->setWindowTitle(txt+" ["+systemBase()->name()+"]");
128  dialog->setWindowIcon(QIcon(QString(":/vp1/icons/icons/3d_32x32.png")));
129  launchButton->setMaximumHeight(static_cast<int>(0.5+QFontMetricsF(launchButton->font()).height()*1.05+2));
130  launchButton->setMinimumHeight(launchButton->maximumHeight());
131  launchButton->setCheckable(true);
132 
133  QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
134  sizePolicy.setHorizontalStretch(0);
135  sizePolicy.setVerticalStretch(0);
136  sizePolicy.setHeightForWidth(launchButton->sizePolicy().hasHeightForWidth());
137  launchButton->setSizePolicy(sizePolicy);
138  launchButton->setFocusPolicy(Qt::NoFocus);
139 
140  if (enabledButton)
141  launchButton->setEnabled(enabledButton->isChecked());
142 
143  m_d->dialogs << new Imp::DialogInfo(launchButton,dialog,enabledButton);
144 
145  connect(launchButton,SIGNAL(clicked()),this,SLOT(toggleDialogState()));
146  if (enabledButton)
147  connect(enabledButton,SIGNAL(toggled(bool)),this,SLOT(enabledButtonStateChanged()));
148  CloseEventEater* closeEventEater = new CloseEventEater(this);
149  dialog->installEventFilter(closeEventEater);
150 
151  if(closeButton) {
152  closeButton->setText("&Close");
153  closeButton->setToolTip("Close this dialog [Esc]");
154  connect(closeButton,SIGNAL(clicked()),dialog,SLOT(close()));
155  }
156  connect(new QShortcut(QKeySequence(Qt::Key_Escape), dialog),SIGNAL(activated()),dialog,SLOT(close()));
157 
158  //To avoid an extra call in the code we do this a few times more than necessary (fixme: put in initLastVars!!):
159  int maxwidth(0);
160  for (Imp::DialogInfo* di : m_d->dialogs)
161  maxwidth = std::max(maxwidth,di->launchButton->sizeHint().width());
162  for (Imp::DialogInfo* di : m_d->dialogs)
163  di->launchButton->setMinimumWidth(maxwidth);
164 }
165 
166 //____________________________________________________________________
168 {
169  Imp::DialogInfo * di(0);
170  for (Imp::DialogInfo* di2 : m_d->dialogs) {
171  if (di2->enabledButton==sender()) {
172  di = di2;
173  break;
174  }
175  }
176  if (!di) {
177  message("ERROR: enabledButtonStateChanged() triggered with unrecognised sender() ="
178  +QString(sender()?sender()->objectName():"NULL"));
179  return;
180  }
181 
182  bool on(di->enabledButton->isChecked());
183  if (di->launchButton->isEnabled()!=on)
184  di->launchButton->setEnabled(on);
185  if (!on) {
186  if (di->dialogWidget->isVisible())
187  di->dialogWidget->setVisible(false);
188  if (di->dialogWidget->windowState()==Qt::WindowMinimized)
189  di->dialogWidget->setWindowState(Qt::WindowNoState);
190  }
191 }
192 
193 //____________________________________________________________________
194 void VP1Controller::toggleDialogState(QObject* widget)
195 {
196  Imp::DialogInfo * di(0);
197  for (Imp::DialogInfo* di2 : m_d->dialogs) {
198  if (di2->launchButton==sender() || (widget && di2->dialogWidget==widget)) {
199  di = di2;
200  break;
201  }
202  }
203 
204  if (!di) {
205  message("ERROR: toggleDialogState() triggered with unrecognised sender() ="
206  +QString(sender()?sender()->objectName():"NULL"));
207  return;
208  }
209 
210  bool oldvis = di->dialogWidget->isVisible();
211 
212  if (oldvis&&di->dialogWidget->windowState()==Qt::WindowMinimized) {
213  di->dialogWidget->setWindowState(Qt::WindowNoState);
214  } else {
215  di->dialogWidget->setVisible(!oldvis);
216  if (!oldvis && di->neverShown) {
217  di->neverShown = false;
218  //do stuff
219  // QSize size(955, 717);
220  // size = size.expandedTo(VP1MainWindow->minimumSizeHint());
221  // di->dialogWidget->resize(di->dialogWidget->minimumSizeHint());
222  }
223  }
224 
225  //synchronise toggle button state (for example if this was called by CloseEventEater)
226  if (di->launchButton->isCheckable() && oldvis){
227  di->launchButton->setChecked(false);
228  }
229 }
230 
231 //____________________________________________________________________
233 {
234  if (sender()!=m_d->collWidget||!m_d->collWidget) {
235  message("ERROR: Unexpected signal in collWidgetContentChanged slot!!");
236  return;
237  }
238  QScrollArea* scrollarea = dynamic_cast<QScrollArea*>(m_d->collWidget->parent());
239  if (!scrollarea&&m_d->collWidget->parent())
240  scrollarea = dynamic_cast<QScrollArea*>(m_d->collWidget->parent()->parent());
241  if (!scrollarea) {
242  message("ERROR: m_d->collWidget not child or grandchild of a scroll area!!");
243  return;
244  }
246  m_d->collWidget->setMinimumWidth(width);
247  m_d->collWidget->setMaximumWidth(width);
248  QScrollBar * sb = scrollarea->verticalScrollBar();
249  if (sb)
250  width+=sb->sizeHint().width();
251  scrollarea->setMinimumWidth(width+2);//2 is just some margin
252 }
253 
254 //____________________________________________________________________
255 void VP1Controller::setupCollWidgetInScrollArea(QScrollArea * scrollarea, VP1CollectionWidget* collWidget)
256 {
257  if (!scrollarea || !collWidget) {
258  message("ERROR: NULL scrollarea or collWidget");
259  return;
260  }
261  QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
262  sizePolicy.setHorizontalStretch(0);
263  sizePolicy.setVerticalStretch(scrollarea->sizePolicy().verticalStretch());
264  sizePolicy.setHeightForWidth(scrollarea->sizePolicy().hasHeightForWidth());
265  scrollarea->setSizePolicy(sizePolicy);
266 
267  collWidget->setContentsMargins(0,0,0,0);
268  if (!collWidget->children().isEmpty()&&collWidget->children().at(0)->isWidgetType()) {
269  static_cast<QWidget*>(collWidget->children().at(0))->setContentsMargins(0,0,0,0);
270  }
271  scrollarea->setContentsMargins(0,0,0,0);
272 
273  scrollarea->setWidgetResizable(true);
274  scrollarea->setFrameShape(QFrame::NoFrame);
275  scrollarea->setFrameShadow(QFrame::Plain);
276  collWidget->setParent(scrollarea);
277  scrollarea->setWidget(collWidget);
278  scrollarea->viewport()->setContentsMargins(0,0,0,0);
279  scrollarea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
280  collWidget->setObjectName(objectName()+"_CollWidget");
281  scrollarea->setObjectName(objectName()+"_CollWidgetScrollArea");
282  m_d->collWidget = collWidget;
283  connect(collWidget,SIGNAL(visibleContentsChanged()),this,SLOT(collWidgetContentChanged()));
284 }
285 
286 
287 //____________________________________________________________________
288 QButtonGroup * VP1Controller::defineRadioButtonGroup( QRadioButton * rb0, QRadioButton * rb1,QRadioButton * rb2,
289  QRadioButton * rb3,QRadioButton * rb4,QRadioButton * rb5,
290  QRadioButton * rb6,QRadioButton * rb7,QRadioButton * rb8,
291  QRadioButton * rb9 )
292 {
293  QList<QRadioButton *> l;
294  l << rb0 << rb1 << rb2 << rb3 << rb4 << rb5 << rb6 << rb7 << rb8 << rb9;
295  l.removeAll(0);
296  return defineRadioButtonGroup(l);
297 }
298 
299 //____________________________________________________________________
300 QButtonGroup * VP1Controller::defineRadioButtonGroup( const QList<QRadioButton *>& l )
301 {
302  QRadioButton * rb_checked(0);
303  for (QRadioButton *rb : l) {
304  if (rb->isChecked()) {
305  rb_checked = rb;
306  break;
307  }
308  }
309  QButtonGroup * radiogroup = new QButtonGroup(this);
310  for (QRadioButton *rb : l)
311  radiogroup->addButton(rb);
312  if (rb_checked)
313  rb_checked->setChecked(true);
314  return radiogroup;
315 }
316 
317 //____________________________________________________________________
318 const char * VP1Controller::addUpdateSlot(const char * slot)
319 {
320  messageVerbose("Adding update slot: "+QString(slot));
321  connect(this,SIGNAL(dummyUpdateTrigger()),this,slot);
322  m_d->lastUpdateSlot = slot;
323  return slot;
324 }
325 
326 //____________________________________________________________________
327 void VP1Controller::connectToLastUpdateSlot(QObject* sender,const char * signal)
328 {
329  connect(sender,signal,this,m_d->lastUpdateSlot);
330 }
331 
332 //____________________________________________________________________
334 {
335  connectToLastUpdateSlot(cb,SIGNAL(toggled(bool)));
336 }
337 
338 //____________________________________________________________________
340 {
341  connectToLastUpdateSlot(cb,SIGNAL(currentIndexChanged(int)));
342 }
343 
344 //____________________________________________________________________
346 {
347  connectToLastUpdateSlot(gb,SIGNAL(toggled(bool)));
348 }
349 
350 //____________________________________________________________________
352 {
353  connectToLastUpdateSlot(sb,SIGNAL(valueChanged(int)));
354 }
355 
356 //____________________________________________________________________
358 {
359  connectToLastUpdateSlot(dsb,SIGNAL(valueChanged(double)));
360 }
361 
362 //____________________________________________________________________
364 {
365  connectToLastUpdateSlot(rb,SIGNAL(toggled(bool)));
366 }
367 
368 //____________________________________________________________________
370 {
371  connectToLastUpdateSlot(bg,SIGNAL(buttonClicked(int)));
372 }
373 
374 //____________________________________________________________________
376 {
377  connectToLastUpdateSlot(s,SIGNAL(valueChanged(int)));
378 }
379 
380 //____________________________________________________________________
382 {
383  connectToLastUpdateSlot(csb,SIGNAL(colorChanged(const QColor&)));
384 }
385 
386 //____________________________________________________________________
387 void VP1Controller::restoreSettings(const QByteArray& ba)
388 {
389  messageDebug("VP1Controller::restoreSettings()");
390 
393 
394  //warn unrestored:
395  if (m_d->collWidget)
396  s.ignoreWidget(m_d->collWidget);
397  s.warnUnrestored((QWidget*)(this));
398  for (Imp::DialogInfo* di : m_d->dialogs)
399  s.warnUnrestored(di->dialogWidget);
400 
401  QTimer::singleShot(0, this, SLOT(testForChanges()));
402 }
403 
404 //____________________________________________________________________
405 QByteArray VP1Controller::saveSettings() const
406 {
407  messageDebug("VP1Controller::saveSettings()");
408 
410 
411  messageDebug("calling actualSaveSettings()...");
413 
414  //Warn unsaved:
415  if (m_d->collWidget)
416  s.ignoreWidget(m_d->collWidget);
417 
418  s.warnUnsaved((QWidget*)(this));
419  for (Imp::DialogInfo* di : m_d->dialogs)
420  s.warnUnsaved(di->dialogWidget);
421 
422  return s.result();
423 
424 }
425 
426 //____________________________________________________________________
428 {
429  if (!m_d->fallBackMaterial) {
430  m_d->fallBackMaterial = new SoMaterial;
431  m_d->fallBackMaterial->ref();
432  }
433  return m_d->fallBackMaterial;
434 }
435 
436 //____________________________________________________________________
438 {
439  if (!mb) {
440  message("ERROR: Null material button pointer");
441  return fallBackMaterial();
442  }
443  QList<SoMaterial*> mats = mb->handledMaterials();
444  if (mats.count()!=1) {
445  message("ERROR: No material in button "+mb->objectName());
446  return fallBackMaterial();
447  }
448  return mats.at(0);
449 
450 
451 }
VP1Serialise.h
VP1Controller::defineRadioButtonGroup
QButtonGroup * defineRadioButtonGroup(QRadioButton *rb0, QRadioButton *rb1, QRadioButton *rb2=0, QRadioButton *rb3=0, QRadioButton *rb4=0, QRadioButton *rb5=0, QRadioButton *rb6=0, QRadioButton *rb7=0, QRadioButton *rb8=0, QRadioButton *rb9=0)
Definition: VP1Controller.cxx:288
VP1Controller::addUpdateSlot
const char * addUpdateSlot(const char *slot)
Definition: VP1Controller.cxx:318
beamspotman.r
def r
Definition: beamspotman.py:676
VP1Controller::setupCollWidgetInScrollArea
void setupCollWidgetInScrollArea(QScrollArea *scrollarea, VP1CollectionWidget *collWidget)
Definition: VP1Controller.cxx:255
VP1Controller::Imp::DialogInfo::neverShown
bool neverShown
Definition: VP1Controller.cxx:59
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
VP1Controller::toString
static QString toString(const T &par)
Definition: VP1Controller.h:138
VP1Deserialise.h
VP1Serialise
Definition: VP1Serialise.h:45
StandaloneBunchgroupHandler.bg
bg
Definition: StandaloneBunchgroupHandler.py:243
VP1Controller::Imp::lastUpdateSlot
const char * lastUpdateSlot
Definition: VP1Controller.cxx:49
VP1Controller::dummyUpdateTrigger
void dummyUpdateTrigger()
VP1Controller::VP1Controller
VP1Controller(IVP1System *sys, const QString &classname)
Definition: VP1Controller.cxx:76
CloseEventEater.h
WriteCellNoiseToCool.rb
rb
Definition: WriteCellNoiseToCool.py:229
VP1MaterialButton.h
max
constexpr double max()
Definition: ap_fixedTest.cxx:33
VP1MaterialButton
Definition: VP1MaterialButton.h:46
VP1HelperClassBase::messageVerbose
void messageVerbose(const QString &) const
Definition: VP1HelperClassBase.cxx:78
VP1Controller::fallBackMaterial
SoMaterial * fallBackMaterial() const
Definition: VP1Controller.cxx:427
fillPileUpNoiseLumi.connect
string connect
Definition: fillPileUpNoiseLumi.py:70
VP1Controller::initDialog
void initDialog(T &theUI, QPushButton *launchbutton, QAbstractButton *enabledButton=0)
Definition: VP1Controller.h:144
CSV_InDetExporter.new
new
Definition: CSV_InDetExporter.py:145
VP1Controller::Imp::collWidget
VP1CollectionWidget * collWidget
Definition: VP1Controller.cxx:50
VP1Controller::restoreSettings
void restoreSettings(const QByteArray &)
Definition: VP1Controller.cxx:387
VP1Controller::actualSaveSettings
virtual void actualSaveSettings(VP1Serialise &) const =0
UploadAMITag.l
list l
Definition: UploadAMITag.larcaf.py:158
VP1String::str
static QString str(const QString &s)
Definition: VP1String.h:49
VP1Controller::saveSettings
QByteArray saveSettings() const
Definition: VP1Controller.cxx:405
VP1ColorSelectButton
Definition: VP1ColorSelectButton.h:20
VP1HelperClassBase::messageDebug
void messageDebug(const QString &) const
Definition: VP1HelperClassBase.cxx:65
VP1Controller::connectToLastUpdateSlot
void connectToLastUpdateSlot(QObject *sender, const char *signal)
Definition: VP1Controller.cxx:327
mapkey::sys
@ sys
Definition: TElectronEfficiencyCorrectionTool.cxx:42
VP1CollectionWidget.h
Cut::signal
@ signal
Definition: SUSYToolsAlg.cxx:67
IVP1System
Definition: IVP1System.h:36
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
VP1Controller::Imp::DialogInfo::DialogInfo
DialogInfo(QPushButton *lb, QWidget *dw, QAbstractButton *ec)
Definition: VP1Controller.cxx:53
python.BunchSpacingUtils.lb
lb
Definition: BunchSpacingUtils.py:88
lumiFormat.i
int i
Definition: lumiFormat.py:85
VP1Controller::Imp::fallBackMaterial
SoMaterial * fallBackMaterial
Definition: VP1Controller.cxx:64
python.CaloCondTools.g
g
Definition: CaloCondTools.py:15
VP1Controller::Imp::DialogInfo::~DialogInfo
~DialogInfo()
Definition: VP1Controller.cxx:55
VP1Controller::m_d
Imp * m_d
Definition: VP1Controller.h:127
VP1Controller::m_initVarsMode
bool m_initVarsMode
Definition: VP1Controller.h:129
VP1CustomTourEditor
Definition: VP1CustomTourEditor.h:26
VP1Controller::~VP1Controller
virtual ~VP1Controller()
Definition: VP1Controller.cxx:90
VP1ColorSelectButton.h
VP1CollectionWidget::appropriateFixedWidth
int appropriateFixedWidth() const
Definition: VP1CollectionWidget.cxx:276
VP1Deserialise
Definition: VP1Deserialise.h:44
CloseEventEater
Definition: CloseEventEater.h:12
VP1HelperClassBase
Definition: VP1HelperClassBase.h:28
VP1Controller::Imp::DialogInfo::launchButton
QPushButton * launchButton
Definition: VP1Controller.cxx:58
VP1Controller::Imp
Definition: VP1Controller.cxx:46
VP1Controller::Imp::DialogInfo::dialogWidget
QWidget * dialogWidget
Definition: VP1Controller.cxx:57
VP1Controller::Imp::DialogInfo
Definition: VP1Controller.cxx:51
keylayer_zslicemap.sb
sb
Definition: keylayer_zslicemap.py:192
VP1HelperClassBase::systemBase
IVP1System * systemBase() const
Definition: VP1HelperClassBase.h:50
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
createCoolChannelIdFile.par
par
Definition: createCoolChannelIdFile.py:29
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
VP1Controller::getMaterial
SoMaterial * getMaterial(VP1MaterialButton *) const
Definition: VP1Controller.cxx:437
VP1Controller::Imp::dialogs
QList< DialogInfo * > dialogs
Definition: VP1Controller.cxx:62
VP1Controller::actualRestoreSettings
virtual void actualRestoreSettings(VP1Deserialise &)=0
a
TList * a
Definition: liststreamerinfos.cxx:10
Base_Fragment.width
width
Definition: Sherpa_i/share/common/Base_Fragment.py:59
VP1CollectionWidget
Definition: VP1CollectionWidget.h:32
VP1Controller::testForChanges
void testForChanges()
Definition: VP1Controller.h:112
TRT_PAI_physicsConstants::mb
const double mb
1mb to cm2
Definition: TRT_PAI_physicsConstants.h:15
VP1Controller::collWidgetContentChanged
void collWidgetContentChanged()
Definition: VP1Controller.cxx:232
VP1Controller::enabledButtonStateChanged
void enabledButtonStateChanged()
Definition: VP1Controller.cxx:167
VP1HelperClassBase::message
void message(const QString &) const
Definition: VP1HelperClassBase.cxx:49
VP1Controller.h
VP1Controller::toggleDialogState
void toggleDialogState(QObject *widget=0)
Definition: VP1Controller.cxx:194
VP1Controller::initLastVars
void initLastVars()
Definition: VP1Controller.cxx:68
IVP1System.h
VP1Controller::m_customTourEditor
static VP1CustomTourEditor * m_customTourEditor
Definition: VP1Controller.h:125
VP1Controller::Imp::DialogInfo::enabledButton
QAbstractButton * enabledButton
Definition: VP1Controller.cxx:56
VP1Controller::currentSettingsVersion
virtual int currentSettingsVersion() const =0