@@ -3,6 +3,8 | |||
|
3 | 3 | |
|
4 | 4 | #include <QWidget> |
|
5 | 5 | |
|
6 | #include <memory> | |
|
7 | ||
|
6 | 8 | namespace Ui { |
|
7 | 9 | class DataSourceWidget; |
|
8 | 10 | } // Ui |
@@ -29,7 +31,10 public slots: | |||
|
29 | 31 | void addDataSource(DataSourceItem *dataSource) noexcept; |
|
30 | 32 | |
|
31 | 33 | private: |
|
34 | void updateTreeWidget() noexcept; | |
|
35 | ||
|
32 | 36 | Ui::DataSourceWidget *ui; |
|
37 | std::unique_ptr<DataSourceItem> m_Root; | |
|
33 | 38 | |
|
34 | 39 | private slots: |
|
35 | 40 | /// Slot called when the filtering text has changed |
@@ -36,7 +36,11 DataSourceTreeWidgetItem *createTreeWidgetItem(DataSourceItem *dataSource) | |||
|
36 | 36 | |
|
37 | 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 | 45 | ui->setupUi(this); |
|
42 | 46 | |
@@ -51,6 +55,9 DataSourceWidget::DataSourceWidget(QWidget *parent) : QWidget{parent}, ui{new Ui | |||
|
51 | 55 | |
|
52 | 56 | // Connection to filter tree |
|
53 | 57 | connect(ui->filterLineEdit, &QLineEdit::textChanged, this, &DataSourceWidget::filterChanged); |
|
58 | ||
|
59 | // First init | |
|
60 | updateTreeWidget(); | |
|
54 | 61 | } |
|
55 | 62 | |
|
56 | 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 | 90 | void DataSourceWidget::filterChanged(const QString &text) noexcept |
|
71 | 91 | { |
|
72 | 92 | auto validateItem = [&text](const DataSourceTreeWidgetItem &item) { |
General Comments 0
You need to be logged in to leave comments.
Login now