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

merge data fcts

parent 823a90ab
No related branches found
No related tags found
1 merge request!2261merge local class TreeModel into parent class
Pipeline #124526 failed
......@@ -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();
......
......@@ -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;
......
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