DataSourceWidget.cpp
63 lines
| 1.9 KiB
| text/x-c
|
CppLexer
Alexandre Leroux
|
r82 | #include <DataSource/DataSourceWidget.h> | ||
#include <ui_DataSourceWidget.h> | ||||
r1495 | #include <DataSource/datasources.h> | |||
r1497 | #include <QCompleter> | |||
r1495 | #include <SqpApplication.h> | |||
Alexandre Leroux
|
r82 | |||
r1497 | #include <QAction> | |||
Alexandre Leroux
|
r143 | |||
r1478 | namespace | |||
{ | ||||
Alexandre Leroux
|
r82 | |||
/// Number of columns displayed in the tree | ||||
const auto TREE_NB_COLUMNS = 1; | ||||
/// Header labels for the tree | ||||
r1478 | const auto TREE_HEADER_LABELS = QStringList { QObject::tr("Name") }; | |||
Alexandre Leroux
|
r82 | |||
} // namespace | ||||
r1478 | DataSourceWidget::DataSourceWidget(QWidget* parent) | |||
r1497 | : QWidget { parent }, ui { new Ui::DataSourceWidget } | |||
Alexandre Leroux
|
r82 | { | ||
Alexandre Leroux
|
r109 | ui->setupUi(this); | ||
r1495 | m_model_proxy.setSourceModel(&(sqpApp->dataSources())); | |||
ui->treeView->setModel(&m_model_proxy); | ||||
ui->treeView->setDragEnabled(true); | ||||
m_model_proxy.setFilterRole(Qt::ToolTipRole); | ||||
m_model_proxy.setRecursiveFilteringEnabled(true); | ||||
Alexandre Leroux
|
r475 | |||
// Connection to filter tree | ||||
r1497 | connect(ui->filterLineEdit, &QLineEdit::textChanged, &m_model_proxy, | |||
static_cast<void (QSortFilterProxyModel::*)(const QString&)>( | ||||
&QSortFilterProxyModel::setFilterRegExp)); | ||||
sqpApp->dataSources().addIcon("satellite", QVariant(QIcon(":/icones/satellite.svg"))); | ||||
QAction* expandAll = new QAction("Expand all"); | ||||
QAction* collapseAll = new QAction("Collapse all"); | ||||
ui->treeView->addAction(expandAll); | ||||
ui->treeView->addAction(collapseAll); | ||||
ui->treeView->setContextMenuPolicy(Qt::ActionsContextMenu); | ||||
connect(expandAll, &QAction::triggered, [treeView = ui->treeView](bool checked) { | ||||
(void)checked; | ||||
treeView->expandAll(); | ||||
}); | ||||
connect(collapseAll, &QAction::triggered, [treeView = ui->treeView](bool checked) { | ||||
(void)checked; | ||||
treeView->collapseAll(); | ||||
}); | ||||
QCompleter* completer = new QCompleter(this); | ||||
completer->setModel(sqpApp->dataSources().completionModel()); | ||||
completer->setCaseSensitivity(Qt::CaseInsensitive); | ||||
ui->filterLineEdit->setCompleter(completer); | ||||
Alexandre Leroux
|
r82 | } | ||
Alexandre Leroux
|
r83 | |||
r232 | DataSourceWidget::~DataSourceWidget() noexcept | |||
{ | ||||
delete ui; | ||||
} | ||||