##// END OF EJS Templates
Adds line edit as a search box above data source tree
Alexandre Leroux -
r475:72f279351624
parent child
Show More
@@ -1,39 +1,42
1 1 #ifndef SCIQLOP_DATASOURCEWIDGET_H
2 2 #define SCIQLOP_DATASOURCEWIDGET_H
3 3
4 4 #include <QWidget>
5 5
6 6 namespace Ui {
7 7 class DataSourceWidget;
8 8 } // Ui
9 9
10 10 class DataSourceItem;
11 11
12 12 /**
13 13 * @brief The DataSourceWidget handles the graphical representation (as a tree) of the data sources
14 14 * attached to SciQlop.
15 15 */
16 16 class DataSourceWidget : public QWidget {
17 17 Q_OBJECT
18 18
19 19 public:
20 20 explicit DataSourceWidget(QWidget *parent = 0);
21 21 virtual ~DataSourceWidget() noexcept;
22 22
23 23 public slots:
24 24 /**
25 25 * Adds a data source. An item associated to the data source is created and then added to the
26 26 * representation tree
27 27 * @param dataSource the data source to add. The pointer has to be not null
28 28 */
29 29 void addDataSource(DataSourceItem *dataSource) noexcept;
30 30
31 31 private:
32 32 Ui::DataSourceWidget *ui;
33 33
34 34 private slots:
35 /// Slot called when the filtering text has changed
36 void filterChanged(const QString &text) noexcept;
37
35 38 /// Slot called when right clicking on an item in the tree (displays a menu)
36 39 void onTreeMenuRequested(const QPoint &pos) noexcept;
37 40 };
38 41
39 42 #endif // SCIQLOP_DATASOURCEWIDGET_H
@@ -1,77 +1,84
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 #include <QMenu>
9 9
10 10 namespace {
11 11
12 12 /// Number of columns displayed in the tree
13 13 const auto TREE_NB_COLUMNS = 1;
14 14
15 15 /// Header labels for the tree
16 16 const auto TREE_HEADER_LABELS = QStringList{QObject::tr("Name")};
17 17
18 18 /**
19 19 * Creates the item associated to a data source
20 20 * @param dataSource the data source for which to create the item
21 21 * @return the new item
22 22 */
23 23 DataSourceTreeWidgetItem *createTreeWidgetItem(DataSourceItem *dataSource)
24 24 {
25 25 // Creates item for the data source
26 26 auto item = new DataSourceTreeWidgetItem{dataSource};
27 27
28 28 // Generates items for the children of the data source
29 29 for (auto i = 0; i < dataSource->childCount(); ++i) {
30 30 item->addChild(createTreeWidgetItem(dataSource->child(i)));
31 31 }
32 32
33 33 return item;
34 34 }
35 35
36 36 } // namespace
37 37
38 38 DataSourceWidget::DataSourceWidget(QWidget *parent) : QWidget{parent}, ui{new Ui::DataSourceWidget}
39 39 {
40 40 ui->setupUi(this);
41 41
42 42 // Set tree properties
43 43 ui->treeWidget->setColumnCount(TREE_NB_COLUMNS);
44 44 ui->treeWidget->setHeaderLabels(TREE_HEADER_LABELS);
45 45 ui->treeWidget->setContextMenuPolicy(Qt::CustomContextMenu);
46 46
47 47 // Connection to show a menu when right clicking on the tree
48 48 connect(ui->treeWidget, &QTreeWidget::customContextMenuRequested, this,
49 49 &DataSourceWidget::onTreeMenuRequested);
50
51 // Connection to filter tree
52 connect(ui->filterLineEdit, &QLineEdit::textChanged, this, &DataSourceWidget::filterChanged);
50 53 }
51 54
52 55 DataSourceWidget::~DataSourceWidget() noexcept
53 56 {
54 57 delete ui;
55 58 }
56 59
57 60 void DataSourceWidget::addDataSource(DataSourceItem *dataSource) noexcept
58 61 {
59 62 // Creates the item associated to the source and adds it to the tree widget. The tree widget
60 63 // takes the ownership of the item
61 64 if (dataSource) {
62 65 ui->treeWidget->addTopLevelItem(createTreeWidgetItem(dataSource));
63 66 }
64 67 }
65 68
69 void DataSourceWidget::filterChanged(const QString &text) noexcept
70 {
71 }
72
66 73 void DataSourceWidget::onTreeMenuRequested(const QPoint &pos) noexcept
67 74 {
68 75 // Retrieves the selected item in the tree, and build the menu from its actions
69 76 if (auto selectedItem = dynamic_cast<DataSourceTreeWidgetItem *>(ui->treeWidget->itemAt(pos))) {
70 77 QMenu treeMenu{};
71 78 treeMenu.addActions(selectedItem->actions());
72 79
73 80 if (!treeMenu.isEmpty()) {
74 81 treeMenu.exec(mapToGlobal(pos));
75 82 }
76 83 }
77 84 }
@@ -1,42 +1,33
1 1 <?xml version="1.0" encoding="UTF-8"?>
2 2 <ui version="4.0">
3 3 <class>DataSourceWidget</class>
4 4 <widget class="QWidget" name="DataSourceWidget">
5 5 <property name="geometry">
6 6 <rect>
7 7 <x>0</x>
8 8 <y>0</y>
9 9 <width>400</width>
10 10 <height>300</height>
11 11 </rect>
12 12 </property>
13 13 <property name="windowTitle">
14 14 <string>Data sources</string>
15 15 </property>
16 16 <layout class="QGridLayout" name="gridLayout">
17 <property name="topMargin">
18 <number>0</number>
19 </property>
20 <property name="rightMargin">
21 <number>0</number>
22 </property>
23 <property name="bottomMargin">
24 <number>0</number>
25 </property>
26 <property name="spacing">
27 <number>0</number>
28 </property>
29 17 <item row="0" column="0">
18 <widget class="QLineEdit" name="filterLineEdit"/>
19 </item>
20 <item row="1" column="0">
30 21 <widget class="QTreeWidget" name="treeWidget">
31 22 <column>
32 23 <property name="text">
33 24 <string notr="true">1</string>
34 25 </property>
35 26 </column>
36 27 </widget>
37 28 </item>
38 29 </layout>
39 30 </widget>
40 31 <resources/>
41 32 <connections/>
42 33 </ui>
General Comments 0
You need to be logged in to leave comments. Login now