ATLAS Offline Software
Loading...
Searching...
No Matches
VolumeTreeModel Class Reference

#include <VolumeTreeModel.h>

Inheritance diagram for VolumeTreeModel:
Collaboration diagram for VolumeTreeModel:

Classes

class  Imp

Public Member Functions

 VolumeTreeModel (QObject *parent=0)
virtual ~VolumeTreeModel ()
void addSubSystem (VP1GeoFlags::SubSystemFlag flag, const VolumeHandle::VolumeHandleList &roothandles)
void enableSubSystem (VP1GeoFlags::SubSystemFlag flag)
void disableSubSystem (VP1GeoFlags::SubSystemFlag flag)
void getRootHandles (std::vector< std::pair< VolumeHandle::VolumeHandleListItr, VolumeHandle::VolumeHandleListItr > > &) const
QModelIndex index (int, int, const QModelIndex &) const
QModelIndex parent (const QModelIndex &) const
int rowCount (const QModelIndex &) const
int columnCount (const QModelIndex &idx) const
QVariant data (const QModelIndex &, int) const
Qt::ItemFlags flags (const QModelIndex &index) const
QVariant headerData (int section, Qt::Orientation orientation, int role) const
bool hasChildren (const QModelIndex &parent=QModelIndex()) const
bool canFetchMore (const QModelIndex &parent) const
void fetchMore (const QModelIndex &parent)
void cleanup ()

Private Attributes

Impm_d

Detailed Description

Definition at line 14 of file VolumeTreeModel.h.

Constructor & Destructor Documentation

◆ VolumeTreeModel()

VolumeTreeModel::VolumeTreeModel ( QObject * parent = 0)

Definition at line 103 of file VolumeTreeModel.cxx.

104 : QAbstractItemModel(parent), m_d(new Imp())
105{
108 Imp::section2string[Imp::INDET] = "Inner Detector";
109 Imp::section2string[Imp::CALO] = "Calorimeters";
110 Imp::section2string[Imp::MUON] = "Muon Spectrometer";
111 Imp::section2string[Imp::MISC] = "Miscellaneous";
112 }
115 // Inner Detector
122 //HGTD
124 // Calorimeters
127 //Toroids
131 // Structure
135 // Muon chambers
143 // Beam Pipe
145 // FWD detectors
149 // Cavern
151 }
152}
static const Attributes_t empty
@ MuonEndcapStationTGC
Definition VP1GeoFlags.h:47
@ MuonEndcapStationNSW
Definition VP1GeoFlags.h:65
@ MuonBarrelStationInner
Definition VP1GeoFlags.h:42
@ MuonBarrelStationMiddle
Definition VP1GeoFlags.h:44
@ MuonBarrelStationOuter
Definition VP1GeoFlags.h:45
@ MuonEndcapStationCSC
Definition VP1GeoFlags.h:46
@ MuonEndcapStationMDT
Definition VP1GeoFlags.h:49
static void defineSubSystem(VP1GeoFlags::SubSystemFlag, QString, SECTION)
static std::map< SECTION, QString > section2string
static std::map< VP1GeoFlags::SubSystemFlag, SECTION > subsysflag2section
QModelIndex parent(const QModelIndex &) const

◆ ~VolumeTreeModel()

VolumeTreeModel::~VolumeTreeModel ( )
virtual

Definition at line 168 of file VolumeTreeModel.cxx.

169{
170 delete m_d;
171}

Member Function Documentation

◆ addSubSystem()

void VolumeTreeModel::addSubSystem ( VP1GeoFlags::SubSystemFlag flag,
const VolumeHandle::VolumeHandleList & roothandles )

Definition at line 174 of file VolumeTreeModel.cxx.

