ATLAS Offline Software
VP1CollectionWidget.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 
7 // //
8 // Implementation of class VP1CollectionWidget //
9 // //
10 // Author: Thomas H. Kittelmann (Thomas.Kittelmann@cern.ch) //
11 // Initial version: June 2008 //
12 // //
14 
18 #include "VP1Base/VP1Msg.h"
19 
20 #include <QSpacerItem>
21 #include <QGridLayout>
22 #include <QLabel>
23 #include <QCheckBox>
24 #include <QSet>
25 #include <QList>
26 #include <QRegExp>
27 
28 //____________________________________________________________________
30 public:
33  QWidget * collWidget;
35  QList<QWidget *> widgetsFromCollections;
36  QList<VP1Collection*> collections;
39  QList<VP1StdCollection*> last_visibleStdCollections;
40  QList<qint32> visibleStdCollectionTypesFromVisStdCols(const QList<VP1StdCollection*>& l) const;
42  void clearGui(bool deleteGuiElements);
43 
45 
46 };
47 
48 //____________________________________________________________________
50  : QWidget(parent), VP1HelperClassBase(0,"VP1CollectionWidget"), m_d(new Imp(this))
51 {
52 }
53 
54 //____________________________________________________________________
56 {
57  delete m_d;
58 }
59 
60 //____________________________________________________________________
61 QList<VP1Collection*> VP1CollectionWidget::collections() const
62 {
63  return m_d->collections;
64 }
65 
66 //____________________________________________________________________
67 void VP1CollectionWidget::Imp::clearGui(bool deleteGuiElements)
68 {
69  if (!deleteGuiElements) {
70  for(QWidget *w : widgetsFromCollections) {
71  w->hide();
72  w->setParent(0);
73  }
74  }
75  delete collWidget;
76  collWidget = 0;
77 
78 }
79 
80 //____________________________________________________________________
81 void VP1CollectionWidget::clear(bool deleteCollections,bool deleteGuiElements)
82 {
84  m_d->clearGui(deleteGuiElements);
85  m_d->widgetsFromCollections.clear();
86 
87  if (deleteCollections) {
89  delete col;
90  }
91  m_d->collections.clear();
92 
93  //Fixme: update report-on-width
95 
98 }
99 
100 //____________________________________________________________________
102 {
103  theclass->setUpdatesEnabled(false);
104  if (collWidget)
105  clearGui(false);
106 
107  collWidget = new QWidget();//We only add the widget in the end (to avoid needless updates).
108 
109  QVBoxLayout * vlayout = new QVBoxLayout;
110  vlayout->setSpacing(0);
111  vlayout->setMargin(0);
112  if (collections.isEmpty()) {
113  QHBoxLayout * labellayout = new QHBoxLayout;
114  labellayout->setSpacing(0);
115  labellayout->addWidget(new QLabel("No collections in event."),0,Qt::AlignLeft);
116  labellayout->addStretch(1);
117  vlayout->addLayout(labellayout);
118  }
119 
120  QSet<QString> sections;
122  sections.insert(col->section());
123  QList<QString> sectionsSorted = sections.values();
124  std::sort(sectionsSorted.begin(), sectionsSorted.end());
125  theclass->sortSections(sectionsSorted);
126 
127  const bool nosectionlabels = sectionsSorted.count() == 1 && sectionsSorted.at(0).isEmpty();
128 
129  int maxFirstColumnCheckBoxWidth(0);
130  QList<QCheckBox*> firstColumnCheckBoxes;
131 
132  int gridmargins(0);
133  for (QString section : sectionsSorted) {
134  //type section header:
135  QLabel * sectionlabel(0);
136  if (!nosectionlabels) {
137  QHBoxLayout * labellayout = new QHBoxLayout;
138  labellayout->setSpacing(0);
139  sectionlabel =new QLabel;
140  sectionlabel->setTextFormat(Qt::RichText);
141  sectionlabel->setText("<b>"+section+"</b>");
142  labellayout->addWidget(sectionlabel,0,Qt::AlignLeft);
143  labellayout->addStretch(1);
144  vlayout->addLayout(labellayout);
145  }
146  //Add individual widgets for collections:
147  QGridLayout * gridLayout = new QGridLayout;
148  gridLayout->setHorizontalSpacing(6);
149  gridLayout->setVerticalSpacing(0);
150  gridLayout->setMargin(0);
151  if (!nosectionlabels)
152  gridLayout->addItem(new QSpacerItem(10, 1, QSizePolicy::Fixed, QSizePolicy::Fixed),0,0);
153  vlayout->addLayout(gridLayout);
154  for (VP1Collection* col : collections) {
155  if (col->section()!=section)
156  continue;
157  if (sectionlabel) {
158  if (!col->sectionToolTip().isEmpty())
159  sectionlabel->setToolTip(col->sectionToolTip());
160  sectionlabel = 0;
161  }
162  int newrow = gridLayout->rowCount();
163  int i(1);
164  for (QWidget*w : col->widgetsForGuiRow()) {
165  if (!w) {
166  theclass->message("WARNING: Ignoring null widget provided by widgetsForGuiRow() (perhaps due to a VP1StdCollection you didn't init()?)");
167  continue;
168  }
169  //Smaller font:
170  QFont f(w->font());
171  // f.setPointSizeF(f.pointSizeF()*0.9);
172  w->setFont(f);
173  int maxheight = static_cast<int>(0.5+QFontMetricsF(f).height()*1.05+2);
174  w->setMaximumHeight(maxheight);
175  VP1MaterialButton * mb = dynamic_cast<VP1MaterialButton *>(w);
176  if (mb)
177  mb->setDimension(maxheight);
178  if (i==1) {
179  QCheckBox * cb = dynamic_cast<QCheckBox *>(w);
180  if (cb) {
181  firstColumnCheckBoxes << cb;
182  if (maxFirstColumnCheckBoxWidth<cb->sizeHint().width())
183  maxFirstColumnCheckBoxWidth = cb->sizeHint().width();
184  }
185  }
186  widgetsFromCollections << w;
187  w->setParent(collWidget);
188  w->setVisible(true);
189  gridLayout->addWidget( w, newrow, i++);
190  }
191  gridLayout->addItem(new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Expanding),newrow,i);
192  }
193  if (gridmargins==0) {
194  int left, top, right, bottom;
195  gridLayout->getContentsMargins ( &left, &top, &right, &bottom );
196  gridmargins = left+right;
197  }
198  }
199 
200  if (maxFirstColumnCheckBoxWidth>0) {
201  for (QCheckBox *cb : firstColumnCheckBoxes)
202  cb->setMinimumWidth(maxFirstColumnCheckBoxWidth);
203  }
204 
205  vlayout->addStretch(1);
206 
207  QHBoxLayout * hlayout = new QHBoxLayout;
208  hlayout->setMargin(0);
209  hlayout->setSpacing(0);
210  hlayout->addLayout(vlayout);
211  hlayout->addStretch(1);
212  collWidget->setLayout(hlayout);
213 
214  //Put collWidget into the collection widget:
215  delete theclass->layout();
216  QHBoxLayout * hlayoutPageCol = new QHBoxLayout;
217  collWidget->setParent(theclass);
218  hlayoutPageCol->addWidget(collWidget);
219  theclass->setLayout(hlayoutPageCol);
220  theclass->setContentsMargins(0,0,0,0);
221  collWidget->setContentsMargins(0,0,0,0);
222  hlayoutPageCol->setContentsMargins(0,0,0,0);
223  //Fixme: reshuffle the above or turn off updates to avoid flicker.
224 
225  theclass->setContentsMargins(0,0,0,0);
226  collWidget->setContentsMargins(0,0,0,0);
227  appropriateFixedWidth = collWidget->sizeHint().width()//Fixme: before we add the collwidget.
228  +gridmargins;
229 
230  theclass->setUpdatesEnabled(true);
231  theclass->visibleContentsChanged();
232 
233 }
234 
235 
236 //____________________________________________________________________
237 void VP1CollectionWidget::addCollections(QList<VP1Collection*> cols, bool applySavedStates )
238 {
239  messageVerbose("addCollections called with "+str(cols.count())+" new collections");
240 
241  m_d->collections << cols;//FIXME: Test not already there.
242 
244 
245  if (applySavedStates)
247 
249  for (VP1Collection* col : cols) {
250  VP1StdCollection* stdcol = dynamic_cast<VP1StdCollection*>(col);
251  if (stdcol)
252  connect(stdcol,SIGNAL(visibilityChanged(bool)),this,SLOT(possibleChange_visibleStdCollections()));
253  }
254 
255 }
256 
257 //____________________________________________________________________
258 void VP1CollectionWidget::setCollections(QList<VP1Collection*> cols,bool applySavedStates)
259 {
260  m_d->collections = cols;
261 
263 
264  if (applySavedStates)
266 
268  for (VP1Collection* col : cols) {
269  VP1StdCollection* stdcol = dynamic_cast<VP1StdCollection*>(col);
270  if (stdcol)
271  connect(stdcol,SIGNAL(visibilityChanged(bool)),this,SLOT(possibleChange_visibleStdCollections()));
272  }
273 }
274 
275 //____________________________________________________________________
277 {
278  return m_d->appropriateFixedWidth;
279 }
280 
281 //____________________________________________________________________
283 {
284  VP1Msg::messageDebug("VP1CollectionWidget::Imp::updateStatesWithCurrentInfo()");
286 }
287 
288 //____________________________________________________________________
289 void VP1CollectionWidget::addStateInfo(const VP1CollStates& newinfo, bool overwritesExisting )
290 {
292  QMapIterator<QByteArray,QByteArray> it(newinfo);
293  while (it.hasNext()) {
294  it.next();
295  if (!overwritesExisting&&m_d->states.contains(it.key()))
296  continue;
297  m_d->states.insert(it.key(),it.value());
298  }
299  if (overwritesExisting)
301 }
302 
303 //____________________________________________________________________
305 {
307  return m_d->states;
308 }
309 
310 
311 //____________________________________________________________________
312 QList<qint32> VP1CollectionWidget::Imp::visibleStdCollectionTypesFromVisStdCols(const QList<VP1StdCollection*>& l) const
313 {
314  QSet<qint32> vt;
315  for (VP1StdCollection* stdcol : l)
316  vt.insert(stdcol->collTypeID());
317  QList<qint32> vistypes = vt.values();
318  std::sort(vistypes.begin(), vistypes.end());
319  return vistypes;
320 
321 }
322 
323 //____________________________________________________________________
325 {
327 }
328 
329 //____________________________________________________________________
330 QList<VP1StdCollection*> VP1CollectionWidget::visibleStdCollections() const
331 {
332  QList<VP1StdCollection*> l;
333  for(VP1StdCollection* stdcol : collections<VP1StdCollection>()) {
334  if (stdcol->visible())
335  l << stdcol;
336  }
337  return l;
338 }
339 
340 //____________________________________________________________________
342 {
343  QList<VP1StdCollection*> visstdcols = visibleStdCollections();
344  QList<qint32> vistypes = m_d->visibleStdCollectionTypesFromVisStdCols(visstdcols);
345 
346  if ( m_d->last_visibleStdCollections != visstdcols ) {
347  m_d->last_visibleStdCollections = visstdcols;
348  visibleStdCollectionsChanged(visstdcols);
349  }
350 
351  if ( m_d->last_visibleStdCollectionTypes != vistypes ) {
354  }
355 
356 }
357 
358 
359 
360 //____________________________________________________________________
361 void VP1CollectionWidget::ensureFirst(const QString& wildcard,QList<QString>& strs)
362 {
363  QRegExp rx(wildcard,Qt::CaseInsensitive,QRegExp::Wildcard);
364  QList<QString> l;
365  for (QString str : strs)
366  if (rx.exactMatch(str))
367  l << str;
368  for (QString str : l)
369  strs.removeAll(str);
370  for (QString str : strs)
371  l << str;
372  strs = l;
373 
374 }
375 
376 //____________________________________________________________________
377 void VP1CollectionWidget::ensureLast(const QString& wildcard,QList<QString>& strs)
378 {
379  QRegExp rx(wildcard,Qt::CaseInsensitive,QRegExp::Wildcard);
380  QList<QString> l;
381  for(QString str : strs)
382  if (rx.exactMatch(str))
383  l << str;
384  for (QString str : l)
385  strs.removeAll(str);
386  strs << l;
387 }
VP1CollectionWidget::Imp::last_visibleStdCollectionTypes
QList< qint32 > last_visibleStdCollectionTypes
Definition: VP1CollectionWidget.cxx:38
VP1CollStates
QMap< QByteArray, QByteArray > VP1CollStates
Definition: VP1Collection.h:27
VP1CollectionWidget::Imp
Definition: VP1CollectionWidget.cxx:29
VP1CollectionWidget::Imp::Imp
Imp(VP1CollectionWidget *tc)
Definition: VP1CollectionWidget.cxx:31
VP1CollectionWidget::visibleStdCollectionsChanged
void visibleStdCollectionsChanged(const QList< VP1StdCollection * > &)
VP1CollectionWidget::addCollections
void addCollections(QList< VP1Collection * >, bool applySavedStates=true)
Definition: VP1CollectionWidget.cxx:237
VP1CollectionWidget::Imp::updateStatesWithCurrentInfo
void updateStatesWithCurrentInfo()
Definition: VP1CollectionWidget.cxx:282
VP1MaterialButton.h
VP1Msg.h
VP1MaterialButton
Definition: VP1MaterialButton.h:46
VP1HelperClassBase::messageVerbose
void messageVerbose(const QString &) const
Definition: VP1HelperClassBase.cxx:78
VP1CollectionWidget::Imp::states
VP1CollStates states
Definition: VP1CollectionWidget.cxx:37
fillPileUpNoiseLumi.connect
string connect
Definition: fillPileUpNoiseLumi.py:70
CSV_InDetExporter.new
new
Definition: CSV_InDetExporter.py:145
VP1CollectionWidget::VP1CollectionWidget
VP1CollectionWidget(QWidget *parent=0)
Definition: VP1CollectionWidget.cxx:49
VP1Collection::updateStates
static void updateStates(VP1CollStates &state, const VP1CollStates &newInfo)
Definition: VP1Collection.cxx:118
skel.it
it
Definition: skel.GENtoEVGEN.py:396
UploadAMITag.l
list l
Definition: UploadAMITag.larcaf.py:158
VP1CollectionWidget::clear
void clear(bool deleteCollections=true, bool deleteGuiElements=false)
Definition: VP1CollectionWidget.cxx:81
VP1Collection::getStates
static VP1CollStates getStates(QList< VP1Collection * >)
Definition: VP1Collection.cxx:92
VP1String::str
static QString str(const QString &s)
Definition: VP1String.h:49
VP1CollectionWidget::setCollections
void setCollections(QList< VP1Collection * >, bool applySavedStates=true)
Definition: VP1CollectionWidget.cxx:258
VP1CollectionWidget::Imp::repopulateGUIFromCollections
void repopulateGUIFromCollections()
Definition: VP1CollectionWidget.cxx:101
VP1CollectionWidget.h
VP1CollectionWidget::Imp::visibleStdCollectionTypesFromVisStdCols
QList< qint32 > visibleStdCollectionTypesFromVisStdCols(const QList< VP1StdCollection * > &l) const
Definition: VP1CollectionWidget.cxx:312
HitType::wildcard
@ wildcard
VP1CollectionWidget::ensureLast
static void ensureLast(const QString &wildcard, QList< QString > &)
Definition: VP1CollectionWidget.cxx:377
beamspotnt.cols
list cols
Definition: bin/beamspotnt.py:1114
VP1CollectionWidget::addStateInfo
void addStateInfo(const VP1CollStates &, bool overwritesExisting=true)
Definition: VP1CollectionWidget.cxx:289
VP1CollectionWidget::visibleStdCollectionTypes
QList< qint32 > visibleStdCollectionTypes() const
Definition: VP1CollectionWidget.cxx:324
lumiFormat.i
int i
Definition: lumiFormat.py:85
VP1CollectionWidget::possibleChange_visibleStdCollections
void possibleChange_visibleStdCollections()
Definition: VP1CollectionWidget.cxx:341
VP1CollectionWidget::~VP1CollectionWidget
virtual ~VP1CollectionWidget()
Definition: VP1CollectionWidget.cxx:55
test_pyathena.parent
parent
Definition: test_pyathena.py:15
VP1CollectionWidget::states
VP1CollStates states() const
Definition: VP1CollectionWidget.cxx:304
VP1CollectionWidget::Imp::clearGui
void clearGui(bool deleteGuiElements)
Definition: VP1CollectionWidget.cxx:67
hist_file_dump.f
f
Definition: hist_file_dump.py:135
VP1CollectionWidget::collections
QList< VP1Collection * > collections() const
Definition: VP1CollectionWidget.cxx:61
VP1Collection::applyStates
static void applyStates(QList< VP1Collection * >, const VP1CollStates &)
Definition: VP1Collection.cxx:108
VP1CollectionWidget::appropriateFixedWidth
int appropriateFixedWidth() const
Definition: VP1CollectionWidget.cxx:276
VP1CollectionWidget::m_d
Imp * m_d
Definition: VP1CollectionWidget.h:102
VP1HelperClassBase
Definition: VP1HelperClassBase.h:28
VP1Collection
Definition: VP1Collection.h:31
VP1CollectionWidget::Imp::appropriateFixedWidth
int appropriateFixedWidth
Definition: VP1CollectionWidget.cxx:34
VP1CollectionWidget::Imp::theclass
VP1CollectionWidget * theclass
Definition: VP1CollectionWidget.cxx:32
VP1CollectionWidget::visibleStdCollections
QList< VP1StdCollection * > visibleStdCollections() const
Definition: VP1CollectionWidget.cxx:330
validateBDTTau.vt
vt
Definition: validateBDTTau.py:43
query_example.col
col
Definition: query_example.py:7
VP1Msg::messageDebug
static void messageDebug(const QString &)
Definition: VP1Msg.cxx:39
VP1CollectionWidget
Definition: VP1CollectionWidget.h:32
TRT_PAI_physicsConstants::mb
const double mb
1mb to cm2
Definition: TRT_PAI_physicsConstants.h:15
VP1CollectionWidget::ensureFirst
static void ensureFirst(const QString &wildcard, QList< QString > &)
Definition: VP1CollectionWidget.cxx:361
VP1CollectionWidget::Imp::widgetsFromCollections
QList< QWidget * > widgetsFromCollections
Definition: VP1CollectionWidget.cxx:35
VP1CollectionWidget::Imp::collWidget
QWidget * collWidget
Definition: VP1CollectionWidget.cxx:33
str
Definition: BTagTrackIpAccessor.cxx:11
top
@ top
Definition: TruthClasses.h:64
VP1StdCollection
Definition: VP1StdCollection.h:31
python.IoTestsLib.w
def w
Definition: IoTestsLib.py:200
section
void section(const std::string &sec)
Definition: TestTriggerMenuAccess.cxx:22
VP1StdCollection.h
VP1CollectionWidget::visibleContentsChanged
void visibleContentsChanged()
VP1CollectionWidget::visibleStdCollectionTypesChanged
void visibleStdCollectionTypesChanged(const QList< qint32 > &)
VP1CollectionWidget::Imp::last_visibleStdCollections
QList< VP1StdCollection * > last_visibleStdCollections
Definition: VP1CollectionWidget.cxx:39
VP1CollectionWidget::Imp::collections
QList< VP1Collection * > collections
Definition: VP1CollectionWidget.cxx:36