@@ -1,100 +1,100 | |||||
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/DataSourceTreeWidgetHelper.h> |
|
6 | #include <DataSource/DataSourceTreeWidgetHelper.h> | |
7 | #include <DataSource/DataSourceTreeWidgetItem.h> |
|
7 | #include <DataSource/DataSourceTreeWidgetItem.h> | |
8 |
|
8 | |||
9 | #include <QMenu> |
|
9 | #include <QMenu> | |
10 |
|
10 | |||
11 | namespace { |
|
11 | namespace { | |
12 |
|
12 | |||
13 | /// Number of columns displayed in the tree |
|
13 | /// Number of columns displayed in the tree | |
14 | const auto TREE_NB_COLUMNS = 1; |
|
14 | const auto TREE_NB_COLUMNS = 1; | |
15 |
|
15 | |||
16 | /// Header labels for the tree |
|
16 | /// Header labels for the tree | |
17 | const auto TREE_HEADER_LABELS = QStringList{QObject::tr("Name")}; |
|
17 | const auto TREE_HEADER_LABELS = QStringList{QObject::tr("Name")}; | |
18 |
|
18 | |||
19 | /** |
|
19 | /** | |
20 | * Creates the item associated to a data source |
|
20 | * Creates the item associated to a data source | |
21 | * @param dataSource the data source for which to create the item |
|
21 | * @param dataSource the data source for which to create the item | |
22 | * @return the new item |
|
22 | * @return the new item | |
23 | */ |
|
23 | */ | |
24 | DataSourceTreeWidgetItem *createTreeWidgetItem(DataSourceItem *dataSource) |
|
24 | DataSourceTreeWidgetItem *createTreeWidgetItem(DataSourceItem *dataSource) | |
25 | { |
|
25 | { | |
26 | // Creates item for the data source |
|
26 | // Creates item for the data source | |
27 | auto item = new DataSourceTreeWidgetItem{dataSource}; |
|
27 | auto item = new DataSourceTreeWidgetItem{dataSource}; | |
28 |
|
28 | |||
29 | // Generates items for the children of the data source |
|
29 | // Generates items for the children of the data source | |
30 | for (auto i = 0; i < dataSource->childCount(); ++i) { |
|
30 | for (auto i = 0; i < dataSource->childCount(); ++i) { | |
31 | item->addChild(createTreeWidgetItem(dataSource->child(i))); |
|
31 | item->addChild(createTreeWidgetItem(dataSource->child(i))); | |
32 | } |
|
32 | } | |
33 |
|
33 | |||
34 | return item; |
|
34 | return item; | |
35 | } |
|
35 | } | |
36 |
|
36 | |||
37 | } // namespace |
|
37 | } // namespace | |
38 |
|
38 | |||
39 | DataSourceWidget::DataSourceWidget(QWidget *parent) : QWidget{parent}, ui{new Ui::DataSourceWidget} |
|
39 | DataSourceWidget::DataSourceWidget(QWidget *parent) : QWidget{parent}, ui{new Ui::DataSourceWidget} | |
40 | { |
|
40 | { | |
41 | ui->setupUi(this); |
|
41 | ui->setupUi(this); | |
42 |
|
42 | |||
43 | // Set tree properties |
|
43 | // Set tree properties | |
44 | ui->treeWidget->setColumnCount(TREE_NB_COLUMNS); |
|
44 | ui->treeWidget->setColumnCount(TREE_NB_COLUMNS); | |
45 | ui->treeWidget->setHeaderLabels(TREE_HEADER_LABELS); |
|
45 | ui->treeWidget->setHeaderLabels(TREE_HEADER_LABELS); | |
46 | ui->treeWidget->setContextMenuPolicy(Qt::CustomContextMenu); |
|
46 | ui->treeWidget->setContextMenuPolicy(Qt::CustomContextMenu); | |
47 |
|
47 | |||
48 | // Connection to show a menu when right clicking on the tree |
|
48 | // Connection to show a menu when right clicking on the tree | |
49 | connect(ui->treeWidget, &QTreeWidget::customContextMenuRequested, this, |
|
49 | connect(ui->treeWidget, &QTreeWidget::customContextMenuRequested, this, | |
50 | &DataSourceWidget::onTreeMenuRequested); |
|
50 | &DataSourceWidget::onTreeMenuRequested); | |
51 |
|
51 | |||
52 | // Connection to filter tree |
|
52 | // Connection to filter tree | |
53 | connect(ui->filterLineEdit, &QLineEdit::textChanged, this, &DataSourceWidget::filterChanged); |
|
53 | connect(ui->filterLineEdit, &QLineEdit::textChanged, this, &DataSourceWidget::filterChanged); | |
54 | } |
|
54 | } | |
55 |
|
55 | |||
56 | DataSourceWidget::~DataSourceWidget() noexcept |
|
56 | DataSourceWidget::~DataSourceWidget() noexcept | |
57 | { |
|
57 | { | |
58 | delete ui; |
|
58 | delete ui; | |
59 | } |
|
59 | } | |
60 |
|
60 | |||
61 | void DataSourceWidget::addDataSource(DataSourceItem *dataSource) noexcept |
|
61 | void DataSourceWidget::addDataSource(DataSourceItem *dataSource) noexcept | |
62 | { |
|
62 | { | |
63 | // Creates the item associated to the source and adds it to the tree widget. The tree widget |
|
63 | // Creates the item associated to the source and adds it to the tree widget. The tree widget | |
64 | // takes the ownership of the item |
|
64 | // takes the ownership of the item | |
65 | if (dataSource) { |
|
65 | if (dataSource) { | |
66 | ui->treeWidget->addTopLevelItem(createTreeWidgetItem(dataSource)); |
|
66 | ui->treeWidget->addTopLevelItem(createTreeWidgetItem(dataSource)); | |
67 | } |
|
67 | } | |
68 | } |
|
68 | } | |
69 |
|
69 | |||
70 | void DataSourceWidget::filterChanged(const QString &text) noexcept |
|
70 | void DataSourceWidget::filterChanged(const QString &text) noexcept | |
71 | { |
|
71 | { | |
72 | auto validateItem = [&text](const DataSourceTreeWidgetItem &item) { |
|
72 | auto validateItem = [&text](const DataSourceTreeWidgetItem &item) { | |
73 | auto regExp = QRegExp{text, Qt::CaseInsensitive, QRegExp::Wildcard}; |
|
73 | auto regExp = QRegExp{text, Qt::CaseInsensitive, QRegExp::Wildcard}; | |
74 |
|
74 | |||
75 | // An item is valid if any of its metadata validates the text filter |
|
75 | // An item is valid if any of its metadata validates the text filter | |
76 | auto itemMetadata = item.data()->data(); |
|
76 | auto itemMetadata = item.data()->data(); | |
77 | auto itemMetadataEnd = itemMetadata.cend(); |
|
77 | auto itemMetadataEnd = itemMetadata.cend(); | |
78 | auto acceptFilter |
|
78 | auto acceptFilter | |
79 | = [®Exp](const auto &variant) { return variant.toString().contains(regExp); }; |
|
79 | = [®Exp](const auto &variant) { return variant.toString().contains(regExp); }; | |
80 |
|
80 | |||
81 | return std::find_if(itemMetadata.cbegin(), itemMetadataEnd, acceptFilter) |
|
81 | return std::find_if(itemMetadata.cbegin(), itemMetadataEnd, acceptFilter) | |
82 | != itemMetadataEnd; |
|
82 | != itemMetadataEnd; | |
83 | }; |
|
83 | }; | |
84 |
|
84 | |||
85 | // Applies filter on tree widget |
|
85 | // Applies filter on tree widget | |
86 | DataSourceTreeWidgetHelper::filter(*ui->treeWidget, validateItem); |
|
86 | DataSourceTreeWidgetHelper::filter(*ui->treeWidget, validateItem); | |
87 | } |
|
87 | } | |
88 |
|
88 | |||
89 | void DataSourceWidget::onTreeMenuRequested(const QPoint &pos) noexcept |
|
89 | void DataSourceWidget::onTreeMenuRequested(const QPoint &pos) noexcept | |
90 | { |
|
90 | { | |
91 | // Retrieves the selected item in the tree, and build the menu from its actions |
|
91 | // Retrieves the selected item in the tree, and build the menu from its actions | |
92 | if (auto selectedItem = dynamic_cast<DataSourceTreeWidgetItem *>(ui->treeWidget->itemAt(pos))) { |
|
92 | if (auto selectedItem = dynamic_cast<DataSourceTreeWidgetItem *>(ui->treeWidget->itemAt(pos))) { | |
93 | QMenu treeMenu{}; |
|
93 | QMenu treeMenu{}; | |
94 | treeMenu.addActions(selectedItem->actions()); |
|
94 | treeMenu.addActions(selectedItem->actions()); | |
95 |
|
95 | |||
96 | if (!treeMenu.isEmpty()) { |
|
96 | if (!treeMenu.isEmpty()) { | |
97 |
treeMenu.exec( |
|
97 | treeMenu.exec(QCursor::pos()); | |
98 | } |
|
98 | } | |
99 | } |
|
99 | } | |
100 | } |
|
100 | } |
@@ -1,199 +1,199 | |||||
1 | #include <Variable/VariableController.h> |
|
1 | #include <Variable/VariableController.h> | |
2 | #include <Variable/VariableInspectorWidget.h> |
|
2 | #include <Variable/VariableInspectorWidget.h> | |
3 | #include <Variable/VariableMenuHeaderWidget.h> |
|
3 | #include <Variable/VariableMenuHeaderWidget.h> | |
4 | #include <Variable/VariableModel.h> |
|
4 | #include <Variable/VariableModel.h> | |
5 |
|
5 | |||
6 | #include <ui_VariableInspectorWidget.h> |
|
6 | #include <ui_VariableInspectorWidget.h> | |
7 |
|
7 | |||
8 | #include <QMouseEvent> |
|
8 | #include <QMouseEvent> | |
9 | #include <QSortFilterProxyModel> |
|
9 | #include <QSortFilterProxyModel> | |
10 | #include <QStyledItemDelegate> |
|
10 | #include <QStyledItemDelegate> | |
11 | #include <QWidgetAction> |
|
11 | #include <QWidgetAction> | |
12 |
|
12 | |||
13 | #include <SqpApplication.h> |
|
13 | #include <SqpApplication.h> | |
14 |
|
14 | |||
15 | Q_LOGGING_CATEGORY(LOG_VariableInspectorWidget, "VariableInspectorWidget") |
|
15 | Q_LOGGING_CATEGORY(LOG_VariableInspectorWidget, "VariableInspectorWidget") | |
16 |
|
16 | |||
17 |
|
17 | |||
18 | class QProgressBarItemDelegate : public QStyledItemDelegate { |
|
18 | class QProgressBarItemDelegate : public QStyledItemDelegate { | |
19 |
|
19 | |||
20 | public: |
|
20 | public: | |
21 | QProgressBarItemDelegate(QObject *parent) : QStyledItemDelegate{parent} {} |
|
21 | QProgressBarItemDelegate(QObject *parent) : QStyledItemDelegate{parent} {} | |
22 |
|
22 | |||
23 | void paint(QPainter *painter, const QStyleOptionViewItem &option, |
|
23 | void paint(QPainter *painter, const QStyleOptionViewItem &option, | |
24 | const QModelIndex &index) const |
|
24 | const QModelIndex &index) const | |
25 | { |
|
25 | { | |
26 | auto data = index.data(Qt::DisplayRole); |
|
26 | auto data = index.data(Qt::DisplayRole); | |
27 | auto progressData = index.data(VariableRoles::ProgressRole); |
|
27 | auto progressData = index.data(VariableRoles::ProgressRole); | |
28 | if (data.isValid() && progressData.isValid()) { |
|
28 | if (data.isValid() && progressData.isValid()) { | |
29 | auto name = data.value<QString>(); |
|
29 | auto name = data.value<QString>(); | |
30 | auto progress = progressData.value<double>(); |
|
30 | auto progress = progressData.value<double>(); | |
31 | if (progress > 0) { |
|
31 | if (progress > 0) { | |
32 | auto cancelButtonWidth = 20; |
|
32 | auto cancelButtonWidth = 20; | |
33 | auto progressBarOption = QStyleOptionProgressBar{}; |
|
33 | auto progressBarOption = QStyleOptionProgressBar{}; | |
34 | auto progressRect = option.rect; |
|
34 | auto progressRect = option.rect; | |
35 | progressRect.setWidth(progressRect.width() - cancelButtonWidth); |
|
35 | progressRect.setWidth(progressRect.width() - cancelButtonWidth); | |
36 | progressBarOption.rect = progressRect; |
|
36 | progressBarOption.rect = progressRect; | |
37 | progressBarOption.minimum = 0; |
|
37 | progressBarOption.minimum = 0; | |
38 | progressBarOption.maximum = 100; |
|
38 | progressBarOption.maximum = 100; | |
39 | progressBarOption.progress = progress; |
|
39 | progressBarOption.progress = progress; | |
40 | progressBarOption.text |
|
40 | progressBarOption.text | |
41 | = QString("%1 %2").arg(name).arg(QString::number(progress, 'f', 2) + "%"); |
|
41 | = QString("%1 %2").arg(name).arg(QString::number(progress, 'f', 2) + "%"); | |
42 | progressBarOption.textVisible = true; |
|
42 | progressBarOption.textVisible = true; | |
43 | progressBarOption.textAlignment = Qt::AlignCenter; |
|
43 | progressBarOption.textAlignment = Qt::AlignCenter; | |
44 |
|
44 | |||
45 |
|
45 | |||
46 | QApplication::style()->drawControl(QStyle::CE_ProgressBar, &progressBarOption, |
|
46 | QApplication::style()->drawControl(QStyle::CE_ProgressBar, &progressBarOption, | |
47 | painter); |
|
47 | painter); | |
48 |
|
48 | |||
49 | // Cancel button |
|
49 | // Cancel button | |
50 | auto buttonRect = QRect(progressRect.right(), option.rect.top(), cancelButtonWidth, |
|
50 | auto buttonRect = QRect(progressRect.right(), option.rect.top(), cancelButtonWidth, | |
51 | option.rect.height()); |
|
51 | option.rect.height()); | |
52 | auto buttonOption = QStyleOptionButton{}; |
|
52 | auto buttonOption = QStyleOptionButton{}; | |
53 | buttonOption.rect = buttonRect; |
|
53 | buttonOption.rect = buttonRect; | |
54 | buttonOption.text = "X"; |
|
54 | buttonOption.text = "X"; | |
55 |
|
55 | |||
56 | QApplication::style()->drawControl(QStyle::CE_PushButton, &buttonOption, painter); |
|
56 | QApplication::style()->drawControl(QStyle::CE_PushButton, &buttonOption, painter); | |
57 | } |
|
57 | } | |
58 | else { |
|
58 | else { | |
59 | QStyledItemDelegate::paint(painter, option, index); |
|
59 | QStyledItemDelegate::paint(painter, option, index); | |
60 | } |
|
60 | } | |
61 | } |
|
61 | } | |
62 | else { |
|
62 | else { | |
63 | QStyledItemDelegate::paint(painter, option, index); |
|
63 | QStyledItemDelegate::paint(painter, option, index); | |
64 | } |
|
64 | } | |
65 | } |
|
65 | } | |
66 |
|
66 | |||
67 | bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, |
|
67 | bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, | |
68 | const QModelIndex &index) |
|
68 | const QModelIndex &index) | |
69 | { |
|
69 | { | |
70 | if (event->type() == QEvent::MouseButtonRelease) { |
|
70 | if (event->type() == QEvent::MouseButtonRelease) { | |
71 | auto data = index.data(Qt::DisplayRole); |
|
71 | auto data = index.data(Qt::DisplayRole); | |
72 | auto progressData = index.data(VariableRoles::ProgressRole); |
|
72 | auto progressData = index.data(VariableRoles::ProgressRole); | |
73 | if (data.isValid() && progressData.isValid()) { |
|
73 | if (data.isValid() && progressData.isValid()) { | |
74 | auto cancelButtonWidth = 20; |
|
74 | auto cancelButtonWidth = 20; | |
75 | auto progressRect = option.rect; |
|
75 | auto progressRect = option.rect; | |
76 | progressRect.setWidth(progressRect.width() - cancelButtonWidth); |
|
76 | progressRect.setWidth(progressRect.width() - cancelButtonWidth); | |
77 | // Cancel button |
|
77 | // Cancel button | |
78 | auto buttonRect = QRect(progressRect.right(), option.rect.top(), cancelButtonWidth, |
|
78 | auto buttonRect = QRect(progressRect.right(), option.rect.top(), cancelButtonWidth, | |
79 | option.rect.height()); |
|
79 | option.rect.height()); | |
80 |
|
80 | |||
81 | auto e = (QMouseEvent *)event; |
|
81 | auto e = (QMouseEvent *)event; | |
82 | auto clickX = e->x(); |
|
82 | auto clickX = e->x(); | |
83 | auto clickY = e->y(); |
|
83 | auto clickY = e->y(); | |
84 |
|
84 | |||
85 | auto x = buttonRect.left(); // the X coordinate |
|
85 | auto x = buttonRect.left(); // the X coordinate | |
86 | auto y = buttonRect.top(); // the Y coordinate |
|
86 | auto y = buttonRect.top(); // the Y coordinate | |
87 | auto w = buttonRect.width(); // button width |
|
87 | auto w = buttonRect.width(); // button width | |
88 | auto h = buttonRect.height(); // button height |
|
88 | auto h = buttonRect.height(); // button height | |
89 |
|
89 | |||
90 | if (clickX > x && clickX < x + w) { |
|
90 | if (clickX > x && clickX < x + w) { | |
91 | if (clickY > y && clickY < y + h) { |
|
91 | if (clickY > y && clickY < y + h) { | |
92 | auto variableModel = sqpApp->variableController().variableModel(); |
|
92 | auto variableModel = sqpApp->variableController().variableModel(); | |
93 | variableModel->abortProgress(index); |
|
93 | variableModel->abortProgress(index); | |
94 | } |
|
94 | } | |
95 | } |
|
95 | } | |
96 | else { |
|
96 | else { | |
97 | QStyledItemDelegate::editorEvent(event, model, option, index); |
|
97 | QStyledItemDelegate::editorEvent(event, model, option, index); | |
98 | } |
|
98 | } | |
99 | } |
|
99 | } | |
100 | else { |
|
100 | else { | |
101 | QStyledItemDelegate::editorEvent(event, model, option, index); |
|
101 | QStyledItemDelegate::editorEvent(event, model, option, index); | |
102 | } |
|
102 | } | |
103 | } |
|
103 | } | |
104 | else { |
|
104 | else { | |
105 | QStyledItemDelegate::editorEvent(event, model, option, index); |
|
105 | QStyledItemDelegate::editorEvent(event, model, option, index); | |
106 | } |
|
106 | } | |
107 | } |
|
107 | } | |
108 | }; |
|
108 | }; | |
109 |
|
109 | |||
110 | VariableInspectorWidget::VariableInspectorWidget(QWidget *parent) |
|
110 | VariableInspectorWidget::VariableInspectorWidget(QWidget *parent) | |
111 | : QWidget{parent}, |
|
111 | : QWidget{parent}, | |
112 | ui{new Ui::VariableInspectorWidget}, |
|
112 | ui{new Ui::VariableInspectorWidget}, | |
113 | m_ProgressBarItemDelegate{new QProgressBarItemDelegate{this}} |
|
113 | m_ProgressBarItemDelegate{new QProgressBarItemDelegate{this}} | |
114 | { |
|
114 | { | |
115 | ui->setupUi(this); |
|
115 | ui->setupUi(this); | |
116 |
|
116 | |||
117 | // Sets model for table |
|
117 | // Sets model for table | |
118 | // auto sortFilterModel = new QSortFilterProxyModel{this}; |
|
118 | // auto sortFilterModel = new QSortFilterProxyModel{this}; | |
119 | // sortFilterModel->setSourceModel(sqpApp->variableController().variableModel()); |
|
119 | // sortFilterModel->setSourceModel(sqpApp->variableController().variableModel()); | |
120 |
|
120 | |||
121 | auto variableModel = sqpApp->variableController().variableModel(); |
|
121 | auto variableModel = sqpApp->variableController().variableModel(); | |
122 | ui->tableView->setModel(variableModel); |
|
122 | ui->tableView->setModel(variableModel); | |
123 |
|
123 | |||
124 | // Adds extra signal/slot between view and model, so the view can be updated instantly when |
|
124 | // Adds extra signal/slot between view and model, so the view can be updated instantly when | |
125 | // there is a change of data in the model |
|
125 | // there is a change of data in the model | |
126 | connect(variableModel, SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)), this, |
|
126 | connect(variableModel, SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)), this, | |
127 | SLOT(refresh())); |
|
127 | SLOT(refresh())); | |
128 |
|
128 | |||
129 | ui->tableView->setSelectionModel(sqpApp->variableController().variableSelectionModel()); |
|
129 | ui->tableView->setSelectionModel(sqpApp->variableController().variableSelectionModel()); | |
130 | ui->tableView->setItemDelegateForColumn(0, m_ProgressBarItemDelegate); |
|
130 | ui->tableView->setItemDelegateForColumn(0, m_ProgressBarItemDelegate); | |
131 |
|
131 | |||
132 | // Fixes column sizes |
|
132 | // Fixes column sizes | |
133 | auto model = ui->tableView->model(); |
|
133 | auto model = ui->tableView->model(); | |
134 | const auto count = model->columnCount(); |
|
134 | const auto count = model->columnCount(); | |
135 | for (auto i = 0; i < count; ++i) { |
|
135 | for (auto i = 0; i < count; ++i) { | |
136 | ui->tableView->setColumnWidth( |
|
136 | ui->tableView->setColumnWidth( | |
137 | i, model->headerData(i, Qt::Horizontal, Qt::SizeHintRole).toSize().width()); |
|
137 | i, model->headerData(i, Qt::Horizontal, Qt::SizeHintRole).toSize().width()); | |
138 | } |
|
138 | } | |
139 |
|
139 | |||
140 | // Sets selection options |
|
140 | // Sets selection options | |
141 | ui->tableView->setSelectionBehavior(QTableView::SelectRows); |
|
141 | ui->tableView->setSelectionBehavior(QTableView::SelectRows); | |
142 | ui->tableView->setSelectionMode(QTableView::ExtendedSelection); |
|
142 | ui->tableView->setSelectionMode(QTableView::ExtendedSelection); | |
143 |
|
143 | |||
144 | // Connection to show a menu when right clicking on the tree |
|
144 | // Connection to show a menu when right clicking on the tree | |
145 | ui->tableView->setContextMenuPolicy(Qt::CustomContextMenu); |
|
145 | ui->tableView->setContextMenuPolicy(Qt::CustomContextMenu); | |
146 | connect(ui->tableView, &QTableView::customContextMenuRequested, this, |
|
146 | connect(ui->tableView, &QTableView::customContextMenuRequested, this, | |
147 | &VariableInspectorWidget::onTableMenuRequested); |
|
147 | &VariableInspectorWidget::onTableMenuRequested); | |
148 | } |
|
148 | } | |
149 |
|
149 | |||
150 | VariableInspectorWidget::~VariableInspectorWidget() |
|
150 | VariableInspectorWidget::~VariableInspectorWidget() | |
151 | { |
|
151 | { | |
152 | delete ui; |
|
152 | delete ui; | |
153 | } |
|
153 | } | |
154 |
|
154 | |||
155 | void VariableInspectorWidget::onTableMenuRequested(const QPoint &pos) noexcept |
|
155 | void VariableInspectorWidget::onTableMenuRequested(const QPoint &pos) noexcept | |
156 | { |
|
156 | { | |
157 | auto selectedRows = ui->tableView->selectionModel()->selectedRows(); |
|
157 | auto selectedRows = ui->tableView->selectionModel()->selectedRows(); | |
158 |
|
158 | |||
159 | // Gets the model to retrieve the underlying selected variables |
|
159 | // Gets the model to retrieve the underlying selected variables | |
160 | auto model = sqpApp->variableController().variableModel(); |
|
160 | auto model = sqpApp->variableController().variableModel(); | |
161 | auto selectedVariables = QVector<std::shared_ptr<Variable> >{}; |
|
161 | auto selectedVariables = QVector<std::shared_ptr<Variable> >{}; | |
162 | for (const auto &selectedRow : qAsConst(selectedRows)) { |
|
162 | for (const auto &selectedRow : qAsConst(selectedRows)) { | |
163 | if (auto selectedVariable = model->variable(selectedRow.row())) { |
|
163 | if (auto selectedVariable = model->variable(selectedRow.row())) { | |
164 | selectedVariables.push_back(selectedVariable); |
|
164 | selectedVariables.push_back(selectedVariable); | |
165 | } |
|
165 | } | |
166 | } |
|
166 | } | |
167 |
|
167 | |||
168 | QMenu tableMenu{}; |
|
168 | QMenu tableMenu{}; | |
169 |
|
169 | |||
170 | // Emits a signal so that potential receivers can populate the menu before displaying it |
|
170 | // Emits a signal so that potential receivers can populate the menu before displaying it | |
171 | emit tableMenuAboutToBeDisplayed(&tableMenu, selectedVariables); |
|
171 | emit tableMenuAboutToBeDisplayed(&tableMenu, selectedVariables); | |
172 |
|
172 | |||
173 | // Adds menu-specific actions |
|
173 | // Adds menu-specific actions | |
174 | if (!selectedVariables.isEmpty()) { |
|
174 | if (!selectedVariables.isEmpty()) { | |
175 | // 'Delete' action |
|
175 | // 'Delete' action | |
176 | auto deleteFun = [&selectedVariables]() { |
|
176 | auto deleteFun = [&selectedVariables]() { | |
177 | sqpApp->variableController().deleteVariables(selectedVariables); |
|
177 | sqpApp->variableController().deleteVariables(selectedVariables); | |
178 | }; |
|
178 | }; | |
179 |
|
179 | |||
180 | tableMenu.addSeparator(); |
|
180 | tableMenu.addSeparator(); | |
181 | tableMenu.addAction(QIcon{":/icones/delete.png"}, tr("Delete"), deleteFun); |
|
181 | tableMenu.addAction(QIcon{":/icones/delete.png"}, tr("Delete"), deleteFun); | |
182 | } |
|
182 | } | |
183 |
|
183 | |||
184 | if (!tableMenu.isEmpty()) { |
|
184 | if (!tableMenu.isEmpty()) { | |
185 | // Generates menu header (inserted before first action) |
|
185 | // Generates menu header (inserted before first action) | |
186 | auto firstAction = tableMenu.actions().first(); |
|
186 | auto firstAction = tableMenu.actions().first(); | |
187 | auto headerAction = new QWidgetAction{&tableMenu}; |
|
187 | auto headerAction = new QWidgetAction{&tableMenu}; | |
188 | headerAction->setDefaultWidget(new VariableMenuHeaderWidget{selectedVariables, &tableMenu}); |
|
188 | headerAction->setDefaultWidget(new VariableMenuHeaderWidget{selectedVariables, &tableMenu}); | |
189 | tableMenu.insertAction(firstAction, headerAction); |
|
189 | tableMenu.insertAction(firstAction, headerAction); | |
190 |
|
190 | |||
191 | // Displays menu |
|
191 | // Displays menu | |
192 |
tableMenu.exec( |
|
192 | tableMenu.exec(QCursor::pos()); | |
193 | } |
|
193 | } | |
194 | } |
|
194 | } | |
195 |
|
195 | |||
196 | void VariableInspectorWidget::refresh() noexcept |
|
196 | void VariableInspectorWidget::refresh() noexcept | |
197 | { |
|
197 | { | |
198 | ui->tableView->viewport()->update(); |
|
198 | ui->tableView->viewport()->update(); | |
199 | } |
|
199 | } |
@@ -1,313 +1,313 | |||||
1 | #include "Visualization/VisualizationGraphWidget.h" |
|
1 | #include "Visualization/VisualizationGraphWidget.h" | |
2 | #include "Visualization/IVisualizationWidgetVisitor.h" |
|
2 | #include "Visualization/IVisualizationWidgetVisitor.h" | |
3 | #include "Visualization/VisualizationDefs.h" |
|
3 | #include "Visualization/VisualizationDefs.h" | |
4 | #include "Visualization/VisualizationGraphHelper.h" |
|
4 | #include "Visualization/VisualizationGraphHelper.h" | |
5 | #include "Visualization/VisualizationGraphRenderingDelegate.h" |
|
5 | #include "Visualization/VisualizationGraphRenderingDelegate.h" | |
6 | #include "ui_VisualizationGraphWidget.h" |
|
6 | #include "ui_VisualizationGraphWidget.h" | |
7 |
|
7 | |||
8 | #include <Data/ArrayData.h> |
|
8 | #include <Data/ArrayData.h> | |
9 | #include <Data/IDataSeries.h> |
|
9 | #include <Data/IDataSeries.h> | |
10 | #include <Settings/SqpSettingsDefs.h> |
|
10 | #include <Settings/SqpSettingsDefs.h> | |
11 | #include <SqpApplication.h> |
|
11 | #include <SqpApplication.h> | |
12 | #include <Variable/Variable.h> |
|
12 | #include <Variable/Variable.h> | |
13 | #include <Variable/VariableController.h> |
|
13 | #include <Variable/VariableController.h> | |
14 |
|
14 | |||
15 | #include <unordered_map> |
|
15 | #include <unordered_map> | |
16 |
|
16 | |||
17 | Q_LOGGING_CATEGORY(LOG_VisualizationGraphWidget, "VisualizationGraphWidget") |
|
17 | Q_LOGGING_CATEGORY(LOG_VisualizationGraphWidget, "VisualizationGraphWidget") | |
18 |
|
18 | |||
19 | namespace { |
|
19 | namespace { | |
20 |
|
20 | |||
21 | /// Key pressed to enable zoom on horizontal axis |
|
21 | /// Key pressed to enable zoom on horizontal axis | |
22 | const auto HORIZONTAL_ZOOM_MODIFIER = Qt::NoModifier; |
|
22 | const auto HORIZONTAL_ZOOM_MODIFIER = Qt::NoModifier; | |
23 |
|
23 | |||
24 | /// Key pressed to enable zoom on vertical axis |
|
24 | /// Key pressed to enable zoom on vertical axis | |
25 | const auto VERTICAL_ZOOM_MODIFIER = Qt::ControlModifier; |
|
25 | const auto VERTICAL_ZOOM_MODIFIER = Qt::ControlModifier; | |
26 |
|
26 | |||
27 | } // namespace |
|
27 | } // namespace | |
28 |
|
28 | |||
29 | struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate { |
|
29 | struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate { | |
30 |
|
30 | |||
31 | explicit VisualizationGraphWidgetPrivate() |
|
31 | explicit VisualizationGraphWidgetPrivate() | |
32 | : m_DoAcquisition{true}, m_IsCalibration{false}, m_RenderingDelegate{nullptr} |
|
32 | : m_DoAcquisition{true}, m_IsCalibration{false}, m_RenderingDelegate{nullptr} | |
33 | { |
|
33 | { | |
34 | } |
|
34 | } | |
35 |
|
35 | |||
36 | // 1 variable -> n qcpplot |
|
36 | // 1 variable -> n qcpplot | |
37 | std::map<std::shared_ptr<Variable>, PlottablesMap> m_VariableToPlotMultiMap; |
|
37 | std::map<std::shared_ptr<Variable>, PlottablesMap> m_VariableToPlotMultiMap; | |
38 | bool m_DoAcquisition; |
|
38 | bool m_DoAcquisition; | |
39 | bool m_IsCalibration; |
|
39 | bool m_IsCalibration; | |
40 | QCPItemTracer *m_TextTracer; |
|
40 | QCPItemTracer *m_TextTracer; | |
41 | /// Delegate used to attach rendering features to the plot |
|
41 | /// Delegate used to attach rendering features to the plot | |
42 | std::unique_ptr<VisualizationGraphRenderingDelegate> m_RenderingDelegate; |
|
42 | std::unique_ptr<VisualizationGraphRenderingDelegate> m_RenderingDelegate; | |
43 | }; |
|
43 | }; | |
44 |
|
44 | |||
45 | VisualizationGraphWidget::VisualizationGraphWidget(const QString &name, QWidget *parent) |
|
45 | VisualizationGraphWidget::VisualizationGraphWidget(const QString &name, QWidget *parent) | |
46 | : QWidget{parent}, |
|
46 | : QWidget{parent}, | |
47 | ui{new Ui::VisualizationGraphWidget}, |
|
47 | ui{new Ui::VisualizationGraphWidget}, | |
48 | impl{spimpl::make_unique_impl<VisualizationGraphWidgetPrivate>()} |
|
48 | impl{spimpl::make_unique_impl<VisualizationGraphWidgetPrivate>()} | |
49 | { |
|
49 | { | |
50 | ui->setupUi(this); |
|
50 | ui->setupUi(this); | |
51 |
|
51 | |||
52 | // The delegate must be initialized after the ui as it uses the plot |
|
52 | // The delegate must be initialized after the ui as it uses the plot | |
53 | impl->m_RenderingDelegate = std::make_unique<VisualizationGraphRenderingDelegate>(*ui->widget); |
|
53 | impl->m_RenderingDelegate = std::make_unique<VisualizationGraphRenderingDelegate>(*ui->widget); | |
54 |
|
54 | |||
55 | ui->graphNameLabel->setText(name); |
|
55 | ui->graphNameLabel->setText(name); | |
56 |
|
56 | |||
57 | // 'Close' options : widget is deleted when closed |
|
57 | // 'Close' options : widget is deleted when closed | |
58 | setAttribute(Qt::WA_DeleteOnClose); |
|
58 | setAttribute(Qt::WA_DeleteOnClose); | |
59 | connect(ui->closeButton, &QToolButton::clicked, this, &VisualizationGraphWidget::close); |
|
59 | connect(ui->closeButton, &QToolButton::clicked, this, &VisualizationGraphWidget::close); | |
60 | ui->closeButton->setIcon(sqpApp->style()->standardIcon(QStyle::SP_TitleBarCloseButton)); |
|
60 | ui->closeButton->setIcon(sqpApp->style()->standardIcon(QStyle::SP_TitleBarCloseButton)); | |
61 |
|
61 | |||
62 | // Set qcpplot properties : |
|
62 | // Set qcpplot properties : | |
63 | // - Drag (on x-axis) and zoom are enabled |
|
63 | // - Drag (on x-axis) and zoom are enabled | |
64 | // - Mouse wheel on qcpplot is intercepted to determine the zoom orientation |
|
64 | // - Mouse wheel on qcpplot is intercepted to determine the zoom orientation | |
65 | ui->widget->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); |
|
65 | ui->widget->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); | |
66 | ui->widget->axisRect()->setRangeDrag(Qt::Horizontal); |
|
66 | ui->widget->axisRect()->setRangeDrag(Qt::Horizontal); | |
67 |
|
67 | |||
68 | connect(ui->widget, &QCustomPlot::mousePress, this, &VisualizationGraphWidget::onMousePress); |
|
68 | connect(ui->widget, &QCustomPlot::mousePress, this, &VisualizationGraphWidget::onMousePress); | |
69 | connect(ui->widget, &QCustomPlot::mouseRelease, this, |
|
69 | connect(ui->widget, &QCustomPlot::mouseRelease, this, | |
70 | &VisualizationGraphWidget::onMouseRelease); |
|
70 | &VisualizationGraphWidget::onMouseRelease); | |
71 | connect(ui->widget, &QCustomPlot::mouseMove, this, &VisualizationGraphWidget::onMouseMove); |
|
71 | connect(ui->widget, &QCustomPlot::mouseMove, this, &VisualizationGraphWidget::onMouseMove); | |
72 | connect(ui->widget, &QCustomPlot::mouseWheel, this, &VisualizationGraphWidget::onMouseWheel); |
|
72 | connect(ui->widget, &QCustomPlot::mouseWheel, this, &VisualizationGraphWidget::onMouseWheel); | |
73 | connect(ui->widget->xAxis, static_cast<void (QCPAxis::*)(const QCPRange &, const QCPRange &)>( |
|
73 | connect(ui->widget->xAxis, static_cast<void (QCPAxis::*)(const QCPRange &, const QCPRange &)>( | |
74 | &QCPAxis::rangeChanged), |
|
74 | &QCPAxis::rangeChanged), | |
75 | this, &VisualizationGraphWidget::onRangeChanged, Qt::DirectConnection); |
|
75 | this, &VisualizationGraphWidget::onRangeChanged, Qt::DirectConnection); | |
76 |
|
76 | |||
77 | // Activates menu when right clicking on the graph |
|
77 | // Activates menu when right clicking on the graph | |
78 | ui->widget->setContextMenuPolicy(Qt::CustomContextMenu); |
|
78 | ui->widget->setContextMenuPolicy(Qt::CustomContextMenu); | |
79 | connect(ui->widget, &QCustomPlot::customContextMenuRequested, this, |
|
79 | connect(ui->widget, &QCustomPlot::customContextMenuRequested, this, | |
80 | &VisualizationGraphWidget::onGraphMenuRequested); |
|
80 | &VisualizationGraphWidget::onGraphMenuRequested); | |
81 |
|
81 | |||
82 | connect(this, &VisualizationGraphWidget::requestDataLoading, &sqpApp->variableController(), |
|
82 | connect(this, &VisualizationGraphWidget::requestDataLoading, &sqpApp->variableController(), | |
83 | &VariableController::onRequestDataLoading); |
|
83 | &VariableController::onRequestDataLoading); | |
84 |
|
84 | |||
85 | connect(&sqpApp->variableController(), &VariableController::updateVarDisplaying, this, |
|
85 | connect(&sqpApp->variableController(), &VariableController::updateVarDisplaying, this, | |
86 | &VisualizationGraphWidget::onUpdateVarDisplaying); |
|
86 | &VisualizationGraphWidget::onUpdateVarDisplaying); | |
87 | } |
|
87 | } | |
88 |
|
88 | |||
89 |
|
89 | |||
90 | VisualizationGraphWidget::~VisualizationGraphWidget() |
|
90 | VisualizationGraphWidget::~VisualizationGraphWidget() | |
91 | { |
|
91 | { | |
92 | delete ui; |
|
92 | delete ui; | |
93 | } |
|
93 | } | |
94 |
|
94 | |||
95 | void VisualizationGraphWidget::enableAcquisition(bool enable) |
|
95 | void VisualizationGraphWidget::enableAcquisition(bool enable) | |
96 | { |
|
96 | { | |
97 | impl->m_DoAcquisition = enable; |
|
97 | impl->m_DoAcquisition = enable; | |
98 | } |
|
98 | } | |
99 |
|
99 | |||
100 | void VisualizationGraphWidget::addVariable(std::shared_ptr<Variable> variable, SqpRange range) |
|
100 | void VisualizationGraphWidget::addVariable(std::shared_ptr<Variable> variable, SqpRange range) | |
101 | { |
|
101 | { | |
102 | // Uses delegate to create the qcpplot components according to the variable |
|
102 | // Uses delegate to create the qcpplot components according to the variable | |
103 | auto createdPlottables = VisualizationGraphHelper::create(variable, *ui->widget); |
|
103 | auto createdPlottables = VisualizationGraphHelper::create(variable, *ui->widget); | |
104 | impl->m_VariableToPlotMultiMap.insert({variable, std::move(createdPlottables)}); |
|
104 | impl->m_VariableToPlotMultiMap.insert({variable, std::move(createdPlottables)}); | |
105 |
|
105 | |||
106 | connect(variable.get(), SIGNAL(updated()), this, SLOT(onDataCacheVariableUpdated())); |
|
106 | connect(variable.get(), SIGNAL(updated()), this, SLOT(onDataCacheVariableUpdated())); | |
107 |
|
107 | |||
108 | auto varRange = variable->range(); |
|
108 | auto varRange = variable->range(); | |
109 |
|
109 | |||
110 | this->enableAcquisition(false); |
|
110 | this->enableAcquisition(false); | |
111 | this->setGraphRange(range); |
|
111 | this->setGraphRange(range); | |
112 | this->enableAcquisition(true); |
|
112 | this->enableAcquisition(true); | |
113 |
|
113 | |||
114 | emit requestDataLoading(QVector<std::shared_ptr<Variable> >() << variable, range, varRange, |
|
114 | emit requestDataLoading(QVector<std::shared_ptr<Variable> >() << variable, range, varRange, | |
115 | false); |
|
115 | false); | |
116 |
|
116 | |||
117 | emit variableAdded(variable); |
|
117 | emit variableAdded(variable); | |
118 | } |
|
118 | } | |
119 |
|
119 | |||
120 | void VisualizationGraphWidget::removeVariable(std::shared_ptr<Variable> variable) noexcept |
|
120 | void VisualizationGraphWidget::removeVariable(std::shared_ptr<Variable> variable) noexcept | |
121 | { |
|
121 | { | |
122 | // Each component associated to the variable : |
|
122 | // Each component associated to the variable : | |
123 | // - is removed from qcpplot (which deletes it) |
|
123 | // - is removed from qcpplot (which deletes it) | |
124 | // - is no longer referenced in the map |
|
124 | // - is no longer referenced in the map | |
125 | auto variableIt = impl->m_VariableToPlotMultiMap.find(variable); |
|
125 | auto variableIt = impl->m_VariableToPlotMultiMap.find(variable); | |
126 | if (variableIt != impl->m_VariableToPlotMultiMap.cend()) { |
|
126 | if (variableIt != impl->m_VariableToPlotMultiMap.cend()) { | |
127 | auto &plottablesMap = variableIt->second; |
|
127 | auto &plottablesMap = variableIt->second; | |
128 |
|
128 | |||
129 | for (auto plottableIt = plottablesMap.cbegin(), plottableEnd = plottablesMap.cend(); |
|
129 | for (auto plottableIt = plottablesMap.cbegin(), plottableEnd = plottablesMap.cend(); | |
130 | plottableIt != plottableEnd;) { |
|
130 | plottableIt != plottableEnd;) { | |
131 | ui->widget->removePlottable(plottableIt->second); |
|
131 | ui->widget->removePlottable(plottableIt->second); | |
132 | plottableIt = plottablesMap.erase(plottableIt); |
|
132 | plottableIt = plottablesMap.erase(plottableIt); | |
133 | } |
|
133 | } | |
134 |
|
134 | |||
135 | impl->m_VariableToPlotMultiMap.erase(variableIt); |
|
135 | impl->m_VariableToPlotMultiMap.erase(variableIt); | |
136 | } |
|
136 | } | |
137 |
|
137 | |||
138 | // Updates graph |
|
138 | // Updates graph | |
139 | ui->widget->replot(); |
|
139 | ui->widget->replot(); | |
140 | } |
|
140 | } | |
141 |
|
141 | |||
142 | void VisualizationGraphWidget::setRange(std::shared_ptr<Variable> variable, const SqpRange &range) |
|
142 | void VisualizationGraphWidget::setRange(std::shared_ptr<Variable> variable, const SqpRange &range) | |
143 | { |
|
143 | { | |
144 | // Note: in case of different axes that depends on variable, we could start with a code like |
|
144 | // Note: in case of different axes that depends on variable, we could start with a code like | |
145 | // that: |
|
145 | // that: | |
146 | // auto componentsIt = impl->m_VariableToPlotMultiMap.equal_range(variable); |
|
146 | // auto componentsIt = impl->m_VariableToPlotMultiMap.equal_range(variable); | |
147 | // for (auto it = componentsIt.first; it != componentsIt.second;) { |
|
147 | // for (auto it = componentsIt.first; it != componentsIt.second;) { | |
148 | // } |
|
148 | // } | |
149 | ui->widget->xAxis->setRange(range.m_TStart, range.m_TEnd); |
|
149 | ui->widget->xAxis->setRange(range.m_TStart, range.m_TEnd); | |
150 | ui->widget->replot(); |
|
150 | ui->widget->replot(); | |
151 | } |
|
151 | } | |
152 |
|
152 | |||
153 | void VisualizationGraphWidget::setYRange(const SqpRange &range) |
|
153 | void VisualizationGraphWidget::setYRange(const SqpRange &range) | |
154 | { |
|
154 | { | |
155 | ui->widget->yAxis->setRange(range.m_TStart, range.m_TEnd); |
|
155 | ui->widget->yAxis->setRange(range.m_TStart, range.m_TEnd); | |
156 | } |
|
156 | } | |
157 |
|
157 | |||
158 | SqpRange VisualizationGraphWidget::graphRange() const noexcept |
|
158 | SqpRange VisualizationGraphWidget::graphRange() const noexcept | |
159 | { |
|
159 | { | |
160 | auto graphRange = ui->widget->xAxis->range(); |
|
160 | auto graphRange = ui->widget->xAxis->range(); | |
161 | return SqpRange{graphRange.lower, graphRange.upper}; |
|
161 | return SqpRange{graphRange.lower, graphRange.upper}; | |
162 | } |
|
162 | } | |
163 |
|
163 | |||
164 | void VisualizationGraphWidget::setGraphRange(const SqpRange &range) |
|
164 | void VisualizationGraphWidget::setGraphRange(const SqpRange &range) | |
165 | { |
|
165 | { | |
166 | qCDebug(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::setGraphRange START"); |
|
166 | qCDebug(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::setGraphRange START"); | |
167 | ui->widget->xAxis->setRange(range.m_TStart, range.m_TEnd); |
|
167 | ui->widget->xAxis->setRange(range.m_TStart, range.m_TEnd); | |
168 | ui->widget->replot(); |
|
168 | ui->widget->replot(); | |
169 | qCDebug(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::setGraphRange END"); |
|
169 | qCDebug(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::setGraphRange END"); | |
170 | } |
|
170 | } | |
171 |
|
171 | |||
172 | void VisualizationGraphWidget::accept(IVisualizationWidgetVisitor *visitor) |
|
172 | void VisualizationGraphWidget::accept(IVisualizationWidgetVisitor *visitor) | |
173 | { |
|
173 | { | |
174 | if (visitor) { |
|
174 | if (visitor) { | |
175 | visitor->visit(this); |
|
175 | visitor->visit(this); | |
176 | } |
|
176 | } | |
177 | else { |
|
177 | else { | |
178 | qCCritical(LOG_VisualizationGraphWidget()) |
|
178 | qCCritical(LOG_VisualizationGraphWidget()) | |
179 | << tr("Can't visit widget : the visitor is null"); |
|
179 | << tr("Can't visit widget : the visitor is null"); | |
180 | } |
|
180 | } | |
181 | } |
|
181 | } | |
182 |
|
182 | |||
183 | bool VisualizationGraphWidget::canDrop(const Variable &variable) const |
|
183 | bool VisualizationGraphWidget::canDrop(const Variable &variable) const | |
184 | { |
|
184 | { | |
185 | /// @todo : for the moment, a graph can always accomodate a variable |
|
185 | /// @todo : for the moment, a graph can always accomodate a variable | |
186 | Q_UNUSED(variable); |
|
186 | Q_UNUSED(variable); | |
187 | return true; |
|
187 | return true; | |
188 | } |
|
188 | } | |
189 |
|
189 | |||
190 | bool VisualizationGraphWidget::contains(const Variable &variable) const |
|
190 | bool VisualizationGraphWidget::contains(const Variable &variable) const | |
191 | { |
|
191 | { | |
192 | // Finds the variable among the keys of the map |
|
192 | // Finds the variable among the keys of the map | |
193 | auto variablePtr = &variable; |
|
193 | auto variablePtr = &variable; | |
194 | auto findVariable |
|
194 | auto findVariable | |
195 | = [variablePtr](const auto &entry) { return variablePtr == entry.first.get(); }; |
|
195 | = [variablePtr](const auto &entry) { return variablePtr == entry.first.get(); }; | |
196 |
|
196 | |||
197 | auto end = impl->m_VariableToPlotMultiMap.cend(); |
|
197 | auto end = impl->m_VariableToPlotMultiMap.cend(); | |
198 | auto it = std::find_if(impl->m_VariableToPlotMultiMap.cbegin(), end, findVariable); |
|
198 | auto it = std::find_if(impl->m_VariableToPlotMultiMap.cbegin(), end, findVariable); | |
199 | return it != end; |
|
199 | return it != end; | |
200 | } |
|
200 | } | |
201 |
|
201 | |||
202 | QString VisualizationGraphWidget::name() const |
|
202 | QString VisualizationGraphWidget::name() const | |
203 | { |
|
203 | { | |
204 | return ui->graphNameLabel->text(); |
|
204 | return ui->graphNameLabel->text(); | |
205 | } |
|
205 | } | |
206 |
|
206 | |||
207 | void VisualizationGraphWidget::onGraphMenuRequested(const QPoint &pos) noexcept |
|
207 | void VisualizationGraphWidget::onGraphMenuRequested(const QPoint &pos) noexcept | |
208 | { |
|
208 | { | |
209 | QMenu graphMenu{}; |
|
209 | QMenu graphMenu{}; | |
210 |
|
210 | |||
211 | // Iterates on variables (unique keys) |
|
211 | // Iterates on variables (unique keys) | |
212 | for (auto it = impl->m_VariableToPlotMultiMap.cbegin(), |
|
212 | for (auto it = impl->m_VariableToPlotMultiMap.cbegin(), | |
213 | end = impl->m_VariableToPlotMultiMap.cend(); |
|
213 | end = impl->m_VariableToPlotMultiMap.cend(); | |
214 | it != end; it = impl->m_VariableToPlotMultiMap.upper_bound(it->first)) { |
|
214 | it != end; it = impl->m_VariableToPlotMultiMap.upper_bound(it->first)) { | |
215 | // 'Remove variable' action |
|
215 | // 'Remove variable' action | |
216 | graphMenu.addAction(tr("Remove variable %1").arg(it->first->name()), |
|
216 | graphMenu.addAction(tr("Remove variable %1").arg(it->first->name()), | |
217 | [ this, var = it->first ]() { removeVariable(var); }); |
|
217 | [ this, var = it->first ]() { removeVariable(var); }); | |
218 | } |
|
218 | } | |
219 |
|
219 | |||
220 | if (!graphMenu.isEmpty()) { |
|
220 | if (!graphMenu.isEmpty()) { | |
221 |
graphMenu.exec( |
|
221 | graphMenu.exec(QCursor::pos()); | |
222 | } |
|
222 | } | |
223 | } |
|
223 | } | |
224 |
|
224 | |||
225 | void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1, const QCPRange &t2) |
|
225 | void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1, const QCPRange &t2) | |
226 | { |
|
226 | { | |
227 | qCDebug(LOG_VisualizationGraphWidget()) << tr("TORM: VisualizationGraphWidget::onRangeChanged") |
|
227 | qCDebug(LOG_VisualizationGraphWidget()) << tr("TORM: VisualizationGraphWidget::onRangeChanged") | |
228 | << QThread::currentThread()->objectName() << "DoAcqui" |
|
228 | << QThread::currentThread()->objectName() << "DoAcqui" | |
229 | << impl->m_DoAcquisition; |
|
229 | << impl->m_DoAcquisition; | |
230 |
|
230 | |||
231 | auto graphRange = SqpRange{t1.lower, t1.upper}; |
|
231 | auto graphRange = SqpRange{t1.lower, t1.upper}; | |
232 | auto oldGraphRange = SqpRange{t2.lower, t2.upper}; |
|
232 | auto oldGraphRange = SqpRange{t2.lower, t2.upper}; | |
233 |
|
233 | |||
234 | if (impl->m_DoAcquisition) { |
|
234 | if (impl->m_DoAcquisition) { | |
235 | QVector<std::shared_ptr<Variable> > variableUnderGraphVector; |
|
235 | QVector<std::shared_ptr<Variable> > variableUnderGraphVector; | |
236 |
|
236 | |||
237 | for (auto it = impl->m_VariableToPlotMultiMap.begin(), |
|
237 | for (auto it = impl->m_VariableToPlotMultiMap.begin(), | |
238 | end = impl->m_VariableToPlotMultiMap.end(); |
|
238 | end = impl->m_VariableToPlotMultiMap.end(); | |
239 | it != end; it = impl->m_VariableToPlotMultiMap.upper_bound(it->first)) { |
|
239 | it != end; it = impl->m_VariableToPlotMultiMap.upper_bound(it->first)) { | |
240 | variableUnderGraphVector.push_back(it->first); |
|
240 | variableUnderGraphVector.push_back(it->first); | |
241 | } |
|
241 | } | |
242 | emit requestDataLoading(std::move(variableUnderGraphVector), graphRange, oldGraphRange, |
|
242 | emit requestDataLoading(std::move(variableUnderGraphVector), graphRange, oldGraphRange, | |
243 | !impl->m_IsCalibration); |
|
243 | !impl->m_IsCalibration); | |
244 |
|
244 | |||
245 | if (!impl->m_IsCalibration) { |
|
245 | if (!impl->m_IsCalibration) { | |
246 | qCDebug(LOG_VisualizationGraphWidget()) |
|
246 | qCDebug(LOG_VisualizationGraphWidget()) | |
247 | << tr("TORM: VisualizationGraphWidget::Synchronize notify !!") |
|
247 | << tr("TORM: VisualizationGraphWidget::Synchronize notify !!") | |
248 | << QThread::currentThread()->objectName() << graphRange << oldGraphRange; |
|
248 | << QThread::currentThread()->objectName() << graphRange << oldGraphRange; | |
249 | emit synchronize(graphRange, oldGraphRange); |
|
249 | emit synchronize(graphRange, oldGraphRange); | |
250 | } |
|
250 | } | |
251 | } |
|
251 | } | |
252 | } |
|
252 | } | |
253 |
|
253 | |||
254 | void VisualizationGraphWidget::onMouseMove(QMouseEvent *event) noexcept |
|
254 | void VisualizationGraphWidget::onMouseMove(QMouseEvent *event) noexcept | |
255 | { |
|
255 | { | |
256 | // Handles plot rendering when mouse is moving |
|
256 | // Handles plot rendering when mouse is moving | |
257 | impl->m_RenderingDelegate->onMouseMove(event); |
|
257 | impl->m_RenderingDelegate->onMouseMove(event); | |
258 | } |
|
258 | } | |
259 |
|
259 | |||
260 | void VisualizationGraphWidget::onMouseWheel(QWheelEvent *event) noexcept |
|
260 | void VisualizationGraphWidget::onMouseWheel(QWheelEvent *event) noexcept | |
261 | { |
|
261 | { | |
262 | auto zoomOrientations = QFlags<Qt::Orientation>{}; |
|
262 | auto zoomOrientations = QFlags<Qt::Orientation>{}; | |
263 |
|
263 | |||
264 | // Lambda that enables a zoom orientation if the key modifier related to this orientation |
|
264 | // Lambda that enables a zoom orientation if the key modifier related to this orientation | |
265 | // has |
|
265 | // has | |
266 | // been pressed |
|
266 | // been pressed | |
267 | auto enableOrientation |
|
267 | auto enableOrientation | |
268 | = [&zoomOrientations, event](const auto &orientation, const auto &modifier) { |
|
268 | = [&zoomOrientations, event](const auto &orientation, const auto &modifier) { | |
269 | auto orientationEnabled = event->modifiers().testFlag(modifier); |
|
269 | auto orientationEnabled = event->modifiers().testFlag(modifier); | |
270 | zoomOrientations.setFlag(orientation, orientationEnabled); |
|
270 | zoomOrientations.setFlag(orientation, orientationEnabled); | |
271 | }; |
|
271 | }; | |
272 | enableOrientation(Qt::Vertical, VERTICAL_ZOOM_MODIFIER); |
|
272 | enableOrientation(Qt::Vertical, VERTICAL_ZOOM_MODIFIER); | |
273 | enableOrientation(Qt::Horizontal, HORIZONTAL_ZOOM_MODIFIER); |
|
273 | enableOrientation(Qt::Horizontal, HORIZONTAL_ZOOM_MODIFIER); | |
274 |
|
274 | |||
275 | ui->widget->axisRect()->setRangeZoom(zoomOrientations); |
|
275 | ui->widget->axisRect()->setRangeZoom(zoomOrientations); | |
276 | } |
|
276 | } | |
277 |
|
277 | |||
278 | void VisualizationGraphWidget::onMousePress(QMouseEvent *event) noexcept |
|
278 | void VisualizationGraphWidget::onMousePress(QMouseEvent *event) noexcept | |
279 | { |
|
279 | { | |
280 | impl->m_IsCalibration = event->modifiers().testFlag(Qt::ControlModifier); |
|
280 | impl->m_IsCalibration = event->modifiers().testFlag(Qt::ControlModifier); | |
281 | } |
|
281 | } | |
282 |
|
282 | |||
283 | void VisualizationGraphWidget::onMouseRelease(QMouseEvent *event) noexcept |
|
283 | void VisualizationGraphWidget::onMouseRelease(QMouseEvent *event) noexcept | |
284 | { |
|
284 | { | |
285 | impl->m_IsCalibration = false; |
|
285 | impl->m_IsCalibration = false; | |
286 | } |
|
286 | } | |
287 |
|
287 | |||
288 | void VisualizationGraphWidget::onDataCacheVariableUpdated() |
|
288 | void VisualizationGraphWidget::onDataCacheVariableUpdated() | |
289 | { |
|
289 | { | |
290 | auto graphRange = ui->widget->xAxis->range(); |
|
290 | auto graphRange = ui->widget->xAxis->range(); | |
291 | auto dateTime = SqpRange{graphRange.lower, graphRange.upper}; |
|
291 | auto dateTime = SqpRange{graphRange.lower, graphRange.upper}; | |
292 |
|
292 | |||
293 | for (auto &variableEntry : impl->m_VariableToPlotMultiMap) { |
|
293 | for (auto &variableEntry : impl->m_VariableToPlotMultiMap) { | |
294 | auto variable = variableEntry.first; |
|
294 | auto variable = variableEntry.first; | |
295 | qCDebug(LOG_VisualizationGraphWidget()) |
|
295 | qCDebug(LOG_VisualizationGraphWidget()) | |
296 | << "TORM: VisualizationGraphWidget::onDataCacheVariableUpdated S" << variable->range(); |
|
296 | << "TORM: VisualizationGraphWidget::onDataCacheVariableUpdated S" << variable->range(); | |
297 | qCDebug(LOG_VisualizationGraphWidget()) |
|
297 | qCDebug(LOG_VisualizationGraphWidget()) | |
298 | << "TORM: VisualizationGraphWidget::onDataCacheVariableUpdated E" << dateTime; |
|
298 | << "TORM: VisualizationGraphWidget::onDataCacheVariableUpdated E" << dateTime; | |
299 | if (dateTime.contains(variable->range()) || dateTime.intersect(variable->range())) { |
|
299 | if (dateTime.contains(variable->range()) || dateTime.intersect(variable->range())) { | |
300 | VisualizationGraphHelper::updateData(variableEntry.second, variable->dataSeries(), |
|
300 | VisualizationGraphHelper::updateData(variableEntry.second, variable->dataSeries(), | |
301 | variable->range()); |
|
301 | variable->range()); | |
302 | } |
|
302 | } | |
303 | } |
|
303 | } | |
304 | } |
|
304 | } | |
305 |
|
305 | |||
306 | void VisualizationGraphWidget::onUpdateVarDisplaying(std::shared_ptr<Variable> variable, |
|
306 | void VisualizationGraphWidget::onUpdateVarDisplaying(std::shared_ptr<Variable> variable, | |
307 | const SqpRange &range) |
|
307 | const SqpRange &range) | |
308 | { |
|
308 | { | |
309 | auto it = impl->m_VariableToPlotMultiMap.find(variable); |
|
309 | auto it = impl->m_VariableToPlotMultiMap.find(variable); | |
310 | if (it != impl->m_VariableToPlotMultiMap.end()) { |
|
310 | if (it != impl->m_VariableToPlotMultiMap.end()) { | |
311 | VisualizationGraphHelper::updateData(it->second, variable->dataSeries(), range); |
|
311 | VisualizationGraphHelper::updateData(it->second, variable->dataSeries(), range); | |
312 | } |
|
312 | } | |
313 | } |
|
313 | } |
General Comments 0
You need to be logged in to leave comments.
Login now