176{
177 //NB: This method does not need to be super-fast, thus we do a lot
178 //of not-so-fast iterations over maps/lists rather than keep extra
179 //maps/lists around.
180
181 //Check whether we added this subsystem already:
182 bool found(false);
183 for(Imp::SectionInfo* section : m_d->allSections) {
184 for(Imp::SubSystem* subsys : (section->enabledSubSystems+section->disabledSubSystems)) {
185 if (subsys->subsysflag==flag) {
186 found=true;
187 break;
188 }
189 }
190 }
191
192 if (found) {
193 std::cout<<"VolumeTreeModel::addSubSystem Error: System has already been added!"<<std::endl;
194 return;
195 }
196
197 //Determine section flag:
198 Imp::SECTION sectionflag;
200 std::cout<<"VolumeTreeModel::addSubSystem Error: Unknown system flag! Please update the code!"<<std::endl;
201 sectionflag=Imp::UNKNOWN;
202 } else {
203 sectionflag=Imp::subsysflag2section[flag];
204 }
205
206 //Find the section belonging to the system (create a new one if
207 //needed - i.e. if this is the first subsystem in a given section):
209 found = false;
210 for(Imp::SectionInfo* sec : m_d->allSections) {
211 if (sec->sectionflag==sectionflag) {
212 //std::cout << "added section: " << sec->sectionflag << std::endl;
213 section = sec;
214 break;
215 }
216 }
217
218 if (!section) {
219 section = new Imp::SectionInfo(sectionflag);
220 //section->sectionflag = sectionflag;
222 section->name = "Unknown Section Flag";
223 else
224 section->name = Imp::section2string[sectionflag];
225 m_d->allSections<<section;
226 //We dont add it to m_d->activeSections since the subsystem (and
227 //thus the section since it has no other subsystems) is considered
228 //disabled until enabled by a call to enableSubSystem().
229 }
230
231 //Create SubSystem instance for this subsystem and give it the roothandles:
232 Imp::SubSystem * subsys = new Imp::SubSystem(section,flag);
233 //subsys->section = section;
234 //subsys->subsysflag = flag;
236 subsys->name = "Unknown subsystem flag";
237 else
238 subsys->name = Imp::subsysflag2string[flag];
239 subsys->volhandlelist = roothandles;
240
241 //Add the subsystem pointer to the relevant maps:
242 section->disabledSubSystems << subsys;
243 m_d->flag2subsystems[flag]=subsys;
244}
void section(const std::string &sec)
static std::map< VP1GeoFlags::SubSystemFlag, QString > subsysflag2string
std::string find(const std::string &s)
return a remapped string
Definition hcg.cxx:140
bool flag
Definition master.py:29

◆ canFetchMore()

bool VolumeTreeModel::canFetchMore ( const QModelIndex & parent) const

Definition at line 498 of file VolumeTreeModel.cxx.

499{
500 if (!parent.isValid())
501 return false;
502
503 VolumeHandle * parentHandle = Imp::handlePointer(parent);
504
505 if (Imp::isRegularVolumeHandle(parentHandle)&&!parentHandle->childrenAreInitialised())
506 return true;
507
508 return false;
509}
bool childrenAreInitialised() const
static VolumeHandle * handlePointer(const QModelIndex &idx)
static bool isRegularVolumeHandle(VolumeHandle *handle)

◆ cleanup()

void VolumeTreeModel::cleanup ( )

Definition at line 155 of file VolumeTreeModel.cxx.

156{
157 //This is where we delete all SectionInfo/SubSystem pointers (and thus also all VolumeHandles):
158 std::map<VP1GeoFlags::SubSystemFlag,Imp::SubSystem*>::iterator it, itE = m_d->flag2subsystems.end();
159 for (it = m_d->flag2subsystems.begin();it!=itE;++it)
160 disableSubSystem(it->first);
161 for (it = m_d->flag2subsystems.begin();it!=itE;++it)
162 delete it->second;
163 for (Imp::SectionInfo* section : m_d->allSections)
164 delete section;
165}
void disableSubSystem(VP1GeoFlags::SubSystemFlag flag)

◆ columnCount()

int VolumeTreeModel::columnCount ( const QModelIndex & idx) const
inline

Definition at line 35 of file VolumeTreeModel.h.

35{ return rowCount(idx) > 0 ? 1 : 0; }
int rowCount(const QModelIndex &) const

◆ data()

QVariant VolumeTreeModel::data ( const QModelIndex & index,
int role ) const

Definition at line 448 of file VolumeTreeModel.cxx.

