From f87183c47a69235f2476d3417bd5bec13d9cfe99 2017-08-17 07:36:58 From: perrinel Date: 2017-08-17 07:36:58 Subject: [PATCH] Merge pull request #224 from SCIQLOP-Initialisation develop Develop --- diff --git a/core/include/DataSource/DataSourceItem.h b/core/include/DataSource/DataSourceItem.h index 0a8194e..cecbf82 100644 --- a/core/include/DataSource/DataSourceItem.h +++ b/core/include/DataSource/DataSourceItem.h @@ -75,6 +75,12 @@ public: DataSourceItem *parentItem() const noexcept; /** + * Gets the item's root + * @return the top parent, the item itself if it's the root item + */ + const DataSourceItem &rootItem() const noexcept; + + /** * Sets or appends a value to a key * @param key the key * @param value the value diff --git a/core/src/DataSource/DataSourceController.cpp b/core/src/DataSource/DataSourceController.cpp index 0a3d1e3..220945e 100644 --- a/core/src/DataSource/DataSourceController.cpp +++ b/core/src/DataSource/DataSourceController.cpp @@ -11,6 +11,28 @@ Q_LOGGING_CATEGORY(LOG_DataSourceController, "DataSourceController") +namespace { + +/** + * Builds the metadata of the variable that will be generated from the loading of an item + * @param dataSourceItem the data source item from which to generate the metadata + * @return the metadata of the variable + */ +QVariantHash variableMetadata(const DataSourceItem &dataSourceItem) +{ + // Variable metadata contains... + + // ... all metadata of the item + auto result = dataSourceItem.data(); + + // ... and the name of the plugin, recovered from root item + result.insert(QStringLiteral("plugin"), dataSourceItem.rootItem().name()); + + return result; +} + +} // namespace + class DataSourceController::DataSourceControllerPrivate { public: QMutex m_WorkingMutex; @@ -94,7 +116,8 @@ void DataSourceController::loadProductItem(const QUuid &dataSourceUid, auto it = impl->m_DataProviders.find(dataSourceUid); auto dataProvider = (it != impl->m_DataProviders.end()) ? it->second : nullptr; - emit variableCreationRequested(productItem.name(), productItem.data(), dataProvider); + emit variableCreationRequested(productItem.name(), variableMetadata(productItem), + dataProvider); } else { qCWarning(LOG_DataSourceController()) << tr("Can't load an item that is not a product"); diff --git a/core/src/DataSource/DataSourceItem.cpp b/core/src/DataSource/DataSourceItem.cpp index 48c1abd..cf316d8 100644 --- a/core/src/DataSource/DataSourceItem.cpp +++ b/core/src/DataSource/DataSourceItem.cpp @@ -90,6 +90,11 @@ DataSourceItem *DataSourceItem::parentItem() const noexcept return impl->m_Parent; } +const DataSourceItem &DataSourceItem::rootItem() const noexcept +{ + return isRoot() ? *this : parentItem()->rootItem(); +} + void DataSourceItem::setData(const QString &key, const QVariant &value, bool append) noexcept { auto it = impl->m_Data.constFind(key); diff --git a/core/src/Variable/VariableModel.cpp b/core/src/Variable/VariableModel.cpp index e5f6f37..a3065ba 100644 --- a/core/src/Variable/VariableModel.cpp +++ b/core/src/Variable/VariableModel.cpp @@ -16,7 +16,10 @@ namespace { const auto NAME_COLUMN = 0; const auto TSTART_COLUMN = 1; const auto TEND_COLUMN = 2; -const auto NB_COLUMNS = 3; +const auto UNIT_COLUMN = 3; +const auto MISSION_COLUMN = 4; +const auto PLUGIN_COLUMN = 5; +const auto NB_COLUMNS = 6; // Column properties const auto DEFAULT_HEIGHT = 25; @@ -34,10 +37,10 @@ struct ColumnProperties { int m_Height; }; -const auto COLUMN_PROPERTIES - = QHash{{NAME_COLUMN, {QObject::tr("Name")}}, - {TSTART_COLUMN, {QObject::tr("tStart"), 180}}, - {TEND_COLUMN, {QObject::tr("tEnd"), 180}}}; +const auto COLUMN_PROPERTIES = QHash{ + {NAME_COLUMN, {QObject::tr("Name")}}, {TSTART_COLUMN, {QObject::tr("tStart"), 180}}, + {TEND_COLUMN, {QObject::tr("tEnd"), 180}}, {UNIT_COLUMN, {QObject::tr("Unit")}}, + {MISSION_COLUMN, {QObject::tr("Mission")}}, {PLUGIN_COLUMN, {QObject::tr("Plugin")}}}; /// Format for datetimes const auto DATETIME_FORMAT = QStringLiteral("dd/MM/yyyy \nhh:mm:ss:zzz"); @@ -163,6 +166,12 @@ QVariant VariableModel::data(const QModelIndex &index, int role) const return dateTimeVariant(variable->range().m_TStart); case TEND_COLUMN: return dateTimeVariant(variable->range().m_TEnd); + case UNIT_COLUMN: + return variable->metadata().value(QStringLiteral("units")); + case MISSION_COLUMN: + return variable->metadata().value(QStringLiteral("mission")); + case PLUGIN_COLUMN: + return variable->metadata().value(QStringLiteral("plugin")); default: // No action break;