@@ -1,33 +1,34 | |||
|
1 | 1 | #ifndef SCIQLOP_DATASOURCEWIDGET_H |
|
2 | 2 | #define SCIQLOP_DATASOURCEWIDGET_H |
|
3 | 3 | |
|
4 | #include <Common/spimpl.h> | |
|
5 | ||
|
6 | 4 | #include <QWidget> |
|
7 | 5 | |
|
6 | namespace Ui { | |
|
7 | class DataSourceWidget; | |
|
8 | } // Ui | |
|
9 | ||
|
8 | 10 | class DataSourceItem; |
|
9 | 11 | |
|
10 | 12 | /** |
|
11 | 13 | * @brief The DataSourceWidget handles the graphical representation (as a tree) of the data sources |
|
12 | 14 | * attached to SciQlop. |
|
13 | 15 | */ |
|
14 | 16 | class DataSourceWidget : public QWidget { |
|
15 | 17 | Q_OBJECT |
|
16 | 18 | |
|
17 | 19 | public: |
|
18 | 20 | explicit DataSourceWidget(QWidget *parent = 0); |
|
19 | 21 | |
|
20 | 22 | public slots: |
|
21 | 23 | /** |
|
22 | 24 | * Adds a data source. An item associated to the data source is created and then added to the |
|
23 | 25 | * representation tree |
|
24 | 26 | * @param dataSource the data source to add. The pointer has to be not null |
|
25 | 27 | */ |
|
26 | 28 | void addDataSource(DataSourceItem *dataSource) noexcept; |
|
27 | 29 | |
|
28 | 30 | private: |
|
29 |
|
|
|
30 | spimpl::unique_impl_ptr<DataSourceWidgetPrivate> impl; | |
|
31 | Ui::DataSourceWidget *ui; | |
|
31 | 32 | }; |
|
32 | 33 | |
|
33 | 34 | #endif // SCIQLOP_DATASOURCEWIDGET_H |
@@ -1,63 +1,52 | |||
|
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 | 16 | /** |
|
17 | 17 | * Creates the item associated to a data source |
|
18 | 18 | * @param dataSource the data source for which to create the item |
|
19 | 19 | * @return the new item |
|
20 | 20 | */ |
|
21 | 21 | DataSourceTreeWidgetItem *createTreeWidgetItem(DataSourceItem *dataSource) |
|
22 | 22 | { |
|
23 | 23 | // Creates item for the data source |
|
24 | 24 | auto item = new DataSourceTreeWidgetItem{dataSource}; |
|
25 | 25 | |
|
26 | 26 | // Generates items for the children of the data source |
|
27 | 27 | for (auto i = 0; i < dataSource->childCount(); ++i) { |
|
28 | 28 | item->addChild(createTreeWidgetItem(dataSource->child(i))); |
|
29 | 29 | } |
|
30 | 30 | |
|
31 | 31 | return item; |
|
32 | 32 | } |
|
33 | 33 | |
|
34 | 34 | } // namespace |
|
35 | 35 | |
|
36 | class DataSourceWidget::DataSourceWidgetPrivate { | |
|
37 | public: | |
|
38 | explicit DataSourceWidgetPrivate(DataSourceWidget &widget) | |
|
39 | : m_Ui{std::make_unique<Ui::DataSourceWidget>()} | |
|
40 | { | |
|
41 | m_Ui->setupUi(&widget); | |
|
42 | ||
|
43 | // Set tree properties | |
|
44 | m_Ui->treeWidget->setColumnCount(TREE_NB_COLUMNS); | |
|
45 | m_Ui->treeWidget->setHeaderLabels(TREE_HEADER_LABELS); | |
|
46 | } | |
|
47 | ||
|
48 | std::unique_ptr<Ui::DataSourceWidget> m_Ui; | |
|
49 | }; | |
|
50 | ||
|
51 | DataSourceWidget::DataSourceWidget(QWidget *parent) | |
|
52 | : QWidget{parent}, impl{spimpl::make_unique_impl<DataSourceWidgetPrivate>(*this)} | |
|
36 | DataSourceWidget::DataSourceWidget(QWidget *parent) : QWidget{parent}, ui{new Ui::DataSourceWidget} | |
|
53 | 37 | { |
|
38 | ui->setupUi(this); | |
|
39 | ||
|
40 | // Set tree properties | |
|
41 | ui->treeWidget->setColumnCount(TREE_NB_COLUMNS); | |
|
42 | ui->treeWidget->setHeaderLabels(TREE_HEADER_LABELS); | |
|
54 | 43 | } |
|
55 | 44 | |
|
56 | 45 | void DataSourceWidget::addDataSource(DataSourceItem *dataSource) noexcept |
|
57 | 46 | { |
|
58 | 47 | // Creates the item associated to the source and adds it to the tree widget. The tree widget |
|
59 | 48 | // takes the ownership of the item |
|
60 | 49 | if (dataSource) { |
|
61 |
|
|
|
50 | ui->treeWidget->addTopLevelItem(createTreeWidgetItem(dataSource)); | |
|
62 | 51 | } |
|
63 | 52 | } |
General Comments 0
You need to be logged in to leave comments.
Login now