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

extract method InstrumentView::setToolbarActions

parent 110efb6d
No related branches found
No related tags found
1 merge request!2387unify code for list views
......@@ -46,6 +46,39 @@ InstrumentView::InstrumentView()
layout->addWidget(toolbar);
toolbar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
setToolbarActions(toolbar);
//... Everything below top toolbar
auto* hLayout = new QHBoxLayout;
layout->addLayout(hLayout);
// Left margin: instrument list
hLayout->addWidget(m_qlistview);
m_qlistview->setMinimumWidth(200);
// Large widget: current instrument
hLayout->addWidget(m_scroll_area);
m_scroll_area->setWidgetResizable(true);
m_scroll_area->setMinimumWidth(1000);
m_scroll_area->setWidget(new QWidget(m_scroll_area)); // initial state: blank widget
hLayout->addStretch(1);
//... Finalize
connect(gDoc->instruments(), &InstrumentsSet::setChanged, this,
&InstrumentView::createWidgetsForCurrentInstrument);
updateActions();
}
void InstrumentView::setToolbarActions(QToolBar* toolbar)
{
//... New-instrument actions
auto new_action = [this, toolbar](const QString& name, const QString& description) {
QAction* a = new QAction("New " + name, this);
a->setIcon(QIcon(":/images/shape-square-plus.svg"));
......@@ -66,6 +99,8 @@ InstrumentView::InstrumentView()
connect(new_action("depthprobe", "depth intensity profile"), &QAction::triggered,
[this] { m_qlistmodel->pushInstrument(new DepthprobeInstrumentItem); });
//... Copy and remove actions
m_rm_action = ActionFactory::createRemoveAction("instrument", this);
toolbar->addAction(m_rm_action);
connect(m_rm_action, &QAction::triggered, m_qlistmodel, &InstrumentsQModel::removeInstrument);
......@@ -74,6 +109,8 @@ InstrumentView::InstrumentView()
toolbar->addAction(m_cp_action);
connect(m_cp_action, &QAction::triggered, m_qlistmodel, &InstrumentsQModel::copyInstrument);
//... Save and load actions
m_save_action = new QAction("Store in library", this);
m_save_action->setIcon(QIcon(":/images/library.svg"));
m_save_action->setToolTip("Store instrument in library");
......@@ -88,32 +125,6 @@ InstrumentView::InstrumentView()
connect(m_load_action, &QAction::triggered, [this] {
m_qlistmodel->pushInstrument(RW::loadComponentFromXML<InstrumentItem>("instrument"));
});
//... Everything below top toolbar
auto* hLayout = new QHBoxLayout;
layout->addLayout(hLayout);
// Left margin: instrument list
hLayout->addWidget(m_qlistview);
m_qlistview->setMinimumWidth(200);
// Large widget: current instrument
hLayout->addWidget(m_scroll_area);
m_scroll_area->setWidgetResizable(true);
m_scroll_area->setMinimumWidth(1000);
m_scroll_area->setWidget(new QWidget(m_scroll_area)); // initial state: blank widget
hLayout->addStretch(1);
//... Finalize
connect(gDoc->instruments(), &InstrumentsSet::setChanged, this,
&InstrumentView::createWidgetsForCurrentInstrument);
updateActions();
}
void InstrumentView::createWidgetsForCurrentInstrument()
......
......@@ -23,6 +23,7 @@
class InstrumentItem;
class InstrumentsQListView;
class InstrumentsQModel;
class QToolBar;
class InstrumentView : public QWidget {
Q_OBJECT
......@@ -33,6 +34,7 @@ private slots:
void updateActions();
private:
void setToolbarActions(QToolBar* toolbar);
void createWidgetsForCurrentInstrument();
InstrumentsQModel* m_qlistmodel;
......
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