Commit 952b77f6 authored by Bob Obara's avatar Bob Obara

ENH: Added insertGroups to GroupItem

You can now insert n groups before the ith group in the item.
parent c45b9497
......@@ -132,6 +132,10 @@ an item's ForceRequired is set then even if it's definition indicates it should
* void Item::setForceRequired(bool)
* bool Item::forceRequired()
### Changes to GroupItem
* New Methods
* bool insertGroups(std::size_t ith, std::size_t num) - inserts num groups before ith element. If inserting num groups would violate the item's maximum number of groups or if ith is greater than the original number of groups, then the item is left unchanged and false is returned. Append and Prepend methods have been modified to call this new method with num= 1 and ith = numberOfGroups or 0 respectively.
### Custom attribute item and definition types
SMTK's attribute system now supports the registration of user-defined attribute items and definitions by overloading `smtk::attribute::CustomItem` and `smtk::attribute::CustomItemDefinition`, respectively. The registration of custom item definition types must occur before the attribute is serialized. Custom item definitions can be listed in plugins' Registrar implementations as follows:
......
......@@ -219,7 +219,7 @@ void GroupItem::visitChildren(std::function<void(ItemPtr, bool)> visitor, bool a
}
}
bool GroupItem::appendGroup()
bool GroupItem::insertGroups(std::size_t pos, std::size_t num)
{
if (!this->isExtensible())
{
......@@ -229,37 +229,36 @@ bool GroupItem::appendGroup()
const GroupItemDefinition* def =
static_cast<const GroupItemDefinition*>(this->definition().get());
std::size_t maxN = def->maxNumberOfGroups(), n = this->numberOfGroups();
if (maxN && (n >= maxN))
{
// max number of groups reached
return false;
}
m_items.resize(n + 1);
def->buildGroup(this, static_cast<int>(n));
return true;
}
bool GroupItem::prependGroup()
{
if (!this->isExtensible())
if ((pos > n) || (maxN && ((n + num) > maxN)))
{
// inserting beyond the end of the vector or
// inserting these groups would violate the max size
return false;
}
const GroupItemDefinition* def =
static_cast<const GroupItemDefinition*>(this->definition().get());
std::size_t maxN = def->maxNumberOfGroups(), n = this->numberOfGroups();
if (maxN && (n >= maxN))
std::vector<smtk::attribute::ItemPtr> placeHolder;
m_items.insert(m_items.begin() + pos, num, placeHolder);
for (std::size_t i = pos; i < pos + num; i++)
{
// max number of groups reached
return false;
def->buildGroup(this, static_cast<int>(i));
}
std::vector<smtk::attribute::ItemPtr> placeHolder;
m_items.insert(m_items.begin(), placeHolder);
def->buildGroup(this, 0);
return true;
}
bool GroupItem::appendGroup()
{
return this->insertGroups(m_items.size(), 1);
}
bool GroupItem::prependGroup()
{
return this->insertGroups(0, 1);
}
bool GroupItem::removeGroup(std::size_t element)
{
if (!this->isExtensible())
......
......@@ -76,6 +76,9 @@ public:
std::size_t numberOfItemsPerGroup() const;
bool appendGroup();
bool prependGroup();
///\brief Insert num groups before index pos - so append is pos = numberOfGroups
/// and prepend would be pos = 0
bool insertGroups(std::size_t pos, std::size_t num);
bool removeGroup(std::size_t element);
/// Return the i-th item in the first entry of the group.
......
......@@ -32,6 +32,7 @@ PySharedPtrClass< smtk::attribute::GroupItem, smtk::attribute::Item > pybind11_i
.def("_find", (smtk::attribute::ItemPtr (smtk::attribute::GroupItem::*)(::std::string const &, ::smtk::attribute::SearchStyle)) &smtk::attribute::GroupItem::find, py::arg("name"), py::arg("style") = ::smtk::attribute::SearchStyle::IMMEDIATE)
.def("_find", (smtk::attribute::ItemPtr (smtk::attribute::GroupItem::*)(::size_t, ::std::string const &, ::smtk::attribute::SearchStyle)) &smtk::attribute::GroupItem::find, py::arg("element"), py::arg("name"), py::arg("style") = ::smtk::attribute::SearchStyle::IMMEDIATE)
.def("_find", (smtk::attribute::ConstItemPtr (smtk::attribute::GroupItem::*)(::size_t, ::std::string const &, ::smtk::attribute::SearchStyle) const) &smtk::attribute::GroupItem::find, py::arg("element"), py::arg("name"), py::arg("style") = ::smtk::attribute::SearchStyle::IMMEDIATE)
.def("insertGroups", &smtk::attribute::GroupItem::insertGroups, py::arg("element"), py::arg("num"))
.def("isExtensible", &smtk::attribute::GroupItem::isExtensible)
.def("item", (smtk::attribute::ItemPtr (smtk::attribute::GroupItem::*)(::size_t) const) &smtk::attribute::GroupItem::item, py::arg("ith"))
.def("item", (smtk::attribute::ItemPtr (smtk::attribute::GroupItem::*)(::size_t, ::size_t) const) &smtk::attribute::GroupItem::item, py::arg("element"), py::arg("ith"))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment