Skip to content
Snippets Groups Projects
Commit 8b11741c authored by t.knopff's avatar t.knopff
Browse files

More elegant implementation of the change communication regarding instrument view

parent 1d9ea98e
No related branches found
No related tags found
1 merge request!392Overhaul ui: job list
...@@ -131,8 +131,6 @@ void InstrumentEditor::setItem(InstrumentItem* item) ...@@ -131,8 +131,6 @@ void InstrumentEditor::setItem(InstrumentItem* item)
void InstrumentEditor::onInstrumentNameChanged() void InstrumentEditor::onInstrumentNameChanged()
{ {
if (m_item) { if (m_item)
m_item->setItemName(m_nameLineEdit->text()); m_item->setItemName(m_nameLineEdit->text());
emit instrumentNameChanged();
}
} }
...@@ -40,9 +40,6 @@ public: ...@@ -40,9 +40,6 @@ public:
void setItem(InstrumentItem* instrument); void setItem(InstrumentItem* instrument);
signals:
void instrumentNameChanged();
private slots: private slots:
void onInstrumentNameChanged(); void onInstrumentNameChanged();
......
...@@ -66,6 +66,15 @@ InstrumentListModel::InstrumentListModel(InstrumentModel* instruments, QObject* ...@@ -66,6 +66,15 @@ InstrumentListModel::InstrumentListModel(InstrumentModel* instruments, QObject*
m_specularIcon.addPixmap(QPixmap(":/images/specular_instrument_shaded.svg"), QIcon::Normal); m_specularIcon.addPixmap(QPixmap(":/images/specular_instrument_shaded.svg"), QIcon::Normal);
m_depthProbeIcon.addPixmap(QPixmap(":/images/depth_instrument.svg"), QIcon::Selected); m_depthProbeIcon.addPixmap(QPixmap(":/images/depth_instrument.svg"), QIcon::Selected);
m_depthProbeIcon.addPixmap(QPixmap(":/images/depth_instrument_shaded.svg"), QIcon::Normal); m_depthProbeIcon.addPixmap(QPixmap(":/images/depth_instrument_shaded.svg"), QIcon::Normal);
for (InstrumentItem* instrument : m_instruments->instrumentItems())
attachToInstrument(instrument);
}
InstrumentListModel::~InstrumentListModel()
{
for (InstrumentItem* instrument : m_instruments->instrumentItems())
detachFromInstrument(instrument);
} }
int InstrumentListModel::rowCount(const QModelIndex&) const int InstrumentListModel::rowCount(const QModelIndex&) const
...@@ -129,7 +138,9 @@ QModelIndex InstrumentListModel::addNewDepthProbeInstrument() ...@@ -129,7 +138,9 @@ QModelIndex InstrumentListModel::addNewDepthProbeInstrument()
void InstrumentListModel::removeInstrument(const QModelIndex& index) void InstrumentListModel::removeInstrument(const QModelIndex& index)
{ {
beginRemoveRows(QModelIndex(), index.row(), index.row()); beginRemoveRows(QModelIndex(), index.row(), index.row());
m_instruments->removeInstrument(instrumentForIndex(index)); InstrumentItem* instrument = instrumentForIndex(index);
detachFromInstrument(instrument);
m_instruments->removeInstrument(instrument);
endRemoveRows(); endRemoveRows();
} }
...@@ -149,6 +160,7 @@ QModelIndex InstrumentListModel::copyInstrument(const InstrumentItem* source) ...@@ -149,6 +160,7 @@ QModelIndex InstrumentListModel::copyInstrument(const InstrumentItem* source)
beginInsertRows(QModelIndex(), row, row); beginInsertRows(QModelIndex(), row, row);
InstrumentItem* copy = m_instruments->insertCopy(*source); InstrumentItem* copy = m_instruments->insertCopy(*source);
copy->setItemName(copyName); copy->setItemName(copyName);
attachToInstrument(copy);
endInsertRows(); endInsertRows();
return m_instruments->indexOfItem(copy); return m_instruments->indexOfItem(copy);
...@@ -166,7 +178,31 @@ template <class Instrument> QModelIndex InstrumentListModel::addNewInstrument() ...@@ -166,7 +178,31 @@ template <class Instrument> QModelIndex InstrumentListModel::addNewInstrument()
beginInsertRows(QModelIndex(), row, row); beginInsertRows(QModelIndex(), row, row);
Instrument* instrument = m_instruments->insertItem<Instrument>(); Instrument* instrument = m_instruments->insertItem<Instrument>();
instrument->setItemName(name); instrument->setItemName(name);
attachToInstrument(instrument);
endInsertRows(); endInsertRows();
return m_instruments->indexOfItem(instrument); return m_instruments->indexOfItem(instrument);
} }
void InstrumentListModel::attachToInstrument(InstrumentItem* instrument)
{
instrument->mapper()->setOnPropertyChange
(std::bind(&InstrumentListModel::notifyInstrumentPropertyChange, this, instrument,
std::placeholders::_1), this);
}
void InstrumentListModel::detachFromInstrument(InstrumentItem* instrument)
{
instrument->mapper()->unsubscribe(this);
}
void InstrumentListModel::notifyInstrumentPropertyChange(InstrumentItem* instrument,
const QString& property)
{
if (SessionItem::isItemNamePropertyName(property)) {
QVector<InstrumentItem*> instruments = m_instruments->instrumentItems();
int i = instruments.indexOf(instrument);
if (i != -1)
emit dataChanged(index(i,0),index(i,0));
}
}
...@@ -26,6 +26,7 @@ class InstrumentListModel : public QAbstractListModel { ...@@ -26,6 +26,7 @@ class InstrumentListModel : public QAbstractListModel {
public: public:
InstrumentListModel(InstrumentModel* instruments, QObject* parent = nullptr); InstrumentListModel(InstrumentModel* instruments, QObject* parent = nullptr);
~InstrumentListModel();
virtual int rowCount(const QModelIndex& parent = QModelIndex()) const override; virtual int rowCount(const QModelIndex& parent = QModelIndex()) const override;
...@@ -50,6 +51,10 @@ public: ...@@ -50,6 +51,10 @@ public:
private: private:
template <class Instrument> QModelIndex addNewInstrument(); template <class Instrument> QModelIndex addNewInstrument();
void attachToInstrument(InstrumentItem* item);
void detachFromInstrument(InstrumentItem* item);
void notifyInstrumentPropertyChange(InstrumentItem* instrument, const QString& property);
private: private:
InstrumentModel* m_instruments; InstrumentModel* m_instruments;
......
...@@ -146,11 +146,6 @@ QList<QAction*> InstrumentListView::toolbarActions() const ...@@ -146,11 +146,6 @@ QList<QAction*> InstrumentListView::toolbarActions() const
m_loadFromLibraryAction}; m_loadFromLibraryAction};
} }
void InstrumentListView::updateSelectedInstrument()
{
update();
}
void InstrumentListView::onItemSelectionChanged() void InstrumentListView::onItemSelectionChanged()
{ {
updateActions(); updateActions();
......
...@@ -41,9 +41,6 @@ public: ...@@ -41,9 +41,6 @@ public:
signals: signals:
void instrumentSelected(InstrumentItem* instrument); void instrumentSelected(InstrumentItem* instrument);
public slots:
void updateSelectedInstrument();
private slots: private slots:
void onItemSelectionChanged(); void onItemSelectionChanged();
void onNewGisas(); void onNewGisas();
......
...@@ -44,9 +44,6 @@ InstrumentView::InstrumentView(QWidget* parent, ProjectDocument* document) ...@@ -44,9 +44,6 @@ InstrumentView::InstrumentView(QWidget* parent, ProjectDocument* document)
connect(m_instrumentListView, &InstrumentListView::instrumentSelected, this, connect(m_instrumentListView, &InstrumentListView::instrumentSelected, this,
&InstrumentView::onInstrumentSelected); &InstrumentView::onInstrumentSelected);
connect(m_instrumentEditor, &InstrumentEditor::instrumentNameChanged, m_instrumentListView,
&InstrumentListView::updateSelectedInstrument);
onInstrumentSelected(nullptr); onInstrumentSelected(nullptr);
} }
......
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