449{
450 if ((role!=Qt::DisplayRole&&role!=Qt::ForegroundRole)||!index.isValid())
451 return QVariant();
452
453 VolumeHandle *volumeHandle = Imp::handlePointer(index);
454 if (Imp::isRegularVolumeHandle(volumeHandle)) {
455 if (role==Qt::ForegroundRole) {
456 if (volumeHandle->isAttached())
457 return QVariant();
458 else
459 return QColor::fromRgbF( 0.5, 0.5, 0.5 );
460 }
461 //DisplayRole:
462 if (volumeHandle->nChildren()>1)
463 return volumeHandle->getName()+" ["+QString::number(volumeHandle->nChildren())+"]";
464 else
465 return volumeHandle->getName();
466 }
467
468 if (role==Qt::ForegroundRole)
469 return QVariant();
470
471 if (Imp::isSubSystemPointer(volumeHandle))
472 return Imp::subSystemPointer(volumeHandle)->name;
473
474 Q_ASSERT(Imp::isSectionInfoPointer(volumeHandle));
475 return Imp::sectionInfoPointer(volumeHandle)->name;
476}
QString getName() const
bool isAttached() const
unsigned nChildren() const
static SubSystem * subSystemPointer(VolumeHandle *handle)
static bool isSectionInfoPointer(VolumeHandle *handle)
static SectionInfo * sectionInfoPointer(VolumeHandle *handle)
static bool isSubSystemPointer(VolumeHandle *handle)
QModelIndex index(int, int, const QModelIndex &) const

◆ disableSubSystem()

void VolumeTreeModel::disableSubSystem ( VP1GeoFlags::SubSystemFlag flag)

Definition at line 294 of file VolumeTreeModel.cxx.

295{
296 beginResetModel(); // see: http://doc.qt.io/qt-5/qabstractitemmodel-obsolete.html
297
298 //If it was not even added previously we can just return:
299 if (m_d->flag2subsystems.find(flag)==m_d->flag2subsystems.end())
300 return;
301
302 Imp::SubSystem * subsys = m_d->flag2subsystems[flag];
303 //Find the appropriate section:
305 for(Imp::SectionInfo* sec : m_d->allSections) {
306 if (sec->disabledSubSystems.contains(subsys)) {
307 //It is already disabled
308 assert(!sec->enabledSubSystems.contains(subsys));
309 return;
310 }
311 if (sec->enabledSubSystems.contains(subsys)) {
312 assert(!sec->disabledSubSystems.contains(subsys));
313 section=sec;
314 break;
315 }
316 }
317 assert(section);
318 if (!section) {
319 std::cout<<"VolumeTreeModel::disableSubSystem Error: Did not find section of subsystem!."<<std::endl;
320 return;
321 }
322
323 //Move the subsystem from the enabled to the disabled list:
324 section->disabledSubSystems << subsys;
325 section->enabledSubSystems.removeAll(subsys);
326 //If the newly disabled subsystem was the only enabled subsystem, the section needs to be disabled as well:
327 if (section->enabledSubSystems.count()==0) {
328 assert(m_d->activeSections.contains(section));
329 m_d->activeSections.removeAll(section);
330 }
331
332 //Remove volume handle pointers from quick subsystem access map:
333 for (VolumeHandle* volhandle : subsys->volhandlelist ) {
334 Q_ASSERT(m_d->volhandle2subsystem.find(volhandle)!=m_d->volhandle2subsystem.end());
335 m_d->volhandle2subsystem.erase(m_d->volhandle2subsystem.find(volhandle));
336 }
337
338 endResetModel();
339// reset();//Fixme: use proper insert rows/colums/etc. instead!
340}

◆ enableSubSystem()

void VolumeTreeModel::enableSubSystem ( VP1GeoFlags::SubSystemFlag flag)

Definition at line 247 of file VolumeTreeModel.cxx.

