HAL
gatelibrary_tab_general.cpp
Go to the documentation of this file.
1 
10 
12 #include "gui/gui_globals.h"
13 #include <QFrame>
14 #include <QScrollArea>
15 
16 namespace hal
17 {
18  //--------------------- general frame ---------------------------
20  : GatelibraryComponentFrame("General", parent)
21  {
22  mNameLabel = new GateLibraryLabel(true, " - ", this);
23  mIdLabel = new GateLibraryLabel(true, " - ", this);
24  mPropertiesLabel = new GateLibraryLabel(true, " - ", this);
25 
26  mLayout->addRow(new GateLibraryLabel(false, "Name:", this), mNameLabel);
27  mLayout->addRow(new GateLibraryLabel(false, "ID:", this), mIdLabel);
28  mLayout->addRow(new GateLibraryLabel(false, "Properties:", this), mPropertiesLabel);
29 
31  }
32 
34  {
35  if(!gt)
36  {
37  mNameLabel->setText("-");
38  mIdLabel->setText("-");
39  mPropertiesLabel->setText("-");
40  return;
41  }
42 
43  mNameLabel->setText(QString::fromStdString(gt->get_name()));
44  mIdLabel->setText(QString::number(gt->get_id()));
45 
46  // add properties
47  QString properties = "";
48 
49  bool first = true;
50  for (GateTypeProperty p : gt->get_property_list()) {
51  //add \n before each property except the first
52  if(first)
53  first = false;
54  else
55  properties.append("\n");
56 
58  }
59  mPropertiesLabel->setText(properties);
60  }
61 
62  //--------------------- boolean function frame ------------------
64  : GatelibraryComponentFrame("Boolean Functions", parent)
65  {
67  }
68 
70  {
71  // Clear existing labels
72  QLayoutItem* item;
73  while (!mLayout->isEmpty())
74  {
75  if ((item = mLayout->takeAt(0)) != nullptr) {
76  delete item->widget();
77  delete item;
78  }
79  }
80  mLayout->insertRow(0, new GateLibraryLabel(false, "Boolean Functions", this));
81 
82  //add label and corresponding boolean function to the layout
83  auto boolFunctions = gt->get_boolean_functions();
85 
86  // add boolean functions for each output
87  for(std::pair<const std::basic_string<char>, BooleanFunction> bf : boolFunctions){
88  GateLibraryLabel* label = new GateLibraryLabel(true, QString::fromStdString(bf.second.to_string()), this);
89  mLayout->insertRow(1, new GateLibraryLabel(false, QString::fromStdString(bf.first), this), label);
90  }
91 
92  if (boolFunctions.empty())
93  hide();
94  else
95  show();
96  }
97 
98  //--------------------- tab widget with all component frames ----
100  {
101  QVBoxLayout* topLayout = new QVBoxLayout(this);
102  QScrollArea* scroll = new QScrollArea(this); // add scrollbar if needed
103 
104  QFrame* content = new QFrame(scroll);
105  QVBoxLayout* layout = new QVBoxLayout(content);
106 
107  mGeneralFrame = new GatelibraryFrameGeneral(content);
108  layout->addWidget(mGeneralFrame);
109 
110  mFlipflopFrame = new GatelibraryFrameFF(content);
111  layout->addWidget(mFlipflopFrame);
112  mFlipflopFrame->hide();
113 
114  mStateFrame = new GatelibraryFrameState(content);
115  layout->addWidget(mStateFrame);
116  mStateFrame->hide();
117 
118  mLutFrame = new GatelibraryFrameLut(content);
119  layout->addWidget(mLutFrame);
120  mLutFrame->hide();
121 
122  mInitFrame = new GatelibraryFrameInit(content);
123  layout->addWidget(mInitFrame);
124  mInitFrame->hide();
125 
126  mBooleanFrame = new GatelibraryFrameBoolean(content);
127  layout->addWidget(mBooleanFrame);
128  mBooleanFrame->hide();
129 
130  mLatchFrame = new GateLibraryFrameLatch(content);
131  layout->addWidget(mLatchFrame);
132  mLatchFrame->hide();
133 
134  mRAMFrame = new GateLibraryFrameRAM(content);
135  layout->addWidget(mRAMFrame);
136  mRAMFrame->hide();
137 
138  mRAMPortFrame = new GateLibraryFrameRAMPort(content);
139  layout->addWidget(mRAMPortFrame);
140  mRAMPortFrame->hide();
141 
142  scroll->setWidget(content);
143  scroll->setWidgetResizable(true);
144 
145  content->setLayout(layout);
146  topLayout->addWidget(scroll);
147  }
148 
150  {
151  mGeneralFrame->update(gt);
152  if(!gt){
153  //TODO make default look
154  mFlipflopFrame->hide();
155  mStateFrame->hide();
156  mLutFrame->hide();
157  mInitFrame->hide();
158  mBooleanFrame->hide();
159  mLatchFrame->hide();
160  mRAMFrame->hide();
161  mRAMPortFrame->hide();
162  return;
163  }
164 
165  mFlipflopFrame->update(gt);
166  mStateFrame->update(gt);
167  mLutFrame->update(gt);
168  mInitFrame->update(gt);
169  mBooleanFrame->update(gt);
170  mLatchFrame->update(gt);
171  mRAMFrame->update(gt);
172  mRAMPortFrame->update(gt);
173  }
174 }
void update(GateType *gt) override
void update(GateType *gt) override
void update(GateType *gt) override
GateLibraryTabGeneral(QWidget *parent=nullptr)
std::vector< GateTypeProperty > get_property_list() const
Definition: gate_type.cpp:79
const std::string & get_name() const
Definition: gate_type.cpp:64
u32 get_id() const
Definition: gate_type.cpp:59
const std::unordered_map< std::string, BooleanFunction > & get_boolean_functions() const
Definition: gate_type.cpp:746
void update(GateType *gt) override
GatelibraryFrameBoolean(QWidget *parent=nullptr)
void update(GateType *gt) override
GatelibraryFrameGeneral(QWidget *parent=nullptr)
void update(GateType *gt) override
void update(GateType *gt) override
void update(GateType *gt) override
void update(GateType *gt) override
std::string enum_to_string(T e)
Definition: enums.h:52
void addWidget(QWidget *widget, int stretch, Qt::Alignment alignment)
void addRow(QWidget *label, QWidget *field)
void setFieldGrowthPolicy(QFormLayout::FieldGrowthPolicy policy)
void insertRow(int row, QWidget *label, QWidget *field)
virtual QLayoutItem * takeAt(int index) override
void setText(const QString &)
void addWidget(QWidget *w)
virtual bool isEmpty() const const override
virtual QWidget * widget()
QString & append(QChar ch)
QString fromStdString(const std::string &str)
QString number(int n, int base)
void hide()
QLayout * layout() const const
void scroll(int dx, int dy)
void setLayout(QLayout *layout)
void show()
void update()