1 #include "BlockLibraryWidget.h"
2 #include "BlockLibraryTree.h"
4 BlockLibraryWidget::BlockLibraryWidget(Dispatcher* _dispatcher,
6 QWidget *parent) : QWidget(parent) {
9 dispatcher = _dispatcher;
17 // creating the widget : tree, buttons, ...
18 QBoxLayout* layout = new QBoxLayout(QBoxLayout::TopToBottom, this);
19 tree = new QTreeWidget(this);
21 buttonAdd = new QPushButton("add to", this);
22 buttonAdd->setEnabled(false);
23 comboScenes = new QComboBox();
25 QHBoxLayout* layAdd = new QHBoxLayout;
26 layAdd->addWidget(buttonAdd);
27 layAdd->addWidget(comboScenes);
29 layClkRst = new QGridLayout;
31 boxClkRst = new QGroupBox("Clock/reset connection");
32 boxClkRst->setLayout(layClkRst);
34 QVBoxLayout* layBottom = new QVBoxLayout;
35 layBottom->addLayout(layAdd);
36 layBottom->addWidget(boxClkRst);
39 connect(tree, SIGNAL(itemClicked(QTreeWidgetItem*,int)), this, SLOT(clicked()));
40 connect(tree, SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)), this, SLOT(doubleClicked()));
41 connect(buttonAdd, SIGNAL(clicked()), this, SLOT(addClicked()));
43 BlockCategory* cat = params->categoryTree->searchCategory(0);
45 QTreeWidgetItem* item = tree->invisibleRootItem();
46 tree->setHeaderLabel("Blocks list");
50 layout->addWidget(tree);
51 layout->addLayout(layBottom);
52 this->setLayout(layout);
54 //this->setFixedSize(300,230);
58 BlockLibraryWidget::~BlockLibraryWidget() {
61 void BlockLibraryWidget::addChild(BlockCategory *catParent,QTreeWidgetItem* itemParent) {
63 QTreeWidgetItem* newItemCat = NULL;
64 QTreeWidgetItem* newItemBlock = NULL;
66 QList<BlockCategory *> childs = catParent->getAllChilds();
67 foreach(BlockCategory* cat, childs){
69 if (cat->getId()<100) {
70 newItemCat = new QTreeWidgetItem(itemParent);
71 newItemCat->setData(0,Qt::DisplayRole, cat->getName());
72 QList<ReferenceBlock*> list = cat->getBlocks();
73 for(int i=0; i<list.length(); i++){
74 newItemBlock = new QTreeWidgetItem(newItemCat);
75 newItemBlock->setData(0,Qt::DisplayRole, list.at(i)->getName());
76 newItemBlock->setData(1,Qt::DisplayRole, cat->getId());
77 newItemBlock->setData(2,Qt::DisplayRole, i);
78 newItemBlock->setIcon(0,QIcon("icons/window_new.png"));
80 addChild(cat,newItemCat);
84 - getting the childs of catParent
85 - for each BlockCategory cat of that list :
86 - create an new TreeWidgetItem (newImteCat), with itemParent as a parent
87 - set the first column of that item with the categry name
88 - get the list of the blocks that are associated with cat
89 - for i = 0 to that list size.
90 - create a new TreeWidgetItem (newItemBlock), with newItemCat as a parent
91 - set the first column of that item with the block name
92 - set the second column of that item with the newItemCat id
93 - set the third column of that item with the value of i
95 - call again addChild with cat and newImteCat as parameters
101 void BlockLibraryWidget::addClicked() {
103 QTreeWidgetItem *item = tree->selectedItems().at(0);
104 if(item->data(1,Qt::DisplayRole).isValid() && item->data(2,Qt::DisplayRole).isValid()){
105 int idCat = item->data(1,Qt::DisplayRole).toInt();
106 int idBlock = item->data(2,Qt::DisplayRole).toInt();
107 QVariant v = comboScenes->currentData();
109 cout << "adding block to scene " << v.toInt() << endl;
111 QHash<QString, int> clkRstToGen;
112 for(int i=0;i<layClkRst->rowCount();i++) {
113 QLayoutItem* item = layClkRst->itemAtPosition(i,0);
114 QLabel* lab = (QLabel *)(item->widget());
115 item = layClkRst->itemAtPosition(i,1);
116 QComboBox* combo = (QComboBox *)(item->widget());
117 clkRstToGen.insert(lab->text(),combo->currentIndex());
121 dispatcher->addBlock(Dispatcher::Design, idCat, idBlock, v.toInt(), clkRstToGen);
124 // only take the first selected
125 // retrieve id of category and id of block
126 // calling dispatcher addBlock() method.
129 void BlockLibraryWidget::clicked() {
130 if(tree->selectedItems().length() > 0){
131 QTreeWidgetItem *item = tree->selectedItems().at(0);
132 if(item->data(1,Qt::DisplayRole).isValid()) {
133 buttonAdd->setEnabled(true);
134 int idParent = item->data(1,Qt::DisplayRole).toInt();
135 int idBlock = item->data(2,Qt::DisplayRole).toInt();
136 updateClkRst(idParent, idBlock);
139 buttonAdd->setEnabled(false);
144 void BlockLibraryWidget::doubleClicked() {
148 void BlockLibraryWidget::updateComboScene() {
149 comboScenes->clear();
150 QMap<int,QString> list = dispatcher->getAllGroupNames();
151 QMapIterator<int,QString> iter(list);
152 while (iter.hasNext()) {
154 comboScenes->addItem(iter.value(),QVariant(iter.key()));
158 void BlockLibraryWidget::updateClkRst(int idCat, int idBlock) {
160 while (layClkRst->count() > 0) {
161 QWidget* widget = layClkRst->itemAt(0)->widget();
162 layClkRst->removeWidget(widget);
167 for(int i=0;i<nbClock;i++) {
168 comboClkGen[i]->deleteLater();
170 delete [] comboClkGen;
173 for(int i=0;i<nbRst;i++) {
174 comboRstGen[i]->deleteLater();
176 delete [] comboRstGen;
179 ReferenceBlock* ref = params->getReferenceBlock(idCat,idBlock);
180 QList<AbstractInterface*> lstClocks = ref->getInterfaces(AbstractInterface::Input, AbstractInterface::Clock);
181 nbClock = lstClocks.size();
182 QList<AbstractInterface*> lstRst = ref->getInterfaces(AbstractInterface::Input, AbstractInterface::Reset);
183 nbRst = lstRst.size();
185 comboClkGen = new QComboBox*[lstClocks.size()];
186 for(int i=0;i<lstClocks.size();i++) {
187 comboClkGen[i] = new QComboBox();
190 foreach(double d, params->clocks) {
191 name = "ext_clk_"+QString::number(id)+" (";
192 name += QString::number(d) + " MHz)";
193 comboClkGen[i]->addItem(name);
198 comboRstGen = new QComboBox*[lstRst.size()];
199 for(int i=0;i<lstRst.size();i++) {
200 comboRstGen[i] = new QComboBox();
202 for(int j=0;j<params->clocks.size();j++) {
203 name = "ext_rst_"+QString::number(j);
204 comboRstGen[i]->addItem(name);
207 layClkRst->addWidget(new QLabel("Clock/Reset name"), 0, 0);
208 layClkRst->addWidget(new QLabel("connect to"), 0, 1);
210 foreach(AbstractInterface* iface, lstClocks) {
211 layClkRst->addWidget(new QLabel(iface->getName()), row,0);
212 layClkRst->addWidget(comboClkGen[row-1],row, 1);
215 foreach(AbstractInterface* iface, lstRst) {
216 layClkRst->addWidget(new QLabel(iface->getName()), row,0);
217 layClkRst->addWidget(comboRstGen[row-1-nbClock],row, 1);