##// END OF EJS Templates
Changes data source item icons (1)...
Changes data source item icons (1) - Adds new type of item (component) - Uses new icons

File last commit:

r342:2fbf66a7ca8a
r344:93d5f7162981
Show More
DataSourceItem.cpp
86 lines | 2.3 KiB | text/x-c | CppLexer
Alexandre Leroux
Define a data source item
r35 #include <DataSource/DataSourceItem.h>
Alexandre Leroux
Defines actions for a data source items...
r144 #include <DataSource/DataSourceItemAction.h>
Alexandre Leroux
Define a data source item
r35
#include <QVector>
Alexandre Leroux
Changes structure of data hold by the item...
r342 const QString DataSourceItem::NAME_DATA_KEY = QStringLiteral("name");
Alexandre Leroux
Adds action in the mock plugin to load products
r146
Alexandre Leroux
Define a data source item
r35 struct DataSourceItem::DataSourceItemPrivate {
Alexandre Leroux
Changes structure of data hold by the item...
r342 explicit DataSourceItemPrivate(DataSourceItemType type, QHash<QString, QVariant> data)
Alexandre Leroux
Defines actions for a data source items...
r144 : m_Parent{nullptr}, m_Children{}, m_Type{type}, m_Data{std::move(data)}, m_Actions{}
Alexandre Leroux
Define a data source item
r35 {
}
DataSourceItem *m_Parent;
std::vector<std::unique_ptr<DataSourceItem> > m_Children;
Alexandre Leroux
Adds type for a data source item...
r79 DataSourceItemType m_Type;
Alexandre Leroux
Changes structure of data hold by the item...
r342 QHash<QString, QVariant> m_Data;
Alexandre Leroux
Defines actions for a data source items...
r144 std::vector<std::unique_ptr<DataSourceItemAction> > m_Actions;
Alexandre Leroux
Define a data source item
r35 };
Alexandre Leroux
Changes structure of data hold by the item...
r342 DataSourceItem::DataSourceItem(DataSourceItemType type, const QString &name)
: DataSourceItem{type, QHash<QString, QVariant>{{NAME_DATA_KEY, name}}}
{
}
DataSourceItem::DataSourceItem(DataSourceItemType type, QHash<QString, QVariant> data)
Alexandre Leroux
Adds type for a data source item...
r79 : impl{spimpl::make_unique_impl<DataSourceItemPrivate>(type, std::move(data))}
Alexandre Leroux
Define a data source item
r35 {
}
Alexandre Leroux
Defines actions for a data source items...
r144 QVector<DataSourceItemAction *> DataSourceItem::actions() const noexcept
{
Alexandre Leroux
Minor fixes
r171 auto result = QVector<DataSourceItemAction *>{};
Alexandre Leroux
Defines actions for a data source items...
r144
std::transform(std::cbegin(impl->m_Actions), std::cend(impl->m_Actions),
std::back_inserter(result), [](const auto &action) { return action.get(); });
return result;
}
void DataSourceItem::addAction(std::unique_ptr<DataSourceItemAction> action) noexcept
{
action->setDataSourceItem(this);
impl->m_Actions.push_back(std::move(action));
}
Alexandre Leroux
Define a data source item
r35 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();
}
Alexandre Leroux
Changes structure of data hold by the item...
r342 QVariant DataSourceItem::data(const QString &key) const noexcept
Alexandre Leroux
Define a data source item
r35 {
Alexandre Leroux
Changes structure of data hold by the item...
r342 return impl->m_Data.value(key);
Alexandre Leroux
Define a data source item
r35 }
Alexandre Leroux
Adds action in the mock plugin to load products
r146 QString DataSourceItem::name() const noexcept
{
Alexandre Leroux
Changes structure of data hold by the item...
r342 return data(NAME_DATA_KEY).toString();
Alexandre Leroux
Adds action in the mock plugin to load products
r146 }
Alexandre Leroux
Define a data source item
r35 DataSourceItem *DataSourceItem::parentItem() const noexcept
{
return impl->m_Parent;
}
Alexandre Leroux
Adds type for a data source item...
r79
DataSourceItemType DataSourceItem::type() const noexcept
{
return impl->m_Type;
}