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

mv to parent class

parent 6ba46a1f
No related branches found
No related tags found
1 merge request!2261merge local class TreeModel into parent class
......@@ -295,54 +295,3 @@ void InstrumentLibraryEditor::onInstrumentChangedByEditor()
auto* currentInstrument = m_treeModel->itemForIndex(m_treeView->currentIndex());
m_instrumentLibrary->editController()->notifyInstrumentChanged(currentInstrument);
}
/*********************************************************************************************/
TreeModel::TreeModel(QObject* parent, InstrumentModel* model)
: InstrumentsTreeModel(parent, model)
{
}
void TreeModel::setNewInstrument(InstrumentItem* addedInstrument)
{
m_newInstrument = addedInstrument;
}
QVariant TreeModel::data(const QModelIndex& index, int role) const
{
if (isHeadline(index))
return InstrumentsTreeModel::data(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 InstrumentsTreeModel::data(index, role);
}
......@@ -25,23 +25,6 @@
class InstrumentItem;
class InstrumentLibrary;
//! A model extension for InstrumentsTreeModel which
//! * shows a "NEW" sign in the icon of a newly added instrument.
//! * creates a HTML text for the Display role
class TreeModel : public InstrumentsTreeModel {
public:
TreeModel(QObject* parent, InstrumentModel* model);
//! Set the instrument which shall have a "NEW" sign in its icon
void setNewInstrument(InstrumentItem* addedInstrument);
QVariant data(const QModelIndex& index, int role) const override;
private:
InstrumentItem* m_newInstrument = nullptr;
};
class InstrumentLibraryEditor : public QDialog {
Q_OBJECT
public:
......
......@@ -303,3 +303,56 @@ InstrumentsTreeModel::InstrumentType InstrumentsTreeModel::instrumentType(Instru
ASSERT_NEVER;
return None;
}
/*********************************************************************************************/
TreeModel::TreeModel(QObject* parent, InstrumentModel* model)
: InstrumentsTreeModel(parent, model)
{
}
void TreeModel::setNewInstrument(InstrumentItem* addedInstrument)
{
m_newInstrument = addedInstrument;
}
QVariant TreeModel::data(const QModelIndex& index, int role) const
{
if (isHeadline(index))
return InstrumentsTreeModel::data(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 InstrumentsTreeModel::data(index, role);
}
......@@ -68,4 +68,20 @@ private:
bool m_enableEmptyHeadlines;
};
//! A model extension for InstrumentsTreeModel which
//! * shows a "NEW" sign in the icon of a newly added instrument.
//! * creates a HTML text for the Display role
class TreeModel : public InstrumentsTreeModel {
public:
TreeModel(QObject* parent, InstrumentModel* model);
//! Set the instrument which shall have a "NEW" sign in its icon
void setNewInstrument(InstrumentItem* addedInstrument);
QVariant data(const QModelIndex& index, int role) const override;
private:
InstrumentItem* m_newInstrument = nullptr;
};
#endif // BORNAGAIN_GUI_VIEW_INSTRUMENT_INSTRUMENTSTREEMODEL_H
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