##// END OF EJS Templates
Few corrections
perrinel -
r763:fb27cebc64ba
parent child
Show More
@@ -1,108 +1,112
1 #ifndef SCIQLOP_SQPITERATOR_H
1 #ifndef SCIQLOP_SQPITERATOR_H
2 #define SCIQLOP_SQPITERATOR_H
2 #define SCIQLOP_SQPITERATOR_H
3
3
4 #include "CoreGlobal.h"
4 #include "CoreGlobal.h"
5
5
6 /**
6 /**
7 * @brief The SqpIterator class represents an iterator used in SciQlop. It defines all operators
7 * @brief The SqpIterator class represents an iterator used in SciQlop. It defines all operators
8 * needed for a standard forward iterator
8 * needed for a standard forward iterator
9 * @tparam T the type of object handled in iterator
9 * @tparam T the type of object handled in iterator
10 * @sa http://www.cplusplus.com/reference/iterator/
10 * @sa http://www.cplusplus.com/reference/iterator/
11 */
11 */
12 template <typename T>
12 template <typename T>
13 class SCIQLOP_CORE_EXPORT SqpIterator {
13 class SCIQLOP_CORE_EXPORT SqpIterator {
14 public:
14 public:
15 using iterator_category = std::random_access_iterator_tag;
15 using iterator_category = std::random_access_iterator_tag;
16 using value_type = const T;
16 using value_type = const T;
17 using difference_type = std::ptrdiff_t;
17 using difference_type = std::ptrdiff_t;
18 using pointer = value_type *;
18 using pointer = value_type *;
19 using reference = value_type &;
19 using reference = value_type &;
20
20
21 explicit SqpIterator(T value) : m_CurrentValue{std::move(value)} {}
21 explicit SqpIterator(T value) : m_CurrentValue{std::move(value)} {}
22
22
23 virtual ~SqpIterator() noexcept = default;
23 virtual ~SqpIterator() noexcept = default;
24 SqpIterator(const SqpIterator &) = default;
24 SqpIterator(const SqpIterator &) = default;
25 SqpIterator &operator=(SqpIterator other) { swap(m_CurrentValue, other.m_CurrentValue); }
25 SqpIterator &operator=(SqpIterator other)
26 {
27 swap(m_CurrentValue, other.m_CurrentValue);
28 return *this;
29 }
26
30
27 SqpIterator &operator++()
31 SqpIterator &operator++()
28 {
32 {
29 m_CurrentValue.next();
33 m_CurrentValue.next();
30 return *this;
34 return *this;
31 }
35 }
32
36
33 SqpIterator &operator--()
37 SqpIterator &operator--()
34 {
38 {
35 m_CurrentValue.prev();
39 m_CurrentValue.prev();
36 return *this;
40 return *this;
37 }
41 }
38
42
39 SqpIterator operator++(int)const
43 SqpIterator operator++(int)const
40 {
44 {
41 auto result = *this;
45 auto result = *this;
42 this->operator++();
46 this->operator++();
43 return result;
47 return result;
44 }
48 }
45 SqpIterator operator--(int)const
49 SqpIterator operator--(int)const
46 {
50 {
47 auto result = *this;
51 auto result = *this;
48 this->operator--();
52 this->operator--();
49 return result;
53 return result;
50 }
54 }
51
55
52 SqpIterator &operator+=(int offset)
56 SqpIterator &operator+=(int offset)
53 {
57 {
54 if (offset >= 0) {
58 if (offset >= 0) {
55 m_CurrentValue.next(offset);
59 m_CurrentValue.next(offset);
56 }
60 }
57 else {
61 else {
58 while (offset++) {
62 while (offset++) {
59 m_CurrentValue.prev();
63 m_CurrentValue.prev();
60 }
64 }
61 }
65 }
62
66
63 return *this;
67 return *this;
64 }
68 }
65 SqpIterator &operator-=(int offset) { return *this += -offset; }
69 SqpIterator &operator-=(int offset) { return *this += -offset; }
66
70
67 SqpIterator operator+(int offset) const
71 SqpIterator operator+(int offset) const
68 {
72 {
69 auto result = *this;
73 auto result = *this;
70 result += offset;
74 result += offset;
71 return result;
75 return result;
72 }
76 }
73 SqpIterator operator-(int offset) const
77 SqpIterator operator-(int offset) const
74 {
78 {
75 auto result = *this;
79 auto result = *this;
76 result -= offset;
80 result -= offset;
77 return result;
81 return result;
78 }
82 }
79
83
80 int operator-(const SqpIterator &other) const
84 int operator-(const SqpIterator &other) const
81 {
85 {
82 return m_CurrentValue.distance(other.m_CurrentValue);
86 return m_CurrentValue.distance(other.m_CurrentValue);
83 }
87 }
84
88
85 const T *operator->() const { return &m_CurrentValue; }
89 const T *operator->() const { return &m_CurrentValue; }
86 const T &operator*() const { return m_CurrentValue; }
90 const T &operator*() const { return m_CurrentValue; }
87 T *operator->() { return &m_CurrentValue; }
91 T *operator->() { return &m_CurrentValue; }
88 T &operator*() { return m_CurrentValue; }
92 T &operator*() { return m_CurrentValue; }
89 T &operator[](int offset) const { return m_CurrentValue.advance(offset); }
93 T &operator[](int offset) const { return m_CurrentValue.advance(offset); }
90
94
91 bool operator==(const SqpIterator &other) const
95 bool operator==(const SqpIterator &other) const
92 {
96 {
93 return m_CurrentValue.equals(other.m_CurrentValue);
97 return m_CurrentValue.equals(other.m_CurrentValue);
94 }
98 }
95 bool operator!=(const SqpIterator &other) const { return !(*this == other); }
99 bool operator!=(const SqpIterator &other) const { return !(*this == other); }
96 bool operator>(const SqpIterator &other) const { return other.m_CurrentValue.lowerThan(*this); }
100 bool operator>(const SqpIterator &other) const { return other.m_CurrentValue.lowerThan(*this); }
97 bool operator<(const SqpIterator &other) const
101 bool operator<(const SqpIterator &other) const
98 {
102 {
99 return m_CurrentValue.lowerThan(other.m_CurrentValue);
103 return m_CurrentValue.lowerThan(other.m_CurrentValue);
100 }
104 }
101 bool operator>=(const SqpIterator &other) const { return !(*this < other); }
105 bool operator>=(const SqpIterator &other) const { return !(*this < other); }
102 bool operator<=(const SqpIterator &other) const { return !(*this > other); }
106 bool operator<=(const SqpIterator &other) const { return !(*this > other); }
103
107
104 private:
108 private:
105 T m_CurrentValue;
109 T m_CurrentValue;
106 };
110 };
107
111
108 #endif // SCIQLOP_SQPITERATOR_H
112 #endif // SCIQLOP_SQPITERATOR_H
@@ -1,84 +1,83
1 #include "Data/DataSeriesIterator.h"
1 #include "Data/DataSeriesIterator.h"
2
2
3 DataSeriesIteratorValue::DataSeriesIteratorValue(
3 DataSeriesIteratorValue::DataSeriesIteratorValue(
4 std::unique_ptr<DataSeriesIteratorValue::Impl> impl)
4 std::unique_ptr<DataSeriesIteratorValue::Impl> impl)
5 : m_Impl{std::move(impl)}
5 : m_Impl{std::move(impl)}
6 {
6 {
7 }
7 }
8
8
9 DataSeriesIteratorValue::DataSeriesIteratorValue(const DataSeriesIteratorValue &other)
9 DataSeriesIteratorValue::DataSeriesIteratorValue(const DataSeriesIteratorValue &other)
10 : m_Impl{other.m_Impl->clone()}
10 : m_Impl{other.m_Impl->clone()}
11 {
11 {
12 }
12 }
13
13
14 DataSeriesIteratorValue &DataSeriesIteratorValue::operator=(DataSeriesIteratorValue other)
14 DataSeriesIteratorValue &DataSeriesIteratorValue::operator=(DataSeriesIteratorValue other)
15 {
15 {
16 m_Impl->swap(*other.m_Impl);
16 m_Impl->swap(*other.m_Impl);
17 return *this;
17 return *this;
18 }
18 }
19
19
20 int DataSeriesIteratorValue::distance(const DataSeriesIteratorValue &other) const
20 int DataSeriesIteratorValue::distance(const DataSeriesIteratorValue &other) const
21 {
21 {
22 auto dist = m_Impl->distance(*other.m_Impl);
23 return m_Impl->distance(*other.m_Impl);
22 return m_Impl->distance(*other.m_Impl);
24 }
23 }
25
24
26 bool DataSeriesIteratorValue::equals(const DataSeriesIteratorValue &other) const
25 bool DataSeriesIteratorValue::equals(const DataSeriesIteratorValue &other) const
27 {
26 {
28 return m_Impl->equals(*other.m_Impl);
27 return m_Impl->equals(*other.m_Impl);
29 }
28 }
30
29
31 bool DataSeriesIteratorValue::lowerThan(const DataSeriesIteratorValue &other) const
30 bool DataSeriesIteratorValue::lowerThan(const DataSeriesIteratorValue &other) const
32 {
31 {
33 return m_Impl->lowerThan(*other.m_Impl);
32 return m_Impl->lowerThan(*other.m_Impl);
34 }
33 }
35
34
36 DataSeriesIteratorValue DataSeriesIteratorValue::advance(int offset) const
35 DataSeriesIteratorValue DataSeriesIteratorValue::advance(int offset) const
37 {
36 {
38 return DataSeriesIteratorValue{m_Impl->advance(offset)};
37 return DataSeriesIteratorValue{m_Impl->advance(offset)};
39 }
38 }
40
39
41 void DataSeriesIteratorValue::next(int offset)
40 void DataSeriesIteratorValue::next(int offset)
42 {
41 {
43 m_Impl->next(offset);
42 m_Impl->next(offset);
44 }
43 }
45
44
46 void DataSeriesIteratorValue::prev()
45 void DataSeriesIteratorValue::prev()
47 {
46 {
48 m_Impl->prev();
47 m_Impl->prev();
49 }
48 }
50
49
51 double DataSeriesIteratorValue::x() const
50 double DataSeriesIteratorValue::x() const
52 {
51 {
53 return m_Impl->x();
52 return m_Impl->x();
54 }
53 }
55
54
56 double DataSeriesIteratorValue::value() const
55 double DataSeriesIteratorValue::value() const
57 {
56 {
58 return m_Impl->value();
57 return m_Impl->value();
59 }
58 }
60
59
61 double DataSeriesIteratorValue::value(int componentIndex) const
60 double DataSeriesIteratorValue::value(int componentIndex) const
62 {
61 {
63 return m_Impl->value(componentIndex);
62 return m_Impl->value(componentIndex);
64 }
63 }
65
64
66 double DataSeriesIteratorValue::minValue() const
65 double DataSeriesIteratorValue::minValue() const
67 {
66 {
68 return m_Impl->minValue();
67 return m_Impl->minValue();
69 }
68 }
70
69
71 double DataSeriesIteratorValue::maxValue() const
70 double DataSeriesIteratorValue::maxValue() const
72 {
71 {
73 return m_Impl->maxValue();
72 return m_Impl->maxValue();
74 }
73 }
75
74
76 QVector<double> DataSeriesIteratorValue::values() const
75 QVector<double> DataSeriesIteratorValue::values() const
77 {
76 {
78 return m_Impl->values();
77 return m_Impl->values();
79 }
78 }
80
79
81 DataSeriesIteratorValue::Impl *DataSeriesIteratorValue::impl()
80 DataSeriesIteratorValue::Impl *DataSeriesIteratorValue::impl()
82 {
81 {
83 return m_Impl.get();
82 return m_Impl.get();
84 }
83 }
@@ -1,228 +1,232
1 #include <Variable/RenameVariableDialog.h>
1 #include <Variable/RenameVariableDialog.h>
2 #include <Variable/Variable.h>
2 #include <Variable/Variable.h>
3 #include <Variable/VariableController.h>
3 #include <Variable/VariableController.h>
4 #include <Variable/VariableInspectorWidget.h>
4 #include <Variable/VariableInspectorWidget.h>
5 #include <Variable/VariableMenuHeaderWidget.h>
5 #include <Variable/VariableMenuHeaderWidget.h>
6 #include <Variable/VariableModel.h>
6 #include <Variable/VariableModel.h>
7
7
8 #include <ui_VariableInspectorWidget.h>
8 #include <ui_VariableInspectorWidget.h>
9
9
10 #include <QMouseEvent>
10 #include <QMouseEvent>
11 #include <QSortFilterProxyModel>
11 #include <QSortFilterProxyModel>
12 #include <QStyledItemDelegate>
12 #include <QStyledItemDelegate>
13 #include <QWidgetAction>
13 #include <QWidgetAction>
14
14
15 #include <SqpApplication.h>
15 #include <SqpApplication.h>
16
16
17 Q_LOGGING_CATEGORY(LOG_VariableInspectorWidget, "VariableInspectorWidget")
17 Q_LOGGING_CATEGORY(LOG_VariableInspectorWidget, "VariableInspectorWidget")
18
18
19
19
20 class QProgressBarItemDelegate : public QStyledItemDelegate {
20 class QProgressBarItemDelegate : public QStyledItemDelegate {
21
21
22 public:
22 public:
23 QProgressBarItemDelegate(QObject *parent) : QStyledItemDelegate{parent} {}
23 QProgressBarItemDelegate(QObject *parent) : QStyledItemDelegate{parent} {}
24
24
25 void paint(QPainter *painter, const QStyleOptionViewItem &option,
25 void paint(QPainter *painter, const QStyleOptionViewItem &option,
26 const QModelIndex &index) const
26 const QModelIndex &index) const
27 {
27 {
28 auto data = index.data(Qt::DisplayRole);
28 auto data = index.data(Qt::DisplayRole);
29 auto progressData = index.data(VariableRoles::ProgressRole);
29 auto progressData = index.data(VariableRoles::ProgressRole);
30 if (data.isValid() && progressData.isValid()) {
30 if (data.isValid() && progressData.isValid()) {
31 auto name = data.value<QString>();
31 auto name = data.value<QString>();
32 auto progress = progressData.value<double>();
32 auto progress = progressData.value<double>();
33 if (progress > 0) {
33 if (progress > 0) {
34 auto cancelButtonWidth = 20;
34 auto cancelButtonWidth = 20;
35 auto progressBarOption = QStyleOptionProgressBar{};
35 auto progressBarOption = QStyleOptionProgressBar{};
36 auto progressRect = option.rect;
36 auto progressRect = option.rect;
37 progressRect.setWidth(progressRect.width() - cancelButtonWidth);
37 progressRect.setWidth(progressRect.width() - cancelButtonWidth);
38 progressBarOption.rect = progressRect;
38 progressBarOption.rect = progressRect;
39 progressBarOption.minimum = 0;
39 progressBarOption.minimum = 0;
40 progressBarOption.maximum = 100;
40 progressBarOption.maximum = 100;
41 progressBarOption.progress = progress;
41 progressBarOption.progress = progress;
42 progressBarOption.text
42 progressBarOption.text
43 = QString("%1 %2").arg(name).arg(QString::number(progress, 'f', 2) + "%");
43 = QString("%1 %2").arg(name).arg(QString::number(progress, 'f', 2) + "%");
44 progressBarOption.textVisible = true;
44 progressBarOption.textVisible = true;
45 progressBarOption.textAlignment = Qt::AlignCenter;
45 progressBarOption.textAlignment = Qt::AlignCenter;
46
46
47
47
48 QApplication::style()->drawControl(QStyle::CE_ProgressBar, &progressBarOption,
48 QApplication::style()->drawControl(QStyle::CE_ProgressBar, &progressBarOption,
49 painter);
49 painter);
50
50
51 // Cancel button
51 // Cancel button
52 auto buttonRect = QRect(progressRect.right(), option.rect.top(), cancelButtonWidth,
52 auto buttonRect = QRect(progressRect.right(), option.rect.top(), cancelButtonWidth,
53 option.rect.height());
53 option.rect.height());
54 auto buttonOption = QStyleOptionButton{};
54 auto buttonOption = QStyleOptionButton{};
55 buttonOption.rect = buttonRect;
55 buttonOption.rect = buttonRect;
56 buttonOption.text = "X";
56 buttonOption.text = "X";
57
57
58 QApplication::style()->drawControl(QStyle::CE_PushButton, &buttonOption, painter);
58 QApplication::style()->drawControl(QStyle::CE_PushButton, &buttonOption, painter);
59 }
59 }
60 else {
60 else {
61 QStyledItemDelegate::paint(painter, option, index);
61 QStyledItemDelegate::paint(painter, option, index);
62 }
62 }
63 }
63 }
64 else {
64 else {
65 QStyledItemDelegate::paint(painter, option, index);
65 QStyledItemDelegate::paint(painter, option, index);
66 }
66 }
67 }
67 }
68
68
69 bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option,
69 bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option,
70 const QModelIndex &index)
70 const QModelIndex &index)
71 {
71 {
72 if (event->type() == QEvent::MouseButtonRelease) {
72 if (event->type() == QEvent::MouseButtonRelease) {
73 auto data = index.data(Qt::DisplayRole);
73 auto data = index.data(Qt::DisplayRole);
74 auto progressData = index.data(VariableRoles::ProgressRole);
74 auto progressData = index.data(VariableRoles::ProgressRole);
75 if (data.isValid() && progressData.isValid()) {
75 if (data.isValid() && progressData.isValid()) {
76 auto cancelButtonWidth = 20;
76 auto cancelButtonWidth = 20;
77 auto progressRect = option.rect;
77 auto progressRect = option.rect;
78 progressRect.setWidth(progressRect.width() - cancelButtonWidth);
78 progressRect.setWidth(progressRect.width() - cancelButtonWidth);
79 // Cancel button
79 // Cancel button
80 auto buttonRect = QRect(progressRect.right(), option.rect.top(), cancelButtonWidth,
80 auto buttonRect = QRect(progressRect.right(), option.rect.top(), cancelButtonWidth,
81 option.rect.height());
81 option.rect.height());
82
82
83 auto e = (QMouseEvent *)event;
83 auto e = (QMouseEvent *)event;
84 auto clickX = e->x();
84 auto clickX = e->x();
85 auto clickY = e->y();
85 auto clickY = e->y();
86
86
87 auto x = buttonRect.left(); // the X coordinate
87 auto x = buttonRect.left(); // the X coordinate
88 auto y = buttonRect.top(); // the Y coordinate
88 auto y = buttonRect.top(); // the Y coordinate
89 auto w = buttonRect.width(); // button width
89 auto w = buttonRect.width(); // button width
90 auto h = buttonRect.height(); // button height
90 auto h = buttonRect.height(); // button height
91
91
92 if (clickX > x && clickX < x + w) {
92 if (clickX > x && clickX < x + w) {
93 if (clickY > y && clickY < y + h) {
93 if (clickY > y && clickY < y + h) {
94 auto variableModel = sqpApp->variableController().variableModel();
94 auto variableModel = sqpApp->variableController().variableModel();
95 variableModel->abortProgress(index);
95 variableModel->abortProgress(index);
96 }
96 }
97 return true;
97 }
98 }
98 else {
99 else {
99 QStyledItemDelegate::editorEvent(event, model, option, index);
100 return QStyledItemDelegate::editorEvent(event, model, option, index);
100 }
101 }
101 }
102 }
102 else {
103 else {
103 QStyledItemDelegate::editorEvent(event, model, option, index);
104 return QStyledItemDelegate::editorEvent(event, model, option, index);
104 }
105 }
105 }
106 }
106 else {
107 else {
107 QStyledItemDelegate::editorEvent(event, model, option, index);
108 return QStyledItemDelegate::editorEvent(event, model, option, index);
108 }
109 }
110
111
112 return QStyledItemDelegate::editorEvent(event, model, option, index);
109 }
113 }
110 };
114 };
111
115
112 VariableInspectorWidget::VariableInspectorWidget(QWidget *parent)
116 VariableInspectorWidget::VariableInspectorWidget(QWidget *parent)
113 : QWidget{parent},
117 : QWidget{parent},
114 ui{new Ui::VariableInspectorWidget},
118 ui{new Ui::VariableInspectorWidget},
115 m_ProgressBarItemDelegate{new QProgressBarItemDelegate{this}}
119 m_ProgressBarItemDelegate{new QProgressBarItemDelegate{this}}
116 {
120 {
117 ui->setupUi(this);
121 ui->setupUi(this);
118
122
119 // Sets model for table
123 // Sets model for table
120 // auto sortFilterModel = new QSortFilterProxyModel{this};
124 // auto sortFilterModel = new QSortFilterProxyModel{this};
121 // sortFilterModel->setSourceModel(sqpApp->variableController().variableModel());
125 // sortFilterModel->setSourceModel(sqpApp->variableController().variableModel());
122
126
123 auto variableModel = sqpApp->variableController().variableModel();
127 auto variableModel = sqpApp->variableController().variableModel();
124 ui->tableView->setModel(variableModel);
128 ui->tableView->setModel(variableModel);
125
129
126 // Adds extra signal/slot between view and model, so the view can be updated instantly when
130 // Adds extra signal/slot between view and model, so the view can be updated instantly when
127 // there is a change of data in the model
131 // there is a change of data in the model
128 connect(variableModel, SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)), this,
132 connect(variableModel, SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)), this,
129 SLOT(refresh()));
133 SLOT(refresh()));
130
134
131 ui->tableView->setSelectionModel(sqpApp->variableController().variableSelectionModel());
135 ui->tableView->setSelectionModel(sqpApp->variableController().variableSelectionModel());
132 ui->tableView->setItemDelegateForColumn(0, m_ProgressBarItemDelegate);
136 ui->tableView->setItemDelegateForColumn(0, m_ProgressBarItemDelegate);
133
137
134 // Fixes column sizes
138 // Fixes column sizes
135 auto model = ui->tableView->model();
139 auto model = ui->tableView->model();
136 const auto count = model->columnCount();
140 const auto count = model->columnCount();
137 for (auto i = 0; i < count; ++i) {
141 for (auto i = 0; i < count; ++i) {
138 ui->tableView->setColumnWidth(
142 ui->tableView->setColumnWidth(
139 i, model->headerData(i, Qt::Horizontal, Qt::SizeHintRole).toSize().width());
143 i, model->headerData(i, Qt::Horizontal, Qt::SizeHintRole).toSize().width());
140 }
144 }
141
145
142 // Sets selection options
146 // Sets selection options
143 ui->tableView->setSelectionBehavior(QTableView::SelectRows);
147 ui->tableView->setSelectionBehavior(QTableView::SelectRows);
144 ui->tableView->setSelectionMode(QTableView::ExtendedSelection);
148 ui->tableView->setSelectionMode(QTableView::ExtendedSelection);
145
149
146 // Connection to show a menu when right clicking on the tree
150 // Connection to show a menu when right clicking on the tree
147 ui->tableView->setContextMenuPolicy(Qt::CustomContextMenu);
151 ui->tableView->setContextMenuPolicy(Qt::CustomContextMenu);
148 connect(ui->tableView, &QTableView::customContextMenuRequested, this,
152 connect(ui->tableView, &QTableView::customContextMenuRequested, this,
149 &VariableInspectorWidget::onTableMenuRequested);
153 &VariableInspectorWidget::onTableMenuRequested);
150 }
154 }
151
155
152 VariableInspectorWidget::~VariableInspectorWidget()
156 VariableInspectorWidget::~VariableInspectorWidget()
153 {
157 {
154 delete ui;
158 delete ui;
155 }
159 }
156
160
157 void VariableInspectorWidget::onTableMenuRequested(const QPoint &pos) noexcept
161 void VariableInspectorWidget::onTableMenuRequested(const QPoint &pos) noexcept
158 {
162 {
159 auto selectedRows = ui->tableView->selectionModel()->selectedRows();
163 auto selectedRows = ui->tableView->selectionModel()->selectedRows();
160
164
161 // Gets the model to retrieve the underlying selected variables
165 // Gets the model to retrieve the underlying selected variables
162 auto model = sqpApp->variableController().variableModel();
166 auto model = sqpApp->variableController().variableModel();
163 auto selectedVariables = QVector<std::shared_ptr<Variable> >{};
167 auto selectedVariables = QVector<std::shared_ptr<Variable> >{};
164 for (const auto &selectedRow : qAsConst(selectedRows)) {
168 for (const auto &selectedRow : qAsConst(selectedRows)) {
165 if (auto selectedVariable = model->variable(selectedRow.row())) {
169 if (auto selectedVariable = model->variable(selectedRow.row())) {
166 selectedVariables.push_back(selectedVariable);
170 selectedVariables.push_back(selectedVariable);
167 }
171 }
168 }
172 }
169
173
170 QMenu tableMenu{};
174 QMenu tableMenu{};
171
175
172 // Emits a signal so that potential receivers can populate the menu before displaying it
176 // Emits a signal so that potential receivers can populate the menu before displaying it
173 emit tableMenuAboutToBeDisplayed(&tableMenu, selectedVariables);
177 emit tableMenuAboutToBeDisplayed(&tableMenu, selectedVariables);
174
178
175 // Adds menu-specific actions
179 // Adds menu-specific actions
176 if (!selectedVariables.isEmpty()) {
180 if (!selectedVariables.isEmpty()) {
177 tableMenu.addSeparator();
181 tableMenu.addSeparator();
178
182
179 // 'Rename' and 'Duplicate' actions (only if one variable selected)
183 // 'Rename' and 'Duplicate' actions (only if one variable selected)
180 if (selectedVariables.size() == 1) {
184 if (selectedVariables.size() == 1) {
181 auto selectedVariable = selectedVariables.front();
185 auto selectedVariable = selectedVariables.front();
182
186
183 auto duplicateFun = [&selectedVariable]() {
187 auto duplicateFun = [&selectedVariable]() {
184 sqpApp->variableController().cloneVariable(selectedVariable);
188 sqpApp->variableController().cloneVariable(selectedVariable);
185 };
189 };
186
190
187 tableMenu.addAction(tr("Duplicate"), duplicateFun);
191 tableMenu.addAction(tr("Duplicate"), duplicateFun);
188
192
189 auto renameFun = [&selectedVariable, &model, this]() {
193 auto renameFun = [&selectedVariable, &model, this]() {
190 // Generates forbidden names (names associated to existing variables)
194 // Generates forbidden names (names associated to existing variables)
191 auto allVariables = model->variables();
195 auto allVariables = model->variables();
192 auto forbiddenNames = QVector<QString>(allVariables.size());
196 auto forbiddenNames = QVector<QString>(allVariables.size());
193 std::transform(allVariables.cbegin(), allVariables.cend(), forbiddenNames.begin(),
197 std::transform(allVariables.cbegin(), allVariables.cend(), forbiddenNames.begin(),
194 [](const auto &variable) { return variable->name(); });
198 [](const auto &variable) { return variable->name(); });
195
199
196 RenameVariableDialog dialog{selectedVariable->name(), forbiddenNames, this};
200 RenameVariableDialog dialog{selectedVariable->name(), forbiddenNames, this};
197 if (dialog.exec() == QDialog::Accepted) {
201 if (dialog.exec() == QDialog::Accepted) {
198 selectedVariable->setName(dialog.name());
202 selectedVariable->setName(dialog.name());
199 }
203 }
200 };
204 };
201
205
202 tableMenu.addAction(tr("Rename..."), renameFun);
206 tableMenu.addAction(tr("Rename..."), renameFun);
203 }
207 }
204
208
205 // 'Delete' action
209 // 'Delete' action
206 auto deleteFun = [&selectedVariables]() {
210 auto deleteFun = [&selectedVariables]() {
207 sqpApp->variableController().deleteVariables(selectedVariables);
211 sqpApp->variableController().deleteVariables(selectedVariables);
208 };
212 };
209
213
210 tableMenu.addAction(QIcon{":/icones/delete.png"}, tr("Delete"), deleteFun);
214 tableMenu.addAction(QIcon{":/icones/delete.png"}, tr("Delete"), deleteFun);
211 }
215 }
212
216
213 if (!tableMenu.isEmpty()) {
217 if (!tableMenu.isEmpty()) {
214 // Generates menu header (inserted before first action)
218 // Generates menu header (inserted before first action)
215 auto firstAction = tableMenu.actions().first();
219 auto firstAction = tableMenu.actions().first();
216 auto headerAction = new QWidgetAction{&tableMenu};
220 auto headerAction = new QWidgetAction{&tableMenu};
217 headerAction->setDefaultWidget(new VariableMenuHeaderWidget{selectedVariables, &tableMenu});
221 headerAction->setDefaultWidget(new VariableMenuHeaderWidget{selectedVariables, &tableMenu});
218 tableMenu.insertAction(firstAction, headerAction);
222 tableMenu.insertAction(firstAction, headerAction);
219
223
220 // Displays menu
224 // Displays menu
221 tableMenu.exec(QCursor::pos());
225 tableMenu.exec(QCursor::pos());
222 }
226 }
223 }
227 }
224
228
225 void VariableInspectorWidget::refresh() noexcept
229 void VariableInspectorWidget::refresh() noexcept
226 {
230 {
227 ui->tableView->viewport()->update();
231 ui->tableView->viewport()->update();
228 }
232 }
General Comments 0
You need to be logged in to leave comments. Login now