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