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

InstrumentView cleanly separate updateActions/Editor

parent 772d152e
No related branches found
No related tags found
1 merge request!2405Update instrument & sample lists after change of name or description
......@@ -65,8 +65,11 @@ InstrumentView::InstrumentView()
//... Finalize
connect(gDoc->instruments(), &InstrumentsSet::setChanged, this,
&InstrumentView::createWidgetsForCurrentInstrument);
connect(gDoc->instruments(), &InstrumentsSet::setChanged, [this]
{
updateEditor();
updateActions();
});
updateActions();
}
......@@ -131,18 +134,26 @@ void InstrumentView::updateActions()
m_save_action->setEnabled(enabled);
}
void InstrumentView::createWidgetsForCurrentInstrument()
void InstrumentView::updateEditor()
{
updateActions();
InstrumentItem* t = m_set->currentItem();
if (!t) {
m_scroll_area->setWidget(new QWidget(m_scroll_area)); // blank widget
return;
}
if (t == m_displayed_item)
return;
m_displayed_item = t;
if (!t)
delete m_scroll_area->takeWidget();
else
m_scroll_area->setWidget(createEditor(t));
}
auto* w = new QWidget(m_scroll_area);
auto* layout = new QVBoxLayout(w);
QWidget* InstrumentView::createEditor(InstrumentItem* t)
{
auto* result = new QWidget(m_scroll_area);
if (!t)
return result; // blank widget
auto* layout = new QVBoxLayout(result);
//... Groupbox with instrument name and description (same layout for all instrument types)
......@@ -189,5 +200,6 @@ void InstrumentView::createWidgetsForCurrentInstrument()
ASSERT_NEVER;
layout->addWidget(editor);
m_scroll_area->setWidget(w);
return result;
}
......@@ -32,11 +32,13 @@ public:
private:
void setToolbarActions(QToolBar* toolbar);
void updateActions();
void createWidgetsForCurrentInstrument();
void updateEditor();
QWidget* createEditor(InstrumentItem*);
InstrumentsSet* m_set;
SetView* m_qlistview;
QScrollArea* m_scroll_area;
InstrumentItem* m_displayed_item = nullptr;
QAction* m_rm_action;
QAction* m_cp_action;
......
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