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