diff --git a/gui/include/DataSource/DataSourceWidget.h b/gui/include/DataSource/DataSourceWidget.h index ea3f2fa..e0634f7 100644 --- a/gui/include/DataSource/DataSourceWidget.h +++ b/gui/include/DataSource/DataSourceWidget.h @@ -17,6 +17,14 @@ class DataSourceWidget : public QWidget { public: explicit DataSourceWidget(QWidget *parent = 0); +public slots: + /** + * Adds a data source. An item associated to the data source is created and then added to the + * representation tree + * @param dataSource the data source to add + */ + void addDataSource(DataSourceItem &dataSource) noexcept; + private: class DataSourceWidgetPrivate; spimpl::unique_impl_ptr impl; diff --git a/gui/src/DataSource/DataSourceWidget.cpp b/gui/src/DataSource/DataSourceWidget.cpp index 5bba037..20e3014 100644 --- a/gui/src/DataSource/DataSourceWidget.cpp +++ b/gui/src/DataSource/DataSourceWidget.cpp @@ -13,6 +13,24 @@ const auto TREE_NB_COLUMNS = 1; /// Header labels for the tree const auto TREE_HEADER_LABELS = QStringList{QObject::tr("Name")}; +/** + * Creates the item associated to a data source + * @param dataSource the data source for which to create the item + * @return the new item + */ +DataSourceTreeWidgetItem *createTreeWidgetItem(DataSourceItem *dataSource) +{ + // Creates item for the data source + auto item = new DataSourceTreeWidgetItem{dataSource}; + + // Generates items for the children of the data source + for (auto i = 0; i < dataSource->childCount(); ++i) { + item->addChild(createTreeWidgetItem(dataSource->child(i))); + } + + return item; +} + } // namespace class DataSourceWidget::DataSourceWidgetPrivate { @@ -34,3 +52,10 @@ DataSourceWidget::DataSourceWidget(QWidget *parent) : QWidget{parent}, impl{spimpl::make_unique_impl(*this)} { } + +void DataSourceWidget::addDataSource(DataSourceItem &dataSource) noexcept +{ + // Creates the item associated to the source and adds it to the tree widget. The tree widget + // takes the ownership of the item + impl->m_Ui->treeWidget->addTopLevelItem(createTreeWidgetItem(&dataSource)); +}