@@ -1,25 +1,33 | |||
|
1 | 1 | #ifndef SCIQLOP_DATASOURCEWIDGET_H |
|
2 | 2 | #define SCIQLOP_DATASOURCEWIDGET_H |
|
3 | 3 | |
|
4 | 4 | #include <Common/spimpl.h> |
|
5 | 5 | |
|
6 | 6 | #include <QWidget> |
|
7 | 7 | |
|
8 | 8 | class DataSourceItem; |
|
9 | 9 | |
|
10 | 10 | /** |
|
11 | 11 | * @brief The DataSourceWidget handles the graphical representation (as a tree) of the data sources |
|
12 | 12 | * attached to SciQlop. |
|
13 | 13 | */ |
|
14 | 14 | class DataSourceWidget : public QWidget { |
|
15 | 15 | Q_OBJECT |
|
16 | 16 | |
|
17 | 17 | public: |
|
18 | 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 | 28 | private: |
|
21 | 29 | class DataSourceWidgetPrivate; |
|
22 | 30 | spimpl::unique_impl_ptr<DataSourceWidgetPrivate> impl; |
|
23 | 31 | }; |
|
24 | 32 | |
|
25 | 33 | #endif // SCIQLOP_DATASOURCEWIDGET_H |
@@ -1,36 +1,61 | |||
|
1 | 1 | #include <DataSource/DataSourceWidget.h> |
|
2 | 2 | |
|
3 | 3 | #include <ui_DataSourceWidget.h> |
|
4 | 4 | |
|
5 | 5 | #include <DataSource/DataSourceItem.h> |
|
6 | 6 | #include <DataSource/DataSourceTreeWidgetItem.h> |
|
7 | 7 | |
|
8 | 8 | namespace { |
|
9 | 9 | |
|
10 | 10 | /// Number of columns displayed in the tree |
|
11 | 11 | const auto TREE_NB_COLUMNS = 1; |
|
12 | 12 | |
|
13 | 13 | /// Header labels for the tree |
|
14 | 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 | 34 | } // namespace |
|
17 | 35 | |
|
18 | 36 | class DataSourceWidget::DataSourceWidgetPrivate { |
|
19 | 37 | public: |
|
20 | 38 | explicit DataSourceWidgetPrivate(DataSourceWidget &widget) |
|
21 | 39 | : m_Ui{std::make_unique<Ui::DataSourceWidget>()} |
|
22 | 40 | { |
|
23 | 41 | m_Ui->setupUi(&widget); |
|
24 | 42 | |
|
25 | 43 | // Set tree properties |
|
26 | 44 | m_Ui->treeWidget->setColumnCount(TREE_NB_COLUMNS); |
|
27 | 45 | m_Ui->treeWidget->setHeaderLabels(TREE_HEADER_LABELS); |
|
28 | 46 | } |
|
29 | 47 | |
|
30 | 48 | std::unique_ptr<Ui::DataSourceWidget> m_Ui; |
|
31 | 49 | }; |
|
32 | 50 | |
|
33 | 51 | DataSourceWidget::DataSourceWidget(QWidget *parent) |
|
34 | 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