diff --git a/GUI/View/Instrument/InstrumentsTreeModel.cpp b/GUI/View/Instrument/InstrumentsTreeModel.cpp index 68003f4b8713ede5c68d3c688328e061958792ac..3d80f88f4318abd0306ce2fc24f90ef06aeddbe6 100644 --- a/GUI/View/Instrument/InstrumentsTreeModel.cpp +++ b/GUI/View/Instrument/InstrumentsTreeModel.cpp @@ -19,10 +19,17 @@ #include <QApplication> #include <QtGui> +namespace { + +using IType = InstrumentsTreeModel::InstrumentType; +const auto types = {IType::Gisas, IType::Offspec, IType::Specular, IType::Depthprobe}; + +} // namespace + + InstrumentsTreeModel::InstrumentsTreeModel(QObject* parent, InstrumentModel* model) : QAbstractItemModel(parent) , m_model(model) - , m_visibleTypes(All) , m_namesAreEditable(false) , m_enableEmptyHeadlines(true) { @@ -43,24 +50,6 @@ void InstrumentsTreeModel::clear() endResetModel(); } -QList<InstrumentsTreeModel::InstrumentType> InstrumentsTreeModel::visibleTypes() const -{ - QList<InstrumentsTreeModel::InstrumentType> result; - - const auto forType = [&](InstrumentType type) { - if (m_visibleTypes.testFlag(type) - && (m_enableEmptyHeadlines || !instrumentItemsOfType(type).isEmpty())) - result << type; - }; - - forType(Gisas); - forType(Offspec); - forType(Specular); - forType(Depthprobe); - - return result; -} - QVector<InstrumentItem*> InstrumentsTreeModel::instrumentItemsOfType(InstrumentType type) const { switch (type) { @@ -88,7 +77,7 @@ QVector<InstrumentItem*> InstrumentsTreeModel::instrumentItemsOfType(InstrumentT QModelIndex InstrumentsTreeModel::indexOfHeadline(InstrumentType type) const { int row = 0; - for (auto t : visibleTypes()) { + for (auto t : ::types) { if (t == type) return createIndex(row, 0, nullptr); row++; @@ -105,7 +94,7 @@ QModelIndex InstrumentsTreeModel::index(int row, int column, const QModelIndex& if (!parent.isValid()) return createIndex(row, column, nullptr); - for (auto type : visibleTypes()) + for (auto type : ::types) if (parent == indexOfHeadline(type)) return createIndex(row, column, instrumentItemsOfType(type)[row]); @@ -121,7 +110,7 @@ QModelIndex InstrumentsTreeModel::parent(const QModelIndex& index) const return QModelIndex(); auto* item = itemForIndex(index); - for (auto type : visibleTypes()) + for (auto type : ::types) if (instrumentItemsOfType(type).contains(item)) return indexOfHeadline(type); @@ -136,10 +125,10 @@ int InstrumentsTreeModel::columnCount(const QModelIndex& /*parent*/) const int InstrumentsTreeModel::rowCount(const QModelIndex& parent) const { if (!parent.isValid()) - return visibleTypes().size(); + return ::types.size(); // parent is a headline - for (auto type : visibleTypes()) + for (auto type : ::types) if (parent == indexOfHeadline(type)) return instrumentItemsOfType(type).size(); @@ -270,7 +259,7 @@ QModelIndex InstrumentsTreeModel::indexForItem(InstrumentItem* item) const if (item == nullptr) return QModelIndex(); - for (auto type : visibleTypes()) + for (auto type : ::types) if (auto row = instrumentItemsOfType(type).indexOf(item); row >= 0) return createIndex(row, 0, item); diff --git a/GUI/View/Instrument/InstrumentsTreeModel.h b/GUI/View/Instrument/InstrumentsTreeModel.h index a5d6bd26a91aa0c18114e7a389071bc13c74cd49..3ba2e85a5635ed27e8e94339cae2d2c1dbeddbf1 100644 --- a/GUI/View/Instrument/InstrumentsTreeModel.h +++ b/GUI/View/Instrument/InstrumentsTreeModel.h @@ -60,12 +60,10 @@ public: private: void clear(); - QList<InstrumentType> visibleTypes() const; QVector<InstrumentItem*> instrumentItemsOfType(InstrumentType type) const; private: InstrumentModel* m_model = nullptr; - VisibleInstrumentTypes m_visibleTypes; bool m_namesAreEditable; bool m_enableEmptyHeadlines; };