##// END OF EJS Templates
Implements method to add a data source in the widget...
Alexandre Leroux -
r83:49b6273d9035
parent child
Show More
@@ -17,6 +17,14 class DataSourceWidget : public QWidget {
17 public:
17 public:
18 explicit DataSourceWidget(QWidget *parent = 0);
18 explicit DataSourceWidget(QWidget *parent = 0);
19
19
20 public slots:
21 /**
22 * Adds a data source. An item associated to the data source is created and then added to the
23 * representation tree
24 * @param dataSource the data source to add
25 */
26 void addDataSource(DataSourceItem &dataSource) noexcept;
27
20 private:
28 private:
21 class DataSourceWidgetPrivate;
29 class DataSourceWidgetPrivate;
22 spimpl::unique_impl_ptr<DataSourceWidgetPrivate> impl;
30 spimpl::unique_impl_ptr<DataSourceWidgetPrivate> impl;
@@ -13,6 +13,24 const auto TREE_NB_COLUMNS = 1;
13 /// Header labels for the tree
13 /// Header labels for the tree
14 const auto TREE_HEADER_LABELS = QStringList{QObject::tr("Name")};
14 const auto TREE_HEADER_LABELS = QStringList{QObject::tr("Name")};
15
15
16 /**
17 * Creates the item associated to a data source
18 * @param dataSource the data source for which to create the item
19 * @return the new item
20 */
21 DataSourceTreeWidgetItem *createTreeWidgetItem(DataSourceItem *dataSource)
22 {
23 // Creates item for the data source
24 auto item = new DataSourceTreeWidgetItem{dataSource};
25
26 // Generates items for the children of the data source
27 for (auto i = 0; i < dataSource->childCount(); ++i) {
28 item->addChild(createTreeWidgetItem(dataSource->child(i)));
29 }
30
31 return item;
32 }
33
16 } // namespace
34 } // namespace
17
35
18 class DataSourceWidget::DataSourceWidgetPrivate {
36 class DataSourceWidget::DataSourceWidgetPrivate {
@@ -34,3 +52,10 DataSourceWidget::DataSourceWidget(QWidget *parent)
34 : QWidget{parent}, impl{spimpl::make_unique_impl<DataSourceWidgetPrivate>(*this)}
52 : QWidget{parent}, impl{spimpl::make_unique_impl<DataSourceWidgetPrivate>(*this)}
35 {
53 {
36 }
54 }
55
56 void DataSourceWidget::addDataSource(DataSourceItem &dataSource) noexcept
57 {
58 // Creates the item associated to the source and adds it to the tree widget. The tree widget
59 // takes the ownership of the item
60 impl->m_Ui->treeWidget->addTopLevelItem(createTreeWidgetItem(&dataSource));
61 }
General Comments 0
You need to be logged in to leave comments. Login now