diff --git a/GUI/View/Instrument/InstrumentsTreeModel.cpp b/GUI/View/Instrument/InstrumentsTreeModel.cpp index 521c324704ed3b8a58f2c96d39b450f472458ca4..994c6c282ffd5290c82772b3f55092ae91357e13 100644 --- a/GUI/View/Instrument/InstrumentsTreeModel.cpp +++ b/GUI/View/Instrument/InstrumentsTreeModel.cpp @@ -232,45 +232,6 @@ InstrumentsTreeModel::InstrumentType InstrumentsTreeModel::instrumentType(Instru } QVariant InstrumentsTreeModel::data(const QModelIndex& index, int role) const -{ - if (isHeadline(index)) - return data2(index, role); - - auto* const item = itemForIndex(index); - - if (role == Qt::DisplayRole) { - auto descr = item->description(); - if (!descr.isEmpty()) { - descr.prepend("<br><br>"); - // max 4 lines - while (descr.count("\n") > 3) { - descr.truncate(descr.lastIndexOf("\n")); - descr += " [...]"; - } - descr.replace("\n", "<br>"); - } - return "<b>" + item->instrumentName() + "</b>" + descr; - } - - if (role == Qt::DecorationRole && (item == m_newInstrument)) { - if (role == Qt::DecorationRole) - switch (instrumentType(item)) { - case Gisas: - return QIcon(":/images/gisas_instrument_new.svg"); - case Offspec: - return QIcon(":/images/offspec_instrument_new.svg"); - case Specular: - return QIcon(":/images/specular_instrument_new.svg"); - case Depthprobe: - return QIcon(":/images/depth_instrument_new.svg"); - default: - break; - } - } - return data2(index, role); -} - -QVariant InstrumentsTreeModel::data2(const QModelIndex& index, int role) const { if (isHeadline(index)) { QString title; @@ -311,13 +272,42 @@ QVariant InstrumentsTreeModel::data2(const QModelIndex& index, int role) const case Qt::ForegroundRole: return qApp->palette().color(QPalette::Text); - default: - return {}; } + return {}; } auto* const item = itemForIndex(index); + if (role == Qt::DisplayRole) { + auto descr = item->description(); + if (!descr.isEmpty()) { + descr.prepend("<br><br>"); + // max 4 lines + while (descr.count("\n") > 3) { + descr.truncate(descr.lastIndexOf("\n")); + descr += " [...]"; + } + descr.replace("\n", "<br>"); + } + return "<b>" + item->instrumentName() + "</b>" + descr; + } + + if (role == Qt::DecorationRole && (item == m_newInstrument)) { + if (role == Qt::DecorationRole) + switch (instrumentType(item)) { + case Gisas: + return QIcon(":/images/gisas_instrument_new.svg"); + case Offspec: + return QIcon(":/images/offspec_instrument_new.svg"); + case Specular: + return QIcon(":/images/specular_instrument_new.svg"); + case Depthprobe: + return QIcon(":/images/depth_instrument_new.svg"); + default: + break; + } + } + if (role == Qt::ToolTipRole) return item->description(); diff --git a/GUI/View/Instrument/InstrumentsTreeModel.h b/GUI/View/Instrument/InstrumentsTreeModel.h index 20609d02d32f2caad490877c2e9dfe9ed3360d72..522561ef4f32748152182be4672582fed2f47f3c 100644 --- a/GUI/View/Instrument/InstrumentsTreeModel.h +++ b/GUI/View/Instrument/InstrumentsTreeModel.h @@ -48,7 +48,6 @@ public: int columnCount(const QModelIndex& parent = QModelIndex()) const override; int rowCount(const QModelIndex& parent = QModelIndex()) const override; QVariant data(const QModelIndex& index, int role) const override; - QVariant data2(const QModelIndex& index, int role = Qt::DisplayRole) const; Qt::ItemFlags flags(const QModelIndex& index) const override; bool setData(const QModelIndex& index, const QVariant& value, int role) override; InstrumentItem* itemForIndex(const QModelIndex& index) const;