248{
249 beginResetModel(); // see: http://doc.qt.io/qt-5/qabstractitemmodel-obsolete.html
250
251 //Check the subsystem was added previously:
252 if (m_d->flag2subsystems.find(flag)==m_d->flag2subsystems.end()) {
253 std::cout<<"VolumeTreeModel::enableSubSystem Error: System never added!"<<std::endl;
254 return;
255 }
256 Imp::SubSystem * subsys = m_d->flag2subsystems[flag];
257 //Find the appropriate section:
259 for(Imp::SectionInfo* sec : m_d->allSections) {
260 if (sec->enabledSubSystems.contains(subsys)) {
261 //It is already enabled
262 assert(!sec->disabledSubSystems.contains(subsys));
263 return;
264 }
265 if (sec->disabledSubSystems.contains(subsys)) {
266 assert(!sec->enabledSubSystems.contains(subsys));
267 section=sec;
268 break;
269 }
270 }
271 assert(section);
272 if (!section) {
273 std::cout<<"VolumeTreeModel::enableSubSystem Error: Did not find section of subsystem!."<<std::endl;
274 return;
275 }
276 //Move the subsystem from the disabled to the enabled list:
277 section->enabledSubSystems << subsys;//Fixme: Ordering.
278 section->disabledSubSystems.removeAll(subsys);
279 //If the newly added subsystem is the only enabled subsystem, the section needs to be enabled as well:
280 if (section->enabledSubSystems.count()==1) {
281 assert(!m_d->activeSections.contains(section));
282 m_d->activeSections << section;//Fixme: Ordering.
283 }
284 //Put volume handle pointers into quick subsystem access map:
285 for (VolumeHandle* volhandle : subsys->volhandlelist ) {
286 m_d->volhandle2subsystem[volhandle] = subsys;
287 }
288
289 endResetModel();
290
291}

◆ fetchMore()

void VolumeTreeModel::fetchMore ( const QModelIndex & parent)

Definition at line 512 of file VolumeTreeModel.cxx.

513{
514 if (!parent.isValid())
515 return;//should probably never happen
516
517 VolumeHandle* parentHandle = Imp::handlePointer(parent);
518
519 if (Imp::isRegularVolumeHandle(parentHandle)&&!parentHandle->childrenAreInitialised()) {
520 // beginInsertRows(parent,0,int(parentHandle->nChildren())-1);
521 parentHandle->initialiseChildren();
522 layoutChanged();//fixme??
523 // endInsertRows();
524 return;
525 }
526}
void initialiseChildren()

◆ flags()

Qt::ItemFlags VolumeTreeModel::flags ( const QModelIndex & index) const

Definition at line 480 of file VolumeTreeModel.cxx.

481{
482 if (!index.isValid())
483 return Qt::ItemFlags();
484
486 return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
487 else
488 return Qt::ItemIsEnabled;
489}

◆ getRootHandles()

void VolumeTreeModel::getRootHandles ( std::vector< std::pair< VolumeHandle::VolumeHandleListItr, VolumeHandle::VolumeHandleListItr > > & out) const

Definition at line 343 of file VolumeTreeModel.cxx.

344{
345 out.clear();
346 out.reserve(m_d->flag2subsystems.size());
347 std::map<VP1GeoFlags::SubSystemFlag,Imp::SubSystem*>::iterator it, itE = m_d->flag2subsystems.end();
348 for (it = m_d->flag2subsystems.begin();it!=itE;++it)
349 out.push_back(std::pair<VolumeHandle::VolumeHandleListItr,VolumeHandle::VolumeHandleListItr>
350 (it->second->volhandlelist.begin(),it->second->volhandlelist.end()));
351
352}

◆ hasChildren()

bool VolumeTreeModel::hasChildren ( const QModelIndex & parent = QModelIndex()) const

Definition at line 529 of file VolumeTreeModel.cxx.

530{
531 return rowCount(parent)>0;//Our rowCount is relatively fast (no looping to count).
532}

◆ headerData()

QVariant VolumeTreeModel::headerData ( int section,
Qt::Orientation orientation,
int role ) const

Definition at line 492 of file VolumeTreeModel.cxx.

493{
494 return QVariant();
495}

◆ index()

QModelIndex VolumeTreeModel::index ( int row,
int column,
const QModelIndex & parent ) const

Definition at line 355 of file VolumeTreeModel.cxx.

