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

Cloned GUI/Model/Descriptor/SelectionProperty -> GUI/Model/Descriptor/SelectionVector

parent 41a15b21
No related branches found
No related tags found
1 merge request!2328more systematic class names; simplifications in SelectionProperty context; + doyxall
...@@ -215,84 +215,4 @@ private: ...@@ -215,84 +215,4 @@ private:
std::function<void(CatalogedType* newItem, const CatalogedType* oldItem)> m_initializer; std::function<void(CatalogedType* newItem, const CatalogedType* oldItem)> m_initializer;
}; };
//! A special kind of owning vector, providing "standard" interfaces for
//! 'std::vector<SelectionProperty<Catalog>>', used in classes that work not just with single
//! SelectionProperty but with the set of them, for example 'InstrumentsSet', 'CompoundItem',
//! 'ParticleLayoutItems', 'MaskItems'
template <typename Catalog> class SelectionVector {
public:
using CatalogedType = typename Catalog::CatalogedType;
void delete_element(const CatalogedType* element)
{
for (size_t i = 0; i < m_selections.size(); i++)
if (m_selections[i].currentItem() == element)
m_selections.erase(m_selections.begin() + i);
}
void delete_at(size_t i) { m_selections.erase(m_selections.begin() + i); }
void insert_at(size_t i, CatalogedType* element)
{
SelectionProperty<Catalog> newSelection;
newSelection.setCurrentItem(element);
m_selections.insert(m_selections.begin() + i, std::move(newSelection));
}
int index_of(const CatalogedType* element) const
{
for (size_t i = 0; i < m_selections.size(); i++)
if (m_selections[i].currentItem() == element)
return int(i);
return -1;
}
void move(size_t fromIndex, size_t toIndex)
{
if (fromIndex > toIndex)
std::rotate(m_selections.rend() - fromIndex - 1, m_selections.rend() - fromIndex,
m_selections.rend() - toIndex);
else
std::rotate(m_selections.begin() + fromIndex, m_selections.begin() + fromIndex + 1,
m_selections.begin() + toIndex + 1);
}
QVector<CatalogedType*> toModifiableQVector() const
{
QVector<CatalogedType*> result;
for (const auto& sel : m_selections)
result.append(sel.currentItem());
return result;
}
QVector<const CatalogedType*> toQVector() const
{
QVector<const CatalogedType*> result;
for (const auto& sel : m_selections)
result.append(sel.currentItem());
return result;
}
void push_back(CatalogedType* item) { insert_at(m_selections.size(), item); }
void clear() { m_selections.clear(); }
size_t size() const { return m_selections.size(); }
bool empty() const { return m_selections.empty(); }
SelectionProperty<Catalog>& operator[](int i) { return m_selections[i]; }
SelectionProperty<Catalog>& at(int i) { return m_selections.at(i); }
SelectionProperty<Catalog>& front() { return m_selections.front(); }
SelectionProperty<Catalog>& back() { return m_selections.back(); }
using Iterator = typename std::vector<SelectionProperty<Catalog>>::iterator;
using ConstIterator = typename std::vector<SelectionProperty<Catalog>>::const_iterator;
ConstIterator begin() const { return m_selections.cbegin(); }
ConstIterator end() const { return m_selections.cend(); }
Iterator begin() { return m_selections.begin(); }
Iterator end() { return m_selections.end(); }
private:
std::vector<SelectionProperty<Catalog>> m_selections;
};
#endif // BORNAGAIN_GUI_MODEL_DESCRIPTOR_SELECTIONPROPERTY_H #endif // BORNAGAIN_GUI_MODEL_DESCRIPTOR_SELECTIONPROPERTY_H
// ************************************************************************************************
//
// BornAgain: simulate and fit reflection and scattering
//
//! @file GUI/Model/Descriptor/SelectionVector.h
//! @brief Defines class SelectionVector.
//!
//! @homepage http://www.bornagainproject.org
//! @license GNU General Public License v3 or higher (see COPYING)
//! @copyright Forschungszentrum Jülich GmbH 2021
//! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
//
// ************************************************************************************************
#ifndef BORNAGAIN_GUI_MODEL_DESCRIPTOR_SELECTIONVECTOR_H
#define BORNAGAIN_GUI_MODEL_DESCRIPTOR_SELECTIONVECTOR_H
#include "GUI/Model/Descriptor/SelectionProperty.h"
//! A special kind of owning vector, providing "standard" interfaces for
//! 'std::vector<SelectionProperty<Catalog>>', used in classes that work not just with single
//! SelectionProperty but with the set of them, for example 'InstrumentsSet', 'CompoundItem',
//! 'ParticleLayoutItems', 'MaskItems'
template <typename Catalog> class SelectionVector {
public:
using CatalogedType = typename Catalog::CatalogedType;
void delete_element(const CatalogedType* element)
{
for (size_t i = 0; i < m_selections.size(); i++)
if (m_selections[i].currentItem() == element)
m_selections.erase(m_selections.begin() + i);
}
void delete_at(size_t i) { m_selections.erase(m_selections.begin() + i); }
void insert_at(size_t i, CatalogedType* element)
{
SelectionProperty<Catalog> newSelection;
newSelection.setCurrentItem(element);
m_selections.insert(m_selections.begin() + i, std::move(newSelection));
}
int index_of(const CatalogedType* element) const
{
for (size_t i = 0; i < m_selections.size(); i++)
if (m_selections[i].currentItem() == element)
return int(i);
return -1;
}
void move(size_t fromIndex, size_t toIndex)
{
if (fromIndex > toIndex)
std::rotate(m_selections.rend() - fromIndex - 1, m_selections.rend() - fromIndex,
m_selections.rend() - toIndex);
else
std::rotate(m_selections.begin() + fromIndex, m_selections.begin() + fromIndex + 1,
m_selections.begin() + toIndex + 1);
}
QVector<CatalogedType*> toModifiableQVector() const
{
QVector<CatalogedType*> result;
for (const auto& sel : m_selections)
result.append(sel.currentItem());
return result;
}
QVector<const CatalogedType*> toQVector() const
{
QVector<const CatalogedType*> result;
for (const auto& sel : m_selections)
result.append(sel.currentItem());
return result;
}
void push_back(CatalogedType* item) { insert_at(m_selections.size(), item); }
void clear() { m_selections.clear(); }
size_t size() const { return m_selections.size(); }
bool empty() const { return m_selections.empty(); }
SelectionProperty<Catalog>& operator[](int i) { return m_selections[i]; }
SelectionProperty<Catalog>& at(int i) { return m_selections.at(i); }
SelectionProperty<Catalog>& front() { return m_selections.front(); }
SelectionProperty<Catalog>& back() { return m_selections.back(); }
using Iterator = typename std::vector<SelectionProperty<Catalog>>::iterator;
using ConstIterator = typename std::vector<SelectionProperty<Catalog>>::const_iterator;
ConstIterator begin() const { return m_selections.cbegin(); }
ConstIterator end() const { return m_selections.cend(); }
Iterator begin() { return m_selections.begin(); }
Iterator end() { return m_selections.end(); }
private:
std::vector<SelectionProperty<Catalog>> m_selections;
};
#endif // BORNAGAIN_GUI_MODEL_DESCRIPTOR_SELECTIONVECTOR_H
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
#ifndef BORNAGAIN_GUI_MODEL_DEVICE_INSTRUMENTSSET_H #ifndef BORNAGAIN_GUI_MODEL_DEVICE_INSTRUMENTSSET_H
#define BORNAGAIN_GUI_MODEL_DEVICE_INSTRUMENTSSET_H #define BORNAGAIN_GUI_MODEL_DEVICE_INSTRUMENTSSET_H
#include "GUI/Model/Descriptor/SelectionProperty.h" #include "GUI/Model/Descriptor/SelectionVector.h"
#include "GUI/Model/Device/InstrumentItemCatalog.h" #include "GUI/Model/Device/InstrumentItemCatalog.h"
#include <QVector> #include <QVector>
#include <QXmlStreamWriter> #include <QXmlStreamWriter>
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
#ifndef BORNAGAIN_GUI_MODEL_MASK_MASKSSET_H #ifndef BORNAGAIN_GUI_MODEL_MASK_MASKSSET_H
#define BORNAGAIN_GUI_MODEL_MASK_MASKSSET_H #define BORNAGAIN_GUI_MODEL_MASK_MASKSSET_H
#include "GUI/Model/Descriptor/SelectionProperty.h" #include "GUI/Model/Descriptor/SelectionVector.h"
#include "GUI/Model/Mask/MaskItemCatalog.h" #include "GUI/Model/Mask/MaskItemCatalog.h"
#include "GUI/Model/Mask/OverlayItem.h" #include "GUI/Model/Mask/OverlayItem.h"
#include <QModelIndex> #include <QModelIndex>
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#ifndef BORNAGAIN_GUI_MODEL_SAMPLE_COMPOUNDITEM_H #ifndef BORNAGAIN_GUI_MODEL_SAMPLE_COMPOUNDITEM_H
#define BORNAGAIN_GUI_MODEL_SAMPLE_COMPOUNDITEM_H #define BORNAGAIN_GUI_MODEL_SAMPLE_COMPOUNDITEM_H
#include "GUI/Model/Descriptor/SelectionVector.h"
#include "GUI/Model/Sample/ItemWithParticles.h" #include "GUI/Model/Sample/ItemWithParticles.h"
#include "GUI/Model/Sample/ItemWithParticlesCatalog.h" #include "GUI/Model/Sample/ItemWithParticlesCatalog.h"
#include "Sample/Particle/Compound.h" #include "Sample/Particle/Compound.h"
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
#define BORNAGAIN_GUI_MODEL_SAMPLE_PARTICLELAYOUTITEM_H #define BORNAGAIN_GUI_MODEL_SAMPLE_PARTICLELAYOUTITEM_H
#include "GUI/Model/Descriptor/DoubleProperty.h" #include "GUI/Model/Descriptor/DoubleProperty.h"
#include "GUI/Model/Descriptor/SelectionProperty.h" #include "GUI/Model/Descriptor/SelectionVector.h"
#include "GUI/Model/Sample/InterferenceItemCatalog.h" #include "GUI/Model/Sample/InterferenceItemCatalog.h"
#include "GUI/Model/Sample/InterferenceItems.h" #include "GUI/Model/Sample/InterferenceItems.h"
#include "GUI/Model/Sample/Item3D.h" #include "GUI/Model/Sample/Item3D.h"
......
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