Skip to content

Commit 6f9a0c6

Browse files
committed
[feature/multi-output-luts_parameter-tab] Changes in the parameter table are now also saved in the gate
1 parent 0ab02f9 commit 6f9a0c6

5 files changed

Lines changed: 34 additions & 16 deletions

File tree

plugins/gui/include/gui/selection_details_widget/gate_details_widget/parameter_table_model.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,14 @@
2525

2626
#pragma once
2727

28-
#include "hal_core/netlist/parameter.h"
29-
3028
#include <QAbstractTableModel>
3129
#include <QString>
3230
#include <QVector>
3331

34-
#include <string>
35-
#include <unordered_map>
36-
#include <utility>
37-
3832
namespace hal
3933
{
34+
class Gate;
35+
4036
/**
4137
* @ingroup utility_widgets-selection_details
4238
*
@@ -92,11 +88,12 @@ namespace hal
9288
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
9389

9490
/**
95-
* Fills the table with the given gate parameters (name -> (declaration, value)).
91+
* Fills the table with the parameters of the given gate and remembers the gate so that
92+
* edits can be written back to it.
9693
*
97-
* @param parameters - The parameters as returned by Gate::get_parameters().
94+
* @param gate - The gate whose parameters are displayed.
9895
*/
99-
void updateData(const std::unordered_map<std::string, std::pair<Parameter, std::string>>& parameters);
96+
void updateData(Gate* gate);
10097

10198
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
10299

@@ -113,5 +110,8 @@ namespace hal
113110
};
114111

115112
QVector<ParameterRow> mRows;
113+
114+
// Non-owning pointer to the gate currently displayed; the netlist owns the gate.
115+
Gate* mGate = nullptr;
116116
};
117117
}

plugins/gui/include/gui/selection_details_widget/gate_details_widget/parameter_table_widget.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ namespace hal
5858
*
5959
* @param gate - The gate.
6060
*/
61-
void setGate(Gate* gate);
61+
void setGate(Gate* gate) const;
6262

6363
private:
6464
ParameterTableModel* mParameterTableModel;

plugins/gui/src/selection_details_widget/gate_details_widget/parameter_table_model.cpp

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
#include "gui/selection_details_widget/gate_details_widget/parameter_table_model.h"
22

3+
#include "hal_core/netlist/gate.h"
34
#include "hal_core/utilities/enums.h"
45

56
#include <algorithm>
7+
#include <boost/container/container_fwd.hpp>
68

79
namespace hal
810
{
@@ -70,12 +72,13 @@ namespace hal
7072
return QVariant();
7173
}
7274

73-
void ParameterTableModel::updateData(const std::unordered_map<std::string, std::pair<Parameter, std::string>>& parameters)
75+
void ParameterTableModel::updateData(Gate* gate)
7476
{
7577
beginResetModel();
78+
mGate = gate;
7679
mRows.clear();
7780

78-
for (const auto& [name, declAndValue] : parameters)
81+
for (const auto& [name, declAndValue] : gate->get_parameters())
7982
{
8083
const Parameter& decl = declAndValue.first;
8184

@@ -101,7 +104,22 @@ namespace hal
101104
return false;
102105
}
103106

104-
this->mRows[index.row()].value = value.toString();
107+
const std::string name = mRows[index.row()].name.toStdString();
108+
109+
Result<Parameter> param = this->mGate->get_parameter_declaration(name);
110+
if (param.is_error())
111+
{
112+
return false;
113+
}
114+
115+
Result<std::monostate> result = this->mGate->set_parameter(param.get(), value.toString().toStdString());
116+
if (result.is_error())
117+
{
118+
return false;
119+
}
120+
121+
std::string norm_value = this->mGate->get_parameter_value(name).get();
122+
this->mRows[index.row()].value = QString::fromStdString(norm_value);
105123

106124
Q_EMIT dataChanged(index, index);
107125
return true;

plugins/gui/src/selection_details_widget/gate_details_widget/parameter_table_widget.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ namespace hal
2121
setItemDelegateForColumn(4, new ParameterValueDelegate(this));
2222
}
2323

24-
void ParameterTableWidget::setGate(Gate* gate)
24+
void ParameterTableWidget::setGate(Gate* gate) const
2525
{
2626
if (gate == nullptr)
2727
return;
2828

29-
mParameterTableModel->updateData(gate->get_parameters());
29+
mParameterTableModel->updateData(gate);
3030
}
3131
}
3232

plugins/gui/src/selection_details_widget/gate_details_widget/parameter_value_delegate.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ namespace hal
2424
}
2525
case Parameter::Type::Integer: {
2626
auto textField = new QLineEdit(parent);
27-
textField->setValidator(new QIntValidator(textField));
27+
textField->setValidator(new QRegularExpressionValidator(QRegularExpression("-?\\d*"), textField));
2828
return textField;
2929
}
3030
case Parameter::Type::Float: {

0 commit comments

Comments
 (0)