##// END OF EJS Templates
Reads variable's metadata to retrieve the type of data series (scalar, vector, spectrogram)
Reads variable's metadata to retrieve the type of data series (scalar, vector, spectrogram)

File last commit:

r1232:74e2e6e57838
r1250:23206e07bbc2
Show More
DataSourceItem.cpp
187 lines | 5.1 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
Inits merge method of two items
r1031 #include <DataSource/DataSourceItemMergeHelper.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
Sets the name of the plugin for products and components...
r1036 const QString DataSourceItem::PLUGIN_DATA_KEY = QStringLiteral("plugin");
Use correct product ID when creating an event
r1232 const QString DataSourceItem::ID_DATA_KEY = QStringLiteral("uuid");
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
(Minor) Uses QVariantHash alias in DataSourceItem
r407 explicit DataSourceItemPrivate(DataSourceItemType type, QVariantHash 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
(Minor) Uses QVariantHash alias in DataSourceItem
r407 QVariantHash 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)
Alexandre Leroux
(Minor) Uses QVariantHash alias in DataSourceItem
r407 : DataSourceItem{type, QVariantHash{{NAME_DATA_KEY, name}}}
Alexandre Leroux
Changes structure of data hold by the item...
r342 {
}
Alexandre Leroux
(Minor) Uses QVariantHash alias in DataSourceItem
r407 DataSourceItem::DataSourceItem(DataSourceItemType type, QVariantHash 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
Implements merge method (2)...
r1033 std::unique_ptr<DataSourceItem> DataSourceItem::clone() const
{
auto result = std::make_unique<DataSourceItem>(impl->m_Type, impl->m_Data);
// Clones children
for (const auto &child : impl->m_Children) {
result->appendChild(std::move(child->clone()));
}
// Clones actions
for (const auto &action : impl->m_Actions) {
result->addAction(std::move(action->clone()));
}
return result;
}
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
(Minor) Uses QVariantHash alias in DataSourceItem
r407 QVariantHash DataSourceItem::data() const noexcept
Alexandre Leroux
Handles tooltip for a data source item
r346 {
return impl->m_Data;
}
Alexandre Leroux
Inits merge method of two items
r1031 void DataSourceItem::merge(const DataSourceItem &item)
{
DataSourceItemMergeHelper::merge(item, *this);
}
Alexandre Leroux
Changes data source item icons (2)...
r345 bool DataSourceItem::isRoot() const noexcept
{
return impl->m_Parent == nullptr;
}
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
Alexandre Leroux
Adds plugin column to variable widget...
r551 const DataSourceItem &DataSourceItem::rootItem() const noexcept
{
return isRoot() ? *this : parentItem()->rootItem();
}
Alexandre Leroux
Implements DataSourceItem::setData() method...
r347 void DataSourceItem::setData(const QString &key, const QVariant &value, bool append) noexcept
{
auto it = impl->m_Data.constFind(key);
if (append && it != impl->m_Data.constEnd()) {
// Case of an existing value to which we want to add to the new value
if (it->canConvert<QVariantList>()) {
auto variantList = it->value<QVariantList>();
variantList.append(value);
impl->m_Data.insert(key, variantList);
}
else {
impl->m_Data.insert(key, QVariantList{*it, value});
}
}
else {
// Other cases :
// - new value in map OR
// - replacement of an existing value (not appending)
impl->m_Data.insert(key, value);
}
}
Alexandre Leroux
Adds type for a data source item...
r79 DataSourceItemType DataSourceItem::type() const noexcept
{
return impl->m_Type;
}
Alexandre Leroux
Adds operators for DataSourceItem
r348
Drop of product in variables
r870 DataSourceItem *DataSourceItem::findItem(const QVariantHash &data, bool recursive)
{
for (const auto &child : impl->m_Children) {
if (child->impl->m_Data == data) {
return child.get();
}
Reset of the drag&drop operations when a drag is started from the datasource or from the variables
r877 if (recursive) {
Improves reliability
r874 if (auto foundItem = child->findItem(data, true)) {
Drop of product in variables
r870 return foundItem;
}
}
}
return nullptr;
}
Alexandre Leroux
Adds operators for DataSourceItem
r348 bool DataSourceItem::operator==(const DataSourceItem &other)
{
// Compares items' attributes
if (std::tie(impl->m_Type, impl->m_Data) == std::tie(other.impl->m_Type, other.impl->m_Data)) {
// Compares contents of items' children
return std::equal(std::cbegin(impl->m_Children), std::cend(impl->m_Children),
Alexandre Leroux
Adds test cases...
r1041 std::cbegin(other.impl->m_Children), std::cend(other.impl->m_Children),
Alexandre Leroux
Adds operators for DataSourceItem
r348 [](const auto &itemChild, const auto &otherChild) {
return *itemChild == *otherChild;
});
}
else {
return false;
}
}
bool DataSourceItem::operator!=(const DataSourceItem &other)
{
return !(*this == other);
}