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 // Calorimeters
125 //Toroids
129 // Structure
133 // Muon chambers
141 // Beam Pipe
143 // FWD detectors
147 // Cavern
149 }
150}
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 166 of file VolumeTreeModel.cxx.

167{
168 delete m_d;
169}

Member Function Documentation

◆ addSubSystem()

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

Definition at line 172 of file VolumeTreeModel.cxx.

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

◆ canFetchMore()

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

Definition at line 496 of file VolumeTreeModel.cxx.

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

◆ cleanup()

void VolumeTreeModel::cleanup ( )

Definition at line 153 of file VolumeTreeModel.cxx.

154{
155 //This is where we delete all SectionInfo/SubSystem pointers (and thus also all VolumeHandles):
156 std::map<VP1GeoFlags::SubSystemFlag,Imp::SubSystem*>::iterator it, itE = m_d->flag2subsystems.end();
157 for (it = m_d->flag2subsystems.begin();it!=itE;++it)
158 disableSubSystem(it->first);
159 for (it = m_d->flag2subsystems.begin();it!=itE;++it)
160 delete it->second;
161 for (Imp::SectionInfo* section : m_d->allSections)
162 delete section;
163}
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 446 of file VolumeTreeModel.cxx.

447{
448 if ((role!=Qt::DisplayRole&&role!=Qt::ForegroundRole)||!index.isValid())
449 return QVariant();
450
451 VolumeHandle *volumeHandle = Imp::handlePointer(index);
452 if (Imp::isRegularVolumeHandle(volumeHandle)) {
453 if (role==Qt::ForegroundRole) {
454 if (volumeHandle->isAttached())
455 return QVariant();
456 else
457 return QColor::fromRgbF( 0.5, 0.5, 0.5 );
458 }
459 //DisplayRole:
460 if (volumeHandle->nChildren()>1)
461 return volumeHandle->getName()+" ["+QString::number(volumeHandle->nChildren())+"]";
462 else
463 return volumeHandle->getName();
464 }
465
466 if (role==Qt::ForegroundRole)
467 return QVariant();
468
469 if (Imp::isSubSystemPointer(volumeHandle))
470 return Imp::subSystemPointer(volumeHandle)->name;
471
472 Q_ASSERT(Imp::isSectionInfoPointer(volumeHandle));
473 return Imp::sectionInfoPointer(volumeHandle)->name;
474}
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 292 of file VolumeTreeModel.cxx.

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

◆ enableSubSystem()

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

Definition at line 245 of file VolumeTreeModel.cxx.

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

◆ fetchMore()

void VolumeTreeModel::fetchMore ( const QModelIndex & parent)

Definition at line 510 of file VolumeTreeModel.cxx.

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

◆ flags()

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

Definition at line 478 of file VolumeTreeModel.cxx.

479{
480 if (!index.isValid())
481 return Qt::ItemFlags();
482
484 return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
485 else
486 return Qt::ItemIsEnabled;
487}

◆ getRootHandles()

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

Definition at line 341 of file VolumeTreeModel.cxx.

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

◆ hasChildren()

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

Definition at line 527 of file VolumeTreeModel.cxx.

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

◆ headerData()

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

Definition at line 490 of file VolumeTreeModel.cxx.

491{
492 return QVariant();
493}

◆ index()

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

Definition at line 353 of file VolumeTreeModel.cxx.

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

◆ parent()

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

Definition at line 388 of file VolumeTreeModel.cxx.

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

◆ rowCount()

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

Definition at line 422 of file VolumeTreeModel.cxx.

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