##// END OF EJS Templates
Creates helper that filters a tree widget according to a filter function
Creates helper that filters a tree widget according to a filter function

File last commit:

r475:72f279351624
r476:becb718e8802
Show More
DataSourceWidget.cpp
84 lines | 2.4 KiB | text/x-c | CppLexer
/ gui / src / DataSource / DataSourceWidget.cpp
Alexandre Leroux
Creates the data source widget...
r82 #include <DataSource/DataSourceWidget.h>
#include <ui_DataSourceWidget.h>
#include <DataSource/DataSourceItem.h>
#include <DataSource/DataSourceTreeWidgetItem.h>
Alexandre Leroux
Handles right clicking on the tree of the data sources...
r143 #include <QMenu>
Alexandre Leroux
Creates the data source widget...
r82 namespace {
/// Number of columns displayed in the tree
const auto TREE_NB_COLUMNS = 1;
/// Header labels for the tree
const auto TREE_HEADER_LABELS = QStringList{QObject::tr("Name")};
Alexandre Leroux
Implements method to add a data source in the widget...
r83 /**
* Creates the item associated to a data source
* @param dataSource the data source for which to create the item
* @return the new item
*/
DataSourceTreeWidgetItem *createTreeWidgetItem(DataSourceItem *dataSource)
{
// Creates item for the data source
auto item = new DataSourceTreeWidgetItem{dataSource};
// Generates items for the children of the data source
for (auto i = 0; i < dataSource->childCount(); ++i) {
item->addChild(createTreeWidgetItem(dataSource->child(i)));
}
return item;
}
Alexandre Leroux
Creates the data source widget...
r82 } // namespace
Alexandre Leroux
(Minor) Extracts ui of DataSourceWidget
r109 DataSourceWidget::DataSourceWidget(QWidget *parent) : QWidget{parent}, ui{new Ui::DataSourceWidget}
Alexandre Leroux
Creates the data source widget...
r82 {
Alexandre Leroux
(Minor) Extracts ui of DataSourceWidget
r109 ui->setupUi(this);
// Set tree properties
ui->treeWidget->setColumnCount(TREE_NB_COLUMNS);
ui->treeWidget->setHeaderLabels(TREE_HEADER_LABELS);
Alexandre Leroux
Handles right clicking on the tree of the data sources...
r143 ui->treeWidget->setContextMenuPolicy(Qt::CustomContextMenu);
// Connection to show a menu when right clicking on the tree
connect(ui->treeWidget, &QTreeWidget::customContextMenuRequested, this,
&DataSourceWidget::onTreeMenuRequested);
Alexandre Leroux
Adds line edit as a search box above data source tree
r475
// Connection to filter tree
connect(ui->filterLineEdit, &QLineEdit::textChanged, this, &DataSourceWidget::filterChanged);
Alexandre Leroux
Creates the data source widget...
r82 }
Alexandre Leroux
Implements method to add a data source in the widget...
r83
add missing delete ui
r232 DataSourceWidget::~DataSourceWidget() noexcept
{
delete ui;
}
Alexandre Leroux
Change signal/slot signature for data source
r92 void DataSourceWidget::addDataSource(DataSourceItem *dataSource) noexcept
Alexandre Leroux
Implements method to add a data source in the widget...
r83 {
// Creates the item associated to the source and adds it to the tree widget. The tree widget
// takes the ownership of the item
Alexandre Leroux
Change signal/slot signature for data source
r92 if (dataSource) {
Alexandre Leroux
(Minor) Extracts ui of DataSourceWidget
r109 ui->treeWidget->addTopLevelItem(createTreeWidgetItem(dataSource));
Alexandre Leroux
Change signal/slot signature for data source
r92 }
Alexandre Leroux
Implements method to add a data source in the widget...
r83 }
Alexandre Leroux
Handles right clicking on the tree of the data sources...
r143
Alexandre Leroux
Adds line edit as a search box above data source tree
r475 void DataSourceWidget::filterChanged(const QString &text) noexcept
{
}
Alexandre Leroux
Handles right clicking on the tree of the data sources...
r143 void DataSourceWidget::onTreeMenuRequested(const QPoint &pos) noexcept
{
// Retrieves the selected item in the tree, and build the menu from its actions
if (auto selectedItem = dynamic_cast<DataSourceTreeWidgetItem *>(ui->treeWidget->itemAt(pos))) {
QMenu treeMenu{};
treeMenu.addActions(selectedItem->actions());
if (!treeMenu.isEmpty()) {
treeMenu.exec(mapToGlobal(pos));
}
}
}