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

Private GIT Repository
correct bug with clkrstgen
[blast.git] / BlocksToConfigureWidget.cpp
1 #include "BlocksToConfigureWidget.h"
2 #include <QTreeWidgetItem>
3 #include "ParametersWindow.h"
4
5
6 BlocksToConfigureWidget::BlocksToConfigureWidget(QList<AbstractBlock *> blocksList, Parameters *_params, QWidget *parent) :
7     QWidget(parent)
8 {
9   blocks = blocksList;
10   params = _params;
11   layout = new QGridLayout;
12   tree = new QTreeWidget(this);
13   configureButton = new QPushButton("configure", this);
14   configureButton->setEnabled(false);
15
16   connect(tree, SIGNAL(itemClicked(QTreeWidgetItem*,int)), this, SLOT(clicked()));
17   connect(tree, SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)), this, SLOT(doubleClicked()));
18   connect(configureButton, SIGNAL(clicked()), this, SLOT(configure()));
19
20   updateNamesList();
21   tree->setHeaderLabel("blocks to configure");
22   layout->addWidget(tree);
23   layout->addWidget(configureButton);
24
25   this->setLayout(layout);
26   this->setFixedSize(300,230);
27 }
28
29 void BlocksToConfigureWidget::updateNamesList()
30 {
31   tree->clear();
32   QTreeWidgetItem *item = NULL;
33   foreach(AbstractBlock *block, blocks){
34     item = new QTreeWidgetItem(tree->invisibleRootItem());
35     item->setData(0, Qt::DisplayRole, block->getName());
36   }
37
38 }
39
40 void BlocksToConfigureWidget::updateBlocksList()
41 {
42   blocks = params->getBlocksToConfigure();
43   updateNamesList();
44 }
45
46 void BlocksToConfigureWidget::closeEvent(QCloseEvent *event)
47 {
48   //when parameters validation is over,
49   //we start connections validation.
50   params->connectionsValidation();
51 }
52
53 void BlocksToConfigureWidget::clicked()
54 {
55   if(tree->selectedItems().length() > 0)
56     configureButton->setEnabled(true);
57   else
58     configureButton->setEnabled(false);
59 }
60
61 void BlocksToConfigureWidget::doubleClicked()
62 {
63   configure();
64 }
65
66 void BlocksToConfigureWidget::configure()
67 {
68   if(tree->selectedItems().length() > 0){
69     bool firstItem = true;  //    We take only the first selected item
70     for (int i=0; i<tree->topLevelItemCount(); i++){
71       if(firstItem && tree->topLevelItem(i)->isSelected()){
72         firstItem = false;
73         new ParametersWindow(blocks.at(i), params, this);
74       }
75     }
76   }
77 }