Skip to content
Snippets Groups Projects
Commit 0ae683ae authored by Wuttke, Joachim's avatar Wuttke, Joachim
Browse files

follow-up InstrumentsTreeModel

parent 9f334634
No related branches found
No related tags found
1 merge request!2136rm single-instrument and single-sample mode; no need to disable some instrument tyes
......@@ -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);
......
......@@ -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;
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment