@@ -3,6 +3,8 | |||||
3 |
|
3 | |||
4 | #include <QWidget> |
|
4 | #include <QWidget> | |
5 |
|
5 | |||
|
6 | #include <memory> | |||
|
7 | ||||
6 | namespace Ui { |
|
8 | namespace Ui { | |
7 | class DataSourceWidget; |
|
9 | class DataSourceWidget; | |
8 | } // Ui |
|
10 | } // Ui | |
@@ -29,7 +31,10 public slots: | |||||
29 | void addDataSource(DataSourceItem *dataSource) noexcept; |
|
31 | void addDataSource(DataSourceItem *dataSource) noexcept; | |
30 |
|
32 | |||
31 | private: |
|
33 | private: | |
|
34 | void updateTreeWidget() noexcept; | |||
|
35 | ||||
32 | Ui::DataSourceWidget *ui; |
|
36 | Ui::DataSourceWidget *ui; | |
|
37 | std::unique_ptr<DataSourceItem> m_Root; | |||
33 |
|
38 | |||
34 | private slots: |
|
39 | private slots: | |
35 | /// Slot called when the filtering text has changed |
|
40 | /// Slot called when the filtering text has changed |
@@ -36,7 +36,11 DataSourceTreeWidgetItem *createTreeWidgetItem(DataSourceItem *dataSource) | |||||
36 |
|
36 | |||
37 | } // namespace |
|
37 | } // namespace | |
38 |
|
38 | |||
39 |
DataSourceWidget::DataSourceWidget(QWidget *parent) |
|
39 | DataSourceWidget::DataSourceWidget(QWidget *parent) | |
|
40 | : QWidget{parent}, | |||
|
41 | ui{new Ui::DataSourceWidget}, | |||
|
42 | m_Root{ | |||
|
43 | std::make_unique<DataSourceItem>(DataSourceItemType::NODE, QStringLiteral("Sources"))} | |||
40 | { |
|
44 | { | |
41 | ui->setupUi(this); |
|
45 | ui->setupUi(this); | |
42 |
|
46 | |||
@@ -51,6 +55,9 DataSourceWidget::DataSourceWidget(QWidget *parent) : QWidget{parent}, ui{new Ui | |||||
51 |
|
55 | |||
52 | // Connection to filter tree |
|
56 | // Connection to filter tree | |
53 | connect(ui->filterLineEdit, &QLineEdit::textChanged, this, &DataSourceWidget::filterChanged); |
|
57 | connect(ui->filterLineEdit, &QLineEdit::textChanged, this, &DataSourceWidget::filterChanged); | |
|
58 | ||||
|
59 | // First init | |||
|
60 | updateTreeWidget(); | |||
54 | } |
|
61 | } | |
55 |
|
62 | |||
56 | DataSourceWidget::~DataSourceWidget() noexcept |
|
63 | DataSourceWidget::~DataSourceWidget() noexcept | |
@@ -67,6 +74,19 void DataSourceWidget::addDataSource(DataSourceItem *dataSource) noexcept | |||||
67 | } |
|
74 | } | |
68 | } |
|
75 | } | |
69 |
|
76 | |||
|
77 | void DataSourceWidget::updateTreeWidget() noexcept | |||
|
78 | { | |||
|
79 | ui->treeWidget->clear(); | |||
|
80 | ||||
|
81 | auto rootItem = createTreeWidgetItem(m_Root.get()); | |||
|
82 | ui->treeWidget->addTopLevelItem(rootItem); | |||
|
83 | rootItem->setExpanded(true); | |||
|
84 | ||||
|
85 | // Sorts tree | |||
|
86 | ui->treeWidget->setSortingEnabled(true); | |||
|
87 | ui->treeWidget->sortByColumn(0, Qt::AscendingOrder); | |||
|
88 | } | |||
|
89 | ||||
70 | void DataSourceWidget::filterChanged(const QString &text) noexcept |
|
90 | void DataSourceWidget::filterChanged(const QString &text) noexcept | |
71 | { |
|
91 | { | |
72 | auto validateItem = [&text](const DataSourceTreeWidgetItem &item) { |
|
92 | auto validateItem = [&text](const DataSourceTreeWidgetItem &item) { |
General Comments 0
You need to be logged in to leave comments.
Login now