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

MasksSet PolyVector -> OwningVector

parent e5107719
No related branches found
No related tags found
1 merge request!2372convert MasksSets from PolyVector to OwningVector (#914 1/3)
Pipeline #130411 passed
......@@ -81,20 +81,21 @@ public:
m_item.reset(t);
}
//! Serializes the catalog index of the currently selected type and calls
//! main serialization method of the selected class.
void writeTo(QXmlStreamWriter* w) const
static void writeItemTo(const BaseType* t, QXmlStreamWriter* w)
{
const uint typeIndex = static_cast<uint>(Catalog::type(m_item.get()));
const uint typeIndex = static_cast<uint>(Catalog::type(t));
XML::writeAttribute(w, XML::Attrib::type, typeIndex);
// The next line allows to see the name of item type in XML. May be skipped while reading.
XML::writeAttribute(w, XML::Attrib::name,
Catalog::uiInfo(Catalog::type(m_item.get())).menuEntry);
XML::writeAttribute(w, XML::Attrib::name, Catalog::uiInfo(Catalog::type(t)).menuEntry);
XML::writeAttribute(w, XML::Attrib::selection_version, uint(1));
if (m_item)
m_item->writeTo(w);
if (t)
t->writeTo(w);
}
//! Serializes the catalog index of the currently selected type and calls
//! main serialization method of the selected class.
void writeTo(QXmlStreamWriter* w) const { writeItemTo(m_item.get(), w); }
//! Deserializes the catalog index of the currently selected type, creates a new
//! object of this type and calls main deserialization method of the selected class.
template <typename... Args> void readFrom(QXmlStreamReader* r, Args... args)
......
......@@ -33,7 +33,7 @@ MasksSet::~MasksSet() = default;
QVector<MaskItem*> MasksSet::maskItemsQ() const
{
QVector<MaskItem*> ret;
for (MaskItem* t : m_mask_items.toQVector())
for (MaskItem* t : m_mask_items)
ret << t;
return ret;
}
......@@ -41,29 +41,29 @@ QVector<MaskItem*> MasksSet::maskItemsQ() const
void MasksSet::insertMask(int row, MaskItem* maskItem)
{
// takes owning of maskItem!
m_mask_items.insert_item_at(row, maskItem);
m_mask_items.insert_at(row, maskItem);
}
void MasksSet::addMaskItem(MaskItem* maskItem)
{
// takes owning of maskItem!
m_mask_items.emplace_item_back(maskItem);
m_mask_items.emplace_back(maskItem);
}
void MasksSet::moveMask(int from_row, int to_row)
{
m_mask_items.move_polyitem(from_row, to_row);
m_mask_items.swap(from_row, to_row);
}
void MasksSet::removeMaskAt(int row)
{
m_mask_items.delete_polyitem_at(row);
m_mask_items.delete_at(row);
}
RegionOfInterestItem* MasksSet::regionOfInterestItem() const
{
for (const auto& maskSel : m_mask_items)
if (auto* roi = dynamic_cast<RegionOfInterestItem*>(maskSel.certainItem()))
for (auto* t : m_mask_items)
if (auto* roi = dynamic_cast<RegionOfInterestItem*>(t))
return roi;
return nullptr;
......@@ -86,7 +86,7 @@ int MasksSet::size() const
MaskItem* MasksSet::at(const int idx)
{
return m_mask_items.at(idx).certainItem();
return m_mask_items.at(idx);
}
int MasksSet::indexOfItem(const MaskItem* maskItem) const
......@@ -99,9 +99,7 @@ void MasksSet::updateMaskNames()
const auto reg = QRegularExpression("[0-9]");
QMap<QString, int> numMasksByType;
for (const auto& p : m_mask_items) {
MaskItem* t = p.certainItem();
for (MaskItem* t : m_mask_items) {
QString name = t->maskName();
name.remove(reg);
......@@ -121,9 +119,9 @@ void MasksSet::writeTo(QXmlStreamWriter* w) const
{
XML::writeAttribute(w, XML::Attrib::version, uint(1));
for (const auto& sel : m_mask_items) {
for (const MaskItem* t : m_mask_items) {
w->writeStartElement(Tag::Mask);
sel.writeTo(w);
PolyItem<MasksCatalog>::writeItemTo(t, w);
w->writeEndElement();
}
}
......@@ -141,7 +139,7 @@ void MasksSet::readFrom(QXmlStreamReader* r, MessageService*)
if (tag == Tag::Mask) {
PolyItem<MasksCatalog> p;
p.readFrom(r);
m_mask_items.emplace_item_back(p.releaseItem());
m_mask_items.emplace_back(p.releaseItem());
XML::gotoEndElementOfTag(r, tag);
} else
......
......@@ -72,7 +72,7 @@ public:
const QModelIndex rootIndex;
protected:
PolyVector<MasksCatalog> m_mask_items;
OwningVector<MaskItem> m_mask_items;
};
#endif // BORNAGAIN_GUI_MODEL_MASK_MASKSSET_H
......@@ -33,8 +33,8 @@ private:
template <typename LineType> QVector<const LineItem*> projections() const
{
QVector<const LineItem*> result;
for (const auto& proj : m_mask_items)
if (const auto* line_item = dynamic_cast<const LineType*>(proj.certainItem()))
for (const auto* proj : m_mask_items)
if (const auto* line_item = dynamic_cast<const LineType*>(proj))
result.push_back(line_item);
return result;
}
......
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