]> AND Private Git Repository - blast.git/blobdiff - BlockLibraryWidget.cpp
Logo AND Algorithmique Numérique Distribuée

Private GIT Repository
nearly finished GroupBlock VHDL gen
[blast.git] / BlockLibraryWidget.cpp
index 0aa9ed14faf203eb2bca833ded49d193b8f2ac86..0d2636d7db1189b88cdc4baa387267327fa88646 100644 (file)
@@ -10,10 +10,16 @@ BlockLibraryWidget::BlockLibraryWidget(Dispatcher* _dispatcher,
   params = _params;
 
   // creating the widget : tree, buttons, ...
   params = _params;
 
   // creating the widget : tree, buttons, ...
-  layout = new QBoxLayout(QBoxLayout::TopToBottom, this);
+  QBoxLayout* layout = new QBoxLayout(QBoxLayout::TopToBottom, this);
   tree = new QTreeWidget(this);
   tree = new QTreeWidget(this);
-  buttonAdd = new QPushButton("add", this);
+
+  buttonAdd = new QPushButton("add to", this);
   buttonAdd->setEnabled(false);
   buttonAdd->setEnabled(false);
+  comboScenes = new QComboBox();
+
+  QHBoxLayout* layBottom = new QHBoxLayout;
+  layBottom->addWidget(buttonAdd);
+  layBottom->addWidget(comboScenes);
 
   connect(tree, SIGNAL(itemClicked(QTreeWidgetItem*,int)), this, SLOT(clicked()));
   connect(tree, SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)), this, SLOT(doubleClicked()));
 
   connect(tree, SIGNAL(itemClicked(QTreeWidgetItem*,int)), this, SLOT(clicked()));
   connect(tree, SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)), this, SLOT(doubleClicked()));
@@ -24,11 +30,10 @@ BlockLibraryWidget::BlockLibraryWidget(Dispatcher* _dispatcher,
   QTreeWidgetItem* item = tree->invisibleRootItem();
   tree->setHeaderLabel("Blocks list");
 
   QTreeWidgetItem* item = tree->invisibleRootItem();
   tree->setHeaderLabel("Blocks list");
 
-
   addChild(cat,item);
 
   layout->addWidget(tree);
   addChild(cat,item);
 
   layout->addWidget(tree);
-  layout->addWidget(buttonAdd);
+  layout->addLayout(layBottom);
   this->setLayout(layout);
 
   this->setFixedSize(300,230);
   this->setLayout(layout);
 
   this->setFixedSize(300,230);
@@ -45,17 +50,20 @@ void BlockLibraryWidget::addChild(BlockCategory *catParent,QTreeWidgetItem* item
 
   QList<BlockCategory *> childs = catParent->getAllChilds();
   foreach(BlockCategory* cat, childs){
 
   QList<BlockCategory *> childs = catParent->getAllChilds();
   foreach(BlockCategory* cat, childs){
-    newItemCat = new QTreeWidgetItem(itemParent);
-    newItemCat->setData(0,Qt::DisplayRole, cat->getName());
-    QList<ReferenceBlock*> list = cat->getBlocks();
-    for(int i=0; i<list.length(); i++){
-      newItemBlock = new QTreeWidgetItem(newItemCat);
-      newItemBlock->setData(0,Qt::DisplayRole, list.at(i)->getName());
-      newItemBlock->setData(1,Qt::DisplayRole, cat->getId());
-      newItemBlock->setData(2,Qt::DisplayRole, i);
-      newItemBlock->setIcon(0,QIcon("icons/window_new.png"));
+
+    if (cat->getId()<100) {
+      newItemCat = new QTreeWidgetItem(itemParent);
+      newItemCat->setData(0,Qt::DisplayRole, cat->getName());
+      QList<ReferenceBlock*> list = cat->getBlocks();
+      for(int i=0; i<list.length(); i++){
+        newItemBlock = new QTreeWidgetItem(newItemCat);
+        newItemBlock->setData(0,Qt::DisplayRole, list.at(i)->getName());
+        newItemBlock->setData(1,Qt::DisplayRole, cat->getId());
+        newItemBlock->setData(2,Qt::DisplayRole, i);
+        newItemBlock->setIcon(0,QIcon("icons/window_new.png"));
+      }
+      addChild(cat,newItemCat);
     }
     }
-    addChild(cat,newItemCat);
   }
   /* TO DO :
      - getting the childs of catParent
   }
   /* TO DO :
      - getting the childs of catParent
@@ -81,7 +89,9 @@ void BlockLibraryWidget::addClicked() {
   if(item->data(1,Qt::DisplayRole).isValid() && item->data(2,Qt::DisplayRole).isValid()){
     int idParent = item->data(1,Qt::DisplayRole).toInt();
     int idBlock = item->data(2,Qt::DisplayRole).toInt();
   if(item->data(1,Qt::DisplayRole).isValid() && item->data(2,Qt::DisplayRole).isValid()){
     int idParent = item->data(1,Qt::DisplayRole).toInt();
     int idBlock = item->data(2,Qt::DisplayRole).toInt();
-    dispatcher->addBlock(idParent, idBlock);
+    QVariant v = comboScenes->currentData();
+    cout << "adding block to scene " << v.toInt() << endl;
+    dispatcher->addBlock(idParent, idBlock, v.toInt());
   }
 
   // only take the first selected
   }
 
   // only take the first selected
@@ -89,9 +99,7 @@ void BlockLibraryWidget::addClicked() {
   // calling dispatcher addBlock() method.
 }
 
   // calling dispatcher addBlock() method.
 }
 
-
-void BlockLibraryWidget::clicked()
-{
+void BlockLibraryWidget::clicked() {
   if(tree->selectedItems().length() > 0){
     QTreeWidgetItem *item = tree->selectedItems().at(0);
     if(item->data(1,Qt::DisplayRole).isValid())
   if(tree->selectedItems().length() > 0){
     QTreeWidgetItem *item = tree->selectedItems().at(0);
     if(item->data(1,Qt::DisplayRole).isValid())
@@ -101,7 +109,16 @@ void BlockLibraryWidget::clicked()
   }
 }
 
   }
 }
 
-void BlockLibraryWidget::doubleClicked()
-{
+void BlockLibraryWidget::doubleClicked() {
   addClicked();
 }
   addClicked();
 }
+
+void BlockLibraryWidget::updateComboScene() {
+  comboScenes->clear();
+  QMap<int,QString> list = dispatcher->getAllGroupNames();
+  QMapIterator<int,QString> iter(list);
+  while (iter.hasNext()) {
+    iter.next();
+    comboScenes->addItem(iter.value(),QVariant(iter.key()));
+  }
+}