From 2b02d015a2e5267bc88b2ee0d05b42a2267b928b Mon Sep 17 00:00:00 2001 From: "Joachim Wuttke (h)" <j.wuttke@fz-juelich.de> Date: Thu, 21 Dec 2023 13:44:33 +0100 Subject: [PATCH] merge data fcts --- GUI/View/Instrument/InstrumentsTreeModel.cpp | 72 +++++++++----------- GUI/View/Instrument/InstrumentsTreeModel.h | 1 - 2 files changed, 31 insertions(+), 42 deletions(-) diff --git a/GUI/View/Instrument/InstrumentsTreeModel.cpp b/GUI/View/Instrument/InstrumentsTreeModel.cpp index 521c324704e..994c6c282ff 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 20609d02d32..522561ef4f3 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; -- GitLab