##// END OF EJS Templates
Adds type for a data source item...
Adds type for a data source item An item can be a node or a product. The type will be useful for various operations, like setting the item icon in the data source widget

File last commit:

r79:0afc39d45cc4
r79:0afc39d45cc4
Show More
DataSourceItem.cpp
56 lines | 1.4 KiB | text/x-c | CppLexer
#include <DataSource/DataSourceItem.h>
#include <QVector>
struct DataSourceItem::DataSourceItemPrivate {
explicit DataSourceItemPrivate(DataSourceItemType type, QVector<QVariant> data)
: m_Parent{nullptr}, m_Children{}, m_Type{type}, m_Data{std::move(data)}
{
}
DataSourceItem *m_Parent;
std::vector<std::unique_ptr<DataSourceItem> > m_Children;
DataSourceItemType m_Type;
QVector<QVariant> m_Data;
};
DataSourceItem::DataSourceItem(DataSourceItemType type, QVector<QVariant> data)
: impl{spimpl::make_unique_impl<DataSourceItemPrivate>(type, std::move(data))}
{
}
void DataSourceItem::appendChild(std::unique_ptr<DataSourceItem> child) noexcept
{
child->impl->m_Parent = this;
impl->m_Children.push_back(std::move(child));
}
DataSourceItem *DataSourceItem::child(int childIndex) const noexcept
{
if (childIndex < 0 || childIndex >= childCount()) {
return nullptr;
}
else {
return impl->m_Children.at(childIndex).get();
}
}
int DataSourceItem::childCount() const noexcept
{
return impl->m_Children.size();
}
QVariant DataSourceItem::data(int dataIndex) const noexcept
{
return impl->m_Data.value(dataIndex);
}
DataSourceItem *DataSourceItem::parentItem() const noexcept
{
return impl->m_Parent;
}
DataSourceItemType DataSourceItem::type() const noexcept
{
return impl->m_Type;
}