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

InstrumentsQModel::copyInstrument() now directly operating on current instrument

parent 52eef28f
No related branches found
No related tags found
1 merge request!2387unify code for list views
......@@ -49,10 +49,11 @@ InstrumentsQListView::InstrumentsQListView()
connect(gActions->new_depthprobe_instrument, &QAction::triggered, this,
&InstrumentsQListView::onNewDepthprobe);
connect(gActions->remove_instrument, &QAction::triggered, this,
&InstrumentsQListView::onRemove);
connect(gActions->remove_instrument, &QAction::triggered, m_model,
&InstrumentsQModel::removeInstrument);
connect(gActions->copy_instrument, &QAction::triggered, this, &InstrumentsQListView::onCopy);
connect(gActions->copy_instrument, &QAction::triggered, m_model,
&InstrumentsQModel::copyInstrument);
connect(gActions->store_in_library_instrument, &QAction::triggered, this,
&InstrumentsQListView::onStoreInLibrary);
......@@ -95,27 +96,6 @@ void InstrumentsQListView::onNewDepthprobe()
m_model->addNewDepthprobeInstrument();
}
//! Removes currently selected instrument.
void InstrumentsQListView::onRemove()
{
QModelIndexList indexes = selectionModel()->selectedIndexes();
if (!indexes.empty()) {
m_model->removeInstrument(indexes.front());
ensureItemSelected();
}
}
//! Makes a copy of the currently selected instrument.
void InstrumentsQListView::onCopy()
{
QModelIndexList indexes = selectionModel()->selectedIndexes();
if (!indexes.empty()) {
QModelIndex idx = m_model->copyInstrument(indexes.front());
selectionModel()->select(idx, QItemSelectionModel::ClearAndSelect);
}
}
void InstrumentsQListView::onStoreInLibrary() const
{
const InstrumentItem* t = gDoc->instruments()->currentItem();
......@@ -144,10 +124,8 @@ void InstrumentsQListView::onLoadFromLibrary()
return;
try {
if (InstrumentItem* ii = InstrumentXML::load(fname)) {
QModelIndex idx = m_model->copyInstrument(ii);
selectionModel()->select(idx, QItemSelectionModel::ClearAndSelect);
}
if (InstrumentItem* t = InstrumentXML::load(fname))
m_model->pushInstrument(t);
} catch (const std::exception& ex) {
QMessageBox(QMessageBox::Warning, "BornAgain: failed loading", QString(ex.what()),
QMessageBox::Ok, nullptr)
......
......@@ -39,9 +39,6 @@ private slots:
void onNewSpecular();
void onNewDepthprobe();
void onRemove();
void onCopy();
void onStoreInLibrary() const;
void onLoadFromLibrary();
......
......@@ -82,31 +82,27 @@ QModelIndex InstrumentsQModel::addNewDepthprobeInstrument()
return pushInstrument(t);
}
void InstrumentsQModel::removeInstrument(const QModelIndex& index)
void InstrumentsQModel::removeInstrument()
{
beginRemoveRows(QModelIndex(), index.row(), index.row());
const InstrumentItem* instrument = instrumentItemForIndex(index);
gDoc->instrumentsModifier()->removeInstrument(instrument);
endRemoveRows();
}
QModelIndex InstrumentsQModel::copyInstrument(const QModelIndex& source)
{
const InstrumentItem* srcInstr = instrumentItemForIndex(source);
ASSERT(srcInstr);
InstrumentsSet* set = gDoc->instrumentsModifier();
const InstrumentItem* t = set->currentItem();
return copyInstrument(srcInstr);
const int row = set->index_of(t);
beginInsertRows({}, row, row);
set->removeInstrument(t);
endRemoveRows();
}
QModelIndex InstrumentsQModel::copyInstrument(const InstrumentItem* source)
QModelIndex InstrumentsQModel::copyInstrument() // TODO implement using pushInstrument
{
InstrumentsSet* set = gDoc->instrumentsModifier();
const QString copyName = set->suggestInstrumentName(source->instrumentName());
const int row = set->instrumentItems().size();
const InstrumentItem* t = set->currentItem();
const QString copyName = set->suggestInstrumentName(t->instrumentName());
const int row = set->instrumentItems().size();
beginInsertRows({}, row, row);
InstrumentItem* copy = set->insertItemCopy(*source);
copy->setInstrumentName(copyName);
InstrumentItem* t2 = set->insertItemCopy(*t);
t2->setInstrumentName(copyName);
emit set->instrumentAddedOrRemoved();
endInsertRows();
......
......@@ -36,13 +36,11 @@ public:
QModelIndex addNewSpecularInstrument();
QModelIndex addNewDepthprobeInstrument();
void removeInstrument(const QModelIndex& index);
QModelIndex copyInstrument(const QModelIndex& source);
QModelIndex copyInstrument(const InstrumentItem* source);
void removeInstrument();
QModelIndex copyInstrument();
QModelIndex pushInstrument(InstrumentItem*);
private:
QModelIndex pushInstrument(InstrumentItem*);
void onInstrumentNameChanged(const InstrumentItem* instrument);
};
......
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