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

rm SamplesSet::addSampleItem()

parent 2626fe38
No related branches found
No related tags found
1 merge request!2384all "set" classes now inherit VectorWC
...@@ -35,12 +35,6 @@ QVector<SampleItem*> SamplesSet::sampleItems() const ...@@ -35,12 +35,6 @@ QVector<SampleItem*> SamplesSet::sampleItems() const
return QVector<SampleItem*>(m_samples.begin(), m_samples.end()); return QVector<SampleItem*>(m_samples.begin(), m_samples.end());
} }
SampleItem* SamplesSet::addSampleItem()
{
addSampleItem(new SampleItem());
return m_samples.back();
}
void SamplesSet::addSampleItem(SampleItem* sample) void SamplesSet::addSampleItem(SampleItem* sample)
{ {
m_samples.push_back(sample); m_samples.push_back(sample);
...@@ -88,7 +82,9 @@ void SamplesSet::readFrom(QXmlStreamReader* r) ...@@ -88,7 +82,9 @@ void SamplesSet::readFrom(QXmlStreamReader* r)
// sample // sample
if (tag == Tag::Sample) { if (tag == Tag::Sample) {
addSampleItem()->readFrom(r); auto* t = new SampleItem;
t->readFrom(r);
addSampleItem(t);
XML::gotoEndElementOfTag(r, tag); XML::gotoEndElementOfTag(r, tag);
// selected index // selected index
......
...@@ -27,9 +27,7 @@ public: ...@@ -27,9 +27,7 @@ public:
~SamplesSet(); ~SamplesSet();
QVector<SampleItem*> sampleItems() const; QVector<SampleItem*> sampleItems() const;
SampleItem* addSampleItem();
void addSampleItem(SampleItem* sample); void addSampleItem(SampleItem* sample);
void removeSample(SampleItem* sample); void removeSample(SampleItem* sample);
QStringList sampleNames() const; QStringList sampleNames() const;
......
...@@ -89,29 +89,35 @@ QModelIndex SamplesQModel::createSample() ...@@ -89,29 +89,35 @@ QModelIndex SamplesQModel::createSample()
{ {
const QStringList existingNames = gDoc->samples()->sampleNames(); const QStringList existingNames = gDoc->samples()->sampleNames();
auto* t = new SampleItem;
t->setSampleName(GUI::Util::String::suggestName(existingNames, "Sample"));
t->addStandardMaterials();
const int row = gDoc->samples()->sampleItems().size(); const int row = gDoc->samples()->sampleItems().size();
beginInsertRows(QModelIndex(), row, row); beginInsertRows(QModelIndex(), row, row);
auto* sample_item = gDoc->samplesModifier()->addSampleItem(); gDoc->samplesModifier()->addSampleItem(t);
sample_item->setSampleName(GUI::Util::String::suggestName(existingNames, "Sample"));
sample_item->addStandardMaterials();
endInsertRows(); endInsertRows();
return indexForItem(sample_item);
return indexForItem(t);
} }
QModelIndex SamplesQModel::createSampleFromExamples(const QString& className, const QString& title, QModelIndex SamplesQModel::createSampleFromExamples(const QString& className, const QString& title,
const QString& description) const QString& description)
{ {
auto* sample = dynamic_cast<SampleItem*>(GUI::ExamplesFactory::itemizeSample(className)); auto* t = dynamic_cast<SampleItem*>(GUI::ExamplesFactory::itemizeSample(className));
if (!sample) if (!t)
return {}; return {};
sample->setSampleName(title); t->setSampleName(title);
sample->setDescription(description); t->setDescription(description);
const int row = gDoc->samples()->sampleItems().size(); const int row = gDoc->samples()->sampleItems().size();
beginInsertRows(QModelIndex(), row, row); beginInsertRows(QModelIndex(), row, row);
gDoc->samplesModifier()->addSampleItem(sample); gDoc->samplesModifier()->addSampleItem(t);
endInsertRows(); endInsertRows();
return indexForItem(sample);
return indexForItem(t);
} }
#ifdef BORNAGAIN_PYTHON #ifdef BORNAGAIN_PYTHON
...@@ -121,16 +127,17 @@ QModelIndex SamplesQModel::createSampleFromPython() ...@@ -121,16 +127,17 @@ QModelIndex SamplesQModel::createSampleFromPython()
if (!sample) if (!sample)
return {}; // any messages already shown to user return {}; // any messages already shown to user
SampleItem* sampleItem = PyImportAssistant::itemizeSample(*sample); SampleItem* t = PyImportAssistant::itemizeSample(*sample);
if (!sampleItem) if (!t)
return {}; // any messages already shown to user return {}; // any messages already shown to user
t->setDescription("Imported from python code");
sampleItem->setDescription("Imported from python code");
const int row = gDoc->samples()->sampleItems().size(); const int row = gDoc->samples()->sampleItems().size();
beginInsertRows(QModelIndex(), row, row); beginInsertRows(QModelIndex(), row, row);
gDoc->samplesModifier()->addSampleItem(sampleItem); gDoc->samplesModifier()->addSampleItem(t);
endInsertRows(); endInsertRows();
return indexForItem(sampleItem);
return indexForItem(t);
} }
#endif #endif
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