356{
357 //Check that row and column are in allowed ranges (positive and within row/column count of parent):
358 if (!hasIndex(row, column, parent))
359 return QModelIndex();
360
361 if (!parent.isValid()) {
362 //We must return the index of a section label:
363 Q_ASSERT(row<m_d->activeSections.count());
364 return createIndex(row, column, m_d->activeSections.at(row));
365 }
366
367 VolumeHandle * parentHandle = Imp::handlePointer(parent);
368
369 if (Imp::isRegularVolumeHandle(parentHandle)) {
370 if (!parentHandle->childrenAreInitialised())
371 parentHandle->initialiseChildren();//Fixme: It seems that it is occasionally necessary to do this. Why?? Why not fetchMore??
372 VolumeHandle * childHandle = parentHandle->child(row);
373 Q_ASSERT(childHandle);
374 return createIndex(row, column, childHandle);
375 }
376
377 if (Imp::isSubSystemPointer(parentHandle)) {
378 //Return index of top-level volume:
379 Q_ASSERT(unsigned(row)<Imp::subSystemPointer(parentHandle)->volhandlelist.size());
380 return createIndex(row, column, Imp::subSystemPointer(parentHandle)->volhandlelist.at(row));
381 }
382
383 //Must be SectionInfo:
384 Q_ASSERT(Imp::isSectionInfoPointer(parentHandle));
385 Q_ASSERT(row<Imp::sectionInfoPointer(parentHandle)->enabledSubSystems.count());
386 return createIndex(row, column, Imp::sectionInfoPointer(parentHandle)->enabledSubSystems.at(row));
387}
VolumeHandle * child(int index) const

◆ parent()

QModelIndex VolumeTreeModel::parent ( const QModelIndex & index) const

Definition at line 390 of file VolumeTreeModel.cxx.

391{
392 if (!index.isValid())
393 return QModelIndex();
394
395 //See if we have a volumeHandle as index:
396 VolumeHandle *childHandle = Imp::handlePointer(index);
397
398 if (Imp::isRegularVolumeHandle(childHandle)) {
399 VolumeHandle *parentHandle = childHandle->parent();
400 if (parentHandle)
401 return createIndex(parentHandle->childNumber(), 0, parentHandle);
402
403 //childHandle has 0 parent pointer => parent must be a subsystem label:
404 Q_ASSERT(m_d->volhandle2subsystem.find(childHandle)!=m_d->volhandle2subsystem.end());
405 Imp::SubSystem * subsys = m_d->volhandle2subsystem[childHandle];
406 Q_ASSERT(subsys);
407 Q_ASSERT(subsys->section->enabledSubSystems.contains(subsys));
408 return createIndex(subsys->section->enabledSubSystems.indexOf(subsys), 0, subsys);
409 }
410
411
412 if (Imp::isSubSystemPointer(childHandle)) {
413 //Index is a SubSystem => parent must be a section label:
414 Q_ASSERT(m_d->activeSections.contains(Imp::subSystemPointer(childHandle)->section));
415 return createIndex(m_d->activeSections.indexOf(Imp::subSystemPointer(childHandle)->section), 0, Imp::subSystemPointer(childHandle)->section);
416 }
417
418 //Must be SectionInfo => parent is root (i.e. invalid):
419 Q_ASSERT(Imp::isSectionInfoPointer(childHandle));
420 return QModelIndex();
421}
VolumeHandle * parent()
int childNumber() const

◆ rowCount()

int VolumeTreeModel::rowCount ( const QModelIndex & parent) const

Definition at line 424 of file VolumeTreeModel.cxx.

425{
426 if (parent.column() > 0)
427 return 0;
428
429 if (!parent.isValid())
430 return m_d->activeSections.size();//Number of active sections
431
432 VolumeHandle * parentHandle = Imp::handlePointer(parent);
433
434 if (Imp::isRegularVolumeHandle(parentHandle)) {
435 return parentHandle->nChildren();
436 }
437
438 if (Imp::isSubSystemPointer(parentHandle)) {
439 return Imp::subSystemPointer(parentHandle)->volhandlelist.size();
440 }
441
442 //Must be SectionInfo pointer:
443 Q_ASSERT(Imp::isSectionInfoPointer(parentHandle));
444 return Imp::sectionInfoPointer(parentHandle)->enabledSubSystems.count();
445}
VolumeHandle::VolumeHandleList volhandlelist

Member Data Documentation

◆ m_d

Imp* VolumeTreeModel::m_d
private

Definition at line 47 of file VolumeTreeModel.h.


The documentation for this class was generated from the following files: