1 /*=========================================================================
2 Program: vv http://www.creatis.insa-lyon.fr/rio/vv
5 - University of LYON http://www.universite-lyon.fr/
6 - Léon Bérard cancer center http://www.centreleonberard.fr
7 - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr
9 This software is distributed WITHOUT ANY WARRANTY; without even
10 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11 PURPOSE. See the copyright notices for more information.
13 It is distributed under dual licence
15 - BSD See included LICENSE.txt file
16 - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17 ===========================================================================**/
19 #ifndef _vvLinkPanel_CXX
20 #define _vvLinkPanel_CXX
22 #include "vvLinkPanel.h"
23 #include "clitkCommon.h"
27 #include "QTreePushButton.h"
29 //------------------------------------------------------------------------------
30 vvLinkPanel::vvLinkPanel(QWidget * parent):QWidget(parent)
37 linkTableWidget->resizeColumnsToContents();
38 linkTableWidget->verticalHeader()->hide();
39 linkTableWidget->horizontalHeader()->hide();
40 linkTableWidget->hideColumn(4);
41 linkTableWidget->hideColumn(5);
43 connect(image1ComboBox,SIGNAL(currentIndexChanged(int)),this,SLOT(UpdateComboBox2(int)));
44 connect(linkButton,SIGNAL(clicked()),this,SLOT(addLink()));
45 connect(linkAllButton,SIGNAL(clicked()),this,SLOT(linkAll()));
47 //------------------------------------------------------------------------------
50 //------------------------------------------------------------------------------
51 void vvLinkPanel::addImage(std::string name, std::string id)
53 imageNames.push_back(name);
54 image1Ids.push_back(id);
57 //------------------------------------------------------------------------------
60 //------------------------------------------------------------------------------
61 bool vvLinkPanel::isLinkAll()
65 //------------------------------------------------------------------------------
67 //------------------------------------------------------------------------------
68 void vvLinkPanel::removeImage(int index)
70 std::string idRemoved = image1Ids[index];
71 std::vector<std::string>::iterator Nameiter = imageNames.begin();
72 std::vector<std::string>::iterator Iditer = image1Ids.begin();
73 for (int i = 0; i < index; i++) {
77 imageNames.erase(Nameiter);
78 image1Ids.erase(Iditer);
80 for (int i = linkTableWidget->rowCount() - 1; i >= 0 ; i--) {
81 if (linkTableWidget->item(i,4)->text().toStdString() == idRemoved ||
82 linkTableWidget->item(i,5)->text().toStdString() == idRemoved) {
83 emit removeLink(linkTableWidget->item(i,4)->text(),linkTableWidget->item(i,5)->text());
84 linkTableWidget->removeRow(i);
85 UpdateComboBox2(image1ComboBox->currentIndex());
89 //------------------------------------------------------------------------------
92 //------------------------------------------------------------------------------
93 void vvLinkPanel::UpdateComboBox1()
95 image1ComboBox->clear();
96 for (unsigned int i = 0; i < imageNames.size(); i++) {
97 image1ComboBox->addItem(imageNames[i].c_str());
100 //------------------------------------------------------------------------------
103 //------------------------------------------------------------------------------
104 void vvLinkPanel::UpdateComboBox2(int index)
106 image2ComboBox->clear();
108 if (imageNames.size() > 1 && index >= 0) {
109 for (unsigned int i = 0; i < imageNames.size(); i++) {
110 if ((int)i != index) {
111 bool AlreadyLinked = false;
112 for (int row = 0; row < linkTableWidget->rowCount(); row++) {
113 if ((linkTableWidget->item(row,1)->text().toStdString() == imageNames[index] &&
114 linkTableWidget->item(row,3)->text().toStdString() == imageNames[i]) ||
115 (linkTableWidget->item(row,3)->text().toStdString() == imageNames[index] &&
116 linkTableWidget->item(row,1)->text().toStdString() == imageNames[i])) {
117 AlreadyLinked = true;
121 if (!AlreadyLinked) {
122 image2ComboBox->addItem(imageNames[i].c_str());
123 image2Ids.push_back(image1Ids[i]);
128 if (image2ComboBox->count() == 0)
129 linkButton->setEnabled(0);
131 linkButton->setEnabled(1);
133 //------------------------------------------------------------------------------
136 //------------------------------------------------------------------------------
137 void vvLinkPanel::linkAll()
140 //First remove all links
141 while (linkTableWidget->rowCount())
143 //Now create all possible links
144 int count=image2ComboBox->count();
145 for (int j=0; j<count; j++) {
146 image1ComboBox->setCurrentIndex(j);
147 image2ComboBox->setCurrentIndex(0);
148 for (int i=0; i< count-j; i++)
153 //------------------------------------------------------------------------------
156 //------------------------------------------------------------------------------
157 void vvLinkPanel::addLink()
159 if (!image1ComboBox->currentText().isEmpty()
160 && !image2ComboBox->currentText().isEmpty()) {
161 int row = linkTableWidget->rowCount();
162 linkTableWidget->insertRow(row);
164 linkTableWidget->setItem(row,1,new QTableWidgetItem(image1ComboBox->currentText()));
165 linkTableWidget->setItem(row,2,new QTableWidgetItem("&"));
166 linkTableWidget->setItem(row,3,new QTableWidgetItem(image2ComboBox->currentText()));
167 linkTableWidget->setItem(row,4,new QTableWidgetItem(image1Ids[image1ComboBox->currentIndex()].c_str()));
168 linkTableWidget->setItem(row,5,new QTableWidgetItem(image2Ids[image2ComboBox->currentIndex()].c_str()));
169 QTreePushButton* cButton = new QTreePushButton;
170 cButton->setIndex(linkTableWidget->rowCount());
171 cButton->setColumn(0);
172 cButton->setIcon(QIcon(QString::fromUtf8(":/common/icons/exit.png")));
173 connect(cButton,SIGNAL(clickedInto(int, int)),
174 this,SLOT(removeLink(int, int)));
175 cButton->setToolTip(tr("remove link"));
176 linkTableWidget->setCellWidget(row,0,cButton);
178 linkTableWidget->resizeColumnToContents(0);
179 linkTableWidget->resizeColumnToContents(1);
180 linkTableWidget->resizeColumnToContents(2);
181 linkTableWidget->resizeColumnToContents(3);
182 linkTableWidget->setRowHeight(row,17);
184 emit addLink(image1Ids[image1ComboBox->currentIndex()].c_str(),
185 image2Ids[image2ComboBox->currentIndex()].c_str());
186 UpdateComboBox2(image1ComboBox->currentIndex());
190 //------------------------------------------------------------------------------
193 //------------------------------------------------------------------------------
194 void vvLinkPanel::removeLink(int row, int column)
198 while (linkTableWidget->item(row-1,4) == NULL) {
200 // DD(linkTableWidget->rowCount());
204 if (linkTableWidget->item(row-1,5) == NULL) {
205 return; // should not happend ...
208 emit removeLink(linkTableWidget->item(row-1,4)->text(),linkTableWidget->item(row-1,5)->text());
210 linkTableWidget->removeRow(row-1);
211 // DD("after removeRow");
212 UpdateComboBox2(image1ComboBox->currentIndex());
215 //------------------------------------------------------------------------------
217 #endif /* end #define _vvLinkPanel_CXX */